initial commit
This commit is contained in:
commit
86f9333aec
21 changed files with 6449 additions and 0 deletions
63
src/entity_registry.rs
Normal file
63
src/entity_registry.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use bevy_ecs::prelude::*;
|
||||
|
||||
use crate::{
|
||||
hierarchy::Parent,
|
||||
player::{Attacker, Player},
|
||||
weapon::Weapon,
|
||||
Id, Name, Stages,
|
||||
};
|
||||
|
||||
#[cfg_attr(feature = "json", derive(serde::Serialize))]
|
||||
#[cfg_attr(feature = "json", serde(tag = "type", rename_all = "snake_case"))]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum EntityInfo {
|
||||
Player {
|
||||
name: String,
|
||||
id: usize,
|
||||
is_attacker: bool,
|
||||
},
|
||||
Weapon {
|
||||
name: String,
|
||||
owner: usize,
|
||||
id: usize,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct EntityRegistry(pub HashMap<Entity, EntityInfo>);
|
||||
|
||||
fn read_entities(
|
||||
player_q: Query<(Entity, &Name, &Id, Has<Attacker>), With<Player>>,
|
||||
weapon_q: Query<(Entity, &Parent, &Name, &Id), With<Weapon>>,
|
||||
mut registry: ResMut<EntityRegistry>,
|
||||
) {
|
||||
for (player, name, id, is_attacker) in player_q.iter() {
|
||||
registry.0.insert(
|
||||
player,
|
||||
EntityInfo::Player {
|
||||
name: name.0.clone(),
|
||||
id: id.0,
|
||||
is_attacker,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
for (weapon, player, name, id) in weapon_q.iter() {
|
||||
let (_, _, player_id, _) = player_q.get(player.get()).unwrap();
|
||||
registry.0.insert(
|
||||
weapon,
|
||||
EntityInfo::Weapon {
|
||||
name: name.0.clone(),
|
||||
owner: player_id.0,
|
||||
id: id.0,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn configure(stages: &mut Stages) {
|
||||
stages.world.init_resource::<EntityRegistry>();
|
||||
stages.snapshot.add_systems(read_entities);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue