From 058aa39d309f59ff79c89d2196125942155fb29f Mon Sep 17 00:00:00 2001 From: Kyle Kemp Date: Fri, 16 Aug 2024 07:20:09 -0500 Subject: [PATCH] fix build --- src/app/services/settings.service.ts | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/app/services/settings.service.ts diff --git a/src/app/services/settings.service.ts b/src/app/services/settings.service.ts new file mode 100644 index 0000000..e5b5785 --- /dev/null +++ b/src/app/services/settings.service.ts @@ -0,0 +1,54 @@ +import { effect, inject, Injectable, signal } from '@angular/core'; +import { LocalStorageService } from 'ngx-webstorage'; + +export interface ModSettings { + autosaveFilePath: string; +} + +const defaultSettings: () => ModSettings = () => ({ + autosaveFilePath: '', +}); + +@Injectable({ + providedIn: 'root', +}) +export class SettingsService { + private localStorage = inject(LocalStorageService); + + public allSettings = signal>({}); + + constructor() { + const settings = + (this.localStorage.retrieve('settings') as Record) ?? + {}; + this.allSettings.set(settings); + + effect(() => { + const settings = this.allSettings(); + this.localStorage.store('settings', settings); + }); + } + + public createSettingsForMod(modId: string) { + if (this.allSettings()[modId]) return; + + this.allSettings.update((settings) => ({ + ...settings, + [modId]: defaultSettings(), + })); + } + + public setSettingForMod( + modId: string, + setting: keyof ModSettings, + value: any + ) { + this.allSettings.update((settings) => ({ + ...settings, + [modId]: { + ...settings[modId], + [setting]: value, + }, + })); + } +}