diff --git a/src/field.js b/src/field.js index 053b72c..279c6d7 100644 --- a/src/field.js +++ b/src/field.js @@ -179,18 +179,20 @@ class Field extends component.Component { throw new Error(`field.fill needs array or number, got ${v}`); } - pack() { + toArrays() { let newPitch = this.width; let numPixels = this.height * newPitch; - let newBuff = new Uint8Array(numPixels); + let newArrays = new Array(this.height); for (let y = 0; y < this.height; y++) { + let newRow = new Array(this.width); for (let x = 0; x < this.width; x++) { let k = y*this.pitch + x; let j = y*newPitch + x; - newBuff[j] = this.data[k]; + newRow[x] = this.data[k]; } + newArrays[y] = newRow; } - return newBuff; + return newArrays; } xform(kind) { diff --git a/src/tileset_builder.js b/src/tileset_builder.js index 4854b99..f071935 100644 --- a/src/tileset_builder.js +++ b/src/tileset_builder.js @@ -12,7 +12,7 @@ class TilesetBuilderDisplay extends baseDisplay.BaseDisplay { } this._tileset = new tiles.Tileset(details); this._frames = []; - this._numFrames = info.numFrames || 64; + this._numFrames = info.numFrames || 256; } name() { diff --git a/test/cycle_palette.js b/test/cycle_palette.js index 0ac4a20..e3f5550 100644 --- a/test/cycle_palette.js +++ b/test/cycle_palette.js @@ -27,17 +27,17 @@ describe('Cycle palette', function() { util.renderCompareTo(ra, 'test/testdata/green-fruit.png'); - let expect = new Uint8Array([ - 0, 0, 0, 0, 4, 0, 0, 0, - 0, 0, 0, 0, 0, 4, 0, 0, - 0, 2, 8, 8, 8, 4, 2, 0, - 2, 8,14, 8, 4, 8, 8, 2, - 8,14,14, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, - 0, 8, 8, 8, 8, 8, 8, 0, - 0, 0, 8, 8, 8, 8, 0, 0 - ]); - assert.deepEqual(expect, ra.field.pack()); + let expect = [ + [ 0, 0, 0, 0, 4, 0, 0, 0], + [ 0, 0, 0, 0, 0, 4, 0, 0], + [ 0, 2, 8, 8, 8, 4, 2, 0], + [ 2, 8,14, 8, 4, 8, 8, 2], + [ 8,14,14, 8, 8, 8, 8, 8], + [ 8, 8, 8, 8, 8, 8, 8, 8], + [ 0, 8, 8, 8, 8, 8, 8, 0], + [ 0, 0, 8, 8, 8, 8, 0, 0], + ]; + assert.deepEqual(expect, ra.field.toArrays()); // Compare the palette palette = ra.palette; @@ -171,17 +171,17 @@ describe('Cycle palette', function() { let img = ra.loadImage('test/testdata/small-fruit.png'); ra.paste(img); - let expect = new Uint8Array([ - 1, 1, 1, 1, 4, 1, 1, 1, - 1, 1, 1, 1, 1, 4, 1, 1, - 1, 2, 0, 0, 0, 4, 2, 1, - 2, 0, 3, 0, 4, 0, 0, 2, - 0, 3, 3, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 1, - 1, 1, 0, 0, 0, 0, 1, 1 - ]); - assert.deepEqual(expect, ra.field.pack()); + let expect = [ + [1, 1, 1, 1, 4, 1, 1, 1], + [1, 1, 1, 1, 1, 4, 1, 1], + [1, 2, 0, 0, 0, 4, 2, 1], + [2, 0, 3, 0, 4, 0, 0, 2], + [0, 3, 3, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 0, 0, 1], + [1, 1, 0, 0, 0, 0, 1, 1], + ]; + assert.deepEqual(expect, ra.field.toArrays()); // Compare the palette let palette = ra.palette; diff --git a/test/plane.js b/test/field.js similarity index 84% rename from test/plane.js rename to test/field.js index 5a40991..b133838 100644 --- a/test/plane.js +++ b/test/field.js @@ -11,14 +11,14 @@ describe('Field', function() { [0,0,0,7], [0,7,7,0], ]); - let bin = pl.pack(); + let bin = pl.toArrays(); - let expect = new Uint8Array([ - 0, 7, 7, 0, - 7, 7, 0, 7, - 0, 0, 0, 7, - 0, 7, 7, 0, - ]); + let expect = [ + [0, 7, 7, 0], + [7, 7, 0, 7], + [0, 0, 0, 7], + [0, 7, 7, 0], + ]; assert.deepEqual(expect, bin); }); @@ -38,14 +38,14 @@ describe('Field', function() { let pl = new ra.Field(); pl.setSize(4, 4); pl.fill(5); - let bin = pl.pack(); + let bin = pl.toArrays(); - let expect = new Uint8Array([ - 5, 5, 5, 5, - 5, 5, 5, 5, - 5, 5, 5, 5, - 5, 5, 5, 5, - ]); + let expect = [ + [5, 5, 5, 5], + [5, 5, 5, 5], + [5, 5, 5, 5], + [5, 5, 5, 5], + ]; assert.deepEqual(expect, bin); }); @@ -56,14 +56,14 @@ describe('Field', function() { 7,7,0,7, 0,0,0,7, 0,7,7,0]); - let bin = pl.pack(); + let bin = pl.toArrays(); - let expect = new Uint8Array([ - 0, 7, 7, 0, - 7, 7, 0, 7, - 0, 0, 0, 7, - 0, 7, 7, 0, - ]); + let expect = [ + [0, 7, 7, 0], + [7, 7, 0, 7], + [0, 0, 0, 7], + [0, 7, 7, 0], + ]; assert.deepEqual(expect, bin); }); diff --git a/test/hsv_sort.js b/test/hsv_sort.js index c041880..ee91beb 100644 --- a/test/hsv_sort.js +++ b/test/hsv_sort.js @@ -22,14 +22,14 @@ describe('HSV sort', function() { util.ensureFilesMatch('test/testdata/pal_sphere.png', tmpout); // Compare the field data buffer - let bin = ra.field.pack(); + let bin = ra.field.toArrays(); let pitch = 16; let actual = ''; for (let y = 0; y < 16; y++) { for (let x = 0; x < 16; x++) { let k = y*pitch+x; - actual += `${bin[k]} `; + actual += `${bin[y][x]} `; } actual += '\n'; } @@ -76,7 +76,7 @@ describe('HSV sort', function() { ra.save(pal, tmpout); util.ensureFilesMatch('test/testdata/pal_sphere_sort.png', tmpout); - let bin = ra.field.pack(); + let bin = ra.field.toArrays(); let pitch = 16; // Compare the field data buffer @@ -84,7 +84,7 @@ describe('HSV sort', function() { for (let y = 0; y < 16; y++) { for (let x = 0; x < 16; x++) { let k = y*pitch+x; - actual += `${bin[k]} `; + actual += `${bin[y][x]} `; } actual += '\n'; } diff --git a/test/image.js b/test/image.js index 89c90a2..29f24ed 100644 --- a/test/image.js +++ b/test/image.js @@ -47,17 +47,17 @@ describe('Image', function() { util.renderCompareTo(ra, 'test/testdata/small-fruit.png'); // 8-bit data array is using pico8 values - let expect = new Uint8Array([ - 0, 0, 0, 0, 4, 0, 0, 0, - 0, 0, 0, 0, 0, 4, 0, 0, - 0, 2, 8, 8, 8, 4, 2, 0, - 2, 8,14, 8, 4, 8, 8, 2, - 8,14,14, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, - 0, 8, 8, 8, 8, 8, 8, 0, - 0, 0, 8, 8, 8, 8, 0, 0 - ]); - assert.deepEqual(expect, ra.field.pack()); + let expect = [ + [0, 0, 0, 0, 4, 0, 0, 0], + [0, 0, 0, 0, 0, 4, 0, 0], + [0, 2, 8, 8, 8, 4, 2, 0], + [2, 8,14, 8, 4, 8, 8, 2], + [8,14,14, 8, 8, 8, 8, 8], + [8, 8, 8, 8, 8, 8, 8, 8], + [0, 8, 8, 8, 8, 8, 8, 0], + [0, 0, 8, 8, 8, 8, 0, 0], + ]; + assert.deepEqual(expect, ra.field.toArrays()); }); @@ -71,17 +71,17 @@ describe('Image', function() { util.renderCompareTo(ra, 'test/testdata/small-fruit.png'); - let expect = new Uint8Array([ - 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 0, - 0, 4, 2, 2, 2, 1, 4, 0, - 4, 2, 5, 2, 1, 2, 2, 4, - 2, 5, 5, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, - 0, 2, 2, 2, 2, 2, 2, 0, - 0, 0, 2, 2, 2, 2, 0, 0 - ]); - assert.deepEqual(expect, ra.field.pack()); + let expect = [ + [0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0], + [0, 4, 2, 2, 2, 1, 4, 0], + [4, 2, 5, 2, 1, 2, 2, 4], + [2, 5, 5, 2, 2, 2, 2, 2], + [2, 2, 2, 2, 2, 2, 2, 2], + [0, 2, 2, 2, 2, 2, 2, 0], + [0, 0, 2, 2, 2, 2, 0, 0], + ]; + assert.deepEqual(expect, ra.field.toArrays()); // Compare the palette let palette = ra.palette; @@ -160,17 +160,17 @@ describe('Image', function() { util.renderCompareTo(ra, 'test/testdata/small-fruit-quant.png'); // 8-bit data array is using pico8 values - let expect = new Uint8Array([ - 1, 1,39, 1, 3,32,27,38, - 0,30,36,28,31, 5,40,26, - 37,42, 9,14, 7, 4,45,35, - 43,54,58,21,24,55,19,44, - 17,57,59,50,15,18,46,22, - 53, 6,56,48,47, 8,13,16, - 41,51,20,10,17,18,52,34, - 25,29,12,11,23,49,33, 2, - ]); - assert.deepEqual(expect, ra.field.pack()); + let expect = [ + [ 1, 1,39, 1, 3,32,27,38], + [ 0,30,36,28,31, 5,40,26], + [37,42, 9,14, 7, 4,45,35], + [43,54,58,21,24,55,19,44], + [17,57,59,50,15,18,46,22], + [53, 6,56,48,47, 8,13,16], + [41,51,20,10,17,18,52,34], + [25,29,12,11,23,49,33, 2], + ]; + assert.deepEqual(expect, ra.field.toArrays()); }); diff --git a/test/tileset.js b/test/tileset.js index 108c5d4..8c97e66 100644 --- a/test/tileset.js +++ b/test/tileset.js @@ -356,13 +356,13 @@ describe('Tileset', function() { assert.equal(tiles.length, 8); assert.equal(tiles.numTiles, 8); - let pattern = ra.field.pack(); - let expect = new Uint8Array([ - 0, 1, 2, 3, - 1, 4, 4, 4, - 5, 5, 2, 6, - 1, 7, 0, 0, - ]); + let pattern = ra.field.toArrays(); + let expect = [ + [0, 1, 2, 3], + [1, 4, 4, 4], + [5, 5, 2, 6], + [1, 7, 0, 0], + ]; assert.deepEqual(expect, pattern); assert.deepEqual(4, ra.field.width); assert.deepEqual(4, ra.field.height);