Coverage for /home/kale/kxgames/libraries/kxg/kxg/world.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python3
# Make a copy of self._tokens.values() because it's possible for tokens # to be added or removed from the world while the world is being # iterated through. Concretely, this can happen when a token extension # sends a message to add or remove a token during on_update_game().
can't pickle the world.
The world should never have to be pickled and sent over the network, because each machine starts with its own world and is kept in sync by the messaging system. But unless you are explicitly trying to pickle the world on your own, this error is more likely to be the symptom of a major bug in the messaging system that is preventing it from correctly deciding which tokens need to be pickled.""")
raise AssertionError("""\ World.__getstate__ should've refused to pickle the world.""")
def get_token(self, id): """ Return the token with the given id. If no token with the given id is registered to the world, an IndexError is thrown. """
def get_last_id(self): """ Return the largest token id registered with the world. If no tokens have been added to the world, the id for the world itself (0) is returned. This means that the first "real" token id is 1. """
def is_locked(self): """ Return whether or not the world is currently allowed to be modified. """
def has_game_ended(self): """ Return true if the game has ended. """
def _unlock_temporarily(self): """ Allow tokens to modify the world for the duration of a with-block.
It's important that tokens only modify the world at appropriate times, otherwise the changes they make may not be communicated across the network to other clients. To help catch and prevent these kinds of errors, the game engine keeps the world locked most of the time and only briefly unlocks it (using this method) when tokens are allowed to make changes. When the world is locked, token methods that aren't marked as being read-only can't be called. When the world is unlocked, any token method can be called. These checks can be disabled by running python with optimization enabled.
You should never call this method manually from within your own game. This method is intended to be used by the game engine, which was carefully designed to allow the world to be modified only when safe. Calling this method yourself disables an important safety check. """ else: finally:
assert token.has_id, msg("""\ token {token} should've been assigned an id by Message._assign_token_ids() before World._add_token() was called.""") assert token not in self, msg("""\ Message._assign_token_ids() should've refused to process a token that was already in the world.""")
# Add the token to the world.
""" Tell the world which actors are running on this machine. This information is used to create extensions for new tokens. """
def require_world(object):
|