enigma-bbs/core/menu_module.js

85 lines
1.9 KiB
JavaScript
Raw Normal View History

/* jslint node: true */
'use strict';
2015-03-23 04:52:04 +00:00
var PluginModule = require('./plugin_module.js').PluginModule;
var theme = require('./theme.js');
var Log = require('./logger.js').log;
2015-03-23 04:52:04 +00:00
var async = require('async');
var assert = require('assert');
exports.MenuModule = MenuModule;
function MenuModule(options) {
PluginModule.call(this, options);
2015-03-23 04:52:04 +00:00
var self = this;
this.menuConfig = options.menuConfig;
this.menuMethods = {};
2015-03-23 04:52:04 +00:00
this.viewControllers = [];
this.initSequence = function() {
2015-03-23 04:52:04 +00:00
async.waterfall(
[
function beforeDisplayArt(callback) {
self.beforeArt();
callback(null);
},
2015-03-23 04:52:04 +00:00
function displayArt(callback) {
theme.displayThemeArt(self.menuConfig.art, self.client, function onArt(err, mciMap) {
// :TODO: If the art simply is not found, or failed to load... we need to continue
if(err) {
console.log('TODO: log this error properly... maybe handle slightly diff.');
}
callback(null, mciMap);
2015-03-23 04:52:04 +00:00
});
},
function afterArtDisplayed(mciMap, callback) {
if(mciMap) {
2015-03-23 04:52:04 +00:00
self.mciReady(mciMap);
}
callback(null);
2015-03-23 04:52:04 +00:00
}
],
function complete(err) {
2015-03-23 04:52:04 +00:00
if(err) {
// :TODO: Log me!!! ... and what else?
console.log(err);
2015-03-23 04:52:04 +00:00
}
self.finishedLoading();
2015-03-23 04:52:04 +00:00
}
);
};
}
require('util').inherits(MenuModule, PluginModule);
MenuModule.prototype.enter = function(client) {
2015-03-23 04:52:04 +00:00
this.client = client;
assert(typeof client !== 'undefined');
this.initSequence();
};
MenuModule.prototype.leave = function() {
var count = this.viewControllers.length;
for(var i = 0; i < count; ++i) {
this.viewControllers[i].detachClientEvents();
}
};
MenuModule.prototype.addViewController = function(vc) {
this.viewControllers.push(vc);
2015-03-23 04:52:04 +00:00
return vc;
};
MenuModule.prototype.beforeArt = function() {
};
2015-03-23 04:52:04 +00:00
MenuModule.prototype.mciReady = function(mciMap) {
};
MenuModule.prototype.finishedLoading = function() {
};