[+] Backend sdk
This commit is contained in:
+1
-1
@@ -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
@@ -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
@@ -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) }),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user