From d4c1c7ecb5688ef64f45425d9ac8e7ddeb8e8602 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Wed, 3 Feb 2021 10:51:08 +0100 Subject: Fix commands Commands now operate on the local file system, but on the remote world --- src/client/map/mod.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/client/map') 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()) + } } -- cgit v1.2.3-70-g09d2