From ff2f897520704adacc8287b3499167bbcf56deb8 Mon Sep 17 00:00:00 2001
From: Tom Barrett <tom@tombarrett.xyz>
Date: Thu, 17 Nov 2022 21:15:30 +0100
Subject: for version 9

---
 src/cell.rs |  8 ++++----
 src/main.rs | 50 ++++++++++++++++++++++++++++----------------------
 2 files changed, 32 insertions(+), 26 deletions(-)

(limited to 'src')

diff --git a/src/cell.rs b/src/cell.rs
index 6a818c5..7c2385d 100644
--- a/src/cell.rs
+++ b/src/cell.rs
@@ -12,9 +12,9 @@ pub struct AnimationTimer {
 }
 
 impl AnimationTimer {
-    pub fn from_seconds(duration: f32, repeating: bool) -> AnimationTimer {
+    pub fn from_seconds(duration: f32, mode: TimerMode) -> AnimationTimer {
         AnimationTimer {
-            timer: Timer::from_seconds(duration, repeating),
+            timer: Timer::from_seconds(duration, mode),
         }
     }
 
@@ -39,7 +39,7 @@ impl AnimationTimer {
     }
 
     pub fn repeating(&self) -> bool {
-        self.timer.repeating()
+        self.timer.mode() == TimerMode::Repeating
     }
 }
 
@@ -139,7 +139,7 @@ pub fn start_explosion(
         if cell.occupant == Occupant::Explosion {
             commands
                 .entity(entity)
-                .insert(AnimationTimer::from_seconds(0.1, true));
+                .insert(AnimationTimer::from_seconds(0.1, TimerMode::Repeating));
         }
     }
 }
diff --git a/src/main.rs b/src/main.rs
index 0c7f92e..e958c16 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,5 @@
 use bevy::math::Vec3;
 use bevy::prelude::*;
-use bevy::render::texture::ImageSettings;
 use gems::cell::{self, AnimationTimer, Cell, Occupant};
 use gems::constants;
 use rand::{thread_rng, Rng};
@@ -18,7 +17,7 @@ fn star_spawning(
                 timer.set_duration(Duration::new(thread_rng().gen_range(2..5), 0));
                 timer.reset();
                 commands
-                    .spawn_bundle(SpriteSheetBundle {
+                    .spawn(SpriteSheetBundle {
                         sprite: TextureAtlasSprite::new(constants::TILESHEET_STAR1),
                         texture_atlas: texture_atlas_handle.clone(),
                         transform: Transform {
@@ -32,7 +31,7 @@ fn star_spawning(
                         },
                         ..Default::default()
                     })
-                    .insert(AnimationTimer::from_seconds(0.15, true));
+                    .insert(AnimationTimer::from_seconds(0.15, TimerMode::Once));
             }
         }
     }
@@ -52,11 +51,13 @@ pub fn setup(
         Vec2::new(constants::TILE_SIZE, constants::TILE_SIZE),
         5,
         5,
+        None,
+        None,
     );
     let atlas_handle = texture_atlases.add(atlas);
 
-    commands.spawn_bundle(Camera2dBundle::default());
-    commands.spawn_bundle(SpriteBundle {
+    commands.spawn(Camera2dBundle::default());
+    commands.spawn(SpriteBundle {
         texture: background,
         transform: Transform {
             translation: Vec3::new(50.0, 0.0, 0.0),
@@ -65,7 +66,7 @@ pub fn setup(
         },
         ..Default::default()
     });
-    commands.spawn_bundle(SpriteBundle {
+    commands.spawn(SpriteBundle {
         texture: title,
         transform: Transform {
             translation: Vec3::new(240.0, 200.0, 0.2),
@@ -74,7 +75,7 @@ pub fn setup(
         },
         ..Default::default()
     });
-    commands.spawn_bundle(SpriteSheetBundle {
+    commands.spawn(SpriteSheetBundle {
         sprite: TextureAtlasSprite::new(constants::TILESHEET_COSMONAUT1),
         texture_atlas: atlas_handle.clone(),
         transform: Transform {
@@ -84,11 +85,11 @@ pub fn setup(
         },
         ..Default::default()
     });
-    commands.spawn_bundle((
-        AnimationTimer::from_seconds(1.0, false),
+    commands.spawn((
+        AnimationTimer::from_seconds(1.0, TimerMode::Once),
         atlas_handle.clone(),
     ));
-    commands.spawn_bundle(SpriteSheetBundle {
+    commands.spawn(SpriteSheetBundle {
         sprite: TextureAtlasSprite::new(constants::TILESHEET_COSMONAUT2),
         texture_atlas: atlas_handle.clone(),
         transform: Transform {
@@ -106,7 +107,7 @@ pub fn setup(
     for i in 0..constants::GRID_SIZE {
         for j in 0..constants::GRID_SIZE {
             commands
-                .spawn_bundle(SpriteSheetBundle {
+                .spawn(SpriteSheetBundle {
                     texture_atlas: atlas_handle.clone(),
                     visibility: Visibility { is_visible: false },
                     transform: Transform {
@@ -190,13 +191,13 @@ fn cosmonaut_detect(
                 && sprite.index == constants::TILESHEET_COSMONAUT1
             {
                 commands
-                    .spawn_bundle(SpriteSheetBundle {
+                    .spawn(SpriteSheetBundle {
                         sprite: TextureAtlasSprite::new(constants::TILESHEET_VISOR1),
                         texture_atlas: texture_atlas_handle.clone(),
                         transform: *transform,
                         ..Default::default()
                     })
-                    .insert(AnimationTimer::from_seconds(0.1, true));
+                    .insert(AnimationTimer::from_seconds(0.1, TimerMode::Repeating));
             }
         }
     }
@@ -279,15 +280,20 @@ fn mouse(
 
 pub fn main() {
     App::new()
-        .insert_resource(ImageSettings::default_nearest())
-        .insert_resource(WindowDescriptor {
-            title: "gems".to_string(),
-            width: constants::WINDOW_WIDTH,
-            height: constants::WINDOW_HEIGHT,
-            resizable: false,
-            ..Default::default()
-        })
-        .add_plugins(DefaultPlugins)
+        .add_plugins(
+            DefaultPlugins
+                .set(ImagePlugin::default_nearest())
+                .set(WindowPlugin {
+                    window: WindowDescriptor {
+                        title: "gems".to_string(),
+                        width: constants::WINDOW_WIDTH,
+                        height: constants::WINDOW_HEIGHT,
+                        resizable: false,
+                        ..default()
+                    },
+                    ..default()
+                }),
+        )
         .add_startup_system(setup)
         .add_system(cell::insert)
         .add_system(cell::falling)
-- 
cgit v1.2.3