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'
for cy in [ 0 ... @screen.length ]
continue if !@screen[ cy ]?
for cx in [ 0 ... @screen[ cy ].length ]
pixel = @screen[ cy ][ cx ]
continue if !pixel?
if pixel.attr?
fg = pixel.attr & 15
bg = ( pixel.attr & 240 ) >> 4
else
fg = pixel.fg
bg = pixel.bg
if @screen[ cy ]?
for cx in [ 0 ... @screen[ cy ].length ]
pixel = @screen[ cy ][ cx ]
if pixel?
if pixel.attr?
fg = pixel.attr & 15
bg = ( pixel.attr & 240 ) >> 4
else
fg = pixel.fg
bg = pixel.bg
px = cx * @font.width
py = cy * @font.height
px = cx * @font.width
py = cy * @font.height
ctx.fillStyle = @palette.toRgbaString( @palette.colors[ bg ] )
ctx.fillRect px, py, @font.width, @font.height
ctx.fillStyle = @palette.toRgbaString( @palette.colors[ bg ] )
ctx.fillRect px, py, @font.width, @font.height
ctx.fillStyle = @palette.toRgbaString( @palette.colors[ fg ] )
chr = @font.chars[ pixel.ch.charCodeAt( 0 ) & 0xff ]
for i in [ 0 ... @font.height ]
line = chr[ i ]
for j in [ 0 ... @font.width ]
if line & ( 1 << @font.width - 1 - j )
ctx.fillRect px + j, py + i, 1, 1
ctx.fillStyle = @palette.toRgbaString( @palette.colors[ fg ] )
chr = @font.chars[ pixel.ch.charCodeAt( 0 ) & 0xff ]
i = 0
for line in chr
# [ 0 ... @font.height ]
# line = chr[ i ]
# 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 'height', h

View file

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