From: Christian Heller Date: Sat, 27 Apr 2019 17:20:32 +0000 (+0200) Subject: Move re-positioning of things in inventory to Thing code. X-Git-Url: https://plomlompom.com/repos/?a=commitdiff_plain;h=52cf6eee2b83be0fedd0df716395eb715ffddebb;p=plomrogue2-experiments Move re-positioning of things in inventory to Thing code. --- diff --git a/new/plomrogue/tasks.py b/new/plomrogue/tasks.py index ae55980..330eff9 100644 --- a/new/plomrogue/tasks.py +++ b/new/plomrogue/tasks.py @@ -52,9 +52,6 @@ class Task_MOVE(Task): def do(self): self.thing.position = (0,0), self.thing.world.maps[(0,0)].\ move(self.thing.position[1], self.args[0]) - for id_ in self.thing.inventory: - t = self.thing.world.get_thing(id_) - t.position = self.thing.position diff --git a/new/plomrogue/things.py b/new/plomrogue/things.py index f020eda..13384fc 100644 --- a/new/plomrogue/things.py +++ b/new/plomrogue/things.py @@ -13,6 +13,26 @@ class ThingBase: else: self.id_ = id_ + @property + def position(self): + return self._position + + def _position_set(self, pos): + """Set self._position to pos. + + We use this setter as core to the @position.setter property + method due to property setter subclassing not yet working + properly, see . We will + therefore super() _position_set instead of @position.setter in + subclasses. + + """ + self._position = pos + + @position.setter + def position(self, pos): + self._position_set(pos) + class Thing(ThingBase): @@ -20,12 +40,18 @@ class Thing(ThingBase): in_inventory = False def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) self.inventory = [] + super().__init__(*args, **kwargs) def proceed(self): pass + def _position_set(self, pos): + super()._position_set(pos) + for t_id in self.inventory: + t = self.world.get_thing(t_id) + t.position = self.position + class ThingItem(Thing):