inventory finishes
This commit is contained in:
parent
aadb966fa4
commit
f26adf352e
6 changed files with 126 additions and 5 deletions
23
src/main.rs
23
src/main.rs
|
|
@ -37,6 +37,7 @@ pub enum RunState {
|
|||
PlayerTurn,
|
||||
MonsterTurn,
|
||||
ShowInventory,
|
||||
ShowDropItem,
|
||||
}
|
||||
|
||||
pub struct State {
|
||||
|
|
@ -59,6 +60,8 @@ impl State {
|
|||
inventory_system.run_now(&self.ecs);
|
||||
let mut potion_system = PotionUseSystem {};
|
||||
potion_system.run_now(&self.ecs);
|
||||
let mut drop_system = ItemDropSystem {};
|
||||
drop_system.run_now(&self.ecs);
|
||||
self.ecs.maintain();
|
||||
}
|
||||
}
|
||||
|
|
@ -75,7 +78,9 @@ impl GameState for State {
|
|||
let renderables = self.ecs.read_storage::<Renderable>();
|
||||
let map = self.ecs.fetch::<Map>();
|
||||
|
||||
for (pos, render) in (&positions, &renderables).join() {
|
||||
let mut data = (&positions, &renderables).join().collect::<Vec<_>>();
|
||||
data.sort_by(|&a, &b| b.1.render_order.cmp(&a.1.render_order));
|
||||
for (pos, render) in data.iter() {
|
||||
let idx = map.xy_idx(pos.x, pos.y);
|
||||
if map.visible_tiles[idx] {
|
||||
ctx.set(pos.x, pos.y, render.fg, render.bg, render.glyph);
|
||||
|
|
@ -124,6 +129,21 @@ impl GameState for State {
|
|||
}
|
||||
}
|
||||
}
|
||||
RunState::ShowDropItem => {
|
||||
let result = gui::drop_item_menu(self, ctx);
|
||||
match result.0 {
|
||||
gui::ItemMenuResult::Cancel => new_runstate = RunState::AwaitingInput,
|
||||
gui::ItemMenuResult::NoResponse => {}
|
||||
gui::ItemMenuResult::Selected => {
|
||||
let item_entity = result.1.unwrap();
|
||||
let mut intent = self.ecs.write_storage::<WantsToDropItem>();
|
||||
intent
|
||||
.insert(*self.ecs.fetch::<Entity>(), WantsToDropItem { item: item_entity })
|
||||
.expect("Unable to insert intent");
|
||||
new_runstate = RunState::PlayerTurn;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -159,6 +179,7 @@ fn main() -> rltk::BError {
|
|||
gs.ecs.register::<Potion>();
|
||||
gs.ecs.register::<InBackpack>();
|
||||
gs.ecs.register::<WantsToPickupItem>();
|
||||
gs.ecs.register::<WantsToDropItem>();
|
||||
gs.ecs.register::<WantsToDrinkPotion>();
|
||||
|
||||
let map = Map::new_map_rooms_and_corridors();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue