Package scripts :: Package objects :: Script base
[hide private]
[frames] | no frames]

Module base

source code

Containes classes defining the base properties of all interactable in-game 
objects (such as Carryable, Openable, etc. These are generally independent 
classes, which can be combined in almost any way and order. 

Some rules that should be followed when CREATING base property classes:

1. If you want to support some custom initialization arguments, 
   always define them as keyword ones. Only GameObject would use 
   positional arguments.
2. In __init__() **ALWAYS** call the parent's __init__(**kwargs), preferably 
   *at the end* of your __init__() (makes it easier to follow)
3. There should always be an attributes.append(x) call on __init__ 
   (where X is the name of the class)

EXAMPLE:

class Openable(object):
    def __init__ (self, is_open = True, **kwargs):
        self.attribbutes.append("openable")
        self.is_open = is_open
        super(Openable,self).__init__ (**kwargs)
     

Some rules are to be followed when USING the base classes to make composed 
ones:

1. The first parent should always be the base GameObject class
2. Base classes other than GameObject can be inherited in any order
3. The __init__ functoin of the composed class should always invoke the
   parent's __init__() *before* it starts customizing any variables.

EXAMPLE:

class TinCan (GameObject, Container, Scriptable, Destructable, Carryable):
    def __init__ (self, *args, **kwargs):
        super(TinCan,self).__init__ (*args, **kwargs)
        self.name = 'Tin Can'

Classes [hide private]
  BaseObject
A base class that supports dynamic attributes functionality
  DynamicObject
Class with basic attributes
  GameObject
A base class to be inherited by all game objects.
  Scriptable
Allows objects to have predefined scripts executed on certain events
  Openable
Adds open() and .close() capabilities to game objects The current state is tracked by the .is_open variable
  Lockable
Allows objects to be locked
  Carryable
Allows objects to be stored in containers
  Container
Gives objects the capability to hold other objects
  Living
Objects that 'live'
  CharStats
Provides the object with character statistics
  Wearable
Objects than can be weared
  Usable
Allows the object to be used in some way (e.g.
  Weapon
Allows the object to be used as a weapon
  Destructable
Allows the object to be destroyed
  Trapable
Provides trap slots to the object