Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Aug 16, 2024
1 parent d5e7091 commit 058aa39
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/app/services/settings.service.ts
Original file line number Diff line number Diff line change
@@ -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<Record<string, ModSettings>>({});

constructor() {
const settings =
(this.localStorage.retrieve('settings') as Record<string, ModSettings>) ??
{};
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,
},
}));
}
}

0 comments on commit 058aa39

Please sign in to comment.