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,6 +13,12 @@ pub fn digest_next_order(scene_item: &SceneItem) -> Vec<SceneItemModifier> {
13 13
             Order::MoveTo(_) => {
14 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,10 +32,21 @@ pub fn digest_current_order(scene_item: &SceneItem) -> Vec<SceneItemModifier> {
26 32
     if let Some(current_order) = &scene_item.current_order {
27 33
         match current_order {
28 34
             Order::MoveTo(move_to_scene_point) => {
35
+                // FIXME BS NOW: Change order only if it is not the current order
29 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,8 +58,8 @@ pub fn digest_current_behavior(scene_item: &SceneItem) -> Vec<SceneItemModifier>
41 58
 
42 59
     match scene_item.state.current_behavior {
43 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 63
             // Note: angle computed by adding FRAC_PI_2 because sprites are north oriented
47 64
             scene_item_modifiers.push(SceneItemModifier::ChangeDisplayAngle(
48 65
                 f32::atan2(

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

@@ -5,6 +5,7 @@ use crate::ScenePoint;
5 5
 
6 6
 pub enum ItemBehavior {
7 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,4 +3,6 @@ use crate::ScenePoint;
3 3
 #[derive(Clone)]
4 4
 pub enum Order {
5 5
     MoveTo(ScenePoint),
6
+    MoveFastTo(ScenePoint),
7
+    HideTo(ScenePoint),
6 8
 }

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

@@ -111,8 +111,9 @@ impl SceneItem {
111 111
         // Here some logical about state, nature (soldier, tank, ...) and current behavior to
112 112
         // determine sprite type
113 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 117
             ItemBehavior::Standing => SpriteType::StandingSoldier,
117 118
         }
118 119
     }

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

@@ -174,12 +174,18 @@ impl MainState {
174 174
         }
175 175
 
176 176
         if let Some(scene_item_prepare_order) = &self.scene_item_prepare_order {
177
-            // TODO: Add order to scene_item
178 177
             match scene_item_prepare_order {
179 178
                 SceneItemPrepareOrder::Move(scene_item_usize) => {
180 179
                     let mut scene_item = self.get_scene_item_mut(*scene_item_usize);
181 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 191
             self.scene_item_prepare_order = None;
@@ -197,8 +203,16 @@ impl MainState {
197 203
                             Some(SceneItemPrepareOrder::Move(scene_item_usize));
198 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 218
             self.scene_item_menu = None;
@@ -241,7 +255,7 @@ impl MainState {
241 255
         // Scene items movements
242 256
         for scene_item in self.scene_items.iter_mut() {
243 257
             match scene_item.state.current_behavior {
244
-                ItemBehavior::WalkingTo(scene_point) => {
258
+                ItemBehavior::MoveTo(scene_point) => {
245 259
                     // FIXME BS NOW: velocity
246 260
                     let move_vector = (scene_point - scene_item.position).normalize() * 1.0;
247 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,6 +23,8 @@ pub enum UserEvent {
23 23
 
24 24
 pub enum SceneItemPrepareOrder {
25 25
     Move(usize), // scene_item usize
26
+    MoveFast(usize), // scene_item usize
27
+    Hide(usize), // scene_item usize
26 28
 }
27 29
 
28 30
 #[derive(Clone)]