@puzzmo/cli 1.0.66 → 1.0.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/download/page-downloader.js +24 -8
- package/lib/download/page-downloader.js.map +1 -1
- package/package.json +1 -1
- package/schemas/puzzmo-file-schema.json +81 -0
- package/src/download/page-downloader.ts +33 -9
- package/templates/minesweeper/package.json +2 -2
- package/templates/minesweeper/src/appBundle.tsx +147 -0
- package/templates/minesweeper/tsconfig.json +4 -1
- package/templates/minesweeper/src/appBundle.ts +0 -123
|
@@ -2,14 +2,25 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import https from "node:https";
|
|
4
4
|
import http from "node:http";
|
|
5
|
-
/**
|
|
6
|
-
const
|
|
5
|
+
/** Browser UA, as some hosts refuse requests without one */
|
|
6
|
+
const userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
|
7
|
+
/** Fetch that tolerates expired/self-signed SSL certificates, and follows redirects */
|
|
8
|
+
const fetchPage = async (url, redirectsLeft = 5) => {
|
|
7
9
|
const parsed = new URL(url);
|
|
8
10
|
const isHttps = parsed.protocol === "https:";
|
|
9
11
|
return new Promise((resolve, reject) => {
|
|
10
12
|
const mod = isHttps ? https : http;
|
|
11
|
-
const opts =
|
|
13
|
+
const opts = {
|
|
14
|
+
headers: { "user-agent": userAgent, accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" },
|
|
15
|
+
...(isHttps ? { rejectUnauthorized: false } : {}),
|
|
16
|
+
};
|
|
12
17
|
const req = mod.get(url, opts, (res) => {
|
|
18
|
+
const status = res.statusCode ?? 0;
|
|
19
|
+
if (status >= 300 && status < 400 && res.headers.location && redirectsLeft > 0) {
|
|
20
|
+
res.resume();
|
|
21
|
+
resolve(fetchPage(new URL(res.headers.location, url).href, redirectsLeft - 1));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
13
24
|
const chunks = [];
|
|
14
25
|
res.on("data", (chunk) => chunks.push(chunk));
|
|
15
26
|
res.on("end", () => {
|
|
@@ -18,8 +29,9 @@ const fetchPage = async (url) => {
|
|
|
18
29
|
const view = new Uint8Array(ab);
|
|
19
30
|
view.set(buffer);
|
|
20
31
|
resolve({
|
|
21
|
-
ok:
|
|
22
|
-
status
|
|
32
|
+
ok: status >= 200 && status < 300,
|
|
33
|
+
status,
|
|
34
|
+
contentType: res.headers["content-type"] ?? "",
|
|
23
35
|
text: async () => buffer.toString("utf-8"),
|
|
24
36
|
arrayBuffer: async () => ab,
|
|
25
37
|
});
|
|
@@ -74,11 +86,15 @@ const downloadAsset = async (ref, baseURL, srcDir, downloaded, content, optional
|
|
|
74
86
|
export const downloadPage = async (url, outputDir) => {
|
|
75
87
|
const srcDir = path.join(outputDir, "src");
|
|
76
88
|
fs.mkdirSync(srcDir, { recursive: true });
|
|
77
|
-
// Download the HTML
|
|
89
|
+
// Download the HTML. SPA hosts (e.g. static buckets) serve the app shell with a 404
|
|
90
|
+
// for client-side routes, which browsers render fine — so trust the body over the status.
|
|
78
91
|
const response = await fetchPage(url);
|
|
79
|
-
if (!response.ok)
|
|
80
|
-
throw new Error(`Failed to fetch ${url}: ${response.status}`);
|
|
81
92
|
let html = await response.text();
|
|
93
|
+
const servedHTML = response.contentType.includes("text/html") && html.trim().length > 0;
|
|
94
|
+
if (!response.ok && !servedHTML)
|
|
95
|
+
throw new Error(`Failed to fetch ${url}: ${response.status}`);
|
|
96
|
+
if (!response.ok)
|
|
97
|
+
console.warn(` Warning: ${url} returned ${response.status}, using the HTML it served anyway`);
|
|
82
98
|
const baseURL = new URL(url);
|
|
83
99
|
const downloaded = new Set();
|
|
84
100
|
const assetContent = new Map();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-downloader.js","sourceRoot":"","sources":["../../src/download/page-downloader.ts"],"names":[],"mappings":"AAAA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,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC/C,IAAI,KAAK,CAAC,CAAC,CAAC;YAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACnC,CAAC;IAED,oBAAoB;IACpB,MAAM,QAAQ,GAAG,8BAA8B,CAAA;IAC/C,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC9C,IAAI,KAAK,CAAC,CAAC,CAAC;YAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACnC,CAAC;IAED,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;AAAA,CAC1B,CAAA;AAED,wEAAwE;AACxE,MAAM,eAAe,GAAG,gEAAgE,CAAA;AAExF,6EAA6E;AAC7E,MAAM,oBAAoB,GAAG,CAAC,MAAc,EAAY,EAAE,CAAC;IACzD,MAAM,IAAI,GAAa,EAAE,CAAA;IAEzB,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,4BAA4B,eAAe,6BAA6B,EAAE,IAAI,CAAC,CAAA;IACxG,IAAI,KAAK,CAAA;IACT,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC7C,IAAI,KAAK,CAAC,CAAC,CAAC;YAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACnC,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;AAAA,CAC1B,CAAA"}
|
package/package.json
CHANGED
|
@@ -215,6 +215,13 @@
|
|
|
215
215
|
},
|
|
216
216
|
"description": "Awards notables (achievements/badges) to users when conditions are met at game completion. When a notable is awarded, it appears on the user's profile and creates a social news item.\n\nThe `valueExp` is evaluated against the game's deed scope. If it returns truthy, the notable is awarded. Expression scope includes all deed values from the gameplay (camelCase keys).\n\nTwo types of notables:\n\n1. **Code-based notables**: Use `notableName` (e.g. \"jokinAround\") with `notableIndex` (0 or 1). These reference predefined notables in UserAwardsBitmapKeys (index 0) or UserAwardsBitmap1Keys (index 1). **Restricted to games owned by the Puzzmo team.** 2. **System notables**: Use `notableName` as \"{index}-{bitmapValue}\" format (e.g. \"2-4\"). These reference dynamic notables stored in the SystemNotable database table. Available to all games.\n\nExample: Award a notable when player scores over 100 points\n\n```json { \"completionNotables\": [ { \"valueExp\": \"score > 100\", \"notableIndex\": 0, \"notableName\": \"jokinAround\" }, { \"valueExp\": \"perfect === true\", \"notableName\": \"2-4\" } ] } ```"
|
|
217
217
|
},
|
|
218
|
+
"checklists": {
|
|
219
|
+
"type": "array",
|
|
220
|
+
"items": {
|
|
221
|
+
"$ref": "#/definitions/ChecklistAugmentation"
|
|
222
|
+
},
|
|
223
|
+
"description": "In-game checklists shown to the user. The `type` discriminator distinguishes between different kinds; today only `tutorial` is consumed by the runtime.\n\nTutorial checklists are an ordered sequence of steps: the player is always shown the first step they have not finished, and how far they got is remembered across sessions so an abandoned tutorial resumes rather than restarting. Once it is finished — or once the player has completed the game's daily at least once — the tutorial stops being shown.\n\nChecklists merge by `stableID` across sources (gameVersion, remix, puzzle frontmatter) with last-write-wins, so a remix or puzzle can override a game-level tutorial without duplicating the entry."
|
|
224
|
+
},
|
|
218
225
|
"forceGameSettings": {
|
|
219
226
|
"type": "object",
|
|
220
227
|
"description": "Forces specific game settings for this puzzle, overriding user preferences. Only applies when set via puzzle front-matter (not from game-level augmentations).\n\nWhen a puzzle has forced settings, those settings are locked in the UI and displayed as read-only with a note that the setting is specific to this puzzle. Users cannot change forced settings.\n\nThe settings object keys/values are game-specific. To find valid settings for a game, set the setting yourself in the game and check your user profile in the admin to see the stored format.\n\nExample: Force monochrome grid mode for a crossword puzzle\n\n```json { \"forceGameSettings\": { \"monoGrid\": true } } ```"
|
|
@@ -349,6 +356,80 @@
|
|
|
349
356
|
"required": ["displayName", "formatString"],
|
|
350
357
|
"additionalProperties": false,
|
|
351
358
|
"description": "Data given by either via a puzzle in front-matter, or a game in completion. A general unit of data which can be used to represent a lot of configuration points from the game to the API."
|
|
359
|
+
},
|
|
360
|
+
"ChecklistAugmentation": {
|
|
361
|
+
"type": "object",
|
|
362
|
+
"properties": {
|
|
363
|
+
"stableID": {
|
|
364
|
+
"type": "string",
|
|
365
|
+
"description": "Stable identifier used to de-dupe the checklist",
|
|
366
|
+
"examples": ["[gameslug]:tutorial"]
|
|
367
|
+
},
|
|
368
|
+
"type": {
|
|
369
|
+
"type": "string",
|
|
370
|
+
"const": "tutorial",
|
|
371
|
+
"description": "The kind of checklist. Currently only `tutorial` is available"
|
|
372
|
+
},
|
|
373
|
+
"title": {
|
|
374
|
+
"type": "string",
|
|
375
|
+
"description": "Display title shown above the checklist.",
|
|
376
|
+
"examples": ["Poker Hands"]
|
|
377
|
+
},
|
|
378
|
+
"instructionsVisibleFromItemIndex": {
|
|
379
|
+
"type": "number",
|
|
380
|
+
"description": "How many steps the player must finish before the help/instructions become visible; before that point they are gated to the tutorial steps. Omit to make the instructions available from the start.",
|
|
381
|
+
"examples": [2]
|
|
382
|
+
},
|
|
383
|
+
"items": {
|
|
384
|
+
"type": "array",
|
|
385
|
+
"items": {
|
|
386
|
+
"$ref": "#/definitions/ChecklistAugmentationItem"
|
|
387
|
+
},
|
|
388
|
+
"description": "The individual steps, in the order the player works through them."
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
"required": ["stableID", "type", "items"],
|
|
392
|
+
"additionalProperties": false
|
|
393
|
+
},
|
|
394
|
+
"ChecklistAugmentationItem": {
|
|
395
|
+
"type": "object",
|
|
396
|
+
"properties": {
|
|
397
|
+
"title": {
|
|
398
|
+
"type": "string",
|
|
399
|
+
"description": "The item's headline in the tutorial UI; when omitted nothing is shown.",
|
|
400
|
+
"examples": ["Easy"]
|
|
401
|
+
},
|
|
402
|
+
"subtitle": {
|
|
403
|
+
"type": "string",
|
|
404
|
+
"description": "Supporting line rendered under the title.",
|
|
405
|
+
"examples": ["Open the Poker Hand reference"]
|
|
406
|
+
},
|
|
407
|
+
"expandMD": {
|
|
408
|
+
"type": "string",
|
|
409
|
+
"description": "The body revealed when the item is expanded, as markdown.",
|
|
410
|
+
"examples": ["Tap the button on the lower left side of the screen with the book icon on it"]
|
|
411
|
+
},
|
|
412
|
+
"targetCount": {
|
|
413
|
+
"type": "number",
|
|
414
|
+
"description": "Target count to mark this item complete (uses `incrementExp` as an expression to determine the count from deeds sent via a checkpoint).",
|
|
415
|
+
"examples": [2]
|
|
416
|
+
},
|
|
417
|
+
"incrementExp": {
|
|
418
|
+
"type": "string",
|
|
419
|
+
"description": "Expression evaluated against the deed scope; the result is added to `count`.",
|
|
420
|
+
"examples": ["threeOfAKindCount", "flushCount >= 3"]
|
|
421
|
+
},
|
|
422
|
+
"filterExp": {
|
|
423
|
+
"type": "string",
|
|
424
|
+
"description": "Optional gate expression — when falsy, the item is skipped for evaluation.",
|
|
425
|
+
"examples": ["excessMoves === 0"]
|
|
426
|
+
},
|
|
427
|
+
"liveUpdate": {
|
|
428
|
+
"type": "boolean",
|
|
429
|
+
"description": "When true, the item updates during checkpoints, not only at completion."
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
"additionalProperties": false
|
|
352
433
|
}
|
|
353
434
|
}
|
|
354
435
|
}
|
|
@@ -3,18 +3,38 @@ import path from "node:path"
|
|
|
3
3
|
import https from "node:https"
|
|
4
4
|
import http from "node:http"
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/** Browser UA, as some hosts refuse requests without one */
|
|
7
|
+
const userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
|
8
|
+
|
|
9
|
+
type FetchResult = {
|
|
10
|
+
ok: boolean
|
|
11
|
+
status: number
|
|
12
|
+
contentType: string
|
|
13
|
+
text: () => Promise<string>
|
|
14
|
+
arrayBuffer: () => Promise<ArrayBuffer>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Fetch that tolerates expired/self-signed SSL certificates, and follows redirects */
|
|
18
|
+
const fetchPage = async (url: string, redirectsLeft = 5): Promise<FetchResult> => {
|
|
10
19
|
const parsed = new URL(url)
|
|
11
20
|
const isHttps = parsed.protocol === "https:"
|
|
12
21
|
|
|
13
22
|
return new Promise((resolve, reject) => {
|
|
14
23
|
const mod = isHttps ? https : http
|
|
15
|
-
const opts =
|
|
24
|
+
const opts = {
|
|
25
|
+
headers: { "user-agent": userAgent, accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" },
|
|
26
|
+
...(isHttps ? { rejectUnauthorized: false } : {}),
|
|
27
|
+
}
|
|
16
28
|
|
|
17
29
|
const req = mod.get(url, opts, (res) => {
|
|
30
|
+
const status = res.statusCode ?? 0
|
|
31
|
+
|
|
32
|
+
if (status >= 300 && status < 400 && res.headers.location && redirectsLeft > 0) {
|
|
33
|
+
res.resume()
|
|
34
|
+
resolve(fetchPage(new URL(res.headers.location, url).href, redirectsLeft - 1))
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
18
38
|
const chunks: Uint8Array[] = []
|
|
19
39
|
res.on("data", (chunk: Uint8Array) => chunks.push(chunk))
|
|
20
40
|
res.on("end", () => {
|
|
@@ -23,8 +43,9 @@ const fetchPage = async (
|
|
|
23
43
|
const view = new Uint8Array(ab)
|
|
24
44
|
view.set(buffer)
|
|
25
45
|
resolve({
|
|
26
|
-
ok:
|
|
27
|
-
status
|
|
46
|
+
ok: status >= 200 && status < 300,
|
|
47
|
+
status,
|
|
48
|
+
contentType: res.headers["content-type"] ?? "",
|
|
28
49
|
text: async () => buffer.toString("utf-8"),
|
|
29
50
|
arrayBuffer: async () => ab,
|
|
30
51
|
})
|
|
@@ -90,10 +111,13 @@ export const downloadPage = async (url: string, outputDir: string): Promise<{ ti
|
|
|
90
111
|
const srcDir = path.join(outputDir, "src")
|
|
91
112
|
fs.mkdirSync(srcDir, { recursive: true })
|
|
92
113
|
|
|
93
|
-
// Download the HTML
|
|
114
|
+
// Download the HTML. SPA hosts (e.g. static buckets) serve the app shell with a 404
|
|
115
|
+
// for client-side routes, which browsers render fine — so trust the body over the status.
|
|
94
116
|
const response = await fetchPage(url)
|
|
95
|
-
if (!response.ok) throw new Error(`Failed to fetch ${url}: ${response.status}`)
|
|
96
117
|
let html = await response.text()
|
|
118
|
+
const servedHTML = response.contentType.includes("text/html") && html.trim().length > 0
|
|
119
|
+
if (!response.ok && !servedHTML) throw new Error(`Failed to fetch ${url}: ${response.status}`)
|
|
120
|
+
if (!response.ok) console.warn(` Warning: ${url} returned ${response.status}, using the HTML it served anyway`)
|
|
97
121
|
|
|
98
122
|
const baseURL = new URL(url)
|
|
99
123
|
const downloaded = new Set<string>()
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { AppBundle, ThumbnailConfig } from "@puzzmo/sdk"
|
|
2
|
+
import { svgFontFaceCSSRaw } from "@puzzmo/sdk/fonts"
|
|
3
|
+
import { createEncoder, defineSchema } from "@puzzmo/sdk/inputs"
|
|
4
|
+
import { h, render } from "@puzzmo/sdk/svgJSX"
|
|
5
|
+
|
|
6
|
+
type Puzzle = { rows: number; cols: number; mines: [number, number][] }
|
|
7
|
+
type State = { revealed: boolean[]; flagged: boolean[] }
|
|
8
|
+
|
|
9
|
+
/** Mirrors the schema in src/main.ts so a saved input string round-trips here too. */
|
|
10
|
+
const stateSchema = defineSchema<State>({
|
|
11
|
+
version: 1,
|
|
12
|
+
fields: {
|
|
13
|
+
revealed: { type: "bitArray" },
|
|
14
|
+
flagged: { type: "bitArray" },
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Renders a small SVG preview of the puzzle plus its pixel dimensions, so the host can size
|
|
20
|
+
* the thumbnail without parsing the SVG. When an `inputStr` is supplied the preview reflects
|
|
21
|
+
* the player's progress; otherwise it shows a blank board.
|
|
22
|
+
*
|
|
23
|
+
* The host renders this in lists/share cards/completion screens — there's no animation and no
|
|
24
|
+
* theme variables, so colors are baked from `config.theme` directly.
|
|
25
|
+
*
|
|
26
|
+
* The JSX here is not React: tsconfig sets `jsxFactory` to `h`, so it compiles to the SDK's
|
|
27
|
+
* svgJSX and `render` turns the result into SVG DOM to serialize. A thumbnail bundle has to stay
|
|
28
|
+
* React-free — the server renders it against a minimal SVG DOM with no React in it. `h` is
|
|
29
|
+
* imported for the compiler's benefit rather than this file's; a classic factory has to be in
|
|
30
|
+
* scope. Attribute names are SVG's or React's as you please: camelCase is kebab-cased on the way
|
|
31
|
+
* out, bar the few SVG spells that way itself (`viewBox`, `preserveAspectRatio`).
|
|
32
|
+
*/
|
|
33
|
+
export const renderThumbnail: AppBundle["renderThumbnail"] = (puzzleStr: string, inputStr?: string, config?: ThumbnailConfig) => {
|
|
34
|
+
const puzzle = JSON.parse(puzzleStr) as Puzzle
|
|
35
|
+
const { rows, cols } = puzzle
|
|
36
|
+
const cells = rows * cols
|
|
37
|
+
const mineSet = new Set(puzzle.mines.map(([r, c]) => r * cols + c))
|
|
38
|
+
|
|
39
|
+
let revealed: boolean[] = new Array(cells).fill(false)
|
|
40
|
+
let flagged: boolean[] = new Array(cells).fill(false)
|
|
41
|
+
|
|
42
|
+
if (inputStr) {
|
|
43
|
+
try {
|
|
44
|
+
const codec = createEncoder(stateSchema, { revealed: { length: cells }, flagged: { length: cells } })
|
|
45
|
+
const decoded = codec.decode(codec.migrate(inputStr))
|
|
46
|
+
revealed = decoded.revealed
|
|
47
|
+
flagged = decoded.flagged
|
|
48
|
+
} catch {
|
|
49
|
+
// Bad/old state: fall back to a blank thumbnail.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const theme = config?.theme
|
|
54
|
+
const bg = theme?.a_bg ?? "#1a1a1a"
|
|
55
|
+
const cellHidden = theme?.g_unsolved ?? "#3a3a3a"
|
|
56
|
+
const cellShown = theme?.g_bg ?? "#1f1f1f"
|
|
57
|
+
const border = theme?.g_outline ?? "#4a4a4a"
|
|
58
|
+
const mineColor = theme?.error ?? "#ff5555"
|
|
59
|
+
const flagColor = theme?.subBrand ?? "#ffaa55"
|
|
60
|
+
const numberColor = theme?.g_textDark ?? "#1b1b28"
|
|
61
|
+
|
|
62
|
+
const size = 200
|
|
63
|
+
const pad = 4
|
|
64
|
+
const gap = 1
|
|
65
|
+
const cellW = (size - pad * 2 - gap * (cols - 1)) / cols
|
|
66
|
+
const cellH = (size - pad * 2 - gap * (rows - 1)) / rows
|
|
67
|
+
const glyphSize = Math.min(cellW, cellH) * 0.7
|
|
68
|
+
|
|
69
|
+
const board = Array.from({ length: cells }, (_, i) => {
|
|
70
|
+
const x = pad + (i % cols) * (cellW + gap)
|
|
71
|
+
const y = pad + Math.floor(i / cols) * (cellH + gap)
|
|
72
|
+
const isRevealed = revealed[i]
|
|
73
|
+
const isMine = mineSet.has(i)
|
|
74
|
+
// A glyph sits low in the cell so its baseline lands near the middle.
|
|
75
|
+
const cx = x + cellW / 2
|
|
76
|
+
const cy = y + cellH / 2 + cellH * 0.32
|
|
77
|
+
const adjacent = isRevealed && !isMine ? countAdjacent(mineSet, i, rows, cols) : 0
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<g>
|
|
81
|
+
<rect
|
|
82
|
+
x={x.toFixed(2)}
|
|
83
|
+
y={y.toFixed(2)}
|
|
84
|
+
width={cellW.toFixed(2)}
|
|
85
|
+
height={cellH.toFixed(2)}
|
|
86
|
+
fill={isRevealed ? cellShown : cellHidden}
|
|
87
|
+
stroke={border}
|
|
88
|
+
stroke-width={0.5}
|
|
89
|
+
/>
|
|
90
|
+
{isRevealed && isMine && (
|
|
91
|
+
<circle cx={cx.toFixed(2)} cy={(y + cellH / 2).toFixed(2)} r={(Math.min(cellW, cellH) * 0.25).toFixed(2)} fill={mineColor} />
|
|
92
|
+
)}
|
|
93
|
+
{adjacent > 0 && <Glyph x={cx} y={cy} size={glyphSize} fill={numberColor} weight={700} text={String(adjacent)} />}
|
|
94
|
+
{!isRevealed && flagged[i] && <Glyph x={cx} y={cy} size={glyphSize} fill={flagColor} text="⚑" />}
|
|
95
|
+
</g>
|
|
96
|
+
)
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const root = render(
|
|
100
|
+
<svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox={`0 0 ${size} ${size}`}>
|
|
101
|
+
{/* Embed the @font-face rule so the SVG renders with Puzzmo's bundled font
|
|
102
|
+
even outside the game (host previews, share cards, opengraph). */}
|
|
103
|
+
<style>{svgFontFaceCSSRaw(["RedHatMono-Bold"])}</style>
|
|
104
|
+
<rect width={size} height={size} fill={bg} />
|
|
105
|
+
{board}
|
|
106
|
+
</svg>,
|
|
107
|
+
)
|
|
108
|
+
if (!root || !("outerHTML" in root)) throw new Error("Could not render the minesweeper thumbnail")
|
|
109
|
+
|
|
110
|
+
return { svg: root.outerHTML, width: size, height: size }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* A centered character in the board's monospace font — a mine count, or a flag.
|
|
115
|
+
*
|
|
116
|
+
* `font-weight` is spread in rather than passed as `undefined`: svgJSX writes every prop it is
|
|
117
|
+
* given, and an undefined value would serialize as the string "undefined".
|
|
118
|
+
*/
|
|
119
|
+
const Glyph = (props: { x: number; y: number; size: number; fill: string; text: string; weight?: number }) => (
|
|
120
|
+
<text
|
|
121
|
+
x={props.x.toFixed(2)}
|
|
122
|
+
y={props.y.toFixed(2)}
|
|
123
|
+
text-anchor="middle"
|
|
124
|
+
font-family="RedHatMono-Bold, ui-monospace, monospace"
|
|
125
|
+
font-size={props.size.toFixed(1)}
|
|
126
|
+
fill={props.fill}
|
|
127
|
+
{...(props.weight ? { "font-weight": props.weight } : {})}
|
|
128
|
+
>
|
|
129
|
+
{props.text}
|
|
130
|
+
</text>
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
const countAdjacent = (mineSet: Set<number>, i: number, rows: number, cols: number): number => {
|
|
134
|
+
const r = Math.floor(i / cols)
|
|
135
|
+
const c = i % cols
|
|
136
|
+
let n = 0
|
|
137
|
+
for (let dr = -1; dr <= 1; dr++) {
|
|
138
|
+
for (let dc = -1; dc <= 1; dc++) {
|
|
139
|
+
if (dr === 0 && dc === 0) continue
|
|
140
|
+
const nr = r + dr
|
|
141
|
+
const nc = c + dc
|
|
142
|
+
if (nr < 0 || nr >= rows || nc < 0 || nc >= cols) continue
|
|
143
|
+
if (mineSet.has(nr * cols + nc)) n++
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return n
|
|
147
|
+
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import type { AppBundle, ThumbnailConfig } from "@puzzmo/sdk"
|
|
2
|
-
import { svgFontFaceCSSRaw } from "@puzzmo/sdk/fonts"
|
|
3
|
-
import { createEncoder, defineSchema } from "@puzzmo/sdk/inputs"
|
|
4
|
-
|
|
5
|
-
type Puzzle = { rows: number; cols: number; mines: [number, number][] }
|
|
6
|
-
type State = { revealed: boolean[]; flagged: boolean[] }
|
|
7
|
-
|
|
8
|
-
/** Mirrors the schema in src/main.ts so a saved input string round-trips here too. */
|
|
9
|
-
const stateSchema = defineSchema<State>({
|
|
10
|
-
version: 1,
|
|
11
|
-
fields: {
|
|
12
|
-
revealed: { type: "bitArray" },
|
|
13
|
-
flagged: { type: "bitArray" },
|
|
14
|
-
},
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
const escapeXml = (s: string) => s.replace(/[<>&"']/g, (c) => `&#${c.charCodeAt(0)};`)
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Renders a small SVG preview of the puzzle plus its pixel dimensions, so the host can size
|
|
21
|
-
* the thumbnail without parsing the SVG. When an `inputStr` is supplied the preview reflects
|
|
22
|
-
* the player's progress; otherwise it shows a blank board.
|
|
23
|
-
*
|
|
24
|
-
* The host renders this in lists/share cards/completion screens — there's no DOM,
|
|
25
|
-
* no animation, no theme variables. We bake colors from `config.theme` directly.
|
|
26
|
-
*/
|
|
27
|
-
export const renderThumbnail: AppBundle["renderThumbnail"] = (puzzleStr: string, inputStr?: string, config?: ThumbnailConfig) => {
|
|
28
|
-
const puzzle = JSON.parse(puzzleStr) as Puzzle
|
|
29
|
-
const { rows, cols } = puzzle
|
|
30
|
-
const cells = rows * cols
|
|
31
|
-
const mineSet = new Set(puzzle.mines.map(([r, c]) => r * cols + c))
|
|
32
|
-
|
|
33
|
-
let revealed: boolean[] = new Array(cells).fill(false)
|
|
34
|
-
let flagged: boolean[] = new Array(cells).fill(false)
|
|
35
|
-
|
|
36
|
-
if (inputStr) {
|
|
37
|
-
try {
|
|
38
|
-
const codec = createEncoder(stateSchema, { revealed: { length: cells }, flagged: { length: cells } })
|
|
39
|
-
const decoded = codec.decode(codec.migrate(inputStr))
|
|
40
|
-
revealed = decoded.revealed
|
|
41
|
-
flagged = decoded.flagged
|
|
42
|
-
} catch {
|
|
43
|
-
// Bad/old state: fall back to a blank thumbnail.
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const theme = config?.theme
|
|
48
|
-
const bg = theme?.a_bg ?? "#1a1a1a"
|
|
49
|
-
const cellHidden = theme?.g_unsolved ?? "#3a3a3a"
|
|
50
|
-
const cellShown = theme?.g_bg ?? "#1f1f1f"
|
|
51
|
-
const border = theme?.g_outline ?? "#4a4a4a"
|
|
52
|
-
const mineColor = theme?.error ?? "#ff5555"
|
|
53
|
-
const flagColor = theme?.subBrand ?? "#ffaa55"
|
|
54
|
-
const numberColor = theme?.g_textDark ?? "#1b1b28"
|
|
55
|
-
|
|
56
|
-
const size = 200
|
|
57
|
-
const pad = 4
|
|
58
|
-
const gap = 1
|
|
59
|
-
const cellW = (size - pad * 2 - gap * (cols - 1)) / cols
|
|
60
|
-
const cellH = (size - pad * 2 - gap * (rows - 1)) / rows
|
|
61
|
-
|
|
62
|
-
const parts: string[] = []
|
|
63
|
-
parts.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 ${size} ${size}">`)
|
|
64
|
-
// Embed the @font-face rule so the SVG renders with Puzzmo's bundled font
|
|
65
|
-
// even outside the game (host previews, share cards, opengraph).
|
|
66
|
-
parts.push(`<style>${svgFontFaceCSSRaw(["RedHatMono-Bold"])}</style>`)
|
|
67
|
-
parts.push(`<rect width="${size}" height="${size}" fill="${escapeXml(bg)}"/>`)
|
|
68
|
-
|
|
69
|
-
for (let i = 0; i < cells; i++) {
|
|
70
|
-
const r = Math.floor(i / cols)
|
|
71
|
-
const c = i % cols
|
|
72
|
-
const x = pad + c * (cellW + gap)
|
|
73
|
-
const y = pad + r * (cellH + gap)
|
|
74
|
-
const isRevealed = revealed[i]
|
|
75
|
-
const fill = isRevealed ? cellShown : cellHidden
|
|
76
|
-
parts.push(
|
|
77
|
-
`<rect x="${x.toFixed(2)}" y="${y.toFixed(2)}" width="${cellW.toFixed(2)}" height="${cellH.toFixed(2)}" fill="${escapeXml(fill)}" stroke="${escapeXml(border)}" stroke-width="0.5"/>`,
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
if (isRevealed && mineSet.has(i)) {
|
|
81
|
-
const cx = x + cellW / 2
|
|
82
|
-
const cy = y + cellH / 2
|
|
83
|
-
const rad = Math.min(cellW, cellH) * 0.25
|
|
84
|
-
parts.push(`<circle cx="${cx.toFixed(2)}" cy="${cy.toFixed(2)}" r="${rad.toFixed(2)}" fill="${escapeXml(mineColor)}"/>`)
|
|
85
|
-
} else if (isRevealed && !mineSet.has(i)) {
|
|
86
|
-
const n = countAdjacent(mineSet, i, rows, cols)
|
|
87
|
-
if (n > 0) {
|
|
88
|
-
const cx = x + cellW / 2
|
|
89
|
-
const cy = y + cellH / 2 + cellH * 0.32
|
|
90
|
-
const fontSize = Math.min(cellW, cellH) * 0.7
|
|
91
|
-
parts.push(
|
|
92
|
-
`<text x="${cx.toFixed(2)}" y="${cy.toFixed(2)}" text-anchor="middle" font-family="RedHatMono-Bold, ui-monospace, monospace" font-size="${fontSize.toFixed(1)}" font-weight="700" fill="${escapeXml(numberColor)}">${n}</text>`,
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
} else if (flagged[i]) {
|
|
96
|
-
const cx = x + cellW / 2
|
|
97
|
-
const cy = y + cellH / 2 + cellH * 0.32
|
|
98
|
-
const fontSize = Math.min(cellW, cellH) * 0.7
|
|
99
|
-
parts.push(
|
|
100
|
-
`<text x="${cx.toFixed(2)}" y="${cy.toFixed(2)}" text-anchor="middle" font-family="RedHatMono-Bold, ui-monospace, monospace" font-size="${fontSize.toFixed(1)}" fill="${escapeXml(flagColor)}">⚑</text>`,
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
parts.push(`</svg>`)
|
|
106
|
-
return { svg: parts.join(""), width: size, height: size }
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const countAdjacent = (mineSet: Set<number>, i: number, rows: number, cols: number): number => {
|
|
110
|
-
const r = Math.floor(i / cols)
|
|
111
|
-
const c = i % cols
|
|
112
|
-
let n = 0
|
|
113
|
-
for (let dr = -1; dr <= 1; dr++) {
|
|
114
|
-
for (let dc = -1; dc <= 1; dc++) {
|
|
115
|
-
if (dr === 0 && dc === 0) continue
|
|
116
|
-
const nr = r + dr
|
|
117
|
-
const nc = c + dc
|
|
118
|
-
if (nr < 0 || nr >= rows || nc < 0 || nc >= cols) continue
|
|
119
|
-
if (mineSet.has(nr * cols + nc)) n++
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return n
|
|
123
|
-
}
|