Package horizons :: Package component :: Class Component
[hide private]
[frames] | no frames]

Class Component

source code

Base class for all components. Something like an interface.

TUTORIAL: This is what all components share, basically only set up and tear down. It would be advisable to look through all methods here, and especially to see the difference between loading components (from a savegame) and setting them up in a normal game.

Once you know how it works, please proceed to horizons/world/ingametype.py where you'll see how the actual things in Unknown Horizons are created.

Instance Methods [hide private]
 
__init__(self)
Used for initialization code that does not require any other components.
source code
 
session(self) source code
 
initialize(self)
This is called by the ComponentHolder after it set the instance.
source code
 
remove(self)
Removes component and reference to instance
source code
 
save(self, db)
Will do nothing, but will be always called in componentholder code, even if not implemented.
source code
 
load(self, db, worldid)
This does on load what __init() and initalize() together do on constructions at runtime.
source code
 
__gt__(self, other) source code
 
__lt__(self, other) source code
Class Methods [hide private]
 
get_instance(cls, arguments=None)
This function is used to instantiate classes from yaml data.
source code
Class Variables [hide private]
  NAME = None
hash(x)
  DEPENDENCIES = []
Method Details [hide private]

__init__(self)
(Constructor)

source code 

Used for initialization code that does not require any other components. This is always called first, on construction and on load.

session(self)

source code 
Decorators:
  • @property

initialize(self)

source code 

This is called by the ComponentHolder after it set the instance. Use this to initialize any needed infrastructure. When this is called, it is guaranteed that all other components this one has a dependency on have been added, but initalize may not have been called on them, only __init__. It is only called after construction, not on load().

load(self, db, worldid)

source code 

This does on load what __init() and initalize() together do on constructions at runtime. Has to set up everything that is not setup in __init__(). Note that on loading __init__() is called with the data needed by the component through get_instance(), but initialize() is not, so any work needed for loading as well should be moved to a separate method and called here.

get_instance(cls, arguments=None)
Class Method

source code 

This function is used to instantiate classes from yaml data. Override this if the component has more than just a basic constructor with primitive types (takes custom classes as arguments, e.g. Storages)