Browse Source

NESTile now uses the Utils.isInt() function.

dev-tmpl
Bryan Miller 5 years ago
parent
commit
451edac454
2 changed files with 14 additions and 8 deletions
  1. +7
    -3
      app/js/main.js
  2. +7
    -5
      app/js/models/NESTile.js

+ 7
- 3
app/js/main.js View File

var TileA = new NESTile(); var TileA = new NESTile();
var TileB = new NESTile(); var TileB = new NESTile();
TileB.setPixelIndex(0,0,2); TileB.setPixelIndex(0,0,2);
//var TileC = TileB.clone().flip(1);
var TileC = TileB.clone();
TileC.flip(1);
var TileC = TileB.clone().flip(1);
//var TileC = TileB.clone();
//TileC.flip(1);


for (var i=0; i < 64; i++){ for (var i=0; i < 64; i++){
console.log(TileC.pixels[i]); console.log(TileC.pixels[i]);
console.log("TileA does NOT match TileB: ", TileA.isEq(TileB) == -1); console.log("TileA does NOT match TileB: ", TileA.isEq(TileB) == -1);
console.log("TileA does NOT match TileC: ", TileA.isEq(TileC) == -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 TileC with Flag 1: ", TileB.isEq(TileC) == 1);

console.log(TileC);
console.log(TileC.dataArray);
console.log(TileC.pixels[7]);
} }





+ 7
- 5
app/js/models/NESTile.js View File

import Utils from "/app/js/common/Utils.js";
import NESPalette from "/app/js/models/NESPalette.js"; import NESPalette from "/app/js/models/NESPalette.js";


function BitMask(offset){ function BitMask(offset){
get pixels(){ get pixels(){
return new Proxy(this, { return new Proxy(this, {
get: function(obj, prop){ get: function(obj, prop){
if (!Number.isInt(prop))
console.log(prop);
if (!Utils.isInt(prop))
throw new TypeError("Expected integer index."); throw new TypeError("Expected integer index.");
if (prop < 0 || prop >= 64) if (prop < 0 || prop >= 64)
throw new RangeError("Index out of bounds."); throw new RangeError("Index out of bounds.");
}, },


set: function(obj, prop, value){ set: function(obj, prop, value){
if (!Number.isInt(prop))
if (!Utils.isInt(prop))
throw new TypeError("Expected integer index."); throw new TypeError("Expected integer index.");
if (!Number.isInt(value))
if (!Utils.isInt(value))
throw new TypeError("Color index expected to be integer."); throw new TypeError("Color index expected to be integer.");
if (prop < 0 || prop >= 64) if (prop < 0 || prop >= 64)
throw new RangeError("Index out of bounds."); throw new RangeError("Index out of bounds.");


get dataArray(){ get dataArray(){
var d = []; var d = [];
for (var x = 0; x < 8; x++){
for (var y = 0; y < 8; y++){
for (var y = 0; y < 8; y++){
for (var x = 0; x < 8; x++){
d.push(this.getPixelIndex(x, y)); d.push(this.getPixelIndex(x, y));
} }
} }

Loading…
Cancel
Save