From c460b695d1995c007646fbcfe3a009001f6bedb5 Mon Sep 17 00:00:00 2001 From: yoriswind Date: Sun, 8 Nov 2026 04:37:34 -0800 Subject: [PATCH] Resolve imported Action calls in their own archive folder --- .../actions_edit_cmds/library_commands/tests.rs | 15 +++++++++++++++ .../engine/src/cmd/atn_cmds/files/replacement.rs | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/actions_edit_cmds/library_commands/tests.rs b/crates/engine/src/cmd/actions_edit_cmds/library_commands/tests.rs index f7d7b66c634..e95e92fbf24 100644 --- a/crates/engine/src/cmd/actions_edit_cmds/library_commands/tests.rs +++ b/crates/engine/src/cmd/actions_edit_cmds/library_commands/tests.rs @@ -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()); +} diff --git a/crates/engine/src/cmd/atn_cmds/files/replacement.rs b/crates/engine/src/cmd/atn_cmds/files/replacement.rs index c800da38e01..69c577ea358 100644 --- a/crates/engine/src/cmd/atn_cmds/files/replacement.rs +++ b/crates/engine/src/cmd/atn_cmds/files/replacement.rs @@ -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())))