Module containing the model base class.
Model base class.
Parameters: |
|
---|
Unregister itself.
Handle the registering functions.
If the model doesn’t have its own corresponding handler, it will recursively look into its children.
Returns: | func – a callable that recursively look into the children |
---|---|
Raises: | AttributeError – in regular cases. |
Warning: no exception is raised if no handler is found. It will be silentely ignored and False will be returned
This choice has been made on purpose, considering the controller might register more types of actions than the model can handle.
Iterator support.
Returns: | list – the direct children. |
---|
Recursively get the dictionnary of all models with their associated key (including itself).
Returns: | dict – the (key, model) dictionnary |
---|
Method to override.
Called at initialization with the same arguments as the __init__ method, but without the parent. If a model has to be initialized with custom arguments, this is where they should be handled.
The base implementation also start a timer call self.lifetime. It is a non periodic timer with no upper limit and no callback.
Empty method to override if needed.
Called when the state is reloaded.
Empty method to override.
Called at each tick of the state.
Returns: | bool – True to stop the current state, False otherwise. |
---|
Timer model class.
Parameters: |
|
---|
It uses the current system FPS value to update accordingly. This way, the timer ignore lags or frame rate variations.
Get the current value of the timer.
Parameters: | normalized (bool) – normalize the value with start and stop value (default is False) |
---|---|
Returns: | float – current value (between 0 and 1 if normalized. |
Return the (start, stop) interval as a tuple.
Initalize the timer.
Parameters: |
|
---|
Return True if the timer is paused, False otherwise.
Return True if the timer reached its start value. Return False otherwise.
Return True if the timer reached its stop value. Return False otherwise.
Stop the timer.
Returns: | itself for affectation |
---|
Reset the timer.
Returns: | itself for affectation |
---|
Set the timer.
Parameters: | value (float or None) – value to set the timer, set to stop if value is None |
---|---|
Returns: | model – itself for affectation |
Raises: | ValueError – if value not between start and stop |
Start the timer.
Parameters: | ratio (float) – speed in unit per seconds (default is 1.0) |
---|---|
Returns: | itself for affectation |
Update the timer.
Use self.state.current_fps to update the current value accordingly. Also call the callback if needed.
Build a property from an attribute name in gamedata.
The main purpose is simplify the communication between the model and the gamedata.
Example:
@property_from_gamedata("player_score"):
def score(self):
return 0