| export default class NESTile{ | export default class NESTile{ | ||||
| constructor(){ | constructor(){ | ||||
| this.__palette = null; | |||||
| this.__paletteIndex = 0; | this.__paletteIndex = 0; | ||||
| this.__data = new Uint8Array(16); | this.__data = new Uint8Array(16); | ||||
| } | } | ||||
| get pixels(){ | get pixels(){ | ||||
| return new Proxy(this, { | return new Proxy(this, { | ||||
| get: function(obj, prop){ | get: function(obj, prop){ | ||||
| if (prop === "length") | |||||
| return 64; | |||||
| if (!Utils.isInt(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) | ||||
| this.__data = bytes; | this.__data = bytes; | ||||
| } | } | ||||
| get palette(){return this.__palette;} | |||||
| set palette(p){ | |||||
| if (p !== null && !(p instanceof NESPalette)){ | |||||
| throw new TypeError("Expected NESPalette instance or null."); | |||||
| } | |||||
| this.__palette = p; | |||||
| } | |||||
| get paletteIndex(){return this.__paletteIndex;} | get paletteIndex(){return this.__paletteIndex;} | ||||
| set paletteIndex(pi){ | set paletteIndex(pi){ | ||||
| return GetDataArrayColor(this.__data, x, y); | return GetDataArrayColor(this.__data, x, y); | ||||
| } | } | ||||
| getPixel(x, y){ | |||||
| var ci = 0; | |||||
| try { | |||||
| ci = this.getPixelIndex(x, y); | |||||
| } catch (e) { | |||||
| throw e; | |||||
| } | |||||
| if (this.__palette !== null){ | |||||
| return this.__palette.get_palette_color(this.__paletteIndex, ci); | |||||
| } | |||||
| switch(ci){ | |||||
| case 1: | |||||
| return "#555555"; | |||||
| case 2: | |||||
| return "#AAAAAA"; | |||||
| case 3: | |||||
| return "#FFFFFF"; | |||||
| } | |||||
| return 0; | |||||
| } | |||||
| flip(flag){ | flip(flag){ | ||||
| if (flag >= 1 && flag <= 3){ | if (flag >= 1 && flag <= 3){ | ||||
| var newData = new Uint8Array(16); | var newData = new Uint8Array(16); |