parent
eb9ba21144
commit
36141245e1
@ -1,10 +1,12 @@
|
||||
mod command;
|
||||
mod dispatch;
|
||||
mod new;
|
||||
mod parse;
|
||||
mod parser_error;
|
||||
mod set;
|
||||
|
||||
pub use command::Command;
|
||||
pub use new::*;
|
||||
pub use parse::Parse;
|
||||
pub use parser_error::ParserError;
|
||||
pub use set::*;
|
||||
|
@ -0,0 +1,5 @@
|
||||
mod new;
|
||||
mod room;
|
||||
mod zone;
|
||||
|
||||
pub use new::*;
|
@ -0,0 +1,39 @@
|
||||
use std::default::Default;
|
||||
|
||||
use mio::Token;
|
||||
use strum_macros::{Display, EnumIter};
|
||||
|
||||
use crate::command::Parse;
|
||||
use crate::database::Db;
|
||||
use crate::queue::SendQueue;
|
||||
|
||||
#[derive(Clone, Debug, Display, EnumIter, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub enum CommandNew {
|
||||
Room,
|
||||
Zone,
|
||||
Default,
|
||||
}
|
||||
|
||||
impl Default for CommandNew {
|
||||
fn default() -> Self {
|
||||
Self::Default
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for CommandNew {
|
||||
fn help(&self) -> &str {
|
||||
match self {
|
||||
Self::Room => "new room :: Create a new room.",
|
||||
Self::Zone => "new zone :: Create a new zone.",
|
||||
Self::Default => "",
|
||||
}
|
||||
}
|
||||
|
||||
fn dispatch_map(&self) -> fn(&Self, String, Token, &mut Db) -> SendQueue {
|
||||
match self {
|
||||
Self::Room => Self::dispatch_room,
|
||||
Self::Zone => Self::dispatch_zone,
|
||||
Self::Default => Self::dispatch_default,
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use mio::Token;
|
||||
|
||||
use crate::command::CommandNew;
|
||||
use crate::database::Db;
|
||||
use crate::queue::SendQueue;
|
||||
use crate::world::Room;
|
||||
use crate::{try_option_send_error, try_send_error};
|
||||
|
||||
impl CommandNew {
|
||||
/// Create a new room
|
||||
pub fn dispatch_room(
|
||||
_command: &CommandNew,
|
||||
_args: String,
|
||||
token: Token,
|
||||
db: &mut Db,
|
||||
) -> SendQueue {
|
||||
let player = try_option_send_error!(token, db.get_connected_player(token));
|
||||
let room = try_option_send_error!(token, db.load_room(player.location));
|
||||
let zone = try_option_send_error!(token, db.load_zone(room.zone));
|
||||
let mut root = try_send_error!(token, db.root_zone(&zone));
|
||||
let new_room_id = try_send_error!(token, db.new_area_id());
|
||||
|
||||
let new_room = Room {
|
||||
id: new_room_id,
|
||||
zone: root.id,
|
||||
name: format!("New Room {}", new_room_id),
|
||||
description: Vec::new(),
|
||||
users_visible: true,
|
||||
exits: HashMap::new(),
|
||||
};
|
||||
|
||||
let _ = try_send_error!(token, db.save_room(&new_room));
|
||||
let _ = root.areas.insert(new_room.id);
|
||||
let _ = try_send_error!(token, db.save_zone(&root));
|
||||
|
||||
SendQueue(vec![(token, format!("Room created with id {}", new_room_id), true)].into())
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use mio::Token;
|
||||
|
||||
use crate::command::CommandNew;
|
||||
use crate::database::Db;
|
||||
use crate::queue::SendQueue;
|
||||
use crate::world::Zone;
|
||||
use crate::{try_option_send_error, try_send_error};
|
||||
|
||||
impl CommandNew {
|
||||
/// Create a new zone
|
||||
pub fn dispatch_zone(
|
||||
_command: &CommandNew,
|
||||
_args: String,
|
||||
token: Token,
|
||||
db: &mut Db,
|
||||
) -> SendQueue {
|
||||
let player = try_option_send_error!(token, db.get_connected_player(token));
|
||||
let room = try_option_send_error!(token, db.load_room(player.location));
|
||||
let zone = try_option_send_error!(token, db.load_zone(room.zone));
|
||||
let mut root = try_send_error!(token, db.root_zone(&zone));
|
||||
let new_zone_id = try_send_error!(token, db.new_area_id());
|
||||
|
||||
let new_zone = Zone {
|
||||
id: new_zone_id,
|
||||
parent: root.id,
|
||||
name: format!("New Zone {}", new_zone_id),
|
||||
users_visible: true,
|
||||
areas: HashSet::new(),
|
||||
};
|
||||
|
||||
let _ = try_send_error!(token, db.save_zone(&new_zone));
|
||||
let _ = root.areas.insert(new_zone.id);
|
||||
let _ = try_send_error!(token, db.save_zone(&root));
|
||||
|
||||
SendQueue(vec![(token, format!("Zone created with id {}", new_zone_id), true)].into())
|
||||
}
|
||||
}
|
Loading…
Reference in new issue