From 6b07da4b231c56c258c53f2c7fde722b8f17fe96 Mon Sep 17 00:00:00 2001 From: averrin Date: Tue, 19 Jul 2022 17:33:26 +0200 Subject: [PATCH] fix for arg input default value; better one-liner --- README.md | 1 + src/modules/Sequencer.js | 1 + src/view/components/ArgInput.svelte | 5 +++-- src/view/components/SequencerTab.svelte | 14 +++++++++++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 75c94d1..92e35e8 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ It's not going to be MATT's alternative, so actions are pretty basic ## Plans - [ ] Documentation +- [ ] Extension API - [ ] v10 support - [ ] Beginner / Expert UI mode - [ ] Better import / export diff --git a/src/modules/Sequencer.js b/src/modules/Sequencer.js index 4d0de15..295f4dd 100644 --- a/src/modules/Sequencer.js +++ b/src/modules/Sequencer.js @@ -22,6 +22,7 @@ export class DSequence { async prepare(overrides) { overrides = overrides || {}; for (const [name, value] of Object.entries(overrides)) { + if (value === null) continue; const v = this.variables.find(v => v.name == name); if (v) { v.override(value) diff --git a/src/view/components/ArgInput.svelte b/src/view/components/ArgInput.svelte index 50e5296..1db8fc8 100644 --- a/src/view/components/ArgInput.svelte +++ b/src/view/components/ArgInput.svelte @@ -7,6 +7,7 @@ import { XIcon } from "@rgossiaux/svelte-heroicons/solid"; import { HsvPicker } from "svelte-color-picker"; import { v4 as uuidv4 } from "uuid"; + const dispatch = createEventDispatcher(); export let id = uuidv4(); export let value; @@ -23,6 +24,7 @@ let spec = argSpecs.find((s) => s.id == type); if (value === undefined || value === null || (value === "" && "default" in spec && value !== spec.default)) { resetValue(); + debounce(dispatch("change", value), 200); } function selectFile() { @@ -58,7 +60,6 @@ import { createEventDispatcher } from "svelte"; - const dispatch = createEventDispatcher(); let options = additionalItems; if (spec && "options" in spec) { options = [...spec.options, ...additionalItems].flat(); @@ -98,7 +99,7 @@ } function resetValue() { if (spec.options) { - value = spec.options[0]; + value = spec.options[0].value; } else if ("default" in spec) { value = spec.default; } else { diff --git a/src/view/components/SequencerTab.svelte b/src/view/components/SequencerTab.svelte index dfaddbf..c20606e 100644 --- a/src/view/components/SequencerTab.svelte +++ b/src/view/components/SequencerTab.svelte @@ -16,6 +16,7 @@ export let onTagClick; let seq; let fullCode = ""; + let oneliner = ""; const unsubscribe = sequences.subscribe((seqs) => { if (!seq) { seq = @@ -24,10 +25,12 @@ new DSequence(uuidv4(), "New Sequence"); } fullCode = getCode(); + oneliner = getOnelliner(); globalThis.game.settings.set(moduleId, SETTINGS.SELECTED_SEQ, seq.id); }); $: debounce(() => { fullCode = getCode(); + oneliner = getOnelliner(); }, 200); onDestroy(unsubscribe); @@ -36,6 +39,15 @@ return seq.convertToCode(); } + function getOnelliner() { + let vars = {}; + for (const v of seq.variables) { + vars[v.name] = null; + } + vars = JSON.stringify(vars); + return `await Director.playSequence("${seq.title}", ${vars});`; + } + function addSeq() { sequences.update((seqs) => { seq = new DSequence(uuidv4(), `New Sequence ${seqs.length}`); @@ -126,7 +138,7 @@ listAutoWidth={false} /> globalThis.ui.notifications.info("Oneliner copied!")} let:copy >