diff --git a/src/app.rs b/src/app.rs index f8be5bc..fd3297b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -18,7 +18,7 @@ use crate::{ game::{for_each_tile_on_screen, Biome, GameState}, graphics::{self, ScreenSc, ScreenVec}, input::Input, - inventory::{TileLayer, UseAction}, + inventory::{ItemId, Slot, TileLayer, UseAction}, math::{center_offset, TILE_SIZE}, res::Res, CliArgs, @@ -404,6 +404,16 @@ impl App { Cmd::TeleportPlayerSpawn => { 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, + }) + } + } + } } } } diff --git a/src/cmdline.rs b/src/cmdline.rs index dcaae1e..6661e76 100644 --- a/src/cmdline.rs +++ b/src/cmdline.rs @@ -9,6 +9,7 @@ pub enum CmdLine { Clear, Tp(Tp), Spawn, + Give(Give), } #[derive(Parser)] @@ -28,6 +29,11 @@ impl Tp { } } +#[derive(Parser)] +pub struct Give { + name: String, +} + pub enum Dispatch { Cmd(Cmd), ClearConsole, @@ -39,7 +45,7 @@ impl CmdLine { Ok(Self::try_parse_from(words)?) } - pub(crate) fn dispatch(&self) -> Dispatch { + pub(crate) fn dispatch(self) -> Dispatch { match self { CmdLine::Quit => Dispatch::Cmd(Cmd::QuitApp), CmdLine::Freecam => Dispatch::Cmd(Cmd::ToggleFreecam), @@ -49,6 +55,7 @@ impl CmdLine { relative: tp.rel, }), CmdLine::Spawn => Dispatch::Cmd(Cmd::TeleportPlayerSpawn), + CmdLine::Give(give) => Dispatch::Cmd(Cmd::GiveItemByName(give.name)), } } } diff --git a/src/command.rs b/src/command.rs index 5972422..569eafd 100644 --- a/src/command.rs +++ b/src/command.rs @@ -10,6 +10,7 @@ pub enum Cmd { relative: bool, }, TeleportPlayerSpawn, + GiveItemByName(String), } pub type CmdVec = Vec; diff --git a/src/inventory.rs b/src/inventory.rs index 7922a1d..7c2f22e 100644 --- a/src/inventory.rs +++ b/src/inventory.rs @@ -115,6 +115,16 @@ impl Default for ItemDb { }, 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, + }, ], } } diff --git a/tiles.dat b/tiles.dat index d3897fa..63551ed 100644 Binary files a/tiles.dat and b/tiles.dat differ