1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-11-29 15:56:53 +00:00

Loading counter

This commit is contained in:
dawnDus 2022-01-21 11:31:25 -05:00 committed by alula
parent ce6de7c0a0
commit af1f9f5d89
2 changed files with 49 additions and 1 deletions

View file

@ -1,9 +1,12 @@
use byteorder::{ReadBytesExt, LE};
use crate::common::Rect;
use crate::components::draw_common::{Alignment, draw_number, draw_number_zeros};
use crate::components::draw_common::{draw_number, draw_number_zeros, Alignment};
use crate::entity::GameEntity;
use crate::frame::Frame;
use crate::framework::context::Context;
use crate::framework::error::GameResult;
use crate::framework::filesystem;
use crate::player::Player;
use crate::shared_game_state::{SharedGameState, TimingMode};
@ -17,6 +20,43 @@ impl NikumaruCounter {
pub fn new() -> NikumaruCounter {
NikumaruCounter { tick: 0, shown: false }
}
fn load_saved_time(&mut self, ctx: &mut Context) -> GameResult<u32> {
if let Ok(mut data) = filesystem::user_open(ctx, "/290.rec") {
let mut ticks: [u32; 4] = [0, 0, 0, 0];
for iter in 0..=3 {
ticks[iter] = data.read_u32::<LE>()?;
}
let random = data.read_u32::<LE>()?;
let random_list: [u8; 4] = random.to_le_bytes();
for iter in 0..=3 {
ticks[iter] = u32::from_le_bytes([
ticks[iter].to_le_bytes()[0] - random_list[iter],
ticks[iter].to_le_bytes()[1] - random_list[iter],
ticks[iter].to_le_bytes()[2] - random_list[iter],
ticks[iter].to_le_bytes()[3] - random_list[iter] / 2,
]);
}
if ticks[0] == ticks[1] && ticks[0] == ticks[2] {
return Ok(ticks[0]);
}
} else {
log::warn!("Cannot open 290.rec.");
}
Ok(0)
}
pub fn load_counter(&mut self, ctx: &mut Context) -> GameResult {
self.tick = self.load_saved_time(ctx)? as usize;
if self.tick > 0 {
self.shown = true;
}
Ok(())
}
}
impl GameEntity<&Player> for NikumaruCounter {

View file

@ -1,5 +1,7 @@
use crate::common::{Color, VERSION_BANNER};
use crate::components::background::Background;
use crate::components::nikumaru::NikumaruCounter;
use crate::entity::GameEntity;
use crate::frame::Frame;
use crate::framework::context::Context;
use crate::framework::error::GameResult;
@ -34,6 +36,7 @@ pub struct TitleScene {
save_select_menu: Menu,
background: Background,
frame: Frame,
nikumaru_rec: NikumaruCounter,
stage: Stage,
textures: StageTexturePaths,
}
@ -67,6 +70,7 @@ impl TitleScene {
save_select_menu: Menu::new(0, 0, 200, 0),
background: Background::new(),
frame: Frame::new(),
nikumaru_rec: NikumaruCounter::new(),
stage: fake_stage,
textures,
}
@ -117,6 +121,8 @@ impl Scene for TitleScene {
self.controller.update(state, ctx)?;
self.controller.update_trigger();
self.nikumaru_rec.load_counter(ctx)?;
Ok(())
}
@ -211,6 +217,8 @@ impl Scene for TitleScene {
self.draw_text_centered(&VERSION_BANNER, state.canvas_size.1 - 15.0, state, ctx)?;
self.draw_text_centered(COPYRIGHT_PIXEL, state.canvas_size.1 - 30.0, state, ctx)?;
self.nikumaru_rec.draw(state, ctx, &self.frame)?;
match self.current_menu {
CurrentMenu::MainMenu => self.main_menu.draw(state, ctx)?,
CurrentMenu::OptionMenu => self.option_menu.draw(state, ctx)?,