Clean up entity spawning code

This commit is contained in:
timokoesters 2019-08-25 11:35:54 +02:00
parent b826edf6e8
commit e8ccbe75fa
No known key found for this signature in database
GPG Key ID: CD80BE9AAEE78097
2 changed files with 5 additions and 15 deletions

View File

@ -411,7 +411,7 @@ fn handle_spawn(server: &mut Server, entity: EcsEntity, args: String, action: &C
let body = kind_to_body(id);
server
.create_npc(pos, get_npc_name(id), body)
.create_npc(pos, comp::Stats::new(get_npc_name(id)), body)
.with(comp::Vel(vel))
.with(agent)
.build();

View File

@ -142,7 +142,7 @@ impl Server {
pub fn create_npc(
&mut self,
pos: comp::Pos,
name: String,
stats: comp::Stats,
body: comp::Body,
) -> EcsEntityBuilder {
self.state
@ -153,7 +153,7 @@ impl Server {
.with(comp::Ori(Vec3::unit_y()))
.with(comp::Controller::default())
.with(body)
.with(comp::Stats::new(name))
.with(stats)
.with(comp::CharacterState::default())
}
@ -174,8 +174,7 @@ impl Server {
offset: Vec3::unit_z(),
..comp::LightEmitter::default()
})
//.with(comp::LightEmitter::default())
.with(comp::CharacterState::default())
//.with(comp::LightEmitter::default())
}
pub fn create_player_character(
@ -421,16 +420,7 @@ impl Server {
scale = 2.5 + rand::random::<f32>();
}
self.state
.ecs_mut()
.create_entity_synced()
.with(comp::Pos(npc.pos))
.with(comp::Vel(Vec3::zero()))
.with(comp::Ori(Vec3::unit_y()))
.with(comp::Controller::default())
.with(body)
.with(stats)
.with(comp::CharacterState::default())
self.create_npc(comp::Pos(npc.pos), stats, body)
.with(comp::Agent::enemy())
.with(comp::Scale(scale))
.build();