2020-10-12 16:23:07 +02:00
|
|
|
import {LocalUser} from "./LocalUser";
|
|
|
|
|
2020-12-04 11:30:35 +01:00
|
|
|
const characterLayersKey = 'characterLayers';
|
|
|
|
const gameQualityKey = 'gameQuality';
|
|
|
|
const videoQualityKey = 'videoQuality';
|
|
|
|
|
2020-10-15 12:05:40 +02:00
|
|
|
//todo: add localstorage fallback
|
2020-10-12 16:23:07 +02:00
|
|
|
class LocalUserStore {
|
|
|
|
|
|
|
|
saveUser(localUser: LocalUser) {
|
|
|
|
localStorage.setItem('localUser', JSON.stringify(localUser));
|
|
|
|
}
|
|
|
|
getLocalUser(): LocalUser|null {
|
|
|
|
const data = localStorage.getItem('localUser');
|
|
|
|
return data ? JSON.parse(data) : null;
|
|
|
|
}
|
2020-10-15 12:05:40 +02:00
|
|
|
|
|
|
|
setName(name:string): void {
|
|
|
|
window.localStorage.setItem('playerName', name);
|
|
|
|
}
|
|
|
|
getName(): string {
|
|
|
|
return window.localStorage.getItem('playerName') ?? '';
|
|
|
|
}
|
2020-10-20 13:44:57 +02:00
|
|
|
|
|
|
|
setPlayerCharacterIndex(playerCharacterIndex: number): void {
|
|
|
|
window.localStorage.setItem('selectedPlayer', ''+playerCharacterIndex);
|
|
|
|
}
|
|
|
|
getPlayerCharacterIndex(): number {
|
|
|
|
return parseInt(window.localStorage.getItem('selectedPlayer') || '');
|
|
|
|
}
|
|
|
|
|
2020-10-20 17:22:32 +02:00
|
|
|
setCustomCursorPosition(activeRow:number, selectedLayers: number[]): void {
|
|
|
|
window.localStorage.setItem('customCursorPosition', JSON.stringify({activeRow, selectedLayers}));
|
2020-10-20 13:44:57 +02:00
|
|
|
}
|
2020-10-20 17:22:32 +02:00
|
|
|
getCustomCursorPosition(): {activeRow:number, selectedLayers:number[]}|null {
|
2020-10-20 13:44:57 +02:00
|
|
|
return JSON.parse(window.localStorage.getItem('customCursorPosition') || "null");
|
|
|
|
}
|
2020-12-04 11:30:35 +01:00
|
|
|
|
|
|
|
setCharacterLayers(layers: string[]): void {
|
|
|
|
window.localStorage.setItem(characterLayersKey, JSON.stringify(layers));
|
|
|
|
}
|
|
|
|
getCharacterLayers(): string[]|null {
|
|
|
|
return JSON.parse(window.localStorage.getItem(characterLayersKey) || "null");
|
|
|
|
}
|
|
|
|
|
|
|
|
getGameQualityValue(): number {
|
|
|
|
return parseInt(window.localStorage.getItem(gameQualityKey) || '') || 60;
|
|
|
|
}
|
|
|
|
setGameQualityValue(value: number): void {
|
|
|
|
localStorage.setItem(gameQualityKey, '' + value);
|
|
|
|
}
|
|
|
|
|
|
|
|
getVideoQualityValue(): number {
|
|
|
|
return parseInt(window.localStorage.getItem(videoQualityKey) || '') || 20;
|
|
|
|
}
|
|
|
|
setVideoQualityValue(value: number): void {
|
|
|
|
localStorage.setItem(videoQualityKey, '' + value);
|
|
|
|
}
|
2020-10-12 16:23:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const localUserStore = new LocalUserStore();
|