restart #1

Merged
neillc merged 5 commits from restart into main 2024-05-06 11:41:02 +10:00
6 changed files with 306 additions and 7 deletions

4
.gitignore vendored
View file

@ -1,2 +1,4 @@
node_modules/*
*zip
.vscode/
mkzip.sh
*.zip

View file

@ -1,6 +1,6 @@
{
"id": "token-action-hud-gurps",
"title": "Token Action HUD GURPS",
"title": "Token Action HUD for GURPS",
"description": "Token Action HUD is a repositionable HUD of actions for a selected token",
"authors": [
{
@ -10,10 +10,10 @@
],
"url": "This is auto replaced",
"flags": {},
"version": "0.0.2",
"version": "0.0.97",
"compatibility": {
"minimum": "11",
"verified": "11.313"
"verified": "11.351"
},
"esmodules": [
"./scripts/init.js"
@ -63,7 +63,8 @@
}
},
"socket": false,
"readme": "https://github.com/Larkinabout/fvtt-token-action-hud-template#readme",
"readme": "http://172.23.0.17:8000/module.json",
"manifest": "http://172.23.0.17:8000/module.json",
"download": "http://172.23.0.17:8000/fvtt-token-action-hud-gurps.zip",
"protected": false,
"coreTranslation": false,

View file

@ -28,9 +28,11 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
let items = this.actor.items
items = coreModule.api.Utils.sortItemsByName(items)
this.items = items
}
if (this.actorType === 'character') {
//debugger;
this.#buildCharacterActions()
} else if (!this.actor) {
this.#buildMultipleTokenActions()
@ -42,9 +44,160 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
* @private
*/
#buildCharacterActions () {
// 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()
}
_get_attributes(parent) {
const macroType = "attributes";
let actions = [];
let attributes = Object.entries(this.actor.system.attributes)
attributes.forEach((a) => {
const key = a[0];
const value = a[1].value
// img
let actionId = key
if ( key == "WILL" ) actionId = "Will";
if ( key == "PER" ) actionId = "Per";
actions.push({
id: actionId,
name: coreModule.api.Utils.i18n("GURPS.attributes" + key),
description: coreModule.api.Utils.i18n('GURPS.attributes'),
encodedValue: [macroType, key].join(this.delimiter),
})
});
this.addActions(actions, parent)
}
_get_melee_attacks(parent) {
// debugger;
const macroType = "melee";
let actions = [];
let melee_attacks = Object.entries(this.actor.system.melee)
melee_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 = '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_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;
const macroType = "skills";
let actions = [];
let skills = Object.entries(this.actor.system.skills)
skills.forEach((a) => {
const key = a[1].name;
const value = a[1].level
// img
let actionId = key;
let otf = 'Sk:"' + 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.Skills'),
encodedValue: [macroType, otf].join(this.delimiter),
})
});
this.addActions(actions, parent)
}
_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

View file

@ -28,7 +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: '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' },
@ -44,6 +52,11 @@ export const GROUP = {
* Item types
*/
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' },

View file

@ -12,8 +12,51 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
group.listName = `Group: ${coreModule.api.Utils.i18n(group.listName ?? group.name)}`
})
const groupsArray = Object.values(groups)
// debugger;
DEFAULTS = {
layout: [
{
nestId: 'attributes',
id: 'attributes',
name: coreModule.api.Utils.i18n('GURPS.attributes'),
groups: [
{ ...groups.attributes, nestId: 'attributes_attributes' }
]
},
{
nestId: 'skills',
id: 'skills',
name: coreModule.api.Utils.i18n('GURPS.skills'),
groups: [
{ ...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' }
]
},
{
nestId: 'melee',
id: 'melee',
name: coreModule.api.Utils.i18n('GURPS.meleeWeapons'),
groups: [
{ ...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' }
]
},
{
nestId: 'inventory',
id: 'inventory',
@ -37,7 +80,7 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
{ ...groups.rests, nestId: 'utility_rests' },
{ ...groups.utility, nestId: 'utility_utility' }
]
}
},
],
groups: groupsArray
}

View file

@ -1,3 +1,8 @@
import {doRoll} from "/systems/gurps/module/dierolls/dieroll.js"
// Do we need to use executeOTF?
export let RollHandler = null
Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
@ -74,7 +79,22 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
case 'utility':
this.#handleUtilityAction(token, actionId)
break
}
case 'attributes':
this.#handleAttributeAction(actor, actionId)
break
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
}
}
/**
@ -104,5 +124,72 @@ Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
break
}
}
async #handleAttributeAction(actor, actionId) {
// actor, formula, targetmods, prefix = '', thing = '', chatthing = '', origtarget = -1, optionalArgs = {},
if ( actionId == "WILL" ) actionId = "Will";
if ( actionId == "PER" ) actionId = "Per";
// debugger;
let formula = '3d6';
let targetmods = null;
let prefix = "Rolls vs" // should be i18n of 'GURPS.rollVs'
let attrname = coreModule.api.Utils.i18n(GURPS.attributeNames[actionId])
let thing = attrname; // actionID ?
let chatthing = attrname + "/[@" + actor.id + "@" + coreModule.api.Utils.i18n(GURPS.attributes[actionId]) +"]";
let target = actor.system.attributes[actionId.toUpperCase()].value;
let opt = {};
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;
// actor, formula, targetmods, prefix = '', thing = '', chatthing = '', origtarget = -1, optionalArgs = {},
// executeOTF(inputstring, priv = false, event = null, actor = null) {
// 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);
}
}
})