From 9534504b208aa527359ed6a98a1f5918cd5f408f Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 29 Mar 2024 17:18:43 +0100 Subject: [PATCH] cleanup --- src/world.rs | 112 +++++++++++++++------------------------------------ 1 file changed, 33 insertions(+), 79 deletions(-) diff --git a/src/world.rs b/src/world.rs index 7946397..8b15c5c 100644 --- a/src/world.rs +++ b/src/world.rs @@ -351,32 +351,13 @@ impl ParserState { self.reset_message(); } fn spawn_actor(&mut self, commands: &mut Commands, asset_server: &Res) { - let component_actor = actor::Actor { + let mut actor = commands.spawn_empty(); + actor.insert(actor::Actor { angular_momentum: self.angular_momentum, id: self.id.clone(), ..default() - }; - let component_lifeform = actor::LifeForm::default(); - let component_talker = actor::Talker { - conv_id: self.chat.clone(), - ..default() - }; - let component_vehicle = actor::Vehicle; - let component_engine = actor::Engine { - thrust_forward: self.thrust_forward, - thrust_back: self.thrust_back, - thrust_sideways: self.thrust_sideways, - reaction_wheels: self.reaction_wheels, - warmup_seconds: self.warmup_seconds, - engine_type: self.engine_type, - ..default() - }; - let component_suit = actor::Suit { - oxygen: self.oxygen, - oxygen_max: nature::OXY_D, - ..default() - }; - let component_model = SceneBundle { + }); + actor.insert(SceneBundle { transform: Transform { translation: self.pos, scale: Vec3::splat(self.model_scale), @@ -384,65 +365,38 @@ impl ParserState { }, scene: asset_server.load(asset_name_to_path(self.model.as_str())), ..default() - }; + }); + if self.is_lifeform { + actor.insert(actor::LifeForm::default()); + actor.insert(actor::Suit { + oxygen: self.oxygen, + oxygen_max: nature::OXY_D, + ..default() + }); + } + if !self.chat.is_empty() { + actor.insert(actor::Talker { + conv_id: self.chat.clone(), + ..default() + }); + } + if self.is_vehicle { + actor.insert(actor::Vehicle); + actor.insert(actor::Engine { + thrust_forward: self.thrust_forward, + thrust_back: self.thrust_back, + thrust_sideways: self.thrust_sideways, + reaction_wheels: self.reaction_wheels, + warmup_seconds: self.warmup_seconds, + engine_type: self.engine_type, + ..default() + }); + } + actor.insert(RigidBody::Dynamic); + actor.insert(Collider::cuboid(1.0, 1.0, 1.0)); - // TODO: is there a more dynamic way to construct this...? info!("Spawning actor {} with model {} at {}/{}/{}", self.name, self.model, self.pos.x, self.pos.y, self.pos.z); - if self.is_lifeform { - if !self.chat.is_empty() { - commands.spawn(( - component_actor, - component_lifeform, - component_suit, - component_talker, - component_model, - RigidBody::Dynamic, - Collider::cuboid(1.0, 1.0, 1.0), - )); - } - else { - commands.spawn(( - component_actor, - component_lifeform, - component_suit, - component_model, - RigidBody::Dynamic, - Collider::cuboid(1.0, 1.0, 1.0), - )); - } - } - else { - if !self.chat.is_empty() { - commands.spawn(( - component_actor, - component_talker, - component_model, - RigidBody::Dynamic, - Collider::cuboid(1.0, 1.0, 1.0), - )); - } - else { - if self.is_vehicle { - commands.spawn(( - component_actor, - component_model, - component_vehicle, - component_engine, - RigidBody::Dynamic, - Collider::cuboid(1.0, 1.0, 1.0), - )); - } - else { - commands.spawn(( - component_actor, - component_model, - RigidBody::Dynamic, - Collider::cuboid(1.0, 1.0, 1.0), - )); - } - } - } self.reset(); } fn spawn_entities(&mut self, commands: &mut Commands, asset_server: &Res) {