Create the CommandSetRoomDescription sub command, move the former description command into it and rename it set, and the delete command.master
parent
651a3a4d7f
commit
87367644cc
@ -0,0 +1,42 @@
|
|||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use mio::Token;
|
||||||
|
|
||||||
|
use crate::command::CommandSetRoomDescription;
|
||||||
|
use crate::database::Db;
|
||||||
|
use crate::queue::SendQueue;
|
||||||
|
use crate::{try_option_send_error, try_send, try_send_error};
|
||||||
|
|
||||||
|
impl CommandSetRoomDescription {
|
||||||
|
/// Set the specified line in the description to the specified text.
|
||||||
|
pub fn dispatch_delete(&self, args: String, token: Token, db: &mut Db) -> SendQueue {
|
||||||
|
// make sure something was provided
|
||||||
|
if args.is_empty() {
|
||||||
|
return SendQueue(vec![(token, "Delete which line?".into(), true)].into());
|
||||||
|
}
|
||||||
|
|
||||||
|
// try and get the line number
|
||||||
|
let line_num: usize = try_send!(
|
||||||
|
token,
|
||||||
|
u8::from_str(&args),
|
||||||
|
"Can't figure out line number from '{}'.",
|
||||||
|
&args
|
||||||
|
)
|
||||||
|
.into();
|
||||||
|
|
||||||
|
// load the player and room
|
||||||
|
let player = try_option_send_error!(token, db.get_connected_player(token));
|
||||||
|
let mut room = try_option_send_error!(token, db.load_room(player.location));
|
||||||
|
|
||||||
|
// make sure description has enough lines
|
||||||
|
if line_num > room.description.len().into() || line_num <= 0 {
|
||||||
|
return SendQueue(vec![(token, "Line doeesn't exist".into(), true)].into());
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove the line and save
|
||||||
|
room.description.remove(line_num-1);
|
||||||
|
let _ = try_send_error!(token, db.save_room(&room));
|
||||||
|
|
||||||
|
SendQueue::ok(token)
|
||||||
|
}
|
||||||
|
}
|
@ -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 CommandSetRoomDescription {
|
||||||
|
Delete,
|
||||||
|
Set,
|
||||||
|
Default,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for CommandSetRoomDescription {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Parse for CommandSetRoomDescription {
|
||||||
|
fn help(&self) -> &str {
|
||||||
|
match self {
|
||||||
|
Self::Delete => "set room description delete LINE :: Delete line LINE from room description",
|
||||||
|
Self::Set => "set room description set LINE DESC :: Set room description line LINE to DESC",
|
||||||
|
Self::Default => "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dispatch_map(&self) -> fn(&Self, String, Token, &mut Db) -> SendQueue {
|
||||||
|
match self {
|
||||||
|
Self::Delete => Self::dispatch_delete,
|
||||||
|
Self::Set => Self::dispatch_set,
|
||||||
|
Self::Default => Self::dispatch_default,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
mod delete;
|
||||||
|
mod description;
|
||||||
|
mod set;
|
||||||
|
|
||||||
|
pub use delete::*;
|
||||||
|
pub use description::*;
|
||||||
|
pub use set::*;
|
Loading…
Reference in new issue