aboutsummaryrefslogtreecommitdiff
path: root/src/client/cli/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/cli/cmd')
-rw-r--r--src/client/cli/cmd/edit.rs20
-rw-r--r--src/client/cli/cmd/read.rs17
-rw-r--r--src/client/cli/cmd/write.rs4
3 files changed, 32 insertions, 9 deletions
diff --git a/src/client/cli/cmd/edit.rs b/src/client/cli/cmd/edit.rs
index 7a02959..1cfb530 100644
--- a/src/client/cli/cmd/edit.rs
+++ b/src/client/cli/cmd/edit.rs
@@ -2,8 +2,9 @@
use super::Command;
use super::{CmdParseError, FromArgs};
-use crate::client::map::MapData;
use crate::client::Editor;
+use crate::net::Cargo;
+use crate::world::World;
use std::path::PathBuf;
/// Command to load a file from the disk and replace the current editor contents with it's info.
@@ -25,8 +26,8 @@ impl FromArgs for Edit {
impl Command for Edit {
fn process(&self, editor: &mut Editor) -> Result<String, String> {
- let data = match MapData::load_from_file(&self.file) {
- Ok(data) => data,
+ let world = match World::load_from_file(&self.file) {
+ Ok(world) => world,
Err(err) => {
return Err(format!(
"Unable to read file: {:?}, reason: {:?}",
@@ -35,7 +36,18 @@ impl Command for Edit {
}
};
- editor.map_mut().set_data(data);
+ // Clear all data from the world, afterwards add all components from the file.
+ editor.server().send(Cargo::ClearAll);
+ for (_, icon) in world.icons().iter() {
+ editor.server().send(Cargo::AddIcon(icon.clone()));
+ }
+ for (_, room) in world.rooms().iter() {
+ editor.server().send(Cargo::AddRoom(room.clone()));
+ }
+ for (_, wall) in world.walls().iter() {
+ editor.server().send(Cargo::AddWall(wall.clone()));
+ }
+
Ok(format!("Map data from {:?} loaded.", &self.file))
}
}
diff --git a/src/client/cli/cmd/read.rs b/src/client/cli/cmd/read.rs
index 313530a..3b20308 100644
--- a/src/client/cli/cmd/read.rs
+++ b/src/client/cli/cmd/read.rs
@@ -3,7 +3,8 @@
use super::Command;
use super::{CmdParseError, FromArgs};
use crate::client::Editor;
-use crate::map::MapData;
+use crate::net::Cargo;
+use crate::world::World;
use std::path::PathBuf;
/// Command to read a file from the system
@@ -25,7 +26,7 @@ impl FromArgs for Read {
impl Command for Read {
fn process(&self, editor: &mut Editor) -> Result<String, String> {
- let data = match MapData::load_from_file(&self.file) {
+ let world = match World::load_from_file(&self.file) {
Ok(data) => data,
Err(err) => {
return Err(format!(
@@ -35,7 +36,17 @@ impl Command for Read {
}
};
- editor.map_mut().add_data(data);
+ // Send all components of the file to the server.
+ for (_, icon) in world.icons().iter() {
+ editor.server().send(Cargo::AddIcon(icon.clone()));
+ }
+ for (_, room) in world.rooms().iter() {
+ editor.server().send(Cargo::AddRoom(room.clone()));
+ }
+ for (_, wall) in world.walls().iter() {
+ editor.server().send(Cargo::AddWall(wall.clone()));
+ }
+
Ok(format!(
"Map data from {:?} read and added to the current buffer.",
&self.file
diff --git a/src/client/cli/cmd/write.rs b/src/client/cli/cmd/write.rs
index 3114f63..37d5a0a 100644
--- a/src/client/cli/cmd/write.rs
+++ b/src/client/cli/cmd/write.rs
@@ -25,9 +25,9 @@ impl FromArgs for Write {
impl Command for Write {
fn process(&self, editor: &mut Editor) -> Result<String, String> {
- let data = MapData::extract_data(editor.map());
+ let world = editor.map().clone_as_world();
- match data.write_to_file(&self.destination) {
+ match world.write_to_file(&self.destination) {
Ok(_) => Ok(format!(
"Successfully wrote contents to `{:?}`",
&self.destination