use ::rltk::prelude::*; use ::specs::prelude::*; use super::{get_item_display_name, item_result_menu, ItemMenuResult}; use crate::components::{CursedItem, Equipped, InBackpack, Item, Name}; use crate::{MasterDungeonMap, State}; pub fn remove_curse_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option) { let player_entity = gs.ecs.fetch::(); let equipped = gs.ecs.read_storage::(); let backpack = gs.ecs.read_storage::(); let entities = gs.ecs.entities(); let item_components = gs.ecs.read_storage::(); let cursed = gs.ecs.read_storage::(); let names = gs.ecs.read_storage::(); let dm = gs.ecs.fetch::(); let mut draw_batch = DrawBatch::new(); let mut items = Vec::new(); (&entities, &item_components, &cursed) .join() .filter(|(item_entity, _item, _cursed)| { let mut keep = false; if let Some(bp) = backpack.get(*item_entity) { if bp.owner == *player_entity { if let Some(name) = names.get(*item_entity) { if dm.identified_items.contains(&name.name) { keep = true; } } } } // It's equipped, so we know it's cursed if let Some(equip) = equipped.get(*item_entity) { if equip.owner == *player_entity { keep = true; } } keep }) .for_each(|item| items.push((item.0, get_item_display_name(&gs.ecs, item.0)))); let result = item_result_menu( &mut draw_batch, "Remove Curse From Which Item?", items.len(), &items, ctx.key, ); draw_batch .submit(6000) .expect("Failed to batch render Remove Curse Menu"); result }