mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fixed items with components having incorrect hashes
This commit is contained in:
parent
558e2aefb7
commit
e69aa8c4ee
@ -369,7 +369,7 @@ use std::hash::{Hash, Hasher};
|
|||||||
impl Hash for Item {
|
impl Hash for Item {
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
self.item_definition_id().hash(state);
|
self.item_definition_id().hash(state);
|
||||||
self.components.hash(state);
|
self.components.iter().for_each(|comp| comp.hash(state));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,23 +666,17 @@ impl Item {
|
|||||||
ability_map: &AbilityMap,
|
ability_map: &AbilityMap,
|
||||||
msm: &MaterialStatManifest,
|
msm: &MaterialStatManifest,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let item_hash = {
|
|
||||||
let mut s = DefaultHasher::new();
|
|
||||||
inner_item.item_definition_id().hash(&mut s);
|
|
||||||
components.hash(&mut s);
|
|
||||||
s.finish()
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut item = Item {
|
let mut item = Item {
|
||||||
item_id: Arc::new(AtomicCell::new(None)),
|
item_id: Arc::new(AtomicCell::new(None)),
|
||||||
amount: NonZeroU32::new(1).unwrap(),
|
amount: NonZeroU32::new(1).unwrap(),
|
||||||
components,
|
components,
|
||||||
slots: vec![None; inner_item.num_slots() as usize],
|
slots: vec![None; inner_item.num_slots() as usize],
|
||||||
item_base: inner_item,
|
item_base: inner_item,
|
||||||
|
// Updated immediately below
|
||||||
item_config: None,
|
item_config: None,
|
||||||
hash: item_hash,
|
hash: 0,
|
||||||
};
|
};
|
||||||
item.update_item_config(ability_map, msm);
|
item.update_item_state(ability_map, msm);
|
||||||
item
|
item
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -828,10 +822,20 @@ impl Item {
|
|||||||
self.components.get_mut(index)
|
self.components.get_mut(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_item_config(&mut self, ability_map: &AbilityMap, msm: &MaterialStatManifest) {
|
/// Updates state of an item (important for creation of new items,
|
||||||
|
/// persistence, and if components are ever added to items after initial
|
||||||
|
/// creation)
|
||||||
|
pub fn update_item_state(&mut self, ability_map: &AbilityMap, msm: &MaterialStatManifest) {
|
||||||
|
// Updates item config of an item
|
||||||
if let Ok(item_config) = ItemConfig::try_from((&*self, ability_map, msm)) {
|
if let Ok(item_config) = ItemConfig::try_from((&*self, ability_map, msm)) {
|
||||||
self.item_config = Some(Box::new(item_config));
|
self.item_config = Some(Box::new(item_config));
|
||||||
}
|
}
|
||||||
|
// Updates hash of an item
|
||||||
|
self.hash = {
|
||||||
|
let mut s = DefaultHasher::new();
|
||||||
|
self.hash(&mut s);
|
||||||
|
s.finish()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator that drains items contained within the item's slots
|
/// Returns an iterator that drains items contained within the item's slots
|
||||||
|
@ -403,14 +403,14 @@ impl Loadout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn persistence_update_all_item_configs(
|
pub fn persistence_update_all_item_states(
|
||||||
&mut self,
|
&mut self,
|
||||||
ability_map: &item::tool::AbilityMap,
|
ability_map: &item::tool::AbilityMap,
|
||||||
msm: &item::tool::MaterialStatManifest,
|
msm: &item::tool::MaterialStatManifest,
|
||||||
) {
|
) {
|
||||||
self.slots.iter_mut().for_each(|slot| {
|
self.slots.iter_mut().for_each(|slot| {
|
||||||
if let Some(item) = &mut slot.slot {
|
if let Some(item) = &mut slot.slot {
|
||||||
item.update_item_config(ability_map, msm);
|
item.update_item_state(ability_map, msm);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -784,14 +784,14 @@ impl Inventory {
|
|||||||
|
|
||||||
pub fn swap_equipped_weapons(&mut self) { self.loadout.swap_equipped_weapons() }
|
pub fn swap_equipped_weapons(&mut self) { self.loadout.swap_equipped_weapons() }
|
||||||
|
|
||||||
pub fn persistence_update_all_item_configs(
|
pub fn persistence_update_all_item_states(
|
||||||
&mut self,
|
&mut self,
|
||||||
ability_map: &item::tool::AbilityMap,
|
ability_map: &item::tool::AbilityMap,
|
||||||
msm: &item::tool::MaterialStatManifest,
|
msm: &item::tool::MaterialStatManifest,
|
||||||
) {
|
) {
|
||||||
self.slots_mut().for_each(|mut slot| {
|
self.slots_mut().for_each(|mut slot| {
|
||||||
if let Some(item) = &mut slot {
|
if let Some(item) = &mut slot {
|
||||||
item.update_item_config(ability_map, msm);
|
item.update_item_state(ability_map, msm);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -420,7 +420,7 @@ pub fn convert_inventory_from_database_items(
|
|||||||
|
|
||||||
// Some items may have had components added, so update the item config of each
|
// Some items may have had components added, so update the item config of each
|
||||||
// item to ensure that it correctly accounts for components that were added
|
// item to ensure that it correctly accounts for components that were added
|
||||||
inventory.persistence_update_all_item_configs(&ABILITY_MAP, &MATERIAL_STATS_MANIFEST);
|
inventory.persistence_update_all_item_states(&ABILITY_MAP, &MATERIAL_STATS_MANIFEST);
|
||||||
|
|
||||||
Ok(inventory)
|
Ok(inventory)
|
||||||
}
|
}
|
||||||
@ -483,7 +483,7 @@ pub fn convert_loadout_from_database_items(
|
|||||||
|
|
||||||
// Some items may have had components added, so update the item config of each
|
// Some items may have had components added, so update the item config of each
|
||||||
// item to ensure that it correctly accounts for components that were added
|
// item to ensure that it correctly accounts for components that were added
|
||||||
loadout.persistence_update_all_item_configs(&ABILITY_MAP, &MATERIAL_STATS_MANIFEST);
|
loadout.persistence_update_all_item_states(&ABILITY_MAP, &MATERIAL_STATS_MANIFEST);
|
||||||
|
|
||||||
Ok(loadout)
|
Ok(loadout)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user