use bevy hierarchy system

This commit is contained in:
TotallyNot 2025-11-03 18:54:07 +01:00
parent 35413b563c
commit cfe2631578
Signed by: pyrite
GPG key ID: 7F1BA9170CD35D15
15 changed files with 246 additions and 643 deletions

View file

@ -52,19 +52,6 @@ pub struct PlayerDto {
impl PlayerDto {
pub fn spawn(self, world: &mut World) -> EntityWorldMut<'_> {
let primary = self.weapons.primary.map(|p| p.spawn(world));
let secondary = self.weapons.secondary.map(|s| s.spawn(world));
let melee = self.weapons.melee.map(|m| m.spawn(world));
let temporary = self.weapons.temporary.map(|m| m.spawn(world));
let fists = WeaponDto::FISTS.spawn(world);
let kick = WeaponDto::KITCHEN_KNIFE.spawn(world);
let head = self.armour.helmet.map(|a| a.spawn(world));
let torso = self.armour.body.map(|a| a.spawn(world));
let legs = self.armour.pants.map(|a| a.spawn(world));
let hands = self.armour.gloves.map(|a| a.spawn(world));
let feet = self.armour.boots.map(|a| a.spawn(world));
let mut commands = world.spawn(draw_id());
commands.insert((
@ -85,22 +72,48 @@ impl PlayerDto {
faction,
});
commands.insert(Weapons {
primary,
secondary,
melee,
temporary,
kick,
fists,
let mut weapons = None;
commands.with_children(|spawner| {
let primary = self.weapons.primary.map(|p| p.spawn(spawner));
let secondary = self.weapons.secondary.map(|s| s.spawn(spawner));
let melee = self.weapons.melee.map(|m| m.spawn(spawner));
let temporary = self.weapons.temporary.map(|m| m.spawn(spawner));
let fists = WeaponDto::FISTS.spawn(spawner);
let kick = WeaponDto::KICK.spawn(spawner);
weapons = Some(Weapons {
primary,
secondary,
melee,
temporary,
kick,
fists,
});
});
if let Some(weapons) = weapons {
commands.insert(weapons);
}
let mut armour = None;
commands.with_children(|spawner| {
let head = self.armour.helmet.map(|a| a.spawn(spawner));
let torso = self.armour.body.map(|a| a.spawn(spawner));
let legs = self.armour.pants.map(|a| a.spawn(spawner));
let hands = self.armour.gloves.map(|a| a.spawn(spawner));
let feet = self.armour.boots.map(|a| a.spawn(spawner));
armour = Some(PlayerArmour {
torso,
head,
legs,
feet,
hands,
})
});
commands.insert(PlayerArmour {
torso,
head,
legs,
feet,
hands,
});
if let Some(armour) = armour {
commands.insert(armour);
}
commands
}