wip loading

This commit is contained in:
Evan Pratten 2022-03-22 12:45:25 -04:00
parent dc0c38206a
commit ba5c20fb55

View File

@ -1,25 +1,71 @@
//! Handles loading the global resources and playing an intro animation
//!
//! ## Overview
//!
//! This module contains `LoadingScreen` which will perform multi-threaded resource loading while rendering a loading animation.
//!
//! ## Whats happening
//!
//! - Discord RPC is set
//! - Resources are loaded
//! - Animation is rendered
use poll_promise::Promise;
use raylib::prelude::*; use raylib::prelude::*;
use crate::discord::DiscordChannel; use crate::{
discord::{DiscordChannel, DiscordRpcSignal},
global_resource_package::GlobalResources,
project_constants::ProjectConstants,
};
#[derive(Debug)] pub struct LoadingScreen {
pub struct LoadingScreen {} pub resources: Option<GlobalResources>,
has_updated_discord_status: bool,
}
impl LoadingScreen { impl LoadingScreen {
/// Construct a new `LoadingScreen` /// Construct a new `LoadingScreen`
pub fn new() -> Self { pub fn new() -> Self {
Self {} Self {
resources: None,
has_updated_discord_status: false,
}
} }
pub fn render( pub async fn render(
&mut self, &mut self,
raylib: &mut RaylibHandle, raylib: &mut RaylibHandle,
rl_thread: &RaylibThread, rl_thread: &RaylibThread,
discord: &DiscordChannel, discord: &DiscordChannel,
constants: &ProjectConstants,
) -> bool { ) -> bool {
let mut d = raylib.begin_drawing(&rl_thread); // Handle updating the Discord status
if !self.has_updated_discord_status {
discord
.send(DiscordRpcSignal::ChangeDetails {
details: constants
.discord
.strings
.get("details.loading")
.unwrap()
.to_owned(),
party_status: None,
})
.await
.unwrap();
self.has_updated_discord_status = true;
}
// Begin loading resources if we haven't already
if let None = self.resources {
self.resources = Some(GlobalResources::load(raylib, rl_thread).await);
}
// Draw some graphics
let mut d = raylib.begin_drawing(&rl_thread);
d.clear_background(raylib::color::Color::BLACK);
d.clear_background(raylib::color::Color::WHITE);
true true
} }