Scripts: a script run after the startup scripts plays the Actions panel's actions

With Run Startup Scripts on, File › Scripts runs the chosen script as
`script.startup.run`'s `then`, and the app gave the Actions panel's
actions only to `script.run`'s own parameters. `app.doScript` in that
script then found no action set. The app now gives `then` the panel's
actions as well, unless the caller gave its own.
This commit is contained in:
dotCooCoo committed 2026-11-27 22:51:03 -08:00
1 parent ac3056e829
commit a2e04d98e0
2 files changed
+25 -6

No files matched your search

+12 -6
View File
@@ -39,14 +39,20 @@ fn playback_steps(action: &Action) -> Vec<PlayStep> {
.collect()
}
/// For command `id` `script.run`: gives its `params` the panel's actions as `actions`, which the
/// script's `app.doScript` plays, unless the caller gave them: every action of every set, in panel
/// order, with its steps as playback runs them ([`playback_steps`]) and each step's place in the
/// action. An action that `actions` cannot hold (a step that is not a command, a name that is too
/// long, or one past the limits of [`vectorcraft_engine::script::actions`]) is left out.
/// For command `id` `script.run`, or the script of `script.startup.run`'s `then`: gives its
/// `params` the panel's actions as `actions`, which the script's `app.doScript` plays, unless the
/// caller gave them: every action of every set, in panel order, with its steps as playback runs
/// them ([`playback_steps`]) and each step's place in the action. An action that `actions` cannot
/// hold (a step that is not a command, a name that is too long, or one past the limits of
/// [`vectorcraft_engine::script::actions`]) is left out.
pub(crate) fn add_script_actions(app: &VectorcraftApp, id: &str, params: &mut Value) {
use vectorcraft_engine::script::actions::{MAX_ACTIONS, MAX_ACTIONS_BYTES, MAX_ALL_STEPS, Playable, parse};
let Some(p) = params.as_object_mut().filter(|_| id == "script.run") else { return };
let target = match id {
"script.run" => Some(params),
"script.startup.run" => params.get_mut("then"),
_ => None,
};
let Some(p) = target.and_then(Value::as_object_mut) else { return };
if p.contains_key("actions") {
return;
}
@@ -674,6 +674,19 @@ fn a_script_plays_the_panels_actions() {
assert_eq!(objects(&app), 2);
}
/// The script that `script.startup.run` runs after the startup scripts (its `then`) plays the
/// panel's actions too, as File › Scripts runs a script with Run Startup Scripts on.
#[test]
fn the_script_after_the_startup_scripts_plays_the_panels_actions() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
push_set(&mut app, "Mine", vec![action("Draw", &[("shape.rectangle", json!({"x": 0, "y": 10, "width": 10, "height": 10}))])]);
app.session.script_frames = false;
let then = json!({"source": "try { app.doScript('Draw', 'Mine'); vc.log('ok'); } catch (e) { vc.log(e.message); }", "name": "t.js"});
let r = app.run("script.startup.run", json!({"reason": "menu", "then": then})).unwrap();
assert_eq!(r["then"]["log"], json!(["ok"]), "{r}");
}
/// The steps a script's `app.doScript` plays act on the view's active artboard, as the panel's
/// playback does: Align to Artboard in a recorded batch, and Fit to Selected Art.
#[test]