pygase.gamestate
Customize a game state model and apply state updates.
Contents
TO_DELETE: 4 byte update marker for game state attributes that are to be deletedGameStatus: enum for the status of the game simulationGameState: class for serializable custom state data objectsGameStateUpdate: class for serializable objects that express changes to a GameState object
GameStatus
GameStatus(self, /, *args, **kwargs)
Enum for the game simulation status.
'Paused''Active'
GameState
GameState(self, time_order:int=0, game_status:int=0, **kwargs)
Customize a serializable game state model.
Contains game state information that will be synchronized between the server and the clients.
Via pygase.utils.Sendable its instances will be serialized using the msgpack protocol
and must only contain attributes of type str, bytes, Sqn, int, float, bool
as well as lists or tuples of such.
Arguments
- time_order (int): current time order number of the game state, higher means more recent
- game_status (int):
GameStatusenum value that describes whether or not the game loop is running
Provide custom game state attributes via keyword arguments or assign them later.
Attributes
game_status (int): see constructor argument of same nametime_order (pygase.utils.Sqn): see constructor argument of same name
GameState instances mainly consist of custom attributes that make up the game state.
is_paused
GameState.is_paused(self) -> bool
Return True if game is paused.
GameStateUpdate
GameStateUpdate(self, time_order:int, **kwargs)
Update a GameState object.
Contains a set of changes to carry out on a GameState.
The server keeps a time_order counter and labels all updates in ascending order.
Attributes of a GameStateUpdate object represent new values of GameState attributes.
To remove game state attributes just assign TO_DELETE to it in the update.
Use the + operator to add updates to one another and combine them or to add them to a
game state in order to update it.
Arguments
- time_order (int): the time order up to which the update reaches
game state attributes to be updated
Attributes
time_order (pygase.utils.Sqn): see constructor argument of same name
GameStateUpdate instances mainly consist of custom game state attributes to update.
from_bytes
GameStateUpdate.from_bytes(bytepack:bytes) -> 'GameStateUpdate'
Extend Sendable.from_bytes to make sure time_order is of type Sqn.