@seriousgaming/sdk-tools 1.3.0 → 1.5.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 +4055 -2646
- package/dist/client.js +807 -172
- package/dist/core/session-host.d.ts +4 -2
- package/dist/core/settings-locks.d.ts +27 -2
- package/dist/dev/console/assets/{index-DEV8N0na.js → index-BVF8exas.js} +22 -22
- package/dist/dev/console/index.html +1 -1
- package/dist/dev/public-origins.d.ts +61 -0
- package/dist/dev/routes.d.ts +4 -0
- package/dist/dev/shell.d.ts +32 -4
- package/dist/dev/view/batch.d.ts +7 -1
- package/dist/docs/ai-agents.md +5 -0
- package/dist/docs/api/index.md +1 -1
- package/dist/docs/api/sdk-tools-client.md +1 -0
- package/dist/docs/api/sdk.md +79 -2
- package/dist/docs/changelog-0.x.md +2 -2
- package/dist/docs/changelog.md +62 -4
- package/dist/docs/cli-and-dev-server.md +58 -0
- package/dist/docs/cli-error-codes.md +39 -36
- package/dist/docs/cli-reference.md +68 -21
- package/dist/docs/concepts/terminology.md +1 -1
- package/dist/docs/environment-variables.md +10 -5
- package/dist/docs/guides/ai-facilitation.md +2 -0
- package/dist/docs/guides/capabilities.md +4 -0
- package/dist/docs/guides/designing-a-game.md +2 -0
- package/dist/docs/guides/designing-screens.md +133 -0
- package/dist/docs/guides/endpoints.md +4 -2
- package/dist/docs/guides/engine-testing.md +6 -2
- package/dist/docs/guides/engine.md +2 -0
- package/dist/docs/guides/file-handling.md +116 -22
- package/dist/docs/guides/games.md +3 -1
- package/dist/docs/guides/global-settings.md +2 -0
- package/dist/docs/guides/guide.md +2 -0
- package/dist/docs/guides/hooks.md +2 -0
- package/dist/docs/guides/index.md +9 -0
- package/dist/docs/guides/internationalization.md +2 -0
- package/dist/docs/guides/llm-integration.md +5 -3
- package/dist/docs/guides/multi-team-games.md +3 -1
- package/dist/docs/guides/patterns.md +2 -0
- package/dist/docs/guides/presentation.md +1 -1
- package/dist/docs/guides/production-constraints.md +2 -0
- package/dist/docs/guides/scenario-editor.md +3 -1
- package/dist/docs/guides/scenarios.md +15 -3
- package/dist/docs/guides/session-game-flow.md +365 -0
- package/dist/docs/guides/session-hooks.md +205 -0
- package/dist/docs/guides/session.md +27 -565
- package/dist/docs/guides/settings.md +64 -2
- package/dist/docs/guides/setup.md +3 -1
- package/dist/docs/guides/speech-generation.md +2 -0
- package/dist/docs/guides/starter-game.md +61 -21
- package/dist/docs/guides/testing.md +2 -0
- package/dist/docs/guides/tick-controller.md +3 -1
- package/dist/docs/guides/type-safety.md +2 -0
- package/dist/docs/guides/ui-files-and-llms.md +328 -0
- package/dist/docs/guides/ui-participants.md +281 -0
- package/dist/docs/guides/ui-styling.md +263 -0
- package/dist/docs/guides/ui-ticks.md +247 -0
- package/dist/docs/guides/ui.md +11 -1092
- package/dist/docs/guides/upgrading.md +2 -0
- package/dist/docs/guides/validators.md +64 -4
- package/dist/docs/guides/waiting-room.md +1 -1
- package/dist/docs/index.md +2 -1
- package/dist/docs/page-index.md +145 -0
- package/dist/docs/recipes/adapt-a-game-for-walkthroughs.md +1 -1
- package/dist/docs/recipes/adapt-ui-for-observers.md +1 -1
- package/dist/docs/recipes/create-presentation.md +11 -0
- package/dist/docs/recipes/create-scenario-editor.md +1 -0
- package/dist/docs/recipes/create-session-ui.md +2 -1
- package/dist/docs/recipes/create-setup.md +1 -0
- package/dist/docs/recipes/create-user-interface.md +1 -0
- package/dist/docs/recipes/create-waiting-room-ui.md +1 -0
- package/dist/docs/recipes/design-state-for-concurrent-writes.md +1 -1
- package/dist/docs/recipes/fix-duplicate-packages.md +2 -2
- package/dist/docs/recipes/index.md +3 -0
- package/dist/docs/recipes/screenshot-a-surface.md +80 -0
- package/dist/docs/recipes/test-a-multi-role-game.md +1 -1
- package/dist/docs/recipes/upload-and-display-files.md +7 -7
- package/dist/docs/recipes/use-request-tick.md +2 -2
- package/dist/docs/recipes/validate-scenarios.md +4 -1
- package/dist/execution/config-resolver.d.ts +4 -1
- package/dist/execution/endpoint-runner.d.ts +6 -0
- package/dist/execution/logic-calls.d.ts +7 -2
- package/dist/execution/scenario-gates.d.ts +21 -1
- package/dist/guide/settings.d.ts +1 -1
- package/dist/host.js +64 -2
- package/dist/runtime/manifest-version.d.ts +1 -1
- package/dist/runtime.js +7 -2
- package/dist/storage/asset-resolver.d.ts +24 -1
- package/dist/storage/blob-store.d.ts +7 -0
- package/dist/templates/package/CLAUDE.md.template +14 -5
- package/dist/templates/package/DESIGN.md.liquid +39 -7
- package/dist/templates/package/README.md.liquid +1 -1
- package/dist/templates/package/claude/rules/workflow-create-user-interface.md +1 -1
- package/dist/templates/package/pnpm-workspace.yaml.template +13 -0
- package/dist/templates/starter-game/capabilities/pacing/capability.sdk.json +18 -0
- package/dist/templates/starter-game/package.json +2 -0
- package/dist/templates/starter-game/presentation/defaults.ts +52 -0
- package/dist/templates/starter-game/presentation/index.html +20 -0
- package/dist/templates/starter-game/presentation/presentation.sdk.json +10 -0
- package/dist/templates/starter-game/presentation/src/App.tsx +55 -0
- package/dist/templates/starter-game/presentation/src/Band.tsx +40 -0
- package/dist/templates/starter-game/presentation/src/Slides.tsx +415 -0
- package/dist/templates/starter-game/presentation/src/WeatherIcon.tsx +21 -0
- package/dist/templates/starter-game/presentation/src/i18n.ts +88 -0
- package/dist/templates/starter-game/presentation/src/main.tsx +15 -0
- package/dist/templates/starter-game/presentation/src/stalls.test.ts +196 -0
- package/dist/templates/starter-game/presentation/src/stalls.ts +199 -0
- package/dist/templates/starter-game/presentation/types.ts +94 -0
- package/dist/templates/starter-game/seriousgaming.sdk.json +2 -1
- package/dist/templates/starter-game/session/defaults.ts +6 -0
- package/dist/templates/starter-game/session/index.html +1 -1
- package/dist/templates/starter-game/session/session.sdk.json +2 -2
- package/dist/templates/starter-game/session/src/App.test.tsx +436 -115
- package/dist/templates/starter-game/session/src/App.tsx +372 -222
- package/dist/templates/starter-game/session/src/JoinCodes.tsx +184 -0
- package/dist/templates/starter-game/session/src/ManagePanel.tsx +188 -0
- package/dist/templates/starter-game/session/src/Results.tsx +340 -0
- package/dist/templates/starter-game/session/src/SessionBar.tsx +179 -0
- package/dist/templates/starter-game/session/src/SessionPanels.tsx +105 -0
- package/dist/templates/starter-game/session/src/SidePanel.tsx +89 -0
- package/dist/templates/starter-game/session/src/StallCard.tsx +253 -0
- package/dist/templates/starter-game/session/src/TopBar.tsx +36 -0
- package/dist/templates/starter-game/session/src/i18n.ts +91 -24
- package/dist/templates/starter-game/session/src/status.ts +28 -0
- package/dist/templates/starter-game/session/types.ts +8 -2
- package/dist/templates/starter-game/shared/Awning.tsx +31 -0
- package/dist/templates/starter-game/shared/HostLogo.test.tsx +38 -0
- package/dist/templates/starter-game/shared/HostLogo.tsx +48 -0
- package/dist/templates/starter-game/shared/StallIcons.tsx +83 -0
- package/dist/templates/starter-game/shared/days.ts +11 -0
- package/dist/templates/starter-game/shared/format.test.ts +13 -0
- package/dist/templates/starter-game/{ui/src → shared}/format.ts +1 -1
- package/dist/templates/starter-game/testing/e2e/game.spec.ts +42 -8
- package/dist/templates/starter-game/ui/defaults.ts +3 -0
- package/dist/templates/starter-game/ui/src/App.test.tsx +197 -29
- package/dist/templates/starter-game/ui/src/App.tsx +176 -99
- package/dist/templates/starter-game/ui/src/DayBar.test.tsx +50 -7
- package/dist/templates/starter-game/ui/src/DayBar.tsx +96 -38
- package/dist/templates/starter-game/ui/src/DaysTable.tsx +69 -0
- package/dist/templates/starter-game/ui/src/FirstDay.tsx +37 -0
- package/dist/templates/starter-game/ui/src/Header.tsx +257 -0
- package/dist/templates/starter-game/ui/src/Lesson.tsx +63 -0
- package/dist/templates/starter-game/ui/src/MakeRow.tsx +98 -71
- package/dist/templates/starter-game/ui/src/Notices.tsx +59 -0
- package/dist/templates/starter-game/ui/src/PastDay.tsx +88 -0
- package/dist/templates/starter-game/ui/src/Section.tsx +26 -26
- package/dist/templates/starter-game/ui/src/ThemeToggle.tsx +25 -11
- package/dist/templates/starter-game/ui/src/TodayPanel.test.tsx +37 -33
- package/dist/templates/starter-game/ui/src/TodayPanel.tsx +66 -52
- package/dist/templates/starter-game/ui/src/WeatherCard.tsx +47 -0
- package/dist/templates/starter-game/ui/src/WeekOver.tsx +145 -0
- package/dist/templates/starter-game/ui/src/YesterdayPanel.tsx +65 -114
- package/dist/templates/starter-game/ui/src/days.ts +58 -0
- package/dist/templates/starter-game/ui/src/i18n.ts +86 -32
- package/dist/templates/starter-game/ui/src/test-helpers.ts +1 -0
- package/dist/templates/starter-game/ui/src/theme.ts +8 -8
- package/dist/templates/starter-game/ui/types.ts +6 -0
- package/dist/templates/starter-game/ui/ui.sdk.json +1 -1
- package/dist/templates/starter-game/validators/daylimit/defaults.ts +13 -0
- package/dist/templates/starter-game/validators/daylimit/logic/logic.test.ts +20 -0
- package/dist/templates/starter-game/validators/daylimit/logic/logic.ts +23 -0
- package/dist/templates/starter-game/validators/daylimit/types.ts +23 -0
- package/dist/templates/starter-game/validators/daylimit/validator.sdk.json +10 -0
- package/dist/templates/starter-game/waiting_room/src/App.test.tsx +83 -5
- package/dist/templates/starter-game/waiting_room/src/App.tsx +262 -119
- package/dist/templates/starter-game/waiting_room/src/i18n.ts +8 -4
- package/dist/utils/error-codes.d.ts +12 -0
- package/dist/utils/local-refs.d.ts +40 -0
- package/dist/utils/schema-members.d.ts +19 -0
- package/package.json +11 -4
- package/dist/templates/starter-game/session/src/Section.tsx +0 -37
- package/dist/templates/starter-game/session/src/TeamDoor.tsx +0 -96
- package/dist/templates/starter-game/session/src/format.ts +0 -8
- package/dist/templates/starter-game/ui/src/HistoryPanel.test.tsx +0 -74
- package/dist/templates/starter-game/ui/src/HistoryPanel.tsx +0 -120
- package/dist/templates/starter-game/ui/src/HostLogo.test.tsx +0 -25
- package/dist/templates/starter-game/ui/src/HostLogo.tsx +0 -38
|
@@ -73,6 +73,10 @@ export declare const ERROR_CODES: {
|
|
|
73
73
|
readonly category: "usage";
|
|
74
74
|
readonly description: "A file named on the command line does not exist or cannot be read.";
|
|
75
75
|
};
|
|
76
|
+
readonly DOCS_SECTION_NOT_FOUND: {
|
|
77
|
+
readonly category: "usage";
|
|
78
|
+
readonly description: "The page `docs view --section` reads has no heading by that name; the details list the ones it has.";
|
|
79
|
+
};
|
|
76
80
|
readonly RESOURCE_TYPE_UNKNOWN: {
|
|
77
81
|
readonly category: "usage";
|
|
78
82
|
readonly description: "The resource type does not exist, or does not support this operation.";
|
|
@@ -261,6 +265,10 @@ export declare const ERROR_CODES: {
|
|
|
261
265
|
readonly category: "refused";
|
|
262
266
|
readonly description: "Game logic (an engine, hook, endpoint, validator or tick controller) threw. A diagnostic, not an error code: it sits in `diagnostics` under the command's TICK_FAILED, SESSION_ERROR or HANDLER_ERROR, with the file, line and column it threw at.";
|
|
263
267
|
};
|
|
268
|
+
readonly SURFACE_NOT_RENDERED: {
|
|
269
|
+
readonly category: "refused";
|
|
270
|
+
readonly description: "`sdk screenshot` gave up on the page: its surface did not connect, or did not report its first paint before the timeout. error.details carries the page's console errors, failed requests and uncaught exceptions.";
|
|
271
|
+
};
|
|
264
272
|
readonly SETTINGS_STALE: {
|
|
265
273
|
readonly category: "refused";
|
|
266
274
|
readonly description: "The package changed on disk since the session started in a way that applies only at initialisation (a setting, a manifest field such as `teams`, or a capability removed or moved to another scope), so a command that advances or changes play was refused. Run `sdk init`.";
|
|
@@ -301,6 +309,10 @@ export declare const ERROR_CODES: {
|
|
|
301
309
|
readonly category: "environment";
|
|
302
310
|
readonly description: "The dev server could not be stopped.";
|
|
303
311
|
};
|
|
312
|
+
readonly BROWSER_MISSING: {
|
|
313
|
+
readonly category: "environment";
|
|
314
|
+
readonly description: "`sdk screenshot` found no Playwright in the package's dependencies, or no Chromium installed for it. Add `@playwright/test` and run `pnpm exec playwright install chromium`.";
|
|
315
|
+
};
|
|
304
316
|
readonly LLM_NOT_CONFIGURED: {
|
|
305
317
|
readonly category: "environment";
|
|
306
318
|
readonly description: "Logic called generateText, and the dev server or in-process session running it has no platform API key configured.";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { JSONSchema7, JSONSchema7Definition } from 'json-schema';
|
|
2
|
+
/**
|
|
3
|
+
* Local references in a resource's schema (§6.1, §6.1a): a `$ref` naming a
|
|
4
|
+
* part of the same schema, such as a subschema under `$defs` or
|
|
5
|
+
* `definitions`, so that one shape can be used in several places or contain
|
|
6
|
+
* itself. A reference resolves against the schema of the resource that holds
|
|
7
|
+
* it, never another file or another resource's schema.
|
|
8
|
+
*/
|
|
9
|
+
/** Whether `ref` names a part of the schema holding it: `#` or `#/...`. */
|
|
10
|
+
export declare function isLocalRef(ref: string): boolean;
|
|
11
|
+
/** The part of `root` a local `ref` names, or undefined when it names nothing. */
|
|
12
|
+
export declare function resolveLocalRef(root: JSONSchema7, ref: string): JSONSchema7Definition | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* `schema` with its `$ref` followed, as many times as it takes, and the
|
|
15
|
+
* keywords written beside each reference kept over the target's: a
|
|
16
|
+
* `{ "$ref": "#/$defs/rule", "default": ... }` is the rule with that default.
|
|
17
|
+
* A reference that names nothing, or a chain that comes back on itself, stops
|
|
18
|
+
* where it is, without its `$ref`; the build refuses the first, and the
|
|
19
|
+
* second describes no value.
|
|
20
|
+
*/
|
|
21
|
+
export declare function dereference(root: JSONSchema7, schema: JSONSchema7): JSONSchema7;
|
|
22
|
+
/** Every subschema directly beneath `schema`, with its JSON pointer step. */
|
|
23
|
+
export declare function childSchemas(schema: JSONSchema7): {
|
|
24
|
+
step: string;
|
|
25
|
+
schema: JSONSchema7;
|
|
26
|
+
}[];
|
|
27
|
+
/** A `$ref` the build refuses, with the JSON pointer of the subschema carrying it. */
|
|
28
|
+
export interface RefProblem {
|
|
29
|
+
pointer: string;
|
|
30
|
+
ref: string;
|
|
31
|
+
reason: 'not-local' | 'unresolved';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Every `$ref` in `schema` that is not local or names nothing in it, for the
|
|
35
|
+
* build to refuse: a runtime resolves references against the resource's own
|
|
36
|
+
* schema and nothing else (§6.1a), so either would leave a value unchecked.
|
|
37
|
+
*/
|
|
38
|
+
export declare function refProblems(schema: JSONSchema7): RefProblem[];
|
|
39
|
+
/** A {@link RefProblem} as a build error line. */
|
|
40
|
+
export declare function refProblemMessage(owner: string, keyword: string, problem: RefProblem): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
+
/**
|
|
3
|
+
* The subschemas a value under `key` of an object is held to: its entry in
|
|
4
|
+
* `properties`, every `patternProperties` schema whose pattern the key
|
|
5
|
+
* matches, and `additionalProperties` when it is a schema and neither of the
|
|
6
|
+
* others applies, as JSON Schema applies them. A keyed map, the shape a
|
|
7
|
+
* setting takes when scenarios add and remove its entries, is declared
|
|
8
|
+
* through the last two.
|
|
9
|
+
*/
|
|
10
|
+
export declare function memberSchemas(schema: JSONSchema7, key: string): JSONSchema7[];
|
|
11
|
+
/**
|
|
12
|
+
* Every subschema an object's members are declared by, with the step a path
|
|
13
|
+
* through it takes: the property's name, `*` for `additionalProperties`, or
|
|
14
|
+
* the pattern between slashes for a `patternProperties` entry.
|
|
15
|
+
*/
|
|
16
|
+
export declare function memberDeclarations(schema: JSONSchema7): {
|
|
17
|
+
step: string;
|
|
18
|
+
schema: JSONSchema7;
|
|
19
|
+
}[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seriousgaming/sdk-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "SDK tooling for building Serious Gaming games",
|
|
5
5
|
"homepage": "https://sdk.seriousgaming.com/",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@mui/icons-material": "^9.4.0",
|
|
71
71
|
"@mui/material": "^9.4.0",
|
|
72
72
|
"@playwright/test": "^1.64.0",
|
|
73
|
-
"@seriousgaming/sdk": "1.
|
|
73
|
+
"@seriousgaming/sdk": "1.5.0",
|
|
74
74
|
"@testing-library/jest-dom": "^7.0.1",
|
|
75
75
|
"@testing-library/react": "^16.3.3",
|
|
76
76
|
"@types/adm-zip": "^0.5.8",
|
|
@@ -99,7 +99,13 @@
|
|
|
99
99
|
"vitest": "^5.0.3"
|
|
100
100
|
},
|
|
101
101
|
"peerDependencies": {
|
|
102
|
-
"@
|
|
102
|
+
"@playwright/test": ">=1.50.0",
|
|
103
|
+
"@seriousgaming/sdk": "^1.5.0"
|
|
104
|
+
},
|
|
105
|
+
"peerDependenciesMeta": {
|
|
106
|
+
"@playwright/test": {
|
|
107
|
+
"optional": true
|
|
108
|
+
}
|
|
103
109
|
},
|
|
104
110
|
"engines": {
|
|
105
111
|
"node": ">=24"
|
|
@@ -117,8 +123,9 @@
|
|
|
117
123
|
"test:run": "vitest run && vitest run --config cli/dev/console/vitest.config.ts",
|
|
118
124
|
"test:coverage": "vitest run --coverage",
|
|
119
125
|
"test:run:coverage": "vitest run --coverage && vitest run --config cli/dev/console/vitest.config.ts",
|
|
120
|
-
"test:e2e": "pnpm run test:e2e:cli && pnpm run test:integration && pnpm run test:e2e:ui",
|
|
126
|
+
"test:e2e": "pnpm run test:e2e:cli && pnpm run test:e2e:browser && pnpm run test:integration && pnpm run test:e2e:ui",
|
|
121
127
|
"test:e2e:cli": "vitest run --config e2e/vitest.e2e.config.ts",
|
|
128
|
+
"test:e2e:browser": "vitest run --config e2e/vitest.e2e.browser.config.ts",
|
|
122
129
|
"test:integration": "vitest run --config integration/vitest.integration.config.ts",
|
|
123
130
|
"test:conformance": "vitest run --config conformance/vitest.conformance.config.ts",
|
|
124
131
|
"conformance:report": "CONFORMANCE_REPORT=1 vitest run --config conformance/vitest.conformance.config.ts",
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Box, Card, CardContent, Stack, Typography } from '@mui/material';
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
type Props = {
|
|
5
|
-
title: string;
|
|
6
|
-
hint?: string;
|
|
7
|
-
action?: ReactNode;
|
|
8
|
-
children: ReactNode;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/** One card, one heading, one job. Every panel on this surface is built of these. */
|
|
12
|
-
export default function Section({ title, hint, action, children }: Props) {
|
|
13
|
-
return (
|
|
14
|
-
<Card variant="outlined">
|
|
15
|
-
<CardContent>
|
|
16
|
-
<Stack
|
|
17
|
-
direction="row"
|
|
18
|
-
spacing={2}
|
|
19
|
-
sx={{ alignItems: 'flex-start', justifyContent: 'space-between' }}
|
|
20
|
-
>
|
|
21
|
-
<Box>
|
|
22
|
-
<Typography variant="h6" component="h2">
|
|
23
|
-
{title}
|
|
24
|
-
</Typography>
|
|
25
|
-
{hint && (
|
|
26
|
-
<Typography variant="body2" color="text.secondary">
|
|
27
|
-
{hint}
|
|
28
|
-
</Typography>
|
|
29
|
-
)}
|
|
30
|
-
</Box>
|
|
31
|
-
{action}
|
|
32
|
-
</Stack>
|
|
33
|
-
<Box sx={{ mt: 2 }}>{children}</Box>
|
|
34
|
-
</CardContent>
|
|
35
|
-
</Card>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Button, Stack, Tooltip, Typography } from '@mui/material';
|
|
2
|
-
import type { TeamLinks } from '@seriousgaming/sdk/ui';
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
import { useTranslation } from 'react-i18next';
|
|
5
|
-
|
|
6
|
-
type Props = {
|
|
7
|
-
links: TeamLinks | undefined;
|
|
8
|
-
teamName: string;
|
|
9
|
-
show: boolean;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The two ways a facilitator gets into a stall: observing, and joining.
|
|
14
|
-
*
|
|
15
|
-
* Both are one click. Reading a URL out of a table and typing it into another
|
|
16
|
-
* tab is the thing a facilitator actually does half a dozen times a session,
|
|
17
|
-
* and it is the slowest part of running one.
|
|
18
|
-
*
|
|
19
|
-
* `target="_blank"` rather than navigating this frame: a session surface owns
|
|
20
|
-
* the whole canvas, and replacing it with a player's screen would leave the
|
|
21
|
-
* facilitator with no way back. The host grants `allow-popups` and
|
|
22
|
-
* `allow-popups-to-escape-sandbox` for exactly this.
|
|
23
|
-
*
|
|
24
|
-
* The two links are not the same kind of thing, and the labels say so.
|
|
25
|
-
* Observing admits nobody: an observer has no participant record and no
|
|
26
|
-
* presence, so the stall never sees a fourth person appear. Joining is a real
|
|
27
|
-
* seat at a real stall, which is what you want when you are showing somebody
|
|
28
|
-
* how it works and not what you want when you are checking on them.
|
|
29
|
-
*/
|
|
30
|
-
export default function TeamDoor({ links, teamName, show }: Props) {
|
|
31
|
-
const { t } = useTranslation();
|
|
32
|
-
const [copied, setCopied] = useState(false);
|
|
33
|
-
const [reveal, setReveal] = useState(false);
|
|
34
|
-
|
|
35
|
-
// Empty until the host delivers them, which is one frame rather than never.
|
|
36
|
-
if (!links || !show) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const copyJoinLink = async () => {
|
|
41
|
-
// Feature-detected: `clipboard-write` is delegated to this frame, but
|
|
42
|
-
// Permissions Policy is implemented unevenly and a browser may gate the
|
|
43
|
-
// write on a gesture it does not think it had. Falling back to showing
|
|
44
|
-
// the URL is worse than copying and better than a button that does
|
|
45
|
-
// nothing.
|
|
46
|
-
try {
|
|
47
|
-
await navigator.clipboard.writeText(links.joinUrl);
|
|
48
|
-
setCopied(true);
|
|
49
|
-
setReveal(false);
|
|
50
|
-
} catch {
|
|
51
|
-
setReveal(true);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
<Stack spacing={0.5}>
|
|
57
|
-
<Stack direction="row" spacing={1}>
|
|
58
|
-
<Button
|
|
59
|
-
size="small"
|
|
60
|
-
variant="outlined"
|
|
61
|
-
component="a"
|
|
62
|
-
href={links.observeUrl}
|
|
63
|
-
target="_blank"
|
|
64
|
-
rel="noopener"
|
|
65
|
-
>
|
|
66
|
-
{t('door.observe')}
|
|
67
|
-
</Button>
|
|
68
|
-
<Button
|
|
69
|
-
size="small"
|
|
70
|
-
component="a"
|
|
71
|
-
href={links.joinUrl}
|
|
72
|
-
target="_blank"
|
|
73
|
-
rel="noopener"
|
|
74
|
-
>
|
|
75
|
-
{t('door.join')}
|
|
76
|
-
</Button>
|
|
77
|
-
<Tooltip title={t('door.copyHint', { team: teamName })}>
|
|
78
|
-
<Button
|
|
79
|
-
size="small"
|
|
80
|
-
color="inherit"
|
|
81
|
-
aria-label={t('door.copy', { team: teamName })}
|
|
82
|
-
onClick={() => void copyJoinLink()}
|
|
83
|
-
onMouseLeave={() => setCopied(false)}
|
|
84
|
-
>
|
|
85
|
-
{copied ? t('door.copied') : t('door.copyShort')}
|
|
86
|
-
</Button>
|
|
87
|
-
</Tooltip>
|
|
88
|
-
</Stack>
|
|
89
|
-
{reveal && (
|
|
90
|
-
<Typography variant="caption" sx={{ fontFamily: 'monospace', userSelect: 'all' }}>
|
|
91
|
-
{links.joinUrl}
|
|
92
|
-
</Typography>
|
|
93
|
-
)}
|
|
94
|
-
</Stack>
|
|
95
|
-
);
|
|
96
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/** Display helpers shared by the panels, so one round of a number is decided once. */
|
|
2
|
-
|
|
3
|
-
export const money = (prefix: string, value: number) =>
|
|
4
|
-
`${value < 0 ? '-' : ''}${prefix}${Math.abs(Math.round(value)).toLocaleString()}`;
|
|
5
|
-
|
|
6
|
-
export const percent = (fraction: number) => `${Math.round(fraction * 100)}%`;
|
|
7
|
-
|
|
8
|
-
export const units = (value: number) => Math.round(value).toLocaleString();
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { renderUserInterface } from '@seriousgaming/sdk/ui/testing';
|
|
2
|
-
import { screen, waitFor } from '@testing-library/react';
|
|
3
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
-
|
|
5
|
-
import type { Context } from '../types';
|
|
6
|
-
import HistoryPanel from './HistoryPanel';
|
|
7
|
-
import './i18n';
|
|
8
|
-
import { baseSettings, baseContext, playedDay } from './test-helpers';
|
|
9
|
-
|
|
10
|
-
/** Day `n`'s results, as the round that closed it recorded them. */
|
|
11
|
-
function dayResults(n: number, profit: number): Context['results'] {
|
|
12
|
-
return { ...playedDay.results, Day: n, Profit: profit, Purse: profit * n };
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe('HistoryPanel', () => {
|
|
16
|
-
it('shows nothing before the first day has been played', () => {
|
|
17
|
-
renderUserInterface(<HistoryPanel />, { data: baseContext, settings: baseSettings });
|
|
18
|
-
|
|
19
|
-
expect(screen.queryByText('Every day so far')).not.toBeInTheDocument();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('lists the earlier days from the host, and today from live context', async () => {
|
|
23
|
-
const getPastState = vi.fn(async () => [
|
|
24
|
-
{
|
|
25
|
-
teamId: 'team-1',
|
|
26
|
-
index: 0,
|
|
27
|
-
name: 'Team 1',
|
|
28
|
-
tick: 1,
|
|
29
|
-
recordedAt: 0,
|
|
30
|
-
complete: false,
|
|
31
|
-
context: { results: dayResults(1, 100) },
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
teamId: 'team-1',
|
|
35
|
-
index: 0,
|
|
36
|
-
name: 'Team 1',
|
|
37
|
-
tick: 2,
|
|
38
|
-
recordedAt: 0,
|
|
39
|
-
complete: false,
|
|
40
|
-
context: { results: dayResults(2, 200) },
|
|
41
|
-
},
|
|
42
|
-
]);
|
|
43
|
-
|
|
44
|
-
renderUserInterface(<HistoryPanel />, {
|
|
45
|
-
data: { ...playedDay, results: dayResults(3, 300) },
|
|
46
|
-
settings: baseSettings,
|
|
47
|
-
completedTicks: 3,
|
|
48
|
-
callbacks: { getPastState: getPastState as never },
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
await waitFor(() => expect(screen.getByTestId('day-1')).toBeInTheDocument());
|
|
52
|
-
expect(screen.getByTestId('day-2')).toBeInTheDocument();
|
|
53
|
-
expect(screen.getByTestId('day-3')).toBeInTheDocument();
|
|
54
|
-
expect(getPastState).toHaveBeenCalledWith({
|
|
55
|
-
fromTick: 1,
|
|
56
|
-
toTick: 3,
|
|
57
|
-
capabilityIds: ['results'],
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('still shows today when the history cannot be read', async () => {
|
|
62
|
-
renderUserInterface(<HistoryPanel />, {
|
|
63
|
-
data: { ...playedDay, results: dayResults(2, 200) },
|
|
64
|
-
settings: baseSettings,
|
|
65
|
-
completedTicks: 2,
|
|
66
|
-
callbacks: {
|
|
67
|
-
getPastState: vi.fn(async () => Promise.reject(new Error('no'))) as never,
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
await waitFor(() => expect(screen.getByTestId('day-2')).toBeInTheDocument());
|
|
72
|
-
expect(screen.queryByTestId('day-1')).not.toBeInTheDocument();
|
|
73
|
-
});
|
|
74
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { Box, Table, TableBody, TableCell, TableHead, TableRow, Typography } from '@mui/material';
|
|
2
|
-
import { useUserInterfaceCallbacks, useUserInterfaceData } from '@seriousgaming/sdk/ui';
|
|
3
|
-
import { useEffect, useState } from 'react';
|
|
4
|
-
import { useTranslation } from 'react-i18next';
|
|
5
|
-
|
|
6
|
-
import type { Settings, Context } from '../types';
|
|
7
|
-
import { count, money } from './format';
|
|
8
|
-
import Section from './Section';
|
|
9
|
-
|
|
10
|
-
type DayResults = Context['results'];
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Every day the stall has traded, read back from the host's history.
|
|
14
|
-
*
|
|
15
|
-
* The engine keeps only today's `results` in context. Each earlier day is in
|
|
16
|
-
* the round the team closed, which `getPastState` returns, so the table asks
|
|
17
|
-
* for those and adds today's from live context. Nothing grows in context as
|
|
18
|
-
* the days go by, which is what keeps a long session cheap.
|
|
19
|
-
*
|
|
20
|
-
* The history changes only when a tick commits or is undone, and both change
|
|
21
|
-
* `completedTicks`, so that is what the fetch waits on.
|
|
22
|
-
*/
|
|
23
|
-
export default function HistoryPanel() {
|
|
24
|
-
const { data, settings, completedTicks } = useUserInterfaceData<Context, Settings>();
|
|
25
|
-
const { getPastState } = useUserInterfaceCallbacks();
|
|
26
|
-
const { t } = useTranslation();
|
|
27
|
-
const symbol = settings.ui.CurrencySymbol;
|
|
28
|
-
|
|
29
|
-
const [past, setPast] = useState<DayResults[]>([]);
|
|
30
|
-
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
if (completedTicks < 2) {
|
|
33
|
-
setPast([]);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
let cancelled = false;
|
|
37
|
-
getPastState<Context>({ fromTick: 1, toTick: completedTicks, capabilityIds: ['results'] })
|
|
38
|
-
.then((entries) => {
|
|
39
|
-
if (!cancelled) setPast(entries.map((entry) => entry.context.results));
|
|
40
|
-
})
|
|
41
|
-
// History is a nice-to-have on this screen: a failed read leaves the
|
|
42
|
-
// table showing today alone rather than an error.
|
|
43
|
-
.catch(() => {
|
|
44
|
-
if (!cancelled) setPast([]);
|
|
45
|
-
});
|
|
46
|
-
return () => {
|
|
47
|
-
cancelled = true;
|
|
48
|
-
};
|
|
49
|
-
}, [completedTicks, getPastState]);
|
|
50
|
-
|
|
51
|
-
const byDay = new Map<number, DayResults>();
|
|
52
|
-
for (const results of [...past, data.results]) {
|
|
53
|
-
if (results.Day > 0) byDay.set(results.Day, results);
|
|
54
|
-
}
|
|
55
|
-
const days = [...byDay.values()].sort((a, b) => a.Day - b.Day);
|
|
56
|
-
|
|
57
|
-
if (days.length === 0) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const best = Math.max(...days.map((day) => day.Profit));
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<Section title={t('history.title')} hint={t('history.hint')}>
|
|
65
|
-
<Box sx={{ overflowX: 'auto' }}>
|
|
66
|
-
<Table size="small">
|
|
67
|
-
<TableHead>
|
|
68
|
-
<TableRow>
|
|
69
|
-
<TableCell>{t('history.day')}</TableCell>
|
|
70
|
-
<TableCell>{t('history.weather')}</TableCell>
|
|
71
|
-
<TableCell align="right">{t('yesterday.made')}</TableCell>
|
|
72
|
-
<TableCell align="right">{t('yesterday.sold')}</TableCell>
|
|
73
|
-
<TableCell align="right">{t('yesterday.pouredAway')}</TableCell>
|
|
74
|
-
<TableCell align="right">{t('yesterday.turnedAway')}</TableCell>
|
|
75
|
-
<TableCell align="right">{t('yesterday.profit')}</TableCell>
|
|
76
|
-
<TableCell align="right">{t('yesterday.purse')}</TableCell>
|
|
77
|
-
</TableRow>
|
|
78
|
-
</TableHead>
|
|
79
|
-
<TableBody>
|
|
80
|
-
{days.map((day) => {
|
|
81
|
-
const totals = totalsOf(day);
|
|
82
|
-
return (
|
|
83
|
-
<TableRow key={day.Day} data-testid={`day-${day.Day}`}>
|
|
84
|
-
<TableCell>{day.Day}</TableCell>
|
|
85
|
-
<TableCell>
|
|
86
|
-
<Typography variant="body2">
|
|
87
|
-
{t(`weather.${day.Weather}Short`)}
|
|
88
|
-
</Typography>
|
|
89
|
-
</TableCell>
|
|
90
|
-
<TableCell align="right">{count(totals.made)}</TableCell>
|
|
91
|
-
<TableCell align="right">{count(totals.sold)}</TableCell>
|
|
92
|
-
<TableCell align="right">{count(totals.pouredAway)}</TableCell>
|
|
93
|
-
<TableCell align="right">{count(totals.turnedAway)}</TableCell>
|
|
94
|
-
<TableCell
|
|
95
|
-
align="right"
|
|
96
|
-
sx={day.Profit === best ? { fontWeight: 700 } : undefined}
|
|
97
|
-
>
|
|
98
|
-
{money(symbol, day.Profit)}
|
|
99
|
-
</TableCell>
|
|
100
|
-
<TableCell align="right">{money(symbol, day.Purse)}</TableCell>
|
|
101
|
-
</TableRow>
|
|
102
|
-
);
|
|
103
|
-
})}
|
|
104
|
-
</TableBody>
|
|
105
|
-
</Table>
|
|
106
|
-
</Box>
|
|
107
|
-
</Section>
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** The day's lines, added up across the menu. */
|
|
112
|
-
function totalsOf(results: DayResults) {
|
|
113
|
-
const lines = Object.values(results.Lines);
|
|
114
|
-
return {
|
|
115
|
-
made: lines.reduce((sum, line) => sum + line.Made, 0),
|
|
116
|
-
sold: lines.reduce((sum, line) => sum + line.Sold, 0),
|
|
117
|
-
pouredAway: lines.reduce((sum, line) => sum + line.PouredAway, 0),
|
|
118
|
-
turnedAway: lines.reduce((sum, line) => sum + line.TurnedAway, 0),
|
|
119
|
-
};
|
|
120
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createMockBrand,
|
|
3
|
-
createMockUserInterfaceTheme,
|
|
4
|
-
renderUserInterface,
|
|
5
|
-
} from '@seriousgaming/sdk/ui/testing';
|
|
6
|
-
import { screen } from '@testing-library/react';
|
|
7
|
-
import { describe, expect, it } from 'vitest';
|
|
8
|
-
|
|
9
|
-
import HostLogo from './HostLogo';
|
|
10
|
-
|
|
11
|
-
describe('the host logo', () => {
|
|
12
|
-
it("shows the host's logo, named for the host", () => {
|
|
13
|
-
const brand = createMockBrand({ name: 'Northwind' });
|
|
14
|
-
renderUserInterface(<HostLogo />, { theme: createMockUserInterfaceTheme({ brand }) });
|
|
15
|
-
|
|
16
|
-
const logo = screen.getByRole('img', { name: 'Northwind' });
|
|
17
|
-
expect(logo).toHaveAttribute('src', brand.logo?.onLight);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('shows nothing when the host sends no logo', () => {
|
|
21
|
-
renderUserInterface(<HostLogo />);
|
|
22
|
-
|
|
23
|
-
expect(screen.queryByTestId('host-logo')).not.toBeInTheDocument();
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Box, useTheme } from '@mui/material';
|
|
2
|
-
import { useBrandLogo } from '@seriousgaming/sdk/ui';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The host's logo, where it sends one, so the stall sits inside whoever is
|
|
6
|
-
* running the session. Nothing at all when the host sends no logo.
|
|
7
|
-
*
|
|
8
|
-
* A host that sent only the other variant gets a panel of the colour the
|
|
9
|
-
* artwork was drawn for, rather than dark ink on a dark bar.
|
|
10
|
-
*/
|
|
11
|
-
export default function HostLogo() {
|
|
12
|
-
const logo = useBrandLogo();
|
|
13
|
-
const mode = useTheme().palette.mode;
|
|
14
|
-
if (!logo) return null;
|
|
15
|
-
|
|
16
|
-
const mismatched = logo.drawnFor !== mode;
|
|
17
|
-
return (
|
|
18
|
-
<Box
|
|
19
|
-
component="img"
|
|
20
|
-
src={logo.src}
|
|
21
|
-
alt={logo.alt}
|
|
22
|
-
data-testid="host-logo"
|
|
23
|
-
sx={{
|
|
24
|
-
height: 28,
|
|
25
|
-
maxWidth: 140,
|
|
26
|
-
objectFit: 'contain',
|
|
27
|
-
flexShrink: 0,
|
|
28
|
-
...(mismatched && {
|
|
29
|
-
bgcolor: logo.drawnFor === 'light' ? '#ffffff' : '#121212',
|
|
30
|
-
borderRadius: 1,
|
|
31
|
-
px: 1,
|
|
32
|
-
py: 0.5,
|
|
33
|
-
boxSizing: 'content-box',
|
|
34
|
-
}),
|
|
35
|
-
}}
|
|
36
|
-
/>
|
|
37
|
-
);
|
|
38
|
-
}
|