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},
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,
})
}
}
}
}
}
}

View file

@ -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)),
}
}
}

View file

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

View file

@ -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,
},
],
}
}

BIN
tiles.dat

Binary file not shown.