From 472d21fd39c99acba1d63770a456c69348cce4d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=80lex=20Rom=C3=A0n?= Date: Thu, 3 Sep 2026 17:43:00 +0200 Subject: [PATCH] Make match loading more deterministic --- src/match_loading.rs | 48 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/src/match_loading.rs b/src/match_loading.rs index f2fb5f0..de6ebb4 100644 --- a/src/match_loading.rs +++ b/src/match_loading.rs @@ -96,6 +96,28 @@ impl MatchAssets { .collect(), } } + + fn into_loading_handles(self) -> Vec { + let mut handles = Vec::with_capacity( + 1 + self + .fighters + .iter() + .map(|fighter| 2 + fighter.attack_scripts.len()) + .sum::(), + ); + handles.push(self.stage.untyped()); + for character in self.fighters { + handles.push(character.model.untyped()); + handles.push(character.baked_animations.untyped()); + handles.extend( + character + .attack_scripts + .into_values() + .map(|handle| handle.untyped()), + ); + } + handles + } } impl AssetCollection for MatchAssets { @@ -104,14 +126,7 @@ impl AssetCollection for MatchAssets { } fn load(world: &mut World) -> Vec { - let assets = Self::requested(world); - let mut handles = Vec::with_capacity(1 + assets.fighters.len()); - handles.push(assets.stage.clone().untyped()); - for character in assets.fighters { - handles.push(character.model.untyped()); - handles.push(character.baked_animations.untyped()); - } - handles + Self::requested(world).into_loading_handles() } } @@ -351,4 +366,21 @@ mod tests { assert!(!valid_player_handles(&players)); } + + #[test] + fn match_loading_waits_for_attack_scripts() { + let mut attack_scripts = HashMap::new(); + attack_scripts.insert(AttackKind::Jab, Handle::default()); + let assets = MatchAssets { + stage: Handle::default(), + fighters: vec![SelectedFighterAssets { + fighter: FighterId::TestFighter, + model: Handle::default(), + baked_animations: Handle::default(), + attack_scripts, + }], + }; + + assert_eq!(assets.into_loading_handles().len(), 4); + } }