diff --git a/CHANGELOG.md b/CHANGELOG.md index fcbe608..5adefd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d ## [Unreleased] +## [0.8.2](https://github.com/averrin/director/compare/0.8.1...0.8.2) +Added: + * More compact collapsed mode + * Actions and Hooks can be global + +Fixed: + * Tagger component acts weird sometimes if there are more than one instance on page + ## [0.8.1](https://github.com/averrin/director/compare/0.8.0...0.8.1) Fixed: * Changing variable type doesnt change list of available variables in arg inputs diff --git a/README.md b/README.md index fa5033b..c70d3dd 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,10 @@ It's not going to be MATT's alternative, so actions are pretty basic ## Plans - [ ] Actual Documentation -- [ ] Better `multiply` +- [ ] API for adding toolbar icon +- [ ] "In scene" tags and icons for them +- [ ] Better `multiply` (mode args, nested modifiers, e.g. playIf) +- [ ] "Undo" for actions - [ ] Migrate to Active Effects Manager - [ ] Automated Animations integration - [ ] Token Attacher integration diff --git a/src/constants.js b/src/constants.js index a7b418b..3b12404 100644 --- a/src/constants.js +++ b/src/constants.js @@ -10,6 +10,12 @@ export function evalExpression(expr, ...args) { // import { foundry } from '../modules/foundry.js'; // import { moduleId, SETTINGS } from '../constants.js'; +export const FLAGS = { + SEQUENCES: "director-sequences", + HOOKS: "director-hooks", + ACTIONS: "director-actions", +} + export const SETTINGS = { GLOBAL_TAGS: "global-tags", TAG_COLORS: "tag-colors", @@ -17,6 +23,8 @@ export const SETTINGS = { UI_SCALE: "ui-scale", RESOLUTION: "resolution", SEQUENCES: "sequences", + ACTIONS: "actions", + HOOKS: "hooks", SHOW_SEQUENCER: "show-sequencer", MANUAL_MODE: "warpgate-mode", diff --git a/src/modules/Actions.js b/src/modules/Actions.js index 8d05edd..71bd7d6 100644 --- a/src/modules/Actions.js +++ b/src/modules/Actions.js @@ -13,6 +13,7 @@ export default class Action { this.name = ""; this.hidden = false; this.version = 1; + this.global = false; } toJSON() { diff --git a/src/modules/Hooks.js b/src/modules/Hooks.js index 2476c35..9aa53ab 100644 --- a/src/modules/Hooks.js +++ b/src/modules/Hooks.js @@ -11,6 +11,7 @@ export default class Hook { this.target = undefined; this.args = []; this.version = 1; + this.global = false; } static fromPlain(plain) { diff --git a/src/modules/Specs.js b/src/modules/Specs.js index 9b3e714..4fb54b9 100644 --- a/src/modules/Specs.js +++ b/src/modules/Specs.js @@ -33,6 +33,14 @@ export const actionTypes = [ group: 'Tokens', execute: (object, action) => object && tools.revive(object?.document || object), }, + { + id: 'macro', + label: 'Run Macro', + group: 'Macro', + args: [{ type: "macro", label: "macro" }], + execute: (object, action) => Array.from(globalThis.game.macros.values()).find(m => m.data.name == action.args[0]).execute({ actor: object?.actor, token: object }), + }, + { id: 'playSequence', label: 'Play sequence', diff --git a/src/modules/settings.js b/src/modules/settings.js index a5d2fff..034fb82 100644 --- a/src/modules/settings.js +++ b/src/modules/settings.js @@ -54,6 +54,20 @@ export function initSettings(app) { default: [], }); + game.settings.register(moduleId, SETTINGS.ACTIONS, { + scope: "world", + config: false, + type: Array, + default: [], + }); + + game.settings.register(moduleId, SETTINGS.HOOKS, { + scope: "world", + config: false, + type: Array, + default: [], + }); + game.settings.register(moduleId, SETTINGS.TAG_COLORS, { scope: "world", config: false, diff --git a/src/modules/stores.js b/src/modules/stores.js index 38bda6c..b407e78 100644 --- a/src/modules/stores.js +++ b/src/modules/stores.js @@ -1,4 +1,4 @@ -import { moduleId, SETTINGS } from '../constants.js'; +import { moduleId, SETTINGS, FLAGS } from '../constants.js'; import { writable } from 'svelte/store'; import { DSequence } from "./Sequencer.js"; import Action from "./Actions.js"; @@ -32,8 +32,8 @@ function updateSequences() { const global = game.settings.get(moduleId, SETTINGS.SEQUENCES); let inScene = []; if (globalThis.canvas.scene) { - inScene = hasFlag(globalThis.canvas.scene, "director-sequences") - ? getFlag(globalThis.canvas.scene, "director-sequences").filter((a) => a).map(a => DSequence.fromPlain(a)) + inScene = hasFlag(globalThis.canvas.scene, FLAGS.SEQUENCES) + ? getFlag(globalThis.canvas.scene, FLAGS.SEQUENCES).filter((a) => a).map(a => DSequence.fromPlain(a)) : []; } sequences.set( @@ -54,7 +54,27 @@ export function initSequences() { } export const actions = writable([]); + +function loadActions(scene) { + const inScene = hasFlag(scene, FLAGS.ACTIONS) + ? getFlag(scene, FLAGS.ACTIONS) + : []; + const global = game.settings.get(moduleId, SETTINGS.ACTIONS); + + actions.set([...global, ...inScene].flat().filter((a) => a).map(a => Action.fromPlain(a))); +} + export const hooks = writable([]); + +function loadHooks(scene) { + const inScene = hasFlag(scene, FLAGS.HOOKS) + ? getFlag(scene, FLAGS.HOOKS) + : []; + const global = game.settings.get(moduleId, SETTINGS.HOOKS); + + hooks.set([...global, ...inScene].flat().filter((a) => a).map(a => Hook.fromPlain(a))); +} + let _scene; export function initCurrentScene() { currentScene.subscribe(async (result) => { @@ -62,12 +82,8 @@ export function initCurrentScene() { if (!scene || scene == null || _scene == scene) return; _scene = scene; - hooks.set(hasFlag(scene, "director-hooks") - ? getFlag(scene, "director-hooks").filter((a) => a).map(a => Hook.fromPlain(a)) - : []); - actions.set(hasFlag(scene, "director-actions") - ? getFlag(scene, "director-actions").filter((a) => a).map(a => Action.fromPlain(a)) - : []); + loadHooks(scene); + loadActions(scene); await HookManager.onSceneChange(scene); @@ -82,8 +98,11 @@ export function initActions() { currentScene.update(async (result) => { const scene = await result; if (!scene || scene == null) return scene; - if (getFlag(scene, "director-actions")?.filter((a) => a) != actions) { - scene.update({ "flags.director-actions": actions.map(a => a.toJSON()) }); + if (getFlag(scene, FLAGS.ACTIONS)?.filter((a) => a) != actions) { + const updates = {}; + updates[`flags.${FLAGS.ACTIONS}`] = actions.filter(a => !a.global).map(a => a.toJSON()) + scene.update(updates); + game.settings.set(moduleId, SETTINGS.ACTIONS, actions.filter(a => a.global)); await HookManager.onActionsChange(actions); globalThis.Hooks.call("DirectorUpdateActions", actions); } @@ -99,8 +118,12 @@ export function initHooks() { currentScene.update(async (result) => { const scene = await result; if (!scene || scene == null) return scene; - if (getFlag(scene, "director-hooks")?.filter((a) => a) != hooks) { - scene.update({ "flags.director-hooks": hooks }); + if (getFlag(scene, FLAGS.HOOKS)?.filter((a) => a) != hooks) { + const updates = {}; + updates[`flags.${FLAGS.HOOKS}`] = hooks.filter(a => !a.global); + scene.update(updates); + game.settings.set(moduleId, SETTINGS.HOOKS, hooks.filter(a => a.global)); + await HookManager.onHooksChange(hooks); globalThis.Hooks.call("DirectorUpdateHooks", hooks); } diff --git a/src/view/MainUI.svelte b/src/view/MainUI.svelte index 0f7dd20..ba2d464 100644 --- a/src/view/MainUI.svelte +++ b/src/view/MainUI.svelte @@ -15,6 +15,8 @@ import HooksTab from "./components/HooksTab.svelte"; import ImportTab from "./components/ImportTab.svelte"; import FaPlay from "svelte-icons/fa/FaPlay.svelte"; + import FaExpandArrowsAlt from "svelte-icons/fa/FaExpandArrowsAlt.svelte"; + import FaCompressArrowsAlt from "svelte-icons/fa/FaCompressArrowsAlt.svelte"; import { HsvPicker } from "svelte-color-picker"; @@ -102,8 +104,8 @@
- {#if !collapsed} +
{#each availableTabs as t (t.title)} @@ -133,31 +135,53 @@ {/if} {:else} -
- {#each currentActions as item (item.id)} - {#if !item.hidden} -
- -
- {/if} - {/each} + +
+ {/if} + {/each} +
+
+ +
{/if}
diff --git a/src/view/components/ActionItem.svelte b/src/view/components/ActionItem.svelte index 663d9d1..fdaec0d 100644 --- a/src/view/components/ActionItem.svelte +++ b/src/view/components/ActionItem.svelte @@ -73,6 +73,7 @@
onItemClickHandler(e, item)} diff --git a/src/view/components/ActionsTab.svelte b/src/view/components/ActionsTab.svelte index c4d0442..f20e87c 100644 --- a/src/view/components/ActionsTab.svelte +++ b/src/view/components/ActionsTab.svelte @@ -112,7 +112,7 @@

Edit action

-
+
+