Skip to content

Commit

Permalink
Added affinity combo box to weapon add and filered aows add list
Browse files Browse the repository at this point in the history
  • Loading branch information
clayamore committed Aug 8, 2024
1 parent 8ba5353 commit 6fc887c
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 5,474 deletions.
662 changes: 0 additions & 662 deletions src/db/armor_name.rs

This file was deleted.

1,815 changes: 0 additions & 1,815 deletions src/db/item_name.rs

This file was deleted.

2,983 changes: 0 additions & 2,983 deletions src/db/weapon_name.rs

This file was deleted.

4 changes: 0 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ fn main() -> Result<(), eframe::Error> {
pub struct App {
save_api: Option<SaveApi>, // Save Api
vm: ViewModel, // ViewModel from the save data
backup_dir: Option<PathBuf>, // Directory containing backup saves
picked_path: PathBuf, // Path to current save file for future use when opening dialogs
current_route: Route, // Current in app view
importer_vm: ImporterViewModel, // ViewModel used for the importer
Expand All @@ -118,7 +117,6 @@ impl App {
pub fn new(_cc: &eframe::CreationContext<'_>) -> Self {
Self {
save_api: None,
backup_dir: None,
picked_path: Default::default(),
current_route: Route::None,
vm: ViewModel::default(),
Expand Down Expand Up @@ -154,8 +152,6 @@ impl App {

// Create directories for the backups if they don't exist
create_dir_all(&backup_path)?;

self.backup_dir = Some(backup_path.clone());
} else {
return Err(SaveApiError::IoError(std::io::Error::new(
std::io::ErrorKind::NotFound,
Expand Down
21 changes: 17 additions & 4 deletions src/ui/inventory/add/single.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::rc::Rc;
use std::{ops::Deref, rc::Rc};

use eframe::egui::{self, Color32, Layout, Ui};

Expand Down Expand Up @@ -89,7 +89,7 @@ pub(crate) fn single_customization(ui: &mut Ui, inventory_vm: &mut InventoryView
);
ui.add_space(8.);

match &inventory_vm.add_vm.selected_item {
match inventory_vm.add_vm.selected_item.clone() {
// No customization needed for these item categories
SelectedItem::None
| SelectedItem::Armor(_)
Expand Down Expand Up @@ -155,7 +155,7 @@ pub(crate) fn single_customization(ui: &mut Ui, inventory_vm: &mut InventoryView

// Draw available ash of war Infusions combo box if there's any
if item.as_ref().borrow().is_infusable() {
ui.add(egui::Label::new("Ash Of War:"));
ui.label("Ash of War:");
if inventory_vm.add_vm.available_infusions.len() > 0 {
if egui::ComboBox::new("infsuion", "")
.show_index(
Expand All @@ -173,10 +173,23 @@ pub(crate) fn single_customization(ui: &mut Ui, inventory_vm: &mut InventoryView
},
)
.changed()
{};
{
inventory_vm.add_vm.infusion_changed();
};
}
ui.end_row();
}

// Draw available affinity combo box if there's any
if inventory_vm.add_vm.selected_infusion != 0 {
ui.label("Affinity:");
egui::ComboBox::new("affinity", "").show_index(
ui,
&mut inventory_vm.add_vm.selected_affinity,
inventory_vm.add_vm.available_affinities.len(),
|i| inventory_vm.add_vm.available_affinities[i].to_string(),
);
}
});
}
}
Expand Down
39 changes: 35 additions & 4 deletions src/vm/inventory/add/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use er_save_lib::{
};
use strsim::sorensen_dice;

use super::{filter::ParamFilter, item_param::ItemParam};
use super::{affinity::Affinity, filter::ParamFilter, item_param::ItemParam};

#[derive(Default, PartialEq)]
pub(crate) enum AddTypeRoute {
Expand All @@ -24,7 +24,7 @@ pub(crate) struct ParamHeader {
pub(crate) item_type: ItemType,
}

#[derive(Default)]
#[derive(Default, Clone)]
pub(crate) enum SelectedItem {
#[default]
None,
Expand All @@ -50,6 +50,7 @@ pub(crate) struct AddViewModel {
pub(crate) selected_weapon_level: u8,
pub(crate) selected_gem: u8,
pub(crate) selected_infusion: usize,
pub(crate) selected_affinity: usize,

// Params
pub(crate) items: Vec<Rc<RefCell<ItemParam<EquipParamGoods>>>>,
Expand All @@ -61,6 +62,7 @@ pub(crate) struct AddViewModel {
// List used in view
pub(crate) current_list: Vec<Rc<RefCell<ParamHeader>>>,
pub(crate) available_infusions: Vec<Rc<RefCell<ParamHeader>>>,
pub(crate) available_affinities: Vec<Affinity>,
}

impl AddViewModel {
Expand Down Expand Up @@ -130,15 +132,24 @@ impl AddViewModel {
let weapons: Vec<Rc<RefCell<ItemParam<EquipParamWeapon>>>> = self
.weapons
.iter()
.filter(ParamFilter::not_infused)
.filter(ParamFilter::weapons_not_infused)
.map(|item| item.clone())
.collect();
Self::init_list(weapons.iter(), filter_text)
}
ItemType::Armor => Self::init_list(self.armors.iter(), filter_text),
ItemType::Accessory => Self::init_list(self.talismans.iter(), filter_text),
ItemType::Item => Self::init_list(self.items.iter(), filter_text),
ItemType::Aow => Self::init_list(self.aows.iter(), filter_text),
ItemType::Aow => {
// Filter out nameless aows
let aows: Vec<Rc<RefCell<ItemParam<EquipParamGem>>>> = self
.aows
.iter()
.filter(ParamFilter::aows_nameless)
.map(|item| item.clone())
.collect();
Self::init_list(aows.iter(), filter_text)
}
};
self.current_list.sort_by(|a, b| {
a.as_ref()
Expand Down Expand Up @@ -258,4 +269,24 @@ impl AddViewModel {
.unwrap()
.clone()
}

pub(crate) fn infusion_changed(&mut self) {
let current_infusion = &mut self.available_infusions[self.selected_infusion];
if let Some(gem_param) = self
.aows
.iter()
.find(|item_param| Rc::ptr_eq(&item_param.as_ref().borrow().header, &current_infusion))
{
self.available_affinities = Affinity::available_affinities(gem_param.clone());
let default_affinity = Affinity::default_affinity(gem_param.clone());
self.selected_affinity = self
.available_affinities
.iter()
.position(|affinity| affinity == &default_affinity)
.unwrap();
} else {
self.selected_affinity = 0;
self.available_affinities = Vec::new();
}
}
}
160 changes: 160 additions & 0 deletions src/vm/inventory/add/affinity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
use std::{cell::RefCell, rc::Rc};

use er_save_lib::EquipParamGem::EquipParamGem;

use super::item_param::ItemParam;

#[derive(Default, PartialEq, Debug)]
pub(crate) enum Affinity {
Standard = 0,
Heavy = 100,
Keen = 200,
Quality = 300,
Fire = 400,
FlameArt = 500,
Lightning = 600,
Sacred = 700,
Magic = 800,
Cold = 900,
Poison = 1000,
Blood = 1100,
Occult = 1200,
Unused13,
Unused14,
Unused15,
Unused16,
Unused17,
Unused18,
Unused19,
Unused20,
Unused21,
Unused22,
Unused23,
#[default]
Uknown,
}
impl ToString for Affinity {
fn to_string(&self) -> String {
match self {
Affinity::Standard => format!("Standard"),
Affinity::Heavy => format!("Heavy"),
Affinity::Keen => format!("Keen"),
Affinity::Quality => format!("Quality"),
Affinity::Fire => format!("Fire"),
Affinity::FlameArt => format!("FlameArt"),
Affinity::Lightning => format!("Lightning"),
Affinity::Sacred => format!("Sacred"),
Affinity::Magic => format!("Magic"),
Affinity::Cold => format!("Cold"),
Affinity::Poison => format!("Poison"),
Affinity::Blood => format!("Blood"),
Affinity::Occult => format!("Occult"),
Affinity::Unused13 => format!("Unused13"),
Affinity::Unused14 => format!("Unused14"),
Affinity::Unused15 => format!("Unused15"),
Affinity::Unused16 => format!("Unused16"),
Affinity::Unused17 => format!("Unused17"),
Affinity::Unused18 => format!("Unused18"),
Affinity::Unused19 => format!("Unused19"),
Affinity::Unused20 => format!("Unused20"),
Affinity::Unused21 => format!("Unused21"),
Affinity::Unused22 => format!("Unused22"),
Affinity::Unused23 => format!("Unused23"),
Affinity::Uknown => format!("Uknown"),
}
}
}

impl Affinity {
pub(crate) fn available_affinities(
gem_param: Rc<RefCell<ItemParam<EquipParamGem>>>,
) -> Vec<Self> {
let mut available_affinites = Vec::new();

// Standard
if gem_param.as_ref().borrow().param.configurableWepAttr00 == 1 {
available_affinites.push(Affinity::Standard);
}

// Heavy
if gem_param.as_ref().borrow().param.configurableWepAttr01 == 1 {
available_affinites.push(Affinity::Heavy);
}

// Keen
if gem_param.as_ref().borrow().param.configurableWepAttr02 == 1 {
available_affinites.push(Affinity::Keen);
}

// Quality
if gem_param.as_ref().borrow().param.configurableWepAttr03 == 1 {
available_affinites.push(Affinity::Quality);
}

// Fire
if gem_param.as_ref().borrow().param.configurableWepAttr04 == 1 {
available_affinites.push(Affinity::Fire);
}

// FlameArt
if gem_param.as_ref().borrow().param.configurableWepAttr05 == 1 {
available_affinites.push(Affinity::FlameArt);
}

// Lightning
if gem_param.as_ref().borrow().param.configurableWepAttr06 == 1 {
available_affinites.push(Affinity::Lightning);
}

// Sacred
if gem_param.as_ref().borrow().param.configurableWepAttr07 == 1 {
available_affinites.push(Affinity::Sacred);
}

// Magic
if gem_param.as_ref().borrow().param.configurableWepAttr08 == 1 {
available_affinites.push(Affinity::Magic);
}

// Cold
if gem_param.as_ref().borrow().param.configurableWepAttr09 == 1 {
available_affinites.push(Affinity::Cold);
}

// Poison
if gem_param.as_ref().borrow().param.configurableWepAttr10 == 1 {
available_affinites.push(Affinity::Poison);
}

// Blood
if gem_param.as_ref().borrow().param.configurableWepAttr11 == 1 {
available_affinites.push(Affinity::Blood);
}

// Occult
if gem_param.as_ref().borrow().param.configurableWepAttr12 == 1 {
available_affinites.push(Affinity::Occult);
}

available_affinites
}

pub(crate) fn default_affinity(gem_param: Rc<RefCell<ItemParam<EquipParamGem>>>) -> Self {
match gem_param.as_ref().borrow().param.defaultWepAttr {
0 => Affinity::Standard,
1 => Affinity::Heavy,
2 => Affinity::Keen,
3 => Affinity::Quality,
4 => Affinity::Fire,
5 => Affinity::FlameArt,
6 => Affinity::Lightning,
7 => Affinity::Sacred,
8 => Affinity::Magic,
9 => Affinity::Cold,
10 => Affinity::Poison,
11 => Affinity::Blood,
12 => Affinity::Occult,
_ => Affinity::Uknown,
}
}
}
18 changes: 16 additions & 2 deletions src/vm/inventory/add/filter.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::{cell::RefCell, rc::Rc};

use er_save_lib::EquipParamWeapon::EquipParamWeapon;
use er_save_lib::{EquipParamGem::EquipParamGem, EquipParamWeapon::EquipParamWeapon};

use super::item_param::ItemParam;

pub(crate) struct ParamFilter;

impl ParamFilter {
pub(crate) fn not_infused(weapon: &&Rc<RefCell<ItemParam<EquipParamWeapon>>>) -> bool {
pub(crate) fn weapons_not_infused(weapon: &&Rc<RefCell<ItemParam<EquipParamWeapon>>>) -> bool {
weapon
.as_ref()
.borrow()
Expand All @@ -21,4 +21,18 @@ impl ParamFilter {
% 10_000
== 0
}

pub(crate) fn aows_nameless(weapon: &&Rc<RefCell<ItemParam<EquipParamGem>>>) -> bool {
weapon
.as_ref()
.borrow()
.header
.as_ref()
.borrow()
.item_id
.as_ref()
.borrow()
.to_owned()
> 9999
}
}
1 change: 1 addition & 0 deletions src/vm/inventory/add/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub(crate) mod add;
pub(crate) mod affinity;
pub(crate) mod filter;
pub(crate) mod item_param;
pub(crate) mod weapon_type;

0 comments on commit 6fc887c

Please sign in to comment.