Skip to content
Snippets Groups Projects
Verified Commit f4f87f29 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

refactor: moved palettes out

parent 4c3d2b70
No related branches found
No related tags found
No related merge requests found
Pipeline #1543 passed
......@@ -5,6 +5,7 @@ import {
PixelFormat,
RomInfo
} from "./react/app";
import { PALETTES } from "./palettes";
import {
Cartridge,
......@@ -23,25 +24,6 @@ const IDLE_HZ = 10;
const SAMPLE_RATE = 2;
const PALETTES = [
{
name: "basic",
colors: ["ffffff", "c0c0c0", "606060", "000000"]
},
{
name: "hogwards",
colors: ["b6a571", "8b7e56", "554d35", "201d13"]
},
{
name: "pacman",
colors: ["ffff00", "ffb897", "3732ff", "000000"]
},
{
name: "mariobros",
colors: ["f7cec3", "cc9e22", "923404", "000000"]
}
];
const KEYS_NAME: Record<string, number> = {
ArrowUp: PadKey.Up,
ArrowDown: PadKey.Down,
......@@ -296,8 +278,10 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
break;
}
// runs the initial palette set operation
this.changePalette();
// runs the initial palette set operation, restoring
// the palette of the emulator according to the currently
// selected one
this.setPalette();
// resets the Game Boy engine to restore it into
// a valid state ready to be used
......@@ -474,10 +458,9 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
}
changePalette() {
const palette = PALETTES[this.paletteIndex];
this.gameBoy?.set_palette_colors_ws(palette.colors);
this.paletteIndex += 1;
this.paletteIndex %= PALETTES.length;
this.setPalette();
}
benchmark(count = 50000000) {
......@@ -501,6 +484,12 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
}
}
private setPalette(index?: number) {
index ??= this.paletteIndex;
const palette = PALETTES[index];
this.gameBoy?.set_palette_colors_ws(palette.colors);
}
private async fetchRom(
romPath: string
): Promise<{ name: string; data: Uint8Array }> {
......
export const PALETTES = [
{
name: "basic",
colors: ["ffffff", "c0c0c0", "606060", "000000"]
},
{
name: "hogwards",
colors: ["b6a571", "8b7e56", "554d35", "201d13"]
},
{
name: "christmas",
colors: ["e8e7df", "8bab95", "9e5c5e", "534d57"]
},
{
name: "goldsilver",
colors: ["c5c66d", "97a1b0", "585e67", "232529"]
},
{
name: "pacman",
colors: ["ffff00", "ffb897", "3732ff", "000000"]
},
{
name: "mariobros",
colors: ["f7cec3", "cc9e22", "923404", "000000"]
},
{
name: "pokemon",
colors: ["f87800", "b86000", "783800", "000000"]
}
];
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment