Browse Source

Slight enhancement of the NESTile.isEq() method.

dev-tmpl
Bryan Miller 5 years ago
parent
commit
657988781c
2 changed files with 20 additions and 4 deletions
  1. +2
    -0
      app/js/main.js
  2. +18
    -4
      app/js/models/NESTile.js

+ 2
- 0
app/js/main.js View File

@@ -89,6 +89,7 @@ function initialize(DOC){
var TileB = new NESTile();
TileB.setPixelIndex(0,0,2);
var TileC = TileB.clone().flip(1);
var TileD = TileB.clone().flip(3);
//var TileC = TileB.clone();
//TileC.flip(1);

@@ -99,6 +100,7 @@ function initialize(DOC){
console.log("TileA does NOT match TileB: ", TileA.isEq(TileB) == -1);
console.log("TileA does NOT match TileC: ", TileA.isEq(TileC) == -1);
console.log("TileB DOES match TileC with Flag 1: ", TileB.isEq(TileC) == 1);
console.log("TileB DOES match TileD with Flag 3: ", TileB.isEq(TileD) == 3);

console.log(TileC);
console.log(TileC.dataArray);

+ 18
- 4
app/js/models/NESTile.js View File

@@ -43,7 +43,6 @@ export default class NESTile{
get pixels(){
return new Proxy(this, {
get: function(obj, prop){
console.log(prop);
if (!Utils.isInt(prop))
throw new TypeError("Expected integer index.");
if (prop < 0 || prop >= 64)
@@ -107,6 +106,16 @@ export default class NESTile{
this.__palette = p;
}

get paletteIndex(){return this.__paletteIndex;}
set paletteIndex(pi){
if (!Utils.isInt(pi))
throw new TypeError("Palette index expected to be an integer.");
if (pi < 0 || pi >= 4){
throw new RangeError("Palette index out of bounds.");
}
this.__paletteIndex = pi;
}

setPixelIndex(x, y, ci){
if (x < 0 || x >= 8 || y < 0 || y >= 8){
throw new ValueError("Coordinates out of bounds.");
@@ -184,13 +193,18 @@ export default class NESTile{
if (tile.base64 === b64){
return 0;
}
if (tile.clone().flip(1).base64 === b64){
var tc = tile.clone().flip(1); // Flip horizontal.
if (tc.base64 === b64){
return 1;
}
if (tile.clone().flip(2).base64 === b64){

tc.flip(3); // Flip horizontal AND verticle. Net effect is the same as tile.clone().flip(2) ... Flip Verticle
if (tc.base64 === b64){
return 2;
}
if (tile.clone().flip(3).base64 === b64){

tc.flip(1); // Flip horizontal again. Net effect is the same as tile.clone().flip(3) ... flip H & V
if (tc.base64 === b64){
return 3;
}
return -1;

Loading…
Cancel
Save