Skip to content

Commit

Permalink
pob: fixes config parsing for new loadouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde committed Jul 24, 2024
1 parent 3c93f0f commit a667c84
Show file tree
Hide file tree
Showing 4 changed files with 387 additions and 4 deletions.
1 change: 1 addition & 0 deletions pob/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl PartialEq<Config> for String {
}
}

#[derive(Debug)]
pub enum ConfigValue<'a> {
String(&'a str),
Number(f32),
Expand Down
16 changes: 16 additions & 0 deletions pob/src/serde/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,22 @@ impl<'de> de::Deserialize<'de> for Gear {
#[derive(Default, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct Config {
// With loadout support
pub active_config_set: Option<String>,
#[serde(default, rename = "ConfigSet")]
pub config_sets: Vec<ConfigSet>,

// Pre loadout patch
#[serde(default, rename = "Input")]
pub input: Vec<Input>,
}

#[derive(Default, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ConfigSet {
// For loadout support.
pub id: Option<String>,

#[serde(default, rename = "Input")]
pub input: Vec<Input>,
}
Expand Down
27 changes: 23 additions & 4 deletions pob/src/serde/pob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,22 @@ impl crate::PathOfBuilding for SerdePathOfBuilding {
}

fn config(&self, config: Config) -> ConfigValue {
self.pob
let input = self
.pob
.config
.input
.active_config_set
.as_deref()
.and_then(|id| {
self.pob
.config
.config_sets
.iter()
.find(|cs| cs.id.as_deref() == Some(id))
})
.map(|cs| &cs.input)
.unwrap_or(&self.pob.config.input);

input
.iter()
.find(|x| config == x.name)
.map(|stat| {
Expand Down Expand Up @@ -398,6 +411,7 @@ mod tests {
static V319_MASTERY_EFFECTS: &str = include_str!("../../test/319_mastery_effects.xml");
static V320_IMPENDING_DOOM: &str = include_str!("../../test/320_impending_doom.xml");
static V322_OVERRIDES: &str = include_str!("../../test/322_overrides.xml");
static V325_LOADOUTS: &str = include_str!("../../test/325_loadouts.xml");

#[test]
fn parse_v316_empty() {
Expand All @@ -414,7 +428,6 @@ mod tests {
assert_eq!(Some(3), pob.stat_parse(Stat::EnduranceChargesMax));
assert_eq!(None, pob.stat_parse::<u8>(Stat::AverageDamage));
assert_eq!(Some("3.16".to_owned()), pob.max_tree_version());
// TODO: test configs
}

#[test]
Expand Down Expand Up @@ -457,7 +470,7 @@ mod tests {
assert_eq!(None, pob.item_sets()[0].title);
assert_eq!(Some("Perfect Gear"), pob.item_sets()[1].title);

// TODO: test configs
assert_eq!(pob.config(Config::Boss).string(), Some("Sirus"));
}

#[test]
Expand Down Expand Up @@ -527,4 +540,10 @@ mod tests {
assert_eq!(wise.node_id, 50197);
assert_eq!(wise.effect, "+1\n\t\t\t\t\tLimited to 1");
}

#[test]
fn parse_v325_loadouts() {
let pob = SerdePathOfBuilding::from_xml(V325_LOADOUTS).unwrap();
assert!(pob.config(Config::PowerCharges).is_true());
}
}
Loading

0 comments on commit a667c84

Please sign in to comment.