some cleanup before heading into main render code

This commit is contained in:
Howland Owl 2013-10-07 16:14:30 +03:00
parent a6c928396e
commit f01c5717f4
2 changed files with 1311 additions and 1301 deletions

View file

@ -10,7 +10,7 @@ class @ImageTextModeSAUCE
parse: ( content ) ->
sauceMarker = content.length - 128;
return false if content.substr( sauceMarker, 5 ) is not 'SAUCE'
return false if content.substr( sauceMarker, 5 ) isnt 'SAUCE'
@id = 'SAUCE'
@version = content.substr( sauceMarker + 5, 2 )
@title = content.substr( sauceMarker + 7, 35 )
@ -66,7 +66,8 @@ class @ImageTextModePalette
class @ImageTextModePaletteVGA extends @ImageTextModePalette
constructor: ( options ) ->
super @colors = [
super
@colors = [
[ 0x00, 0x00, 0x00 ],
[ 0x00, 0x00, 0xaa ],
[ 0x00, 0xaa, 0x00 ],
@ -918,12 +919,12 @@ class @ImageTextMode
constructor: ( options ) ->
@screen = []
@palette = new ImageTextModePaletteVGA
@font = new ImageTextModeFont8x16
this[k] = v for own k, v of options
@palette = new ImageTextModePaletteVGA()
@font = new ImageTextModeFont8x16()
@[k] = v for own k, v of options
parseUrl: ( url ) ->
req = new XMLHttpRequest
req = new XMLHttpRequest()
req.open 'GET', url, false
req.overrideMimeType 'text/plain; charset=x-user-defined'
req.send null
@ -945,6 +946,8 @@ class @ImageTextMode
getByteAt: ( data, offset ) ->
return data.charCodeAt( offset ) & 0xFF
# could we replace this with math.max ?
getWidth: ->
max = 0
for y in [ 0 .. @screen.length - 1 ]
@ -965,7 +968,7 @@ class @ImageTextMode
b = b << 2 | b >> 4
colors.push [ r, g, b ]
@palette = new ImageTextModePalette( { colors: colors } )
@palette = new ImageTextModePalette( colors: colors )
parseFontData: ( data, height = 16 ) ->
chars = []
@ -976,6 +979,8 @@ class @ImageTextMode
chars.push chr
@font = new ImageTextModeFont( { chars: chars, height: height } )
# the majority of time is spent in this routine
renderCanvas: ( canvasElem ) ->
w = @getWidth() * @font.width
h = @getHeight() * @font.height
@ -985,9 +990,9 @@ class @ImageTextMode
canvas.setAttribute 'height', h
ctx = canvas.getContext '2d'
for cy in [ 0 .. @screen.length - 1 ]
for cy in [ 0 ... @screen.length ]
continue if !@screen[ cy ]?
for cx in [ 0 .. @screen[ cy ].length - 1 ]
for cx in [ 0 ... @screen[ cy ].length ]
pixel = @screen[ cy ][ cx ]
continue if !pixel?
if pixel.attr?
@ -1005,9 +1010,9 @@ class @ImageTextMode
ctx.fillStyle = @palette.toRgbaString( @palette.colors[ fg ] )
chr = @font.chars[ pixel.ch.charCodeAt( 0 ) & 0xff ]
for i in [ 0 .. @font.height - 1 ]
for i in [ 0 ... @font.height ]
line = chr[ i ]
for j in [ 0 .. @font.width - 1 ]
for j in [ 0 ... @font.width ]
if line & ( 1 << @font.width - 1 - j )
ctx.fillRect px + j, py + i, 1, 1
@ -1056,7 +1061,7 @@ class @ImageTextModeXBin extends @ImageTextMode
parse: ( content ) ->
@screen = []
headerData = content.substr( 0, 11 )
if headerData.length is not 11 || !headerData.match( '^XBIN\x1a' )
if headerData.length isnt 11 || !headerData.match( '^XBIN\x1a' )
throw new Error( 'File is not an XBin' )
@header.width = @unpackShort( headerData.substr( 5, 2 ) )
@ -1353,7 +1358,7 @@ class @ImageTextModeIDF extends @ImageTextMode
parse: ( content ) ->
headerData = content.substr( 0, 12 )
if headerData.length is not 12 || !headerData.match( '^\x041.4' )
if headerData.length isnt 12 || !headerData.match( '^\x041.4' )
throw new Error( 'File is not an IDF' )
@header.x0 = @unpackShort( headerData.substr( 4, 2 ) )
@ -1558,7 +1563,7 @@ class @ImageTextModePCBoard extends @ImageTextMode
else if ch + content[ 0..2 ].join( '' ) is 'POS:'
content.shift() for [ 1 .. 3 ]
@x = content.shift()
@x += content.shift() if content[ 0 ] is not '@'
@x += content.shift() if content[ 0 ] isnt '@'
@x--
content.shift()
@ -1648,3 +1653,5 @@ class @ImageTextModeAVATAR extends @ImageTextMode
if ++@x >= @linewrap
@x = 0
@y++

View file

@ -1,13 +1,14 @@
// Generated by CoffeeScript 1.6.3
var __hasProp = {}.hasOwnProperty,
(function() {
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
this.ImageTextModeSAUCE = (function() {
this.ImageTextModeSAUCE = (function() {
function ImageTextModeSAUCE() {}
ImageTextModeSAUCE.prototype.parseUrl = function(url) {
var content, req;
req = new XMLHttpRequest;
req = new XMLHttpRequest();
req.open('GET', url, false);
req.overrideMimeType('text/plain; charset=x-user-defined');
req.send(null);
@ -18,7 +19,7 @@ this.ImageTextModeSAUCE = (function() {
ImageTextModeSAUCE.prototype.parse = function(content) {
var commentMarker, i, sauceMarker;
sauceMarker = content.length - 128;
if (content.substr(sauceMarker, 5) === !'SAUCE') {
if (content.substr(sauceMarker, 5) !== 'SAUCE') {
return false;
}
this.id = 'SAUCE';
@ -74,9 +75,9 @@ this.ImageTextModeSAUCE = (function() {
return ImageTextModeSAUCE;
})();
})();
this.ImageTextModePalette = (function() {
this.ImageTextModePalette = (function() {
function ImageTextModePalette(options) {
var k, v;
this.colors = [];
@ -93,9 +94,9 @@ this.ImageTextModePalette = (function() {
return ImageTextModePalette;
})();
})();
this.ImageTextModePaletteVGA = (function(_super) {
this.ImageTextModePaletteVGA = (function(_super) {
__extends(ImageTextModePaletteVGA, _super);
function ImageTextModePaletteVGA(options) {
@ -111,9 +112,9 @@ this.ImageTextModePaletteVGA = (function(_super) {
return ImageTextModePaletteVGA;
})(this.ImageTextModePalette);
})(this.ImageTextModePalette);
this.ImageTextModePaletteANSI = (function(_super) {
this.ImageTextModePaletteANSI = (function(_super) {
__extends(ImageTextModePaletteANSI, _super);
function ImageTextModePaletteANSI(options) {
@ -129,9 +130,9 @@ this.ImageTextModePaletteANSI = (function(_super) {
return ImageTextModePaletteANSI;
})(this.ImageTextModePalette);
})(this.ImageTextModePalette);
this.ImageTextModeFont = (function() {
this.ImageTextModeFont = (function() {
function ImageTextModeFont(options) {
var k, v;
this.chars = [];
@ -145,9 +146,9 @@ this.ImageTextModeFont = (function() {
return ImageTextModeFont;
})();
})();
this.ImageTextModeFont8x16 = (function(_super) {
this.ImageTextModeFont8x16 = (function(_super) {
__extends(ImageTextModeFont8x16, _super);
function ImageTextModeFont8x16(options) {
@ -164,9 +165,9 @@ this.ImageTextModeFont8x16 = (function(_super) {
return ImageTextModeFont8x16;
})(this.ImageTextModeFont);
})(this.ImageTextModeFont);
this.ImageTextModeFont8x8 = (function(_super) {
this.ImageTextModeFont8x8 = (function(_super) {
__extends(ImageTextModeFont8x8, _super);
function ImageTextModeFont8x8(options) {
@ -183,9 +184,9 @@ this.ImageTextModeFont8x8 = (function(_super) {
return ImageTextModeFont8x8;
})(this.ImageTextModeFont);
})(this.ImageTextModeFont);
this.ImageTextModeFontAmiga = (function(_super) {
this.ImageTextModeFontAmiga = (function(_super) {
__extends(ImageTextModeFontAmiga, _super);
function ImageTextModeFontAmiga(options) {
@ -202,16 +203,16 @@ this.ImageTextModeFontAmiga = (function(_super) {
return ImageTextModeFontAmiga;
})(this.ImageTextModeFont);
})(this.ImageTextModeFont);
this.ImageTextMode = (function() {
this.ImageTextMode = (function() {
ImageTextMode.VERSION = '0.01';
function ImageTextMode(options) {
var k, v;
this.screen = [];
this.palette = new ImageTextModePaletteVGA;
this.font = new ImageTextModeFont8x16;
this.palette = new ImageTextModePaletteVGA();
this.font = new ImageTextModeFont8x16();
for (k in options) {
if (!__hasProp.call(options, k)) continue;
v = options[k];
@ -221,7 +222,7 @@ this.ImageTextMode = (function() {
ImageTextMode.prototype.parseUrl = function(url) {
var content, req;
req = new XMLHttpRequest;
req = new XMLHttpRequest();
req.open('GET', url, false);
req.overrideMimeType('text/plain; charset=x-user-defined');
req.send(null);
@ -310,11 +311,11 @@ this.ImageTextMode = (function() {
canvas.setAttribute('width', w);
canvas.setAttribute('height', h);
ctx = canvas.getContext('2d');
for (cy = _i = 0, _ref = this.screen.length - 1; 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) {
continue;
}
for (cx = _j = 0, _ref1 = this.screen[cy].length - 1; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; cx = 0 <= _ref1 ? ++_j : --_j) {
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;
@ -332,9 +333,9 @@ this.ImageTextMode = (function() {
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 - 1; 0 <= _ref2 ? _k <= _ref2 : _k >= _ref2; i = 0 <= _ref2 ? ++_k : --_k) {
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 - 1; 0 <= _ref3 ? _l <= _ref3 : _l >= _ref3; j = 0 <= _ref3 ? ++_l : --_l) {
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);
}
@ -363,9 +364,9 @@ this.ImageTextMode = (function() {
return ImageTextMode;
})();
})();
this.ImageTextModeXBin = (function(_super) {
this.ImageTextModeXBin = (function(_super) {
var ATTRIBUTE_COMPRESSION, CHARACTER_COMPRESSION, COMPRESSED, COMPRESSION_COUNTER, COMPRESSION_TYPE, FIVETWELVE_CHARS, FONT, FULL_COMPRESSION, NON_BLINK, NO_COMPRESSION, PALETTE;
__extends(ImageTextModeXBin, _super);
@ -412,7 +413,7 @@ this.ImageTextModeXBin = (function(_super) {
var fontlength, headerData, offset;
this.screen = [];
headerData = content.substr(0, 11);
if (headerData.length === !11 || !headerData.match('^XBIN\x1a')) {
if (headerData.length !== 11 || !headerData.match('^XBIN\x1a')) {
throw new Error('File is not an XBin');
}
this.header.width = this.unpackShort(headerData.substr(5, 2));
@ -557,9 +558,9 @@ this.ImageTextModeXBin = (function(_super) {
return ImageTextModeXBin;
})(this.ImageTextMode);
})(this.ImageTextMode);
this.ImageTextModeANSI = (function(_super) {
this.ImageTextModeANSI = (function(_super) {
var ANSI_BG, ANSI_BG_INTENSE, ANSI_CSI, ANSI_CUR_DOWN, ANSI_ESC, ANSI_FG, ANSI_FG_INTENSE, ANSI_RESET, ANSI_RETURN, ANSI_SEP, ANSI_TEXT_PROP;
__extends(ImageTextModeANSI, _super);
@ -841,9 +842,9 @@ this.ImageTextModeANSI = (function(_super) {
return ImageTextModeANSI;
})(this.ImageTextMode);
})(this.ImageTextMode);
this.ImageTextModeBin = (function(_super) {
this.ImageTextModeBin = (function(_super) {
__extends(ImageTextModeBin, _super);
function ImageTextModeBin(options) {
@ -886,9 +887,9 @@ this.ImageTextModeBin = (function(_super) {
return ImageTextModeBin;
})(this.ImageTextMode);
})(this.ImageTextMode);
this.ImageTextModeIDF = (function(_super) {
this.ImageTextModeIDF = (function(_super) {
__extends(ImageTextModeIDF, _super);
function ImageTextModeIDF(options) {
@ -910,7 +911,7 @@ this.ImageTextModeIDF = (function(_super) {
ImageTextModeIDF.prototype.parse = function(content) {
var attr, buffer, ch, eodata, headerData, i, info, len, offset, x, y, _i;
headerData = content.substr(0, 12);
if (headerData.length === !12 || !headerData.match('^\x041.4')) {
if (headerData.length !== 12 || !headerData.match('^\x041.4')) {
throw new Error('File is not an IDF');
}
this.header.x0 = this.unpackShort(headerData.substr(4, 2));
@ -960,9 +961,9 @@ this.ImageTextModeIDF = (function(_super) {
return ImageTextModeIDF;
})(this.ImageTextMode);
})(this.ImageTextMode);
this.ImageTextModeADF = (function(_super) {
this.ImageTextModeADF = (function(_super) {
var COLOR_INDEX;
__extends(ImageTextModeADF, _super);
@ -1033,9 +1034,9 @@ this.ImageTextModeADF = (function(_super) {
return ImageTextModeADF;
})(this.ImageTextMode);
})(this.ImageTextMode);
this.ImageTextModeTundra = (function(_super) {
this.ImageTextModeTundra = (function(_super) {
__extends(ImageTextModeTundra, _super);
function ImageTextModeTundra(options) {
@ -1116,9 +1117,9 @@ this.ImageTextModeTundra = (function(_super) {
return ImageTextModeTundra;
})(this.ImageTextMode);
})(this.ImageTextMode);
this.ImageTextModePCBoard = (function(_super) {
this.ImageTextModePCBoard = (function(_super) {
__extends(ImageTextModePCBoard, _super);
function ImageTextModePCBoard(options) {
@ -1194,7 +1195,7 @@ this.ImageTextModePCBoard = (function(_super) {
content.shift();
}
this.x = content.shift();
if (content[0] === !'@') {
if (content[0] !== '@') {
this.x += content.shift();
}
this.x--;
@ -1229,9 +1230,9 @@ this.ImageTextModePCBoard = (function(_super) {
return ImageTextModePCBoard;
})(this.ImageTextMode);
})(this.ImageTextMode);
this.ImageTextModeAVATAR = (function(_super) {
this.ImageTextModeAVATAR = (function(_super) {
__extends(ImageTextModeAVATAR, _super);
function ImageTextModeAVATAR(options) {
@ -1366,4 +1367,6 @@ this.ImageTextModeAVATAR = (function(_super) {
return ImageTextModeAVATAR;
})(this.ImageTextMode);
})(this.ImageTextMode);
}).call(this);