[+] Backend sdk

This commit is contained in:
2024-12-17 00:26:41 -05:00
parent b01a4446ef
commit 058e6675a3
3 changed files with 13 additions and 7 deletions
+1 -1
View File
@@ -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
+3 -4
View File
@@ -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)]
+9 -2
View File
@@ -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) }),
}