From 3cf0aac6bdaa301648e56e9fcd56e59ac9949b50 Mon Sep 17 00:00:00 2001 From: clayamore Date: Sat, 23 Mar 2024 20:31:53 +0100 Subject: [PATCH] Added changed indcitaor for inventory and equipment to prevent updating save file if not changed --- src/ui/equipment.rs | 10 ++++++++++ src/vm/equipment.rs | 2 ++ src/vm/inventory/add_bulk.rs | 4 ++++ src/vm/inventory/add_single.rs | 4 ++++ src/vm/inventory/mod.rs | 5 ++++- src/vm/vm.rs | 16 +++++++++++++++- 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/ui/equipment.rs b/src/ui/equipment.rs index ddb6cfc..18947e2 100644 --- a/src/ui/equipment.rs +++ b/src/ui/equipment.rs @@ -327,6 +327,11 @@ pub mod equipment { ui.label("Equipped"); } else if ui.add_sized([100., 24.], egui::Button::new("Unequip").fill(Color32::LIGHT_RED)).clicked() { + + // Mark this section as changed so when the file is + // saved then it will write this section to the file + equipment_vm.changed = true; + match &inventory_vm.current_subtype_route { InventorySubTypeRoute::None => {}, InventorySubTypeRoute::WeaponLeft => { @@ -429,6 +434,11 @@ pub mod equipment { } else { if ui.add_sized([100., 24.], egui::Button::new("Equip")).clicked() { + + // Mark this section as changed so when the file is + // saved then it will write this section to the file + equipment_vm.changed = true; + match &inventory_vm.current_subtype_route { InventorySubTypeRoute::None => {}, InventorySubTypeRoute::WeaponLeft => { diff --git a/src/vm/equipment.rs b/src/vm/equipment.rs index 8fa9b73..b3da90a 100644 --- a/src/vm/equipment.rs +++ b/src/vm/equipment.rs @@ -30,6 +30,8 @@ pub mod equipment_view_model { pub current_equipped_items: Vec, pub current_index: usize, + + pub changed: bool, } impl EquipmentViewModel { diff --git a/src/vm/inventory/add_bulk.rs b/src/vm/inventory/add_bulk.rs index f5e55b8..e8b0443 100644 --- a/src/vm/inventory/add_bulk.rs +++ b/src/vm/inventory/add_bulk.rs @@ -47,6 +47,10 @@ impl InventoryViewModel { } pub fn add_all_to_inventory(&mut self) { + // Mark this section as changed so when the file is + // saved then it will write this section to the file + self.changed = true; + let items = match self.current_bulk_type_route { InventoryTypeRoute::KeyItems | InventoryTypeRoute::CommonItems => { diff --git a/src/vm/inventory/add_single.rs b/src/vm/inventory/add_single.rs index d7a8541..b3afd12 100644 --- a/src/vm/inventory/add_single.rs +++ b/src/vm/inventory/add_single.rs @@ -23,6 +23,10 @@ impl InventoryViewModel { return; } + // Mark this section as changed so when the file is + // saved then it will write this section to the file + self.changed = true; + // Handle item add match item.item_type { InventoryItemType::WEAPON => { diff --git a/src/vm/inventory/mod.rs b/src/vm/inventory/mod.rs index be68fdc..8f613e6 100644 --- a/src/vm/inventory/mod.rs +++ b/src/vm/inventory/mod.rs @@ -169,7 +169,7 @@ impl InventoryItemViewModel { quantity: item_info.quantity, inventory_index: item_info.inventory_index, equip_index: equip_index, - r#type: gaitem_type + r#type: gaitem_type, } } } @@ -222,6 +222,9 @@ pub struct InventoryViewModel { pub naked_arms: InventoryItemViewModel, pub naked_legs: InventoryItemViewModel, + // Changed indicator + pub changed: bool, + // Log pub log: Vec, diff --git a/src/vm/vm.rs b/src/vm/vm.rs index 7584eb4..4951524 100644 --- a/src/vm/vm.rs +++ b/src/vm/vm.rs @@ -85,7 +85,6 @@ pub mod vm { } pub fn update_save(&self, save_type: &mut SaveType) { - let steam_id = self.steam_id.parse::().expect(""); // Update SteamID for UserData10 save_type.set_global_steam_id(steam_id); @@ -163,6 +162,11 @@ pub mod vm { let general_vm = &self.slots[index].general_vm; let inventory_vm = &self.slots[index].inventory_vm; + // Don't update savefile equipment if it has not been changed + if !inventory_vm.changed { + return; + } + // Map somber to normal weapon upgrade let somber_to_normal: HashMap = HashMap::from([ (0, 0), (1, 0),(2, 5), (3, 7), (4, 10), (5, 12), @@ -235,6 +239,11 @@ pub mod vm { fn update_equipment(&self, save_type: &mut SaveType, index: usize) { let equipment_vm = &self.slots[index].equipment_vm; + // Don't update savefile equipment if it has not been changed + if !equipment_vm.changed { + return; + } + // (gaitem_handle, item_id, equipment_index) let mut quickslots = [(0, u32::MAX, u32::MAX); 10]; let mut pouch_items = [(0, u32::MAX, u32::MAX); 6]; @@ -359,6 +368,11 @@ pub mod vm { let inventory_held = &inventory_vm.storage[0]; let inventory_storage_box = &inventory_vm.storage[1]; + // Don't update savefile equipment if it has not been changed + if !inventory_vm.changed { + return; + } + // Update gaitem map save_type.set_gaitem_map(index, inventory_vm.gaitem_map.clone());