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

refactor: moved palettes out

parent d448185b
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ import { ...@@ -5,6 +5,7 @@ import {
PixelFormat, PixelFormat,
RomInfo RomInfo
} from "./react/app"; } from "./react/app";
import { PALETTES } from "./palettes";
import { import {
Cartridge, Cartridge,
...@@ -23,25 +24,6 @@ const IDLE_HZ = 10; ...@@ -23,25 +24,6 @@ const IDLE_HZ = 10;
const SAMPLE_RATE = 2; 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> = { const KEYS_NAME: Record<string, number> = {
ArrowUp: PadKey.Up, ArrowUp: PadKey.Up,
ArrowDown: PadKey.Down, ArrowDown: PadKey.Down,
...@@ -296,8 +278,10 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { ...@@ -296,8 +278,10 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
break; break;
} }
// runs the initial palette set operation // runs the initial palette set operation, restoring
this.changePalette(); // the palette of the emulator according to the currently
// selected one
this.setPalette();
// resets the Game Boy engine to restore it into // resets the Game Boy engine to restore it into
// a valid state ready to be used // a valid state ready to be used
...@@ -474,10 +458,9 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { ...@@ -474,10 +458,9 @@ export class GameboyEmulator extends EmulatorBase implements Emulator {
} }
changePalette() { changePalette() {
const palette = PALETTES[this.paletteIndex];
this.gameBoy?.set_palette_colors_ws(palette.colors);
this.paletteIndex += 1; this.paletteIndex += 1;
this.paletteIndex %= PALETTES.length; this.paletteIndex %= PALETTES.length;
this.setPalette();
} }
benchmark(count = 50000000) { benchmark(count = 50000000) {
...@@ -501,6 +484,12 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { ...@@ -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( private async fetchRom(
romPath: string romPath: string
): Promise<{ name: string; data: Uint8Array }> { ): 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