use bevy::prelude::*; use crate::{ fighter::manifest::{FighterManifest, FighterManifestRegistry}, match_loading::MatchConfig, ui::{errors::UIErrors, fighter_info::FighterInfoUI}, }; #[derive(Component, FromTemplate)] pub struct BattleUI {} pub fn spawn_battle_ui( mut commands: Commands, config: Res, fighter_registry: Res, manifests: Res>, ) -> Result { let mut fighter_uis = vec![]; for player in &config.players { let manifest = fighter_registry .get(player.fighter) .ok_or_else(|| UIErrors::FighterManifestHandleNotFound(player.fighter))?; let manifest = manifests .get(manifest) .ok_or_else(|| UIErrors::FighterManifestNotFound(player.fighter))?; fighter_uis.push(FighterInfoUI::build(manifest, player)); } let scene = bsn! { BattleUI { } Node { width: percent(100), height: percent(100), flex_direction: FlexDirection::Column, align_items: AlignItems::Center, justify_content: JustifyContent::End, } Children [ ( #FighterInfos Node { width: percent(100), flex_direction: FlexDirection::Row, align_items: AlignItems::End, justify_content: JustifyContent::SpaceEvenly, } Children [ {fighter_uis} ] ) ] }; commands.spawn_scene(scene); Ok(()) } pub fn cleanup_battle_ui(mut commands: Commands, battle_ui: Query>) { for entity in battle_ui { commands.entity(entity).despawn(); } }