diff --git a/pob/src/config.rs b/pob/src/config.rs index a218e32..32b9a39 100644 --- a/pob/src/config.rs +++ b/pob/src/config.rs @@ -75,6 +75,7 @@ impl PartialEq for String { } } +#[derive(Debug)] pub enum ConfigValue<'a> { String(&'a str), Number(f32), diff --git a/pob/src/serde/model.rs b/pob/src/serde/model.rs index 18e2849..057cc2e 100644 --- a/pob/src/serde/model.rs +++ b/pob/src/serde/model.rs @@ -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, + #[serde(default, rename = "ConfigSet")] + pub config_sets: Vec, + + // Pre loadout patch + #[serde(default, rename = "Input")] + pub input: Vec, +} + +#[derive(Default, Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub(crate) struct ConfigSet { + // For loadout support. + pub id: Option, + #[serde(default, rename = "Input")] pub input: Vec, } diff --git a/pob/src/serde/pob.rs b/pob/src/serde/pob.rs index 3233a86..0f4280e 100644 --- a/pob/src/serde/pob.rs +++ b/pob/src/serde/pob.rs @@ -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| { @@ -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() { @@ -414,7 +428,6 @@ mod tests { assert_eq!(Some(3), pob.stat_parse(Stat::EnduranceChargesMax)); assert_eq!(None, pob.stat_parse::(Stat::AverageDamage)); assert_eq!(Some("3.16".to_owned()), pob.max_tree_version()); - // TODO: test configs } #[test] @@ -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] @@ -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()); + } } diff --git a/pob/test/325_loadouts.xml b/pob/test/325_loadouts.xml new file mode 100644 index 0000000..954a586 --- /dev/null +++ b/pob/test/325_loadouts.xml @@ -0,0 +1,347 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + https://www.pathofexile.com/passive-skill-tree/AAAABgAAAAAA + + + + + https://www.pathofexile.com/passive-skill-tree/AAAABgAAAAAA + + + + + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +