diff options
| author | troido <troido@protonmail.com> | 2020-02-07 19:47:49 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-07 19:47:49 +0100 |
| commit | 7dd148f8e0b371cb422f14dfe926e98642c41317 (patch) | |
| tree | 5fcc1d564f86a18632819ce27284260d6b542973 /src/room.rs | |
| parent | 940b1c762bb98a56dddc6e3e7f208867abb3ebe5 (diff) | |
can now load maps in the same format as the python version
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() } |
