+ Very start of theme support. Various changes

This commit is contained in:
NuSkooler 2014-10-26 22:06:41 -06:00
parent 46875ccddd
commit 8119c1688a
8 changed files with 95 additions and 34 deletions

View File

@ -76,8 +76,10 @@ function ANSIEscapeParser(options) {
}; };
self.resetColor = function() { self.resetColor = function() {
self.fgColor = 7; //self.fgColor = 7;
self.bgColor = 0; //self.bgColor = 0;
self.fgColor = 39;
self.bgColor = 49;
}; };
self.rowUpdated = function() { self.rowUpdated = function() {

View File

@ -437,6 +437,7 @@ function display(art, options, cb) {
mciPosQueue.push(mciCode); mciPosQueue.push(mciCode);
// :TODO: Move this out of the loop
if(!emitter) { if(!emitter) {
emitter = options.client.on('onPosition', function onPosition(pos) { emitter = options.client.on('onPosition', function onPosition(pos) {
if(mciPosQueue.length > 0) { if(mciPosQueue.length > 0) {

View File

@ -41,7 +41,8 @@ function createUserTables() {
' user_id INTEGER NOT NULL,' + ' user_id INTEGER NOT NULL,' +
' prop_name VARCHAR NOT NULL,' + ' prop_name VARCHAR NOT NULL,' +
' prop_value VARCHAR,' + ' prop_value VARCHAR,' +
' UNIQUE(user_id, prop_name)' + ' UNIQUE(user_id, prop_name),' +
' FOREIGN KEY(user_id) REFERENCES user(id) ON DELETE CASCADE' +
');' ');'
); );
} }

View File

@ -44,12 +44,13 @@ TextView.prototype.redraw = function() {
var color = this.hasFocus ? this.getFocusColor() : this.getColor(); var color = this.hasFocus ? this.getFocusColor() : this.getColor();
this.client.term.write(ansi.sgr(color.flags, color.fg, color.bg)); //this.client.term.write(ansi.sgr(color.flags, color.fg, color.bg));
this.client.term.write(this.getANSIColor(color));
if(this.isPasswordTextStyle) { if(this.isPasswordTextStyle) {
this.client.term.write(strUtil.pad(new Array(this.text.length).join(this.textMaskChar), this.dimens.width)); this.client.term.write(strUtil.pad(new Array(this.text.length + 1).join(this.textMaskChar), this.dimens.width));
} else { } else {
this.client.term.write(strUtil.pad(this.text, this.dimens.width)); this.client.term.write(strUtil.pad(this.text, this.dimens.width));
} }
}; };

68
core/theme.js Normal file
View File

@ -0,0 +1,68 @@
/* jslint node: true */
'use strict';
var Config = require('./config.js').config;
var art = require('./art.js');
var miscUtil = require('./misc_util.js');
var fs = require('fs');
var paths = require('path');
var async = require('async');
exports.getThemeInfo = getThemeInfo;
exports.getThemeArt = getThemeArt;
// getThemeInfo(themeName)
/*
// getThemeFile(themeShortName, name)
// getArt(name, {
basePath : themeDir,
}
*/
function getThemeInfo(themeID, cb) {
var path = paths.join(Config.paths.art, themeID, 'theme_info.json');
fs.readFile(path, function onData(err, data) {
if(err) {
cb(err);
} else {
try {
var info = JSON.parse(data);
return info;
} catch(e) {
cb(err);
}
}
});
}
function getThemeArt(name, themeID, options, cb) {
// allow options to be optional
if(typeof cb === 'undefined') {
cb = options;
options = {};
}
// set/override some options
options.asAnsi = true;
options.readSauce = true; // can help with encoding
options.random = miscUtil.valueWithDefault(options.random, true);
options.basePath = paths.join(Config.paths.art, themeID);
art.getArt(name, options, function onThemeArt(err, theArt) {
if(err) {
// try fallback
options.basePath = Config.paths.art;
art.getArt(name, options, function onFallbackArt(err, theArt) {
if(err) {
cb(err);
} else {
cb(null, theArt.data);
}
});
} else {
cb(null, theArt.data);
}
});
}

View File

@ -121,12 +121,13 @@ function createNew(user, cb) {
], ],
function onComplete(err) { function onComplete(err) {
if(err) { if(err) {
var originalError = err;
userDb.run('ROLLBACK;', function onRollback(err) { userDb.run('ROLLBACK;', function onRollback(err) {
cb(err); assert(!err);
cb(originalError);
}); });
} else { } else {
userDb.run('COMMIT;', function onCommit(err) { userDb.run('COMMIT;', function onCommit(err) {
if(err) { if(err) {
cb(err); cb(err);
} else { } else {

View File

@ -60,6 +60,14 @@ function View(client, options) {
this.isSpecialKeyMapped = function(keySet, keyName) { this.isSpecialKeyMapped = function(keySet, keyName) {
return this.specialKeyMap[keySet].indexOf(keyName) > -1; return this.specialKeyMap[keySet].indexOf(keyName) > -1;
}; };
this.getANSIColor = function(color) {
var sgr = [ color.flags, color.fg ];
if(color.bg !== color.flags) {
sgr.push(color.bg);
}
return ansi.sgr(sgr);
};
} }
util.inherits(View, events.EventEmitter); util.inherits(View, events.EventEmitter);

View File

@ -6,6 +6,7 @@ var ansi = require('../core/ansi_term.js');
var lineEditor = require('../core/line_editor.js'); var lineEditor = require('../core/line_editor.js');
var art = require('../core/art.js'); var art = require('../core/art.js');
var user = require('../core/user.js'); var user = require('../core/user.js');
var theme = require('../core/theme.js');
//var view = require('../core/view.js'); //var view = require('../core/view.js');
var textView = require('../core/text_view.js'); var textView = require('../core/text_view.js');
@ -28,38 +29,16 @@ function entryPoint(client) {
// :TODO: types, random, and others? could come from conf.mods.matrix or such // :TODO: types, random, and others? could come from conf.mods.matrix or such
//art.getArt('SO-CC1.ANS'/* 'MATRIX'*/, { types: ['.ans'], random: true}, function onArt(err, theArt) { //art.getArt('SO-CC1.ANS'/* 'MATRIX'*/, { types: ['.ans'], random: true}, function onArt(err, theArt) {
art.getArt('MCI_TEST3.ANS', /*'MATRIX_TEST1.ANS'*/ {}, function onArt(err, theArt) { theme.getThemeArt('MATRIX_1', 'NU-MAYAN', function onArt(err, theArt) {
//art.getArt('MATRIX_1.ANS', {}, function onArt(err, theArt) {
if(!err) { if(!err) {
art.display(theArt.data, { client : client, mciReplaceChar : ' ' }, function onArtDisplayed(err, mci) { art.display(theArt, { client : client, mciReplaceChar : ' ' }, function onArtDisplayed(err, mci) {
if(err) { if(err) {
return; return;
} }
/*
var tv = new textView.TextView(client, {
position : [5, 5],
text : 'Hello, World!',
textStyle : 'password',
maxLength : 10,
id : 1,
});
tv.redraw();
var etv = new editTextView.EditTextView(client, {
position : [10, 10],
textStyle : 'upper',
maxLength : 20,
dimens : { width : 30 },
text : 'default',
color : { flags : 0, fg : 31, bg : 40 },
focusColor : { flags : 1, fg : 37, bg : 44 },
id : 2,
});
etv.redraw();*/
user.authenticate('NuSkooler', 'password', client, function onAuth(isValid) { user.authenticate('NuSkooler', 'password', client, function onAuth(isValid) {
console.log(isValid); console.log(isValid);
}); });