mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-08-06 01:35:04 +02:00
Menu "options" block is now deprecated. Move members to "config"!
* Deprecate & allow conversion behind the scenes for now + add warning in log * Add some initial docs * Clean up prompt.hjson and menu.hjson
This commit is contained in:
parent
746bd5abd0
commit
dfe1c297b5
8 changed files with 95 additions and 83 deletions
|
@ -25,11 +25,13 @@ exports.MenuModule = class MenuModule extends PluginModule {
|
|||
this.menuName = options.menuName;
|
||||
this.menuConfig = options.menuConfig;
|
||||
this.client = options.client;
|
||||
this.menuConfig.options = options.menuConfig.options || {};
|
||||
//this.menuConfig.options = options.menuConfig.options || {};
|
||||
this.menuMethods = {}; // methods called from @method's
|
||||
this.menuConfig.config = this.menuConfig.config || {};
|
||||
|
||||
this.cls = _.isBoolean(this.menuConfig.options.cls) ? this.menuConfig.options.cls : Config().menus.cls;
|
||||
this.cls = _.get(this.menuConfig.config, 'cls', Config().menus.cls);
|
||||
|
||||
//this.cls = _.isBoolean(this.menuConfig.options.cls) ? this.menuConfig.options.cls : Config().menus.cls;
|
||||
|
||||
this.viewControllers = {};
|
||||
}
|
||||
|
@ -59,7 +61,7 @@ exports.MenuModule = class MenuModule extends PluginModule {
|
|||
|
||||
self.displayAsset(
|
||||
self.menuConfig.art,
|
||||
self.menuConfig.options,
|
||||
self.menuConfig.config,
|
||||
(err, artData) => {
|
||||
if(err) {
|
||||
self.client.log.trace('Could not display art', { art : self.menuConfig.art, reason : err.message } );
|
||||
|
@ -89,7 +91,7 @@ exports.MenuModule = class MenuModule extends PluginModule {
|
|||
|
||||
self.displayAsset(
|
||||
self.menuConfig.promptConfig.art,
|
||||
self.menuConfig.options,
|
||||
self.menuConfig.config,
|
||||
(err, artData) => {
|
||||
if(artData) {
|
||||
mciData.prompt = artData.mciMap;
|
||||
|
@ -137,9 +139,9 @@ exports.MenuModule = class MenuModule extends PluginModule {
|
|||
}
|
||||
|
||||
beforeArt(cb) {
|
||||
if(_.isNumber(this.menuConfig.options.baudRate)) {
|
||||
if(_.isNumber(this.menuConfig.config.baudRate)) {
|
||||
// :TODO: some terminals not supporting cterm style emulated baud rate end up displaying a broken ESC sequence or a single "r" here
|
||||
this.client.term.rawWrite(ansi.setEmulatedBaudRate(this.menuConfig.options.baudRate));
|
||||
this.client.term.rawWrite(ansi.setEmulatedBaudRate(this.menuConfig.config.baudRate));
|
||||
}
|
||||
|
||||
if(this.cls) {
|
||||
|
@ -220,11 +222,11 @@ exports.MenuModule = class MenuModule extends PluginModule {
|
|||
}
|
||||
|
||||
shouldPause() {
|
||||
return ('end' === this.menuConfig.options.pause || true === this.menuConfig.options.pause);
|
||||
return ('end' === this.menuConfig.config.pause || true === this.menuConfig.config.pause);
|
||||
}
|
||||
|
||||
hasNextTimeout() {
|
||||
return _.isNumber(this.menuConfig.options.nextTimeout);
|
||||
return _.isNumber(this.menuConfig.config.nextTimeout);
|
||||
}
|
||||
|
||||
haveNext() {
|
||||
|
@ -246,7 +248,7 @@ exports.MenuModule = class MenuModule extends PluginModule {
|
|||
if(this.hasNextTimeout()) {
|
||||
setTimeout( () => {
|
||||
return gotoNextMenu();
|
||||
}, this.menuConfig.options.nextTimeout);
|
||||
}, this.menuConfig.config.nextTimeout);
|
||||
} else {
|
||||
return gotoNextMenu();
|
||||
}
|
||||
|
|
|
@ -134,15 +134,28 @@ module.exports = class MenuStack {
|
|||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle deprecated 'options' block by merging to config and warning user.
|
||||
// :TODO: Remove in 0.0.10+
|
||||
//
|
||||
if(modInst.menuConfig.options) {
|
||||
self.client.log.warn(
|
||||
{ options : modInst.menuConfig.options },
|
||||
'Use of "options" is deprecated. Move relevant members to "config" block! Support will be fully removed in future versions'
|
||||
);
|
||||
Object.assign(modInst.menuConfig.config || {}, modInst.menuConfig.options);
|
||||
delete modInst.menuConfig.options;
|
||||
}
|
||||
|
||||
//
|
||||
// If menuFlags were supplied in menu.hjson, they should win over
|
||||
// anything supplied in code.
|
||||
//
|
||||
let menuFlags;
|
||||
if(0 === modInst.menuConfig.options.menuFlags.length) {
|
||||
if(0 === modInst.menuConfig.config.menuFlags.length) {
|
||||
menuFlags = Array.isArray(options.menuFlags) ? options.menuFlags : [];
|
||||
} else {
|
||||
menuFlags = modInst.menuConfig.options.menuFlags;
|
||||
menuFlags = modInst.menuConfig.config.menuFlags;
|
||||
|
||||
// in code we can ask to merge in
|
||||
if(Array.isArray(options.menuFlags) && options.menuFlags.includes('mergeFlags')) {
|
||||
|
@ -179,8 +192,8 @@ module.exports = class MenuStack {
|
|||
|
||||
const stackEntries = self.stack.map(stackEntry => {
|
||||
let name = stackEntry.name;
|
||||
if(stackEntry.instance.menuConfig.options.menuFlags.length > 0) {
|
||||
name += ` (${stackEntry.instance.menuConfig.options.menuFlags.join(', ')})`;
|
||||
if(stackEntry.instance.menuConfig.config.menuFlags.length > 0) {
|
||||
name += ` (${stackEntry.instance.menuConfig.config.menuFlags.join(', ')})`;
|
||||
}
|
||||
return name;
|
||||
});
|
||||
|
|
|
@ -61,10 +61,10 @@ function loadMenu(options, cb) {
|
|||
},
|
||||
function loadMenuModule(menuConfig, callback) {
|
||||
|
||||
menuConfig.options = menuConfig.options || {};
|
||||
menuConfig.options.menuFlags = menuConfig.options.menuFlags || [];
|
||||
if(!Array.isArray(menuConfig.options.menuFlags)) {
|
||||
menuConfig.options.menuFlags = [ menuConfig.options.menuFlags ];
|
||||
menuConfig.config = menuConfig.config || {};
|
||||
menuConfig.config.menuFlags = menuConfig.config.menuFlags || [];
|
||||
if(!Array.isArray(menuConfig.config.menuFlags)) {
|
||||
menuConfig.config.menuFlags = [ menuConfig.config.menuFlags ];
|
||||
}
|
||||
|
||||
const modAsset = asset.getModuleAsset(menuConfig.module);
|
||||
|
|
|
@ -156,7 +156,7 @@ exports.getModule = class ShowArtModule extends MenuModule {
|
|||
// :TODO: we really need a way to supply an explicit path to look in, e.g. general/area_art/
|
||||
self.displayAsset(
|
||||
artSpec,
|
||||
self.menuConfig.options,
|
||||
self.menuConfig.config,
|
||||
(err, artData) => {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
|
|
|
@ -571,7 +571,7 @@ function displayThemedPrompt(name, client, options, cb) {
|
|||
// doing so messes things up -- most terminals that support font
|
||||
// changing can only display a single font at at time.
|
||||
//
|
||||
const dispOptions = Object.assign( {}, options, promptConfig.options );
|
||||
const dispOptions = Object.assign( {}, options, promptConfig.config );
|
||||
// :TODO: We can use term detection to do nifty things like avoid this kind of kludge:
|
||||
if(!options.clearScreen) {
|
||||
dispOptions.font = 'not_really_a_font!'; // kludge :)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue