From ba5c20fb555111a9cc09a41daafd4a8a3b378e4d Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Tue, 22 Mar 2022 12:45:25 -0400 Subject: [PATCH] wip loading --- .../src/rendering/screens/loading_screen.rs | 60 ++++++++++++++++--- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/game/game_logic/src/rendering/screens/loading_screen.rs b/game/game_logic/src/rendering/screens/loading_screen.rs index d3eea8f1..ae1939ad 100644 --- a/game/game_logic/src/rendering/screens/loading_screen.rs +++ b/game/game_logic/src/rendering/screens/loading_screen.rs @@ -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 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, + has_updated_discord_status: bool, +} impl LoadingScreen { /// Construct a new `LoadingScreen` pub fn new() -> Self { - Self {} + Self { + resources: None, + has_updated_discord_status: false, + } } - pub fn render( + pub async fn render( &mut self, raylib: &mut RaylibHandle, rl_thread: &RaylibThread, discord: &DiscordChannel, + constants: &ProjectConstants, ) -> 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 }