Console, experimental tile graphic for continuous tiles

This commit is contained in:
crumblingstatue 2023-04-16 01:03:12 +02:00
parent 8ee0c9d535
commit 4dfb0ff7d7
12 changed files with 201 additions and 23 deletions

54
src/cmdline.rs Normal file
View file

@ -0,0 +1,54 @@
use clap::Parser;
use crate::{command::Cmd, math::WorldPos};
#[derive(Parser)]
pub enum CmdLine {
Quit,
Freecam,
Clear,
Tp(Tp),
Spawn,
}
#[derive(Parser)]
pub struct Tp {
x: u32,
y: u32,
/// Relative to current position
#[arg(short, long)]
rel: bool,
}
impl Tp {
fn to_world_pos(&self) -> WorldPos {
WorldPos {
x: self.x,
y: self.y,
}
}
}
pub enum Dispatch {
Cmd(Cmd),
ClearConsole,
}
impl CmdLine {
pub fn parse_cmdline(cmdline: &str) -> anyhow::Result<Self> {
let words = std::iter::once(" ").chain(cmdline.split_whitespace());
Ok(Self::try_parse_from(words)?)
}
pub(crate) fn dispatch(&self) -> Dispatch {
match self {
CmdLine::Quit => Dispatch::Cmd(Cmd::QuitApp),
CmdLine::Freecam => Dispatch::Cmd(Cmd::ToggleFreecam),
CmdLine::Clear => Dispatch::ClearConsole,
CmdLine::Tp(tp) => Dispatch::Cmd(Cmd::TeleportPlayer {
pos: tp.to_world_pos(),
relative: tp.rel,
}),
CmdLine::Spawn => Dispatch::Cmd(Cmd::TeleportPlayerSpawn),
}
}
}