comparison components/equip.py @ 143:fa5c769468f0

get_equipable now checks if wearer is valid and returns None if it is not. This will fix a falsely raised SlotInvalidError.
author KarstenBock@gmx.net
date Sun, 09 Oct 2011 19:23:59 +0200
parents f2ef124128db
children
comparison
equal deleted inserted replaced
142:c28e29056218 143:fa5c769468f0
19 """ 19 """
20 20
21 def __init__(self): 21 def __init__(self):
22 Base.__init__(self, head=object, neck=object, body=object, belt=object, 22 Base.__init__(self, head=object, neck=object, body=object, belt=object,
23 leg=object, feet=object, l_arm=object, r_arm=object) 23 leg=object, feet=object, l_arm=object, r_arm=object)
24 self.head = None
25 self.neck = None
26 self.body = None
27 self.belt = None
28 self.leg = None
29 self.feet = None
30 self.l_arm = None
31 self.r_arm = None
24 32
25 @property 33 @property
26 def saveable_fields(self): 34 def saveable_fields(self):
27 return [] 35 return []
28 36
74 raise SlotInvalidError(slot) 82 raise SlotInvalidError(slot)
75 raise CannotBeEquippedInSlot(slot, equipable) 83 raise CannotBeEquippedInSlot(slot, equipable)
76 84
77 def get_equipable(wearer, slot): 85 def get_equipable(wearer, slot):
78 """Return the equipable in the given slot""" 86 """Return the equipable in the given slot"""
87 if not wearer:
88 return None
79 try: 89 try:
80 item = getattr(wearer, slot) 90 item = getattr(wearer, slot)
81 return item 91 return item
82 except AttributeError: 92 except AttributeError:
83 raise SlotInvalidError(slot) 93 raise SlotInvalidError(slot)