From be9a5109c85f188a5ad3f6e6adf98ac3f175487b Mon Sep 17 00:00:00 2001 From: hodasemi Date: Sun, 6 Apr 2025 09:23:11 +0200 Subject: [PATCH] Fix character menu --- character_window/src/inventory/content.rs | 2 +- .../src/inventory/item_right_side.rs | 2 +- .../src/inventory/jewel_right_side.rs | 7 - character_window/src/inventory/mod.rs | 2 +- rpg_components/src/components/item_slots.rs | 197 ++++-------------- rpg_components/src/components/statistics.rs | 1 - 6 files changed, 44 insertions(+), 167 deletions(-) diff --git a/character_window/src/inventory/content.rs b/character_window/src/inventory/content.rs index 17d4b93..1404a5a 100644 --- a/character_window/src/inventory/content.rs +++ b/character_window/src/inventory/content.rs @@ -78,7 +78,7 @@ impl Content { let item = inventory.remove_item(item_index); // add or swap items with equipment - if let Some(old_item) = hero_items.insert(item.clone(), attributes, entity)? { + if let Some(old_item) = hero_items.insert(item.clone(), attributes)? { inventory.insert_item(old_item, item_index); } diff --git a/character_window/src/inventory/item_right_side.rs b/character_window/src/inventory/item_right_side.rs index 0f3959f..51e1a77 100644 --- a/character_window/src/inventory/item_right_side.rs +++ b/character_window/src/inventory/item_right_side.rs @@ -251,7 +251,7 @@ mod macros { } if found_item { - items.[](entity)?; + items.[]()?; statistics.update( attributes, diff --git a/character_window/src/inventory/jewel_right_side.rs b/character_window/src/inventory/jewel_right_side.rs index 3217df3..de4e1f2 100644 --- a/character_window/src/inventory/jewel_right_side.rs +++ b/character_window/src/inventory/jewel_right_side.rs @@ -46,13 +46,6 @@ impl ReferenceObject { ReferenceObject::Empty => None, } } - - pub fn some_mut(&mut self) -> Option<&mut Self> { - match self { - ReferenceObject::Item { .. } | ReferenceObject::Jewel { .. } => Some(self), - ReferenceObject::Empty => None, - } - } } #[derive(Default, Resource)] diff --git a/character_window/src/inventory/mod.rs b/character_window/src/inventory/mod.rs index d8a6867..9b284c0 100644 --- a/character_window/src/inventory/mod.rs +++ b/character_window/src/inventory/mod.rs @@ -456,7 +456,7 @@ impl Page for InventoryPage { // check if jewel page is open if self.current_mode == 1 { if JewelRightSide::combine::(world, self.hero)? { - JewelRightSide::clear(world); + JewelRightSide::clear(world)?; self.update_page(world, true)?; } diff --git a/rpg_components/src/components/item_slots.rs b/rpg_components/src/components/item_slots.rs index abcfef3..c6bea9d 100644 --- a/rpg_components/src/components/item_slots.rs +++ b/rpg_components/src/components/item_slots.rs @@ -125,10 +125,8 @@ macro_rules! store_item { macro_rules! setter { ($item:ident) => { paste::paste! { - fn [](&mut self, $item: Option, entity: &mut EntityObject) { + fn [](&mut self, $item: Option) { self.$item = $item; - - self.[](entity).unwrap(); } } }; @@ -152,10 +150,6 @@ pub struct ItemSlotContainer { // jewelry slots rings: [Option; RING_COUNT], amulets: [Option; AMULET_COUNT], - - slot_changed_callback: Option< - Box Result<()> + Send + Sync>, - >, } impl ItemSlotContainer { @@ -172,8 +166,6 @@ impl ItemSlotContainer { rings: [None, None, None, None], amulets: [None, None], - - slot_changed_callback: None, } } @@ -348,104 +340,6 @@ impl ItemSlotContainer { fn set_amulets(&mut self, amulet: Option, index: usize) { self.amulets[index] = amulet; } - - fn apply_helmet_change(&mut self, entity: &mut EntityObject) -> Result<()> { - self.apply_item_change( - ItemSlots::Helmet, - match &self.helmet { - Some(helmet) => helmet.rarity, - None => Rarities::Common, - }, - self.helmet.is_some(), - entity, - ) - } - - fn apply_belt_change(&mut self, entity: &mut EntityObject) -> Result<()> { - self.apply_item_change( - ItemSlots::Belt, - match &self.belt { - Some(belt) => belt.rarity, - None => Rarities::Common, - }, - self.belt.is_some(), - entity, - ) - } - - fn apply_chest_plate_change(&mut self, entity: &mut EntityObject) -> Result<()> { - self.apply_item_change( - ItemSlots::ChestPlate, - match &self.chest_plate { - Some(chest_plate) => chest_plate.rarity, - None => Rarities::Common, - }, - self.chest_plate.is_some(), - entity, - ) - } - - fn apply_gloves_change(&mut self, entity: &mut EntityObject) -> Result<()> { - self.apply_item_change( - ItemSlots::Gloves, - match &self.gloves { - Some(gloves) => gloves.rarity, - None => Rarities::Common, - }, - self.gloves.is_some(), - entity, - ) - } - - fn apply_boots_change(&mut self, entity: &mut EntityObject) -> Result<()> { - self.apply_item_change( - ItemSlots::Boots, - match &self.boots { - Some(boots) => boots.rarity, - None => Rarities::Common, - }, - self.boots.is_some(), - entity, - ) - } - - fn apply_main_hand_change(&mut self, entity: &mut EntityObject) -> Result<()> { - self.apply_item_change( - ItemSlots::MainHand, - match &self.main_hand { - Some(main_hand) => main_hand.rarity, - None => Rarities::Common, - }, - self.main_hand.is_some(), - entity, - ) - } - - fn apply_off_hand_change(&mut self, entity: &mut EntityObject) -> Result<()> { - self.apply_item_change( - ItemSlots::OffHand, - match &self.off_hand { - Some(off_hand) => off_hand.rarity, - None => Rarities::Common, - }, - self.off_hand.is_some(), - entity, - ) - } - - fn apply_item_change( - &self, - item_slot: ItemSlots, - rarity: Rarities, - is_some: bool, - entity: &mut EntityObject, - ) -> Result<()> { - if let Some(slot_changed_callback) = &self.slot_changed_callback { - slot_changed_callback(item_slot, rarity, is_some, entity)?; - } - - Ok(()) - } } // getter @@ -503,99 +397,99 @@ impl ItemSlotContainer { // setter impl ItemSlotContainer { - fn _update_helmet(&mut self, helmet: Item, entity: &mut EntityObject) { + fn _update_helmet(&mut self, helmet: Item) { debug_assert!(helmet.slot == ItemSlots::Helmet); - self.set_helmet(Some(helmet), entity); + self.set_helmet(Some(helmet)); } - pub fn unset_helmet(&mut self, entity: &mut EntityObject) -> Result<()> { + pub fn unset_helmet(&mut self) -> Result<()> { if self.helmet.is_some() { - self.set_helmet(None, entity); + self.set_helmet(None); } Ok(()) } - fn update_chest(&mut self, chest: Item, entity: &mut EntityObject) { + fn update_chest(&mut self, chest: Item) { debug_assert!(chest.slot == ItemSlots::ChestPlate); - self.set_chest_plate(Some(chest), entity); + self.set_chest_plate(Some(chest)); } - pub fn unset_chest(&mut self, entity: &mut EntityObject) -> Result<()> { + pub fn unset_chest(&mut self) -> Result<()> { if self.chest_plate.is_some() { - self.set_chest_plate(None, entity); + self.set_chest_plate(None); } Ok(()) } - fn _update_belt(&mut self, belt: Item, entity: &mut EntityObject) { + fn _update_belt(&mut self, belt: Item) { debug_assert!(belt.slot == ItemSlots::Belt); - self.set_belt(Some(belt), entity); + self.set_belt(Some(belt)); } - pub fn unset_belt(&mut self, entity: &mut EntityObject) -> Result<()> { + pub fn unset_belt(&mut self) -> Result<()> { if self.belt.is_some() { - self.set_belt(None, entity); + self.set_belt(None); } Ok(()) } - fn _update_gloves(&mut self, gloves: Item, entity: &mut EntityObject) { + fn _update_gloves(&mut self, gloves: Item) { debug_assert!(gloves.slot == ItemSlots::Gloves); - self.set_gloves(Some(gloves), entity); + self.set_gloves(Some(gloves)); } - pub fn unset_gloves(&mut self, entity: &mut EntityObject) -> Result<()> { + pub fn unset_gloves(&mut self) -> Result<()> { if self.gloves.is_some() { - self.set_gloves(None, entity); + self.set_gloves(None); } Ok(()) } - fn _update_boots(&mut self, boots: Item, entity: &mut EntityObject) { + fn _update_boots(&mut self, boots: Item) { debug_assert!(boots.slot == ItemSlots::Boots); - self.set_boots(Some(boots), entity); + self.set_boots(Some(boots)); } - pub fn unset_boots(&mut self, entity: &mut EntityObject) -> Result<()> { + pub fn unset_boots(&mut self) -> Result<()> { if self.boots.is_some() { - self.set_boots(None, entity); + self.set_boots(None); } Ok(()) } - fn update_primary_hand(&mut self, primary_hand: Item, entity: &mut EntityObject) { + fn update_primary_hand(&mut self, primary_hand: Item) { debug_assert!(primary_hand.slot == ItemSlots::MainHand); - self.set_main_hand(Some(primary_hand), entity); + self.set_main_hand(Some(primary_hand)); } - pub fn unset_primary_hand(&mut self, entity: &mut EntityObject) -> Result<()> { + pub fn unset_primary_hand(&mut self) -> Result<()> { if self.main_hand.is_some() { - self.set_main_hand(None, entity); + self.set_main_hand(None); } Ok(()) } - fn update_secondary_hand(&mut self, secondary_hand: Item, entity: &mut EntityObject) { + fn update_secondary_hand(&mut self, secondary_hand: Item) { debug_assert!(secondary_hand.slot == ItemSlots::OffHand); - self.set_off_hand(Some(secondary_hand), entity); + self.set_off_hand(Some(secondary_hand)); } - pub fn unset_secondary_hand(&mut self, entity: &mut EntityObject) -> Result<()> { + pub fn unset_secondary_hand(&mut self) -> Result<()> { if self.off_hand.is_some() { - self.set_off_hand(None, entity); + self.set_off_hand(None); } Ok(()) @@ -689,14 +583,14 @@ impl ItemSlotContainer { #[inline] fn _check_items( + &self, draw: &mut Draw, location: &Location, - items: &ItemSlotContainer, item_meshes: &HashMap>, ) -> Result<()> { macro_rules! check { ($func:ident, $name:expr) => { - match items.$func() { + match self.$func() { Some(item) => { Self::_dress(draw, location, item_meshes, $name, item.slot, item.rarity)?; } @@ -779,53 +673,44 @@ impl ItemSlotContainer { } /// inserts the item, returns the current item at this slot - pub fn insert( - &mut self, - item: Item, - attributes: &Attributes, - entity: &mut EntityObject, - ) -> Result> { + pub fn insert(&mut self, item: Item, attributes: &Attributes) -> Result> { // check attribute requirements if attributes < &item.attributes { return Ok(Some(item)); } - self.insert_unchecked(item, entity) + self.insert_unchecked(item) } - pub fn insert_unchecked( - &mut self, - item: Item, - entity: &mut EntityObject, - ) -> Result> { + pub fn insert_unchecked(&mut self, item: Item) -> Result> { Ok(match item.slot { ItemSlots::Helmet => { let current_helmet = self.helmet.clone(); - self._update_helmet(item, entity); + self._update_helmet(item); current_helmet } ItemSlots::ChestPlate => { let current_chest_plate = self.chest_plate.clone(); - self.update_chest(item, entity); + self.update_chest(item); current_chest_plate } ItemSlots::Belt => { let current_belt = self.belt.clone(); - self._update_belt(item, entity); + self._update_belt(item); current_belt } ItemSlots::Gloves => { let current_gloves = self.gloves.clone(); - self._update_gloves(item, entity); + self._update_gloves(item); current_gloves } ItemSlots::Boots => { let current_boots = self.boots.clone(); - self._update_boots(item, entity); + self._update_boots(item); current_boots } @@ -855,13 +740,13 @@ impl ItemSlotContainer { } ItemSlots::MainHand => { let current_main_hand = self.main_hand.clone(); - self.update_primary_hand(item, entity); + self.update_primary_hand(item); current_main_hand } ItemSlots::OffHand => { let current_off_hand = self.off_hand.clone(); - self.update_secondary_hand(item, entity); + self.update_secondary_hand(item); current_off_hand } diff --git a/rpg_components/src/components/statistics.rs b/rpg_components/src/components/statistics.rs index 2094626..f1ec13d 100644 --- a/rpg_components/src/components/statistics.rs +++ b/rpg_components/src/components/statistics.rs @@ -135,7 +135,6 @@ impl Statistics { &mut self, attributes: &mut Attributes, attribute_settings: &AttributeSettings, - items: impl Into>, ) { *self = Self::default();