Skip to content

Commit

Permalink
Added changed indcitaor for inventory and equipment to prevent updati…
Browse files Browse the repository at this point in the history
…ng save file if not changed
  • Loading branch information
clayamore committed Mar 23, 2024
1 parent df15b0c commit 3cf0aac
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/ui/equipment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down
2 changes: 2 additions & 0 deletions src/vm/equipment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub mod equipment_view_model {

pub current_equipped_items: Vec<u32>,
pub current_index: usize,

pub changed: bool,
}

impl EquipmentViewModel {
Expand Down
4 changes: 4 additions & 0 deletions src/vm/inventory/add_bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
4 changes: 4 additions & 0 deletions src/vm/inventory/add_single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
5 changes: 4 additions & 1 deletion src/vm/inventory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down Expand Up @@ -222,6 +222,9 @@ pub struct InventoryViewModel {
pub naked_arms: InventoryItemViewModel,
pub naked_legs: InventoryItemViewModel,

// Changed indicator
pub changed: bool,

// Log
pub log: Vec<String>,

Expand Down
16 changes: 15 additions & 1 deletion src/vm/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ pub mod vm {
}

pub fn update_save(&self, save_type: &mut SaveType) {

let steam_id = self.steam_id.parse::<u64>().expect("");
// Update SteamID for UserData10
save_type.set_global_steam_id(steam_id);
Expand Down Expand Up @@ -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<u8, u8> = HashMap::from([
(0, 0), (1, 0),(2, 5), (3, 7), (4, 10), (5, 12),
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit 3cf0aac

Please sign in to comment.