home · contact · privacy
Move re-positioning of things in inventory to Thing code.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 27 Apr 2019 17:20:32 +0000 (19:20 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 27 Apr 2019 17:20:32 +0000 (19:20 +0200)
new/plomrogue/tasks.py
new/plomrogue/things.py

index ae559800f5f931769f6861cae5a652a8ffd6987b..330eff9b158e41357adbaa91bc207087af0d13c0 100644 (file)
@@ -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])
     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
 
 
 
 
 
 
index f020edae3d4f0cafe3f77d2ed0de252c3aa2553f..13384fc76935d14e328287a34a0716805b75fe6d 100644 (file)
@@ -13,6 +13,26 @@ class ThingBase:
         else:
             self.id_ = id_
 
         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 <https://bugs.python.org/issue14965>. 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):
 
 
 class Thing(ThingBase):
@@ -20,12 +40,18 @@ class Thing(ThingBase):
     in_inventory = False
 
     def __init__(self, *args, **kwargs):
     in_inventory = False
 
     def __init__(self, *args, **kwargs):
-        super().__init__(*args, **kwargs)
         self.inventory = []
         self.inventory = []
+        super().__init__(*args, **kwargs)
 
     def proceed(self):
         pass
 
 
     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):
 
 
 class ThingItem(Thing):