Skip to content

Commit

Permalink
fix(token-defaults): Fix a few bugs with new token defaults code
Browse files Browse the repository at this point in the history
BREAKING CHANGES: This version will no longer work with sheets
prior to 11.4.0
  • Loading branch information
symposion committed Apr 7, 2017
1 parent 17e3b49 commit 106155f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/modules/new-character-configurer.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ module.exports = class NewCharacterConfigurer extends ShapedModule {
configureCharacter(token, character) {
this.logger.debug('Configuring character: $$$', character);
return this.applyCharacterDefaults(character).then(() => {
this.configureCoreTokenSettings(token, character);
this.setTokenBarsOnDrop(token, character);
return character.get('name');
if (token) {
this.configureCoreTokenSettings(token, character);
this.setTokenBarsOnDrop(token, character);
}
return character;
});
}

Expand Down Expand Up @@ -113,7 +115,7 @@ module.exports = class NewCharacterConfigurer extends ShapedModule {
if ((imgsrc.startsWith('https://s3.amazonaws.com/files.staging.d20.io/images/') ||
imgsrc.startsWith('https://s3.amazonaws.com/files.d20.io/images/'))
&& imgsrc.replace(/\/[^.]+\.png/, '') !== character.get('avatar').replace(/\/[^.]+\.png/, '')) {
const fixedImgSrc = imgsrc.test(/\?\d+$/) ? imgsrc : `${imgsrc}`;
const fixedImgSrc = imgsrc.match(/\?\d+$/) ? imgsrc : `${imgsrc}`;
character.set('avatar', fixedImgSrc);
}
}
Expand Down Expand Up @@ -142,12 +144,18 @@ module.exports = class NewCharacterConfigurer 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) {
const value = attribute.get('current');
const max = attribute.get('max');
if (bar.link && !(bar.link === 'pcOnly' && isNpc)) {
token.set(`${barName}_link`, attribute.id);
}
else {
token.set(`${barName}_link`, '');
}
token.set(`${barName}_value`, value);
if (bar.max) {
token.set(`${barName}_max`, max);
}
token.set(`showplayers_${barName}`, bar.showPlayers);
}
}
Expand Down Expand Up @@ -205,11 +213,11 @@ module.exports = class NewCharacterConfigurer extends ShapedModule {
setTokenBarsOnDrop(token, character) {
this.logger.debug('Setting token bars on drop $$$', token);

function setBar(barName, bar, value) {
function setBar(barName, bar, value, max) {
if (value) {
token.set(`${barName}_value`, value);
if (bar.max) {
token.set(`${barName}_max`, value);
token.set(`${barName}_max`, max || value);
}
}
}
Expand Down Expand Up @@ -242,7 +250,8 @@ module.exports = class NewCharacterConfigurer extends ShapedModule {
});
}
else {
setBar(barName, bar, this.roll20.getAttrByName(character.id, bar.attribute));
setBar(barName, bar, this.roll20.getAttrByName(character.id, bar.attribute),
this.roll20.getAttrByName(character.id, bar.attribute, 'max'));
}
}
});
Expand Down

0 comments on commit 106155f

Please sign in to comment.