From f8a0482c2f0df2bf20c503ff2d60df1e51ccead0 Mon Sep 17 00:00:00 2001 From: William Miller Date: Sat, 7 Sep 2024 17:17:21 -0300 Subject: [PATCH] Show more details about gamemodes and server gamestates (#25) When playing Frontier Defense it will show when the player is in a Wave Break or which Wave they are currently through Whenever the server is NOT at the Playing gamestate, the plugin will report the respective states instead such as Selecting Titan screen, Prematch, Epilogue, Postmatch, etc... --- src/presence.rs | 34 ++++++++++++++++++++++++++++++++-- src/presense_bindings.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/presence.rs b/src/presence.rs index dda5473..cea7f85 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -11,7 +11,7 @@ use std::{ time::{SystemTime, UNIX_EPOCH}, }; -use crate::presense_bindings::{GameState, GameStateStruct, UIPresenceStruct}; +use crate::presense_bindings::{GameState, GameStateStruct, SVGameState, UIPresenceStruct}; // heartbeat for pulling presence pub fn run_presence_updates(sqvm: NonNull) { @@ -127,7 +127,10 @@ fn on_presence_updated( activity.end = None; } GameState::Lobby => { - activity.party = None; + activity.party = Some(( + cl_presence.current_players.try_into().unwrap_or_default(), + cl_presence.max_players.try_into().unwrap_or_default(), + )); activity.details = "Lobby".to_string(); activity.state = "In the Lobby".to_string(); activity.large_image = Some("northstar".to_string()); @@ -150,6 +153,18 @@ fn on_presence_updated( if cl_presence.playlist == "campaign" { activity.party = None; activity.end = None; + } else if cl_presence.playlist == "fd" { + cl_presence + .playlist_displayname + .clone_into(&mut activity.state); + if cl_presence.fd_wavenumber == -1 { + activity.details = "On Wave Break".to_string(); + } else { + activity.details = format!( + "Wave: {} of {}", + cl_presence.fd_wavenumber, cl_presence.fd_totalwaves + ); + } } else { cl_presence .playlist_displayname @@ -168,6 +183,21 @@ fn on_presence_updated( activity.end = Some(current_time + ig_end); } } + // This will override previous details established whenever server is not in the Playing gamestate, so friends can see at which stage a match currently is + if cl_presence.servergamestate != SVGameState::Playing { + activity.details = match cl_presence.servergamestate { + SVGameState::WaitingForPlayers => "Waiting Players to Load", + SVGameState::PickLoadout => "Titan Selection", + SVGameState::Prematch => "Match Starting", + SVGameState::SuddenDeath => "In Sudden Death", + SVGameState::SwitchingSides => "Switching Sides", + SVGameState::WinnerDetermined => "Winner Determined", + SVGameState::Epilogue => "In Epilogue", + SVGameState::Postmatch => "Match Ending", + _ => "", + } + .to_string(); + } } }; } diff --git a/src/presense_bindings.rs b/src/presense_bindings.rs index d47ee6d..8bb0848 100644 --- a/src/presense_bindings.rs +++ b/src/presense_bindings.rs @@ -29,6 +29,9 @@ pub struct GameStateStruct { pub other_highest_score: i32, pub max_score: i32, pub time_end: f32, + pub servergamestate: SVGameState, + pub fd_wavenumber: i32, + pub fd_totalwaves: i32, } #[derive(PushToSquirrelVm, GetFromSquirrelVm, Default, Clone)] @@ -42,3 +45,27 @@ impl Default for GameState { Self::Loading } } + +#[derive( + PushToSquirrelVm, GetFromSquirrelVm, GetFromSQObject, Clone, Copy, Debug, PartialEq, Eq, +)] +#[repr(i32)] +/// binding to ServerGameState +pub enum SVGameState { + WaitingForCustomStart, + WaitingForPlayers, + PickLoadout, + Prematch, + Playing, + SuddenDeath, + SwitchingSides, + WinnerDetermined, + Epilogue, + Postmatch, +} + +impl Default for SVGameState { + fn default() -> Self { + Self::WaitingForCustomStart + } +}