Changeset 174


Ignore:
Timestamp:
07/01/09 18:16:25 (10 years ago)
Author:
tie_parpg
Message:
  • added check for locked state to the .open fucntion of Lockables
  • .unlock no longer opens the object
  • renamed Container functions (now it's takeItem/placeItem
  • takeItem now simply removes the quoted item from the Container
  • the mapref argument in GameObject? is now renamed to map_id
  • fixed the trueAttr bug/typo, and updated the unit tests (thanks for the tests, Meggie!)
Location:
trunk/PARPG/scripts
Files:
2 edited

Legend:

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

    r166 r174  
    5454    This must be the first class (left to right) inherited by any game object. 
    5555    """ 
    56     def __init__ (self, ID, gfx = {}, coords = (0.0,0.0), mapref = None,  
     56    def __init__ (self, ID, gfx = {}, coords = (0.0,0.0), map_id = None,  
    5757                  blocking=True, name="Generic object", text="Item description", 
    5858                  **kwargs): 
     
    6464        @type coords 2-item tuple 
    6565        @param coords: Initial coordinates of the object. 
    66         @type mapref: ??? 
    67         @param mapref: Reference to the map where the object is located 
     66        @type map_id: ??? 
     67        @param map_id: Identifier of the map where the object is located 
    6868        @type blocking: Boolean 
    6969        @param blocking: Whether the object blocks character movement 
     
    7676        self.gfx = gfx 
    7777        self.X, self.Y = float(coords[0]), float (coords[1]) 
    78         self.mapref = mapref 
     78        self.map_id = map_id 
    7979        self.blocking = True 
    8080        self.name = name 
     
    8282        super(GameObject,self).__init__ (**kwargs) 
    8383         
    84     def trueAtrr (self, attr): 
     84    def trueAttr (self, attr): 
    8585        """Shortcut function to check if the current object has a member named 
    8686        is_%attr and if that attribute evaluates to True""" 
     
    139139    def unlock (self): 
    140140        """Handles unlocking functionality""" 
    141         self.locked = False 
    142         self.open()         
     141        self.locked = False       
    143142         
    144143    def lock (self): 
     
    147146        self.locked = True 
    148147         
     148    def open (self, *args, **kwargs): 
     149        """Adds a check to see if the object is unlocked before running the 
     150        .open() function of the parent class""" 
     151        if self.locked: 
     152            raise ValueError ("Open failed: object locked") 
     153        super (Lockable,self).open(*args,**kwargs) 
     154         
    149155class Carryable (object): 
    150156    """Allows objects to be stored in containers""" 
     
    162168        super(Container,self).__init__ (**kwargs) 
    163169         
    164     def storeItem (self, item): 
     170    def placeItem (self, item): 
    165171        """Adds the provided carriable item to the inventory.  
    166172        Runs an 'onStoreItem' script, if present"""     
     
    173179            self.runScript('onStoreItem') 
    174180         
    175     def popItem (self, item, newcontainer): 
    176         """Takes the listed item out of the inventory, and adds it to 
    177         `newcontainer`. Runs an 'onPopItem' script"""         
     181    def takeItem (self, item): 
     182        """Takes the listed item out of the inventory.  
     183        Runs an 'ontakeItem' script"""         
    178184        if not item in self.items: 
    179185            raise ValueError ('I do not contain this item: %s' % item) 
    180186        self.items.remove (item) 
    181         newcontainer.storeItem (item) 
    182187        # Run any scripts associated with popping an item out of the container 
    183188        if self.trueAttr ('scriptable'): 
    184             self.runScript('onPopItem') 
     189            self.runScript('ontakeItem') 
    185190         
    186191class Inventory (object): 
  • trunk/PARPG/scripts/tests/classTests.py

    r172 r174  
    1414                {'map': 'objects/objects/crate/image.png'}) 
    1515        self.assertEqual(self.crate.coords, (0.0, 0.0)) 
    16         self.assertEqual(self.crate.mapref, None) 
     16        self.assertEqual(self.crate.map_id, None) 
    1717        self.assertEqual(self.crate.blocking, True) 
    1818        self.assertEqual(self.crate.is_open, True) 
Note: See TracChangeset for help on using the changeset viewer.