slight cleanup / comprehension use

This commit is contained in:
Howland Owl 2013-10-07 18:43:07 +03:00
parent f01c5717f4
commit b3a77f6a66
3 changed files with 54 additions and 48 deletions

1
.jshintrc Normal file
View file

@ -0,0 +1 @@
eqnull

View file

@ -991,30 +991,35 @@ class @ImageTextMode
ctx = canvas.getContext '2d' ctx = canvas.getContext '2d'
for cy in [ 0 ... @screen.length ] for cy in [ 0 ... @screen.length ]
continue if !@screen[ cy ]? if @screen[ cy ]?
for cx in [ 0 ... @screen[ cy ].length ] for cx in [ 0 ... @screen[ cy ].length ]
pixel = @screen[ cy ][ cx ] pixel = @screen[ cy ][ cx ]
continue if !pixel? if pixel?
if pixel.attr? if pixel.attr?
fg = pixel.attr & 15 fg = pixel.attr & 15
bg = ( pixel.attr & 240 ) >> 4 bg = ( pixel.attr & 240 ) >> 4
else else
fg = pixel.fg fg = pixel.fg
bg = pixel.bg bg = pixel.bg
px = cx * @font.width px = cx * @font.width
py = cy * @font.height py = cy * @font.height
ctx.fillStyle = @palette.toRgbaString( @palette.colors[ bg ] ) ctx.fillStyle = @palette.toRgbaString( @palette.colors[ bg ] )
ctx.fillRect px, py, @font.width, @font.height ctx.fillRect px, py, @font.width, @font.height
ctx.fillStyle = @palette.toRgbaString( @palette.colors[ fg ] ) ctx.fillStyle = @palette.toRgbaString( @palette.colors[ fg ] )
chr = @font.chars[ pixel.ch.charCodeAt( 0 ) & 0xff ] chr = @font.chars[ pixel.ch.charCodeAt( 0 ) & 0xff ]
for i in [ 0 ... @font.height ] i = 0
line = chr[ i ] for line in chr
for j in [ 0 ... @font.width ] # [ 0 ... @font.height ]
if line & ( 1 << @font.width - 1 - j ) # line = chr[ i ]
ctx.fillRect px + j, py + i, 1, 1 # for j in [ 0 ... @font.width ]
# if line & ( 1 << @font.width - 1 - j )
# ctx.fillRect px + j, py + i, 1, 1
ctx.fillRect px + j, py + i, 1, 1 for j in [ 0 ... @font.width ] when line & (1 << @font.width - 1 - j )
i += 1
canvasElem.setAttribute 'width', w canvasElem.setAttribute 'width', w
canvasElem.setAttribute 'height', h canvasElem.setAttribute 'height', h

View file

@ -304,7 +304,7 @@
}; };
ImageTextMode.prototype.renderCanvas = function(canvasElem) { ImageTextMode.prototype.renderCanvas = function(canvasElem) {
var bg, canvas, chr, ctx, cx, cy, fg, h, i, j, line, pixel, px, py, w, _i, _j, _k, _l, _ref, _ref1, _ref2, _ref3; var bg, canvas, chr, ctx, cx, cy, fg, h, i, j, line, pixel, px, py, w, _i, _j, _k, _l, _len, _ref, _ref1, _ref2;
w = this.getWidth() * this.font.width; w = this.getWidth() * this.font.width;
h = this.getHeight() * this.font.height; h = this.getHeight() * this.font.height;
canvas = document.createElement('canvas'); canvas = document.createElement('canvas');
@ -312,32 +312,32 @@
canvas.setAttribute('height', h); canvas.setAttribute('height', h);
ctx = canvas.getContext('2d'); ctx = canvas.getContext('2d');
for (cy = _i = 0, _ref = this.screen.length; 0 <= _ref ? _i < _ref : _i > _ref; cy = 0 <= _ref ? ++_i : --_i) { for (cy = _i = 0, _ref = this.screen.length; 0 <= _ref ? _i < _ref : _i > _ref; cy = 0 <= _ref ? ++_i : --_i) {
if (this.screen[cy] == null) { if (this.screen[cy] != null) {
continue; for (cx = _j = 0, _ref1 = this.screen[cy].length; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; cx = 0 <= _ref1 ? ++_j : --_j) {
} pixel = this.screen[cy][cx];
for (cx = _j = 0, _ref1 = this.screen[cy].length; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; cx = 0 <= _ref1 ? ++_j : --_j) { if (pixel != null) {
pixel = this.screen[cy][cx]; if (pixel.attr != null) {
if (pixel == null) { fg = pixel.attr & 15;
continue; bg = (pixel.attr & 240) >> 4;
} } else {
if (pixel.attr != null) { fg = pixel.fg;
fg = pixel.attr & 15; bg = pixel.bg;
bg = (pixel.attr & 240) >> 4; }
} else { px = cx * this.font.width;
fg = pixel.fg; py = cy * this.font.height;
bg = pixel.bg; ctx.fillStyle = this.palette.toRgbaString(this.palette.colors[bg]);
} ctx.fillRect(px, py, this.font.width, this.font.height);
px = cx * this.font.width; ctx.fillStyle = this.palette.toRgbaString(this.palette.colors[fg]);
py = cy * this.font.height; chr = this.font.chars[pixel.ch.charCodeAt(0) & 0xff];
ctx.fillStyle = this.palette.toRgbaString(this.palette.colors[bg]); i = 0;
ctx.fillRect(px, py, this.font.width, this.font.height); for (_k = 0, _len = chr.length; _k < _len; _k++) {
ctx.fillStyle = this.palette.toRgbaString(this.palette.colors[fg]); line = chr[_k];
chr = this.font.chars[pixel.ch.charCodeAt(0) & 0xff]; for (j = _l = 0, _ref2 = this.font.width; 0 <= _ref2 ? _l < _ref2 : _l > _ref2; j = 0 <= _ref2 ? ++_l : --_l) {
for (i = _k = 0, _ref2 = this.font.height; 0 <= _ref2 ? _k < _ref2 : _k > _ref2; i = 0 <= _ref2 ? ++_k : --_k) { if (line & (1 << this.font.width - 1 - j)) {
line = chr[i]; ctx.fillRect(px + j, py + i, 1, 1);
for (j = _l = 0, _ref3 = this.font.width; 0 <= _ref3 ? _l < _ref3 : _l > _ref3; j = 0 <= _ref3 ? ++_l : --_l) { }
if (line & (1 << this.font.width - 1 - j)) { }
ctx.fillRect(px + j, py + i, 1, 1); i += 1;
} }
} }
} }