OffByOneStudios / massive-dangerzone

A platform agnostic module management system.
6 stars 1 forks source link

pyDynECS component manager mutators #47

Closed mason-bially closed 10 years ago

mason-bially commented 10 years ago

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:

mason-bially commented 10 years ago

Handeled with mixins instead.