enigma-bbs/core/menu_module.js

87 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 async = require('async');
var assert = require('assert');
exports.MenuModule = MenuModule;
2015-03-23 04:52:04 +00:00
function MenuModule(menuConfig) {
PluginModule.call(this);
2015-03-23 04:52:04 +00:00
var self = this;
this.menuConfig = menuConfig;
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 onComplete(err) {
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) {
console.log('mciReady')
};
MenuModule.prototype.finishedLoading = function() {
console.log('finishedLoading')
};