Browse Source

remove intentions

Bastien Sevajol 7 years ago
parent
commit
a44c13cc15
2 changed files with 23 additions and 4 deletions
  1. 8 0
      synergine2/simulation.py
  2. 15 4
      synergine2_xyz/move/simulation.py

+ 8 - 0
synergine2/simulation.py View File

31
         # TODO: Raise specialised exception if KeyError
31
         # TODO: Raise specialised exception if KeyError
32
         return self.intentions[intention_type]
32
         return self.intentions[intention_type]
33
 
33
 
34
+    def remove(self, intention_type: typing.Type[Intention]) -> None:
35
+        intentions = self.intentions
36
+        del self.intentions[intention_type]
37
+        self.intentions = intentions
38
+
39
+    def remove_all(self) -> None:
40
+        self.intentions = {}
41
+
34
 
42
 
35
 class Subject(IdentifiedObject):
43
 class Subject(IdentifiedObject):
36
     start_collections = []
44
     start_collections = []

+ 15 - 4
synergine2_xyz/move/simulation.py View File

94
             }
94
             }
95
 
95
 
96
         except IndexError:  # TODO: Specialize ? No movement left
96
         except IndexError:  # TODO: Specialize ? No movement left
97
-            return None
97
+            return {
98
+                'finished': True,
99
+            }
98
         except KeyError:  # TODO: Specialize ? No MoveIntention
100
         except KeyError:  # TODO: Specialize ? No MoveIntention
99
             return None
101
             return None
100
 
102
 
156
     def run(self, data):
158
     def run(self, data):
157
         move_to_data = data[self.move_to_mechanism]
159
         move_to_data = data[self.move_to_mechanism]
158
         if move_to_data:
160
         if move_to_data:
161
+            if move_to_data.get('finished'):
162
+                return move_to_data
159
 
163
 
160
             if self._can_move_to_next_step(move_to_data):
164
             if self._can_move_to_next_step(move_to_data):
161
                 move_to_data['reach_next'] = True
165
                 move_to_data['reach_next'] = True
174
         return move_to_data['just_reach'] or move_to_data['initial']
178
         return move_to_data['just_reach'] or move_to_data['initial']
175
 
179
 
176
     def action(self, data) -> [Event]:
180
     def action(self, data) -> [Event]:
177
-        new_path = data['new_path']
178
         # TODO: MoveToIntention doit être configurable
181
         # TODO: MoveToIntention doit être configurable
179
-        move = self.subject.intentions.get(MoveToIntention)
180
-        move = typing.cast(MoveToIntention, move)
182
+        try:
183
+            if data.get('finished'):
184
+                self.subject.intentions.remove(MoveToIntention)
185
+                return []
186
+            move = self.subject.intentions.get(MoveToIntention)
187
+        except KeyError:  # TODO: Specialize exception
188
+            # Action don't exist anymore
189
+            return []
181
 
190
 
191
+        move = typing.cast(MoveToIntention, move)
192
+        new_path = data['new_path']
182
         if new_path:
193
         if new_path:
183
             move.path = new_path
194
             move.path = new_path
184
             move.path_progression = -1
195
             move.path_progression = -1