diff options
Diffstat (limited to 'src/room.rs')
| -rw-r--r-- | src/room.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/room.rs b/src/room.rs index 5daad29..8d15bde 100644 --- a/src/room.rs +++ b/src/room.rs @@ -30,6 +30,7 @@ use super::systems::{ use super::componentwrapper::ComponentWrapper; use crate::encyclopedia::Encyclopedia; use crate::template::Template; +use crate::roomtemplate::RoomTemplate; @@ -41,12 +42,8 @@ pub struct Room<'a, 'b> { impl <'a, 'b>Room<'a, 'b> { - pub fn new(encyclopedia: Encyclopedia, size: (i64, i64)) -> Room<'a, 'b> { - let (width, height) = size; + pub fn new(encyclopedia: Encyclopedia) -> Room<'a, 'b> { let mut world = World::new(); - world.insert(Size{width, height}); - world.insert(Input{actions: Vec::new()}); - world.insert(Output{output: HashMap::new()}); let mut dispatcher = DispatcherBuilder::new() .with(ControlInput, "controlinput", &[]) @@ -58,6 +55,7 @@ impl <'a, 'b>Room<'a, 'b> { dispatcher.setup(&mut world); + Room { world, dispatcher, @@ -65,6 +63,24 @@ impl <'a, 'b>Room<'a, 'b> { } } + pub fn load_from_template(&mut self, template: &RoomTemplate) { + + let (width, height) = template.size; + self.world.fetch_mut::<Size>().width = width; + self.world.fetch_mut::<Size>().height = height; + + // todo: set spawn + + for (idx, templates) in template.field.iter().enumerate() { + let x = (idx as i64) % width; + let y = (idx as i64) / width; + + for template in templates { + self.add_entity(template, Pos{x, y}); + } + } + } + pub fn view(&self) -> HashMap<String, WorldMessage> { self.world.fetch::<Output>().output.clone() } |
