-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate emulator settings to IndexedDB and reorganize UI scripts
- Loading branch information
1 parent
931c41f
commit 73917b7
Showing
19 changed files
with
381 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum Order { | ||
NEXT = 'next', | ||
PREV = 'prev' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Chip8Quirks } from './chip8.constants'; | ||
|
||
export enum GeneralEmulatorSettings { | ||
FONT_APPEARANCE = 'fontAppearance', | ||
CYCLES_PER_FRAME = 'cyclesPerFrame', | ||
SOUND_STATE = 'soundState', | ||
GAIN_LEVEL = 'gainLevel', | ||
MEMORY_SIZE = 'memorySize', | ||
} | ||
|
||
export type EmulatorSettings = GeneralEmulatorSettings | Chip8Quirks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { database } from '../../constants/emulator.constants'; | ||
import { EmulatorSettings } from '../../constants/settings.constants'; | ||
import { SettingsObject } from '../../types/settings'; | ||
import { DatabaseTool } from '../database'; | ||
|
||
class SettingsManager { | ||
private databaseTool: DatabaseTool<SettingsObject<unknown>>; | ||
|
||
private settingsStorageName = database.storage_name.settings; | ||
|
||
constructor() { | ||
this.databaseTool = new DatabaseTool<SettingsObject<unknown>>( | ||
database.name, | ||
database.current_version, | ||
); | ||
} | ||
|
||
public async initializeManager(): Promise<void> { | ||
await this.databaseTool.openDatabase(); | ||
} | ||
|
||
public async setSetting<T = string>(settingName: EmulatorSettings, value: T): Promise<void> { | ||
const indexedDBValue: SettingsObject<T> = { | ||
id: settingName, | ||
value, | ||
}; | ||
|
||
await this.databaseTool.putObjectInDatabase( | ||
this.settingsStorageName, | ||
settingName, | ||
indexedDBValue, | ||
); | ||
} | ||
|
||
public async getSetting<T = string>(settingName: EmulatorSettings): Promise<T | undefined> { | ||
const result = await this.databaseTool.getObjectFromDatabase( | ||
this.settingsStorageName, | ||
settingName, | ||
); | ||
|
||
if (!result) return undefined; | ||
|
||
return result.value as T; | ||
} | ||
} | ||
|
||
export default new SettingsManager(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.