diff --git a/game/src/context.rs b/game/src/context.rs index a37ebde..afaa4a2 100644 --- a/game/src/context.rs +++ b/game/src/context.rs @@ -2,27 +2,19 @@ use std::{cell::RefCell, sync::mpsc::Sender}; use discord_sdk::activity::ActivityBuilder; -use crate::{GameConfig, utilities::non_ref_raylib::HackedRaylibHandle}; - +use crate::{utilities::non_ref_raylib::HackedRaylibHandle, GameConfig}; #[derive(Debug)] pub enum ControlFlag { - Quit + Quit, + SwitchLevel(usize), } #[derive(Debug)] pub struct GameContext { pub renderer: RefCell, pub config: GameConfig, + pub current_level: usize, pub discord_rpc_send: Sender>, - pub flag_send: Sender> + pub flag_send: Sender>, } - -// impl GameContext { -// /// Construct a new game context. -// pub fn new(raylib: RefCell) -> Self { -// Self { -// renderer: raylib -// } -// } -// } diff --git a/game/src/lib.rs b/game/src/lib.rs index 7b053c4..1172deb 100644 --- a/game/src/lib.rs +++ b/game/src/lib.rs @@ -70,7 +70,7 @@ )] #![clippy::msrv = "1.57.0"] -use std::{cell::RefCell, sync::mpsc::TryRecvError}; +use std::{borrow::BorrowMut, cell::RefCell, sync::mpsc::TryRecvError}; use discord_sdk::activity::ActivityBuilder; use raylib::prelude::*; @@ -147,7 +147,7 @@ pub async fn game_begin(game_config: &mut GameConfig) -> Result<(), Box Result<(), Box Result<(), Box break, + context::ControlFlag::SwitchLevel(level) => { + context.as_mut().current_level = level; + } } } } diff --git a/game/src/scenes/ingame_scene/mod.rs b/game/src/scenes/ingame_scene/mod.rs index f3f5a51..410b2e6 100644 --- a/game/src/scenes/ingame_scene/mod.rs +++ b/game/src/scenes/ingame_scene/mod.rs @@ -68,7 +68,7 @@ impl Action for InGameScreen { self.player.reset(); // Set the player to running - let cur_level = self.levels.get(self.current_level_idx).unwrap(); + let cur_level = self.levels.get(context.current_level).unwrap(); let _ = self.player.update_player( Some(CharacterState::Running), &cur_level.colliders, @@ -94,6 +94,7 @@ impl Action for InGameScreen { ) -> Result, ScreenError> { puffin::profile_function!(); trace!("execute() called on InGameScreen"); + self.current_level_idx = context.current_level; // Grab exclusive access to the renderer let mut renderer = context.renderer.borrow_mut();