mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-15 20:25:00 +01:00
Console, experimental tile graphic for continuous tiles
This commit is contained in:
parent
8ee0c9d535
commit
4dfb0ff7d7
12 changed files with 201 additions and 23 deletions
54
src/cmdline.rs
Normal file
54
src/cmdline.rs
Normal 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue