Browse Source

Switched NESPalette.Default into a function that pulls colors from an array. These default values can now be set with the .SetDefault() function.

dev
Bryan Miller 5 years ago
parent
commit
808079ac24
2 changed files with 35 additions and 10 deletions
  1. +32
    -7
      app/js/models/NESPalette.js
  2. +3
    -3
      app/js/ui/Renderer.js

+ 32
- 7
app/js/models/NESPalette.js View File

@@ -16,6 +16,15 @@ JSONSchema.add({
}
});


var DEFAULT_PALETTE = [
"#080808",
"#343434",
"#a2a2a2",
"#efefef"
];
var OOB_COLOR = "#666666";

/**
* Object for manipulating the eight NES palettes.
* @extends EventCaller
@@ -298,12 +307,28 @@ NESPalette.SystemColor = [
"#000000"
];

NESPalette.Default = [
"#080808",
"#343434",
"#a2a2a2",
"#efefef",
"#666666" // Out of bounds color.
];
NESPalette.Default = function(index){
if (index >= 0 && index < DEFAULT_PALETTE.length)
return DEFAULT_PALETTE[index];
return OOB_COLOR;
}

NESPalette.SetDefaultColor = function(index, r,g,b){
var Hex = (c) => {
c = c.toString(16);
return (c.length < 2) ? "0" + c : c;
};

var Clamp = (c) => {
return Math.floor(Math.max(0, Math.min(255, c)));
};

var color = "#" + Hex(Clamp(r)) + Hex(Clamp(g)) + Hex(Clamp(b));
if (index >= 0 && index < DEFAULT_PALETTE.length){
DEFAULT_PALETTE = color;
} else {
OOB_COLOR = color;
}
}



+ 3
- 3
app/js/ui/Renderer.js View File

@@ -45,7 +45,7 @@ function render(surf, sx, sy, sw, sh, scale, ctx, dx, dy, palcolored){

if (cw <= 0 || ch <= 0){return;}

clear(ctx, NESPalette.Default[4]);
clear(ctx, NESPalette.Default(4));

ctx.save();
var ctximg = ctx.getImageData(0, 0, cw, ch);
@@ -80,12 +80,12 @@ function render(surf, sx, sy, sw, sh, scale, ctx, dx, dy, palcolored){
var x = (i*scale) + dx;

if (x >= 0 && x < cw && y >= 0 && y < ch){
var color = NESPalette.Default[4];
var color = NESPalette.Default(4);
if (palcolored){
color = surf.getColor(i, j);
} else {
var pinfo = surf.getColorIndex(i, j);
color = (pinfo.ci >= 0) ? NESPalette.Default[pinfo.ci] : NESPalette.Default[4];
color = (pinfo.ci >= 0) ? NESPalette.Default(pinfo.ci) : NESPalette.Default(4);
}
PutPixel(x,y,scale,color);
}

Loading…
Cancel
Save