mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-02 16:30:50 -06:00
Engine: a recorded script run keeps the steps that ran
The recorder expanded an automate.runScript step from the workbook as it stood when the recording stopped, so a script edited or deleted during the recording changed the saved macro, or dropped the step. The run now leaves the steps it ran with the recorder (Recorder::ran, by step index, within the byte budget), and the conversion reads those, falling back to the workbook only when they could not be kept.
This commit is contained in:
@@ -1074,6 +1074,9 @@ fn run_script(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
}
|
||||
let _sandbox = crate::io::ScriptSandbox::enter();
|
||||
let mut n = 0;
|
||||
// What ran, for a recorder in progress: the recording keeps these steps with the run, so
|
||||
// editing or deleting the script before the recording stops does not change what it saved.
|
||||
let mut ran_steps: Vec<(String, Json)> = Vec::new();
|
||||
for st in &steps {
|
||||
let id = st["command"].as_str().unwrap_or("");
|
||||
if id.starts_with("automate.") {
|
||||
@@ -1092,6 +1095,12 @@ fn run_script(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
}
|
||||
ran?;
|
||||
n += 1;
|
||||
if s.recorder.is_some() {
|
||||
ran_steps.push((id.to_string(), st["params"].clone()));
|
||||
}
|
||||
}
|
||||
if s.recorder.is_some() {
|
||||
s.script_ran = Some(ran_steps);
|
||||
}
|
||||
Ok(json!({"ran": n}))
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ fn save_recording(s: &mut Session, p: &Json, rec: &crate::record::Recorder, star
|
||||
Some(n) => crate::macros::unique_name(&wb, n),
|
||||
None => crate::macros::next_name(&wb),
|
||||
};
|
||||
let mut converted = crate::macros::recorder::convert(&name, &start, &rec.steps, &wb);
|
||||
let mut converted = crate::macros::recorder::convert(&name, &start, &rec.steps, &rec.ran, &wb);
|
||||
// Steps past the macro limit, and ones recorded in another workbook, are left out and counted
|
||||
// with the ones the recorder dropped.
|
||||
let cut = converted.cut.saturating_add(converted.mac.steps.len().saturating_sub(gridcraft_model::MAX_MACRO_STEPS));
|
||||
|
||||
Reference in New Issue
Block a user