From 71513ab5010a817f38aec78cef2cbc4fd27ac06d Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 3 Oct 2021 10:29:20 -0400 Subject: [PATCH] rpc and stuff --- .../levels/level_0/appearing_platforms.png | Bin 15327 -> 15326 bytes game/src/scenes/death_screen.rs | 15 +++- game/src/scenes/how_to_play_screen.rs | 15 +++- game/src/scenes/ingame_scene/level/loader.rs | 85 +++++++++--------- game/src/scenes/ingame_scene/mod.rs | 19 +++- game/src/scenes/ingame_scene/world.rs | 24 ++--- game/src/scenes/next_level_screen.rs | 20 +++-- game/src/scenes/options_screen.rs | 16 +++- game/src/scenes/win_screen.rs | 16 +++- 9 files changed, 142 insertions(+), 68 deletions(-) diff --git a/game/assets/levels/level_0/appearing_platforms.png b/game/assets/levels/level_0/appearing_platforms.png index 7707af46e89fe37fdca439d363d68fa4c5dfb1b4..53b660addb0759c3a34959e1b8b3543d0ebe8f5f 100644 GIT binary patch delta 1453 zcmV;e1ycIociwl9Bmq&8B_DrVjvOHjMgLhvmVjSimcvuZ4zm1QsOrvi&m@YJ6l!1$ z7;}${nlOKSU*Q`biX{fM?5U&_@o3S)6&;V)Q%_A%Pko-o+;8iPJuHfRdJL1Gm21G$ z)zZU$FL<<6(X$VZyx#-ub)e|gvcEaHHTw#noD7Jsa+ZH3l#HLDpHC?$9+15q$VcoT)zB}*P<)Znph}D8X*+dpnaX#W(H!c1mbxUKtl6o7M)Z%Y;>DhER46p7*T)PhBIgr13{g{w&=<37r7U1 zLG_=w@q=90=>7+}u+ja7+-GiIP#gPe)1!n#XupPA)F^oUFkyOSulu9+*KPRogu1NY zl8xO3q<62*bS#zXFv6j=&O%5?uU)z0u1GZT74CbIkO^B>8&cR?YZGR`q@qTEfkZo< z{W&#jI&eVi1O_!ABCl=lyPZSX+_cQmXlB)3%5)uC;iffC33{1&&!u!5ZQ$Po8~_nj zkyy`RAki8Hm()+L(DmbX1r3Oke*+!!Nplu2UkH5`~h)ub5eAX67Ne2En<9dc^~J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aa+ diff --git a/game/src/scenes/death_screen.rs b/game/src/scenes/death_screen.rs index 19b3582..80e117c 100644 --- a/game/src/scenes/death_screen.rs +++ b/game/src/scenes/death_screen.rs @@ -2,6 +2,7 @@ use std::ops::{Div, Sub}; use chrono::{DateTime, Utc}; use dirty_fsm::{Action, ActionFlag}; +use discord_sdk::activity::{ActivityBuilder, Assets}; use pkg_version::pkg_version_major; use raylib::prelude::*; @@ -14,7 +15,7 @@ use crate::{GameConfig, context::GameContext, utilities::{ }}; use super::{Scenes, ScreenError}; -use tracing::{debug, info, trace}; +use tracing::{debug, info, error, trace}; #[derive(Debug)] pub struct DeathScreen { @@ -36,9 +37,19 @@ impl Action for DeathScreen { Ok(()) } - fn on_first_run(&mut self, _context: &GameContext) -> Result<(), ScreenError> { + fn on_first_run(&mut self, context: &GameContext) -> Result<(), ScreenError> { debug!("Running DeathScreen for the first time"); + if let Err(e) = context.discord_rpc_send.send(Some( + ActivityBuilder::default() + .details("dead... again") + .assets( + Assets::default().large("game-logo-small", Some(context.config.name.clone())), + ) + )) { + error!("Failed to update discord: {}", e); + } + Ok(()) } diff --git a/game/src/scenes/how_to_play_screen.rs b/game/src/scenes/how_to_play_screen.rs index b41f542..bcfb308 100644 --- a/game/src/scenes/how_to_play_screen.rs +++ b/game/src/scenes/how_to_play_screen.rs @@ -2,6 +2,7 @@ use std::ops::{Div, Sub}; use chrono::{DateTime, Utc}; use dirty_fsm::{Action, ActionFlag}; +use discord_sdk::activity::{ActivityBuilder, Assets}; use pkg_version::pkg_version_major; use raylib::prelude::*; @@ -18,7 +19,7 @@ use crate::{ }; use super::{Scenes, ScreenError}; -use tracing::{debug, info, trace}; +use tracing::{debug, error, info, trace}; #[derive(Debug)] pub struct HowToPlayScreen { @@ -40,9 +41,19 @@ impl Action for HowToPlayScreen { Ok(()) } - fn on_first_run(&mut self, _context: &GameContext) -> Result<(), ScreenError> { + fn on_first_run(&mut self, context: &GameContext) -> Result<(), ScreenError> { debug!("Running HowToPlayScreen for the first time"); + if let Err(e) = context.discord_rpc_send.send(Some( + ActivityBuilder::default() + .details("learning how to play") + .assets( + Assets::default().large("game-logo-small", Some(context.config.name.clone())), + ), + )) { + error!("Failed to update discord: {}", e); + } + Ok(()) } diff --git a/game/src/scenes/ingame_scene/level/loader.rs b/game/src/scenes/ingame_scene/level/loader.rs index 05ff1ad..33bbc2a 100644 --- a/game/src/scenes/ingame_scene/level/loader.rs +++ b/game/src/scenes/ingame_scene/level/loader.rs @@ -29,46 +29,51 @@ pub fn load_all_levels( let mut levels = Vec::new(); for level_name in &level_names { - levels.push(Level { - name: level_name.to_string(), - background_tex: WorldPaintTexture::new(load_texture_from_internal_data( - raylib_handle, - thread, - &format!("levels/{}/background.png", level_name), - )?), - platform_tex: load_texture_from_internal_data( - raylib_handle, - thread, - &format!("levels/{}/platforms.png", level_name), - )?, - appearing_platform_tex: load_texture_from_internal_data( - raylib_handle, - thread, - &format!("levels/{}/appearing_platforms.png", level_name), - )?, - disappearing_platform_tex: load_texture_from_internal_data( - raylib_handle, - thread, - &format!("levels/{}/disappearing_platforms.png", level_name), - )?, - colliders: serde_json::from_str( - &String::from_utf8( - StaticGameData::get(&format!("levels/{}/colliders.json", level_name)) - .unwrap() - .data - .into(), - ) - .unwrap(), - )?, - zones: serde_json::from_str( - &String::from_utf8( - StaticGameData::get(&format!("levels/{}/zones.json", level_name)) - .unwrap() - .data - .into(), - ) - .unwrap(), - )?, + let zones = serde_json::from_str( + &String::from_utf8( + StaticGameData::get(&format!("levels/{}/zones.json", level_name)) + .unwrap() + .data + .into(), + ) + .unwrap(), + )?; + levels.push({ + let mut l = Level { + name: level_name.to_string(), + background_tex: WorldPaintTexture::new(load_texture_from_internal_data( + raylib_handle, + thread, + &format!("levels/{}/background.png", level_name), + )?), + platform_tex: load_texture_from_internal_data( + raylib_handle, + thread, + &format!("levels/{}/platforms.png", level_name), + )?, + appearing_platform_tex: load_texture_from_internal_data( + raylib_handle, + thread, + &format!("levels/{}/appearing_platforms.png", level_name), + )?, + disappearing_platform_tex: load_texture_from_internal_data( + raylib_handle, + thread, + &format!("levels/{}/disappearing_platforms.png", level_name), + )?, + colliders: serde_json::from_str( + &String::from_utf8( + StaticGameData::get(&format!("levels/{}/colliders.json", level_name)) + .unwrap() + .data + .into(), + ) + .unwrap(), + )?, + zones, + }; + l.colliders.append(&mut l.zones.appear); + l }); } Ok(levels) diff --git a/game/src/scenes/ingame_scene/mod.rs b/game/src/scenes/ingame_scene/mod.rs index 9ed9748..69e33b0 100644 --- a/game/src/scenes/ingame_scene/mod.rs +++ b/game/src/scenes/ingame_scene/mod.rs @@ -1,3 +1,4 @@ +use chrono::{DateTime, Utc}; use dirty_fsm::{Action, ActionFlag}; use discord_sdk::activity::{ActivityBuilder, Assets}; use raylib::prelude::*; @@ -29,6 +30,7 @@ pub struct InGameScreen { levels: Vec, current_level_idx: usize, player_dead: bool, + level_switch_timestamp: DateTime, } impl InGameScreen { @@ -50,6 +52,7 @@ impl InGameScreen { levels, current_level_idx: 0, player_dead: false, + level_switch_timestamp: Utc::now(), } } } @@ -66,6 +69,7 @@ impl Action for InGameScreen { // Handle cleanup after death self.player_dead = false; self.player.reset(); + self.level_switch_timestamp = Utc::now(); // Set the player to running let cur_level = self.levels.get(context.current_level).unwrap(); @@ -77,9 +81,12 @@ impl Action for InGameScreen { // Update discord if let Err(e) = context.discord_rpc_send.send(Some( - ActivityBuilder::default().details("in game").assets( - Assets::default().large("game-logo-small", Some(context.config.name.clone())), - ), + ActivityBuilder::default() + .details(format!("LVL {}", context.current_level)) + .assets( + Assets::default().large("game-logo-small", Some(context.config.name.clone())), + ) + .start_timestamp(self.level_switch_timestamp), )) { error!("Failed to update discord: {}", e); } @@ -94,7 +101,11 @@ impl Action for InGameScreen { ) -> Result, ScreenError> { puffin::profile_function!(); trace!("execute() called on InGameScreen"); - self.current_level_idx = context.current_level; + + if self.current_level_idx != context.current_level { + self.current_level_idx = context.current_level; + self.level_switch_timestamp = Utc::now(); + } // Grab exclusive access to the renderer let mut renderer = context.renderer.borrow_mut(); diff --git a/game/src/scenes/ingame_scene/world.rs b/game/src/scenes/ingame_scene/world.rs index 7ed6877..aa79317 100644 --- a/game/src/scenes/ingame_scene/world.rs +++ b/game/src/scenes/ingame_scene/world.rs @@ -45,11 +45,13 @@ impl WorldSpaceRender for InGameScreen { .appear .iter() .map(|zone| { - Vector2::new( - zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0), - zone.y - cur_level.platform_tex.height as f32, - ) - .distance_to(self.player.position) as i32 + // Vector2::new( + // zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0), + // zone.y - cur_level.platform_tex.height as f32, + // ) + // .distance_to(self.player.position) as i32 + ((zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0)) - self.player.position.x) + .abs() as i32 }) .min() .unwrap_or(i32::MAX); @@ -86,11 +88,13 @@ impl WorldSpaceRender for InGameScreen { .disappear .iter() .map(|zone| { - Vector2::new( - zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0), - zone.y - cur_level.platform_tex.height as f32, - ) - .distance_to(self.player.position) as i32 + // Vector2::new( + // zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0), + // zone.y - cur_level.platform_tex.height as f32, + // ) + // .distance_to(self.player.position) as i32 + ((zone.x + WORLD_LEVEL_X_OFFSET + (zone.width / 2.0)) - self.player.position.x) + .abs() as i32 }) .min() .unwrap_or(i32::MAX); diff --git a/game/src/scenes/next_level_screen.rs b/game/src/scenes/next_level_screen.rs index c7c5ccb..5714600 100644 --- a/game/src/scenes/next_level_screen.rs +++ b/game/src/scenes/next_level_screen.rs @@ -2,6 +2,7 @@ use std::ops::{Div, Sub}; use chrono::{DateTime, Utc}; use dirty_fsm::{Action, ActionFlag}; +use discord_sdk::activity::{ActivityBuilder, Assets}; use pkg_version::pkg_version_major; use raylib::prelude::*; @@ -18,7 +19,7 @@ use crate::{ }; use super::{Scenes, ScreenError}; -use tracing::{debug, info, trace}; +use tracing::{debug, error, info, trace}; #[derive(Debug)] pub struct NextLevelScreen { @@ -40,8 +41,17 @@ impl Action for NextLevelScreen { Ok(()) } - fn on_first_run(&mut self, _context: &GameContext) -> Result<(), ScreenError> { + fn on_first_run(&mut self, context: &GameContext) -> Result<(), ScreenError> { debug!("Running NextLevelScreen for the first time"); + + if let Err(e) = context.discord_rpc_send.send(Some( + ActivityBuilder::default().details("accepting fate").assets( + Assets::default().large("game-logo-small", Some(context.config.name.clone())), + ), + )) { + error!("Failed to update discord: {}", e); + } + Ok(()) } @@ -58,7 +68,6 @@ impl Action for NextLevelScreen { } else { Ok(ActionFlag::Continue) } - } fn on_finish(&mut self, _interrupted: bool) -> Result<(), ScreenError> { @@ -112,8 +121,9 @@ impl ScreenSpaceRender for NextLevelScreen { ); //Next Level - let hovering_next_button = Rectangle::new(80.0, screen_size.y as f32 / 2.0 + 50.0, 200.0, 40.0) - .check_collision_point_rec(mouse_position); + let hovering_next_button = + Rectangle::new(80.0, screen_size.y as f32 / 2.0 + 50.0, 200.0, 40.0) + .check_collision_point_rec(mouse_position); raylib.draw_rgb_split_text( Vector2::new(80.0, screen_size.y / 2.0 + 50.0), ">> Next Level", diff --git a/game/src/scenes/options_screen.rs b/game/src/scenes/options_screen.rs index 3f85ef6..b0b3832 100644 --- a/game/src/scenes/options_screen.rs +++ b/game/src/scenes/options_screen.rs @@ -2,6 +2,7 @@ use std::ops::{Div, Sub}; use chrono::{DateTime, Utc}; use dirty_fsm::{Action, ActionFlag}; +use discord_sdk::activity::{ActivityBuilder, Assets}; use pkg_version::pkg_version_major; use raylib::prelude::*; @@ -18,7 +19,7 @@ use crate::{ }; use super::{Scenes, ScreenError}; -use tracing::{debug, info, trace}; +use tracing::{debug, error, info, trace}; #[derive(Debug)] pub struct OptionsScreen { @@ -40,9 +41,19 @@ impl Action for OptionsScreen { Ok(()) } - fn on_first_run(&mut self, _context: &GameContext) -> Result<(), ScreenError> { + fn on_first_run(&mut self, context: &GameContext) -> Result<(), ScreenError> { debug!("Running OptionsScreen for the first time"); + if let Err(e) = context.discord_rpc_send.send(Some( + ActivityBuilder::default() + .details("we gott'em boys!") + .assets( + Assets::default().large("game-logo-small", Some(context.config.name.clone())), + ), + )) { + error!("Failed to update discord: {}", e); + } + // Rick-roll the user let _ = webbrowser::open("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); @@ -108,7 +119,6 @@ impl ScreenSpaceRender for OptionsScreen { Color::WHITE, ); - //Back to Menu let hovering_back = Rectangle::new(35.0, screen_size.y as f32 - 80.0, 200.0, 40.0) .check_collision_point_rec(mouse_position); diff --git a/game/src/scenes/win_screen.rs b/game/src/scenes/win_screen.rs index 1a85052..dc2851f 100644 --- a/game/src/scenes/win_screen.rs +++ b/game/src/scenes/win_screen.rs @@ -2,6 +2,7 @@ use std::ops::{Div, Sub}; use chrono::{DateTime, Utc}; use dirty_fsm::{Action, ActionFlag}; +use discord_sdk::activity::{ActivityBuilder, Assets}; use pkg_version::pkg_version_major; use raylib::prelude::*; @@ -18,7 +19,7 @@ use crate::{ }; use super::{Scenes, ScreenError}; -use tracing::{debug, info, trace}; +use tracing::{debug, error, info, trace}; #[derive(Debug)] pub struct WinScreen { @@ -42,8 +43,19 @@ impl Action for WinScreen { Ok(()) } - fn on_first_run(&mut self, _context: &GameContext) -> Result<(), ScreenError> { + fn on_first_run(&mut self, context: &GameContext) -> Result<(), ScreenError> { debug!("Running WinScreen for the first time"); + + if let Err(e) = context.discord_rpc_send.send(Some( + ActivityBuilder::default() + .details("somehow won the game") + .assets( + Assets::default().large("game-logo-small", Some(context.config.name.clone())), + ), + )) { + error!("Failed to update discord: {}", e); + } + Ok(()) }