class Holder: __slots__ = ("__fit", "item", "attributes", "__state") def __init__(self, type_): self.__fit = None self.item = type_ self.attributes = MutableAttributeMap(self) self.__state = State.offline @property def _fit(self): return self.__fit @_fit.setter def _fit(self, newFit): self.attributes.clear() self.__fit = newFit @property def state(self): return self.__state @state.setter def state(self, newState): oldState = self.state if newState == oldState: return if self._fit is not None: self._fit._holderStateSwitch(self, newState) self.__state = newState
class Holder: __slots__ = ('__fit', 'item', 'attributes', '__state') def __init__(self, type_): self.__fit = None self.item = type_ self.attributes = MutableAttributeMap(self) self.__state = State.offline @property def _fit(self): return self.__fit @_fit.setter def _fit(self, newFit): self.attributes.clear() self.__fit = newFit @property def state(self): return self.__state @state.setter def state(self, newState): oldState = self.state if newState == oldState: return if self._fit is not None: self._fit._holderStateSwitch(self, newState) self.__state = newState
class Holder: """ Base holder class inherited by all classes that need to keep track of modified attributes. Positional arguments: typeId -- typeID of item, which is supposed to be base item for holder state -- state which this holder takes during initialization """ __slots__ = ('__typeId', '__state', 'attributes', '__fit', '__type') def __init__(self, typeId, state): # TypeID of item this holder is supposed to wrap self.__typeId = typeId # Keeps current state of the holder self.__state = state # Special dictionary subclass that holds modified attributes # and data related to their calculation self.attributes = MutableAttributeMap(self) # Which fit this holder is bound to self.__fit = None # Which type this holder wraps self.__type = None ## Keeps current target of holder #self.__target = None @property def item(self): return self.__type @property def _fit(self): return self.__fit @_fit.setter def _fit(self, newFit): self.__fit = newFit self._refreshContext() def _refreshContext(self): """ Each time holder's context is changed (holder's fit or fit's eos), this method should be called; it will refresh data which belongs to certain context and which is not actual outside of it. """ self.attributes.clear() try: cacheHandler = self.__fit.eos._cacheHandler except AttributeError: self.__type = None else: self.__type = cacheHandler.getType(self.__typeId) @property def state(self): return self.__state @state.setter def state(self, newState): if newState == self.state: return # When holder is assigned to some fit, ask fit to perform # fit-specific state switch of our holder if self._fit is not None: self._fit._holderStateSwitch(self, newState) self.__state = newState # @property # def target(self): # """Get target, onto which holder is applied""" # return self.__target # # @target.setter # def target(self, newTarget): # """Project holder onto target""" # if self.item.isTargeted is True: # self.__target = newTarget # else: # raise TargetException("attempt to project holder with non-projectable item") @property def trackingSpeed(self): """Get tracking speed of holder""" tsAttrId = self.item._trackingSpeedAttributeId if tsAttrId is not None: try: tracking = self.attributes[tsAttrId] except KeyError: tracking = None else: tracking = None return tracking @property def optimalRange(self): """Get optimal range of holder""" orAttrId = self.item._rangeAttributeId if orAttrId is not None: try: optimal = self.attributes[orAttrId] except KeyError: optimal = None else: optimal = None return optimal @property def falloffRange(self): """Get falloff range of holder""" frAttrId = self.item._falloffAttributeId if frAttrId is not None: try: falloff = self.attributes[frAttrId] except KeyError: falloff = None else: falloff = None return falloff @property def cycleTime(self): """Get cycle time of holder""" ctAttrId = self.item._durationAttributeId if ctAttrId is not None: try: cycleTime = self.attributes[ctAttrId] except KeyError: cycleTime = None else: cycleTime = None return cycleTime
class Holder: """ Base holder class inherited by all classes that need to keep track of modified attributes. Positional arguments: typeId -- typeID of item, which is supposed to be base item for holder state -- state which this holder takes during initialization """ __slots__ = ('__typeId', '__state', 'attributes', '__fit', '__type') def __init__(self, typeId, state): # TypeID of item this holder is supposed to wrap self.__typeId = typeId # Keeps current state of the holder self.__state = state # Special dictionary subclass that holds modified attributes # and data related to their calculation self.attributes = MutableAttributeMap(self) # Which fit this holder is bound to self.__fit = None # Which type this holder wraps self.__type = None ## Keeps current target of holder #self.__target = None @property def item(self): return self.__type @property def _fit(self): return self.__fit @_fit.setter def _fit(self, newFit): self.__fit = newFit self._refreshContext() def _refreshContext(self): """ Each time holder's context is changed (holder's fit or fit's eos), this method should be called; it will refresh data which belongs to certain context and which is not actual outside of it. """ self.attributes.clear() try: cacheHandler = self.__fit.eos._cacheHandler except AttributeError: self.__type = None else: self.__type = cacheHandler.getType(self.__typeId) @property def state(self): return self.__state @state.setter def state(self, newState): if newState == self.state: return # When holder is assigned to some fit, ask fit to perform # fit-specific state switch of our holder if self._fit is not None: self._fit._holderStateSwitch(self, newState) self.__state = newState # @property # def target(self): # """Get target, onto which holder is applied""" # return self.__target # # @target.setter # def target(self, newTarget): # """Project holder onto target""" # if self.item.isTargeted is True: # self.__target = newTarget # else: # raise TargetException("attempt to project holder with non-projectable item") @property def trackingSpeed(self): """Get tracking speed of holder""" return self.__getItemSpecificAttr('_trackingSpeedAttributeId') @property def optimalRange(self): """Get optimal range of holder""" return self.__getItemSpecificAttr('_rangeAttributeId') @property def falloffRange(self): """Get falloff range of holder""" return self.__getItemSpecificAttr('_falloffAttributeId') @property def cycleTime(self): return self.__getItemSpecificAttr('_durationAttributeId') def __getItemSpecificAttr(self, attrName): """Get holder attribute, which is referred by item""" attrId = getattr(self.item, attrName, None) if attrId is not None: try: attrValue = self.attributes[attrId] except KeyError: attrValue = None else: attrValue = None return attrValue