rpc and stuff

This commit is contained in:
Evan Pratten 2021-10-03 10:29:20 -04:00
parent 80c27ddc7e
commit 71513ab501
9 changed files with 142 additions and 68 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -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<Scenes, ScreenError, GameContext> 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(())
}

View File

@ -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<Scenes, ScreenError, GameContext> 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(())
}

View File

@ -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)

View File

@ -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<Level>,
current_level_idx: usize,
player_dead: bool,
level_switch_timestamp: DateTime<Utc>,
}
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<Scenes, ScreenError, GameContext> 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<Scenes, ScreenError, GameContext> 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<Scenes, ScreenError, GameContext> for InGameScreen {
) -> Result<dirty_fsm::ActionFlag<Scenes>, 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();

View File

@ -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);

View File

@ -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<Scenes, ScreenError, GameContext> 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<Scenes, ScreenError, GameContext> 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",

View File

@ -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<Scenes, ScreenError, GameContext> 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);

View File

@ -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<Scenes, ScreenError, GameContext> 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(())
}