Skip to content

Commit

Permalink
Add game mode info to GameCommanderEntry
Browse files Browse the repository at this point in the history
Since this information is static during a session, it should be fine to keep it
in GameCommanderEntry and not in the LogState?
  • Loading branch information
BafDyce committed Nov 1, 2024
1 parent 7ecb593 commit af0ca51
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/modules/state/models/resolvers/game_state_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,31 @@ impl StateResolver<LogEvent> for GameStateResolver {
commander.fid.to_string(),
GameCommanderEntry {
name: commander.name.to_string(),
game_mode: None,
log_state: LogState::default(),
},
);
}
}

_ => {
let Some(current) = self.current_commander_mut() else {
return FeedResult::Later;
};

current.log_state.feed(input);
match &input.content {
LogEventContent::LoadGame(load_game_event) => {
current.game_mode = load_game_event.game_mode.clone();
}
LogEventContent::Music(music_event)
if music_event.music_track == "MainMenu" =>
{
// Player exited to games' main menu. TODO: Is this check sufficient or is there a better way?
current.game_mode = None;
}
LogEventContent::Shutdown => current.game_mode = None,
_ => current.log_state.feed(input),
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::state::LogState;
use crate::{logs::load_game_event::LoadGameEventGameMode, state::LogState};
use serde::Serialize;

#[derive(Default, Serialize)]
pub struct GameCommanderEntry {
pub name: String,
pub game_mode: Option<LoadGameEventGameMode>,
pub log_state: LogState,
}
3 changes: 3 additions & 0 deletions src/modules/state/models/resolvers/log_state_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ impl StateResolver<LogEvent> for LogStateResolver {
None => return FeedResult::Later,
}
}
// Should be unreachable because this is already handled in GameCommanderEntry, however we dont want to
// panic via unreachable!() here, just in case..
LogEventContent::LoadGame(_) => {}
_ => {}
}

Expand Down

0 comments on commit af0ca51

Please sign in to comment.