Implement post-match screen and match finishing. (#76)
CI / build-and-test (push) Failing after 2m8s
CI / production-build (push) Successful in 11m40s

Reviewed-on: #76
Co-authored-by: Álex Román Núñez <eirexe@eirteam.moe>
This commit was merged in pull request #76.
This commit is contained in:
2026-09-28 18:29:01 +00:00
committed by EIREXE
parent 3af36c4bc8
commit 88ad9ed951
5 changed files with 219 additions and 120 deletions
+52 -5
View File
@@ -49,6 +49,45 @@ impl MatchState {
.collect(),
}
}
pub fn is_match_finished(&self, config: &MatchConfig) -> bool {
let time_limit = match config.rules {
MatchRules::Stock {
starting_stocks: _,
time_limit_frames,
} => time_limit_frames,
MatchRules::Timed { time_limit_frames } => Some(time_limit_frames),
};
if let Some(time_limit) = time_limit {
if self.elapsed_frames >= time_limit {
return true;
}
}
if let MatchRules::Stock {
starting_stocks: _,
time_limit_frames: _,
} = config.rules
{
let alive_fighter_count = self
.players
.iter()
.filter(|fighter| {
fighter
.stocks_remaining
.map(|stocks| stocks)
.unwrap_or_default()
> 0
})
.count();
if alive_fighter_count <= 1 {
return true;
}
}
false
}
}
pub struct MatchRuntimePlugin;
@@ -63,7 +102,8 @@ impl Plugin for MatchRuntimePlugin {
.add_systems(OnExit(AppState::InMatch), reset_pause)
.add_systems(
PreUpdate,
toggle_pause
(toggle_pause, check_match_finished)
.chain()
.after(InputSystems)
.before(RunGgrsSystems)
.run_if(in_state(AppState::InMatch)),
@@ -98,14 +138,21 @@ fn toggle_pause(
virtual_time.toggle();
}
fn reset_pause(
mut pause: ResMut<PauseState>,
mut virtual_time: ResMut<Time<Virtual>>,
) {
fn reset_pause(mut pause: ResMut<PauseState>, mut virtual_time: ResMut<Time<Virtual>>) {
pause.paused = false;
virtual_time.unpause();
}
pub fn check_match_finished(
match_state: Res<MatchState>,
match_config: Res<MatchConfig>,
mut next_state: ResMut<NextState<AppState>>,
) {
if match_state.is_match_finished(&match_config) {
next_state.set(AppState::MatchResults);
}
}
#[cfg(test)]
mod tests {
use super::*;