Просмотр исходного кода

XYZ: Allow multiple objects at same position

Bastien Sevajol 7 лет назад
Родитель
Сommit
e9efa887e3
2 измененных файлов: 9 добавлений и 9 удалений
  1. 5 5
      sandbox/engulf/simulation.py
  2. 4 4
      synergine2/xyz.py

+ 5 - 5
sandbox/engulf/simulation.py Просмотреть файл

@@ -19,9 +19,9 @@ class EngulfSubjects(XYZSubjects):
19 19
 
20 20
         if isinstance(value, Cell):
21 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 26
         if isinstance(value, Grass):
27 27
             del self.grass_xyz[value.position]
@@ -30,10 +30,10 @@ class EngulfSubjects(XYZSubjects):
30 30
         super().append(p_object)
31 31
 
32 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 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 39
 class Engulf(XYZSimulation):

+ 4 - 4
synergine2/xyz.py Просмотреть файл

@@ -218,9 +218,9 @@ class XYZSubjects(Subjects):
218 218
         super().remove(value)
219 219
 
220 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 225
     def append(self, p_object: XYZSubjectMixin):
226 226
         super().append(p_object)
@@ -232,7 +232,7 @@ class XYZSubjects(Subjects):
232 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 238
 class XYZSimulation(BaseSimulation):