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

feat: support for background and extra settings

Theme stored in `localStorage`
parent 90b1bf28
No related branches found
No related tags found
No related merge requests found
Pipeline #1817 passed
......@@ -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
......
......@@ -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,
......
......@@ -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));
}
......
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