diff --git a/server/host.py b/server/host.py index 97d1251..2da1ba8 100644 --- a/server/host.py +++ b/server/host.py @@ -62,7 +62,7 @@ async def get_puzzle(id: str): tf = data / f"{id}.json" if not tf.exists(): return {"error": "Puzzle not found"} - return tf.read_text() + return json.loads(tf.read_text()) # Getting / redirects to main page diff --git a/src/App.svelte b/src/App.svelte index 1572051..0989dc0 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -9,10 +9,9 @@ const params = new URLSearchParams(location.search) // Can pass in puzzle data from props - interface Props { puzzleData?: { id: string, rows: number, cols: number, - numbers: i8s, nMask: i8s, hColors: i8s, vColors: i8s, colors: string[] } } - export let { puzzleData }: Props = {} - const pid = puzzleData?.id ?? 'slitherlink' + interface Props { puzzleId?: string, puzzleData?: Checkpoint } + export let { puzzleId, puzzleData }: Props = {} + const pid = puzzleId ?? 'slitherlink' // Main variables const [rows, cols] = [+(puzzleData?.rows ?? params.get('size') ?? 40), +(puzzleData?.cols ?? params.get('size') ?? 40)] diff --git a/src/utils.ts b/src/utils.ts index 2420fe4..86043fb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,11 +1,13 @@ export type i8s = Int8Array -export interface Checkpoint { hStates: i8s, vStates: i8s, hColors: i8s, vColors: i8s, numbers: i8s, nMask: i8s, colors: string[] } +export interface Checkpoint { rows: number, cols: number, + hStates: i8s, vStates: i8s, hColors: i8s, vColors: i8s, numbers: i8s, nMask: i8s, colors: string[] } export const cfg = { cellW: 20, lineW: 4, - totalW: 24 + totalW: 24, + backend: "https://slither0.hydev.org", } export const eStates = { @@ -67,3 +69,8 @@ export const Fmt = { return `${d ? `${d}d ` : ''}${h ? `${h}:` : ''}${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}` } } + +export const Backend = { + get: (id: string) => fetch(`${cfg.backend}/${id}`).then(r => r.text()).then(JsonTy.parse), + post: (data: Checkpoint) => fetch(`${cfg.backend}/`, { method: "post", body: JsonTy.stringify(data) }), +}