Clean up entity spawning code

This commit is contained in:
timokoesters
2019-08-25 11:35:54 +02:00
parent b826edf6e8
commit e8ccbe75fa
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); let body = kind_to_body(id);
server 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(comp::Vel(vel))
.with(agent) .with(agent)
.build(); .build();

View File

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