From 1876f4097f272484a026570447226a15b945d694 Mon Sep 17 00:00:00 2001 From: liquidox Date: Sat, 25 Mar 2017 09:56:19 +0800 Subject: [PATCH] feat(token-defaults): Provide option to only link bars for PCs closes #402 --- lib/modules/config-ui.js | 28 ++++++++++++++++++---------- lib/modules/monster-manager.js | 2 +- lib/shaped-config.js | 10 +++++++++- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/modules/config-ui.js b/lib/modules/config-ui.js index c3c0b9e..7186089 100644 --- a/lib/modules/config-ui.js +++ b/lib/modules/config-ui.js @@ -409,25 +409,33 @@ class TokenBarsMenu extends ConfigMenu { let optionRows = ''; for (let i = 1; i <= 3; i++) { - const currAttr = Utils.getObjectFromPath(this.config, `${ts}.bar${i}.attribute`); + const attrPath = `${ts}.bar${i}.attribute`; + const currAttr = Utils.getObjectFromPath(this.config, attrPath); const currAttrEmptyHint = currAttr || '[not set]'; - const currMax = Utils.getObjectFromPath(this.config, `${ts}.bar${i}.max`); - const currLink = Utils.getObjectFromPath(this.config, `${ts}.bar${i}.link`); + const maxPath = `${ts}.bar${i}.max`; + const currMax = Utils.getObjectFromPath(this.config, maxPath); + const linkPath = `${ts}.bar${i}.link`; + const linkSpec = this.specRoot.tokenSettings[`bar${i}`].link(); + const currLink = _.invert(linkSpec)[Utils.getObjectFromPath(this.config, linkPath)]; const attBtn = this.makeOptionButton({ - path: `${ts}.bar${i}.attribute`, linkText: this.makeText(currAttrEmptyHint), tooltip: 'click to edit', - buttonClass: currAttrEmptyHint === '[not set]' ? 'notselected' : '', width: 60, + path: attrPath, linkText: this.makeText(currAttrEmptyHint), tooltip: 'click to edit', + buttonClass: currAttrEmptyHint === '[not set]' ? 'notselected' : '', command: `?{Bar ${i} Attribute (empty to unset)|${currAttr}} --${menu}`, }); const maxBtn = this.makeOptionButton({ - path: `${ts}.bar${i}.max`, linkText: this.makeBoolText(currMax), tooltip: 'click to toggle', - buttonClass: currMax ? '' : 'notselected', width: 60, + path: maxPath, linkText: this.makeBoolText(currMax), tooltip: 'click to toggle', + buttonClass: currMax ? '' : 'notselected', command: `${!currMax} --${menu}`, }); + + const linkBtn = this.makeOptionButton({ - path: `${ts}.bar${i}.link`, linkText: this.makeBoolText(currLink), tooltip: 'click to togle', - buttonClass: currLink ? '' : 'notselected', width: 60, - command: `${!currLink} --${menu}`, + path: linkPath, + buttonClass: currLink ? '' : 'notselected', + command: `${this.getQueryCommand(linkPath, 'Link', linkSpec)} --${menu}`, + linkText: this.makeText(currLink), + tooltip: 'click to change', }); optionRows += this.makeThreeColOptionTable({ diff --git a/lib/modules/monster-manager.js b/lib/modules/monster-manager.js index ddea3e5..b6f3117 100644 --- a/lib/modules/monster-manager.js +++ b/lib/modules/monster-manager.js @@ -449,7 +449,7 @@ module.exports = class MonsterManager extends ShapedModule { // We create attribute here to ensure we have control over the id const attribute = this.roll20.getOrCreateAttr(character.id, bar.attribute); if (attribute) { - if (bar.link) { + if (bar.link && !(bar.link === 'pcOnly' && isNpc)) { token.set(`${barName}_link`, attribute.id); } else { diff --git a/lib/shaped-config.js b/lib/shaped-config.js index 45670dd..468d7f1 100644 --- a/lib/shaped-config.js +++ b/lib/shaped-config.js @@ -678,11 +678,19 @@ module.exports = class ShapedConfig extends ShapedModule { return this.getOptionList(ShapedConfig.validStatusMarkers()); } + static get barLinkValidator() { + return this.getOptionList({ + always: true, + pcOnly: 'pcOnly', + never: false, + }); + } + static get barValidator() { return { attribute: this.stringValidator, max: this.booleanValidator, - link: this.booleanValidator, + link: this.barLinkValidator, showPlayers: this.booleanValidator, }; }