|
1
|
|
|
from intelligine.core.exceptions import UnableToFoundMovement, MovementModeExpired |
|
2
|
|
|
from intelligine.synergy.event.move.direction import get_position_with_direction_decal |
|
3
|
|
|
from intelligine.shorcut.brain import get_brain_part |
|
4
|
|
|
from synergine.core.exceptions import NotConcernedEvent |
|
5
|
|
|
from intelligine.synergy.event.Event import Event |
|
6
|
|
|
from synergine.core.simulation.mechanism.Mechanism import Mechanism |
|
7
|
|
|
from intelligine.cst import COL_WALKER, BRAIN_SCHEMA, BRAIN_PART_MOVE |
|
8
|
|
|
from synergine_xyz.cst import POSITION |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class MoveEvent(Event): |
|
12
|
|
|
|
|
13
|
|
|
PARAM_POSITION = 'pos' |
|
14
|
|
|
PARAM_DIRECTION = 'dir' |
|
15
|
|
|
PARAM_NEW_MODE = 'mod' |
|
16
|
|
|
|
|
17
|
|
|
_mechanism = Mechanism |
|
18
|
|
|
_concern = COL_WALKER |
|
19
|
|
|
|
|
20
|
|
|
def _prepare(self, object_id, context, parameters={}): |
|
21
|
|
|
try: |
|
22
|
|
|
direction = self._get_direction(object_id, context) |
|
23
|
|
|
except UnableToFoundMovement: |
|
24
|
|
|
raise NotConcernedEvent() |
|
25
|
|
|
except MovementModeExpired as movement_expired: |
|
26
|
|
|
parameters[self.PARAM_NEW_MODE] = movement_expired.get_switch_to_mode() |
|
27
|
|
|
return parameters |
|
28
|
|
|
|
|
29
|
|
|
object_point = context.metas.value.get(POSITION, object_id) |
|
30
|
|
|
move_to_point = get_position_with_direction_decal(direction, object_point) |
|
31
|
|
|
# TODO: future: c le brain qui calcule ou aller, et donc si c possible |
|
32
|
|
|
if self._direction_point_is_possible(context, move_to_point): |
|
33
|
|
|
parameters[self.PARAM_POSITION] = move_to_point |
|
34
|
|
|
parameters[self.PARAM_DIRECTION] = direction |
|
35
|
|
|
# TODO: Sinon lever un NotConcernedEvent |
|
36
|
|
|
return parameters |
|
37
|
|
|
|
|
38
|
|
|
def _get_direction(self, object_id, context): |
|
39
|
|
|
object_move_brain_part = get_brain_part(context, object_id, BRAIN_PART_MOVE) |
|
40
|
|
|
return object_move_brain_part.get_direction(context, object_id) |
|
41
|
|
|
|
|
42
|
|
|
@staticmethod |
|
43
|
|
|
def _direction_point_is_possible(context, direction_point): |
|
44
|
|
|
return context.position_is_penetrable(direction_point) |
|
45
|
|
|
|