From 4619b787e57ede58d944b4a2f145d28156d6b4b4 Mon Sep 17 00:00:00 2001 From: Neill Cox Date: Mon, 6 May 2024 11:37:28 +1000 Subject: [PATCH] Spells and ranged attacks. Partial cleanup of i18n --- module.json | 2 +- scripts/action-handler.js | 72 ++++++++++++++++++++++++++++++++++++--- scripts/constants.js | 13 +++++-- scripts/defaults.js | 22 ++++++++++-- scripts/roll-handler.js | 42 +++++++++++++++++++++-- 5 files changed, 139 insertions(+), 12 deletions(-) diff --git a/module.json b/module.json index 03e77de..99f4d35 100644 --- a/module.json +++ b/module.json @@ -10,7 +10,7 @@ ], "url": "This is auto replaced", "flags": {}, - "version": "0.0.72", + "version": "0.0.97", "compatibility": { "minimum": "11", "verified": "11.351" diff --git a/scripts/action-handler.js b/scripts/action-handler.js index 3f82c98..afc5d70 100644 --- a/scripts/action-handler.js +++ b/scripts/action-handler.js @@ -47,7 +47,9 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { // debugger; this._get_attributes({id: "attributes", type:"system"}) this._get_skills({id: "skills", type:"system"}) + this._get_spells({id: "spells", type:"system"}) this._get_melee_attacks({id: "melee", type:"system"}) + this._get_ranged_attacks({id: "ranged", type:"system"}) this.#buildInventory() } @@ -68,7 +70,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { actions.push({ id: actionId, name: coreModule.api.Utils.i18n("GURPS.attributes" + key), - description: coreModule.api.Utils.i18n('GURPS.Attributes'), + description: coreModule.api.Utils.i18n('GURPS.attributes'), encodedValue: [macroType, key].join(this.delimiter), }) @@ -79,13 +81,16 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { } _get_melee_attacks(parent) { - debugger; + // debugger; const macroType = "melee"; let actions = []; let melee_attacks = Object.entries(this.actor.system.melee) melee_attacks.forEach((a) => { - const key = a[1].name + " (" + a[1].mode + ")"; + let key = a[1].name; + if (a[1].mode) { + key += ` (${a[1].mode})`; + } const value = a[1].level // img @@ -106,8 +111,39 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { } + _get_ranged_attacks(parent) { + // debugger; + const macroType = "ranged"; + let actions = []; + + let ranged_attacks = Object.entries(this.actor.system.ranged) + ranged_attacks.forEach((a) => { + let key = a[1].name; + if (a[1].mode) { + key += ` (${a[1].mode})`; + } + const value = a[1].level + // img + + let actionId = key; + let otf = 'R:"' + key + '"'; // This is going to end badly if the delimiter is set to ":" + + + actions.push({ + id: actionId, + name: coreModule.api.Utils.i18n(key), + description: coreModule.api.Utils.i18n('GURPS.rangedWeapons'), + encodedValue: [macroType, otf].join(this.delimiter), + }) + + + }); + this.addActions(actions, parent) + + } + _get_skills(parent) { - debugger; + // debugger; const macroType = "skills"; let actions = []; @@ -134,6 +170,34 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { } + _get_spells(parent) { + // debugger; + const macroType = "spells"; + let actions = []; + + let spells = Object.entries(this.actor.system.spells) + spells.forEach((a) => { + const key = a[1].name; + const value = a[1].level + // img + + let actionId = key; + let otf = 'Sp:"' + key + '"'; // This is going to end badly if the delimiter is set to ":" + + + actions.push({ + id: actionId, + name: coreModule.api.Utils.i18n(key), + description: coreModule.api.Utils.i18n('GURPS.Spells'), + encodedValue: [macroType, otf].join(this.delimiter), + }) + + + }); + this.addActions(actions, parent) + + } + /** * Build multiple token actions * @private diff --git a/scripts/constants.js b/scripts/constants.js index da28a83..5dfc46e 100644 --- a/scripts/constants.js +++ b/scripts/constants.js @@ -28,10 +28,15 @@ export const ACTION_TYPE = { /** * Groups */ + +// Note: names are automatically localized. I could have avoided some effort if I had realised that sooner. + export const GROUP = { - attributes: { id: 'attributes', name: 'tokenActionHud.gurps.attributes', type: 'system' }, - skills: { id: 'skills', name: 'tokenActionHud.gurps.skills', type: 'system' }, - melee: { id: 'melee', name: 'tokenActionHud.gurps.melee', type: 'system' }, + attributes: { id: 'attributes', name: 'GURPS.attributes', type: 'system' }, + skills: { id: 'skills', name: 'GURPS.skills', type: 'system' }, + spells: { id: 'spells', name: 'GURPS.spells', type: 'system' }, + melee: { id: 'melee', name: 'GURPS.meleeAttack', type: 'system' }, + ranged: { id: 'ranged', name: 'GURPS.rangedAttack', type: 'system' }, armor: { id: 'armor', name: 'tokenActionHud.template.armor', type: 'system' }, equipment: { id: 'equipment', name: 'tokenActionHud.template.equipment', type: 'system' }, consumables: { id: 'consumables', name: 'tokenActionHud.template.consumables', type: 'system' }, @@ -49,7 +54,9 @@ export const GROUP = { export const ITEM_TYPE = { attributes: { groupId: 'attributes' }, skills: { groupId: 'skills' }, + spells: { groupId: 'spells' }, melee: { groupId: 'melee' }, + ranged: { groupId: 'ranged' }, armor: { groupId: 'armor' }, backpack: { groupId: 'containers' }, consumable: { groupId: 'consumables' }, diff --git a/scripts/defaults.js b/scripts/defaults.js index b11b6ae..c8a92bd 100644 --- a/scripts/defaults.js +++ b/scripts/defaults.js @@ -28,7 +28,16 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { id: 'skills', name: coreModule.api.Utils.i18n('GURPS.skills'), groups: [ - { ...groups.skills, nestId: 'skills_skills' } + { ...groups.skills, nestId: 'skills_skills' }, + { ...groups.spells, nestId: 'spells_spells' } + ] + }, + { + nestId: 'spells', + id: 'spells', + name: coreModule.api.Utils.i18n('GURPS.spells'), + groups: [ + { ...groups.spells, nestId: 'spells_spells' } ] }, { @@ -36,7 +45,16 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { id: 'melee', name: coreModule.api.Utils.i18n('GURPS.meleeWeapons'), groups: [ - { ...groups.melee, nestId: 'melee_melee' } + { ...groups.melee, nestId: 'melee_melee' }, + { ...groups.ranged, nestId: 'ranged_ranged' } + ] + }, + { + nestId: 'ranged', + id: 'ranged', + name: coreModule.api.Utils.i18n('GURPS.rangedWeapons'), + groups: [ + { ...groups.ranged, nestId: 'ranged_ranged' } ] }, { diff --git a/scripts/roll-handler.js b/scripts/roll-handler.js index a9c0ca9..23799af 100644 --- a/scripts/roll-handler.js +++ b/scripts/roll-handler.js @@ -85,10 +85,16 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { case 'skills': this.#handleSkillAction(actor, actionId) break + case 'spells': + this.#handleSpellAction(actor, actionId) + break case 'melee': this.#handleMeleeAction(actor, actionId) break - } + case 'ranged': + this.#handleRangedAction(actor, actionId) + break + } } /** @@ -139,6 +145,27 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { doRoll({ actor, formula, targetmods, prefix, thing, chatthing, origtarget: target, optionalArgs: opt }) } + async #handleMeleeAction(actor, actionId) { + /* Melee attacks are done using the otf method. Grab the otf and pass it to the function. */ + let GURPS = globalThis.GURPS; + + // debugger; + let otf = actionId; + GURPS.executeOTF(otf, actor=actor); + } + + async #handleRangedAction(actor, actionId) { + /* Melee attacks are done using the otf method. Grab the otf and pass it to the function. */ + let GURPS = globalThis.GURPS; + + // debugger; + let otf = actionId; + GURPS.executeOTF(otf, actor=actor); + + + // doRoll({ actor, formula, targetmods, prefix, thing, chatthing, origtarget: target, optionalArgs: opt }) + } + async #handleSkillAction(actor, actionId) { /* Skills are done using the otf method. Grab the otf and pass it to the function. */ let GURPS = globalThis.GURPS; @@ -146,12 +173,23 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { // executeOTF(inputstring, priv = false, event = null, actor = null) { - debugger; + // debugger; let otf = actionId; GURPS.executeOTF(otf, actor=actor); // doRoll({ actor, formula, targetmods, prefix, thing, chatthing, origtarget: target, optionalArgs: opt }) } + + async #handleSpellAction(actor, actionId) { + /* Spells are done using the otf method. Grab the otf and pass it to the function. */ + let GURPS = globalThis.GURPS; + + // debugger; + let otf = actionId; + GURPS.executeOTF(otf, actor=actor); + + + } } })