FIX: improved the validation from localstorage for username and characterLayers
This commit is contained in:
parent
575c1a9f23
commit
8e467f3e10
8 changed files with 84 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
|||
import {LocalUser} from "./LocalUser";
|
||||
import {areCharacterLayersValid, isUserNameValid, LocalUser} from "./LocalUser";
|
||||
|
||||
const playerNameKey = 'playerName';
|
||||
const selectedPlayerKey = 'selectedPlayer';
|
||||
|
@ -22,8 +22,9 @@ class LocalUserStore {
|
|||
setName(name:string): void {
|
||||
localStorage.setItem(playerNameKey, name);
|
||||
}
|
||||
getName(): string {
|
||||
return localStorage.getItem(playerNameKey) || '';
|
||||
getName(): string|null {
|
||||
const value = localStorage.getItem(playerNameKey) || '';
|
||||
return isUserNameValid(value) ? value : null;
|
||||
}
|
||||
|
||||
setPlayerCharacterIndex(playerCharacterIndex: number): void {
|
||||
|
@ -44,7 +45,8 @@ class LocalUserStore {
|
|||
localStorage.setItem(characterLayersKey, JSON.stringify(layers));
|
||||
}
|
||||
getCharacterLayers(): string[]|null {
|
||||
return JSON.parse(localStorage.getItem(characterLayersKey) || "null");
|
||||
const value = JSON.parse(localStorage.getItem(characterLayersKey) || "null");
|
||||
return areCharacterLayersValid(value) ? value : null;
|
||||
}
|
||||
|
||||
setGameQualityValue(value: number): void {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue