Skip to content

Commit

Permalink
Show more details about gamemodes and server gamestates (#25)
Browse files Browse the repository at this point in the history
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...
  • Loading branch information
Zanieon authored Sep 7, 2024
1 parent f4dcd63 commit f8a0482
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/presence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HSquirrelVM>) {
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand All @@ -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();
}
}
};
}
27 changes: 27 additions & 0 deletions src/presense_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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
}
}

0 comments on commit f8a0482

Please sign in to comment.