Start applying ecs changes
This commit is contained in:
parent
5719bef6a6
commit
ac1af484b8
22 changed files with 140 additions and 133 deletions
|
@ -9,5 +9,6 @@ paste = { workspace = true }
|
|||
downcast-rs = { workspace = true }
|
||||
|
||||
engine = { workspace = true }
|
||||
ecs = { workspace = true }
|
||||
rpg_components = { path = "../rpg_components" }
|
||||
assetpath.workspace = true
|
||||
|
|
|
@ -34,16 +34,18 @@ impl<A: Ability + 'static> AbilityPageRightSide<A> {
|
|||
include_str!("../../resources/abilities/right_side.xml"),
|
||||
)?;
|
||||
|
||||
let mut resources = world.resources.multi_mut();
|
||||
let gui_handler = resources.get::<GuiHandler>();
|
||||
let engine_settings = resources.get::<EngineSettings>();
|
||||
let context = resources.get::<Context>();
|
||||
|
||||
let color_settings = resources
|
||||
let color_settings = world
|
||||
.resources
|
||||
.get::<ItemSettings>()
|
||||
.rarity_color_settings
|
||||
.clone();
|
||||
|
||||
let (gui_handler, engine_settings, context): (
|
||||
&mut GuiHandler,
|
||||
&mut EngineSettings,
|
||||
&mut Context,
|
||||
) = world.resources.get_mut()?;
|
||||
|
||||
Self::rarity_icon_background(gui_handler, &snippet, "common", color_settings.common)?;
|
||||
Self::rarity_icon_background(gui_handler, &snippet, "uncommon", color_settings.uncommon)?;
|
||||
Self::rarity_icon_background(gui_handler, &snippet, "magical", color_settings.magical)?;
|
||||
|
@ -98,7 +100,7 @@ impl<A: Ability + 'static> AbilityPageRightSide<A> {
|
|||
book.create_tooltip(world, statistics, (target_x, target_y))?;
|
||||
gui.enable(world)?;
|
||||
gui.perform_single_check(
|
||||
world.resources.get_mut::<GuiHandler>(),
|
||||
world.resources.get_mut()?,
|
||||
button_pos.0,
|
||||
button_pos.1,
|
||||
)?;
|
||||
|
@ -120,7 +122,6 @@ impl<A: Ability + 'static> AbilityPageRightSide<A> {
|
|||
move |world, button| match button {
|
||||
ControllerButton::Y => {
|
||||
let entity = world.entity_mut(hero)?;
|
||||
let mut multi_mut = entity.multi_mut();
|
||||
|
||||
let abilities = multi_mut.get::<AbilitySlots<A>>()?;
|
||||
|
||||
|
@ -226,7 +227,7 @@ impl<A: Ability + 'static> AbilityPageRightSide<A> {
|
|||
let addon_type: Arc<Label> = addon_type_snippet.element("addon_type")?;
|
||||
let addon_value: Arc<Label> = addon_type_snippet.element("addon_value")?;
|
||||
|
||||
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
||||
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
|
||||
|
||||
addon_icon.set_icon(gui_handler, &addon.icon())?;
|
||||
addon_type.set_text(gui_handler, &format!("{}", addon.addon_type()))?;
|
||||
|
@ -261,7 +262,7 @@ impl<A: Ability + 'static> RightSide for AbilityPageRightSide<A> {
|
|||
|
||||
let crafting = entity.get_component::<CraftingMaterials>()?;
|
||||
|
||||
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
||||
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
|
||||
|
||||
self.update_crafting_count(gui_handler, "common", crafting.count(Rarities::Common))?;
|
||||
self.update_crafting_count(gui_handler, "uncommon", crafting.count(Rarities::Uncommon))?;
|
||||
|
|
|
@ -32,7 +32,7 @@ impl<A: Ability + 'static> Content<A, AbilityAddon> {
|
|||
let addon = inventory.addon_at(addon_index);
|
||||
let gui = addon.create_tooltip(world, (target_x, target_y))?;
|
||||
gui.enable(world)?;
|
||||
gui.perform_single_check(world.resources.get_mut::<GuiHandler>(), x, y)?;
|
||||
gui.perform_single_check(world.resources.get_mut()?, x, y)?;
|
||||
|
||||
let window = reference.upgrade().unwrap();
|
||||
window.add_tooltip(format!("addon_{addon_index}"), gui);
|
||||
|
@ -47,7 +47,6 @@ impl<A: Ability + 'static> Content<A, AbilityAddon> {
|
|||
ability_page: &AbilityPage<A>,
|
||||
) -> Result<()> {
|
||||
let entity = world.entity_mut(hero)?;
|
||||
let mut multi_mut = entity.multi_mut();
|
||||
|
||||
let inventory = multi_mut.get::<Inventory<A>>()?;
|
||||
let abilities = multi_mut.get::<AbilitySlots<A>>()?;
|
||||
|
@ -68,7 +67,7 @@ impl<A: Ability + 'static> ContentUpdate for Content<A, AbilityAddon> {
|
|||
let reference = self.reference.clone();
|
||||
|
||||
self.update_base(world, |world, button, t, index| {
|
||||
button.set_icon(world.resources.get_mut::<GuiHandler>(), &t.icon())?;
|
||||
button.set_icon(world.resources.get_mut()?, &t.icon())?;
|
||||
|
||||
button.set_custom_callback({
|
||||
let reference = reference.clone();
|
||||
|
@ -136,7 +135,7 @@ impl<A: Ability + 'static> ContentUpdate for Content<A, AbilityAddon> {
|
|||
}
|
||||
|
||||
fn select(&self, world: &mut World) -> Result<()> {
|
||||
self.select(world.resources.get_mut::<GuiHandler>())
|
||||
self.select(world.resources.get_mut()?)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,7 +147,6 @@ impl<A: Ability + 'static> Content<A, AbilityBook<A>> {
|
|||
ability_page: &AbilityPage<A>,
|
||||
) -> Result<()> {
|
||||
let entity = world.entity_mut(hero)?;
|
||||
let mut multi_mut = entity.multi_mut();
|
||||
|
||||
let inventory = multi_mut.get::<Inventory<A>>()?;
|
||||
let abilitiy_slots = multi_mut.get::<AbilitySlots<A>>()?;
|
||||
|
@ -194,17 +192,12 @@ impl<A: Ability + 'static> Content<A, AbilityBook<A>> {
|
|||
let compare_gui =
|
||||
selected_book.create_tooltip(world, statistics, (target_x, target_y))?;
|
||||
compare_gui.enable(world)?;
|
||||
gui.perform_double_check(
|
||||
&compare_gui,
|
||||
world.resources.get_mut::<GuiHandler>(),
|
||||
x,
|
||||
2,
|
||||
)?;
|
||||
gui.perform_double_check(&compare_gui, world.resources.get_mut()?, x, 2)?;
|
||||
|
||||
window.add_tooltip("active_book", compare_gui);
|
||||
}
|
||||
None => {
|
||||
gui.perform_single_check(world.resources.get_mut::<GuiHandler>(), x, y)?;
|
||||
gui.perform_single_check(world.resources.get_mut()?, x, y)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,7 +212,7 @@ impl<A: Ability + 'static> ContentUpdate for Content<A, AbilityBook<A>> {
|
|||
let reference = self.reference.clone();
|
||||
|
||||
self.update_base(world, |world, button, t, index| {
|
||||
button.set_icon(world.resources.get_mut::<GuiHandler>(), &t.icon())?;
|
||||
button.set_icon(world.resources.get_mut()?, &t.icon())?;
|
||||
|
||||
button.set_custom_callback({
|
||||
let reference = reference.clone();
|
||||
|
@ -288,6 +281,6 @@ impl<A: Ability + 'static> ContentUpdate for Content<A, AbilityBook<A>> {
|
|||
}
|
||||
|
||||
fn select(&self, world: &mut World) -> Result<()> {
|
||||
self.select(world.resources.get_mut::<GuiHandler>())
|
||||
self.select(world.resources.get_mut()?)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,10 +75,11 @@ impl<A: Ability + 'static> AbilityPage<A> {
|
|||
include_str!("../../resources/abilities/ability_tooltip.xml"),
|
||||
)?;
|
||||
|
||||
let mut resources = world.resources.multi_mut();
|
||||
let gui_handler = resources.get::<GuiHandler>();
|
||||
let engine_settings = resources.get::<EngineSettings>();
|
||||
let context = resources.get::<Context>();
|
||||
let (gui_handler, engine_settings, context): (
|
||||
&mut GuiHandler,
|
||||
&mut EngineSettings,
|
||||
&mut Context,
|
||||
) = world.resources.get_mut()?;
|
||||
|
||||
let equip: Arc<Label> = ui.element("equip")?;
|
||||
equip.set_info_icon(
|
||||
|
@ -129,10 +130,11 @@ impl<A: Ability + 'static> AbilityPage<A> {
|
|||
include_str!("../../resources/abilities/addon_tooltip.xml"),
|
||||
)?;
|
||||
|
||||
let mut resources = world.resources.multi_mut();
|
||||
let gui_handler = resources.get::<GuiHandler>();
|
||||
let engine_settings = resources.get::<EngineSettings>();
|
||||
let context = resources.get::<Context>();
|
||||
let (gui_handler, engine_settings, context): (
|
||||
&mut GuiHandler,
|
||||
&mut EngineSettings,
|
||||
&mut Context,
|
||||
) = world.resources.get_mut()?;
|
||||
|
||||
let equip: Arc<Label> = ui.element("socket")?;
|
||||
equip.set_info_icon(
|
||||
|
@ -265,7 +267,7 @@ impl<A: Ability + 'static> Page for AbilityPage<A> {
|
|||
|
||||
if mode.content().is_empty() {
|
||||
if let Some(close) = self.close.upgrade() {
|
||||
close.select(world.resources.get_mut::<GuiHandler>())?;
|
||||
close.select(world.resources.get_mut()?)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,7 @@ impl CharacterPage {
|
|||
let grid: Arc<Grid> = snippet.element("statistic_tab")?;
|
||||
let name: Arc<Label> = snippet.element("character_name")?;
|
||||
|
||||
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
||||
name.set_text(gui_handler, hero_name)?;
|
||||
name.set_text(world.resources.get_mut()?, hero_name)?;
|
||||
|
||||
let strength: Arc<Button> = snippet.element("strength_field")?;
|
||||
strength.set_callback({
|
||||
|
@ -109,7 +108,7 @@ impl CharacterPage {
|
|||
let (entity, resources) = world.entity_resources(self.hero)?;
|
||||
let statistics = entity.get_component::<Statistics>()?;
|
||||
|
||||
let gui_handler = resources.get_mut::<GuiHandler>();
|
||||
let gui_handler: &mut GuiHandler = resources.get_mut()?;
|
||||
|
||||
air_def.set_text(gui_handler, &format!("{}", statistics.air_resistance.raw()))?;
|
||||
fire_def.set_text(
|
||||
|
@ -163,7 +162,6 @@ impl CharacterPage {
|
|||
let intelligence: Arc<Button> = self.snippet.element("intelligence_field")?;
|
||||
|
||||
let (entity, resources) = world.entity_resources(self.hero)?;
|
||||
let mut resources = resources.multi_mut();
|
||||
|
||||
let level = entity.get_component::<Level>()?;
|
||||
let attributes = entity.get_component::<Attributes>()?;
|
||||
|
@ -220,7 +218,6 @@ impl CharacterPage {
|
|||
let mut upgraded = false;
|
||||
|
||||
let (entity, resources) = world.entity_resources(hero)?;
|
||||
let mut multi_mut = entity.multi_mut();
|
||||
|
||||
let attribute_settings = resources.get::<AttributeSettings>();
|
||||
let item_settings = resources.get::<ItemSettings>();
|
||||
|
@ -265,7 +262,7 @@ impl Page for CharacterPage {
|
|||
|
||||
fn select(&self, world: &mut World) -> Result<()> {
|
||||
let strength: Arc<Button> = self.snippet.element("strength_field")?;
|
||||
strength.select(world.resources.get_mut::<GuiHandler>())?;
|
||||
strength.select(world.resources.get_mut()?)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -43,10 +43,11 @@ impl<A: Ability + 'static, T: Send + Sync> Content<A, T> {
|
|||
{
|
||||
let base = GuiSnippet::from_str(world, include_str!("../resources/content.xml"))?;
|
||||
|
||||
let mut resources = world.resources.multi_mut();
|
||||
let gui_handler = resources.get::<GuiHandler>();
|
||||
let engine_settings = resources.get::<EngineSettings>();
|
||||
let context = resources.get::<Context>();
|
||||
let (gui_handler, engine_settings, context): (
|
||||
&mut GuiHandler,
|
||||
&mut EngineSettings,
|
||||
&mut Context,
|
||||
) = world.resources.get_mut()?;
|
||||
|
||||
let left: Arc<Button> = base.element("left")?;
|
||||
left.set_text(gui_handler, "<")?;
|
||||
|
|
|
@ -389,7 +389,7 @@ impl<A: Ability + 'static> ContentUpdate for Content<A, Jewel> {
|
|||
}
|
||||
|
||||
fn select(&self, world: &mut World) -> Result<()> {
|
||||
self.select(world.resources.get_mut::<GuiHandler>())
|
||||
self.select(world.resources.get_mut()?)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -403,6 +403,6 @@ impl<A: Ability + 'static> ContentUpdate for Content<A, MapItem> {
|
|||
}
|
||||
|
||||
fn select(&self, world: &mut World) -> Result<()> {
|
||||
self.select(world.resources.get_mut::<GuiHandler>())
|
||||
self.select(world.resources.get_mut()?)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,10 +76,11 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
include_str!("../../resources/inventory/items/tooltip.xml"),
|
||||
)?;
|
||||
|
||||
let mut resources = world.resources.multi_mut();
|
||||
let gui_handler = resources.get::<GuiHandler>();
|
||||
let engine_settings = resources.get::<EngineSettings>();
|
||||
let context = resources.get::<Context>();
|
||||
let (gui_handler, engine_settings, context): (
|
||||
&mut GuiHandler,
|
||||
&mut EngineSettings,
|
||||
&mut Context,
|
||||
) = world.resources.get_mut()?;
|
||||
|
||||
let equip: Arc<Label> = ui.element("equip")?;
|
||||
equip.set_info_icon(
|
||||
|
@ -135,10 +136,11 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
include_str!("../../resources/inventory/jewels/tooltip.xml"),
|
||||
)?;
|
||||
|
||||
let mut resources = world.resources.multi_mut();
|
||||
let gui_handler = resources.get::<GuiHandler>();
|
||||
let engine_settings = resources.get::<EngineSettings>();
|
||||
let context = resources.get::<Context>();
|
||||
let (gui_handler, engine_settings, context): (
|
||||
&mut GuiHandler,
|
||||
&mut EngineSettings,
|
||||
&mut Context,
|
||||
) = world.resources.get_mut()?;
|
||||
|
||||
let socket: Arc<Label> = ui.element("socket")?;
|
||||
socket.set_info_icon(
|
||||
|
@ -186,10 +188,11 @@ impl<A: Ability + 'static> InventoryPage<A> {
|
|||
include_str!("../../resources/inventory/maps/tooltip.xml"),
|
||||
)?;
|
||||
|
||||
let mut resources = world.resources.multi_mut();
|
||||
let gui_handler = resources.get::<GuiHandler>();
|
||||
let engine_settings = resources.get::<EngineSettings>();
|
||||
let context = resources.get::<Context>();
|
||||
let (gui_handler, engine_settings, context): (
|
||||
&mut GuiHandler,
|
||||
&mut EngineSettings,
|
||||
&mut Context,
|
||||
) = world.resources.get_mut()?;
|
||||
|
||||
let select: Arc<Label> = ui.element("select")?;
|
||||
select.set_info_icon(
|
||||
|
|
|
@ -7,6 +7,7 @@ mod traits;
|
|||
|
||||
use anyhow::Result;
|
||||
use downcast_rs::{Downcast, impl_downcast};
|
||||
use ecs::*;
|
||||
use engine::prelude::*;
|
||||
use rpg_components::{
|
||||
components::{
|
||||
|
@ -249,10 +250,9 @@ impl CharacterWindow {
|
|||
S: Storable,
|
||||
{
|
||||
let entity = world.entity_mut(hero)?;
|
||||
let mut multi_mut = entity.multi_mut();
|
||||
|
||||
let crafting_materials = multi_mut.get::<CraftingMaterials>()?;
|
||||
let inventory = multi_mut.get::<Inventory<A>>()?;
|
||||
let (crafting_materials, inventory): (&mut CraftingMaterials, &mut Inventory<A>) =
|
||||
entity.get_components_mut()?;
|
||||
|
||||
// remove callback
|
||||
let storable = f(inventory);
|
||||
|
@ -287,10 +287,11 @@ impl TopLevelGui for CharacterWindow {
|
|||
self.tab_content_grid.attach(world, child, 0, 0, 1, 1)?;
|
||||
self.tab().select(world)?;
|
||||
|
||||
let mut resources = world.resources.multi_mut();
|
||||
let gui_handler = resources.get::<GuiHandler>();
|
||||
let engine_settings = resources.get::<EngineSettings>();
|
||||
let context = resources.get::<Context>();
|
||||
let (gui_handler, engine_settings, context): (
|
||||
&mut GuiHandler,
|
||||
&mut EngineSettings,
|
||||
&mut Context,
|
||||
) = world.resources.get_mut()?;
|
||||
|
||||
let close_button: Arc<Button> = self.menu_gui.element("close")?;
|
||||
close_button.set_info_icon(
|
||||
|
|
|
@ -8,3 +8,4 @@ anyhow = { workspace = true }
|
|||
rusqlite = { workspace = true }
|
||||
assetpath = { workspace = true }
|
||||
engine = { workspace = true }
|
||||
ecs = { workspace = true }
|
||||
|
|
|
@ -36,6 +36,7 @@ pub enum MapObjectType {
|
|||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct Map {
|
||||
async_db: AsyncDBAccess,
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ impl SpawnMarkerEntities {
|
|||
flag.clone_component_from::<Location>(entity)?;
|
||||
flag.clone_component_from::<BoundingBox>(entity)?;
|
||||
|
||||
Location::setup(flag.multi_mut())?;
|
||||
Location::setup(&mut flag)?;
|
||||
|
||||
Ok(flag)
|
||||
}
|
||||
|
|
|
@ -10,3 +10,4 @@ assetpath = { workspace = true }
|
|||
serde = { workspace = true }
|
||||
|
||||
engine = { workspace = true }
|
||||
ecs = { workspace = true }
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::collections::HashMap;
|
|||
|
||||
use crate::{
|
||||
config::{items::ItemSettings, save_game::SaveGame},
|
||||
items::{ability_book::Ability, Item, ItemAffix, ItemSlots, ItemSystem, Rarities},
|
||||
items::{Item, ItemAffix, ItemSlots, ItemSystem, Rarities, ability_book::Ability},
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
@ -125,10 +125,10 @@ macro_rules! store_item {
|
|||
macro_rules! setter {
|
||||
($item:ident) => {
|
||||
paste::paste! {
|
||||
fn [<set_ $item>](&mut self, $item: Option<Item>, multi_mut: &mut MultiMut<'_>) {
|
||||
fn [<set_ $item>](&mut self, $item: Option<Item>, entity: &mut EntityObject) {
|
||||
self.$item = $item;
|
||||
|
||||
self.[<apply_ $item _change>](multi_mut).unwrap();
|
||||
self.[<apply_ $item _change>](entity).unwrap();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -154,7 +154,7 @@ pub struct ItemSlotContainer {
|
|||
amulets: [Option<Item>; AMULET_COUNT],
|
||||
|
||||
slot_changed_callback: Option<
|
||||
Box<dyn Fn(ItemSlots, Rarities, bool, &mut MultiMut<'_>) -> Result<()> + Send + Sync>,
|
||||
Box<dyn Fn(ItemSlots, Rarities, bool, &mut EntityObject) -> Result<()> + Send + Sync>,
|
||||
>,
|
||||
}
|
||||
|
||||
|
@ -349,7 +349,7 @@ impl ItemSlotContainer {
|
|||
self.amulets[index] = amulet;
|
||||
}
|
||||
|
||||
fn apply_helmet_change(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
fn apply_helmet_change(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
self.apply_item_change(
|
||||
ItemSlots::Helmet,
|
||||
match &self.helmet {
|
||||
|
@ -357,11 +357,11 @@ impl ItemSlotContainer {
|
|||
None => Rarities::Common,
|
||||
},
|
||||
self.helmet.is_some(),
|
||||
multi_mut,
|
||||
entity,
|
||||
)
|
||||
}
|
||||
|
||||
fn apply_belt_change(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
fn apply_belt_change(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
self.apply_item_change(
|
||||
ItemSlots::Belt,
|
||||
match &self.belt {
|
||||
|
@ -369,11 +369,11 @@ impl ItemSlotContainer {
|
|||
None => Rarities::Common,
|
||||
},
|
||||
self.belt.is_some(),
|
||||
multi_mut,
|
||||
entity,
|
||||
)
|
||||
}
|
||||
|
||||
fn apply_chest_plate_change(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
fn apply_chest_plate_change(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
self.apply_item_change(
|
||||
ItemSlots::ChestPlate,
|
||||
match &self.chest_plate {
|
||||
|
@ -381,11 +381,11 @@ impl ItemSlotContainer {
|
|||
None => Rarities::Common,
|
||||
},
|
||||
self.chest_plate.is_some(),
|
||||
multi_mut,
|
||||
entity,
|
||||
)
|
||||
}
|
||||
|
||||
fn apply_gloves_change(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
fn apply_gloves_change(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
self.apply_item_change(
|
||||
ItemSlots::Gloves,
|
||||
match &self.gloves {
|
||||
|
@ -393,11 +393,11 @@ impl ItemSlotContainer {
|
|||
None => Rarities::Common,
|
||||
},
|
||||
self.gloves.is_some(),
|
||||
multi_mut,
|
||||
entity,
|
||||
)
|
||||
}
|
||||
|
||||
fn apply_boots_change(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
fn apply_boots_change(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
self.apply_item_change(
|
||||
ItemSlots::Boots,
|
||||
match &self.boots {
|
||||
|
@ -405,11 +405,11 @@ impl ItemSlotContainer {
|
|||
None => Rarities::Common,
|
||||
},
|
||||
self.boots.is_some(),
|
||||
multi_mut,
|
||||
entity,
|
||||
)
|
||||
}
|
||||
|
||||
fn apply_main_hand_change(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
fn apply_main_hand_change(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
self.apply_item_change(
|
||||
ItemSlots::MainHand,
|
||||
match &self.main_hand {
|
||||
|
@ -417,11 +417,11 @@ impl ItemSlotContainer {
|
|||
None => Rarities::Common,
|
||||
},
|
||||
self.main_hand.is_some(),
|
||||
multi_mut,
|
||||
entity,
|
||||
)
|
||||
}
|
||||
|
||||
fn apply_off_hand_change(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
fn apply_off_hand_change(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
self.apply_item_change(
|
||||
ItemSlots::OffHand,
|
||||
match &self.off_hand {
|
||||
|
@ -429,7 +429,7 @@ impl ItemSlotContainer {
|
|||
None => Rarities::Common,
|
||||
},
|
||||
self.off_hand.is_some(),
|
||||
multi_mut,
|
||||
entity,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -438,10 +438,10 @@ impl ItemSlotContainer {
|
|||
item_slot: ItemSlots,
|
||||
rarity: Rarities,
|
||||
is_some: bool,
|
||||
multi_mut: &mut MultiMut<'_>,
|
||||
entity: &mut EntityObject,
|
||||
) -> Result<()> {
|
||||
if let Some(slot_changed_callback) = &self.slot_changed_callback {
|
||||
slot_changed_callback(item_slot, rarity, is_some, multi_mut)?;
|
||||
slot_changed_callback(item_slot, rarity, is_some, entity)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -503,99 +503,99 @@ impl ItemSlotContainer {
|
|||
|
||||
// setter
|
||||
impl ItemSlotContainer {
|
||||
fn _update_helmet(&mut self, helmet: Item, multi_mut: &mut MultiMut<'_>) {
|
||||
fn _update_helmet(&mut self, helmet: Item, entity: &mut EntityObject) {
|
||||
debug_assert!(helmet.slot == ItemSlots::Helmet);
|
||||
|
||||
self.set_helmet(Some(helmet), multi_mut);
|
||||
self.set_helmet(Some(helmet), entity);
|
||||
}
|
||||
|
||||
pub fn unset_helmet(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
pub fn unset_helmet(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
if self.helmet.is_some() {
|
||||
self.set_helmet(None, multi_mut);
|
||||
self.set_helmet(None, entity);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_chest(&mut self, chest: Item, multi_mut: &mut MultiMut<'_>) {
|
||||
fn update_chest(&mut self, chest: Item, entity: &mut EntityObject) {
|
||||
debug_assert!(chest.slot == ItemSlots::ChestPlate);
|
||||
|
||||
self.set_chest_plate(Some(chest), multi_mut);
|
||||
self.set_chest_plate(Some(chest), entity);
|
||||
}
|
||||
|
||||
pub fn unset_chest(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
pub fn unset_chest(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
if self.chest_plate.is_some() {
|
||||
self.set_chest_plate(None, multi_mut);
|
||||
self.set_chest_plate(None, entity);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn _update_belt(&mut self, belt: Item, multi_mut: &mut MultiMut<'_>) {
|
||||
fn _update_belt(&mut self, belt: Item, entity: &mut EntityObject) {
|
||||
debug_assert!(belt.slot == ItemSlots::Belt);
|
||||
|
||||
self.set_belt(Some(belt), multi_mut);
|
||||
self.set_belt(Some(belt), entity);
|
||||
}
|
||||
|
||||
pub fn unset_belt(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
pub fn unset_belt(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
if self.belt.is_some() {
|
||||
self.set_belt(None, multi_mut);
|
||||
self.set_belt(None, entity);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn _update_gloves(&mut self, gloves: Item, multi_mut: &mut MultiMut<'_>) {
|
||||
fn _update_gloves(&mut self, gloves: Item, entity: &mut EntityObject) {
|
||||
debug_assert!(gloves.slot == ItemSlots::Gloves);
|
||||
|
||||
self.set_gloves(Some(gloves), multi_mut);
|
||||
self.set_gloves(Some(gloves), entity);
|
||||
}
|
||||
|
||||
pub fn unset_gloves(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
pub fn unset_gloves(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
if self.gloves.is_some() {
|
||||
self.set_gloves(None, multi_mut);
|
||||
self.set_gloves(None, entity);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn _update_boots(&mut self, boots: Item, multi_mut: &mut MultiMut<'_>) {
|
||||
fn _update_boots(&mut self, boots: Item, entity: &mut EntityObject) {
|
||||
debug_assert!(boots.slot == ItemSlots::Boots);
|
||||
|
||||
self.set_boots(Some(boots), multi_mut);
|
||||
self.set_boots(Some(boots), entity);
|
||||
}
|
||||
|
||||
pub fn unset_boots(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
pub fn unset_boots(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
if self.boots.is_some() {
|
||||
self.set_boots(None, multi_mut);
|
||||
self.set_boots(None, entity);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_primary_hand(&mut self, primary_hand: Item, multi_mut: &mut MultiMut<'_>) {
|
||||
fn update_primary_hand(&mut self, primary_hand: Item, entity: &mut EntityObject) {
|
||||
debug_assert!(primary_hand.slot == ItemSlots::MainHand);
|
||||
|
||||
self.set_main_hand(Some(primary_hand), multi_mut);
|
||||
self.set_main_hand(Some(primary_hand), entity);
|
||||
}
|
||||
|
||||
pub fn unset_primary_hand(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
pub fn unset_primary_hand(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
if self.main_hand.is_some() {
|
||||
self.set_main_hand(None, multi_mut);
|
||||
self.set_main_hand(None, entity);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_secondary_hand(&mut self, secondary_hand: Item, multi_mut: &mut MultiMut<'_>) {
|
||||
fn update_secondary_hand(&mut self, secondary_hand: Item, entity: &mut EntityObject) {
|
||||
debug_assert!(secondary_hand.slot == ItemSlots::OffHand);
|
||||
|
||||
self.set_off_hand(Some(secondary_hand), multi_mut);
|
||||
self.set_off_hand(Some(secondary_hand), entity);
|
||||
}
|
||||
|
||||
pub fn unset_secondary_hand(&mut self, multi_mut: &mut MultiMut<'_>) -> Result<()> {
|
||||
pub fn unset_secondary_hand(&mut self, entity: &mut EntityObject) -> Result<()> {
|
||||
if self.off_hand.is_some() {
|
||||
self.set_off_hand(None, multi_mut);
|
||||
self.set_off_hand(None, entity);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -716,14 +716,13 @@ impl ItemSlotContainer {
|
|||
}
|
||||
|
||||
fn _equipment_changed(
|
||||
multi_mut: &mut MultiMut<'_>,
|
||||
entity: &mut EntityObject,
|
||||
item_meshes: &HashMap<ItemSlots, HashMap<Rarities, AssetMesh>>,
|
||||
slot: ItemSlots,
|
||||
rarity: Rarities,
|
||||
is_some: bool,
|
||||
) -> Result<()> {
|
||||
let draw = multi_mut.get::<Draw>().unwrap();
|
||||
let location = multi_mut.get::<Location>().unwrap();
|
||||
let (draw, location): (&mut Draw, &mut Location) = entity.get_components_mut()?;
|
||||
|
||||
let item_name = match slot {
|
||||
ItemSlots::Helmet => "Helmet",
|
||||
|
@ -784,49 +783,49 @@ impl ItemSlotContainer {
|
|||
&mut self,
|
||||
item: Item,
|
||||
attributes: &Attributes,
|
||||
multi_mut: &mut MultiMut<'_>,
|
||||
entity: &mut EntityObject,
|
||||
) -> Result<Option<Item>> {
|
||||
// check attribute requirements
|
||||
if attributes < &item.attributes {
|
||||
return Ok(Some(item));
|
||||
}
|
||||
|
||||
self.insert_unchecked(item, multi_mut)
|
||||
self.insert_unchecked(item, entity)
|
||||
}
|
||||
|
||||
pub fn insert_unchecked(
|
||||
&mut self,
|
||||
item: Item,
|
||||
multi_mut: &mut MultiMut<'_>,
|
||||
entity: &mut EntityObject,
|
||||
) -> Result<Option<Item>> {
|
||||
Ok(match item.slot {
|
||||
ItemSlots::Helmet => {
|
||||
let current_helmet = self.helmet.clone();
|
||||
self._update_helmet(item, multi_mut);
|
||||
self._update_helmet(item, entity);
|
||||
|
||||
current_helmet
|
||||
}
|
||||
ItemSlots::ChestPlate => {
|
||||
let current_chest_plate = self.chest_plate.clone();
|
||||
self.update_chest(item, multi_mut);
|
||||
self.update_chest(item, entity);
|
||||
|
||||
current_chest_plate
|
||||
}
|
||||
ItemSlots::Belt => {
|
||||
let current_belt = self.belt.clone();
|
||||
self._update_belt(item, multi_mut);
|
||||
self._update_belt(item, entity);
|
||||
|
||||
current_belt
|
||||
}
|
||||
ItemSlots::Gloves => {
|
||||
let current_gloves = self.gloves.clone();
|
||||
self._update_gloves(item, multi_mut);
|
||||
self._update_gloves(item, entity);
|
||||
|
||||
current_gloves
|
||||
}
|
||||
ItemSlots::Boots => {
|
||||
let current_boots = self.boots.clone();
|
||||
self._update_boots(item, multi_mut);
|
||||
self._update_boots(item, entity);
|
||||
|
||||
current_boots
|
||||
}
|
||||
|
@ -856,13 +855,13 @@ impl ItemSlotContainer {
|
|||
}
|
||||
ItemSlots::MainHand => {
|
||||
let current_main_hand = self.main_hand.clone();
|
||||
self.update_primary_hand(item, multi_mut);
|
||||
self.update_primary_hand(item, entity);
|
||||
|
||||
current_main_hand
|
||||
}
|
||||
ItemSlots::OffHand => {
|
||||
let current_off_hand = self.off_hand.clone();
|
||||
self.update_secondary_hand(item, multi_mut);
|
||||
self.update_secondary_hand(item, entity);
|
||||
|
||||
current_off_hand
|
||||
}
|
||||
|
|
|
@ -91,5 +91,6 @@ create_settings_container!(
|
|||
intelligence_settings: IntelligenceSettings,
|
||||
starting_attributes: StartingAttributes,
|
||||
attribute_color_settings: AttributeColorSettings,
|
||||
}
|
||||
},
|
||||
Resource,
|
||||
);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use ecs::Resource;
|
||||
use engine::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -33,7 +34,7 @@ create_settings_container!(
|
|||
mob_experience: MobExperienceSettings,
|
||||
experience_curve: ExperienceCurveSettings,
|
||||
},
|
||||
Serialize, Deserialize,
|
||||
Serialize, Deserialize, Resource,
|
||||
);
|
||||
|
||||
impl ExperienceSettings {
|
||||
|
|
|
@ -190,5 +190,6 @@ create_settings_container!(
|
|||
per_strength_stats: PerStrengthLevelStatistics,
|
||||
per_agility_stats: PerAgilityLevelStatistics,
|
||||
per_intelligence_stats: PerIntelligenceLevelStatistics,
|
||||
}
|
||||
},
|
||||
Resource,
|
||||
);
|
||||
|
|
|
@ -366,7 +366,7 @@ impl SaveGame {
|
|||
let mut entity_object = AssetHandler::create(world).empty_entity();
|
||||
|
||||
entity_object.insert_component(Draw::new(Vec::new()));
|
||||
entity_object.insert_component(Audio::new(world.resources.get_mut::<Context>(), None)?);
|
||||
entity_object.insert_component(Audio::new(world.resources.get_mut()?, None)?);
|
||||
Location::new_and_setup(&mut entity_object)?;
|
||||
|
||||
let experience_settings = world.resources.get::<ExperienceSettings>();
|
||||
|
|
|
@ -248,7 +248,7 @@ impl AbilityAddon {
|
|||
pub fn create_tooltip(&self, world: &mut World, position: (i32, i32)) -> Result<Tooltip> {
|
||||
let gui = GuiBuilder::from_str(world, include_str!("../../resources/addon_snippet.xml"))?;
|
||||
|
||||
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
||||
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
|
||||
|
||||
let icon: Arc<Icon> = gui.element("addon_icon")?;
|
||||
let rarity_label: Arc<Label> = gui.element("rarity_label")?;
|
||||
|
|
|
@ -304,7 +304,7 @@ impl<A: Ability> AbilityBook<A> {
|
|||
) -> Result<Tooltip> {
|
||||
let gui = GuiBuilder::from_str(world, include_str!("../../resources/book_snippet.xml"))?;
|
||||
|
||||
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
||||
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
|
||||
|
||||
let ability_name: Arc<Label> = gui.element("ability_name")?;
|
||||
let rarity_label: Arc<Label> = gui.element("rarity_label")?;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use anyhow::Result;
|
||||
use assetpath::AssetPath;
|
||||
use ecs::resources::Resource;
|
||||
use engine::prelude::*;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
@ -51,6 +52,8 @@ pub struct ItemSystem<A: Ability> {
|
|||
abilities: Vec<A>,
|
||||
}
|
||||
|
||||
impl<A: Ability + 'static> Resource for ItemSystem<A> {}
|
||||
|
||||
impl<A: Ability> ItemSystem<A> {
|
||||
pub fn new(
|
||||
world: &mut World,
|
||||
|
|
|
@ -67,7 +67,7 @@ impl Jewel {
|
|||
let inspector_snippet: Arc<GuiBuilder> =
|
||||
GuiBuilder::from_str(world, include_str!("../../resources/jewel_tooltip.xml"))?;
|
||||
|
||||
let gui_handler = world.resources.get_mut::<GuiHandler>();
|
||||
let gui_handler: &mut GuiHandler = world.resources.get_mut()?;
|
||||
|
||||
let main_grid: Arc<Grid> = inspector_snippet.element("main_grid")?;
|
||||
main_grid.change_position_unscaled(gui_handler, position.0, position.1)?;
|
||||
|
|
Loading…
Reference in a new issue