CI / build-and-test (push) Successful in 1m30s
Reviewed-on: #45 Co-authored-by: Álex Román Núñez <eirexe@eirteam.moe>
57 lines
1.7 KiB
Rust
57 lines
1.7 KiB
Rust
use bevy::prelude::*;
|
|
|
|
use crate::{
|
|
fighter::manifest::{FighterManifest, FighterManifestRegistry}, match_loading::{PendingMatch}, ui::{errors::UIErrors, fighter_info::FighterInfoUI},
|
|
};
|
|
|
|
#[derive(Component, FromTemplate)]
|
|
pub struct BattleUI {
|
|
}
|
|
|
|
pub fn spawn_battle_ui(mut commands: Commands, request: Res<PendingMatch>, fighter_registry: Res<FighterManifestRegistry>, manifests: Res<Assets<FighterManifest>>) -> Result {
|
|
|
|
let mut fighter_uis = vec![];
|
|
|
|
for player in &request.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<Entity, With<BattleUI>>) {
|
|
for entity in battle_ui {
|
|
commands.entity(entity).despawn();
|
|
}
|
|
} |