Browse Source

remove intentions

Bastien Sevajol 6 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,6 +31,14 @@ class IntentionManager(object):
31 31
         # TODO: Raise specialised exception if KeyError
32 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 43
 class Subject(IdentifiedObject):
36 44
     start_collections = []

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

@@ -94,7 +94,9 @@ class MoveToMechanism(SubjectMechanism):
94 94
             }
95 95
 
96 96
         except IndexError:  # TODO: Specialize ? No movement left
97
-            return None
97
+            return {
98
+                'finished': True,
99
+            }
98 100
         except KeyError:  # TODO: Specialize ? No MoveIntention
99 101
             return None
100 102
 
@@ -156,6 +158,8 @@ class MoveToBehaviour(SubjectBehaviour):
156 158
     def run(self, data):
157 159
         move_to_data = data[self.move_to_mechanism]
158 160
         if move_to_data:
161
+            if move_to_data.get('finished'):
162
+                return move_to_data
159 163
 
160 164
             if self._can_move_to_next_step(move_to_data):
161 165
                 move_to_data['reach_next'] = True
@@ -174,11 +178,18 @@ class MoveToBehaviour(SubjectBehaviour):
174 178
         return move_to_data['just_reach'] or move_to_data['initial']
175 179
 
176 180
     def action(self, data) -> [Event]:
177
-        new_path = data['new_path']
178 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 193
         if new_path:
183 194
             move.path = new_path
184 195
             move.path_progression = -1