From 57a0acf97bcd5ae0f8f7290919b56f58b07c4c32 Mon Sep 17 00:00:00 2001
From: Ho <william.ho@etu.hesge.ch>
Date: Fri, 13 Oct 2023 15:53:43 +0200
Subject: [PATCH] =?UTF-8?q?splash.rs=20fonctionne=20sa=20m=C3=A8re?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 game/src/main.rs   | 76 ++--------------------------------------------
 game/src/splash.rs | 69 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 74 deletions(-)
 create mode 100644 game/src/splash.rs

diff --git a/game/src/main.rs b/game/src/main.rs
index c07a8e2..a9e2489 100644
--- a/game/src/main.rs
+++ b/game/src/main.rs
@@ -8,6 +8,8 @@ use bevy::{
 
 const TEXT_COLOR: Color = Color::rgb(0.9, 0.9, 0.9);
 
+mod splash;
+
 // Enum that will be used as a global state for the game
 #[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash, States)]
 enum GameState {
@@ -53,80 +55,6 @@ fn setup(mut commands: Commands) {
     commands.spawn(Camera2dBundle::default());
 }
 
-mod splash{
-
-    use bevy::prelude::*;
-
-    use super::{despawn_screen, GameState};
-
-    // This plugin will display a splash screen with Bevy logo for 1 second before switching to the menu
-    pub struct SplashPlugin;
-
-    impl Plugin for SplashPlugin {
-        fn build(&self, app: &mut App) {
-            // As this plugin is managing the splash screen, it will focus on the state `GameState::Splash`
-            app
-                // When entering the state, spawn everything needed for this screen
-                .add_systems(OnEnter(GameState::Splash), splash_setup)
-                // While in this state, run the `countdown` system
-                .add_systems(Update, countdown.run_if(in_state(GameState::Splash)))
-                // When exiting the state, despawn everything that was spawned for this screen
-                .add_systems(OnExit(GameState::Splash), despawn_screen::<OnSplashScreen>);
-        }
-    }
-
-    // Tag component used to tag entities added on the splash screen
-    #[derive(Component)]
-    struct OnSplashScreen;
-
-    // Newtype to use a `Timer` for this screen as a resource
-    #[derive(Resource, Deref, DerefMut)]
-    struct SplashTimer(Timer);
-
-    fn splash_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
-        let icon = asset_server.load("pokeball.png");
-        // Display the logo
-        commands
-            .spawn((
-                NodeBundle {
-                    style: Style {
-                        align_items: AlignItems::Center,
-                        justify_content: JustifyContent::Center,
-                        width: Val::Percent(100.0),
-                        ..default()
-                    },
-                    ..default()
-                },
-                OnSplashScreen,
-            ))
-            .with_children(|parent| {
-                parent.spawn(ImageBundle {
-                    style: Style {
-                        // This will set the logo to be 200px wide, and auto adjust its height
-                        width: Val::Px(200.0),
-                        ..default()
-                    },
-                    image: UiImage::new(icon),
-                    ..default()
-                });
-            });
-        // Insert the timer as a resource
-        commands.insert_resource(SplashTimer(Timer::from_seconds(1.0, TimerMode::Once)));
-    }
-
-    // Tick the timer, and change state when finished
-    fn countdown(
-        mut game_state: ResMut<NextState<GameState>>,
-        time: Res<Time>,
-        mut timer: ResMut<SplashTimer>,
-    ) {
-        if timer.tick(time.delta()).finished() {
-            game_state.set(GameState::Menu);
-        }
-    }
-}
-
-
 
 mod game {
     use bevy::prelude::*;
diff --git a/game/src/splash.rs b/game/src/splash.rs
new file mode 100644
index 0000000..bcfe412
--- /dev/null
+++ b/game/src/splash.rs
@@ -0,0 +1,69 @@
+use bevy::prelude::*;
+
+    use super::{despawn_screen, GameState};
+
+    // This plugin will display a splash screen with Bevy logo for 1 second before switching to the menu
+    pub struct SplashPlugin;
+
+    impl Plugin for SplashPlugin {
+        fn build(&self, app: &mut App) {
+            // As this plugin is managing the splash screen, it will focus on the state `GameState::Splash`
+            app
+                // When entering the state, spawn everything needed for this screen
+                .add_systems(OnEnter(GameState::Splash), splash_setup)
+                // While in this state, run the `countdown` system
+                .add_systems(Update, countdown.run_if(in_state(GameState::Splash)))
+                // When exiting the state, despawn everything that was spawned for this screen
+                .add_systems(OnExit(GameState::Splash), despawn_screen::<OnSplashScreen>);
+        }
+    }
+
+    // Tag component used to tag entities added on the splash screen
+    #[derive(Component)]
+    struct OnSplashScreen;
+
+    // Newtype to use a `Timer` for this screen as a resource
+    #[derive(Resource, Deref, DerefMut)]
+    struct SplashTimer(Timer);
+
+    fn splash_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
+        let icon = asset_server.load("pokeball.png");
+        // Display the logo
+        commands
+            .spawn((
+                NodeBundle {
+                    style: Style {
+                        align_items: AlignItems::Center,
+                        justify_content: JustifyContent::Center,
+                        width: Val::Percent(100.0),
+                        ..default()
+                    },
+                    ..default()
+                },
+                OnSplashScreen,
+            ))
+            .with_children(|parent| {
+                parent.spawn(ImageBundle {
+                    style: Style {
+                        // This will set the logo to be 200px wide, and auto adjust its height
+                        width: Val::Px(200.0),
+                        ..default()
+                    },
+                    image: UiImage::new(icon),
+                    ..default()
+                });
+            });
+        // Insert the timer as a resource
+        commands.insert_resource(SplashTimer(Timer::from_seconds(1.0, TimerMode::Once)));
+    }
+
+    // Tick the timer, and change state when finished
+    fn countdown(
+        mut game_state: ResMut<NextState<GameState>>,
+        time: Res<Time>,
+        mut timer: ResMut<SplashTimer>,
+    ) {
+        if timer.tick(time.delta()).finished() {
+            game_state.set(GameState::Menu);
+        }
+    }
\ No newline at end of file
-- 
GitLab