Need mutator classes for pyDynECS. These are callable()s which take an IComponentManager class and mutate it's functionality. Below are some mutators we need.
A common pattern for implementing this is to use a function with an anonymous class definition. Mutator order will be important:
_cache_exampleMutator = {}
def ExampleMutator(cls):
if not (cls in _cache_exampleMutator):
class MutatedExample(cls):
...
# Better names for inspection:
MutatedExample.__qualname__ = "MutatedExample<{}>".format(cls.__qualname__)
_cache_exampleMutator[cls] = MutatedExample
return _cache_exampleMutator[cls]
# Usage:
component_manager = ExampleMutator(BasicComponentManager)()
# or
class NewComponentManagerType(ExampleMutator(BasicComponentManager)):
...
Mutators:
Observable(cls, event_type=pyext.Event): Adds events for mutating functions (add, set, del) with the naming scene on_*. Where on_add is triggered before on_set for entities that currently have no component. The events have the following signature (manager, entity, overriding=None) where overriding is only for on_set (on_del is called before the component is actually removed).
Immutable(cls): Removes del, forces set to only be called once (exception otherwise).
Typed/Coering: Refactor the existing non-basic component manager types to be mutators. They don't do enough different to be fully fledged different classes. Also move the coercing/typed function to the class, instead of the constructor.
Need mutator classes for pyDynECS. These are
callable()
s which take anIComponentManager
class and mutate it's functionality. Below are some mutators we need.A common pattern for implementing this is to use a function with an anonymous class definition. Mutator order will be important:
Mutators:
Observable(cls, event_type=pyext.Event)
: Adds events for mutating functions (add
,set
,del
) with the naming sceneon_*
. Whereon_add
is triggered beforeon_set
for entities that currently have no component. The events have the following signature(manager, entity, overriding=None)
whereoverriding
is only foron_set
(on_del
is called before the component is actually removed).Immutable(cls)
: Removes del, forces set to only be called once (exception otherwise).