diff --git a/CHANGELOG.md b/CHANGELOG.md index 48e8e1dbc5de21c298564626151466336165c794..c0a3446c7a3d32373cb90b288a6070e06ea2f80c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Support for theme and palette selection +* Theme stored in `localStorage` ### Changed diff --git a/frontends/web/index.ts b/frontends/web/index.ts index aaddcffc4d7e57279db83f689fc1c802b1b544df..560d43e9424be72ac4b43973ccf29fbc8a637d00 100644 --- a/frontends/web/index.ts +++ b/frontends/web/index.ts @@ -40,7 +40,7 @@ const BACKGROUNDS = [ // creates the emulator structure and initializes the // React app with both the parameters and the emulator - const emulator = new GameboyEmulator(); + const emulator = new GameboyEmulator({ background: background }); startApp("app", { emulator: emulator, fullscreen: fullscreen, diff --git a/frontends/web/ts/gb.ts b/frontends/web/ts/gb.ts index e674e5cd13905c78f193872258905464c5b2c968..221fef8d21e2dc14afaa7c67b1799b9fb549047f 100644 --- a/frontends/web/ts/gb.ts +++ b/frontends/web/ts/gb.ts @@ -93,6 +93,18 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { private romSize = 0; private cartridge: Cartridge | null = null; + /** + * Associative map for extra settings to be used in + * opaque local storage operations, associated setting + * name with its value as a string. + */ + private extraSettings: Record<string, string> = {}; + + constructor(extraSettings = {}) { + super(); + this.extraSettings = extraSettings; + } + /** * Runs the initialization and main loop execution for * the Game Boy emulator. @@ -592,6 +604,11 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { } } + onBackground(background: string) { + this.extraSettings.background = background; + this.storeSettings(); + } + /** * Tries to load game RAM from the `localStorage` using the * current cartridge title as the name of the item and @@ -620,7 +637,8 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { private storeSettings() { if (!window.localStorage) return; const settings = { - palette: PALETTES[this.paletteIndex].name + palette: PALETTES[this.paletteIndex].name, + ...this.extraSettings }; localStorage.setItem("settings", JSON.stringify(settings)); }