浏览代码

Added array-like access to pixels. BROKEN atm.

dev-tmpl
Bryan Miller 5 年前
父节点
当前提交
90ea91d3d3
共有 2 个文件被更改,包括 32 次插入0 次删除
  1. +4
    -0
      app/js/main.js
  2. +28
    -0
      app/js/models/NESTile.js

+ 4
- 0
app/js/main.js 查看文件

@@ -92,6 +92,10 @@ function initialize(DOC){
var TileC = TileB.clone();
TileC.flip(1);

for (var i=0; i < 64; i++){
console.log(TileC.pixels[i]);
}

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);

+ 28
- 0
app/js/models/NESTile.js 查看文件

@@ -39,6 +39,34 @@ export default class NESTile{
this.__data = new Uint8Array(16);
}

get pixels(){
return new Proxy(this, {
get: function(obj, prop){
if (!Number.isInt(prop))
throw new TypeError("Expected integer index.");
if (prop < 0 || prop >= 64)
throw new RangeError("Index out of bounds.");
var dindex = Math.floor(prop*0.25);
var bitoffset = 6 - ((prop % 4) * 2);
return (obj.__data[dindex] & (3 << bitoffset)) >> bitoffset;
},

set: function(obj, prop, value){
if (!Number.isInt(prop))
throw new TypeError("Expected integer index.");
if (!Number.isInt(value))
throw new TypeError("Color index expected to be integer.");
if (prop < 0 || prop >= 64)
throw new RangeError("Index out of bounds.");
if (value < 0 || value >= 4)
throw new RangeError("Color index out of bounds.");
var dindex = Math.floor(index*0.25);
var bitoffset = (index % 4);
obj.__data[dindex] = (obj.__data[dindex] & BitMask(bitoffset)) ^ (ci << ((3 - bitoffset)*2));
}
});
}

get dataArray(){
var d = [];
for (var x = 0; x < 8; x++){

正在加载...
取消
保存