diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-11-21 13:33:20 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-11-21 13:33:20 -0500 |
| commit | fea42b1513e321b6c397c914327a9a4a7d96e331 (patch) | |
| tree | 0c52449d5e53fc60c30d06f75a0e7b6f9a3bd608 /js/lex.js | |
| parent | 9546cd5705e723e4c39ad4b34f0e154b8ab5e904 (diff) | |
split up js and style a little
Diffstat (limited to 'js/lex.js')
| -rw-r--r-- | js/lex.js | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/js/lex.js b/js/lex.js new file mode 100644 index 0000000..39a47cd --- /dev/null +++ b/js/lex.js @@ -0,0 +1,105 @@ +function Lex (x,y) { + if (typeof x == "number") { + this.x = x + this.y = y + this.span = document.createElement("span") + } + else { + this.span = x + } + this.fg = colors.white + this.bg = colors.black + this.char = " " +} +Lex.prototype.build = function(){ + this.span.className = this.css() + this.span.innerHTML = this.html() +} +Lex.prototype.css = function(){ + return "f" + letters[this.fg&15] + "b" + letters[this.bg&15] +} +Lex.prototype.html = function(){ + return this.char == " " ? " " : this.char +} +Lex.prototype.irc = function(){ + if (this.bg == 1 && this.fg == 0) { +// return "\\x03" + "," + (this.bg&15) + this.char + return this.char + } + else { + return "\\x03" + (this.fg&15) + "," + (this.bg&15) + this.char + } +} +Lex.prototype.clone = function (lex){ + if (! erasing && lex.isClear()) return + this.fg = lex.fg + this.bg = lex.bg + this.char = lex.char + this.build() +} +Lex.prototype.fill = function(fg,bg){ + this.fg = fg + this.bg = bg + this.build() +} +Lex.prototype.eq = function(lex){ + return lex && this.fg == lex.fg && this.bg == lex.fg && this.char == lex.char +} +Lex.prototype.clear = function(){ + this.bg = 1 + this.fg = 0 + this.char = " " + this.build() +} +Lex.prototype.isClear = function(){ + return this.bg == 1 && this.fg == 0 && this.char == " " +} +Lex.prototype.focus = function(){ + if (focused) focused.blur() + this.span.classList.add('focused') + focused = this +} +Lex.prototype.blur = function(){ + this.span.classList.remove('focused') + focused = null +} +Lex.prototype.key = function(char, keyCode) { + console.log(keyCode, this.y, this.x) + switch (keyCode) { + case 8: + canvas.focusLex(this.y-1, this.x) + focused.char = " " + focused.build() + return + case 13: // return + canvas.focusLex(0, this.x+1) + break + case 38: // up + canvas.focusLex(this.y, this.x-1) + break + case 40: // down + canvas.focusLex(this.y, this.x+1) + break + case 37: // left + canvas.focusLex(this.y-1, this.x) + break + case 39: // right + canvas.focusLex(this.y+1, this.x) + break + default: + 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) + } + } +} +Lex.prototype.demolish = function(){ + this.span.parentNode.removeChild(this.span) + this.span = null +} |
