Changeset 286 for trunk/game/scripts


Ignore:
Timestamp:
09/18/09 09:08:25 (10 years ago)
Author:
b0rland_parpg
Message:

Ticket #67: patch by b0rland

  • changed default Lockable state to unlocked
  • fixed Lockable constructor logic to correctly process locked/is_open combination
  • fixed typo in Container
  • fixed tests to accomodate the above changes
  • created tests for Openable, Lockable, Container
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/objects/base.py

    r284 r286  
    139139class Lockable (Openable): 
    140140    """Allows objects to be locked""" 
    141     def __init__ (self, locked = True, **kwargs): 
     141    def __init__ (self, locked = False, is_open=True, **kwargs): 
    142142        """Init operation for lockable objects 
    143143        @type locked: Boolean 
    144144        @param locked: Keyword boolen argument to set the initial locked state. 
     145        @type is_open: Boolean 
     146        @param is_open: Keyword boolean argument sets the initial open state. It is ignored if locked is True -- locked objects are always closed. 
    145147        """ 
    146148        self.is_lockable = True 
    147149        self.locked = locked 
    148         Openable.__init__( self, **kwargs ) 
     150        if locked : 
     151            is_open=False 
     152        Openable.__init__( self, is_open, **kwargs ) 
    149153         
    150154    def unlock (self): 
     
    185189        self.items.append (item) 
    186190        # Run any scripts associated with storing an item in the container 
    187         if self.trueAttr ('scriptable'): 
    188             self.runScript('onPlaceItem') 
    189          
     191        try: 
     192            if self.trueAttr ('scriptable'): 
     193                self.runScript('onPlaceItem') 
     194        except AttributeError : 
     195            pass 
     196 
    190197    def takeItem (self, item): 
    191198        """Takes the listed item out of the inventory.  
     
    195202        self.items.remove (item) 
    196203        # Run any scripts associated with popping an item out of the container 
    197         if self.trueAttr ('scriptable'): 
    198             self.runScript('ontakeItem') 
     204        try: 
     205            if self.trueAttr ('scriptable'): 
     206                self.runScript('onTakeItem') 
     207        except AttributeError : 
     208            pass 
    199209         
    200210class Inventory (object): 
Note: See TracChangeset for help on using the changeset viewer.