1
0
Fork 0

Get game name from VAR

This commit is contained in:
Pabloader 2026-04-16 13:51:03 +00:00
parent 1fea3e49d2
commit 6a7cfc0dc9
4 changed files with 10 additions and 6 deletions

View File

@ -1,8 +1,10 @@
import { useEffect, useReducer, useState, type Dispatch, type Reducer, type StateUpdater } from "preact/hooks"; import { useEffect, useReducer, useState, type Dispatch, type Reducer, type StateUpdater } from "preact/hooks";
import { loadObject, saveObject } from "@common/storage"; import { loadObject, saveObject } from "@common/storage";
declare const GAME: string;
export const useRemoteState = <T>(key: string, initialValue: T) => { export const useRemoteState = <T>(key: string, initialValue: T) => {
const storedKey = `useRemoteState.${key}`; const storedKey = `useRemoteState.${GAME}.${key}`;
const [value, setValue] = useState<T>(initialValue); const [value, setValue] = useState<T>(initialValue);
@ -33,7 +35,7 @@ const wrapReducer = <T, A>(reducer: Reducer<T, A>): Reducer<T, A | HydrateAction
}; };
export const useRemoteReducer = <T, A>(key: string, reducer: Reducer<T, A>, initialValue: T) => { export const useRemoteReducer = <T, A>(key: string, reducer: Reducer<T, A>, initialValue: T) => {
const storedKey = `useRemoteReducer.${key}`; const storedKey = `useRemoteReducer.${GAME}.${key}`;
const [state, dispatch] = useReducer(wrapReducer(reducer), initialValue); const [state, dispatch] = useReducer(wrapReducer(reducer), initialValue);

View File

@ -1,7 +1,9 @@
import { useEffect, useReducer, useState, type Dispatch, type Reducer, type StateUpdater } from "preact/hooks"; import { useEffect, useReducer, useState, type Dispatch, type Reducer, type StateUpdater } from "preact/hooks";
declare const GAME: string;
export const useStoredState = <T>(key: string, initialValue: T) => { export const useStoredState = <T>(key: string, initialValue: T) => {
const storedKey = `useStoredState.${key}`; const storedKey = `useStoredState.${GAME}.${key}`;
const [value, setValue] = useState<T>(() => { const [value, setValue] = useState<T>(() => {
try { try {
@ -20,7 +22,7 @@ export const useStoredState = <T>(key: string, initialValue: T) => {
}; };
export const useStoredReducer = <T, A>(key: string, reducer: Reducer<T, A>, initialValue: T) => { export const useStoredReducer = <T, A>(key: string, reducer: Reducer<T, A>, initialValue: T) => {
const storedKey = `useStoredReducer.${key}`; const storedKey = `useStoredReducer.${GAME}.${key}`;
const getInitialValue = (): T => { const getInitialValue = (): T => {
try { try {

View File

@ -63,7 +63,7 @@ export const useHordeState = () => useContext(HordeContext);
const POLL_INTERVAL_MS = 30_000; const POLL_INTERVAL_MS = 30_000;
export const HordeStateProvider = ({ children }: { children: preact.ComponentChildren }) => { export const HordeStateProvider = ({ children }: { children: preact.ComponentChildren }) => {
const [state, dispatch] = useStoredReducer('horde.state', reducer, DEFAULT_STATE); const [state, dispatch] = useStoredReducer('state', reducer, DEFAULT_STATE);
const leaderboard = useBool(false); const leaderboard = useBool(false);
const options = useBool(false); const options = useBool(false);

View File

@ -696,7 +696,7 @@ export const useAppState = () => useContext(StateContext);
// ─── Provider ──────────────────────────────────────────────────────────────── // ─── Provider ────────────────────────────────────────────────────────────────
export const StateContextProvider = ({ children }: { children?: any }) => { export const StateContextProvider = ({ children }: { children?: any }) => {
const [state, dispatch] = useStoredReducer('storywriter.state', reducer, DEFAULT_STATE); const [state, dispatch] = useStoredReducer('state', reducer, DEFAULT_STATE);
const value = useMemo<AppState>(() => { const value = useMemo<AppState>(() => {
const currentWorld = state.worlds.find(w => w.id === state.currentWorldId) ?? null; const currentWorld = state.worlds.find(w => w.id === state.currentWorldId) ?? null;