def __init__(self): self._restrictionTracker = RestrictionTracker(self) self.__ship = None self.__character = None self.items = HolderContainer(self) self.drones = HolderContainer(self)
class Fit: def __init__(self): self._restrictionTracker = RestrictionTracker(self) self.__ship = None self.__character = None self.items = HolderContainer(self) self.drones = HolderContainer(self) @property def ship(self): return self.__ship @ship.setter def ship(self, ship): if self.__ship is not None: self._removeHolder(self.__ship) self.__ship = ship if ship is not None: self._addHolder(self.__ship) @property def character(self): return self.__character @character.setter def character(self, character): if self.__character is not None: self._removeHolder(self.__character) self.__character = character if character is not None: self._addHolder(self.__character) def _addHolder(self, holder): if holder.fit is not None: raise Exception holder.fit = self enabledStates = set(filter(lambda s: s <= holder.state, State)) self._restrictionTracker.enableStates(holder, enabledStates) def _removeHolder(self, holder): if holder.fit is not self: raise Exception disabledStates = set(filter(lambda s: s <= holder.state, State)) self._restrictionTracker.disableStates(holder, disabledStates) holder.fit = None def _holderStateSwitch(self, holder, newState): enabledStates = set(filter(lambda s: s > holder.state and s <= newState, State)) disabledStates = set(filter(lambda s: s > newState and s <= holder.state, State)) self._restrictionTracker.enableStates(holder, enabledStates) self._restrictionTracker.disableStates(holder, disabledStates) def getRestrictionError(self, holder, restriction): try: self._restrictionTracker.validate() except ValidationError as e: errorData = e.args[0] if not holder in errorData: return None holderError = errorData[holder] if not restriction in holderError: return None return holderError[restriction] else: return None
class Fit: def __init__(self): self._restrictionTracker = RestrictionTracker(self) self.__ship = None self.__character = None self.items = HolderContainer(self) self.drones = HolderContainer(self) @property def ship(self): return self.__ship @ship.setter def ship(self, ship): if self.__ship is not None: self._removeHolder(self.__ship) self.__ship = ship if ship is not None: self._addHolder(self.__ship) @property def character(self): return self.__character @character.setter def character(self, character): if self.__character is not None: self._removeHolder(self.__character) self.__character = character if character is not None: self._addHolder(self.__character) def _addHolder(self, holder): if holder.fit is not None: raise Exception holder.fit = self enabledStates = set(filter(lambda s: s <= holder.state, State)) self._restrictionTracker.enableStates(holder, enabledStates) def _removeHolder(self, holder): if holder.fit is not self: raise Exception disabledStates = set(filter(lambda s: s <= holder.state, State)) self._restrictionTracker.disableStates(holder, disabledStates) holder.fit = None def _holderStateSwitch(self, holder, newState): enabledStates = set(filter(lambda s: s > holder.state and s <= newState, State)) disabledStates = set(filter(lambda s: s > newState and s <= holder.state, State)) self._restrictionTracker.enableStates(holder, enabledStates) self._restrictionTracker.disableStates(holder, disabledStates) def getRestrictionError(self, holder, restriction): try: self._restrictionTracker.validate(()) except ValidationError as e: errorData = e.args[0] if not holder in errorData: return None holderError = errorData[holder] if not restriction in holderError: return None return holderError[restriction] else: return None