diff options
Diffstat (limited to 'src/client/map/mod.rs')
| -rw-r--r-- | src/client/map/mod.rs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/client/map/mod.rs b/src/client/map/mod.rs index eaab72f..27cafc4 100644 --- a/src/client/map/mod.rs +++ b/src/client/map/mod.rs @@ -20,6 +20,7 @@ use crate::world::{Room, Wall, World}; use icon_texture_manager::IconTextureManager; use raylib::drawing::RaylibDrawHandle; use raylib::{RaylibHandle, RaylibThread}; +use std::ops::Deref; use std::rc::Rc; /// The map containing all map elements that are seen on the screen. @@ -194,7 +195,10 @@ impl Map { /// items with the same id will therefore be ignored and not added. pub fn add_data(&mut self, world: World) { for (id, i) in world.icons().iter() { - self.add_icon(*id, IconMark::from_icon(*i, self.icon_renderer.clone())); + self.add_icon( + *id, + IconMark::from_icon(i.clone(), self.icon_renderer.clone()), + ); } for (id, r) in world.rooms().iter() { self.add_room(*id, r.clone()); @@ -203,4 +207,28 @@ impl Map { self.add_wall(*id, w.clone()); } } + + /// Creates a world from + pub fn clone_as_world(&self) -> World { + let rooms = self + .rooms + .iter() + .map(|(id, mark)| (*id, mark.deref().clone())) + .collect(); + let rooms = StableVec::from_raw_unchecked(rooms); + let icons = self + .icons + .iter() + .map(|(id, mark)| (*id, mark.deref().clone())) + .collect(); + let icons = StableVec::from_raw_unchecked(icons); + let walls = self + .walls + .iter() + .map(|(id, mark)| (*id, mark.deref().clone())) + .collect(); + let walls = StableVec::from_raw_unchecked(walls); + + World::from_raw_unchecked(rooms, walls, icons, self.used_ids.clone()) + } } |
