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

@@ -88,9 +88,9 @@ function initialize(DOC){
var TileA = new NESTile();
var TileB = new NESTile();
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++){
console.log(TileC.pixels[i]);
@@ -99,6 +99,10 @@ 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(TileC);
console.log(TileC.dataArray);
console.log(TileC.pixels[7]);
}



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

@@ -1,3 +1,4 @@
import Utils from "/app/js/common/Utils.js";
import NESPalette from "/app/js/models/NESPalette.js";

function BitMask(offset){
@@ -42,7 +43,8 @@ export default class NESTile{
get pixels(){
return new Proxy(this, {
get: function(obj, prop){
if (!Number.isInt(prop))
console.log(prop);
if (!Utils.isInt(prop))
throw new TypeError("Expected integer index.");
if (prop < 0 || prop >= 64)
throw new RangeError("Index out of bounds.");
@@ -52,9 +54,9 @@ export default class NESTile{
},

set: function(obj, prop, value){
if (!Number.isInt(prop))
if (!Utils.isInt(prop))
throw new TypeError("Expected integer index.");
if (!Number.isInt(value))
if (!Utils.isInt(value))
throw new TypeError("Color index expected to be integer.");
if (prop < 0 || prop >= 64)
throw new RangeError("Index out of bounds.");
@@ -69,8 +71,8 @@ export default class NESTile{

get dataArray(){
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));
}
}

Loading…
Cancel
Save