Next fixes

This commit is contained in:
hodasemi 2025-04-05 14:18:41 +02:00
parent abf0be7881
commit 93e98f5477
4 changed files with 35 additions and 34 deletions

View file

@ -166,7 +166,8 @@ impl CharacterPage {
let level = entity.get_component::<Level>()?;
let attributes = entity.get_component::<Attributes>()?;
let gui_handler = resources.get::<GuiHandler>();
let (gui_handler, attribute_settings): (&mut GuiHandler, &mut AttributeSettings) =
resources.get_mut()?;
level_label.set_text(gui_handler, format!("Level: {}", level.level()))?;
level_progress.set_text(
@ -178,11 +179,7 @@ impl CharacterPage {
gui_handler,
format!(
"Attributes ({})",
Self::available_attribute_points(
resources.get::<AttributeSettings>(),
attributes,
level
)
Self::available_attribute_points(attribute_settings, attributes, level)
),
)?;
@ -222,15 +219,16 @@ impl CharacterPage {
let attribute_settings = resources.get::<AttributeSettings>();
let item_settings = resources.get::<ItemSettings>();
let level = multi_mut.get::<Level>()?;
let attributes = multi_mut.get::<Attributes>()?;
let (level, attributes, statistics, items): (
&mut Level,
&mut Attributes,
&mut Statistics,
&mut ItemSlotContainer,
) = entity.get_components_mut()?;
if Self::available_attribute_points(attribute_settings, attributes, level) > 0 {
upgrade(attributes);
let statistics = multi_mut.get::<Statistics>()?;
let items = multi_mut.get::<ItemSlotContainer>()?;
statistics.update(attributes, attribute_settings, (&*items, item_settings));
upgraded = true;

View file

@ -67,21 +67,22 @@ impl<A: Ability + 'static> Content<A, Item> {
fn equip_item(world: &mut World, hero: Entity, item_index: usize) -> Result<()> {
let (entity, resources) = world.entity_resources(hero)?;
let hero_items = multi_mut.get::<ItemSlotContainer>()?;
let inventory = multi_mut.get::<Inventory<A>>()?;
let attributes = multi_mut.get::<Attributes>()?;
let (hero_items, inventory, attributes, statistics): (
&mut ItemSlotContainer,
&mut Inventory<A>,
&mut Attributes,
&mut Statistics,
) = entity.get_components_mut()?;
// remove item from inventory
let item = inventory.remove_item(item_index);
// add or swap items with equipment
if let Some(old_item) = hero_items.insert(item.clone(), attributes, &mut multi_mut)? {
if let Some(old_item) = hero_items.insert(item.clone(), attributes, entity)? {
inventory.insert_item(old_item, item_index);
}
// update hero stats
let statistics = multi_mut.get::<Statistics>()?;
statistics.update(
attributes,
resources.get::<AttributeSettings>(),

View file

@ -232,15 +232,19 @@ impl JewelRightSide {
pub fn combine<A: Ability + 'static>(world: &mut World, hero: Entity) -> Result<bool> {
let (entity, resources) = world.entity_resources(hero)?;
let reference_info = resources.get::<Option<ReferenceObject>>();
let (reference_info, lower_info, item_system, attribute_settings, item_settings): (
&mut ReferenceObject,
&mut LowerJewels,
&mut ItemSystem<A>,
&mut AttributeSettings,
&mut ItemSettings,
) = resources.get_mut()?;
if reference_info.is_none() {
if reference_info.some().is_none() {
return Ok(false);
}
let lower_info = resources.get::<LowerJewels>();
if let Some(upper_info) = reference_info {
if let Some(upper_info) = reference_info.some() {
match upper_info {
ReferenceObject::Item { item, source } => {
// check that is there something in lower
@ -278,11 +282,12 @@ impl JewelRightSide {
}
}
ReferenceItemSource::Slots(opt_index) => {
let attribute_settings = resources.get::<AttributeSettings>();
let item_settings = resources.get::<ItemSettings>();
let inventory = multi_mut.get::<Inventory<A>>()?;
let item_slots = multi_mut.get::<ItemSlotContainer>()?;
let (inventory, item_slots, statistics, attributes): (
&mut Inventory<A>,
&mut ItemSlotContainer,
&mut Statistics,
&mut Attributes,
) = entity.get_components_mut()?;
let slot = item.slot;
let item = item_slots.item_mut(slot, *opt_index).as_mut().unwrap();
@ -309,9 +314,6 @@ impl JewelRightSide {
}
}
let statistics = multi_mut.get::<Statistics>()?;
let attributes = multi_mut.get::<Attributes>()?;
statistics.update(
attributes,
attribute_settings,
@ -332,9 +334,6 @@ impl JewelRightSide {
return Ok(false);
}
let item_settings = resources.get::<ItemSettings>();
let item_system = resources.get::<ItemSystem<A>>();
let inventory = entity.get_component_mut::<Inventory<A>>()?;
let upper_jewel = inventory.jewel_mut_at(*index);
@ -362,6 +361,8 @@ impl JewelRightSide {
debug_assert_eq!(*jewel, inventory.remove_jewel(*i))
});
}
ReferenceObject::Empty => unreachable!(),
}
}

View file

@ -7,6 +7,7 @@ use std::marker::PhantomData;
use std::sync::{Arc, Weak};
use anyhow::Result;
use ecs::*;
use engine::prelude::*;
use rpg_components::components::inventory::Inventory;
use rpg_components::items::ability_book::Ability;
@ -42,7 +43,7 @@ impl<A: Ability + 'static> InventoryPage<A> {
reference: Weak<CharacterWindow>,
close: &Arc<Button>,
) -> Result<Self> {
let gui_handler = world.resources.get_mut()?;
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
let grid = Grid::new(gui_handler, 2, 1, false)?;
let left_base = GuiSnippet::from_str(