Quick skip loading screen

This commit is contained in:
Evan Pratten 2021-10-01 19:47:32 -04:00
parent f221aef192
commit 26406b97ba

View File

@ -1,5 +1,6 @@
use std::ops::{Div, Sub};
use cfg_if::cfg_if;
use chrono::{DateTime, Utc};
use dirty_fsm::{Action, ActionFlag};
use raylib::prelude::*;
@ -68,10 +69,20 @@ impl Action<Scenes, ScreenError, GameContext> for LoadingScreen {
trace!("execute() called on LoadingScreen");
self.render_screen_space(&mut context.renderer.borrow_mut());
// Check for a quick skip button in debug builds
cfg_if! {
if #[cfg(debug_assertions)] {
let debug_skip_screen = context.renderer.borrow_mut().is_key_pressed(KeyboardKey::KEY_ESCAPE);
} else {
let debug_skip_screen = false;
}
}
// Keep rendering until we pass the loading screen duration
if let Some(start_timestamp) = self.start_timestamp {
let duration = Utc::now().signed_duration_since(start_timestamp);
if duration.num_seconds() >= LOADING_SCREEN_DURATION_SECONDS as i64 {
if duration.num_seconds() >= LOADING_SCREEN_DURATION_SECONDS as i64 || debug_skip_screen
{
info!("LoadingScreen duration reached, moving to next screen");
Ok(ActionFlag::SwitchState(Scenes::MainMenuScreen))
} else {
@ -128,7 +139,11 @@ impl ScreenSpaceRender for LoadingScreen {
// Only in debug mode, render a debug message
#[cfg(debug_assertions)]
{
raylib.draw_rectangle_v(Vector2::zero(), Vector2::new(screen_size.x, 40.0), Color::RED);
raylib.draw_rectangle_v(
Vector2::zero(),
Vector2::new(screen_size.x, 40.0),
Color::RED,
);
raylib.draw_text(
"Game in DEBUG MODE. Do not redistribute!",
10,