Browse Source

clean code

Bastien Sevajol 9 years ago
parent
commit
ac91025137

+ 3 - 1
intelligine/simulation/object/brain/part/BrainPart.py View File

2
 
2
 
3
     def __init__(self, host_brain):
3
     def __init__(self, host_brain):
4
         self._host_brain = host_brain
4
         self._host_brain = host_brain
5
+        self._context = self._host_brain.get_context()
6
+        self._host = self._host_brain.get_host()
5
 
7
 
6
     def get_host_brain(self):
8
     def get_host_brain(self):
7
         return self._host_brain
9
         return self._host_brain
9
     def get_host(self):
11
     def get_host(self):
10
         return self.get_host_brain().get_host()
12
         return self.get_host_brain().get_host()
11
 
13
 
12
-    def done(self, obj, context):
14
+    def done(self):
13
         pass
15
         pass

+ 18 - 20
intelligine/simulation/object/brain/part/move/AntMoveBrainPart.py View File

3
 from intelligine.simulation.object.brain.part.move.MoveBrainPart import MoveBrainPart
3
 from intelligine.simulation.object.brain.part.move.MoveBrainPart import MoveBrainPart
4
 from intelligine.synergy.event.move.direction import directions_modifiers, get_position_with_direction_decal
4
 from intelligine.synergy.event.move.direction import directions_modifiers, get_position_with_direction_decal
5
 from synergine_xyz.cst import POSITION
5
 from synergine_xyz.cst import POSITION
6
-from intelligine.core.exceptions import NoMolecule, NoTypeInMolecule
6
+from intelligine.core.exceptions import NoMolecule
7
 from intelligine.cst import MOLECULE_SEARCHING, MOVE_MODE_EXPLO, MOVE_MODE_HOME, MOVE_MODE, MOVE_MODE_GOHOME, \
7
 from intelligine.cst import MOLECULE_SEARCHING, MOVE_MODE_EXPLO, MOVE_MODE_HOME, MOVE_MODE, MOVE_MODE_GOHOME, \
8
     EXPLORATION_VECTOR, MOLECULES_DIRECTION, SMELL_FOOD, SMELL_EGG
8
     EXPLORATION_VECTOR, MOLECULES_DIRECTION, SMELL_FOOD, SMELL_EGG
9
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
9
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
17
 
17
 
18
     def _set_exploration_vector(self, new_vector):
18
     def _set_exploration_vector(self, new_vector):
19
         self._exploration_vector = new_vector
19
         self._exploration_vector = new_vector
20
-        # TODO: On devrais donner le context aux brain parts
21
-        self._host_brain.get_context().metas.value.set(EXPLORATION_VECTOR,
22
-                                                       self._host_brain.get_host().get_id(),
23
-                                                       new_vector)
20
+        self._context.metas.value.set(EXPLORATION_VECTOR,
21
+                                      self._host_brain.get_host().get_id(),
22
+                                      new_vector)
24
 
23
 
25
     @classmethod
24
     @classmethod
26
     def get_direction(cls, context, object_id):
25
     def get_direction(cls, context, object_id):
79
         return ByPass(ant_host, home_vector, context, object_id)
78
         return ByPass(ant_host, home_vector, context, object_id)
80
 
79
 
81
     # TODO: obj pas necessaire, il est dans _host
80
     # TODO: obj pas necessaire, il est dans _host
82
-    def done(self, obj, context):
83
-        super().done(obj, context)
84
-        self._appose_molecule(obj)
85
-        self._check_context(obj, context)
86
-        self._apply_context(obj, context)
81
+    def done(self):
82
+        super().done()
83
+        self._appose_molecule()
84
+        self._check_context()
85
+        self._apply_context()
87
 
86
 
88
-    @staticmethod
89
-    def _appose_molecule(obj):
90
-        if obj.get_movement_molecule_gland().is_enabled():
91
-            obj.get_movement_molecule_gland().appose()
87
+    def _appose_molecule(self):
88
+        if self._host.get_movement_molecule_gland().is_enabled():
89
+            self._host.get_movement_molecule_gland().appose()
92
 
90
 
93
-    def _check_context(self, obj, context):
91
+    def _check_context(self):
94
         """
92
         """
95
 
93
 
96
         If was in exploration, and just found home smell;
94
         If was in exploration, and just found home smell;
104
         """
102
         """
105
         movement_mode = self._host_brain.get_movement_mode()
103
         movement_mode = self._host_brain.get_movement_mode()
106
 
104
 
107
-        if movement_mode == MOVE_MODE_GOHOME and self._on_home_smell(context, obj.get_id()):
105
+        if movement_mode == MOVE_MODE_GOHOME and self._on_home_smell(self._context, self._host.get_id()):
108
             self._host_brain.switch_to_mode(MOVE_MODE_HOME)
106
             self._host_brain.switch_to_mode(MOVE_MODE_HOME)
109
-            ant_star = self._get_by_pass_brain(context, obj.get_id())
107
+            ant_star = self._get_by_pass_brain(self._context, self._host.get_id())
110
             ant_star.erase()
108
             ant_star.erase()
111
             # TODO: on change les molecule recherché (Food => SmellFood, definis dans Take, en fct de ce qui est take)
109
             # TODO: on change les molecule recherché (Food => SmellFood, definis dans Take, en fct de ce qui est take)
112
 
110
 
113
-        elif movement_mode == MOVE_MODE_HOME and not self._on_home_smell(context, obj.get_id()):
111
+        elif movement_mode == MOVE_MODE_HOME and not self._on_home_smell(self._context, self._host.get_id()):
114
             self._host_brain.switch_to_mode(MOVE_MODE_EXPLO)
112
             self._host_brain.switch_to_mode(MOVE_MODE_EXPLO)
115
             self._start_new_exploration()
113
             self._start_new_exploration()
116
 
114
 
117
-        elif movement_mode == MOVE_MODE_EXPLO and self._on_home_smell(context, obj.get_id()):
115
+        elif movement_mode == MOVE_MODE_EXPLO and self._on_home_smell(self._context, self._host.get_id()):
118
             self._start_new_exploration()  # TODO: rename en reinit_explo
116
             self._start_new_exploration()  # TODO: rename en reinit_explo
119
 
117
 
120
         # TODO: sitch explo si rien a faire (rien a poser par exemple) et HOME
118
         # TODO: sitch explo si rien a faire (rien a poser par exemple) et HOME
140
         self._set_exploration_vector((self._exploration_vector[0] + just_move_vector[1],
138
         self._set_exploration_vector((self._exploration_vector[0] + just_move_vector[1],
141
                                       self._exploration_vector[1] + just_move_vector[2]))
139
                                       self._exploration_vector[1] + just_move_vector[2]))
142
 
140
 
143
-    def _apply_context(self, obj, context):
141
+    def _apply_context(self):
144
         movement_mode = self._host_brain.get_movement_mode()
142
         movement_mode = self._host_brain.get_movement_mode()
145
         if movement_mode == MOVE_MODE_EXPLO or movement_mode == MOVE_MODE_GOHOME:
143
         if movement_mode == MOVE_MODE_EXPLO or movement_mode == MOVE_MODE_GOHOME:
146
             self._update_exploration_vector()
144
             self._update_exploration_vector()

+ 2 - 2
intelligine/simulation/object/brain/part/transport/AntPutBrainPart.py View File

61
             return True
61
             return True
62
         return False
62
         return False
63
 
63
 
64
-    def done(self, obj, puted_object, context):
64
+    def done(self, puted_object):
65
         # TODO: Il faut refact/logique qqpart pour ca !! Genre Brain.done(PUT, ??)
65
         # TODO: Il faut refact/logique qqpart pour ca !! Genre Brain.done(PUT, ??)
66
         if isinstance(puted_object, Food):
66
         if isinstance(puted_object, Food):
67
             # TODO: Quel mode ? On vient de poser (ps forcement dans la colonie) cls._mode_swicth ?
67
             # TODO: Quel mode ? On vient de poser (ps forcement dans la colonie) cls._mode_swicth ?
68
-            obj.get_brain().switch_to_mode(MOVE_MODE_EXPLO)
68
+            self._host.get_brain().switch_to_mode(MOVE_MODE_EXPLO)
69
             # TODO: TEST Depose au -1 pour des raisons de test. Plus tard ce sera des tas comme un autre !
69
             # TODO: TEST Depose au -1 pour des raisons de test. Plus tard ce sera des tas comme un autre !
70
             puted_object.set_position((-1, 0, 0))
70
             puted_object.set_position((-1, 0, 0))
71
 
71
 

+ 3 - 3
intelligine/simulation/object/brain/part/transport/AntTakeBrainPart.py View File

27
         # Pour le moment si le type de l'objet fait partie des types admis pour le mode courant du porteur, c'est bon.
27
         # Pour le moment si le type de l'objet fait partie des types admis pour le mode courant du porteur, c'est bon.
28
         return cls._match_with_mode(context, object_id, object_to_take_id)
28
         return cls._match_with_mode(context, object_id, object_to_take_id)
29
 
29
 
30
-    def done(self, obj, take_object, context):
30
+    def done(self, take_object):
31
         # TODO: Ranger ca ? Truc plus dynamique/configurable ?
31
         # TODO: Ranger ca ? Truc plus dynamique/configurable ?
32
         # TODO: qqch plus generique ... (attention aux eggs)
32
         # TODO: qqch plus generique ... (attention aux eggs)
33
         if isinstance(take_object, Resource):
33
         if isinstance(take_object, Resource):
34
             self._smell_target = self._host_brain.get_smell_for_object_taken(take_object)
34
             self._smell_target = self._host_brain.get_smell_for_object_taken(take_object)
35
-            obj.get_brain().switch_to_mode(MOVE_MODE_GOHOME)
36
-            obj.get_movement_molecule_gland().appose()
35
+            self._host.get_brain().switch_to_mode(MOVE_MODE_GOHOME)
36
+            self._host.get_movement_molecule_gland().appose()

+ 1 - 1
intelligine/synergy/event/move/MoveAction.py View File

29
 
29
 
30
         obj.set_position(self._parameters[MoveEvent.PARAM_POSITION])
30
         obj.set_position(self._parameters[MoveEvent.PARAM_POSITION])
31
         obj.set_previous_direction(self._parameters[MoveEvent.PARAM_DIRECTION])
31
         obj.set_previous_direction(self._parameters[MoveEvent.PARAM_DIRECTION])
32
-        obj.get_brain().get_part(BRAIN_PART_MOVE).done(obj, context)
32
+        obj.get_brain().get_part(BRAIN_PART_MOVE).done()

+ 1 - 1
intelligine/synergy/event/transport/PutableAction.py View File

21
         obj.put_carry(obj_transported, position_to_put)
21
         obj.put_carry(obj_transported, position_to_put)
22
         context.metas.value.set(CANT_CARRY_STILL, obj.get_id(), 5)
22
         context.metas.value.set(CANT_CARRY_STILL, obj.get_id(), 5)
23
 
23
 
24
-        obj.get_brain().get_part(BRAIN_PART_PUT).done(obj, obj_transported, context)
24
+        obj.get_brain().get_part(BRAIN_PART_PUT).done(obj_transported)

+ 1 - 1
intelligine/synergy/event/transport/TakeableAction.py View File

26
         obj.carry(obj_carried)
26
         obj.carry(obj_carried)
27
         cant_put_still = Core.get_configuration_manager().get('ant.take.cant_put_still')
27
         cant_put_still = Core.get_configuration_manager().get('ant.take.cant_put_still')
28
         context.metas.value.set(CANT_PUT_STILL, obj.get_id(), cant_put_still)
28
         context.metas.value.set(CANT_PUT_STILL, obj.get_id(), cant_put_still)
29
-        obj.get_brain().get_part(BRAIN_PART_TAKE).done(obj, obj_carried, context)
29
+        obj.get_brain().get_part(BRAIN_PART_TAKE).done(obj_carried)