Changeset 286 for trunk/game


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
Location:
trunk/game
Files:
3 added
3 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): 
  • trunk/game/tests/test_crate.py

    r284 r286  
    2222    def setUp(self): 
    2323        self.crate = WoodenCrate(ID='crate01') 
    24         self.crate2 = WoodenCrate(ID='crate02', locked=False) 
     24        self.crate2 = WoodenCrate(ID='crate02', locked=True) 
    2525 
    2626    def testCreation(self): 
     
    3434        self.assertEqual(self.crate.blocking, True) 
    3535        self.assertEqual(self.crate.is_open, True) 
    36         self.assertEqual(self.crate.locked, True) 
     36        self.assertEqual(self.crate.locked, False) 
    3737        self.assertEqual(self.crate.scripts, {}) 
    3838 
    3939        self.assertEqual(self.crate2.ID, 'crate02') 
    40         self.assertEqual(self.crate2.locked, False) 
     40        self.assertEqual(self.crate2.locked, True) 
    4141 
    4242    # can't test containing functionality...there are no containable objects 
     
    4444    def testLockable(self): 
    4545        """ Test the WoodenCrate lockability""" 
    46         self.crate2.lock() 
    47         self.assertEqual(self.crate2.locked, True) 
    48         self.crate2.unlock() 
    49         self.assertEqual(self.crate2.locked, False) 
     46        self.crate.lock() 
     47        self.assertEqual(self.crate.locked, True) 
     48        self.crate.unlock() 
     49        self.assertEqual(self.crate.locked, False) 
  • trunk/game/tests/test_objects_base.py

    r284 r286  
    4848            is_open = True, 
    4949            is_lockable = True, 
    50             locked = True, 
     50            locked = False, 
    5151            is_carryable = True, 
    5252            weight = 1.0, 
Note: See TracChangeset for help on using the changeset viewer.