Browse Source

XYZ: Allow multiple objects at same position

Bastien Sevajol 7 years ago
parent
commit
e9efa887e3
2 changed files with 9 additions and 9 deletions
  1. 5 5
      sandbox/engulf/simulation.py
  2. 4 4
      synergine2/xyz.py

+ 5 - 5
sandbox/engulf/simulation.py View File

19
 
19
 
20
         if isinstance(value, Cell):
20
         if isinstance(value, Cell):
21
             try:
21
             try:
22
-                del self.cell_xyz[value.position]
23
-            except KeyError:
24
-                pass  # TODO: cE DICT DOIT CONTENIR DES LISTES DE SUBJECTS
22
+                self.cell_xyz.get(value.position, []).remove(value)
23
+            except ValueError:
24
+                pass
25
 
25
 
26
         if isinstance(value, Grass):
26
         if isinstance(value, Grass):
27
             del self.grass_xyz[value.position]
27
             del self.grass_xyz[value.position]
30
         super().append(p_object)
30
         super().append(p_object)
31
 
31
 
32
         if isinstance(p_object, Cell):
32
         if isinstance(p_object, Cell):
33
-            self.cell_xyz[p_object.position] = p_object
33
+            self.cell_xyz.get(p_object.position, []).append(p_object)
34
 
34
 
35
         if isinstance(p_object, Grass):
35
         if isinstance(p_object, Grass):
36
-            self.grass_xyz[p_object.position] = p_object
36
+            self.grass_xyz.get(p_object.position, []).append(p_object)
37
 
37
 
38
 
38
 
39
 class Engulf(XYZSimulation):
39
 class Engulf(XYZSimulation):

+ 4 - 4
synergine2/xyz.py View File

218
         super().remove(value)
218
         super().remove(value)
219
 
219
 
220
         try:
220
         try:
221
-            del self.xyz[value.position]
222
-        except KeyError:
223
-            pass  # TODO: cE DICT DOIT CONTENIR DES LISTES DE SUBJECTS
221
+            self.xyz.get(value.position, []).remove(value)
222
+        except ValueError:
223
+            pass
224
 
224
 
225
     def append(self, p_object: XYZSubjectMixin):
225
     def append(self, p_object: XYZSubjectMixin):
226
         super().append(p_object)
226
         super().append(p_object)
232
                 str(p_object),
232
                 str(p_object),
233
             ))
233
             ))
234
 
234
 
235
-        self.xyz[p_object.position] = p_object
235
+        self.xyz.get(p_object.position, []).append(p_object)
236
 
236
 
237
 
237
 
238
 class XYZSimulation(BaseSimulation):
238
 class XYZSimulation(BaseSimulation):