@seriousgaming/sdk-tools 1.2.0 → 1.3.0

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/dist/cli.js CHANGED
@@ -3395,10 +3395,12 @@ function gameOverrideRefusal(overrides) {
3395
3395
 
3396
3396
  // cli/runtime/manifest-version.ts
3397
3397
  var MANIFEST_VERSION = 3;
3398
- var SPEC_REVISION = "1.2";
3398
+ var SPEC_REVISION = "1.3";
3399
3399
  var SUPPORTED_FEATURES = [
3400
3400
  // A validator's `Scenario` gate (§15.8).
3401
- "scenario-validation"
3401
+ "scenario-validation",
3402
+ // The presentation as a host overlay a session surface may open (§6.4).
3403
+ "presentation-overlay"
3402
3404
  ];
3403
3405
  function unsupportedFeatures(manifest) {
3404
3406
  return (manifest.requires ?? []).filter((feature) => !SUPPORTED_FEATURES.includes(feature));
@@ -24346,6 +24348,7 @@ var COMMAND_FIELDS = {
24346
24348
  removeTeam: { teamIndex: "number" },
24347
24349
  renameTeam: { teamId: "string", name: "string" },
24348
24350
  renameOwnTeam: { name: "string", "participantId?": "string", "teamId?": "string" },
24351
+ renameSelf: { name: "string", "participantId?": "string", "teamId?": "string" },
24349
24352
  addParticipant: { teamId: "string", "name?": "string" },
24350
24353
  renameParticipant: { participantId: "string", name: "string" },
24351
24354
  moveParticipant: { participantId: "string", teamId: "string" },
@@ -27059,6 +27062,7 @@ function swallow() {
27059
27062
 
27060
27063
  // cli/core/participant-registry.ts
27061
27064
  import { EventEmitter } from "events";
27065
+ var MAX_PARTICIPANT_NAME_LENGTH = 60;
27062
27066
  var ParticipantRegistry = class extends EventEmitter {
27063
27067
  teams = /* @__PURE__ */ new Map();
27064
27068
  /**
@@ -28305,6 +28309,16 @@ var SessionRoster = class {
28305
28309
  if (!teamId) throw new DeniedError("The caller is not on a team");
28306
28310
  return this.renameTeam(teamId, command.name);
28307
28311
  }
28312
+ renameSelf(command) {
28313
+ if (!command.participantId)
28314
+ throw new DeniedError("Only a participant can rename themselves");
28315
+ const trimmed = command.name.trim();
28316
+ if (!trimmed) throw new DeniedError("A name cannot be blank");
28317
+ if (trimmed.length > MAX_PARTICIPANT_NAME_LENGTH) {
28318
+ throw new DeniedError(`A name is at most ${MAX_PARTICIPANT_NAME_LENGTH} characters`);
28319
+ }
28320
+ return this.renameParticipant(command.participantId, trimmed);
28321
+ }
28308
28322
  async addParticipant(teamId, name) {
28309
28323
  if (!this.host.state.getTeamIndexes().some((i) => `team-${i + 1}` === teamId)) {
28310
28324
  throw new DeniedError(`Unknown team "${teamId}"`);
@@ -29558,6 +29572,7 @@ var PLAY_STAGE = /* @__PURE__ */ new Set([
29558
29572
  "renameParticipant",
29559
29573
  "moveParticipant",
29560
29574
  "renameOwnTeam",
29575
+ "renameSelf",
29561
29576
  "extendTick"
29562
29577
  ]);
29563
29578
  var STALE_BLOCKED = /* @__PURE__ */ new Set([
@@ -30212,6 +30227,8 @@ var Session = class {
30212
30227
  return this.roster.renameTeam(command.teamId, command.name);
30213
30228
  case "renameOwnTeam":
30214
30229
  return this.roster.renameOwnTeam(command);
30230
+ case "renameSelf":
30231
+ return this.roster.renameSelf(command);
30215
30232
  case "addParticipant":
30216
30233
  return this.roster.addParticipant(command.teamId, command.name);
30217
30234
  case "renameParticipant":
@@ -30384,6 +30401,12 @@ var Session = class {
30384
30401
  await deleteBlobs(this.options.packagePath, retentions);
30385
30402
  }
30386
30403
  setLocale(locale) {
30404
+ const supported = this.packageConfiguration()?.game?.definition.supportedLocales;
30405
+ if (supported?.length && !supported.includes(locale)) {
30406
+ throw new DeniedError(
30407
+ `"${locale}" is not one of this game's locales (${supported.join(", ")})`
30408
+ );
30409
+ }
30387
30410
  this.locale = locale;
30388
30411
  this.executor.setLocale(locale);
30389
30412
  return void 0;
@@ -38057,6 +38080,319 @@ function mountableSurfaces(config) {
38057
38080
  ].filter((surface) => surface !== null);
38058
38081
  }
38059
38082
 
38083
+ // cli/dev/view/batch.ts
38084
+ function projectContext2(context, surface) {
38085
+ const declared = /* @__PURE__ */ new Set([...surface.reads, ...surface.writes]);
38086
+ const projected = {};
38087
+ for (const [capability, values] of Object.entries(context)) {
38088
+ if (declared.has(capability)) projected[capability] = values;
38089
+ }
38090
+ return projected;
38091
+ }
38092
+ function settingsFor(state2, surface, { withoutSession = false } = {}) {
38093
+ const settings = withoutSession ? state2.settingsWithoutSession : state2.settings;
38094
+ return Object.fromEntries(
38095
+ surface.settings.filter((identifier) => identifier in settings).map((identifier) => [identifier, settings[identifier]])
38096
+ );
38097
+ }
38098
+ function draftSettingsFor(state2, surface, viewer) {
38099
+ const scenarioId = viewer.scenario ?? null;
38100
+ const draft = state2.scenarioDrafts?.find((entry) => entry.scenarioId === scenarioId);
38101
+ const settings = draft?.settings ?? {};
38102
+ return Object.fromEntries(
38103
+ surface.settings.filter((identifier) => identifier in settings).map((identifier) => [identifier, settings[identifier]])
38104
+ );
38105
+ }
38106
+ function sessionKeyFor(state2, surface, { sessionless = false } = {}) {
38107
+ const outside = surface.kind === "scenario-editor" || surface.kind === "presentation" && sessionless;
38108
+ return outside ? `outside-session:${state2.game.identifier}` : state2.session.sessionKey;
38109
+ }
38110
+ function themeMessages(theme) {
38111
+ return [
38112
+ { type: "setTheme", payload: theme.palette },
38113
+ { type: "themePreferenceChanged", preference: theme.preference }
38114
+ ];
38115
+ }
38116
+ function assetUrls(assetOrigin) {
38117
+ return {
38118
+ blobPrefix: `${assetOrigin}/assets/blobs/`,
38119
+ scenarioAssetPrefix: `${assetOrigin}/assets/scenario/`,
38120
+ sharedAssetPrefix: `${assetOrigin}/assets/shared/`,
38121
+ assetAuthRedeemUrl: `${assetOrigin}/assets/auth/redeem`
38122
+ };
38123
+ }
38124
+ function teamOf(state2, teamIndex) {
38125
+ if (teamIndex === void 0) return state2.teams[0];
38126
+ return state2.teams.find((team) => team.index === teamIndex);
38127
+ }
38128
+ function teamList(state2) {
38129
+ return [...state2.teams].sort((a, b) => a.index - b.index).map((team) => ({ teamId: team.teamId, index: team.index, name: team.name }));
38130
+ }
38131
+ var IDLE_TIMER2 = {
38132
+ enabled: false,
38133
+ paused: false,
38134
+ nextTickAt: null,
38135
+ intervalMs: null,
38136
+ pausedAt: null,
38137
+ pausedMs: 0,
38138
+ extendedMs: 0,
38139
+ scheduleStartedAt: null
38140
+ };
38141
+ function buildBatch(options) {
38142
+ const { surface, state: state2, theme, origin, assetOrigin } = options;
38143
+ const common = [
38144
+ { type: "setLocale", payload: { locale: state2.session.locale } },
38145
+ { type: "setAssetUrls", payload: assetUrls(assetOrigin ?? origin) },
38146
+ ...theme ? themeMessages(theme) : []
38147
+ ];
38148
+ switch (surface.kind) {
38149
+ case "game":
38150
+ case "waiting-room":
38151
+ return [...playerBatch(options), ...common];
38152
+ case "session":
38153
+ return [...sessionBatch(options), ...common];
38154
+ // The two settings editors are sent the same batch (§12.3): neither is
38155
+ // told which slot it fills, since each is its own bundle.
38156
+ case "setup":
38157
+ return [{ type: "setSettings", payload: settingsFor(state2, surface) }, ...common];
38158
+ case "scenario-editor":
38159
+ return [
38160
+ { type: "setSettings", payload: draftSettingsFor(state2, surface, options.viewer) },
38161
+ ...common
38162
+ ];
38163
+ case "presentation":
38164
+ return [...presentationBatch(options), ...common];
38165
+ }
38166
+ return common;
38167
+ }
38168
+ function crossTeamData(state2, surface, ownTeamIndex) {
38169
+ const across = new Set(surface.crossTeamReads);
38170
+ return [...state2.teams].sort((a, b) => a.index - b.index).map((team) => ({
38171
+ teamId: team.teamId,
38172
+ index: team.index,
38173
+ name: team.name,
38174
+ context: team.index === ownTeamIndex ? projectContext2(team.context, surface) : Object.fromEntries(
38175
+ Object.entries(team.context).filter(
38176
+ ([capability]) => across.has(capability)
38177
+ )
38178
+ )
38179
+ }));
38180
+ }
38181
+ function joinUrl(origin, teamIndex) {
38182
+ return `${origin}/team/${teamIndex + 1}/join?bare`;
38183
+ }
38184
+ function playerBatch({
38185
+ surface,
38186
+ state: state2,
38187
+ viewer,
38188
+ origin,
38189
+ roundProcessing
38190
+ }) {
38191
+ const team = teamOf(state2, viewer.teamIndex);
38192
+ const participant = viewer.observer ? void 0 : team?.participants.find((p) => p.id === viewer.participantId) ?? team?.participants[0];
38193
+ const messages2 = [
38194
+ {
38195
+ type: "stateChanged",
38196
+ payload: projectContext2(team?.context ?? {}, surface),
38197
+ // §12.5: the head tick, so a review scrubber can be bounded and a
38198
+ // cache invalidated on undo.
38199
+ completedTicks: team?.completedTicks ?? state2.session.completedTicks
38200
+ },
38201
+ { type: "setSettings", payload: settingsFor(state2, surface) }
38202
+ ];
38203
+ if (participant) {
38204
+ messages2.push({
38205
+ type: "setParticipant",
38206
+ payload: {
38207
+ id: participant.id,
38208
+ name: participant.name,
38209
+ index: participant.index,
38210
+ teamId: team?.teamId ?? "team-1"
38211
+ },
38212
+ // There are no accounts here, so every name is the participant's
38213
+ // own to change (§12.5).
38214
+ canRenameSelf: true
38215
+ });
38216
+ }
38217
+ messages2.push(
38218
+ { type: "setViewerRole", role: viewer.observer ? "observer" : "participant" },
38219
+ { type: "setRunKind", runKind: state2.session.runKind },
38220
+ { type: "setScenarioName", scenarioName: state2.game.scenarioName },
38221
+ {
38222
+ type: "setOwnTeam",
38223
+ payload: team ? { teamId: team.teamId, index: team.index, name: team.name } : { teamId: "team-1", index: 0, name: "Team 1" }
38224
+ },
38225
+ {
38226
+ type: "setOwnTeamJoinLink",
38227
+ payload: team ? { joinUrl: joinUrl(origin, team.index) } : (
38228
+ // §12.3, as amended: a host with nothing to offer says so
38229
+ // rather than staying silent, so a surface rendering a join
38230
+ // panel shows nothing instead of waiting for a message that
38231
+ // never comes.
38232
+ null
38233
+ )
38234
+ },
38235
+ { type: "setParticipantList", participants: team?.participants ?? [] },
38236
+ { type: "setTeamList", payload: teamList(state2) },
38237
+ { type: "setTimer", payload: team?.timer ?? IDLE_TIMER2 }
38238
+ );
38239
+ if (surface.kind === "game") {
38240
+ messages2.push({ type: "setRoundProcessing", processing: roundProcessing === true });
38241
+ }
38242
+ if ((surface.kind === "game" || surface.kind === "waiting-room") && surface.crossTeamReads.length > 0 && state2.session.mode === "shared-state") {
38243
+ messages2.push({
38244
+ type: "setCrossTeamData",
38245
+ payload: crossTeamData(state2, surface, team?.index)
38246
+ });
38247
+ }
38248
+ return messages2;
38249
+ }
38250
+ function sessionBatch({
38251
+ surface,
38252
+ state: state2,
38253
+ gameName,
38254
+ origin,
38255
+ overlays
38256
+ }) {
38257
+ return [
38258
+ {
38259
+ type: "setSessionMeta",
38260
+ payload: {
38261
+ sessionId: "dev-session",
38262
+ name: gameName,
38263
+ readOnly: false,
38264
+ waitingRoomOpen: state2.session.waitingRoomOpen,
38265
+ joinPin: null,
38266
+ canSetLocale: true
38267
+ }
38268
+ },
38269
+ { type: "setSessionData", payload: sessionData(state2, surface) },
38270
+ { type: "setSettings", payload: settingsFor(state2, surface) },
38271
+ { type: "setTeamConfiguration", payload: teamConfiguration(state2) },
38272
+ { type: "setTeamList", payload: teamList(state2) },
38273
+ {
38274
+ type: "setParticipantList",
38275
+ participants: participantList(state2)
38276
+ },
38277
+ { type: "setTeamLinks", payload: teamLinks(state2, origin) },
38278
+ { type: "setWalkthroughLink", payload: walkthroughLink(origin) },
38279
+ { type: "setRunKind", runKind: state2.session.runKind },
38280
+ { type: "setScenarioName", scenarioName: state2.game.scenarioName },
38281
+ { type: "setAvailableOverlays", overlays: overlays ?? availableOverlays() }
38282
+ ];
38283
+ }
38284
+ function presentationBatch({
38285
+ surface,
38286
+ state: state2,
38287
+ gameName,
38288
+ origin,
38289
+ sessionless
38290
+ }) {
38291
+ return [
38292
+ {
38293
+ type: "setPresentation",
38294
+ payload: {
38295
+ game: {
38296
+ name: state2.game.name,
38297
+ // Without a session, as the scenario resolves it alone (§6.15.1).
38298
+ maxTicks: sessionless ? gameSettingsOf(state2.settingsWithoutSession).maxTicks : state2.session.maxTicks,
38299
+ mode: state2.session.mode,
38300
+ scenarioName: state2.game.scenarioName
38301
+ },
38302
+ session: sessionless ? null : {
38303
+ // The dev server runs one session; its id is the
38304
+ // one the session surface is told (above).
38305
+ id: "dev-session",
38306
+ name: gameName,
38307
+ completedTicks: Math.max(
38308
+ state2.session.completedTicks,
38309
+ ...state2.teams.map((team) => team.completedTicks)
38310
+ ),
38311
+ data: sessionData(state2, surface),
38312
+ teams: teamList(state2),
38313
+ participants: participantList(state2),
38314
+ // A deck puts these on the projector, so no observe
38315
+ // URL: watching a team is the facilitator's tool.
38316
+ joinLinks: teamLinks(state2, origin).map(({ teamId, joinUrl: joinUrl2 }) => ({
38317
+ teamId,
38318
+ joinUrl: joinUrl2
38319
+ })),
38320
+ joinPin: null
38321
+ }
38322
+ }
38323
+ },
38324
+ {
38325
+ type: "setSettings",
38326
+ payload: settingsFor(state2, surface, { withoutSession: sessionless })
38327
+ }
38328
+ ];
38329
+ }
38330
+ function walkthroughLink(origin) {
38331
+ return { url: `${origin}/walkthrough` };
38332
+ }
38333
+ function availableOverlays(offered = {}) {
38334
+ return [
38335
+ ...offered.guide ? ["facilitator-guide"] : [],
38336
+ "print-sheets",
38337
+ ...offered.presentation ? ["presentation"] : []
38338
+ ];
38339
+ }
38340
+ function offersPresentationOverlay(config) {
38341
+ return config?.presentation !== void 0 && (config.requires ?? []).includes(PRESENTATION_OVERLAY);
38342
+ }
38343
+ var PRESENTATION_OVERLAY = "presentation-overlay";
38344
+ function participantList(state2) {
38345
+ return state2.teams.flatMap(
38346
+ (team) => team.participants.map((participant) => ({
38347
+ id: participant.id,
38348
+ name: participant.name,
38349
+ index: participant.index,
38350
+ connected: participant.connected,
38351
+ teamId: team.teamId
38352
+ }))
38353
+ );
38354
+ }
38355
+ function teamLinks(state2, origin) {
38356
+ return [...state2.teams].sort((a, b) => a.index - b.index).map((team) => ({
38357
+ teamId: team.teamId,
38358
+ joinUrl: joinUrl(origin, team.index),
38359
+ observeUrl: `${origin}/team/${team.index + 1}/observe`
38360
+ }));
38361
+ }
38362
+ function teamConfiguration(state2) {
38363
+ return {
38364
+ mode: state2.session.mode,
38365
+ ...state2.session.teamBounds.min === void 0 ? {} : { min: state2.session.teamBounds.min },
38366
+ max: state2.session.teamBounds.max
38367
+ };
38368
+ }
38369
+ function sessionData(state2, surface) {
38370
+ const teams = {};
38371
+ for (const team of state2.teams) {
38372
+ const own5 = {};
38373
+ for (const [capability, values] of Object.entries(team.context)) {
38374
+ if (!(capability in state2.shared)) own5[capability] = values;
38375
+ }
38376
+ teams[team.teamId] = {
38377
+ context: projectContext2(own5, surface),
38378
+ completedTicks: team.completedTicks,
38379
+ timer: team.timer ?? IDLE_TIMER2,
38380
+ // Monotonic per delivery. One session, one host, so the tick is a
38381
+ // sufficient clock; the wrapper only compares it with itself.
38382
+ revision: team.completedTicks
38383
+ };
38384
+ }
38385
+ return {
38386
+ // The dev server only ever sends snapshots, so the revision is a
38387
+ // baseline the wrapper never compares a delta against.
38388
+ shared: {
38389
+ context: projectContext2(state2.shared, surface),
38390
+ revision: state2.session.completedTicks
38391
+ },
38392
+ teams
38393
+ };
38394
+ }
38395
+
38060
38396
  // cli/dev/routes.ts
38061
38397
  function runOf(req) {
38062
38398
  return req.query.run === "walkthrough" ? "walkthrough" : "session";
@@ -38220,6 +38556,14 @@ function registerRoutes(app, deps) {
38220
38556
  app.get("/api/guide", (_req, res) => {
38221
38557
  res.json({ guide: session.effectiveGuide() });
38222
38558
  });
38559
+ app.get("/api/overlays", (_req, res) => {
38560
+ res.json({
38561
+ overlays: availableOverlays({
38562
+ guide: session.effectiveGuide() !== null,
38563
+ presentation: offersPresentationOverlay(session.packageConfiguration())
38564
+ })
38565
+ });
38566
+ });
38223
38567
  app.get("/api/guide/content/:locale/:chapter", async (req, res) => {
38224
38568
  const guide = session.guide();
38225
38569
  if (!guide) {
@@ -38336,8 +38680,8 @@ function serveAsset(req, res, root2) {
38336
38680
 
38337
38681
  // cli/dev/view/commands.ts
38338
38682
  var FRAME_COMMANDS = {
38339
- game: /* @__PURE__ */ new Set(["updateData", "requestTick", "renameOwnTeam"]),
38340
- "waiting-room": /* @__PURE__ */ new Set(["updateData", "requestTick", "renameOwnTeam"]),
38683
+ game: /* @__PURE__ */ new Set(["updateData", "requestTick", "renameOwnTeam", "renameSelf"]),
38684
+ "waiting-room": /* @__PURE__ */ new Set(["updateData", "requestTick", "renameOwnTeam", "renameSelf"]),
38341
38685
  session: /* @__PURE__ */ new Set([
38342
38686
  "updateSessionData",
38343
38687
  "updateSharedData",
@@ -38346,6 +38690,7 @@ var FRAME_COMMANDS = {
38346
38690
  "resetGame",
38347
38691
  "resetWalkthrough",
38348
38692
  "setWaitingRoom",
38693
+ "setLocale",
38349
38694
  "createTeam",
38350
38695
  "renameTeam",
38351
38696
  "renameParticipant",
@@ -38365,7 +38710,9 @@ var FRAME_COMMANDS = {
38365
38710
  var NO_TEAM_ID = {
38366
38711
  setWaitingRoom: "The waiting room is session-wide, so setWaitingRoom takes no teamId",
38367
38712
  renameOwnTeam: "renameOwnTeam renames the caller's own team, which the host resolves; it takes no teamId",
38368
- resetWalkthrough: "A walkthrough holds one team, so resetWalkthrough takes no teamId"
38713
+ resetWalkthrough: "A walkthrough holds one team, so resetWalkthrough takes no teamId",
38714
+ setLocale: "The locale is the session's, so setLocale takes no teamId",
38715
+ renameSelf: "renameSelf renames the caller, whom the host resolves; it takes no teamId"
38369
38716
  };
38370
38717
  var FRAME_QUERIES = {
38371
38718
  game: /* @__PURE__ */ new Set(["callEndpoint", "getPastState", "getAllTeamsParticipants"]),
@@ -38405,6 +38752,11 @@ function commandFor(message, surface, viewer) {
38405
38752
  if (message.teamId !== void 0 && message.type in NO_TEAM_ID) {
38406
38753
  return { refused: NO_TEAM_ID[message.type] };
38407
38754
  }
38755
+ if (message.type === "renameSelf" && message.participantId !== void 0) {
38756
+ return {
38757
+ refused: "renameSelf renames the caller, whom the host resolves; it takes no participantId"
38758
+ };
38759
+ }
38408
38760
  const scope = teamScope(viewer);
38409
38761
  const actor = actorOf(viewer);
38410
38762
  const role = roleOf(viewer);
@@ -38463,6 +38815,8 @@ function commandFor(message, surface, viewer) {
38463
38815
  };
38464
38816
  case "setWaitingRoom":
38465
38817
  return { type: "setWaitingRoom", open: message.open === true };
38818
+ case "setLocale":
38819
+ return { type: "setLocale", locale: String(message.locale) };
38466
38820
  case "resetWalkthrough":
38467
38821
  return { type: "resetWalkthrough" };
38468
38822
  case "createTeam":
@@ -38478,6 +38832,8 @@ function commandFor(message, surface, viewer) {
38478
38832
  };
38479
38833
  case "renameOwnTeam":
38480
38834
  return { type: "renameOwnTeam", name: String(message.name), ...actor };
38835
+ case "renameSelf":
38836
+ return { type: "renameSelf", name: String(message.name), ...actor };
38481
38837
  case "renameParticipant":
38482
38838
  return {
38483
38839
  type: "renameParticipant",
@@ -38601,295 +38957,6 @@ function routeHref(route) {
38601
38957
  return search2 ? `${path3}?${search2}` : path3;
38602
38958
  }
38603
38959
 
38604
- // cli/dev/view/batch.ts
38605
- function projectContext2(context, surface) {
38606
- const declared = /* @__PURE__ */ new Set([...surface.reads, ...surface.writes]);
38607
- const projected = {};
38608
- for (const [capability, values] of Object.entries(context)) {
38609
- if (declared.has(capability)) projected[capability] = values;
38610
- }
38611
- return projected;
38612
- }
38613
- function settingsFor(state2, surface, { withoutSession = false } = {}) {
38614
- const settings = withoutSession ? state2.settingsWithoutSession : state2.settings;
38615
- return Object.fromEntries(
38616
- surface.settings.filter((identifier) => identifier in settings).map((identifier) => [identifier, settings[identifier]])
38617
- );
38618
- }
38619
- function draftSettingsFor(state2, surface, viewer) {
38620
- const scenarioId = viewer.scenario ?? null;
38621
- const draft = state2.scenarioDrafts?.find((entry) => entry.scenarioId === scenarioId);
38622
- const settings = draft?.settings ?? {};
38623
- return Object.fromEntries(
38624
- surface.settings.filter((identifier) => identifier in settings).map((identifier) => [identifier, settings[identifier]])
38625
- );
38626
- }
38627
- function sessionKeyFor(state2, surface, { sessionless = false } = {}) {
38628
- const outside = surface.kind === "scenario-editor" || surface.kind === "presentation" && sessionless;
38629
- return outside ? `outside-session:${state2.game.identifier}` : state2.session.sessionKey;
38630
- }
38631
- function themeMessages(theme) {
38632
- return [
38633
- { type: "setTheme", payload: theme.palette },
38634
- { type: "themePreferenceChanged", preference: theme.preference }
38635
- ];
38636
- }
38637
- function assetUrls(assetOrigin) {
38638
- return {
38639
- blobPrefix: `${assetOrigin}/assets/blobs/`,
38640
- scenarioAssetPrefix: `${assetOrigin}/assets/scenario/`,
38641
- sharedAssetPrefix: `${assetOrigin}/assets/shared/`,
38642
- assetAuthRedeemUrl: `${assetOrigin}/assets/auth/redeem`
38643
- };
38644
- }
38645
- function teamOf(state2, teamIndex) {
38646
- if (teamIndex === void 0) return state2.teams[0];
38647
- return state2.teams.find((team) => team.index === teamIndex);
38648
- }
38649
- function teamList(state2) {
38650
- return [...state2.teams].sort((a, b) => a.index - b.index).map((team) => ({ teamId: team.teamId, index: team.index, name: team.name }));
38651
- }
38652
- var IDLE_TIMER2 = {
38653
- enabled: false,
38654
- paused: false,
38655
- nextTickAt: null,
38656
- intervalMs: null,
38657
- pausedAt: null,
38658
- pausedMs: 0,
38659
- extendedMs: 0,
38660
- scheduleStartedAt: null
38661
- };
38662
- function buildBatch(options) {
38663
- const { surface, state: state2, theme, origin, assetOrigin } = options;
38664
- const common = [
38665
- { type: "setLocale", payload: { locale: state2.session.locale } },
38666
- { type: "setAssetUrls", payload: assetUrls(assetOrigin ?? origin) },
38667
- ...theme ? themeMessages(theme) : []
38668
- ];
38669
- switch (surface.kind) {
38670
- case "game":
38671
- case "waiting-room":
38672
- return [...playerBatch(options), ...common];
38673
- case "session":
38674
- return [...sessionBatch(options), ...common];
38675
- // The two settings editors are sent the same batch (§12.3): neither is
38676
- // told which slot it fills, since each is its own bundle.
38677
- case "setup":
38678
- return [{ type: "setSettings", payload: settingsFor(state2, surface) }, ...common];
38679
- case "scenario-editor":
38680
- return [
38681
- { type: "setSettings", payload: draftSettingsFor(state2, surface, options.viewer) },
38682
- ...common
38683
- ];
38684
- case "presentation":
38685
- return [...presentationBatch(options), ...common];
38686
- }
38687
- return common;
38688
- }
38689
- function crossTeamData(state2, surface, ownTeamIndex) {
38690
- const across = new Set(surface.crossTeamReads);
38691
- return [...state2.teams].sort((a, b) => a.index - b.index).map((team) => ({
38692
- teamId: team.teamId,
38693
- index: team.index,
38694
- name: team.name,
38695
- context: team.index === ownTeamIndex ? projectContext2(team.context, surface) : Object.fromEntries(
38696
- Object.entries(team.context).filter(
38697
- ([capability]) => across.has(capability)
38698
- )
38699
- )
38700
- }));
38701
- }
38702
- function joinUrl(origin, teamIndex) {
38703
- return `${origin}/team/${teamIndex + 1}/join?bare`;
38704
- }
38705
- function playerBatch({
38706
- surface,
38707
- state: state2,
38708
- viewer,
38709
- origin,
38710
- roundProcessing
38711
- }) {
38712
- const team = teamOf(state2, viewer.teamIndex);
38713
- const participant = viewer.observer ? void 0 : team?.participants.find((p) => p.id === viewer.participantId) ?? team?.participants[0];
38714
- const messages2 = [
38715
- {
38716
- type: "stateChanged",
38717
- payload: projectContext2(team?.context ?? {}, surface),
38718
- // §12.5: the head tick, so a review scrubber can be bounded and a
38719
- // cache invalidated on undo.
38720
- completedTicks: team?.completedTicks ?? state2.session.completedTicks
38721
- },
38722
- { type: "setSettings", payload: settingsFor(state2, surface) }
38723
- ];
38724
- if (participant) {
38725
- messages2.push({
38726
- type: "setParticipant",
38727
- payload: {
38728
- id: participant.id,
38729
- name: participant.name,
38730
- index: participant.index,
38731
- teamId: team?.teamId ?? "team-1"
38732
- }
38733
- });
38734
- }
38735
- messages2.push(
38736
- { type: "setViewerRole", role: viewer.observer ? "observer" : "participant" },
38737
- { type: "setRunKind", runKind: state2.session.runKind },
38738
- { type: "setScenarioName", scenarioName: state2.game.scenarioName },
38739
- {
38740
- type: "setOwnTeam",
38741
- payload: team ? { teamId: team.teamId, index: team.index, name: team.name } : { teamId: "team-1", index: 0, name: "Team 1" }
38742
- },
38743
- {
38744
- type: "setOwnTeamJoinLink",
38745
- payload: team ? { joinUrl: joinUrl(origin, team.index) } : (
38746
- // §12.3, as amended: a host with nothing to offer says so
38747
- // rather than staying silent, so a surface rendering a join
38748
- // panel shows nothing instead of waiting for a message that
38749
- // never comes.
38750
- null
38751
- )
38752
- },
38753
- { type: "setParticipantList", participants: team?.participants ?? [] },
38754
- { type: "setTeamList", payload: teamList(state2) },
38755
- { type: "setTimer", payload: team?.timer ?? IDLE_TIMER2 }
38756
- );
38757
- if (surface.kind === "game") {
38758
- messages2.push({ type: "setRoundProcessing", processing: roundProcessing === true });
38759
- }
38760
- if ((surface.kind === "game" || surface.kind === "waiting-room") && surface.crossTeamReads.length > 0 && state2.session.mode === "shared-state") {
38761
- messages2.push({
38762
- type: "setCrossTeamData",
38763
- payload: crossTeamData(state2, surface, team?.index)
38764
- });
38765
- }
38766
- return messages2;
38767
- }
38768
- function sessionBatch({
38769
- surface,
38770
- state: state2,
38771
- gameName,
38772
- origin,
38773
- hasGuide
38774
- }) {
38775
- return [
38776
- {
38777
- type: "setSessionMeta",
38778
- payload: {
38779
- sessionId: "dev-session",
38780
- name: gameName,
38781
- readOnly: false,
38782
- waitingRoomOpen: state2.session.waitingRoomOpen,
38783
- joinPin: null
38784
- }
38785
- },
38786
- { type: "setSessionData", payload: sessionData(state2, surface) },
38787
- { type: "setSettings", payload: settingsFor(state2, surface) },
38788
- { type: "setTeamConfiguration", payload: teamConfiguration(state2) },
38789
- { type: "setTeamList", payload: teamList(state2) },
38790
- {
38791
- type: "setParticipantList",
38792
- participants: state2.teams.flatMap(
38793
- (team) => team.participants.map((participant) => ({
38794
- id: participant.id,
38795
- name: participant.name,
38796
- index: participant.index,
38797
- connected: participant.connected,
38798
- teamId: team.teamId
38799
- }))
38800
- )
38801
- },
38802
- { type: "setTeamLinks", payload: teamLinks(state2, origin) },
38803
- { type: "setWalkthroughLink", payload: walkthroughLink(origin) },
38804
- { type: "setRunKind", runKind: state2.session.runKind },
38805
- { type: "setScenarioName", scenarioName: state2.game.scenarioName },
38806
- { type: "setAvailableOverlays", overlays: availableOverlays(hasGuide) }
38807
- ];
38808
- }
38809
- function presentationBatch({
38810
- surface,
38811
- state: state2,
38812
- gameName,
38813
- sessionless
38814
- }) {
38815
- return [
38816
- {
38817
- type: "setPresentation",
38818
- payload: {
38819
- game: {
38820
- name: state2.game.name,
38821
- // Without a session, as the scenario resolves it alone (§6.15.1).
38822
- maxTicks: sessionless ? gameSettingsOf(state2.settingsWithoutSession).maxTicks : state2.session.maxTicks,
38823
- mode: state2.session.mode,
38824
- scenarioName: state2.game.scenarioName
38825
- },
38826
- session: sessionless ? null : {
38827
- // The dev server runs one session; its id is the
38828
- // one the session surface is told (above).
38829
- id: "dev-session",
38830
- name: gameName,
38831
- completedTicks: Math.max(
38832
- state2.session.completedTicks,
38833
- ...state2.teams.map((team) => team.completedTicks)
38834
- ),
38835
- data: sessionData(state2, surface),
38836
- teams: teamList(state2)
38837
- }
38838
- }
38839
- },
38840
- {
38841
- type: "setSettings",
38842
- payload: settingsFor(state2, surface, { withoutSession: sessionless })
38843
- }
38844
- ];
38845
- }
38846
- function walkthroughLink(origin) {
38847
- return { url: `${origin}/walkthrough` };
38848
- }
38849
- function availableOverlays(hasGuide = false) {
38850
- return hasGuide ? ["facilitator-guide", "print-sheets"] : ["print-sheets"];
38851
- }
38852
- function teamLinks(state2, origin) {
38853
- return [...state2.teams].sort((a, b) => a.index - b.index).map((team) => ({
38854
- teamId: team.teamId,
38855
- joinUrl: joinUrl(origin, team.index),
38856
- observeUrl: `${origin}/team/${team.index + 1}/observe`
38857
- }));
38858
- }
38859
- function teamConfiguration(state2) {
38860
- return {
38861
- mode: state2.session.mode,
38862
- ...state2.session.teamBounds.min === void 0 ? {} : { min: state2.session.teamBounds.min },
38863
- max: state2.session.teamBounds.max
38864
- };
38865
- }
38866
- function sessionData(state2, surface) {
38867
- const teams = {};
38868
- for (const team of state2.teams) {
38869
- const own5 = {};
38870
- for (const [capability, values] of Object.entries(team.context)) {
38871
- if (!(capability in state2.shared)) own5[capability] = values;
38872
- }
38873
- teams[team.teamId] = {
38874
- context: projectContext2(own5, surface),
38875
- completedTicks: team.completedTicks,
38876
- timer: team.timer ?? IDLE_TIMER2,
38877
- // Monotonic per delivery. One session, one host, so the tick is a
38878
- // sufficient clock; the wrapper only compares it with itself.
38879
- revision: team.completedTicks
38880
- };
38881
- }
38882
- return {
38883
- // The dev server only ever sends snapshots, so the revision is a
38884
- // baseline the wrapper never compares a delta against.
38885
- shared: {
38886
- context: projectContext2(state2.shared, surface),
38887
- revision: state2.session.completedTicks
38888
- },
38889
- teams
38890
- };
38891
- }
38892
-
38893
38960
  // cli/dev/view/viewer.ts
38894
38961
  function resolveViewer(state2, route) {
38895
38962
  const base = {
@@ -39004,7 +39071,7 @@ function viewMessages(page, state2, options) {
39004
39071
  origin: options.origin,
39005
39072
  assetOrigin: options.assetOrigin,
39006
39073
  gameName: options.gameName,
39007
- hasGuide: options.hasGuide,
39074
+ overlays: options.overlays,
39008
39075
  roundProcessing: options.roundProcessing
39009
39076
  });
39010
39077
  }
@@ -39648,7 +39715,10 @@ Install the package's dependencies to serve its surfaces.
39648
39715
  origin: this.consoleOrigin(view.host),
39649
39716
  assetOrigin: origin,
39650
39717
  gameName: state2.game.name,
39651
- hasGuide: session.effectiveGuide() !== null,
39718
+ overlays: availableOverlays({
39719
+ guide: session.effectiveGuide() !== null,
39720
+ presentation: offersPresentationOverlay(session.packageConfiguration())
39721
+ }),
39652
39722
  roundProcessing
39653
39723
  });
39654
39724
  return { page, messages: messages2 };