Resolve imported Action calls in their own archive folder

This commit is contained in:
yoriswind committed 2026-11-08 04:37:34 -08:00
1 parent 243f14f6fe
commit c460b695d1
2 files changed
+18 -1

No files matched your search

@@ -120,3 +120,18 @@ fn recording_and_assignment_infer_only_unambiguous_folder_occurrences() {
s.execute("actions.assignSet", json!({"action":0,"set":"Exact "})).unwrap();
assert_eq!(s.actions.list[0].set_slot, Some(0));
}
/// Imported callers prefer the same physical folder when a target name is repeated.
#[test]
fn whole_replace_resolves_unqualified_calls_in_their_own_occurrence() {
let mut s = Session::new();
let mut archive = set("Repeated", Some(("Child", 0)));
let child = Action::new("Child", Vec::new());
let parent = Action::new("Parent", vec![("actions.play".into(), json!({"action":"Child"}))]);
let (second, _) = crate::atn_cmds::export("Repeated", &[&child, &parent], &[], false).unwrap();
archive.extend_from_slice(&second[4..]);
s.execute("actions.replace", json!({"confirm":true,"data":photocraft_paint::tile::b64_encode(&archive)})).unwrap();
assert_eq!(s.actions.list[0].name, "Child");
assert_ne!(s.actions.list[1].name, "Child");
assert_eq!(s.actions.list[2].steps[0].1["action"], s.actions.list[1].name.as_str());
}
@@ -68,8 +68,10 @@ impl Replacement {
_ => None,
}
.or_else(|| params.get("set").filter(|value| !value.is_null()));
// An unqualified call in this archive first looks in its original folder.
// Legacy callers outside this import still use their existing name lookup.
let renamed = match scope {
None => first.get(name),
None => action.set_slot.and_then(|slot| local.get(&(slot, name.to_string()))).or_else(|| first.get(name)),
Some(value) => value.as_str().and_then(|set| {
let row = action.set_slot.filter(|_| action.set.as_deref() == Some(set));
row.and_then(|slot| local.get(&(slot, name.to_string()))).or_else(|| scoped.get(&(set.to_string(), name.to_string())))