From b4d19e469b3de98778002ac97814c6b647cba113 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 22 Nov 2014 14:47:43 -0500 Subject: better chara input --- js/lex.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'js/lex.js') diff --git a/js/lex.js b/js/lex.js index 7066ddb..d61f561 100644 --- a/js/lex.js +++ b/js/lex.js @@ -1,3 +1,5 @@ +direction = [1,0] + function Lex (x,y) { if (typeof x == "number") { this.x = x @@ -16,7 +18,7 @@ Lex.prototype.build = function(){ this.span.innerHTML = this.html() } Lex.prototype.css = function(){ - return "f" + letters[mod(this.fg,16)] + "b" + letters[mod(this.bg,15)] + return "f" + letters[mod(this.fg,16)] + "b" + letters[mod(this.bg,16)] } Lex.prototype.html = function(){ return this.char == " " ? " " : this.char || " " @@ -78,7 +80,6 @@ Lex.prototype.demolish = function(){ this.span.parentNode.removeChild(this.span) this.span = null } - Lex.prototype.key = function(char, keyCode) { console.log(keyCode, this.y, this.x) switch (keyCode) { @@ -89,29 +90,30 @@ Lex.prototype.key = function(char, keyCode) { return case 13: // return canvas.focusLex(0, this.x+1) - break + return case 38: // up - canvas.focusLex(this.y, this.x-1) + direction[0] = 0 + direction[1] = -1 break case 40: // down - canvas.focusLex(this.y, this.x+1) + direction[0] = 0 + direction[1] = 1 break case 37: // left - canvas.focusLex(this.y-1, this.x) + direction[0] = -1 + direction[1] = 0 break case 39: // right - canvas.focusLex(this.y+1, this.x) + direction[0] = 1 + direction[1] = 0 break default: + if (! char) { return } this.char = char this.fg = brush.bg this.build() this.blur() - if (this.y < canvas.w-1) { - canvas.aa[this.x][this.y+1].focus() - } - else { - canvas.focusLex(0, this.x+1) - } + break } + canvas.focusLex(this.y + direction[0], this.x + direction[1]) } -- cgit v1.2.3-70-g09d2