* Some basic work on connecting modules

This commit is contained in:
Bryan Ashby
2015-03-23 23:12:19 -06:00
parent 810f001901
commit d1b0663b5d
7 changed files with 109 additions and 17 deletions

View File

@@ -209,7 +209,7 @@ function clearScreen() {
}
function resetScreen() {
return exports.goHome() + exports.eraseData(2);
return exports.goHome() + exports.reset() + exports.eraseData(2);
}
function normal() {

View File

@@ -161,11 +161,20 @@ function Client(input, output) {
} while(0 !== dsrResponseRe.lastIndex);
}
});
self.detachCurrentMenuModule = function() {
if(self.currentMenuModule) {
self.currentMenuModule.leave();
self.currentMenuModule = null;
}
};
}
require('util').inherits(Client, stream);
Client.prototype.end = function () {
this.detachCurrentMenuModule();
return this.output.end.apply(this.output, arguments);
};
@@ -193,9 +202,7 @@ Client.prototype.gotoMenuModule = function(name, cb) {
// Assign a default missing module handler callback if none was provided
cb = miscUtil.valueWithDefault(cb, self.defaultHandlerMissingMod());
if(self.currentMenuModule) {
self.currentMenuModule.leave();
}
self.detachCurrentMenuModule();
menuUtil.loadMenu(name, self, function onMenuModuleLoaded(err, modInst) {
if(err) {

View File

@@ -17,26 +17,37 @@ function MenuModule(menuConfig) {
this.viewControllers = [];
this.loadArt = function() {
this.initSequence = function() {
async.waterfall(
[
function beforeDisplayArt(callback) {
self.beforeArt();
callback(null);
},
function displayArt(callback) {
theme.displayThemeArt(self.menuConfig.art, self.client, function onArt(err, mciMap) {
callback(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);
});
},
function artDisplayed(mciMap, callback) {
if(!mciMap) {
callback(null);
} else {
function afterArtDisplayed(mciMap, callback) {
if(mciMap) {
self.mciReady(mciMap);
}
callback(null);
}
],
function onComplete(err) {
if(err) {
// :TODO: Log me!!! ... and what else?
console.log(err);
}
self.finishedLoading();
}
);
};
@@ -47,12 +58,16 @@ require('util').inherits(MenuModule, PluginModule);
MenuModule.prototype.enter = function(client) {
this.client = client;
assert(typeof client !== 'undefined');
this.initSequence();
};
MenuModule.prototype.leave = function() {
this.viewControllers.forEach(function onVC(vc) {
vc.detachClientEvents();
});
var count = this.viewControllers.length;
for(var i = 0; i < count; ++i) {
this.viewControllers[i].detachClientEvents();
}
};
MenuModule.prototype.addViewController = function(vc) {
@@ -60,5 +75,13 @@ MenuModule.prototype.addViewController = function(vc) {
return vc;
};
MenuModule.prototype.beforeArt = function() {
};
MenuModule.prototype.mciReady = function(mciMap) {
console.log('mciReady')
};
MenuModule.prototype.finishedLoading = function() {
console.log('finishedLoading')
};

View File

@@ -126,7 +126,7 @@ function displayThemeArt(name, client, cb) {
}
art.display( { art : artInfo.data, client : client, iceColors : iceColors }, function onDisplayed(err, mci) {
cb(err, mci);
cb(err, mci, artInfo);
});
}
});