From 1d5328a9f108750ae6314e1741bb532fb3222cc5 Mon Sep 17 00:00:00 2001 From: Neill Cox Date: Mon, 6 May 2024 11:33:00 +1000 Subject: [PATCH] Melee attacks --- module.json | 2 +- scripts/action-handler.js | 31 ++++++++++++++++++++++++++++++- scripts/constants.js | 2 ++ scripts/defaults.js | 8 ++++++++ scripts/roll-handler.js | 5 ++++- 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/module.json b/module.json index e759258..03e77de 100644 --- a/module.json +++ b/module.json @@ -10,7 +10,7 @@ ], "url": "This is auto replaced", "flags": {}, - "version": "0.0.68", + "version": "0.0.72", "compatibility": { "minimum": "11", "verified": "11.351" diff --git a/scripts/action-handler.js b/scripts/action-handler.js index 046369b..3f82c98 100644 --- a/scripts/action-handler.js +++ b/scripts/action-handler.js @@ -44,9 +44,10 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { * @private */ #buildCharacterActions () { - debugger; + // debugger; this._get_attributes({id: "attributes", type:"system"}) this._get_skills({id: "skills", type:"system"}) + this._get_melee_attacks({id: "melee", type:"system"}) this.#buildInventory() } @@ -77,6 +78,34 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { } + _get_melee_attacks(parent) { + 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 + ")"; + const value = a[1].level + // img + + let actionId = key; + let otf = 'M:"' + 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.meleeWeapons'), + encodedValue: [macroType, otf].join(this.delimiter), + }) + + + }); + this.addActions(actions, parent) + + } + _get_skills(parent) { debugger; const macroType = "skills"; diff --git a/scripts/constants.js b/scripts/constants.js index 17737f4..da28a83 100644 --- a/scripts/constants.js +++ b/scripts/constants.js @@ -31,6 +31,7 @@ export const ACTION_TYPE = { 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' }, 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' }, @@ -48,6 +49,7 @@ export const GROUP = { export const ITEM_TYPE = { attributes: { groupId: 'attributes' }, skills: { groupId: 'skills' }, + melee: { groupId: 'melee' }, armor: { groupId: 'armor' }, backpack: { groupId: 'containers' }, consumable: { groupId: 'consumables' }, diff --git a/scripts/defaults.js b/scripts/defaults.js index cdc72f7..b11b6ae 100644 --- a/scripts/defaults.js +++ b/scripts/defaults.js @@ -31,6 +31,14 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { { ...groups.skills, nestId: 'skills_skills' } ] }, + { + nestId: 'melee', + id: 'melee', + name: coreModule.api.Utils.i18n('GURPS.meleeWeapons'), + groups: [ + { ...groups.melee, nestId: 'melee_melee' } + ] + }, { nestId: 'inventory', id: 'inventory', diff --git a/scripts/roll-handler.js b/scripts/roll-handler.js index db7391f..a9c0ca9 100644 --- a/scripts/roll-handler.js +++ b/scripts/roll-handler.js @@ -85,7 +85,10 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => { case 'skills': this.#handleSkillAction(actor, actionId) break - } + case 'melee': + this.#handleMeleeAction(actor, actionId) + break + } } /**