Remove unneeded arc

This commit is contained in:
hodasemi 2024-08-26 15:44:19 +02:00
parent 4db8aefed1
commit d047abbfb7
4 changed files with 13 additions and 21 deletions

View file

@ -328,7 +328,7 @@ impl JewelRightSide {
} }
let item_settings = resources.get::<ItemSettings>(); let item_settings = resources.get::<ItemSettings>();
let item_system = resources.get::<Arc<ItemSystem>>(); let item_system = resources.get::<ItemSystem>();
let inventory = entity.get_component_mut::<Inventory>()?; let inventory = entity.get_component_mut::<Inventory>()?;

View file

@ -435,10 +435,10 @@ impl Hero {
match hero_create_type { match hero_create_type {
HeroCreateType::SaveGame(save_game) => { HeroCreateType::SaveGame(save_game) => {
AbilitySlots::load(game.item_system(), save_game) AbilitySlots::load(&game.item_system(), save_game)
} }
HeroCreateType::New(_) => { HeroCreateType::New(_) => {
let mut abilities = AbilitySlots::empty(game.item_system()); let mut abilities = AbilitySlots::empty();
let book = game_handle.upgrade().item_system().ability_book( let book = game_handle.upgrade().item_system().ability_book(
"Basic Attack", "Basic Attack",

View file

@ -6,7 +6,6 @@ use paste;
use std::{ use std::{
slice::{Iter, IterMut}, slice::{Iter, IterMut},
str::FromStr, str::FromStr,
sync::Arc,
}; };
use crate::config::save_game::SaveGame; use crate::config::save_game::SaveGame;
@ -14,12 +13,10 @@ use crate::items::{ability_addon::AbilityAddonTypes, ability_book::AbilityBook,
use crate::{components::inventory::Storable, items::ItemSystem}; use crate::{components::inventory::Storable, items::ItemSystem};
macro_rules! load { macro_rules! load {
($me: ident, $save_game:ident, $($index:literal,)+) => { ($me: ident, $item_system:ident, $save_game:ident, $($index:literal,)+) => {
paste::expr! { paste::expr! {
$( $(
if $save_game.[<ability_ $index>].used { if $save_game.[<ability_ $index>].used {
let item_system = &$me.item_system;
let ability = &$save_game.[<ability_ $index>]; let ability = &$save_game.[<ability_ $index>];
let mut addons = Vec::new(); let mut addons = Vec::new();
@ -30,10 +27,10 @@ macro_rules! load {
let rarity = Rarities::from_str(&split.nth(0).unwrap())?; let rarity = Rarities::from_str(&split.nth(0).unwrap())?;
let addon_type = AbilityAddonTypes::from_str(&split.nth(0).unwrap())?; let addon_type = AbilityAddonTypes::from_str(&split.nth(0).unwrap())?;
addons.push(Some(item_system.addon(rarity, addon_type))); addons.push(Some($item_system.addon(rarity, addon_type)));
} }
let book = item_system.ability_book( let book = $item_system.ability_book(
&ability.name, &ability.name,
ability.rarity, ability.rarity,
addons, addons,
@ -71,8 +68,6 @@ macro_rules! store {
} }
pub struct AbilitySlots { pub struct AbilitySlots {
item_system: Arc<ItemSystem>,
pub direction: Vector2<f32>, pub direction: Vector2<f32>,
abilities: [Option<AbilityBook>; AbilitySlots::MAX_ABILITIES], abilities: [Option<AbilityBook>; AbilitySlots::MAX_ABILITIES],
@ -82,20 +77,17 @@ impl AbilitySlots {
// stupid workaround for serde Deserialize // stupid workaround for serde Deserialize
pub const MAX_ABILITIES: usize = 4; pub const MAX_ABILITIES: usize = 4;
pub fn empty(item_system: Arc<ItemSystem>) -> Self { pub fn empty() -> Self {
Self { Self {
item_system,
direction: Vector2::zero(), direction: Vector2::zero(),
abilities: Default::default(), abilities: Default::default(),
} }
} }
pub fn load(item_system: Arc<ItemSystem>, save_game: &SaveGame) -> Result<Self> { pub fn load(item_system: &ItemSystem, save_game: &SaveGame) -> Result<Self> {
let mut me = Self::empty(item_system); let mut me = Self::empty();
load!(me, save_game, 0, 1, 2, 3,); load!(me, item_system, save_game, 0, 1, 2, 3,);
Ok(me) Ok(me)
} }

View file

@ -10,7 +10,7 @@ use crate::{
items::{ItemAffix, ItemSystem, Rarities}, items::{ItemAffix, ItemSystem, Rarities},
}; };
use std::{env::var, sync::Arc}; use std::env::var;
use super::{attributes::AttributeSettings, experience::ExperienceSettings, items::ItemSettings}; use super::{attributes::AttributeSettings, experience::ExperienceSettings, items::ItemSettings};
@ -365,7 +365,7 @@ impl SaveGame {
let experience_settings = scene.resources.get::<ExperienceSettings>(); let experience_settings = scene.resources.get::<ExperienceSettings>();
let attribute_settings = scene.resources.get::<AttributeSettings>(); let attribute_settings = scene.resources.get::<AttributeSettings>();
let item_settings = scene.resources.get::<ItemSettings>(); let item_settings = scene.resources.get::<ItemSettings>();
let item_system = scene.resources.get::<Arc<ItemSystem>>(); let item_system = scene.resources.get::<ItemSystem>();
let mut entity_object = engine.assets().empty_entity(); let mut entity_object = engine.assets().empty_entity();
@ -380,7 +380,7 @@ impl SaveGame {
self.general.intelligence, self.general.intelligence,
); );
let inventory = Inventory::load(&self, &item_system)?; let inventory = Inventory::load(&self, &item_system)?;
let abilities = AbilitySlots::load(item_system.clone(), &self)?; let abilities = AbilitySlots::load(item_system, &self)?;
let crafting_materials = CraftingMaterials::load(&self); let crafting_materials = CraftingMaterials::load(&self);
let items = ItemSlotContainer::load(&self, &item_system)?; let items = ItemSlotContainer::load(&self, &item_system)?;
let mut statistics = Statistics::default(); let mut statistics = Statistics::default();