Skip to content

Commit

Permalink
fix for arg input default value; better one-liner
Browse files Browse the repository at this point in the history
  • Loading branch information
averrin committed Jul 19, 2022
1 parent 011d9f9 commit 6b07da4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/modules/Sequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/view/components/ArgInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -58,7 +60,6 @@
import { createEventDispatcher } from "svelte";
const dispatch = createEventDispatcher();
let options = additionalItems;
if (spec && "options" in spec) {
options = [...spec.options, ...additionalItems].flat();
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 13 additions & 1 deletion src/view/components/SequencerTab.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
export let onTagClick;
let seq;
let fullCode = "";
let oneliner = "";
const unsubscribe = sequences.subscribe((seqs) => {
if (!seq) {
seq =
Expand All @@ -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);
Expand All @@ -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}`);
Expand Down Expand Up @@ -126,7 +138,7 @@
listAutoWidth={false}
/>
<CopyToClipboard
text={`await Director.playSequence("${seq.title}")`}
text={oneliner}
on:copy={(_) => globalThis.ui.notifications.info("Oneliner copied!")}
let:copy
>
Expand Down

0 comments on commit 6b07da4

Please sign in to comment.