parent
540d4fb0fb
commit
651a3a4d7f
@ -0,0 +1,50 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use mio::Token;
|
||||
|
||||
use crate::command::CommandSetRoom;
|
||||
use crate::database::Db;
|
||||
use crate::queue::SendQueue;
|
||||
use crate::{option_send, try_option_send_error, try_send, try_send_error};
|
||||
|
||||
impl CommandSetRoom {
|
||||
/// Set the specified line in the description to the specified text.
|
||||
pub fn dispatch_description(&self, args: String, token: Token, db: &mut Db) -> SendQueue {
|
||||
// parse the arguments
|
||||
if args.is_empty() {
|
||||
return SendQueue(
|
||||
vec![(token, "Set what line to what description?".into(), true)].into(),
|
||||
);
|
||||
}
|
||||
|
||||
let space = option_send!(token, args.find(' '), "Set what line to what description?");
|
||||
|
||||
let mut line_string = args.clone();
|
||||
let mut description = line_string.split_off(space);
|
||||
description.remove(0);
|
||||
let line_num: usize = try_send!(
|
||||
token,
|
||||
u8::from_str(&line_string),
|
||||
"Can't figure out line number from '{}'.",
|
||||
line_string
|
||||
)
|
||||
.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() {
|
||||
for _ in room.description.len()..line_num {
|
||||
room.description.push("".into());
|
||||
}
|
||||
}
|
||||
|
||||
// set description and save
|
||||
room.description[line_num - 1] = description;
|
||||
let _ = try_send_error!(token, db.save_room(&room));
|
||||
|
||||
SendQueue::ok(token)
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
mod description;
|
||||
mod name;
|
||||
mod room;
|
||||
|
||||
pub use description::*;
|
||||
pub use name::*;
|
||||
pub use room::*;
|
||||
|
Loading…
Reference in new issue