From 68e71464e1ec5dc9aa244aad1d4e51e8ab21e68a Mon Sep 17 00:00:00 2001 From: Lucian Date: Tue, 21 Mar 2017 21:43:26 +0100 Subject: [PATCH] feat(config): Tidy up config display + align with latest sheet closes #409 --- lib/modules/config-ui.js | 195 +++++++++++++++------------------ lib/modules/monster-manager.js | 10 +- lib/modules/spell-manager.js | 25 ++--- lib/reporter.js | 12 +- lib/shaped-config.js | 96 +++++++++++++--- 5 files changed, 190 insertions(+), 148 deletions(-) diff --git a/lib/modules/config-ui.js b/lib/modules/config-ui.js index 3a5febb..c3c0b9e 100644 --- a/lib/modules/config-ui.js +++ b/lib/modules/config-ui.js @@ -39,13 +39,15 @@ class ConfigUi extends ShapedModule { // drop "menu" options Utils.deepExtend(this.myState.config, _.omit(options, 'menu')); + const msg = this.reporter.getMessageBuilder('Configuration', false, options.playerId); if (options.menu) { - this.reportPlayer('Configuration', options.menu[0].getMenu(), options.playerId); + options.menu[0].writeMenu(msg); } else if (_.isEmpty(_.omit(options, 'menu', 'playerId'))) { const menu = new MainMenu(this.myState.config, ShapedConfig.configOptionsSpec); - this.reportPlayer('Configuration', menu.getMenu(), options.playerId); + menu.writeMenu(msg); } + msg.display(); } } @@ -69,7 +71,7 @@ class ConfigMenu { params.command = `${!currentVal}${!_.isUndefined(params.menuCmd) ? ` --${params.menuCmd}` : ''}`; params.linkText = this.makeBoolText(currentVal); params.tooltip = 'click to toggle'; - params.buttonColor = currentVal ? '#65c4bd' : '#f84545'; + params.buttonClass = currentVal ? '' : 'notselected'; return this.makeOptionRow(params); } @@ -81,7 +83,6 @@ class ConfigMenu { params.command = `${cmd}${!_.isUndefined(params.menuCmd) ? ` --${params.menuCmd}` : ''}`; params.linkText = this.makeText(currentVal); params.tooltip = 'click to change'; - params.buttonColor = '#02baf2'; return this.makeOptionRow(params); } @@ -92,62 +93,37 @@ class ConfigMenu { params.command = `?{${params.prompt}|${currentVal}}${!_.isUndefined(params.menuCmd) ? ` --${params.menuCmd}` : ''}`; params.linkText = currentVal || '[not set]'; params.tooltip = 'click to edit'; - params.buttonColor = params.linkText === '[not set]' ? '#f84545' : '#02baf2'; + params.buttonClass = params.linkText === '[not set]' ? 'notselected' : ''; return this.makeOptionRow(params); } - // noinspection JSUnusedGlobalSymbols - makeColorSetting(params) { - const currentVal = Utils.getObjectFromPath(this.config, params.path); - - params.command = `?{${params.prompt}|${currentVal}}${!_.isUndefined(params.menuCmd) ? ` --${params.menuCmd}` : ''}`; - params.linkText = currentVal || '[not set]'; - params.tooltip = 'click to edit'; - params.buttonColor = params.linkText === '[not set]' ? '#02baf2' : currentVal; - params.buttonTextColor = Utils.getContrastYIQ(params.buttonColor); - return this.makeOptionRow(params); + backToMainMenuButton() { + return this.makeBackButton('Main Menu'); } - backToMainMenuButton() { - return Utils.buildHTML('a', '<-- Main Menu', { - href: '!shaped-config', - style: 'text-align: center; margin: 5px 0 0 0; padding: 2px 2px ; border-radius: 10px; white-space: nowrap; ' + - 'overflow: hidden; text-overflow: ellipsis; background-color: #02baf2; border-color: #c0c0c0;', + makeBackButton(text, targetMenu) { + const menuOption = targetMenu ? `--${targetMenu}` : ''; + return Utils.buildHTML('a', `<-- ${text}`, { + href: `!shaped-config ${menuOption}`, }); } backToTokenOptions() { - return Utils.buildHTML('a', '<-- Token Options', { - href: '!shaped-config --tsMenu', - style: 'text-align: center; margin: 5px 0 0 0; padding: 2px 2px ; border-radius: 10px; white-space: nowrap; ' + - 'overflow: hidden; text-overflow: ellipsis; background-color: #02baf2; border-color: #c0c0c0;', - }); + return this.makeBackButton('Token Options', 'tsMenu'); } backToNewCharOptions() { - return Utils.buildHTML('a', '<-- New Character Options', { - href: '!shaped-config --ncMenu', - style: 'text-align: center; margin: 5px 0 0 0; padding: 2px 2px ; border-radius: 10px; white-space: nowrap; ' + - 'overflow: hidden; text-overflow: ellipsis; background-color: #02baf2; border-color: #c0c0c0;', - }); + return this.makeBackButton('New Character Options', 'ncMenu'); } backToHouseRuleOptions() { - return Utils.buildHTML('a', '<-- Houserule Options', { - href: '!shaped-config --hrMenu', - style: 'text-align: center; margin: 5px 0 0 0; padding: 2px 2px ; border-radius: 10px; white-space: nowrap; ' + - 'overflow: hidden; text-overflow: ellipsis; background-color: #02baf2; border-color: #c0c0c0;', - }); + return this.makeBackButton('Houserule Options', 'hrMenu'); } backToSavesOptions() { - return Utils.buildHTML('a', '<-- Saves Options', { - href: '!shaped-config --savesMenu', - style: 'text-align: center; margin: 5px 0 0 0; padding: 2px 2px ; border-radius: 10px; white-space: nowrap; ' + - 'overflow: hidden; text-overflow: ellipsis; background-color: #02baf2; border-color: #c0c0c0;', - }); + return this.makeBackButton('Saves Options', 'saveMenu'); } getQueryCommand(path, title, optionsSpec) { @@ -181,25 +157,29 @@ class ConfigMenu { let css = `text-align: center; width: ${params.width}px; margin: 2px 0 -3px 0; ` + 'padding: 2px 2px ; border-radius: 10px; border-color: #c0c0c0;' + - `white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background-color: ${params.buttonColor};`; + 'white-space: nowrap; overflow: hidden; text-overflow: ellipsis;'; if (params.buttonTextColor) { - css += `color: ${params.buttonTextColor}`; + css += `color: ${params.buttonTextColor};`; + } + if (params.buttonColor) { + css += `background-color: ${params.buttonColor};`; } return Utils.buildHTML('a', params.linkText, { style: css, + class: params.buttonClass, href: `!shaped-config --${params.path} ${params.command}`, }); } makeText(value) { - return Utils.buildHTML('span', value, { style: 'padding: 0 2px;' }); + return Utils.buildHTML('span', value); } makeBoolText(value) { return value === true ? - Utils.buildHTML('span', 'on', { style: 'padding: 0 2px;' }) : - Utils.buildHTML('span', 'off', { style: 'padding: 0 2px;' }); + Utils.buildHTML('span', 'on') : + Utils.buildHTML('span', 'off'); } /* eslint-disable object-property-newline */ @@ -278,19 +258,19 @@ class ConfigMenu { ], { style: 'border: 1px solid gray;' }); } - getMenu() { + writeMenu(msg) { const parts = this.getMenuParts(); - const th = Utils.buildHTML('th', parts.title, { colspan: '2' }); - const tr = Utils.buildHTML('tr', th, { style: 'margin-top: 5px;' }); - const footer = Utils.buildHTML('tr', Utils.buildHTML('td', parts.footerText, { colspan: '2' })); - return Utils.buildHTML('table', tr + parts.optionRows + footer, { + const content = Utils.buildHTML('table', parts.optionRows, { style: 'width: 100%; font-size: 0.9em;', class: 'shaped-config', }); + msg.addField('subheader', parts.title); + msg.addField('content', content); + msg.addField('text', parts.footerText); } getMenuParts() { - return ''; + return null; } get logWrap() { @@ -309,19 +289,19 @@ class MainMenu extends ConfigMenu { getMenuParts() { const optionRows = this.makeOptionRow({ - title: 'Advantage Tracker', path: 'atMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Advantage Tracker', path: 'atMenu', command: '', linkText: 'view -->', }) + this.makeOptionRow({ - title: 'Token Defaults', path: 'tsMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Token Defaults', path: 'tsMenu', command: '', linkText: 'view -->', }) + this.makeOptionRow({ - title: 'New Characters', path: 'ncMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'New Characters', path: 'ncMenu', command: '', linkText: 'view -->', }) + this.makeOptionRow({ - title: 'Char. Sheet Enhancements', path: 'seMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Char. Sheet Enhancements', path: 'seMenu', command: '', linkText: 'view -->', }) + this.makeOptionRow({ - title: 'Houserules & Variants', path: 'varsMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Houserules & Variants', path: 'varsMenu', command: '', linkText: 'view -->', }); return { @@ -407,10 +387,10 @@ class TokensMenu extends ConfigMenu { path: `${ts}.light.multiplier`, title: 'Light Muliplier', prompt: 'Light Muliplier', menuCmd: menu, }) + this.makeOptionRow({ - title: 'Token Bar Options', path: 'barMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Token Bar Options', path: 'barMenu', command: '', linkText: 'view -->', }) + this.makeOptionRow({ - title: 'Token Aura Options', path: 'auraMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Token Aura Options', path: 'auraMenu', command: '', linkText: 'view -->', }); return { @@ -436,17 +416,17 @@ class TokenBarsMenu extends ConfigMenu { const attBtn = this.makeOptionButton({ path: `${ts}.bar${i}.attribute`, linkText: this.makeText(currAttrEmptyHint), tooltip: 'click to edit', - buttonColor: currAttrEmptyHint === '[not set]' ? '#f84545' : '#02baf2', width: 60, + buttonClass: currAttrEmptyHint === '[not set]' ? 'notselected' : '', width: 60, 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', - buttonColor: currMax ? '#65c4bd' : '#f84545', width: 60, + buttonClass: currMax ? '' : 'notselected', width: 60, command: `${!currMax} --${menu}`, }); const linkBtn = this.makeOptionButton({ path: `${ts}.bar${i}.link`, linkText: this.makeBoolText(currLink), tooltip: 'click to togle', - buttonColor: currLink ? '#65c4bd' : '#f84545', width: 60, + buttonClass: currLink ? '' : 'notselected', width: 60, command: `${!currLink} --${menu}`, }); @@ -486,7 +466,7 @@ class TokenAurasMenu extends ConfigMenu { const radBtn = this.makeOptionButton({ path: `${ts}.aura${i}.radius`, linkText: this.makeText(currRadEmptyHint), tooltip: 'click to edit', - buttonColor: currRadEmptyHint === '[not set]' ? '#f84545' : '#02baf2', width: 60, + buttonClass: currRadEmptyHint === '[not set]' ? 'notselected' : '', width: 60, command: `?{Aura ${i} Radius (empty to unset)|${currRad}} --${menu}`, }); const colorBtn = this.makeOptionButton({ @@ -496,7 +476,7 @@ class TokenAurasMenu extends ConfigMenu { }); const squareBtn = this.makeOptionButton({ path: `tokenSettings.aura${i}.square`, linkText: this.makeBoolText(currSquare), tooltip: 'click to toggle', - buttonColor: currSquare ? '#65c4bd' : '#f84545', width: 60, + buttonClass: currSquare ? '' : 'notselected', width: 60, command: `${!currSquare} --${menu}`, }); @@ -541,19 +521,19 @@ class NewCharacterMenu extends ConfigMenu { const sheetBtn = this.makeOptionButton({ path: `${ncs}.sheetOutput`, linkText: this.makeText(currSheetOut), tooltip: 'click to change', - buttonColor: '#02baf2', width: 60, + width: 60, command: `${this.getQueryCommand(`${ncs}.sheetOutput`, 'Sheet Output', spec.sheetOutput())}` + ` --${menu}`, }); const dSaveBtn = this.makeOptionButton({ path: `${ncs}.deathSaveOutput`, linkText: this.makeText(currDSaveOut), tooltip: 'click to change', - buttonColor: '#02baf2', width: 60, + width: 60, command: `${this.getQueryCommand(`${ncs}.deathSaveOutput`, 'Death Save Output', spec.deathSaveOutput())}` + ` --${menu}`, }); const hdBtn = this.makeOptionButton({ path: `${ncs}.hitDiceOutput`, linkText: this.makeText(currHDOut), tooltip: 'click to change', - buttonColor: '#02baf2', width: 60, + width: 60, command: `${this.getQueryCommand(`${ncs}.hitDiceOutput`, 'Death Save Output', spec.hitDiceOutput())}` + ` --${menu}`, }); @@ -566,19 +546,16 @@ class NewCharacterMenu extends ConfigMenu { }); optionRows += + this.makeQuerySetting({ + path: `${ncs}.rollOptions`, title: 'Roll Options', menuCmd: menu, spec: spec.rollOptions(), + }) + this.makeOptionRow({ - title: 'Initiative Settings', path: 'initMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Initiative Settings', path: 'initMenu', command: '', linkText: 'view -->', }) + this.makeToggleSetting({ path: `${ncs}.showNameOnRollTemplate`, title: 'Show Name on Roll Template', menuCmd: menu, spec: spec.showNameOnRollTemplate(), }) + - this.makeQuerySetting({ - path: `${ncs}.rollOptions`, title: 'Roll Options', menuCmd: menu, spec: spec.rollOptions(), - }) + - this.makeToggleSetting({ - path: `${ncs}.autoRevertAdvantage`, title: 'Revert Advantage', menuCmd: menu, - }) + this.makeToggleSetting({ path: `${ncs}.showTargetAC`, title: 'Show Target AC', menuCmd: menu, }) + @@ -593,37 +570,38 @@ class NewCharacterMenu extends ConfigMenu { path: `${ncs}.automaticallyRollDamageForSavingThrows`, title: 'Auto Roll Dmg Saves', menuCmd: menu, spec: spec.automaticallyRollDamageForSavingThrows(), }) + - this.makeToggleSetting({ - path: `${ncs}.autoAmmo`, title: 'Auto Use Ammo', menuCmd: menu, + this.makeOptionRow({ + title: 'Display Settings', path: 'displayMenu', command: '', linkText: 'view -->', }) + this.makeToggleSetting({ path: `${ncs}.automaticHigherLevelQueries`, title: 'Automatic Higher Level Queries', menuCmd: menu, spec: spec.automaticHigherLevelQueries(), }) + this.makeToggleSetting({ - path: `${ncs}.automaticallyExpendSpellResources`, title: 'Auto spell slots/points', menuCmd: menu, - }) + - this.makeQuerySetting({ - path: `${ncs}.tab`, title: 'Default tab', menuCmd: menu, spec: spec.tab(), + path: `${ncs}.autoAmmo`, title: 'Auto Use Ammo', menuCmd: menu, }) + - this.makeOptionRow({ - title: 'Default Token Actions', path: 'taMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + this.makeToggleSetting({ + path: `${ncs}.autoRevertAdvantage`, title: 'Revert Advantage', menuCmd: menu, }) + - this.makeOptionRow({ - title: 'Display Settings', path: 'displayMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + this.makeToggleSetting({ + path: `${ncs}.automaticallyExpendSpellResources`, title: 'Auto spell slots/points', menuCmd: menu, }) + this.makeOptionRow({ - title: 'Houserule Settings', path: 'hrMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Houserule Settings', path: 'hrMenu', command: '', linkText: 'view -->', }) + this.makeOptionRow({ - title: 'Hide Settings', path: 'hideMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Measurement Systems', path: 'msMenu', command: '', linkText: 'view -->', }) + this.makeOptionRow({ - title: 'Measurement Systems', path: 'msMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Hide Settings', path: 'hideMenu', command: '', linkText: 'view -->', }) + this.makeOptionRow({ - title: 'Text sizes', path: 'textMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Default Token Actions', path: 'taMenu', command: '', linkText: 'view -->', }); + // + + // this.makeOptionRow({ + // title: 'Text sizes', path: 'textMenu', command: '', linkText: 'view -->', + // }); return { title: 'New Character Settings', @@ -669,9 +647,6 @@ class DisplayMenu extends ConfigMenu { const spec = this.specRoot.newCharSettings.display; const optionRows = - this.makeToggleSetting({ - path: `${display}.showRests`, title: 'Show Rests', menuCmd: menu, - }) + this.makeToggleSetting({ path: `${display}.showPassiveSkills`, title: 'Show Passive Skills', menuCmd: menu, }) + @@ -719,10 +694,6 @@ class MeasurementSystemsMenu extends ConfigMenu { this.makeQuerySetting({ path: `${ms}.weightSystem`, title: 'Weight System', prompt: 'Weight System', menuCmd: menu, spec: spec.weightSystem(), - }) + - this.makeInputSetting({ - path: `${ms}.encumbranceMultiplier`, title: 'Encumbrance Multiplier', prompt: 'Encumbrance Multiplier', - menuCmd: menu, }); return { @@ -739,8 +710,13 @@ class NewCharacterHouseruleMenu extends ConfigMenu { const menu = 'hrMenu'; const optionRows = - this.makeToggleSetting({ - path: `${hr}.inspirationMultiple`, title: 'Multiple Inspiration', menuCmd: menu, + this.makeQuerySetting({ + path: `${hr}.hitPointsRecoveredOnALongRest`, title: 'HP Recovered Long Rest', prompt: 'HP Recovered Long Rest', + menuCmd: menu, spec: this.specRoot.newCharSettings.houserules.hitPointsRecoveredOnALongRest(), + }) + + this.makeQuerySetting({ + path: `${hr}.hitDiceRecoveredOnALongRest`, title: 'HD Recovered Long Rest', prompt: 'HD Recovered Long Rest', + menuCmd: menu, spec: this.specRoot.newCharSettings.houserules.hitDiceRecoveredOnALongRest(), }) + this.makeQuerySetting({ path: `${hr}.criticalDamageHouserule`, title: 'Critical Damage', prompt: 'Critical Damage', menuCmd: menu, @@ -758,22 +734,25 @@ class NewCharacterHouseruleMenu extends ConfigMenu { this.makeToggleSetting({ path: `${hr}.expertiseAsAdvantage`, title: 'Expertise as advantage', menuCmd: menu, }) + - this.makeQuerySetting({ - path: `${hr}.baseDC`, title: 'Base DC', prompt: 'Base DC', menuCmd: menu, - spec: this.specRoot.newCharSettings.houserules.baseDC(), - }) + this.makeQuerySetting({ path: `${hr}.mediumArmorMaxDex`, title: 'Medium Armor Max Dex', menuCmd: menu, spec: this.specRoot.newCharSettings.houserules.mediumArmorMaxDex(), }) + + this.makeQuerySetting({ + path: `${hr}.baseDC`, title: 'Base DC', prompt: 'Base DC', menuCmd: menu, + spec: this.specRoot.newCharSettings.houserules.baseDC(), + }) + this.makeToggleSetting({ path: `${hr}.honorToggle`, title: 'Honor', menuCmd: menu, }) + this.makeToggleSetting({ path: `${hr}.sanityToggle`, title: 'Sanity', menuCmd: menu, }) + + this.makeToggleSetting({ + path: `${hr}.inspirationMultiple`, title: 'Multiple Inspiration', menuCmd: menu, + }) + this.makeOptionRow({ - title: 'Saving Throws', path: 'savesMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Saving Throws', path: 'savesMenu', command: '', linkText: 'view -->', }); return { @@ -791,7 +770,7 @@ class HideMenu extends ConfigMenu { const optionRows = [ 'hideAbilityChecks', 'hideSavingThrows', 'hideAttack', 'hideDamage', 'hideFreetext', 'hideRecharge', - 'hideSavingThrowDC', 'hideSavingThrowFailure', 'hideSavingThrowSuccess', 'hideContent', + 'hideTargetAC', 'hideSavingThrowDC', 'hideSavingThrowFailure', 'hideContent', ].reduce((result, functionName) => { const title = Utils.toTitleCase( functionName.replace(/([a-z])([A-Z]+)/g, (match, lower, upper) => `${lower} ${upper.toLowerCase()}`)); @@ -826,13 +805,13 @@ class SavesMenu extends ConfigMenu { path: `${saves}.useAverageOfAbilities`, title: 'Use Average of Highest Abils', menuCmd: menu, }) + this.makeOptionRow({ - title: 'Fortitude', path: 'fortitudeMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Fortitude', path: 'fortitudeMenu', command: '', linkText: 'view -->', }) + this.makeOptionRow({ - title: 'Reflex', path: 'reflexMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Reflex', path: 'reflexMenu', command: '', linkText: 'view -->', }) + this.makeOptionRow({ - title: 'Will', path: 'willMenu', command: '', linkText: 'view -->', buttonColor: '#02baf2', + title: 'Will', path: 'willMenu', command: '', linkText: 'view -->', }); return { @@ -873,7 +852,7 @@ class CustomSaveTypeMenu extends ConfigMenu { class NewCharacterTextSizeMenu extends ConfigMenu { - getMenu() { + getMenuParts() { const textSizes = 'newCharSettings.textSizes'; const menu = 'textMenu'; @@ -925,7 +904,7 @@ class VariantsMenu extends ConfigMenu { } class SheetEnhancementsMenu extends ConfigMenu { - getMenu() { + getMenuParts() { const root = 'sheetEnhancements'; const menu = 'seMenu'; @@ -956,7 +935,7 @@ class SheetEnhancementsMenu extends ConfigMenu { } class TokenActionsMenu extends ConfigMenu { - getMenu() { + getMenuParts() { const root = 'newCharSettings.tokenActions'; const menu = 'taMenu'; const spec = this.specRoot.newCharSettings.tokenActions; diff --git a/lib/modules/monster-manager.js b/lib/modules/monster-manager.js index cbbb516..ddea3e5 100644 --- a/lib/modules/monster-manager.js +++ b/lib/modules/monster-manager.js @@ -177,7 +177,7 @@ module.exports = class MonsterManager extends ShapedModule { character.set('gmnotes', text.replace(/\n/g, '
')); return character; }, - ]).then(this.displayImportResults.bind(this, options.playerId)); + ]); } displayImportResults(playerId, results) { @@ -193,7 +193,11 @@ module.exports = class MonsterManager extends ShapedModule { importMonstersFromJson(options) { return this.importMonsters(options.monsters, options, options.selected.graphic, []) - .then(this.displayImportResults.bind(this, options.playerId)); + .then((results) => { + if (options.monsters.length > 1) { + this.displayImportResults(options.playerId, results); + } + }); } importByToken(options) { @@ -322,7 +326,7 @@ module.exports = class MonsterManager extends ShapedModule { 'Importing character data', msg)) .then(newChar => this.spellManager.importData(newChar, [], false, msg)) .then((newChar) => { - msg.finish(); + msg.finish(`${character.get('name')} import complete`); return newChar; }); } diff --git a/lib/modules/spell-manager.js b/lib/modules/spell-manager.js index 78f9007..c72d48a 100644 --- a/lib/modules/spell-manager.js +++ b/lib/modules/spell-manager.js @@ -166,11 +166,12 @@ module.exports = class SpellManager extends ShapedModule { 'and your campaign more generally. '); } - return this.importData(options.selected.character, options.spells, options.overwrite) + const msg = this.reporter.getMessageStreamer('Import Spells', options.playerId); + return this.importData(options.selected.character, options.spells, options.overwrite, msg) .then(() => { const imported = options.spells.filter(spell => !spell.noImport); const skipped = options.spells.filter(spell => spell.noImport); - let message = ''; + let message = 'Import Complete
'; if (!_.isEmpty(imported)) { message += 'Added the following spells: `; @@ -179,7 +180,7 @@ module.exports = class SpellManager extends ShapedModule { message += 'Skipped the following spells which were already present (use --overwrite to replace): `; } - this.reportPlayer('Import Complete', message, options.playerId); + msg.finish(message); if (options.relist) { _.extend(options, options.relist); options.clearCache('characterSpells'); @@ -191,18 +192,9 @@ module.exports = class SpellManager extends ShapedModule { importData(character, spells, overwrite, msg) { this.logger.debug('Importing new character spells $$$', spells); const pronounInfo = this.getPronounInfo(character); - const closeMessage = !msg; - msg = msg || this.reporter.getMessageStreamer(`${character.get('name')} Spell Import`); const spellAttrs = this.getSpellAttributesForImport(character, pronounInfo, spells, overwrite); - const promise = _.isEmpty(spellAttrs) ? Promise.resolve(character) : + return _.isEmpty(spellAttrs) ? Promise.resolve(character) : this.importer.runImportStage(character, spellAttrs, 'Importing spells', msg); - - return promise.then((newChar) => { - if (closeMessage) { - msg.finish(); - } - return newChar; - }); } removeSpell(options) { @@ -363,13 +355,14 @@ module.exports = class SpellManager extends ShapedModule { options.selected.character = this.roll20.findObjs({ type: 'character' }); } + const msg = this.reporter.getMessageStreamer('Expand Spells', options.playerId); return options.selected.character.reduce((promise, character) => - promise.then(() => this.importData(character, [])), + promise.then(() => this.importData(character, [], false, msg)), Promise.resolve()) .then(() => { - const msg = ' Spells expanded for characters: