Skip to content

Commit

Permalink
pre 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
averrin committed Jul 30, 2022
1 parent e45df02 commit 39cb131
Show file tree
Hide file tree
Showing 18 changed files with 513 additions and 110 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,32 @@ All notable changes to this project will be documented in this file. Dates are d
## [Unreleased]
Added:
* Foundry v10 compatibility. Requires Sequencer's [Foundry_v10 branch](https://github.com/fantasycalendar/FoundryVTT-Sequencer/tree/Foundry_v10)
* `abs` argument for "property" hooks. Applies `Math.abs` before comparing with threshold
* `abs` argument for "property" hooks. Applies `Math.abs` before comparing with a threshold
* `args[1]` of the "setInterval" hook now contains the count of successful calls
* `animateProperty` / `loopProperty` modifiers for sequences
* FxMaster integration
* Setting icon from action's button
* `alt-D` shortcut for toggle Director window
* `runAction` function for the API.
* "copy oneliner" button for actions
* `multiply` modifier for repeating section (effect or animation) for all targets
* Small changes in code generation
* Collapsed UI mode with actions toolbar (similar to AlphaHUD integration)
* `alt-D` shortcut for toggle Director window, `alt-c` for toggle collapsing
* You cannot add a duplicate modifier (there are some exceptions)
* Support of Sequencer 2.1.9
* A bunch of missed arguments for modifiers

Fixed:
* Wrong width of argument labels
* A couple of rare problems in the hooks' calling
* Sequencer's warning about reading db before it's populated
* Many problems with arguments' inputs (i suppose, i also added some more bugs)
* Fixed missing dependencies for v9
* Manual position picking reset controlled tokens to only the first one.

Known bugs:
* Color picker for stroke color in text modifier is bugged
* Alpha in color pickers do nothing

## [0.7.2](https://github.com/averrin/director/compare/0.7.1...0.7.2)

Expand Down
6 changes: 4 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ export const SETTINGS = {
SELECTED_TAB: "selected-tab",
HIDE_IMPORT: "hide-import",
ICON_COLLECTION: "icon-collection",
COLLAPSED: "collapsed",

KEY_SHOW: "key-show",
KEY_COLLAPSE: "key-collapsed",
};

export const HOOKS = [
Expand All @@ -46,13 +48,13 @@ export const tabs = [
{
mode: "hooks",
title: "Hooks",
badge: "<span class='ui-badge ui-mx-1' style='background-color: indianred'>𝛼</span>",
// badge: "<span class='ui-badge ui-indicator-item ui-mx-1' style='background-color: indianred'>𝛼</span>",
},
{ mode: "selection", title: "Selection" },
{
mode: "sequencer",
title: "Sequencer",
badge: "<span class='ui-badge ui-mx-1' style='background-color: darkorange'>𝛽</span>",
// badge: "<span class='ui-badge ui-indicator-item ui-mx-1' style='background-color: darkorange'>𝛽</span>",
},
{ mode: "import", title: "Import" },
];
Expand Down
9 changes: 9 additions & 0 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ Hooks.once('init', async () => {
app.toggle();
}
});

game.keybindings.register(moduleId, SETTINGS.KEY_COLLAPSE, {
name: 'Toggle collapsed UI',
editable: [{ key: 'KeyC', modifiers: [KeyboardManager.MODIFIER_KEYS.ALT] }],
namespace: 'Director',
onDown: () => {
app.toggleCollapsed();
}
});
});

Hooks.on('getSceneControlButtons', (buttons) => {
Expand Down
1 change: 1 addition & 0 deletions src/modules/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class Action {
this.color = undefined;
this.icon = undefined;
this.name = "";
this.hidden = false;
this.version = 1;
}

Expand Down
10 changes: 5 additions & 5 deletions src/modules/Integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function initTokenMagicIntegration() {
toCode: (args) => {
if (args.length < 2) return '';
const filter = TokenMagic.getPreset((args[1] ? args[1].replaceAll('"', '') : ""))?.params;
return `\t.thenDo(async () => await TokenMagic.addUpdateFilters(${args[0]}, ${JSON.stringify(filter)}))\n`;
return `.thenDo(async () => await TokenMagic.addUpdateFilters(${args[0]}, ${JSON.stringify(filter)}))`;
}
});
Director.addSection({
Expand All @@ -66,7 +66,7 @@ function initTokenMagicIntegration() {
},
toCode: (args) => {
if (args.length < 2) return '';
return `\t.thenDo(async () => await TokenMagic.deleteFilters(${args[0]}, ${args[1]}))\n`;
return `.thenDo(async () => await TokenMagic.deleteFilters(${args[0]}, ${args[1]}))`;
}
});

Expand Down Expand Up @@ -166,7 +166,7 @@ function initConvenientEffectsIntegration() {
},
toCode: (args) => {
if (args.length < 2) return '';
return `\t.thenDo(async () => game.dfreds.effectInterface.toggleEffect(${args[1]}, { uuids: [${args[0]}.actor.uuid] }))\n`;
return `.thenDo(async () => game.dfreds.effectInterface.toggleEffect(${args[1]}, { uuids: [${args[0]}.actor.uuid] }))`;
}
});

Expand All @@ -187,7 +187,7 @@ function initConvenientEffectsIntegration() {
},
toCode: (args) => {
if (args.length < 2) return '';
return `\t.thenDo(async () => game.dfreds.effectInterface.addEffect({effectName: ${args[1]}, uuid: ${args[0]}.actor.uuid }))\n`;
return `.thenDo(async () => game.dfreds.effectInterface.addEffect({effectName: ${args[1]}, uuid: ${args[0]}.actor.uuid }))`;
}
});

Expand All @@ -208,7 +208,7 @@ function initConvenientEffectsIntegration() {
},
toCode: (args) => {
if (args.length < 2) return '';
return `\t.thenDo(async () => game.dfreds.effectInterface.removeEffect({effectName: ${args[1]}, uuid: ${args[0]}.actor.uuid }))\n`;
return `.thenDo(async () => game.dfreds.effectInterface.removeEffect({effectName: ${args[1]}, uuid: ${args[0]}.actor.uuid }))`;
}
});

Expand Down
77 changes: 61 additions & 16 deletions src/modules/Sequencer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { v4 as uuidv4 } from "uuid";
import { logger, setting } from "./helpers.js";
import { calculateValueSync, logger, setting } from "./helpers.js";
import { SETTINGS, moduleId } from "../constants.js";
import { sectionSpecs, modifierSpecs, argSpecs } from "./Specs.js";
import { calculateValue } from "./helpers.js"
Expand Down Expand Up @@ -72,7 +72,7 @@ let ${name} = await warpgate.crosshairs.show({
interval: ${setting(SETTINGS.MANUAL_MODE)}
});
${name} = { x: ${name}.x, y: ${name}.y };
controlled.forEach(c => c.control());`;
controlled.forEach(c => c.control({releaseOthers: false}));`;
} else {
val = `await warpgate.crosshairs.show({interval: ${setting(SETTINGS.MANUAL_MODE)}})`;
}
Expand All @@ -85,7 +85,7 @@ controlled.forEach(c => c.control());`;
}
val = ret;
} else if (val.startsWith("#target")) {
ret = `Array.from(game.user.targets)`;
let ret = `Array.from(game.user.targets)`;
if (val.endsWith(".first")) {
ret += '[0]';
} else if (val.endsWith(".last")) {
Expand Down Expand Up @@ -117,6 +117,7 @@ controlled.forEach(c => c.control());`;
}

convertToCode() {
let stage = "beginning";
let r = `// This macro was created by converting Director's sequence. Correctness of this code isn't guaranteed.\n`;
r += `// The code isn't indentical to how Director executes sequences, but it should be a good base for modifications.\n`;
if (this.variables.length > 0) {
Expand All @@ -132,27 +133,62 @@ controlled.forEach(c => c.control());`;
}

r += `\n//==== Sequence construction ====\n`;
r += `const sequence = new Sequence("${moduleId}")\n`;
r += `let sequence = new Sequence("${moduleId}")`;
let i = 0;
for (const section of this.sections) {
const args = section.args.map((a, i) => this.getCodeForVal("", a, section._spec?.args[i]?.type)[0]);

for (const _section of this.sections) {
const section = Section.fromPlain(_section);
let isMulti = false;
let mode;
let targets;
for (const m of section.modifiers) {
if (m.type == "multiply") {
isMulti = true;
mode = m.args[1] || "on";
targets = m.args[0];
}
}
if (isMulti) {
section.modifiers = section.modifiers.filter(m => m.type != "multiply");
const mod = new Modifier(uuidv4(), mode);
mod.setType(mode, section.type);
mod.args[0] = "@_target";
section.modifiers.push(mod);
if (stage == "normal") r += ";";
r += `\n\nfor (const _target of ${this.getCodeForVal("", targets, "selection")[0]}) {`;
stage = "in_multi";
}

r += `\n// ${stage}`;

if (stage == "beginning") r += "\n\t";
if (stage == "in_multi") r += "\n\tsequence = sequence";
if (stage == "after_multi") {
r += "\nsequence = sequence";
}

const args = section.args.filter(a => a !== undefined && a !== null).map((a, i) => this.getCodeForVal("", a, section._spec?.args[i]?.type)[0]);
let sectionName = section.type;
if (stage == "normal") r += "\n\t";
if (stage == "after_multi") {
stage = "normal";
}
if (section.type == "effect") {
const name = args[0] || `${this.title}-${i}`;
r += `\t.${section.type}()\n`;
r += `\t\t.origin("${this.id}")\n`;
r += `\t\t.name(${name})\n`;
r += `.${section.type}()`;
r += `\n\t\t.origin("${this.id}")`;
r += `\n\t\t.name(${name})`;
} else {
if (section._spec && "toCode" in section._spec) {
r += section._spec.toCode(args);
} else {
r += `\t.${sectionName}(${args.join(", ")})\n`;
r += `.${sectionName}(${args.join(", ")})`;
}
}

for (const m of section.modifiers) {
const args = [];
const pre_args = m.args?.map((a, i) => this.getCodeForVal("", a, m._spec?.args[i]?.type)[0]);
const pre_args = m.args?.filter(a => a !== undefined && a !== null).map((a, i) => this.getCodeForVal("", a, m._spec?.args[i]?.type)[0]);
let n = 0;
const options = {};
for (const a of pre_args) {
Expand All @@ -169,12 +205,21 @@ controlled.forEach(c => c.control());`;
if (Object.entries(options).length > 0) {
args.push(JSON.stringify(options));
}
r += `\t\t.${m.type}(${args.join(", ")})\n`;
r += `\n\t\t.${m.type}(${args.join(", ")})`;
}

if (isMulti) {
r += `;\n}\n`
stage = "after_multi";
}

if (stage == "beginning" && i == 0) {
stage = "normal";
}
i++;
}
r += `.play();`
if (stage != "in_multi" && stage != "after_multi") r += ";";
r += `\nsequence.play();`
return r;
}

Expand Down Expand Up @@ -382,7 +427,7 @@ export class Section {
if (!this._spec || !this._spec.args) return;
for (const arg of this._spec?.args) {
const spec = argSpecs.find(s => s.id == arg.type);
let value = spec.default;
let value = arg.default === undefined ? spec.default : arg.default;
if (value === undefined && spec.options) {
let ops = spec.options;
if (typeof spec.options === "function") {
Expand Down Expand Up @@ -426,7 +471,7 @@ export class Modifier {
if (!this._spec || !this._spec.args) return;
for (const arg of this._spec?.args) {
const spec = argSpecs.find(s => s.id == arg.type);
let value = spec.default;
let value = arg.default === undefined ? spec.default : arg.default;
if (value === undefined && spec.options) {
let ops = spec.options;
if (typeof spec.options === "function") {
Expand All @@ -438,7 +483,7 @@ export class Modifier {
value = ops[0];
}
}
if (value === undefined) {
if (value === undefined || arg.optional) {
value = ""
}
this.args.push(value);
Expand Down
Loading

0 comments on commit 39cb131

Please sign in to comment.