From b9611c1b42b11c67aa47d908ca2d77bd3ae7a706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex=20Rom=C3=A1n=20N=C3=BA=C3=B1ez?= Date: Tue, 29 Sep 2026 11:40:59 +0200 Subject: [PATCH] Fix end of match being able to alter state even after the match has finished --- src/match_runtime.rs | 11 ++++++++++- src/schedule.rs | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/match_runtime.rs b/src/match_runtime.rs index 975f3cc..a4577a8 100644 --- a/src/match_runtime.rs +++ b/src/match_runtime.rs @@ -94,9 +94,13 @@ impl MatchState { } fn advance_frame(&mut self, config: &MatchConfig, frame: i32) { + if self.finished_at_frame.is_some() { + return; + } + self.elapsed_frames = self.elapsed_frames.saturating_add(1); - if self.finished_at_frame.is_none() && self.is_match_finished(config) { + if self.is_match_finished(config) { self.finished_at_frame = Some(frame); } } @@ -139,6 +143,10 @@ pub fn ggrs_should_run(pause: Option>) -> bool { !pause.is_some_and(|pause| pause.paused) } +pub(crate) fn match_is_ongoing(match_state: Option>) -> bool { + match_state.is_none_or(|match_state| match_state.finished_at_frame.is_none()) +} + fn toggle_pause( key: Res>, gamepads: Query<&Gamepad>, @@ -257,6 +265,7 @@ mod tests { state.advance_frame(&config, 12); assert_eq!(state.finished_at_frame, Some(11)); + assert_eq!(state.elapsed_frames, 2); } #[test] diff --git a/src/schedule.rs b/src/schedule.rs index cab5ab3..7966b81 100644 --- a/src/schedule.rs +++ b/src/schedule.rs @@ -9,6 +9,8 @@ use bevy::prelude::*; use bevy_ggrs::prelude::*; +use crate::match_runtime::match_is_ongoing; + #[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)] pub enum GameplaySet { /// Turn this frame's netcode inputs into per-fighter input state. @@ -47,7 +49,8 @@ impl Plugin for GameplaySchedulePlugin { GameplaySet::Attacks, GameplaySet::MatchRules, ) - .chain(), + .chain() + .run_if(match_is_ongoing), ); } }