This commit is contained in:
yuni 2024-03-29 17:18:43 +01:00
parent c390a18ae5
commit 9534504b20

View file

@ -351,32 +351,13 @@ impl ParserState {
self.reset_message();
}
fn spawn_actor(&mut self, commands: &mut Commands, asset_server: &Res<AssetServer>) {
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<AssetServer>) {