|
|
@ -3,7 +3,7 @@ use std::default::Default;
|
|
|
|
use mio::Token;
|
|
|
|
use mio::Token;
|
|
|
|
use strum_macros::{Display, EnumIter};
|
|
|
|
use strum_macros::{Display, EnumIter};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::command::{CommandSet, Parse, ParserError};
|
|
|
|
use crate::command::{CommandNew, CommandSet, Parse, ParserError};
|
|
|
|
use crate::database::Db;
|
|
|
|
use crate::database::Db;
|
|
|
|
use crate::queue::SendQueue;
|
|
|
|
use crate::queue::SendQueue;
|
|
|
|
|
|
|
|
|
|
|
@ -24,6 +24,7 @@ pub enum Command {
|
|
|
|
Dig,
|
|
|
|
Dig,
|
|
|
|
Help,
|
|
|
|
Help,
|
|
|
|
Look,
|
|
|
|
Look,
|
|
|
|
|
|
|
|
New(CommandNew),
|
|
|
|
Quit,
|
|
|
|
Quit,
|
|
|
|
Save,
|
|
|
|
Save,
|
|
|
|
Say,
|
|
|
|
Say,
|
|
|
@ -55,6 +56,7 @@ impl Parse for Command {
|
|
|
|
Self::Dig => "dig DIRECTION:: Dig a new path to a new room in the provided direction.",
|
|
|
|
Self::Dig => "dig DIRECTION:: Dig a new path to a new room in the provided direction.",
|
|
|
|
Self::Help => "help [COMMAND]:: Provide help on a specific command, or an overview.",
|
|
|
|
Self::Help => "help [COMMAND]:: Provide help on a specific command, or an overview.",
|
|
|
|
Self::Look => "look :: Take a look around the current room.",
|
|
|
|
Self::Look => "look :: Take a look around the current room.",
|
|
|
|
|
|
|
|
Self::New(_) => "new :: Create new things.",
|
|
|
|
Self::Quit => "quit :: Quit playing and disconnect from the game.",
|
|
|
|
Self::Quit => "quit :: Quit playing and disconnect from the game.",
|
|
|
|
Self::Save => "save :: Write player information to disk.",
|
|
|
|
Self::Save => "save :: Write player information to disk.",
|
|
|
|
Self::Say => "say MESSAGE:: Say something to the room.",
|
|
|
|
Self::Say => "say MESSAGE:: Say something to the room.",
|
|
|
@ -65,6 +67,10 @@ impl Parse for Command {
|
|
|
|
|
|
|
|
|
|
|
|
fn parse_subcommand(&self, s: String) -> Result<(Self, String), ParserError> {
|
|
|
|
fn parse_subcommand(&self, s: String) -> Result<(Self, String), ParserError> {
|
|
|
|
match self {
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Self::New(_) => {
|
|
|
|
|
|
|
|
let (command, args) = CommandNew::parse(s)?;
|
|
|
|
|
|
|
|
Ok((Self::New(command), args))
|
|
|
|
|
|
|
|
}
|
|
|
|
Self::Set(_) => {
|
|
|
|
Self::Set(_) => {
|
|
|
|
let (command, args) = CommandSet::parse(s)?;
|
|
|
|
let (command, args) = CommandSet::parse(s)?;
|
|
|
|
Ok((Self::Set(command), args))
|
|
|
|
Ok((Self::Set(command), args))
|
|
|
@ -76,6 +82,7 @@ impl Parse for Command {
|
|
|
|
|
|
|
|
|
|
|
|
fn subcommand_help(&self, _: String) -> Option<String> {
|
|
|
|
fn subcommand_help(&self, _: String) -> Option<String> {
|
|
|
|
match self {
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Self::New(command_new) => Some(command_new.help_all()),
|
|
|
|
Self::Set(command_set) => Some(command_set.help_all()),
|
|
|
|
Self::Set(command_set) => Some(command_set.help_all()),
|
|
|
|
_ => None,
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -83,6 +90,7 @@ impl Parse for Command {
|
|
|
|
|
|
|
|
|
|
|
|
fn dispatch_map_subcommand(&self, args: String, token: Token, db: &mut Db) -> SendQueue {
|
|
|
|
fn dispatch_map_subcommand(&self, args: String, token: Token, db: &mut Db) -> SendQueue {
|
|
|
|
match self {
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Self::New(command_new) => command_new.dispatch(command_new, args, token, db),
|
|
|
|
Self::Set(command_set) => command_set.dispatch(command_set, args, token, db),
|
|
|
|
Self::Set(command_set) => command_set.dispatch(command_set, args, token, db),
|
|
|
|
_ => SendQueue::new(),
|
|
|
|
_ => SendQueue::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -98,6 +106,7 @@ impl Parse for Command {
|
|
|
|
Self::D | Self::Down => Self::dispatch_move_room,
|
|
|
|
Self::D | Self::Down => Self::dispatch_move_room,
|
|
|
|
Self::Dig => Self::dispatch_dig,
|
|
|
|
Self::Dig => Self::dispatch_dig,
|
|
|
|
Self::Help => Self::dispatch_help,
|
|
|
|
Self::Help => Self::dispatch_help,
|
|
|
|
|
|
|
|
Self::New(_) => Self::dispatch_map_subcommand,
|
|
|
|
Self::Look => Self::dispatch_look,
|
|
|
|
Self::Look => Self::dispatch_look,
|
|
|
|
Self::Quit => Self::dispatch_quit,
|
|
|
|
Self::Quit => Self::dispatch_quit,
|
|
|
|
Self::Save => Self::dispatch_save,
|
|
|
|
Self::Save => Self::dispatch_save,
|
|
|
|