summaryrefslogtreecommitdiff
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/src/lib.rs3
-rw-r--r--graphics/src/render.rs23
2 files changed, 8 insertions, 18 deletions
diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs
index 02eb97f..fef5f9e 100644
--- a/graphics/src/lib.rs
+++ b/graphics/src/lib.rs
@@ -19,7 +19,6 @@ pub type Error = Box<dyn std::error::Error>;
/// The `Result` type used witin this crate
pub type Result<T> = std::result::Result<T, crate::Error>;
-#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Key {
// Movement
@@ -38,7 +37,7 @@ pub enum Key {
F,
Q,
// Number
- Number(u8),
+ Number(usize),
// Debug keys
F3,
F4,
diff --git a/graphics/src/render.rs b/graphics/src/render.rs
index 613763c..762827c 100644
--- a/graphics/src/render.rs
+++ b/graphics/src/render.rs
@@ -7,8 +7,9 @@ use std::{
use dungeon::{
Dungeon,
- entity::{Entity, EntityKind, Item, PLAYER_INVENTORY_SIZE, Player},
+ entity::{Entity, EntityKind, Item},
map::{Floor, MAP_SIZE, Tile},
+ player::{PLAYER_INVENTORY_SIZE, Player},
pos::{Direction, Pos},
};
use raylib::{
@@ -635,21 +636,11 @@ impl Renderer {
self.draw_text_vertical(r, b"INV", TEXT_X, UI_PADDING);
// Draw slots
- for idx in 0..PLAYER_INVENTORY_SIZE {
- if idx >= PLAYER_INVENTORY_SIZE {
- // This should never happen!
- // Maybe use a different type??
- break;
- }
-
- let slot_x = SLOTS_X + SLOT_LEN * idx;
+ for (idx, (opt_item, active)) in player.inventory.iter().enumerate() {
+ let slot_x = SLOTS_X + SLOT_LEN * downcast!(idx, u16);
// Draw slot container
- let tint = if (idx as usize) == player.active_inv_slot {
- Color::YELLOW
- } else {
- Color::WHITE
- };
+ let tint = if active { Color::YELLOW } else { Color::WHITE };
r.draw_atlas(
&self.textures.atlas,
ATLAS_INV_CONTAINER,
@@ -660,8 +651,8 @@ impl Renderer {
tint,
);
- if let Some(item) = player.inventory.get(idx as usize) {
- let tex = self.textures.item_texture(*item);
+ if let Some(item) = opt_item {
+ let tex = self.textures.item_texture(item);
const ITEM_PADDDING: u16 = UI_PADDING * 3;
let dest_rec = rect! {
slot_x + ITEM_PADDDING/2,