diff --git a/CHANGELOG.md b/CHANGELOG.md index 315322d..a792e25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,4 +23,11 @@ - add `log` and `mhlog` helpers ## Version 0.2.1 -- fix changelog \ No newline at end of file +- fix changelog + +## Version 0.2.2 +- switch to SASS for styling + - add SASS compilation to github actions +- remove `isEmpty` helper, I didn't realize there was already one in `foundry.utils` +- implement new version of updateInitiativeStatistics +- document updateInitiativeStatistics \ No newline at end of file diff --git a/README.md b/README.md index e26185e..1efd8e1 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,10 @@ Implements the Relic Gift of the same name. Prompts the user to select a weapon, For recovering weapons hidden in flags by the old Lashing Currents macro originally shipped with the PF2e Relics module. #### Drop Held Torch (`async dropHeldTorch()`) *Requires Item Piles* Requires one token only selected, and a currently held torch. Creates an Item Pile containing the torch, removing it from the actor. If the torch was lit, apply that light to the resulting pile token. Significant generalization and improvements planned. +#### Update Initiative Statistics (`async updateInitiativeStatistics()`) +Provides a dialog to quickly set which statistic the actors of any/all selected tokens use for initiative. +![](https://i.imgur.com/8j80cOL.png) +(styling not final) ## Helper Functions Helpers are accessed via `game.pf2emhl.` @@ -50,14 +54,6 @@ Returns an `Error` with the message having been passed through `localize()` as a Localizes `str` with `data`, preprends `prefix`, and calls `ui.notifications[type]` with the result and `console`. Errors if `type` is not `info`, `warn`, or `error`. If `notify` is nullish, falls back on the module setting, as above. If `log` is provided and is an object, it will be passed to `console[type]()`. `notify` functions as above. #### `MHLError(str, data = {}, { notify = null, prefix = "MacroHelperLibrary: ", log = {}, func = null } = {})` A simple wrapper on `localizedError` above, pre-fills the prefix for this library's calls, and provides the `func` variable which, if provided, is inserted between the prefix and the rest of the error string, for more a more granular 'where did this error come from' report. -#### `isEmpty(value)` -Checks if value is empty. Deep-checks arrays and objects. -```js -isEmpty([]) == true -isEmpty({}) == true -isEmpty([{0:false},"",0]) == true -isEmpty({0:1}) == false -``` #### `log(loggable, type = null, prefix = null)` Passes `loggable` to `console[type]()`, with `prefix` as a separate argument first for ease of console filtering. #### `mhlog(loggable, type = null, prefix="MHL |") ` diff --git a/scripts/classes/MHLDialog.mjs b/scripts/classes/MHLDialog.mjs index fb7060d..e272074 100644 --- a/scripts/classes/MHLDialog.mjs +++ b/scripts/classes/MHLDialog.mjs @@ -1,5 +1,5 @@ import { COLOURS, LABELABLE_TAGS, fu } from "../constants.mjs"; -import { MHLError, isEmpty, localizedBanner } from "../helpers/errorHelpers.mjs"; +import { MHLError, localizedBanner } from "../helpers/errorHelpers.mjs"; import { localize } from "../helpers/stringHelpers.mjs"; const PREFIX = "MHL.Dialog"; export class MHLDialog extends Dialog { @@ -17,7 +17,7 @@ export class MHLDialog extends Dialog { const fields = fu.deepClone(validator); data.validator = (html) => { const formValues = MHLDialog.getFormData(html); - const emptyFields = fields.filter((f) => isEmpty(formValues[f])); + const emptyFields = fields.filter((f) => fu.isEmpty(formValues[f])); if (emptyFields.length) { const fieldsError = fields .map((f) => diff --git a/scripts/macros/updateInitiativeSkills.mjs b/scripts/macros/updateInitiativeSkills.mjs deleted file mode 100644 index bc0cbbd..0000000 --- a/scripts/macros/updateInitiativeSkills.mjs +++ /dev/null @@ -1,59 +0,0 @@ -import { anyTokens } from "../helpers/tokenHelpers.mjs"; -import { setInitiativeStatistic } from "../helpers/pf2eHelpers.mjs"; -import { MHLDialog } from "../classes/MHLDialog.mjs"; -import { MODULE, fu } from "../constants.mjs"; - -export async function updateInitiativeSkillsDialog() { - const tokens = anyTokens().filter( - (t) => !t.actor.traits.has("minion") && ["character", "npc"].includes(t.actor.type) - ); - async function submitCallback(html) { - const { all, ...data } = new FormDataExtended(html.querySelector("form")).object; - if (all) { - for (const id of Object.keys(data)) { - let actor = fromUuidSync(id)?.actor; - await setInitiativeStatistic(actor, all); - } - } else { - for (const [id, skill] of Object.entries(data)) { - let actor = fromUuidSync(id)?.actor; - await setInitiativeStatistic(actor, skill); - } - } - } - const contentData = { - uskills: Object.entries(CONFIG.PF2E.skillList), - tokens: tokens.map((t) => ({ - name: t.name, - id: t.document.uuid, - skills: fu.mergeObject(t.actor.skills, { perception: { slug: "perception", label: "PF2E.PerceptionLabel" } }), - current: t.actor.system.initiative.statistic, - })), - }; - contentData.uskills.unshift(["perception", "PF2E.PerceptionLabel"]); - contentData.uskills.pop(); // remove the generic lore entry - contentData.uskills = contentData.uskills.map((e) => ({ - slug: e[0], - label: e[1], - })); - - const dialogData = { - contentData, - title: `Set Initiative Skills`, - content: `/modules/${MODULE}/templates/updateInitiativeSkills.hbs`, - buttons: { - yes: { - icon: "", - label: `Apply Changes`, - callback: submitCallback, - }, - no: { - icon: "", - label: `Cancel Changes`, - }, - }, - default: "yes", - }; - // console.warn(templateData,dialogData) - new MHLDialog(dialogData).render(true); -} diff --git a/templates/updateInitiativeSkills.hbs b/templates/updateInitiativeSkills.hbs deleted file mode 100644 index 613a621..0000000 --- a/templates/updateInitiativeSkills.hbs +++ /dev/null @@ -1,25 +0,0 @@ -
-
- - -
-
- {{#each tokens as |token|}} -
- - -
- {{/each}} -
\ No newline at end of file