23 lines
536 B
TypeScript
23 lines
536 B
TypeScript
import { Player } from "@/types/player";
|
|
import { PREF } from "./const";
|
|
|
|
export const MIN_PLAYERS = 2;
|
|
export const MAX_PLAYERS = 8;
|
|
|
|
export function setPlayers(players: Player[]) {
|
|
localStorage.setItem(PREF.players, JSON.stringify(players));
|
|
window.dispatchEvent(new Event('storage'));
|
|
}
|
|
|
|
export function getPlayers(): Player[] {
|
|
const players = localStorage.getItem(PREF.players);
|
|
if (players === null) {
|
|
return [];
|
|
}
|
|
try {
|
|
return JSON.parse(players);
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|