mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-06 12:47:13 +02:00
Pardon the noise. More tab to space conversion!
This commit is contained in:
parent
c3635bb26b
commit
1d8be6b014
128 changed files with 8017 additions and 8017 deletions
|
@ -1,20 +1,20 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
// ENiGMA½
|
||||
const loadMenu = require('./menu_util.js').loadMenu;
|
||||
const Errors = require('./enig_error.js').Errors;
|
||||
// ENiGMA½
|
||||
const loadMenu = require('./menu_util.js').loadMenu;
|
||||
const Errors = require('./enig_error.js').Errors;
|
||||
|
||||
// deps
|
||||
const _ = require('lodash');
|
||||
const assert = require('assert');
|
||||
// deps
|
||||
const _ = require('lodash');
|
||||
const assert = require('assert');
|
||||
|
||||
// :TODO: Stack is backwards.... top should be most recent! :)
|
||||
// :TODO: Stack is backwards.... top should be most recent! :)
|
||||
|
||||
module.exports = class MenuStack {
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
this.stack = [];
|
||||
this.client = client;
|
||||
this.stack = [];
|
||||
}
|
||||
|
||||
push(moduleInfo) {
|
||||
|
@ -52,8 +52,8 @@ module.exports = class MenuStack {
|
|||
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) {
|
||||
return cb(Array.isArray(menuConfig.next) ?
|
||||
Errors.MenuStack('No matching condition for "next"', 'NOCONDMATCH') :
|
||||
|
@ -71,16 +71,16 @@ module.exports = class MenuStack {
|
|||
prev(cb) {
|
||||
const menuResult = this.top().instance.getMenuResult();
|
||||
|
||||
// :TODO: leave() should really take a cb...
|
||||
this.pop().instance.leave(); // leave & remove current
|
||||
// :TODO: leave() should really take a cb...
|
||||
this.pop().instance.leave(); // leave & remove current
|
||||
|
||||
const previousModuleInfo = this.pop(); // get previous
|
||||
const previousModuleInfo = this.pop(); // get previous
|
||||
|
||||
if(previousModuleInfo) {
|
||||
const opts = {
|
||||
extraArgs : previousModuleInfo.extraArgs,
|
||||
savedState : previousModuleInfo.savedState,
|
||||
lastMenuResult : menuResult,
|
||||
extraArgs : previousModuleInfo.extraArgs,
|
||||
savedState : previousModuleInfo.savedState,
|
||||
lastMenuResult : menuResult,
|
||||
};
|
||||
|
||||
return this.goto(previousModuleInfo.name, opts, cb);
|
||||
|
@ -108,8 +108,8 @@ module.exports = class MenuStack {
|
|||
}
|
||||
|
||||
const loadOpts = {
|
||||
name : name,
|
||||
client : self.client,
|
||||
name : name,
|
||||
client : self.client,
|
||||
};
|
||||
|
||||
if(currentModuleInfo && currentModuleInfo.menuFlags.includes('forwardArgs')) {
|
||||
|
@ -117,19 +117,19 @@ module.exports = class MenuStack {
|
|||
} else {
|
||||
loadOpts.extraArgs = options.extraArgs || _.get(options, 'formData.value');
|
||||
}
|
||||
loadOpts.lastMenuResult = options.lastMenuResult;
|
||||
loadOpts.lastMenuResult = options.lastMenuResult;
|
||||
|
||||
loadMenu(loadOpts, (err, modInst) => {
|
||||
if(err) {
|
||||
// :TODO: probably should just require a cb...
|
||||
// :TODO: probably should just require a cb...
|
||||
const errCb = cb || self.client.defaultHandlerMissingMod();
|
||||
errCb(err);
|
||||
} else {
|
||||
self.client.log.debug( { menuName : name }, 'Goto menu module');
|
||||
|
||||
//
|
||||
// If menuFlags were supplied in menu.hjson, they should win over
|
||||
// anything supplied in code.
|
||||
// If menuFlags were supplied in menu.hjson, they should win over
|
||||
// anything supplied in code.
|
||||
//
|
||||
let menuFlags;
|
||||
if(0 === modInst.menuConfig.options.menuFlags.length) {
|
||||
|
@ -137,14 +137,14 @@ module.exports = class MenuStack {
|
|||
} else {
|
||||
menuFlags = modInst.menuConfig.options.menuFlags;
|
||||
|
||||
// in code we can ask to merge in
|
||||
// in code we can ask to merge in
|
||||
if(Array.isArray(options.menuFlags) && options.menuFlags.includes('mergeFlags')) {
|
||||
menuFlags = _.uniq(menuFlags.concat(options.menuFlags));
|
||||
}
|
||||
}
|
||||
|
||||
if(currentModuleInfo) {
|
||||
// save stack state
|
||||
// save stack state
|
||||
currentModuleInfo.savedState = currentModuleInfo.instance.getSaveState();
|
||||
|
||||
currentModuleInfo.instance.leave();
|
||||
|
@ -154,18 +154,18 @@ module.exports = class MenuStack {
|
|||
}
|
||||
|
||||
if(menuFlags.includes('popParent')) {
|
||||
this.pop().instance.leave(); // leave & remove current
|
||||
this.pop().instance.leave(); // leave & remove current
|
||||
}
|
||||
}
|
||||
|
||||
self.push({
|
||||
name : name,
|
||||
instance : modInst,
|
||||
extraArgs : loadOpts.extraArgs,
|
||||
menuFlags : menuFlags,
|
||||
name : name,
|
||||
instance : modInst,
|
||||
extraArgs : loadOpts.extraArgs,
|
||||
menuFlags : menuFlags,
|
||||
});
|
||||
|
||||
// restore previous state if requested
|
||||
// restore previous state if requested
|
||||
if(options.savedState) {
|
||||
modInst.restoreSavedState(options.savedState);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue