rm savegame

This commit is contained in:
Evan Pratten 2021-10-03 12:15:44 -04:00
parent 583ece9c12
commit 17049c7fa9
4 changed files with 19 additions and 4 deletions

View File

@ -1,6 +1,6 @@
use std::{cell::RefCell, sync::mpsc::Sender}; use std::{cell::RefCell, sync::mpsc::Sender};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Duration, Utc};
use discord_sdk::activity::ActivityBuilder; use discord_sdk::activity::ActivityBuilder;
use crate::{progress::ProgressData, utilities::non_ref_raylib::HackedRaylibHandle, GameConfig}; use crate::{progress::ProgressData, utilities::non_ref_raylib::HackedRaylibHandle, GameConfig};
@ -10,7 +10,8 @@ pub enum ControlFlag {
Quit, Quit,
SwitchLevel(usize), SwitchLevel(usize),
UpdateLevelStart(DateTime<Utc>), UpdateLevelStart(DateTime<Utc>),
SaveProgress SaveProgress,
MaybeUpdateHighScore(usize, Duration)
} }
#[derive(Debug)] #[derive(Debug)]

View File

@ -335,6 +335,12 @@ pub async fn game_begin(game_config: &mut GameConfig) -> Result<(), Box<dyn std:
context::ControlFlag::SaveProgress => { context::ControlFlag::SaveProgress => {
context.as_mut().player_progress.save(); context.as_mut().player_progress.save();
} }
context::ControlFlag::MaybeUpdateHighScore(level, time) => {
context
.as_mut()
.player_progress
.maybe_write_new_time(level, &time);
}
} }
} }
} }

View File

@ -136,6 +136,16 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
// Check if the player won // Check if the player won
let cur_level = self.levels.get(context.current_level).unwrap(); let cur_level = self.levels.get(context.current_level).unwrap();
if self.player.position.x > cur_level.zones.win.x { if self.player.position.x > cur_level.zones.win.x {
// Save the current time
let elapsed = Utc::now() - self.level_switch_timestamp;
context
.flag_send
.send(Some(ControlFlag::MaybeUpdateHighScore(
self.current_level_idx,
elapsed,
)))
.unwrap();
// Save the progress // Save the progress
context context
.flag_send .flag_send
@ -152,7 +162,6 @@ impl Action<Scenes, ScreenError, GameContext> for InGameScreen {
.send(Some(ControlFlag::SwitchLevel(self.current_level_idx + 1))) .send(Some(ControlFlag::SwitchLevel(self.current_level_idx + 1)))
.unwrap(); .unwrap();
// TODO: This is where the timer should reset and publish state
return Ok(ActionFlag::SwitchState(Scenes::NextLevelScreen)); return Ok(ActionFlag::SwitchState(Scenes::NextLevelScreen));
} }
} }

View File

@ -1 +0,0 @@
{"level_best_times":{}}