Skip to content

Commit

Permalink
feat(rests): Support passing character ID option
Browse files Browse the repository at this point in the history
passing a character ID to the rests command (e.g. !shaped-rests --long --id characterID) will process a long rest for that character
  • Loading branch information
jaltepeter committed Apr 30, 2016
1 parent ec4d4a6 commit 3dae840
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/shaped-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ function ShapedScripts(logger, myState, roll20, parser, entityLookup, reporter,
const defaultIndex = Math.min(myState.config.defaultGenderIndex, myState.config.genderPronouns.length);
const defaultPronounInfo = myState.config.genderPronouns[defaultIndex];
const pronounInfo = _.clone(_.find(myState.config.genderPronouns,
pronounDetails => new RegExp(pronounDetails.matchPattern, 'i').test(gender)) || defaultPronounInfo);
pronounDetails => new RegExp(pronounDetails.matchPattern, 'i').test(gender)) || defaultPronounInfo);

_.defaults(pronounInfo, defaultPronounInfo);

Expand Down Expand Up @@ -726,7 +726,7 @@ function ShapedScripts(logger, myState, roll20, parser, entityLookup, reporter,
}
};
/* eslint-disable no-spaced-func */
}(token.id)), 100);
} (token.id)), 100);
};

this.handleChangeToken = function handleChangeToken(token) {
Expand Down Expand Up @@ -820,7 +820,7 @@ function ShapedScripts(logger, myState, roll20, parser, entityLookup, reporter,
.groupBy(attribute => attribute.get('name').replace(/(repeating_ammo_[^_]+).*/, '$1'))
.find(attributeList =>
_.find(attributeList, attribute =>
attribute.get('name').match(/.*name$/) && attribute.get('current') === options.ammoName)
attribute.get('name').match(/.*name$/) && attribute.get('current') === options.ammoName)
)
.find(attribute => attribute.get('name').match(/.*qty$/))
.value();
Expand Down Expand Up @@ -870,6 +870,10 @@ function ShapedScripts(logger, myState, roll20, parser, entityLookup, reporter,
};

this.handleRest = function handleRest(options) {
if (!_.isUndefined(options.id)) {
// if an ID is passed, overwrite any selection, and only process for the passed charId
options.selected.character = [options.id];
}
if (options.long) {
// handle long rest
rester.doLongRest(options.selected.character);
Expand Down Expand Up @@ -925,7 +929,7 @@ function ShapedScripts(logger, myState, roll20, parser, entityLookup, reporter,
let msg;

const bestSlot = availableSlots
.find(slot => parseInt(slot.get('name').match(/spell_slots_l(\d)/)[1], 10) === level) ||
.find(slot => parseInt(slot.get('name').match(/spell_slots_l(\d)/)[1], 10) === level) ||
_.first(availableSlots);

if (bestSlot) {
Expand Down Expand Up @@ -1266,7 +1270,7 @@ function ShapedScripts(logger, myState, roll20, parser, entityLookup, reporter,

this.getCommandProcessor = function getCommandProcessor() {
return cp('shaped', roll20)
// !shaped-config
// !shaped-config
.addCommand('config', this.configure.bind(this))
.options(configOptionsSpec)
.option('atMenu', booleanValidator)
Expand Down Expand Up @@ -1355,9 +1359,10 @@ function ShapedScripts(logger, myState, roll20, parser, entityLookup, reporter,
.addCommand('rest', this.handleRest.bind(this))
.option('long', booleanValidator)
.option('short', booleanValidator)
.option('id', getCharacterValidator(roll20), false)
.withSelection({
character: {
min: 1,
min: 0,
max: Infinity,
},
})
Expand Down

0 comments on commit 3dae840

Please sign in to comment.