diff --git a/core/art.js b/core/art.js index c12965b9..00e82b08 100644 --- a/core/art.js +++ b/core/art.js @@ -458,7 +458,6 @@ function display(options, cb) { var continous = false; - /* parser.on('row update', function rowUpdate(row) { if(row >= nextPauseTermHeight) { if(!continous && 'termHeight' === options.pause) { @@ -475,7 +474,6 @@ function display(options, cb) { nextPauseTermHeight += options.client.term.termHeight; } }); - */ parser.on('mci', function mciEncountered(mciInfo) { @@ -507,7 +505,7 @@ function display(options, cb) { mciPosQueue.push(mapKey); - options.client.term.rawWrite(ansi.queryPos()); + options.client.term.write(ansi.queryPos(), false); } }); @@ -542,12 +540,12 @@ function display(options, cb) { } if(ansiFont.length > 1) { - options.client.term.rawWrite(ansiFont); + options.client.term.write(ansiFont, false); } if(iceColors) { - options.client.term.rawWrite(ansi.blinkToBrightIntensity()); + options.client.term.write(ansi.blinkToBrightIntensity(), false); } parser.reset(options.art); diff --git a/core/connect.js b/core/connect.js index fb00a6b9..198f6e28 100644 --- a/core/connect.js +++ b/core/connect.js @@ -124,6 +124,11 @@ function connectEntry(client) { // displayBanner(term); + /* + theme.displayThemeArt({client : client, name : 'DM-ENIG2.ANS'}, function onArt() { + + });*/ + setTimeout(function onTimeout() { client.gotoMenuModule( { name : Config.firstMenu }); }, 500); diff --git a/core/ftn_mail_packet.js b/core/ftn_mail_packet.js index 4eb7b83f..8a46a058 100644 --- a/core/ftn_mail_packet.js +++ b/core/ftn_mail_packet.js @@ -28,22 +28,6 @@ function FTNMailPacket(options) { var self = this; self.KLUDGE_PREFIX = '\x01'; - /* - this.loadNodeAddresses = function() { - if(Config.networks) { - for(var name in Config.networks) { - if(!Config.networks[name].address) { - continue; - } - - this.nodeAddresses[name] = Config.networks[name].address; - } - } - }; - - this.loadNodeAddresses(); - */ - this.getPacketHeaderAddress = function() { return { zone : self.packetHeader.destZone, diff --git a/core/ftn_util.js b/core/ftn_util.js index 63f649fd..a53d4a07 100644 --- a/core/ftn_util.js +++ b/core/ftn_util.js @@ -43,18 +43,6 @@ function getDateFromFtnDateTime(dateTime) { return (new Date(Date.parse(dateTime))).toISOString(); } -function getFormattedFTNAddress3D(zone, net, node) { - return util.format('%d:%d/%d', zone, net, node); -} - -function getFormattedFTNAddress4D(zone, net, node, point) { - return util.format('%d:%d/%d.%d', zone, net, node, point); -} - -function getFormattedFTNAddress5D(zone, net, node, point, domain) { - // :TODO: -} - function getFormattedFTNAddress(address, dimensions) { var addr = util.format('%d:%d', address.zone, address.net); switch(dimensions) { diff --git a/core/json_cache.js b/core/json_cache.js new file mode 100644 index 00000000..5859938e --- /dev/null +++ b/core/json_cache.js @@ -0,0 +1,65 @@ +/* jslint node: true */ +'use strict'; + +var Config = require('./config.js').config; +var Log = require('./logger.js').log; + +var paths = require('path'); +var fs = require('fs'); +var Gaze = require('gaze').Gaze; +var stripJsonComments = require('strip-json-comments'); +var assert = require('assert'); + +module.exports = exports = new JSONCache(); + +function JSONCache() { + + var self = this; + this.cache = {}; // filePath -> JSON + this.gaze = new Gaze(); + + this.reCacheJSONFromFile = function(filePath, cb) { + fs.readFile(filePath, { encoding : 'utf-8' }, function fileRead(err, data) { + try { + self.cache[filePath] = JSON.parse(stripJsonComments(data)); + cb(null, self.cache[filePath]); + } catch(e) { + cb(e); + } + }); + }; + + + this.gaze.on('error', function gazeErr(err) { + + }); + + this.gaze.on('changed', function fileChanged(filePath) { + assert(filePath in self.cache); + + Log.info( { filePath : filePath }, 'JSON file changed; recaching'); + + self.reCacheJSONFromFile(filePath, function reCached(err) { + if(err) { + Log.error( { error : err, filePath : filePath } , 'Error recaching JSON'); + } + }); + }); +} + +JSONCache.prototype.getJSON = function(fileName, cb) { + var self = this; + var filePath = paths.join(Config.paths.mods, fileName); + console.log(filePath) + + if(filePath in this.cache) { + cb(null, this.cache[filePath]); + } else { + this.reCacheJSONFromFile(filePath, function fileCached(err, json) { + if(!err) { + self.gaze.add(filePath); + } + cb(err, json); + }); + } +} diff --git a/core/menu_util.js b/core/menu_util.js index f44cdb7f..a9bc2d59 100644 --- a/core/menu_util.js +++ b/core/menu_util.js @@ -8,6 +8,7 @@ var conf = require('./config.js'); // :TODO: remove me! var Config = require('./config.js').config; var asset = require('./asset.js'); var theme = require('./theme.js'); +var jsonCache = require('./json_cache.js'); var fs = require('fs'); var paths = require('path'); @@ -22,28 +23,13 @@ exports.getFormConfigByIDAndMap = getFormConfigByIDAndMap; exports.handleAction = handleAction; exports.applyThemeCustomization = applyThemeCustomization; - -function loadModJSON(fileName, cb) { - // :TODO: really need to cache menu.json and prompt.json only reloading if they change - see chokidar & gaze npms - var filePath = paths.join(Config.paths.mods, fileName); - - fs.readFile(filePath, { encoding : 'utf8' }, function jsonData(err, data) { - try { - var json = JSON.parse(stripJsonComments(data)); - cb(null, json); - } catch(e) { - cb(e); - } - }); -} - function getMenuConfig(name, cb) { var menuConfig; async.waterfall( [ function loadMenuJSON(callback) { - loadModJSON('menu.json', function loaded(err, menuJson) { + jsonCache.getJSON('menu.json', function loaded(err, menuJson) { callback(err, menuJson); }); }, @@ -57,7 +43,7 @@ function getMenuConfig(name, cb) { }, function loadPromptJSON(callback) { if(_.isString(menuConfig.prompt)) { - loadModJSON('prompt.json', function loaded(err, promptJson) { + jsonCache.getJSON('prompt.json', function loaded(err, promptJson) { callback(err, promptJson); }); } else { diff --git a/core/theme.js b/core/theme.js index fba90307..b8354da5 100644 --- a/core/theme.js +++ b/core/theme.js @@ -19,6 +19,7 @@ exports.getRandomTheme = getRandomTheme; exports.initAvailableThemes = initAvailableThemes; exports.displayThemeArt = displayThemeArt; +// :TODO: use JSONCache here... may need to fancy it up a bit in order to have events for after re-cache, e.g. to update helpers below: function loadTheme(themeID, cb) { var path = paths.join(Config.paths.themes, themeID, 'theme.json'); diff --git a/mods/art/test.ans b/mods/art/test.ans new file mode 100644 index 00000000..2ebac4ef --- /dev/null +++ b/mods/art/test.ans @@ -0,0 +1,52 @@ +You should never see this! + + +... nor this +[?33h + fONT tEST + ~~~~~~~~~ + + | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F + ---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--- + 0 |NUL|  |  |  |  |  |  |  |BS |HT |LF | | |CR |  |   + 1 |  |  |  |  |  |  |  |  |  |  |EOF|ESC|  |  |  |   + 2 | | ! | " | # | $ | % | & | ' | ( | ) | * | + | , | - | . | /  + 3 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | : | ; | < | = | > | ?  + ---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--- + 4 | @ | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O  + 5 | P | Q | R | S | T | U | V | W | X | Y | Z | [ | \ | ] | ^ | _  + 6 | ` | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o  + 7 | p | q | r | s | t | u | v | w | x | y | z | { | | | } | ~ |   + ---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--- + 8 | | | | | | | | | | | | | | | |  + 9 | | | | | | | | | | | | | | | |  + A | | | | | | | | | | | | | | | |  + B | | | | | | | | | | | | | | | |  + ---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+--- + C | | | | | | | | | | | | | | | |  + D | | | | | | | | | | | | | | | |  + E | | | | | | | | | | | | | | | |  + F | | | | | | | | | | | | | | | |  + + + cOLOR tEST + ~~~~~~~~~~ + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  diff --git a/mods/menu.json b/mods/menu.json index 4e1578ac..38a8d08f 100644 --- a/mods/menu.json +++ b/mods/menu.json @@ -468,6 +468,8 @@ "VM1" : { "items" : [ "Defaults - DOS ANSI", + "bw_mindgames.ans - DOS", + "test.ans - DOS", "Defaults - Amiga", "Pause at Term Height" ], @@ -480,7 +482,15 @@ { "value" : { "1" : 0 }, "action" : "@menu:demoDefaultsDosAnsi" - } + }, + { + "value" : { "1" : 1 }, + "action" : "@menu:demoDefaultsDosAnsi_bw_mindgames" + }, + { + "value" : { "1" : 2 }, + "action" : "@menu:demoDefaultsDosAnsi_test" + } ] } } @@ -488,7 +498,15 @@ } }, "demoDefaultsDosAnsi" : { - "art" : "WE-CIZB.ANS", + "art" : "DM-ENIG2.ANS", + "options" : { "cls" : true } + }, + "demoDefaultsDosAnsi_bw_mindgames" : { + "art" : "bw_mindgames.ans", + "options" : { "cls" : true } + }, + "demoDefaultsDosAnsi_test" : { + "art" : "test.ans", "options" : { "cls" : true } }, "demoFullScreenEditor" : {