kxg.tokens.TokenSafetyChecks

class kxg.tokens.TokenSafetyChecks(name, bases, members)[source]

Bases: type

Add checks to make sure token methods are being called safely.

In order to keep multiplayer games in sync, the world should only be modified at particular times (e.g. token update methods and messages). The purpose of this metaclass is to stop you from accidentally trying to modify the world outside of these defined times, because doing so would lead to subtle synchronization bugs that could be hard to find.

The engine indicates when it is safe to modify the world by setting a boolean lock flag in the world. This metaclass adds a bit of logic to non-read-only token methods that makes sure the world is unlocked before continuing. The read_only decorator can be used to indicate which methods are read-only, and are therefore excluded from these checks.

The checks configured by this metaclass help find bugs, but may also incur unnecessary computational expense once the game has been fully debugged. For this reason, you can skip the checks by invoking python with optimization enabled (i.e. passing -O).

Public Methods:

__new__(meta, name, bases, members)

Create and return a new object.

add_safety_checks(members)

Iterate through each member of the class being created and add a safety check to every method that isn’t marked as read-only.

add_safety_check(member_name, member_value)

If the given member is a method that is public (i.e.

Inherited from type

__repr__()

Return repr(self).

__call__(*args, **kwargs)

Call self as a function.

__getattribute__(name, /)

Return getattr(self, name).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__delattr__(name, /)

Implement delattr(self, name).

__init__(*args, **kwargs)

Initialize self.

mro()

Return a type’s method resolution order.

__subclasses__()

Return a list of immediate subclasses.

__prepare__()

used to create the namespace for the class statement

__instancecheck__(instance, /)

Check if an object is an instance.

__subclasscheck__(subclass, /)

Check if a class is a subclass.

__dir__()

Specialized __dir__ implementation for types.

__sizeof__()

Return memory consumption of the type object.

__base__

alias of builtins.type

__bases__ = (<class 'type'>,)
__basicsize__ = 864
__call__(*args, **kwargs)

Call self as a function.

__delattr__(name, /)

Implement delattr(self, name).

__dictoffset__ = 264
__dir__()

Specialized __dir__ implementation for types.

__flags__ = 2148292097
__getattribute__(name, /)

Return getattr(self, name).

__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

__instancecheck__(instance, /)

Check if an object is an instance.

__itemsize__ = 40
__mro__ = (<class 'kxg.tokens.TokenSafetyChecks'>, <class 'type'>, <class 'object'>)
__name__ = 'TokenSafetyChecks'
static __new__(meta, name, bases, members)[source]

Create and return a new object. See help(type) for accurate signature.

__prepare__()dict

used to create the namespace for the class statement

__qualname__ = 'TokenSafetyChecks'
__repr__()

Return repr(self).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__sizeof__()

Return memory consumption of the type object.

__subclasscheck__(subclass, /)

Check if a class is a subclass.

__subclasses__()

Return a list of immediate subclasses.

__text_signature__ = None
__weakrefoffset__ = 368
static add_safety_check(member_name, member_value)[source]

If the given member is a method that is public (i.e. doesn’t start with an underscore) and hasn’t been marked as read-only, replace it with a version that will check to make sure the world is locked. This ensures that methods that alter the token are only called from update methods or messages.

classmethod add_safety_checks(members)[source]

Iterate through each member of the class being created and add a safety check to every method that isn’t marked as read-only.

mro()

Return a type’s method resolution order.