Package horizons :: Package component :: Module componentholder :: Class ComponentHolder
[hide private]
[frames] | no frames]

Class ComponentHolder

source code

Class that manages Component plug-ins It can be inherited by all objects that can hold components

TUTORIAL: I can't explain component-oriented architecture to you here, but I can give you an overview of how we use it: Instead of putting all different features of entities into single classes, as is common in OOP, each feature is put into a component. This should increase the encapsulation, and it's easier if an object consists of 15 independent building blocks than if it were 15 classes, where many override the same function call and fight about who gets called first. Check class_mapping for a complete list of the different components we use.

The components are stored in a dict, where the key is their name (a string). This is necessary so objects can be defined as a collection of their components in human readable format. This is done via yaml files in content/objects in our case. You could check out e.g. content/objects/buildings/lumberjackcamp.yaml to see what it looks like.

This class manages the components; it stores them and makes them accessible. Check out the actual component class in horizons/component/

Instance Methods [hide private]
__init__(self, *args, **kwargs) source code
initialize(self, **kwargs)
Has to be called every time a componentholder is created.
source code
__create_components(self) source code
remove(self) source code
load(self, db, worldid) source code
save(self, db) source code
add_component(self, component)
Adds new component to holder and sets the instance attribute on the component
source code
remove_component(self, component_class)
Removes component from holder.
source code
has_component(self, component_class)
Check if holder has component with component name
source code
get_component(self, component) source code
get_component_by_name(self, name) source code
Class Methods [hide private]
get_component_template(cls, component)
Returns the component template data given a component NAME
source code
Class Variables [hide private]
  class_mapping = {'AmbientSoundComponent': AmbientSoundComponen...
Method Details [hide private]

initialize(self, **kwargs)

source code 

Has to be called every time a componentholder is created. This is not in __init__() because we need to make sure that all other sub/parent classes have been inited, for example the ConcreteObject class. This is to ensure that all member variables of sub/parent classes are correctly set when we init the components. If someday all code is moved to components, this will not be necessary any more.

add_component(self, component)

source code 

Adds new component to holder and sets the instance attribute on the component

  • component - a component instance that is to be added all components will have the init only with instance attribute

Class Variable Details [hide private]


{'AmbientSoundComponent': AmbientSoundComponent, 'CommandableComponent\
': CommandableComponent, 'CollectingComponent': CollectingComponent, '\
ColorOverlayComponent': ColorOverlayComponent, 'DepositComponent': Dep\
ositComponent, 'FieldBuilder': FieldBuilder, 'HealthComponent': Health\
Component, 'InventoryOverlayComponent': InventoryOverlayComponent, 'Na\
medComponent': NamedComponent, 'PirateShipNameComponent': PirateShipNa\
meComponent, 'SoldierNameComponent': SoldierNameComponent, 'Inhabitant\
NameComponent': InhabitantNameComponent, 'ProducerComponent': Producer\