@gameslate/sdk 0.3.29 → 0.3.31

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/pack.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { CatalogueSchema } from './catalogue.js';
3
+ import { createPackViewContext, } from './mission-labels.js';
3
4
  /**
4
5
  * A pack's data: everything the web app needs about one game that doesn't depend on the live
5
6
  * state. The daemon serves it (`/api/packs/<gameId>`); shared code never branches on `id`.
@@ -27,6 +28,10 @@ export const ServedPackDataSchema = PackDataSchema.extend({
27
28
  /** a loaded plugin's asset code builds this game's maps and assets from the player's own
28
29
  * files (the cog's build button) */
29
30
  buildsAssets: z.boolean(),
31
+ /** why the mission labels extracted on this PC aren't shown (a labels file that is broken,
32
+ * or built for another version of the pack): the titles are the committed ones until the
33
+ * player rebuilds the game's assets */
34
+ missionLabelsProblem: z.string().optional(),
30
35
  });
31
36
  /** The data part of a pack, without its code. */
32
37
  export function packToData(pack) {
@@ -38,11 +43,13 @@ export function packToData(pack) {
38
43
  ...(pack.panels ? { panels: pack.panels } : {}),
39
44
  };
40
45
  }
41
- /** Runs a pack's code over the live state. */
42
- export function packViewsFor(pack, state) {
46
+ /** Runs a pack's code over the live state, with the mission labels extracted for its game (none:
47
+ * the committed titles, as in a plugin's own tests). */
48
+ export function packViewsFor(pack, state, missionLabels = {}) {
49
+ const context = createPackViewContext(pack.catalogue, missionLabels);
43
50
  return {
44
- facts: pack.describeState?.(state) ?? [],
45
- statusStrip: pack.ui?.statusStrip?.(state) ?? null,
46
- timelines: pack.ui?.timelines?.(state) ?? [],
51
+ facts: pack.describeState?.(state, context) ?? [],
52
+ statusStrip: pack.ui?.statusStrip?.(state, context) ?? null,
53
+ timelines: pack.ui?.timelines?.(state, context) ?? [],
47
54
  };
48
55
  }
@@ -51,6 +51,23 @@ function trustedState(json) {
51
51
  throw new Error('the core sent no game state');
52
52
  return value;
53
53
  }
54
+ /* Labels the core read and checked (mission-labels.ts); a core before sdk 0.3.31 sends none, and
55
+ * then the catalogue's titles are the ones it shows too. Like the state, they are only narrowed
56
+ * here, not re-parsed with zod: the core validated them, and this runs on every views call. */
57
+ function trustedLabels(json) {
58
+ if (json === undefined)
59
+ return {};
60
+ const value = JSON.parse(json);
61
+ if (!isStringRecord(value))
62
+ throw new Error('the core sent mission labels that are not text');
63
+ return value;
64
+ }
65
+ function isStringRecord(value) {
66
+ return (typeof value === 'object' &&
67
+ value !== null &&
68
+ !Array.isArray(value) &&
69
+ Object.values(value).every(v => typeof v === 'string'));
70
+ }
54
71
  function find(list, match, what) {
55
72
  const found = list.find(match);
56
73
  if (!found)
@@ -84,7 +101,7 @@ export function exposeToHost(plugin) {
84
101
  sessions.get(handle)?.close();
85
102
  sessions.delete(handle);
86
103
  },
87
- views: (gameId, state) => JSON.stringify(packViewsFor(pack(gameId), trustedState(state))),
104
+ views: (gameId, state, labels) => JSON.stringify(packViewsFor(pack(gameId), trustedState(state), trustedLabels(labels))),
88
105
  };
89
106
  }
90
107
  /* the asset capabilities, which the core installs only in an asset sandbox */
@@ -938,8 +938,8 @@ export declare const PluginPreviewSchema: z.ZodObject<{
938
938
  }, "strip", z.ZodTypeAny, {
939
939
  id: string;
940
940
  kind: "manifest" | "zip";
941
- name: string;
942
941
  url: string;
942
+ name: string;
943
943
  sha256: string;
944
944
  version: string;
945
945
  games: {
@@ -958,8 +958,8 @@ export declare const PluginPreviewSchema: z.ZodObject<{
958
958
  }, {
959
959
  id: string;
960
960
  kind: "manifest" | "zip";
961
- name: string;
962
961
  url: string;
962
+ name: string;
963
963
  sha256: string;
964
964
  version: string;
965
965
  games: {