Item give command, define panzerium as item

This commit is contained in:
crumblingstatue 2023-04-16 01:16:14 +02:00
parent 4dfb0ff7d7
commit 5f7924b696
5 changed files with 30 additions and 2 deletions

View file

@ -18,7 +18,7 @@ use crate::{
game::{for_each_tile_on_screen, Biome, GameState}, game::{for_each_tile_on_screen, Biome, GameState},
graphics::{self, ScreenSc, ScreenVec}, graphics::{self, ScreenSc, ScreenVec},
input::Input, input::Input,
inventory::{TileLayer, UseAction}, inventory::{ItemId, Slot, TileLayer, UseAction},
math::{center_offset, TILE_SIZE}, math::{center_offset, TILE_SIZE},
res::Res, res::Res,
CliArgs, CliArgs,
@ -404,6 +404,16 @@ impl App {
Cmd::TeleportPlayerSpawn => { Cmd::TeleportPlayerSpawn => {
self.game.world.player.col_en.en.pos = self.game.spawn_point.to_s2dc() self.game.world.player.col_en.en.pos = self.game.spawn_point.to_s2dc()
} }
Cmd::GiveItemByName(name) => {
for (i, item) in self.game.itemdb.db.iter().enumerate() {
if item.name == name {
self.game.inventory.slots.push(Slot {
id: i as ItemId,
qty: 1,
})
}
}
}
} }
} }
} }

View file

@ -9,6 +9,7 @@ pub enum CmdLine {
Clear, Clear,
Tp(Tp), Tp(Tp),
Spawn, Spawn,
Give(Give),
} }
#[derive(Parser)] #[derive(Parser)]
@ -28,6 +29,11 @@ impl Tp {
} }
} }
#[derive(Parser)]
pub struct Give {
name: String,
}
pub enum Dispatch { pub enum Dispatch {
Cmd(Cmd), Cmd(Cmd),
ClearConsole, ClearConsole,
@ -39,7 +45,7 @@ impl CmdLine {
Ok(Self::try_parse_from(words)?) Ok(Self::try_parse_from(words)?)
} }
pub(crate) fn dispatch(&self) -> Dispatch { pub(crate) fn dispatch(self) -> Dispatch {
match self { match self {
CmdLine::Quit => Dispatch::Cmd(Cmd::QuitApp), CmdLine::Quit => Dispatch::Cmd(Cmd::QuitApp),
CmdLine::Freecam => Dispatch::Cmd(Cmd::ToggleFreecam), CmdLine::Freecam => Dispatch::Cmd(Cmd::ToggleFreecam),
@ -49,6 +55,7 @@ impl CmdLine {
relative: tp.rel, relative: tp.rel,
}), }),
CmdLine::Spawn => Dispatch::Cmd(Cmd::TeleportPlayerSpawn), CmdLine::Spawn => Dispatch::Cmd(Cmd::TeleportPlayerSpawn),
CmdLine::Give(give) => Dispatch::Cmd(Cmd::GiveItemByName(give.name)),
} }
} }
} }

View file

@ -10,6 +10,7 @@ pub enum Cmd {
relative: bool, relative: bool,
}, },
TeleportPlayerSpawn, TeleportPlayerSpawn,
GiveItemByName(String),
} }
pub type CmdVec = Vec<Cmd>; pub type CmdVec = Vec<Cmd>;

View file

@ -115,6 +115,16 @@ impl Default for ItemDb {
}, },
consumable: true, consumable: true,
}, },
ItemDef {
name: String::from("Panzerium"),
graphic_name: String::from("tiles/panzerium"),
tex_rect: IntRect::default(),
use_action: UseAction::PlaceTile {
layer: TileLayer::Mid,
id: 6,
},
consumable: true,
},
], ],
} }
} }

BIN
tiles.dat

Binary file not shown.