2020-10-12 16:23:07 +02:00
|
|
|
import {LocalUser} from "./LocalUser";
|
|
|
|
|
2021-01-29 14:42:13 +01:00
|
|
|
const playerNameKey = 'playerName';
|
|
|
|
const selectedPlayerKey = 'selectedPlayer';
|
|
|
|
const customCursorPositionKey = 'customCursorPosition';
|
|
|
|
const characterLayersKey = 'characterLayers';
|
|
|
|
const gameQualityKey = 'gameQuality';
|
|
|
|
const videoQualityKey = 'videoQuality';
|
|
|
|
const audioPlayerVolumeKey = 'audioVolume';
|
|
|
|
const audioPlayerMuteKey = 'audioMute';
|
2020-12-04 11:30:35 +01:00
|
|
|
|
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;
|
|
|
|
}
|
2021-01-29 14:42:13 +01:00
|
|
|
|
2020-10-15 12:05:40 +02:00
|
|
|
setName(name:string): void {
|
2021-01-29 14:42:13 +01:00
|
|
|
localStorage.setItem(playerNameKey, name);
|
2020-10-15 12:05:40 +02:00
|
|
|
}
|
|
|
|
getName(): string {
|
2021-01-29 14:42:13 +01:00
|
|
|
return localStorage.getItem(playerNameKey) || '';
|
2020-10-15 12:05:40 +02:00
|
|
|
}
|
2020-10-20 13:44:57 +02:00
|
|
|
|
|
|
|
setPlayerCharacterIndex(playerCharacterIndex: number): void {
|
2021-01-29 14:42:13 +01:00
|
|
|
localStorage.setItem(selectedPlayerKey, ''+playerCharacterIndex);
|
2020-10-20 13:44:57 +02:00
|
|
|
}
|
|
|
|
getPlayerCharacterIndex(): number {
|
2021-01-29 14:42:13 +01:00
|
|
|
return parseInt(localStorage.getItem(selectedPlayerKey) || '');
|
2020-10-20 13:44:57 +02:00
|
|
|
}
|
|
|
|
|
2020-10-20 17:22:32 +02:00
|
|
|
setCustomCursorPosition(activeRow:number, selectedLayers: number[]): void {
|
2021-01-29 14:42:13 +01:00
|
|
|
localStorage.setItem(customCursorPositionKey, 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 {
|
2021-01-29 14:42:13 +01:00
|
|
|
return JSON.parse(localStorage.getItem(customCursorPositionKey) || "null");
|
2020-10-20 13:44:57 +02:00
|
|
|
}
|
2020-12-04 11:30:35 +01:00
|
|
|
|
|
|
|
setCharacterLayers(layers: string[]): void {
|
2021-01-29 14:42:13 +01:00
|
|
|
localStorage.setItem(characterLayersKey, JSON.stringify(layers));
|
2020-12-04 11:30:35 +01:00
|
|
|
}
|
|
|
|
getCharacterLayers(): string[]|null {
|
2021-01-29 14:42:13 +01:00
|
|
|
return JSON.parse(localStorage.getItem(characterLayersKey) || "null");
|
2020-12-04 11:30:35 +01:00
|
|
|
}
|
2021-01-29 14:42:13 +01:00
|
|
|
|
2020-12-04 11:30:35 +01:00
|
|
|
setGameQualityValue(value: number): void {
|
|
|
|
localStorage.setItem(gameQualityKey, '' + value);
|
|
|
|
}
|
2021-01-29 14:42:13 +01:00
|
|
|
getGameQualityValue(): number {
|
|
|
|
return parseInt(localStorage.getItem(gameQualityKey) || '60');
|
2020-12-04 11:30:35 +01:00
|
|
|
}
|
2021-01-29 14:42:13 +01:00
|
|
|
|
2020-12-04 11:30:35 +01:00
|
|
|
setVideoQualityValue(value: number): void {
|
|
|
|
localStorage.setItem(videoQualityKey, '' + value);
|
|
|
|
}
|
2021-01-29 14:42:13 +01:00
|
|
|
getVideoQualityValue(): number {
|
|
|
|
return parseInt(localStorage.getItem(videoQualityKey) || '20');
|
|
|
|
}
|
|
|
|
|
|
|
|
setAudioPlayerVolume(value: number): void {
|
|
|
|
localStorage.setItem(audioPlayerVolumeKey, '' + value);
|
|
|
|
}
|
|
|
|
getAudioPlayerVolume(): number {
|
|
|
|
return parseFloat(localStorage.getItem(audioPlayerVolumeKey) || '1');
|
|
|
|
}
|
|
|
|
|
|
|
|
setAudioPlayerMuted(value: boolean): void {
|
|
|
|
localStorage.setItem(audioPlayerMuteKey, value.toString());
|
|
|
|
}
|
|
|
|
getAudioPlayerMuted(): boolean {
|
|
|
|
return localStorage.getItem(audioPlayerMuteKey) === 'true';
|
|
|
|
}
|
2020-10-12 16:23:07 +02:00
|
|
|
}
|
|
|
|
|
2021-01-29 14:42:13 +01:00
|
|
|
export const localUserStore = new LocalUserStore();
|