Skip to content

Commit

Permalink
Merge pull request #462 from symposion/roll20-shaped-scripts-430
Browse files Browse the repository at this point in the history
Roll20 shaped scripts 430
  • Loading branch information
symposion authored Apr 7, 2017
2 parents 3f7dbd5 + 106155f commit 7524336
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 386 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ Imports details of named monsters from a database of custom monsters loaded as a
* **--<monster name>** (e.g. **--Lich**) specifies a monster to import. You may supply multiple monsters as separate options, or you may supply multiple in one option separated by commas (**--Ghoul, Zombie, Ghost**)
* **--overwrite** if the selected token already represents a character in the journal, the import will fail to avoid accidentally overwriting data, unless you supply this option to confirm that you wish to do so.
* **--replace** if there is already a character in the journal with the same name as the one you are importing, the import will fail, whether or not the current token represents that character. This is to avoid creating loads of duplicates by mistake, which is almost never what you want to do. If you supply **--replace** the script will overwrite any character with the same name, unless there is more than one, in which case it will fail rather than risking overwriting the wrong one. Note that **--replace** implies **--overwrite**.
* **--as <new name>** if supplied, the new monster will be given the name specified instead of the default name defined in the database.

### Selection
You may no or 1 tokens selected when running this command:
Expand Down Expand Up @@ -300,7 +301,6 @@ You must have at least one token that represents a character selected for this c
Display configuration UI to change default behaviours. The significance of all the options is detailed [below](#configuration)

## !shaped-apply-defaults
* Alias !shaped-token-defaults *
Apply the same defaults that are used when setting up tokens on import to whatever tokens are currently selected. Useful for mass-configuring manually created tokens. See [below](#config-token-settings) for more details on what these options are.

### Selection
Expand Down
2 changes: 1 addition & 1 deletion lib/command-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function processSelection(selection, constraints, roll20, requiredCharVersion) {
if (type === 'character' && object) {
const char = roll20.getObj('character', object.get('represents'));
if (!constraintDetails.anyVersion) {
const version = roll20.getAttrByName(char.id, 'version');
const version = roll20.getAttrByName(char.id, 'version', 'current', true);
if (version !== requiredCharVersion) {
throw new UserError(`Character ${char.get('name')} is not at the required sheet version ` +
`[${requiredCharVersion}], but instead [${version}]. Try opening the character sheet or running ` +
Expand Down
8 changes: 4 additions & 4 deletions lib/entry-point.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const DeathSaveManager = require('./modules/death-save-manager');
const HDManager = require('./modules/hd-manager');
const FXManager = require('./modules/fx-manager');
const SpellManager = require('./modules/spell-manager');
const TokenBarConfigurer = require('./modules/token-bar-configurer');
const NewCharacterConfigurer = require('./modules/new-character-configurer');
const srdConverter = require('./srd-converter');
const UserError = require('./user-error');
const EventDispatcher = require('./event-dispatcher');
Expand All @@ -35,7 +35,7 @@ const logger = new Logger('5eShapedCompanion', roll20);
const entityLookup = new EntityLookup(logger);
const reporter = new Reporter(roll20, 'Shaped Scripts');

const MINIMUM_SHEET_VERSION = '11.2.0';
const MINIMUM_SHEET_VERSION = '11.4.0';
const SHEET_API_VERSION = '1';

const errorHandler = function errorHandler(e) {
Expand Down Expand Up @@ -68,7 +68,7 @@ roll20.on('ready', () => {
});

function runStartup(character, retryCount) {
const version = roll20.getAttrByName(character.id, 'version');
const version = roll20.getAttrByName(character.id, 'version', 'current', true);
const ed = new EventDispatcher(roll20, errorHandler, logger, reporter);
const cw = new ChatWatcher(roll20, logger, ed);
const commandProc = makeCommandProc('shaped', roll20, errorHandler, ed, version, logger);
Expand Down Expand Up @@ -150,10 +150,10 @@ function getModuleList() {
return []
.concat(new SheetWorkerChatOutput(deps))
.concat(new AbilityMaker(deps))
.concat(new TokenBarConfigurer(deps))
.concat(new EntityLister(deps))
.concat(new Importer(deps))
.concat(new SpellManager(deps))
.concat(new NewCharacterConfigurer(deps))
.concat(new ConfigUI(deps))
.concat(new AdvantageTracker(deps))
.concat(new UsesManager(deps))
Expand Down
5 changes: 4 additions & 1 deletion lib/event-dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ module.exports = class EventDispatcher {
const self = this;
return function handlerWrapper() {
try {
handler.apply(null, arguments);
const retVal = handler.apply(null, arguments);
if (retVal instanceof Promise) {
retVal.catch(self.errorHandler);
}
}
catch (e) {
self.errorHandler(e);
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/ability-maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class RepeatingAbilityMaker extends MacroMaker {
let name = Utils.toTitleCase(repeatingName);
if (options.showRecharges) {
const recharge = this.roll20.getAttrByName(character.id,
`repeating_${this.repeatingSection}_${repeatingId}_recharge`);
`repeating_${this.repeatingSection}_${repeatingId}_recharge`, 'current', true);
if (RECHARGE_LOOKUP[recharge]) {
name += ` ${RECHARGE_LOOKUP[recharge]}`;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/death-save-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = class DeathSaveManager extends ShapedModule {
if (this.roll20.getAttrByName(options.character.id, 'shaped_d20') === '1d20') {
return; // Sheet is set to Roll 2 - we don't know if the character has (dis)advantage so automation isn't possible
}
const currentHP = parseInt(this.roll20.getAttrByName(options.character.id, 'HP'), 10);
const currentHP = parseInt(this.roll20.getAttrByName(options.character.id, 'HP', 'current', true), 10);
if (currentHP > 0) {
this.reportResult('Death Saves', `${options.character.get('name')} has more than 0 HP and shouldn't be rolling ` +
'death saves', options);
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/hd-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module.exports = class HDManager extends ShapedModule {
const hdSize = match[2];
const hdAttr = this.roll20.getAttrObjectByName(options.character.id, `hd_d${hdSize}`);
const hpAttr = this.roll20.getOrCreateAttr(options.character.id, 'HP');
const maxReduction = parseInt(this.roll20.getAttrByName(options.character.id, 'hp_max_reduced'), 10);
const maxReduction = parseInt(
this.roll20.getAttrByName(options.character.id, 'hp_max_reduced', 'current', true), 10);
const regained = Math.max(0, parseInt(options.roll1, 10));
const fullMax = hpAttr.get('max') || Infinity;
const reducedMax = maxReduction ? fullMax - maxReduction : fullMax;
Expand Down
Loading

0 comments on commit 7524336

Please sign in to comment.