summaryrefslogtreecommitdiff
path: root/src/room.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-02-08 19:22:00 +0100
committertroido <troido@protonmail.com>2020-02-08 19:22:00 +0100
commitb56add981c2f520789b97d1ee6f71dae41e8c900 (patch)
treedca7d8795c2a51f56173153c286c4dadcf8daff4 /src/room.rs
parent3ebe9e6f792a0457c6f3b37b6e9d92c83f8694e2 (diff)
no templates in the world; only pre-entities
Diffstat (limited to 'src/room.rs')
-rw-r--r--src/room.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/room.rs b/src/room.rs
index 84a1040..c179f61 100644
--- a/src/room.rs
+++ b/src/room.rs
@@ -28,22 +28,20 @@ use super::systems::{
};
use crate::encyclopedia::Encyclopedia;
use crate::roomtemplate::RoomTemplate;
+use crate::template::Template;
pub struct Room<'a, 'b> {
world: World,
- dispatcher: Dispatcher<'a, 'b>
+ dispatcher: Dispatcher<'a, 'b>,
+ encyclopedia: Encyclopedia
}
impl <'a, 'b>Room<'a, 'b> {
pub fn new(encyclopedia: Encyclopedia) -> Room<'a, 'b> {
let mut world = World::new();
- world.insert(NewEntities{
- templates: Vec::new(),
- encyclopedia
- });
let mut dispatcher = DispatcherBuilder::new()
.with(ControlInput, "controlinput", &[])
@@ -59,7 +57,8 @@ impl <'a, 'b>Room<'a, 'b> {
Room {
world,
- dispatcher
+ dispatcher,
+ encyclopedia
}
}
@@ -76,11 +75,19 @@ impl <'a, 'b>Room<'a, 'b> {
let y = (idx as i64) / width;
for template in templates {
- self.world.fetch_mut::<NewEntities>().templates.push((Pos{x, y}, template.clone()));
+ if let Err(msg) = self.add_entity(Pos{x, y}, template) {
+ println!("{}", msg);
+ }
}
}
}
+ pub fn add_entity(&mut self, pos: Pos, template: &Template) -> Result<(), &'static str>{
+ let pre_entity = self.encyclopedia.construct(template)?;
+ self.world.fetch_mut::<NewEntities>().ents.push((pos, pre_entity));
+ Ok(())
+ }
+
pub fn view(&self) -> HashMap<String, WorldMessage> {
self.world.fetch::<Output>().output.clone()
}