Skip to content

Commit

Permalink
feat(token-defaults): Provide option to only link bars for PCs
Browse files Browse the repository at this point in the history
closes #402
  • Loading branch information
liquidox authored and symposion committed Mar 26, 2017
1 parent 7f93f6b commit 1876f40
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
28 changes: 18 additions & 10 deletions lib/modules/config-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/monster-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion lib/shaped-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
Expand Down

0 comments on commit 1876f40

Please sign in to comment.