Skip to content

Commit

Permalink
Merge pull request #74 from AlexKnauth/asr_xml
Browse files Browse the repository at this point in the history
 Deal with either Legacy XML or ASR XML
  • Loading branch information
AlexKnauth authored Apr 30, 2024
2 parents ae23201 + 330a562 commit 55261dd
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 65 deletions.
95 changes: 71 additions & 24 deletions splits/all_skills_shuffle/all_skills_shuffle.lss
Original file line number Diff line number Diff line change
Expand Up @@ -237,29 +237,76 @@
</Segment>
</Segments>
<AutoSplitterSettings>
<Ordered>True</Ordered>
<AutosplitEndRuns>False</AutosplitEndRuns>
<AutosplitStartRuns>RandoWake</AutosplitStartRuns>
<Splits>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
<Split>OnObtainAllSkillsShuffleItem</Split>
</Splits>
<Version>1.0.0.0</Version>
<ScriptPath />
<CustomSettings>
<Setting id="splits" type="list">
<Setting type="string" value="RandoWake" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting type="string" value="EndingSplit" />
</Setting>
<Setting id="splits_0_item" type="string" value="RandoWake" />
<Setting id="splits_1_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_2_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_3_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_4_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_5_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_6_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_7_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_8_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_9_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_10_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_11_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_12_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_13_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_14_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_15_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_16_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_17_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_18_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_19_item" type="string" value="OnObtainAllSkillsShuffleItem" />
<Setting id="splits_20_item" type="string" value="EndingSplit" />
<Setting id="timing_method" type="string" value="LoadRemovedTime" />
<Setting id="splits_insert_0" type="bool">False</Setting>
<Setting id="splits_0_action" type="string" value="None" />
<Setting id="splits_1_action" type="string" value="None" />
<Setting id="splits_2_action" type="string" value="None" />
<Setting id="splits_3_action" type="string" value="None" />
<Setting id="splits_4_action" type="string" value="None" />
<Setting id="splits_5_action" type="string" value="None" />
<Setting id="splits_6_action" type="string" value="None" />
<Setting id="splits_7_action" type="string" value="None" />
<Setting id="splits_8_action" type="string" value="None" />
<Setting id="splits_9_action" type="string" value="None" />
<Setting id="splits_10_action" type="string" value="None" />
<Setting id="splits_11_action" type="string" value="None" />
<Setting id="splits_12_action" type="string" value="None" />
<Setting id="splits_13_action" type="string" value="None" />
<Setting id="splits_14_action" type="string" value="None" />
<Setting id="splits_15_action" type="string" value="None" />
<Setting id="splits_16_action" type="string" value="None" />
<Setting id="splits_17_action" type="string" value="None" />
<Setting id="splits_18_action" type="string" value="None" />
<Setting id="splits_19_action" type="string" value="None" />
<Setting id="splits_20_action" type="string" value="None" />
</CustomSettings>
</AutoSplitterSettings>
</Run>
69 changes: 50 additions & 19 deletions splits/current/splits-direct.lss
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,55 @@
</Segment>
</Segments>
<AutoSplitterSettings>
<Ordered>True</Ordered>
<AutosplitEndRuns>True</AutosplitEndRuns>
<AutosplitStartRuns>StartNewGame</AutosplitStartRuns>
<Splits>
<Split>KingsPass</Split>
<Split>Grub1</Split>
<Split>EnterBroodingMawlek</Split>
<Split>MaskFragment1</Split>
<Split>Grub2</Split>
<Split>MaskFragment2</Split>
<Split>GruzMother</Split>
<Split>SlyRescued</Split>
<Split>Grub3</Split>
<Split>Grub4</Split>
<Split>Grub5</Split>
<Split>MaskFragment3</Split>
<Split>Mask1</Split>
</Splits>
<TimingMethod>LoadRemovedTime</TimingMethod>
<Version>1.0.0.0</Version>
<ScriptPath />
<CustomSettings>
<Setting id="splits" type="list">
<Setting type="string" value="StartNewGame" />
<Setting type="string" value="KingsPass" />
<Setting type="string" value="Grub1" />
<Setting type="string" value="EnterBroodingMawlek" />
<Setting type="string" value="MaskFragment1" />
<Setting type="string" value="Grub2" />
<Setting type="string" value="MaskFragment2" />
<Setting type="string" value="GruzMother" />
<Setting type="string" value="SlyRescued" />
<Setting type="string" value="Grub3" />
<Setting type="string" value="Grub4" />
<Setting type="string" value="Grub5" />
<Setting type="string" value="MaskFragment3" />
<Setting type="string" value="Mask1" />
</Setting>
<Setting id="timing_method" type="string" value="LoadRemovedTime" />
<Setting id="splits_0_item" type="string" value="StartNewGame" />
<Setting id="splits_1_item" type="string" value="KingsPass" />
<Setting id="splits_2_item" type="string" value="Grub1" />
<Setting id="splits_3_item" type="string" value="EnterBroodingMawlek" />
<Setting id="splits_4_item" type="string" value="MaskFragment1" />
<Setting id="splits_5_item" type="string" value="Grub2" />
<Setting id="splits_6_item" type="string" value="MaskFragment2" />
<Setting id="splits_7_item" type="string" value="GruzMother" />
<Setting id="splits_8_item" type="string" value="SlyRescued" />
<Setting id="splits_9_item" type="string" value="Grub3" />
<Setting id="splits_10_item" type="string" value="Grub4" />
<Setting id="splits_11_item" type="string" value="Grub5" />
<Setting id="splits_12_item" type="string" value="MaskFragment3" />
<Setting id="splits_13_item" type="string" value="Mask1" />
<Setting id="splits_insert_0" type="bool">False</Setting>
<Setting id="splits_0_action" type="string" value="None" />
<Setting id="splits_1_action" type="string" value="None" />
<Setting id="splits_2_action" type="string" value="None" />
<Setting id="splits_3_action" type="string" value="None" />
<Setting id="splits_4_action" type="string" value="None" />
<Setting id="splits_5_action" type="string" value="None" />
<Setting id="splits_6_action" type="string" value="None" />
<Setting id="splits_7_action" type="string" value="None" />
<Setting id="splits_8_action" type="string" value="None" />
<Setting id="splits_9_action" type="string" value="None" />
<Setting id="splits_10_action" type="string" value="None" />
<Setting id="splits_11_action" type="string" value="None" />
<Setting id="splits_12_action" type="string" value="None" />
<Setting id="splits_13_action" type="string" value="None" />
</CustomSettings>
</AutoSplitterSettings>
</Run>
69 changes: 50 additions & 19 deletions splits/hits/splits-direct.lss
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,55 @@
</Segment>
</Segments>
<AutoSplitterSettings>
<Ordered>True</Ordered>
<AutosplitEndRuns>True</AutosplitEndRuns>
<AutosplitStartRuns>StartNewGame</AutosplitStartRuns>
<Splits>
<Split>KingsPass</Split>
<Split>Grub1</Split>
<Split>EnterBroodingMawlek</Split>
<Split>MaskFragment1</Split>
<Split>Grub2</Split>
<Split>MaskFragment2</Split>
<Split>GruzMother</Split>
<Split>SlyRescued</Split>
<Split>Grub3</Split>
<Split>Grub4</Split>
<Split>Grub5</Split>
<Split>MaskFragment3</Split>
<Split>Mask1</Split>
</Splits>
<TimingMethod>HitsDreamFalls</TimingMethod>
<Version>1.0.0.0</Version>
<ScriptPath />
<CustomSettings>
<Setting id="splits" type="list">
<Setting type="string" value="StartNewGame" />
<Setting type="string" value="KingsPass" />
<Setting type="string" value="Grub1" />
<Setting type="string" value="EnterBroodingMawlek" />
<Setting type="string" value="MaskFragment1" />
<Setting type="string" value="Grub2" />
<Setting type="string" value="MaskFragment2" />
<Setting type="string" value="GruzMother" />
<Setting type="string" value="SlyRescued" />
<Setting type="string" value="Grub3" />
<Setting type="string" value="Grub4" />
<Setting type="string" value="Grub5" />
<Setting type="string" value="MaskFragment3" />
<Setting type="string" value="Mask1" />
</Setting>
<Setting id="timing_method" type="string" value="HitsDreamFalls" />
<Setting id="splits_0_item" type="string" value="StartNewGame" />
<Setting id="splits_1_item" type="string" value="KingsPass" />
<Setting id="splits_2_item" type="string" value="Grub1" />
<Setting id="splits_3_item" type="string" value="EnterBroodingMawlek" />
<Setting id="splits_4_item" type="string" value="MaskFragment1" />
<Setting id="splits_5_item" type="string" value="Grub2" />
<Setting id="splits_6_item" type="string" value="MaskFragment2" />
<Setting id="splits_7_item" type="string" value="GruzMother" />
<Setting id="splits_8_item" type="string" value="SlyRescued" />
<Setting id="splits_9_item" type="string" value="Grub3" />
<Setting id="splits_10_item" type="string" value="Grub4" />
<Setting id="splits_11_item" type="string" value="Grub5" />
<Setting id="splits_12_item" type="string" value="MaskFragment3" />
<Setting id="splits_13_item" type="string" value="Mask1" />
<Setting id="splits_insert_0" type="bool">False</Setting>
<Setting id="splits_0_action" type="string" value="None" />
<Setting id="splits_1_action" type="string" value="None" />
<Setting id="splits_2_action" type="string" value="None" />
<Setting id="splits_3_action" type="string" value="None" />
<Setting id="splits_4_action" type="string" value="None" />
<Setting id="splits_5_action" type="string" value="None" />
<Setting id="splits_6_action" type="string" value="None" />
<Setting id="splits_7_action" type="string" value="None" />
<Setting id="splits_8_action" type="string" value="None" />
<Setting id="splits_9_action" type="string" value="None" />
<Setting id="splits_10_action" type="string" value="None" />
<Setting id="splits_11_action" type="string" value="None" />
<Setting id="splits_12_action" type="string" value="None" />
<Setting id="splits_13_action" type="string" value="None" />
</CustomSettings>
</AutoSplitterSettings>
</Run>
83 changes: 83 additions & 0 deletions src/asr_xml.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

Check failure on line 1 in src/asr_xml.rs

View workflow job for this annotation

GitHub Actions / Check formatting

Diff in /home/runner/work/hollowknight-autosplit-wasm/hollowknight-autosplit-wasm/src/asr_xml.rs
use std::str::FromStr;

use xmltree::{Element, XMLNode};

pub fn asr_settings_from_xml_nodes(xml_nodes: Vec<XMLNode>) -> Option<asr::settings::Map> {
let custom_settings = xml_nodes.iter().find_map(xml_node_find_custom_settings)?;
Some(parse_settings_map(custom_settings))
}

fn xml_node_find_custom_settings(xml: &XMLNode) -> Option<&[XMLNode]> {
let Element { name, children, .. } = xml.as_element()?;
if name != "CustomSettings" {
return None;
}
Some(children)
}

fn parse_settings_map(xml_nodes: &[XMLNode]) -> asr::settings::Map {
let settings_map = asr::settings::Map::new();
for xml_node in xml_nodes {
if let (Some(id), Some(value)) = parse_settings_entry(xml_node) {
settings_map.insert(id, value);
}
}
settings_map
}

fn parse_settings_list(xml_nodes: &[XMLNode]) -> asr::settings::List {
let settings_list = asr::settings::List::new();
for xml_node in xml_nodes {
if let (_, Some(value)) = parse_settings_entry(xml_node) {
settings_list.push(value);
}
}
settings_list
}

Check failure on line 37 in src/asr_xml.rs

View workflow job for this annotation

GitHub Actions / Check formatting

Diff in /home/runner/work/hollowknight-autosplit-wasm/hollowknight-autosplit-wasm/src/asr_xml.rs

fn parse_settings_entry(xml_node: &XMLNode) -> (Option<&String>, Option<asr::settings::Value>) {
let Some(Element { attributes, children, .. }) = xml_node.as_element() else {
return (None, None);
};
let id = attributes.get("id");
let Some(setting_type) = attributes.get("type") else {
return (id, None);
};
let value = match setting_type.as_str() {
"bool" => Some(parse_bool(&children).unwrap_or_default().into()),

Check warning on line 48 in src/asr_xml.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

this expression creates a reference which is immediately dereferenced by the compiler
"i64" => Some(parse_fromstr::<i64>(&children).unwrap_or_default().into()),

Check warning on line 49 in src/asr_xml.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

this expression creates a reference which is immediately dereferenced by the compiler
"f64" => Some(parse_fromstr::<f64>(&children).unwrap_or_default().into()),

Check warning on line 50 in src/asr_xml.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

this expression creates a reference which is immediately dereferenced by the compiler
"string" => {
if let Some(string_value) = attributes.get("value") {
Some(string_value.as_str().into())
} else {
Some(parse_text(&children).unwrap_or_default().into())

Check warning on line 55 in src/asr_xml.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

this expression creates a reference which is immediately dereferenced by the compiler
}
}
"map" => Some(parse_settings_map(&children).into()),

Check warning on line 58 in src/asr_xml.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

this expression creates a reference which is immediately dereferenced by the compiler
"list" => Some(parse_settings_list(&children).into()),

Check warning on line 59 in src/asr_xml.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

this expression creates a reference which is immediately dereferenced by the compiler
_ => None,
};
(id, value)
}

fn parse_text(xml_nodes: &[XMLNode]) -> Option<&str> {
match xml_nodes {
[] => Some(""),
[XMLNode::Text(s)] => Some(s),
_ => None,
}
}

fn parse_bool(xml_nodes: &[XMLNode]) -> Option<bool> {
match parse_text(xml_nodes)?.trim() {
"True" => Some(true),
"False" => Some(false),
_ => None,
}
}

fn parse_fromstr<F: FromStr>(xml_nodes: &[XMLNode]) -> Option<F> {
parse_text(xml_nodes)?.trim().parse().ok()
}
13 changes: 10 additions & 3 deletions src/auto_splitter_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use asr::future::retry;
use std::path::Path;
use xmltree::{Element, XMLNode};

use crate::{file, legacy_xml};
use crate::{asr_xml, file, legacy_xml};

Check failure on line 8 in src/auto_splitter_settings.rs

View workflow job for this annotation

GitHub Actions / Check formatting

Diff in /home/runner/work/hollowknight-autosplit-wasm/hollowknight-autosplit-wasm/src/auto_splitter_settings.rs
pub async fn wait_asr_settings_init() -> asr::settings::Map {
let settings1 = asr::settings::Map::load();
Expand Down Expand Up @@ -40,8 +40,11 @@ fn asr_settings_from_xml_string(xml_string: &str) -> Option<asr::settings::Map>
}

fn asr_settings_from_xml_nodes(xml_nodes: Vec<XMLNode>) -> Option<asr::settings::Map> {
// TODO: deal with either Legacy XML or ASR XML
legacy_xml::asr_settings_from_xml_nodes(xml_nodes)
if any_xml_nodes_from_asr(&xml_nodes) {
asr_xml::asr_settings_from_xml_nodes(xml_nodes)
} else {
legacy_xml::asr_settings_from_xml_nodes(xml_nodes)
}
}

fn file_find_auto_splitter_settings<P: AsRef<Path>>(path: P) -> Option<Vec<XMLNode>> {
Expand Down Expand Up @@ -69,6 +72,10 @@ fn component_is_asr(e: &Element) -> bool {
s.contains("LiveSplit.AutoSplittingRuntime")
}

fn any_xml_nodes_from_asr(xml_nodes: &[XMLNode]) -> bool {

Check failure on line 75 in src/auto_splitter_settings.rs

View workflow job for this annotation

GitHub Actions / Check formatting

Diff in /home/runner/work/hollowknight-autosplit-wasm/hollowknight-autosplit-wasm/src/auto_splitter_settings.rs
xml_nodes.iter().any(|n| n.as_element().is_some_and(|e| ["Version", "ScriptPath", "CustomSettings"].contains(&e.name.as_str())))
}

// --------------------------------------------------------

async fn wait_asr_settings_load_merge_store(new: &asr::settings::Map) -> asr::settings::Map {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

extern crate alloc;

mod asr_xml;
mod auto_splitter_settings;
mod file;
mod hollow_knight_memory;
Expand Down

0 comments on commit 55261dd

Please sign in to comment.