mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-06 12:47:13 +02:00
* displayArtAsset is now part of asset
* Work on generalizing some things so they can be used for pause/etc.
This commit is contained in:
parent
8b5152d66f
commit
dd478ed6ba
4 changed files with 127 additions and 17 deletions
|
@ -2,6 +2,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Config = require('./config.js').config;
|
var Config = require('./config.js').config;
|
||||||
|
var theme = require('./theme.js');
|
||||||
|
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
@ -10,6 +11,7 @@ exports.parseAsset = parseAsset;
|
||||||
exports.getArtAsset = getArtAsset;
|
exports.getArtAsset = getArtAsset;
|
||||||
exports.resolveConfigAsset = resolveConfigAsset;
|
exports.resolveConfigAsset = resolveConfigAsset;
|
||||||
exports.getViewPropertyAsset = getViewPropertyAsset;
|
exports.getViewPropertyAsset = getViewPropertyAsset;
|
||||||
|
exports.displayArtAsset = displayArtAsset;
|
||||||
|
|
||||||
var ALL_ASSETS = [
|
var ALL_ASSETS = [
|
||||||
'art',
|
'art',
|
||||||
|
@ -83,3 +85,47 @@ function getViewPropertyAsset(src) {
|
||||||
|
|
||||||
return parseAsset(src);
|
return parseAsset(src);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function displayArtAsset(assetSpec, client, options, cb) {
|
||||||
|
assert(_.isObject(client));
|
||||||
|
|
||||||
|
// options are... optional
|
||||||
|
if(3 === arguments.length) {
|
||||||
|
cb = options;
|
||||||
|
options = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
var artAsset = getArtAsset(assetSpec);
|
||||||
|
if(!artAsset) {
|
||||||
|
cb(new Error('Asset not found: ' + assetSpec));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dispOpts = {
|
||||||
|
name : artAsset.asset,
|
||||||
|
client : client,
|
||||||
|
font : options.font,
|
||||||
|
};
|
||||||
|
|
||||||
|
switch(artAsset.type) {
|
||||||
|
case 'art' :
|
||||||
|
theme.displayThemeArt(dispOpts, function displayed(err, artData) {
|
||||||
|
cb(err, err ? null : { mciMap : artData.mciMap, height : artData.extraInfo.height } );
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'method' :
|
||||||
|
// :TODO: fetch & render via method
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'inline ' :
|
||||||
|
// :TODO: think about this more in relation to themes, etc. How can this come
|
||||||
|
// from a theme (with override from menu.json) ???
|
||||||
|
// look @ client.currentTheme.inlineArt[name] -> menu/prompt[name]
|
||||||
|
break;
|
||||||
|
|
||||||
|
default :
|
||||||
|
cb(new Error('Unsupported art asset type: ' + artAsset.type));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,8 @@ function MenuModule(options) {
|
||||||
this.menuMethods = {}; // methods called from @method's
|
this.menuMethods = {}; // methods called from @method's
|
||||||
this.viewControllers = {}; // name->vc
|
this.viewControllers = {}; // name->vc
|
||||||
|
|
||||||
|
// :TODO: Move this elsewhere
|
||||||
|
/*
|
||||||
this.displayArtAsset = function(assetSpec, cb) {
|
this.displayArtAsset = function(assetSpec, cb) {
|
||||||
var artAsset = asset.getArtAsset(assetSpec);
|
var artAsset = asset.getArtAsset(assetSpec);
|
||||||
|
|
||||||
|
@ -64,6 +66,7 @@ function MenuModule(options) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
this.initSequence = function() {
|
this.initSequence = function() {
|
||||||
var mciData = { };
|
var mciData = { };
|
||||||
|
@ -76,12 +79,23 @@ function MenuModule(options) {
|
||||||
},
|
},
|
||||||
function displayMenuArt(callback) {
|
function displayMenuArt(callback) {
|
||||||
if(_.isString(self.menuConfig.art)) {
|
if(_.isString(self.menuConfig.art)) {
|
||||||
self.displayArtAsset(self.menuConfig.art, function displayed(err, artData) {
|
asset.displayArtAsset(
|
||||||
|
self.menuConfig.art,
|
||||||
|
self.client,
|
||||||
|
{ font : self.menuConfig.font },
|
||||||
|
function displayed(err, artData)
|
||||||
|
{
|
||||||
|
if(!err) {
|
||||||
|
mciData.menu = artData.mciMap;
|
||||||
|
}
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
/*self.displayArtAsset(self.menuConfig.art, function displayed(err, artData) {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
mciData.menu = artData.mciMap;
|
mciData.menu = artData.mciMap;
|
||||||
}
|
}
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});*/
|
||||||
} else {
|
} else {
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
|
@ -104,12 +118,16 @@ function MenuModule(options) {
|
||||||
// Prompts *must* have art. If it's missing it's an error
|
// Prompts *must* have art. If it's missing it's an error
|
||||||
// :TODO: allow inline prompts in the future, e.g. @inline:memberName -> { "memberName" : { "text" : "stuff", ... } }
|
// :TODO: allow inline prompts in the future, e.g. @inline:memberName -> { "memberName" : { "text" : "stuff", ... } }
|
||||||
var promptConfig = self.menuConfig.promptConfig;
|
var promptConfig = self.menuConfig.promptConfig;
|
||||||
self.displayArtAsset(promptConfig.art, function displayed(err, artData) {
|
asset.displayArtAsset(
|
||||||
if(!err) {
|
promptConfig.art,
|
||||||
mciData.prompt = artData.mciMap;
|
self.client,
|
||||||
}
|
{ font : self.menuConfig.font },
|
||||||
callback(err);
|
function displayed(err, artData) {
|
||||||
});
|
if(!err) {
|
||||||
|
mciData.prompt = artData.mciMap;
|
||||||
|
}
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,6 +189,9 @@ function displayThemeArt(options, cb) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Pause prompts are a special prompt by the name 'pause'.
|
||||||
|
//
|
||||||
function displayThemePause(options, cb) {
|
function displayThemePause(options, cb) {
|
||||||
//
|
//
|
||||||
// options.client
|
// options.client
|
||||||
|
@ -203,8 +206,8 @@ function displayThemePause(options, cb) {
|
||||||
// :TODO: Support animated pause prompts. Probably via MCI with AnimatedView
|
// :TODO: Support animated pause prompts. Probably via MCI with AnimatedView
|
||||||
// :TODO: support prompts with a height > 1
|
// :TODO: support prompts with a height > 1
|
||||||
// :TODO: Prompt should support MCI codes in general
|
// :TODO: Prompt should support MCI codes in general
|
||||||
// ...this will be more complex due to cursor movement. Will need to track where teh cusor
|
|
||||||
// was before the prompt + filling MCI, then move back and erase correct # of lines
|
var artInfo;
|
||||||
|
|
||||||
async.waterfall(
|
async.waterfall(
|
||||||
[
|
[
|
||||||
|
@ -222,13 +225,20 @@ function displayThemePause(options, cb) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function displayPausePrompt(pausePrompt, callback) {
|
function displayPausePrompt(pausePrompt, callback) {
|
||||||
displayThemeArt( { client : options.client, name : pausePrompt.art }, function pauseDisplayed(err, mciMap, extraInfo) {
|
// :TODO: use displayArtAsset()
|
||||||
if(extraInfo) {
|
displayThemeArt( { client : options.client, name : pausePrompt.art }, function pauseDisplayed(err, artData) {
|
||||||
pauseHeight = extraInfo.height;
|
artInfo = artData;
|
||||||
}
|
callback(err);
|
||||||
callback(null);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
function discoverCursorPosition(callback) {
|
||||||
|
options.client.once('cursor position report', function cpr(pos) {
|
||||||
|
artInfo.startRow = pos[0] - artInfo.extraInfo.height;
|
||||||
|
callback(null);
|
||||||
|
});
|
||||||
|
options.client.term.rawWrite(ansi.queryPos());
|
||||||
|
},
|
||||||
|
// :TODO: use view Controller loadFromPromptConfig() with 'noInput' option or such
|
||||||
function pauseForUserInput(callback) {
|
function pauseForUserInput(callback) {
|
||||||
options.client.waitForKeyPress(function keyPressed() {
|
options.client.waitForKeyPress(function keyPressed() {
|
||||||
callback(null);
|
callback(null);
|
||||||
|
@ -236,16 +246,22 @@ function displayThemePause(options, cb) {
|
||||||
},
|
},
|
||||||
function clearPauseArt(callback) {
|
function clearPauseArt(callback) {
|
||||||
if(options.clearPrompt) {
|
if(options.clearPrompt) {
|
||||||
options.client.term.write(ansi.up(1) + ansi.deleteLine());
|
if(artInfo.startRow) {
|
||||||
|
options.client.term.rawWrite(ansi.goto(artInfo.startRow, 1));
|
||||||
|
options.client.term.rawWrite(ansi.deleteLine(artInfo.extraInfo.height));
|
||||||
|
} else {
|
||||||
|
options.client.term.rawWrite(ansi.up(1) + ansi.deleteLine());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
callback(null);
|
callback(null);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
, function debugPause(callback) {
|
, function debugPause(callback) {
|
||||||
setTimeout(function to() {
|
setTimeout(function to() {
|
||||||
callback(null);
|
callback(null);
|
||||||
}, 4000);
|
}, 4000);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
],
|
],
|
||||||
function complete(err) {
|
function complete(err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
|
|
30
mods/fse.js
30
mods/fse.js
|
@ -7,6 +7,7 @@ var ansi = require('../core/ansi_term.js');
|
||||||
var theme = require('../core/theme.js');
|
var theme = require('../core/theme.js');
|
||||||
var MultiLineEditTextView = require('../core/multi_line_edit_text_view.js').MultiLineEditTextView;
|
var MultiLineEditTextView = require('../core/multi_line_edit_text_view.js').MultiLineEditTextView;
|
||||||
var Message = require('../core/message.js');
|
var Message = require('../core/message.js');
|
||||||
|
var asset = require('../core/asset.js');
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
@ -102,9 +103,19 @@ function FullScreenEditorModule(options) {
|
||||||
function displayFooterArt(callback) {
|
function displayFooterArt(callback) {
|
||||||
var footerArt = self.menuConfig.config.art[options.footerName];
|
var footerArt = self.menuConfig.config.art[options.footerName];
|
||||||
|
|
||||||
|
asset.displayArtAsset(
|
||||||
|
footerArt,
|
||||||
|
self.client,
|
||||||
|
function displayed(err, artData)
|
||||||
|
{
|
||||||
|
callback(err, artData);
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
self.displayArtAsset(footerArt, function artDisplayed(err, artData) {
|
self.displayArtAsset(footerArt, function artDisplayed(err, artData) {
|
||||||
callback(err, artData);
|
callback(err, artData);
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
function complete(err, artData) {
|
function complete(err, artData) {
|
||||||
|
@ -123,9 +134,18 @@ function FullScreenEditorModule(options) {
|
||||||
[
|
[
|
||||||
function displayHeaderAndBody(callback) {
|
function displayHeaderAndBody(callback) {
|
||||||
async.eachSeries( comps, function dispArt(n, next) {
|
async.eachSeries( comps, function dispArt(n, next) {
|
||||||
|
asset.displayArtAsset(
|
||||||
|
art[n],
|
||||||
|
self.client,
|
||||||
|
function displayed(err, artData) {
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
self.displayArtAsset(art[n], function artDisplayed(err, artData) {
|
self.displayArtAsset(art[n], function artDisplayed(err, artData) {
|
||||||
next(err);
|
next(err);
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
}, function complete(err) {
|
}, function complete(err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
|
@ -198,10 +218,20 @@ function FullScreenEditorModule(options) {
|
||||||
assert(_.isString(art.body));
|
assert(_.isString(art.body));
|
||||||
|
|
||||||
async.eachSeries( [ 'header', 'body' ], function dispArt(n, next) {
|
async.eachSeries( [ 'header', 'body' ], function dispArt(n, next) {
|
||||||
|
asset.displayArtAsset(
|
||||||
|
art[n],
|
||||||
|
self.client,
|
||||||
|
function displayed(err, artData) {
|
||||||
|
mciData[n] = artData;
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
self.displayArtAsset(art[n], function artDisplayed(err, artData) {
|
self.displayArtAsset(art[n], function artDisplayed(err, artData) {
|
||||||
mciData[n] = artData;
|
mciData[n] = artData;
|
||||||
next(err);
|
next(err);
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
}, function complete(err) {
|
}, function complete(err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue