Use constants

This commit is contained in:
Bryan Ashby 2018-12-09 02:32:41 -07:00
parent 704c242aa4
commit 844286ea1c
1 changed files with 13 additions and 13 deletions

View File

@ -3,7 +3,10 @@
// ENiGMA½ // ENiGMA½
const loadMenu = require('./menu_util.js').loadMenu; const loadMenu = require('./menu_util.js').loadMenu;
const Errors = require('./enig_error.js').Errors; const {
Errors,
ErrorReasons
} = require('./enig_error.js');
// deps // deps
const _ = require('lodash'); const _ = require('lodash');
@ -43,26 +46,23 @@ module.exports = class MenuStack {
get currentModule() { get currentModule() {
const top = this.top(); const top = this.top();
if(top) { assert(top, 'Empty menu stack!');
return top.instance; return top.instance;
}
} }
next(cb) { next(cb) {
const currentModuleInfo = this.top(); const currentModuleInfo = this.top();
assert(currentModuleInfo, 'Empty menu stack!'); const menuConfig = currentModuleInfo.instance.menuConfig;
const nextMenu = this.client.acs.getConditionalValue(menuConfig.next, 'next');
const menuConfig = currentModuleInfo.instance.menuConfig;
const nextMenu = this.client.acs.getConditionalValue(menuConfig.next, 'next');
if(!nextMenu) { if(!nextMenu) {
return cb(Array.isArray(menuConfig.next) ? return cb(Array.isArray(menuConfig.next) ?
Errors.MenuStack('No matching condition for "next"', 'NOCONDMATCH') : Errors.MenuStack('No matching condition for "next"', ErrorReasons.NoConditionMatch) :
Errors.MenuStack('Invalid or missing "next" member in menu config', 'BADNEXT') Errors.MenuStack('Invalid or missing "next" member in menu config', ErrorReasons.InvalidNextMenu)
); );
} }
if(nextMenu === currentModuleInfo.name) { if(nextMenu === currentModuleInfo.name) {
return cb(Errors.MenuStack('Menu config "next" specifies current menu', 'ALREADYTHERE')); return cb(Errors.MenuStack('Menu config "next" specifies current menu', ErrorReasons.AlreadyThere));
} }
this.goto(nextMenu, { }, cb); this.goto(nextMenu, { }, cb);
@ -86,7 +86,7 @@ module.exports = class MenuStack {
return this.goto(previousModuleInfo.name, opts, cb); return this.goto(previousModuleInfo.name, opts, cb);
} }
return cb(Errors.MenuStack('No previous menu available', 'NOPREV')); return cb(Errors.MenuStack('No previous menu available', ErrorReasons.NoPreviousMenu));
} }
goto(name, options, cb) { goto(name, options, cb) {
@ -102,7 +102,7 @@ module.exports = class MenuStack {
if(currentModuleInfo && name === currentModuleInfo.name) { if(currentModuleInfo && name === currentModuleInfo.name) {
if(cb) { if(cb) {
cb(Errors.MenuStack('Already at supplied menu', 'ALREADYTHERE')); cb(Errors.MenuStack('Already at supplied menu', ErrorReasons.AlreadyThere));
} }
return; return;
} }