@puzzmo/sdk 1.0.76 → 1.0.78
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/README.md +36 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -276,14 +276,43 @@ The `h` function is a JSX factory that creates virtual DOM nodes, and `render` c
|
|
|
276
276
|
|
|
277
277
|
## Editor Integration
|
|
278
278
|
|
|
279
|
-
|
|
279
|
+
An editor bundle tells Puzzmo Workshop two things about your game: how to check that a puzzle is valid, and which settings an embed can change.
|
|
280
280
|
|
|
281
|
-
|
|
282
|
-
import type { EditorBundle, ValidationReport } from "@puzzmo/sdk"
|
|
281
|
+
Create `src/editorBundle.ts` in your game, next to the rest of its source, and make an `EditorBundle` its default export:
|
|
283
282
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
283
|
+
```ts
|
|
284
|
+
// src/editorBundle.ts
|
|
285
|
+
import type { EditorBundle } from "@puzzmo/sdk"
|
|
286
|
+
|
|
287
|
+
const bundle: EditorBundle = {
|
|
288
|
+
// Required. Workshop runs this on every puzzle someone edits or uploads.
|
|
289
|
+
validator: {
|
|
290
|
+
validate(data) {
|
|
291
|
+
return { success: true, issues: [] }
|
|
292
|
+
},
|
|
287
293
|
},
|
|
288
|
-
|
|
294
|
+
// Optional. The form shown on an embed's settings page, and each setting's starting value.
|
|
295
|
+
settings: {
|
|
296
|
+
components: [{ id: "my-game-hard-mode", type: "boolean", name: "hardMode", title: "Hard mode", defaultValue: false }],
|
|
297
|
+
defaults: { hardMode: false },
|
|
298
|
+
},
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export default bundle
|
|
289
302
|
```
|
|
303
|
+
|
|
304
|
+
Then add `editorBundlePlugin` to your Vite config. After the main build it compiles that file into `dist/editor-bundle.js`:
|
|
305
|
+
|
|
306
|
+
```ts
|
|
307
|
+
// vite.config.ts
|
|
308
|
+
import { editorBundlePlugin } from "@puzzmo/sdk/vite"
|
|
309
|
+
import { defineConfig } from "vite"
|
|
310
|
+
|
|
311
|
+
export default defineConfig({
|
|
312
|
+
plugins: [editorBundlePlugin()],
|
|
313
|
+
})
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
The source file's name is only the plugin's default: it looks for `src/editorBundle.js`, then `.ts`, in the folder you run the build from. To keep it somewhere else, pass `editorBundlePlugin({ entry: "path/to/file.ts" })`.
|
|
317
|
+
|
|
318
|
+
The output name is not flexible. Workshop finds the bundle by looking for `editor-bundle.js` at the top of the build you upload, so leave `outputFile` alone. There is nothing else to set up: upload a build containing that file and Workshop loads it.
|