Skip to content

Commit

Permalink
fix(startup): Scale timeout to size of campaign
Browse files Browse the repository at this point in the history
Still trying to fix #341
  • Loading branch information
symposion committed Feb 26, 2017
1 parent 949ac71 commit 155e45a
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions lib/entry-point.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,25 @@ roll20.on('ready', () => {
logger.info('-=> ShapedScripts %%GULP_INJECT_VERSION%% <=-');
Migrator.migrateShapedConfig(myState, logger);
const character = roll20.createObj('character', { name: 'SHAPED_VERSION_TESTER' });
setTimeout(() => {
roll20.createAttrWithWorker(character.id, 'sheet_opened', 1, () => {
const version = roll20.getAttrByName(character.id, 'version');
setTimeout(() => {
_.invoke(roll20.findObjs({ type: 'character', name: 'SHAPED_VERSION_TESTER' }), 'remove');
}, 1000);
logger.info('Detected sheet version as : $$$', version);
if (utils.versionCompare(version, MINIMUM_SHEET_VERSION) < 0) {
reporter.reportError(`Incompatible sheet version. You need at least version ${MINIMUM_SHEET_VERSION} to use ` +
'this script.');
return;
}
const ed = new EventDispatcher(roll20, errorHandler, logger, reporter);
const cw = new ChatWatcher(roll20, logger, ed);
const commandProc = makeCommandProc('shaped', roll20, errorHandler, ed, version);
getModuleList().forEach(module => module.configure(roll20, reporter, logger, myState, commandProc, cw, ed));
});
}, 400);
const campaignSize = roll20.findObjs({}).length;
const delay = Math.max(1000, Math.floor(campaignSize / 30));
logger.debug('Campaign size: $$$', campaignSize);
roll20.createAttrWithWorker(character.id, 'sheet_opened', 1, () => {
const version = roll20.getAttrByName(character.id, 'version');
setTimeout(() => {
_.invoke(roll20.findObjs({ type: 'character', name: 'SHAPED_VERSION_TESTER' }), 'remove');
}, delay);
logger.info('Detected sheet version as : $$$', version);
if (utils.versionCompare(version, MINIMUM_SHEET_VERSION) < 0) {
reporter.reportError(`Incompatible sheet version. You need at least version ${MINIMUM_SHEET_VERSION} to use ` +
'this script.');
return;
}
const ed = new EventDispatcher(roll20, errorHandler, logger, reporter);
const cw = new ChatWatcher(roll20, logger, ed);
const commandProc = makeCommandProc('shaped', roll20, errorHandler, ed, version);
getModuleList().forEach(module => module.configure(roll20, reporter, logger, myState, commandProc, cw, ed));
});
});

module.exports = {
Expand Down

0 comments on commit 155e45a

Please sign in to comment.