Creating scripts

This commit is contained in:
2026-06-18 20:51:00 -05:00
parent 1351055d27
commit d270ee8d16
+7 -9
View File
@@ -211,19 +211,17 @@ impl EditorState {
fn open_scripts_dialog(&mut self) { fn open_scripts_dialog(&mut self) {
let mut names: Vec<String> = self.world.scripts.keys().cloned().collect(); let mut names: Vec<String> = self.world.scripts.keys().cloned().collect();
names.sort(); names.sort();
self.dialog = Some(Dialog::list("Scripts", names, false, |resp, ed: &mut EditorState| { self.dialog = Some(Dialog::list("Scripts", names, true, |resp, ed: &mut EditorState| {
if let ListDialogResponse::Select(name) = resp { match resp {
ed.open_script_editor(&name); ListDialogResponse::Select(name) | ListDialogResponse::Create(name) => {
let source = ed.world.scripts.get(&name).cloned().unwrap_or_default();
ed.code_editor = Some(CodeEditor::new(&name, &source));
}
ListDialogResponse::Cancel => {}
} }
})); }));
} }
/// Opens the code editor on the named script (empty if the name is unknown).
fn open_script_editor(&mut self, name: &str) {
let source = self.world.scripts.get(name).cloned().unwrap_or_default();
self.code_editor = Some(CodeEditor::new(name, &source));
}
/// Closes the code editor, saving its text back into the in-memory script pool /// Closes the code editor, saving its text back into the in-memory script pool
/// (mirrors how the Name/Entry-board dialogs mutate the loaded `World`). /// (mirrors how the Name/Entry-board dialogs mutate the loaded `World`).
pub(crate) fn close_script_editor(&mut self) { pub(crate) fn close_script_editor(&mut self) {