Bastien Sevajol 3 years ago
parent
commit
dd703ca2e0
6 changed files with 48 additions and 11 deletions
  1. 20 3
      src/behavior/animate.rs
  2. 3 2
      src/behavior/mod.rs
  3. 2 0
      src/behavior/order.rs
  4. 3 2
      src/scene/item.rs
  5. 18 4
      src/scene/main.rs
  6. 2 0
      src/ui/mod.rs

+ 20 - 3
src/behavior/animate.rs View File

13
             Order::MoveTo(_) => {
13
             Order::MoveTo(_) => {
14
                 scene_item_modifiers.push(SceneItemModifier::SwitchToCurrentOrder);
14
                 scene_item_modifiers.push(SceneItemModifier::SwitchToCurrentOrder);
15
             }
15
             }
16
+            Order::MoveFastTo(_) => {
17
+                scene_item_modifiers.push(SceneItemModifier::SwitchToCurrentOrder)
18
+            }
19
+            Order::HideTo(_) => {
20
+                scene_item_modifiers.push(SceneItemModifier::SwitchToCurrentOrder)
21
+            }
16
         }
22
         }
17
     }
23
     }
18
 
24
 
26
     if let Some(current_order) = &scene_item.current_order {
32
     if let Some(current_order) = &scene_item.current_order {
27
         match current_order {
33
         match current_order {
28
             Order::MoveTo(move_to_scene_point) => {
34
             Order::MoveTo(move_to_scene_point) => {
35
+                // FIXME BS NOW: Change order only if it is not the current order
29
                 scene_item_modifiers.push(SceneItemModifier::ChangeState(ItemState::new(
36
                 scene_item_modifiers.push(SceneItemModifier::ChangeState(ItemState::new(
30
-                    ItemBehavior::WalkingTo(*move_to_scene_point),
37
+                    ItemBehavior::MoveTo(*move_to_scene_point),
31
                 )))
38
                 )))
32
             }
39
             }
40
+            Order::MoveFastTo(move_to_scene_point) => {
41
+                // FIXME BS NOW: Change order only if it is not the current order
42
+                scene_item_modifiers.push(SceneItemModifier::ChangeState(ItemState::new(
43
+                    ItemBehavior::MoveFastTo(*move_to_scene_point),
44
+                )))}
45
+            Order::HideTo(move_to_scene_point) => {
46
+                // FIXME BS NOW: Change order only if it is not the current order
47
+                scene_item_modifiers.push(SceneItemModifier::ChangeState(ItemState::new(
48
+                    ItemBehavior::HideTo(*move_to_scene_point),
49
+                )))}
33
         }
50
         }
34
     }
51
     }
35
 
52
 
41
 
58
 
42
     match scene_item.state.current_behavior {
59
     match scene_item.state.current_behavior {
43
         ItemBehavior::Standing => {}
60
         ItemBehavior::Standing => {}
44
-        ItemBehavior::WalkingTo(going_to_scene_point)
45
-        | ItemBehavior::CrawlingTo(going_to_scene_point) => {
61
+        ItemBehavior::MoveTo(going_to_scene_point)
62
+        | ItemBehavior::HideTo(going_to_scene_point) => {
46
             // Note: angle computed by adding FRAC_PI_2 because sprites are north oriented
63
             // Note: angle computed by adding FRAC_PI_2 because sprites are north oriented
47
             scene_item_modifiers.push(SceneItemModifier::ChangeDisplayAngle(
64
             scene_item_modifiers.push(SceneItemModifier::ChangeDisplayAngle(
48
                 f32::atan2(
65
                 f32::atan2(

+ 3 - 2
src/behavior/mod.rs View File

5
 
5
 
6
 pub enum ItemBehavior {
6
 pub enum ItemBehavior {
7
     Standing, // since
7
     Standing, // since
8
-    CrawlingTo(ScenePoint),
9
-    WalkingTo(ScenePoint),
8
+    HideTo(ScenePoint),
9
+    MoveTo(ScenePoint),
10
+    MoveFastTo(ScenePoint),
10
 }
11
 }

+ 2 - 0
src/behavior/order.rs View File

3
 #[derive(Clone)]
3
 #[derive(Clone)]
4
 pub enum Order {
4
 pub enum Order {
5
     MoveTo(ScenePoint),
5
     MoveTo(ScenePoint),
6
+    MoveFastTo(ScenePoint),
7
+    HideTo(ScenePoint),
6
 }
8
 }

+ 3 - 2
src/scene/item.rs View File

111
         // Here some logical about state, nature (soldier, tank, ...) and current behavior to
111
         // Here some logical about state, nature (soldier, tank, ...) and current behavior to
112
         // determine sprite type
112
         // determine sprite type
113
         match self.state.current_behavior {
113
         match self.state.current_behavior {
114
-            ItemBehavior::CrawlingTo(_) => SpriteType::CrawlingSoldier,
115
-            ItemBehavior::WalkingTo(_) => SpriteType::WalkingSoldier,
114
+            ItemBehavior::HideTo(_) => SpriteType::CrawlingSoldier,
115
+            ItemBehavior::MoveTo(_) => SpriteType::WalkingSoldier,
116
+            ItemBehavior::MoveFastTo(_) => SpriteType::WalkingSoldier,
116
             ItemBehavior::Standing => SpriteType::StandingSoldier,
117
             ItemBehavior::Standing => SpriteType::StandingSoldier,
117
         }
118
         }
118
     }
119
     }

+ 18 - 4
src/scene/main.rs View File

174
         }
174
         }
175
 
175
 
176
         if let Some(scene_item_prepare_order) = &self.scene_item_prepare_order {
176
         if let Some(scene_item_prepare_order) = &self.scene_item_prepare_order {
177
-            // TODO: Add order to scene_item
178
             match scene_item_prepare_order {
177
             match scene_item_prepare_order {
179
                 SceneItemPrepareOrder::Move(scene_item_usize) => {
178
                 SceneItemPrepareOrder::Move(scene_item_usize) => {
180
                     let mut scene_item = self.get_scene_item_mut(*scene_item_usize);
179
                     let mut scene_item = self.get_scene_item_mut(*scene_item_usize);
181
                     scene_item.next_order = Some(Order::MoveTo(scene_click_point));
180
                     scene_item.next_order = Some(Order::MoveTo(scene_click_point));
182
                 }
181
                 }
182
+                SceneItemPrepareOrder::MoveFast(scene_item_usize) => {
183
+                    let mut scene_item = self.get_scene_item_mut(*scene_item_usize);
184
+                    scene_item.next_order = Some(Order::MoveFastTo(scene_click_point));
185
+                }
186
+                SceneItemPrepareOrder::Hide(scene_item_usize) => {
187
+                    let mut scene_item = self.get_scene_item_mut(*scene_item_usize);
188
+                    scene_item.next_order = Some(Order::HideTo(scene_click_point));}
183
             }
189
             }
184
 
190
 
185
             self.scene_item_prepare_order = None;
191
             self.scene_item_prepare_order = None;
197
                             Some(SceneItemPrepareOrder::Move(scene_item_usize));
203
                             Some(SceneItemPrepareOrder::Move(scene_item_usize));
198
                         self.scene_item_menu = None;
204
                         self.scene_item_menu = None;
199
                     }
205
                     }
200
-                    MenuItem::MoveFast => {}
201
-                    MenuItem::Hide => {}
206
+                    MenuItem::MoveFast => {
207
+                        self.scene_item_prepare_order =
208
+                            Some(SceneItemPrepareOrder::MoveFast(scene_item_usize));
209
+                        self.scene_item_menu = None;
210
+                    }
211
+                    MenuItem::Hide => {
212
+                        self.scene_item_prepare_order =
213
+                            Some(SceneItemPrepareOrder::Hide(scene_item_usize));
214
+                        self.scene_item_menu = None;
215
+                    }
202
                 }
216
                 }
203
             };
217
             };
204
             self.scene_item_menu = None;
218
             self.scene_item_menu = None;
241
         // Scene items movements
255
         // Scene items movements
242
         for scene_item in self.scene_items.iter_mut() {
256
         for scene_item in self.scene_items.iter_mut() {
243
             match scene_item.state.current_behavior {
257
             match scene_item.state.current_behavior {
244
-                ItemBehavior::WalkingTo(scene_point) => {
258
+                ItemBehavior::MoveTo(scene_point) => {
245
                     // FIXME BS NOW: velocity
259
                     // FIXME BS NOW: velocity
246
                     let move_vector = (scene_point - scene_item.position).normalize() * 1.0;
260
                     let move_vector = (scene_point - scene_item.position).normalize() * 1.0;
247
                     // TODO ici il faut calculer le déplacement réél (en fonction des ticks, etc ...)
261
                     // TODO ici il faut calculer le déplacement réél (en fonction des ticks, etc ...)

+ 2 - 0
src/ui/mod.rs View File

23
 
23
 
24
 pub enum SceneItemPrepareOrder {
24
 pub enum SceneItemPrepareOrder {
25
     Move(usize), // scene_item usize
25
     Move(usize), // scene_item usize
26
+    MoveFast(usize), // scene_item usize
27
+    Hide(usize), // scene_item usize
26
 }
28
 }
27
 
29
 
28
 #[derive(Clone)]
30
 #[derive(Clone)]