Browse Source

Added a NESTileSurface class accessible through the renderer that will allow for the quick rendering of NESTiles.

dev
Bryan Miller 5 years ago
parent
commit
90524054d4
1 changed files with 29 additions and 1 deletions
  1. +29
    -1
      app/js/ui/Renderer.js

+ 29
- 1
app/js/ui/Renderer.js View File

@@ -2,6 +2,33 @@ import ISurface from "/app/js/ifaces/ISurface.js";
import NESPalette from "/app/js/models/NESPalette.js";



class NESTileSurface extends ISurface{
constructor(tile, palette, palindex){
super();
this.__tile = tile;
this.__palette = (palette instanceof NESPalette) ? palette : null;
this.__pi = (palindex >= 0 && palindex < 8) ? palindex : -1;
}

get width(){return 8;}
get height(){return 8;}
get length(){return 64;}

getColor(x, y){
var ci = this.__tile.getPixelIndex(x, y);
if (this.__palette !== null){
return this.__palette.get_palette_color(this.__pi, ci);
}
return NESPalette.Default(ci);
}

getColorIndex(x, y){
return {pi:this.__pi, ci:this.__tile.getPixelIndex(x,y)};
}
}


function clear(ctx, color, cw, ch){
if (typeof(cw) !== 'number'){
cw = (Math.floor(ctx.canvas.clientWidth) > 0) ?
@@ -131,5 +158,6 @@ function renderToFit(surf, ctx, palcolored){
export default {
clear: clear,
render: render,
renderToFit: renderToFit
renderToFit: renderToFit,
NESTileSurface: NESTileSurface
};

Loading…
Cancel
Save