some cleanup before heading into main render code
This commit is contained in:
parent
a6c928396e
commit
f01c5717f4
2 changed files with 1311 additions and 1301 deletions
|
|
@ -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++
|
||||
|
||||
|
||||
|
|
|
|||
27
textmode.js
27
textmode.js
|
|
@ -1,4 +1,5 @@
|
|||
// Generated by CoffeeScript 1.6.3
|
||||
(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; };
|
||||
|
||||
|
|
@ -7,7 +8,7 @@ this.ImageTextModeSAUCE = (function() {
|
|||
|
||||
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';
|
||||
|
|
@ -210,8 +211,8 @@ this.ImageTextMode = (function() {
|
|||
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);
|
||||
}
|
||||
|
|
@ -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));
|
||||
|
|
@ -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));
|
||||
|
|
@ -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--;
|
||||
|
|
@ -1367,3 +1368,5 @@ this.ImageTextModeAVATAR = (function(_super) {
|
|||
return ImageTextModeAVATAR;
|
||||
|
||||
})(this.ImageTextMode);
|
||||
|
||||
}).call(this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue