Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show more details about gamemodes and server gamestates #25

Merged
merged 23 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}