@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.
Files changed (176) hide show
  1. package/dist/cli.js +4055 -2646
  2. package/dist/client.js +807 -172
  3. package/dist/core/session-host.d.ts +4 -2
  4. package/dist/core/settings-locks.d.ts +27 -2
  5. package/dist/dev/console/assets/{index-DEV8N0na.js → index-BVF8exas.js} +22 -22
  6. package/dist/dev/console/index.html +1 -1
  7. package/dist/dev/public-origins.d.ts +61 -0
  8. package/dist/dev/routes.d.ts +4 -0
  9. package/dist/dev/shell.d.ts +32 -4
  10. package/dist/dev/view/batch.d.ts +7 -1
  11. package/dist/docs/ai-agents.md +5 -0
  12. package/dist/docs/api/index.md +1 -1
  13. package/dist/docs/api/sdk-tools-client.md +1 -0
  14. package/dist/docs/api/sdk.md +79 -2
  15. package/dist/docs/changelog-0.x.md +2 -2
  16. package/dist/docs/changelog.md +62 -4
  17. package/dist/docs/cli-and-dev-server.md +58 -0
  18. package/dist/docs/cli-error-codes.md +39 -36
  19. package/dist/docs/cli-reference.md +68 -21
  20. package/dist/docs/concepts/terminology.md +1 -1
  21. package/dist/docs/environment-variables.md +10 -5
  22. package/dist/docs/guides/ai-facilitation.md +2 -0
  23. package/dist/docs/guides/capabilities.md +4 -0
  24. package/dist/docs/guides/designing-a-game.md +2 -0
  25. package/dist/docs/guides/designing-screens.md +133 -0
  26. package/dist/docs/guides/endpoints.md +4 -2
  27. package/dist/docs/guides/engine-testing.md +6 -2
  28. package/dist/docs/guides/engine.md +2 -0
  29. package/dist/docs/guides/file-handling.md +116 -22
  30. package/dist/docs/guides/games.md +3 -1
  31. package/dist/docs/guides/global-settings.md +2 -0
  32. package/dist/docs/guides/guide.md +2 -0
  33. package/dist/docs/guides/hooks.md +2 -0
  34. package/dist/docs/guides/index.md +9 -0
  35. package/dist/docs/guides/internationalization.md +2 -0
  36. package/dist/docs/guides/llm-integration.md +5 -3
  37. package/dist/docs/guides/multi-team-games.md +3 -1
  38. package/dist/docs/guides/patterns.md +2 -0
  39. package/dist/docs/guides/presentation.md +1 -1
  40. package/dist/docs/guides/production-constraints.md +2 -0
  41. package/dist/docs/guides/scenario-editor.md +3 -1
  42. package/dist/docs/guides/scenarios.md +15 -3
  43. package/dist/docs/guides/session-game-flow.md +365 -0
  44. package/dist/docs/guides/session-hooks.md +205 -0
  45. package/dist/docs/guides/session.md +27 -565
  46. package/dist/docs/guides/settings.md +64 -2
  47. package/dist/docs/guides/setup.md +3 -1
  48. package/dist/docs/guides/speech-generation.md +2 -0
  49. package/dist/docs/guides/starter-game.md +61 -21
  50. package/dist/docs/guides/testing.md +2 -0
  51. package/dist/docs/guides/tick-controller.md +3 -1
  52. package/dist/docs/guides/type-safety.md +2 -0
  53. package/dist/docs/guides/ui-files-and-llms.md +328 -0
  54. package/dist/docs/guides/ui-participants.md +281 -0
  55. package/dist/docs/guides/ui-styling.md +263 -0
  56. package/dist/docs/guides/ui-ticks.md +247 -0
  57. package/dist/docs/guides/ui.md +11 -1092
  58. package/dist/docs/guides/upgrading.md +2 -0
  59. package/dist/docs/guides/validators.md +64 -4
  60. package/dist/docs/guides/waiting-room.md +1 -1
  61. package/dist/docs/index.md +2 -1
  62. package/dist/docs/page-index.md +145 -0
  63. package/dist/docs/recipes/adapt-a-game-for-walkthroughs.md +1 -1
  64. package/dist/docs/recipes/adapt-ui-for-observers.md +1 -1
  65. package/dist/docs/recipes/create-presentation.md +11 -0
  66. package/dist/docs/recipes/create-scenario-editor.md +1 -0
  67. package/dist/docs/recipes/create-session-ui.md +2 -1
  68. package/dist/docs/recipes/create-setup.md +1 -0
  69. package/dist/docs/recipes/create-user-interface.md +1 -0
  70. package/dist/docs/recipes/create-waiting-room-ui.md +1 -0
  71. package/dist/docs/recipes/design-state-for-concurrent-writes.md +1 -1
  72. package/dist/docs/recipes/fix-duplicate-packages.md +2 -2
  73. package/dist/docs/recipes/index.md +3 -0
  74. package/dist/docs/recipes/screenshot-a-surface.md +80 -0
  75. package/dist/docs/recipes/test-a-multi-role-game.md +1 -1
  76. package/dist/docs/recipes/upload-and-display-files.md +7 -7
  77. package/dist/docs/recipes/use-request-tick.md +2 -2
  78. package/dist/docs/recipes/validate-scenarios.md +4 -1
  79. package/dist/execution/config-resolver.d.ts +4 -1
  80. package/dist/execution/endpoint-runner.d.ts +6 -0
  81. package/dist/execution/logic-calls.d.ts +7 -2
  82. package/dist/execution/scenario-gates.d.ts +21 -1
  83. package/dist/guide/settings.d.ts +1 -1
  84. package/dist/host.js +64 -2
  85. package/dist/runtime/manifest-version.d.ts +1 -1
  86. package/dist/runtime.js +7 -2
  87. package/dist/storage/asset-resolver.d.ts +24 -1
  88. package/dist/storage/blob-store.d.ts +7 -0
  89. package/dist/templates/package/CLAUDE.md.template +14 -5
  90. package/dist/templates/package/DESIGN.md.liquid +39 -7
  91. package/dist/templates/package/README.md.liquid +1 -1
  92. package/dist/templates/package/claude/rules/workflow-create-user-interface.md +1 -1
  93. package/dist/templates/package/pnpm-workspace.yaml.template +13 -0
  94. package/dist/templates/starter-game/capabilities/pacing/capability.sdk.json +18 -0
  95. package/dist/templates/starter-game/package.json +2 -0
  96. package/dist/templates/starter-game/presentation/defaults.ts +52 -0
  97. package/dist/templates/starter-game/presentation/index.html +20 -0
  98. package/dist/templates/starter-game/presentation/presentation.sdk.json +10 -0
  99. package/dist/templates/starter-game/presentation/src/App.tsx +55 -0
  100. package/dist/templates/starter-game/presentation/src/Band.tsx +40 -0
  101. package/dist/templates/starter-game/presentation/src/Slides.tsx +415 -0
  102. package/dist/templates/starter-game/presentation/src/WeatherIcon.tsx +21 -0
  103. package/dist/templates/starter-game/presentation/src/i18n.ts +88 -0
  104. package/dist/templates/starter-game/presentation/src/main.tsx +15 -0
  105. package/dist/templates/starter-game/presentation/src/stalls.test.ts +196 -0
  106. package/dist/templates/starter-game/presentation/src/stalls.ts +199 -0
  107. package/dist/templates/starter-game/presentation/types.ts +94 -0
  108. package/dist/templates/starter-game/seriousgaming.sdk.json +2 -1
  109. package/dist/templates/starter-game/session/defaults.ts +6 -0
  110. package/dist/templates/starter-game/session/index.html +1 -1
  111. package/dist/templates/starter-game/session/session.sdk.json +2 -2
  112. package/dist/templates/starter-game/session/src/App.test.tsx +436 -115
  113. package/dist/templates/starter-game/session/src/App.tsx +372 -222
  114. package/dist/templates/starter-game/session/src/JoinCodes.tsx +184 -0
  115. package/dist/templates/starter-game/session/src/ManagePanel.tsx +188 -0
  116. package/dist/templates/starter-game/session/src/Results.tsx +340 -0
  117. package/dist/templates/starter-game/session/src/SessionBar.tsx +179 -0
  118. package/dist/templates/starter-game/session/src/SessionPanels.tsx +105 -0
  119. package/dist/templates/starter-game/session/src/SidePanel.tsx +89 -0
  120. package/dist/templates/starter-game/session/src/StallCard.tsx +253 -0
  121. package/dist/templates/starter-game/session/src/TopBar.tsx +36 -0
  122. package/dist/templates/starter-game/session/src/i18n.ts +91 -24
  123. package/dist/templates/starter-game/session/src/status.ts +28 -0
  124. package/dist/templates/starter-game/session/types.ts +8 -2
  125. package/dist/templates/starter-game/shared/Awning.tsx +31 -0
  126. package/dist/templates/starter-game/shared/HostLogo.test.tsx +38 -0
  127. package/dist/templates/starter-game/shared/HostLogo.tsx +48 -0
  128. package/dist/templates/starter-game/shared/StallIcons.tsx +83 -0
  129. package/dist/templates/starter-game/shared/days.ts +11 -0
  130. package/dist/templates/starter-game/shared/format.test.ts +13 -0
  131. package/dist/templates/starter-game/{ui/src → shared}/format.ts +1 -1
  132. package/dist/templates/starter-game/testing/e2e/game.spec.ts +42 -8
  133. package/dist/templates/starter-game/ui/defaults.ts +3 -0
  134. package/dist/templates/starter-game/ui/src/App.test.tsx +197 -29
  135. package/dist/templates/starter-game/ui/src/App.tsx +176 -99
  136. package/dist/templates/starter-game/ui/src/DayBar.test.tsx +50 -7
  137. package/dist/templates/starter-game/ui/src/DayBar.tsx +96 -38
  138. package/dist/templates/starter-game/ui/src/DaysTable.tsx +69 -0
  139. package/dist/templates/starter-game/ui/src/FirstDay.tsx +37 -0
  140. package/dist/templates/starter-game/ui/src/Header.tsx +257 -0
  141. package/dist/templates/starter-game/ui/src/Lesson.tsx +63 -0
  142. package/dist/templates/starter-game/ui/src/MakeRow.tsx +98 -71
  143. package/dist/templates/starter-game/ui/src/Notices.tsx +59 -0
  144. package/dist/templates/starter-game/ui/src/PastDay.tsx +88 -0
  145. package/dist/templates/starter-game/ui/src/Section.tsx +26 -26
  146. package/dist/templates/starter-game/ui/src/ThemeToggle.tsx +25 -11
  147. package/dist/templates/starter-game/ui/src/TodayPanel.test.tsx +37 -33
  148. package/dist/templates/starter-game/ui/src/TodayPanel.tsx +66 -52
  149. package/dist/templates/starter-game/ui/src/WeatherCard.tsx +47 -0
  150. package/dist/templates/starter-game/ui/src/WeekOver.tsx +145 -0
  151. package/dist/templates/starter-game/ui/src/YesterdayPanel.tsx +65 -114
  152. package/dist/templates/starter-game/ui/src/days.ts +58 -0
  153. package/dist/templates/starter-game/ui/src/i18n.ts +86 -32
  154. package/dist/templates/starter-game/ui/src/test-helpers.ts +1 -0
  155. package/dist/templates/starter-game/ui/src/theme.ts +8 -8
  156. package/dist/templates/starter-game/ui/types.ts +6 -0
  157. package/dist/templates/starter-game/ui/ui.sdk.json +1 -1
  158. package/dist/templates/starter-game/validators/daylimit/defaults.ts +13 -0
  159. package/dist/templates/starter-game/validators/daylimit/logic/logic.test.ts +20 -0
  160. package/dist/templates/starter-game/validators/daylimit/logic/logic.ts +23 -0
  161. package/dist/templates/starter-game/validators/daylimit/types.ts +23 -0
  162. package/dist/templates/starter-game/validators/daylimit/validator.sdk.json +10 -0
  163. package/dist/templates/starter-game/waiting_room/src/App.test.tsx +83 -5
  164. package/dist/templates/starter-game/waiting_room/src/App.tsx +262 -119
  165. package/dist/templates/starter-game/waiting_room/src/i18n.ts +8 -4
  166. package/dist/utils/error-codes.d.ts +12 -0
  167. package/dist/utils/local-refs.d.ts +40 -0
  168. package/dist/utils/schema-members.d.ts +19 -0
  169. package/package.json +11 -4
  170. package/dist/templates/starter-game/session/src/Section.tsx +0 -37
  171. package/dist/templates/starter-game/session/src/TeamDoor.tsx +0 -96
  172. package/dist/templates/starter-game/session/src/format.ts +0 -8
  173. package/dist/templates/starter-game/ui/src/HistoryPanel.test.tsx +0 -74
  174. package/dist/templates/starter-game/ui/src/HistoryPanel.tsx +0 -120
  175. package/dist/templates/starter-game/ui/src/HostLogo.test.tsx +0 -25
  176. package/dist/templates/starter-game/ui/src/HostLogo.tsx +0 -38
@@ -0,0 +1,88 @@
1
+ import {
2
+ Box,
3
+ Skeleton,
4
+ Table,
5
+ TableBody,
6
+ TableCell,
7
+ TableHead,
8
+ TableRow,
9
+ Typography,
10
+ } from '@mui/material';
11
+ import { useUserInterfaceData } from '@seriousgaming/sdk/ui';
12
+ import { useTranslation } from 'react-i18next';
13
+
14
+ import { count } from '../../shared/format';
15
+ import type { Context, Settings } from '../types';
16
+ import type { DayResults } from './days';
17
+ import Lesson from './Lesson';
18
+ import { menuOf } from './menu';
19
+ import Section from './Section';
20
+ import { ProfitFigure } from './YesterdayPanel';
21
+
22
+ /**
23
+ * One finished day, item by item, read from the host's history.
24
+ *
25
+ * Read-only by construction: nothing on this view writes, so looking back can
26
+ * never change a past day or disturb the plan the team is building for today.
27
+ * The plan stays in context the whole time, which is why coming back finds it
28
+ * exactly as it was left.
29
+ */
30
+ export default function PastDay({ results }: { results: DayResults | undefined }) {
31
+ const { settings } = useUserInterfaceData<Context, Settings>();
32
+ const { t } = useTranslation();
33
+
34
+ if (!results) {
35
+ return (
36
+ <Box aria-busy sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
37
+ <Skeleton width="40%" />
38
+ <Skeleton variant="rounded" height={48} />
39
+ <Skeleton variant="rounded" height={160} />
40
+ </Box>
41
+ );
42
+ }
43
+
44
+ return (
45
+ <Box sx={{ display: 'flex', flexDirection: 'column', gap: 2.25 }}>
46
+ <Box>
47
+ <Typography variant="body2" color="text.secondary">
48
+ {t('yesterday.on', {
49
+ day: results.Day,
50
+ weather: t(`weather.${results.Weather}Lower`),
51
+ })}
52
+ </Typography>
53
+ <ProfitFigure results={results} />
54
+ </Box>
55
+ <Section title={t('lookingBack.made')}>
56
+ <Table size="small" sx={{ tableLayout: 'fixed', width: '100%' }}>
57
+ <TableHead>
58
+ <TableRow>
59
+ <TableCell sx={{ width: '34%' }}>{t('history.item')}</TableCell>
60
+ <TableCell align="right">{t('history.made')}</TableCell>
61
+ <TableCell align="right">{t('history.wanted')}</TableCell>
62
+ <TableCell align="right" sx={{ pr: 0 }}>
63
+ {t('history.sold')}
64
+ </TableCell>
65
+ </TableRow>
66
+ </TableHead>
67
+ <TableBody>
68
+ {menuOf(settings.menu).map(({ id, item }) => {
69
+ const line = results.Lines[id];
70
+ if (!line) return null;
71
+ return (
72
+ <TableRow key={id} data-testid={`line-${id}`}>
73
+ <TableCell>{item.Name}</TableCell>
74
+ <TableCell align="right">{count(line.Made)}</TableCell>
75
+ <TableCell align="right">{count(line.Wanted)}</TableCell>
76
+ <TableCell align="right" sx={{ pr: 0 }}>
77
+ {count(line.Sold)}
78
+ </TableCell>
79
+ </TableRow>
80
+ );
81
+ })}
82
+ </TableBody>
83
+ </Table>
84
+ </Section>
85
+ <Lesson results={results} />
86
+ </Box>
87
+ );
88
+ }
@@ -1,37 +1,37 @@
1
- import { Box, Card, CardContent, Stack, Typography } from '@mui/material';
1
+ import { Card, Stack, Typography } from '@mui/material';
2
2
  import type { ReactNode } from 'react';
3
3
 
4
4
  type Props = {
5
5
  title: string;
6
- hint?: string;
7
- action?: ReactNode;
6
+ /** A short fact beside the heading, such as which day this was. */
7
+ aside?: ReactNode;
8
8
  children: ReactNode;
9
9
  };
10
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) {
11
+ /**
12
+ * One rounded card, one heading, one job.
13
+ *
14
+ * The rounded, outlined card is part of the stall's look, alongside the
15
+ * awning: the host brings the colours, the game brings the shapes.
16
+ */
17
+ export default function Section({ title, aside, children }: Props) {
13
18
  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>
19
+ <Card variant="outlined" component="section" aria-label={title} sx={{ p: 2 }}>
20
+ <Stack
21
+ direction="row"
22
+ spacing={2}
23
+ sx={{ alignItems: 'baseline', justifyContent: 'space-between', mb: 1.5 }}
24
+ >
25
+ <Typography variant="subtitle1" component="h2" sx={{ fontWeight: 600 }}>
26
+ {title}
27
+ </Typography>
28
+ {aside && (
29
+ <Typography variant="body2" color="text.secondary">
30
+ {aside}
31
+ </Typography>
32
+ )}
33
+ </Stack>
34
+ {children}
35
35
  </Card>
36
36
  );
37
37
  }
@@ -1,11 +1,15 @@
1
+ import BrightnessAutoRounded from '@mui/icons-material/BrightnessAutoRounded';
2
+ import DarkModeRounded from '@mui/icons-material/DarkModeRounded';
3
+ import LightModeRounded from '@mui/icons-material/LightModeRounded';
1
4
  import { ToggleButton, ToggleButtonGroup } from '@mui/material';
5
+ import { alpha } from '@mui/material/styles';
2
6
  import { useUserInterfaceCallbacks, useUserInterfaceThemePreference } from '@seriousgaming/sdk/ui';
3
7
  import { useTranslation } from 'react-i18next';
4
8
 
5
9
  const OPTIONS = [
6
- { value: 'light', glyph: '☀' },
7
- { value: 'dark', glyph: '☾' },
8
- { value: 'system', glyph: 'A' },
10
+ { value: 'light', Icon: LightModeRounded },
11
+ { value: 'dark', Icon: DarkModeRounded },
12
+ { value: 'system', Icon: BrightnessAutoRounded },
9
13
  ] as const;
10
14
 
11
15
  /**
@@ -16,6 +20,9 @@ const OPTIONS = [
16
20
  * `useUserInterfaceTheme` like any other state. So the whole session follows,
17
21
  * including the facilitator's screen and the chrome around this frame, rather
18
22
  * than one iframe going dark on its own.
23
+ *
24
+ * Small and quiet in the corner of the top bar: it is set once, if at all, and
25
+ * should never compete with the day.
19
26
  */
20
27
  export default function ThemeToggle() {
21
28
  const preference = useUserInterfaceThemePreference();
@@ -33,15 +40,22 @@ export default function ThemeToggle() {
33
40
  // current value means the control never lands in no state at all.
34
41
  if (next) setThemePreference(next);
35
42
  }}
43
+ sx={(theme) => {
44
+ const ink = theme.palette.primary.contrastText;
45
+ return {
46
+ '& .MuiToggleButton-root': {
47
+ color: alpha(ink, 0.75),
48
+ borderColor: alpha(ink, 0.3),
49
+ p: 0.5,
50
+ },
51
+ '& .MuiToggleButton-root.Mui-selected, & .MuiToggleButton-root.Mui-selected:hover':
52
+ { color: ink, bgcolor: alpha(ink, 0.2) },
53
+ };
54
+ }}
36
55
  >
37
- {OPTIONS.map((option) => (
38
- <ToggleButton
39
- key={option.value}
40
- value={option.value}
41
- aria-label={t(`theme.${option.value}`)}
42
- sx={{ px: 1.25, py: 0.25, lineHeight: 1 }}
43
- >
44
- {option.glyph}
56
+ {OPTIONS.map(({ value, Icon }) => (
57
+ <ToggleButton key={value} value={value} aria-label={t(`theme.${value}`)}>
58
+ <Icon sx={{ fontSize: 16 }} />
45
59
  </ToggleButton>
46
60
  ))}
47
61
  </ToggleButtonGroup>
@@ -13,13 +13,6 @@ import TodayPanel from './TodayPanel';
13
13
 
14
14
  const ada = createMockParticipant({ id: 'participant-1', name: 'Ada' });
15
15
 
16
- const setSlider = (name: string, value: number) => {
17
- const slider = screen.getByRole('slider', { name });
18
- fireEvent.change(slider, { target: { value: String(value) } });
19
- // The row writes on release, not on every frame of a drag.
20
- fireEvent.mouseUp(slider);
21
- };
22
-
23
16
  describe('changing how many to make', () => {
24
17
  it('sends only the item that changed', () => {
25
18
  const setData = vi.fn();
@@ -51,6 +44,21 @@ describe('changing how many to make', () => {
51
44
  expect(setData).toHaveBeenCalledWith({ plan: { Make: { lemonade: 39 } } });
52
45
  });
53
46
 
47
+ it('never goes below none', () => {
48
+ const setData = vi.fn();
49
+ renderUserInterface(<TodayPanel />, {
50
+ data: { ...baseContext, plan: { Make: { lemonade: 3, icedtea: 0, cookies: 0 } } },
51
+ settings: baseSettings,
52
+ participant: ada,
53
+ setData,
54
+ });
55
+
56
+ fireEvent.click(screen.getByRole('button', { name: 'Make less Lemonade' }));
57
+
58
+ expect(setData).toHaveBeenCalledWith({ plan: { Make: { lemonade: 0 } } });
59
+ expect(screen.getByRole('button', { name: 'Make less Cookies' })).toBeDisabled();
60
+ });
61
+
54
62
  /**
55
63
  * The whole reason the plan is a map keyed by item rather than three fields
56
64
  * on one object. This harness merges the way the host does, so a payload
@@ -74,28 +82,14 @@ describe('changing how many to make', () => {
74
82
  data = { ...data, plan: { Make: { ...data.plan.Make, cookies: 30 } } };
75
83
 
76
84
  // Ada, who never saw that, changes her own item.
77
- setSlider('Lemonade', 55);
78
-
79
- expect(data.plan.Make).toEqual({ lemonade: 55, icedtea: 20, cookies: 30 });
80
- });
81
-
82
- it('writes the number the slider was left on', () => {
83
- const setData = vi.fn();
84
- renderUserInterface(<TodayPanel />, {
85
- data: baseContext,
86
- settings: baseSettings,
87
- participant: ada,
88
- setData,
89
- });
85
+ fireEvent.click(screen.getByRole('button', { name: 'Make more Lemonade' }));
90
86
 
91
- setSlider('Lemonade', 70);
92
-
93
- expect(setData).toHaveBeenLastCalledWith({ plan: { Make: { lemonade: 70 } } });
87
+ expect(data.plan.Make).toEqual({ lemonade: 45, icedtea: 20, cookies: 30 });
94
88
  });
95
89
  });
96
90
 
97
91
  describe('the stall’s capacity', () => {
98
- it('says how much room is left', () => {
92
+ it('counts the whole stall against what it can make', () => {
99
93
  renderUserInterface(<TodayPanel />, {
100
94
  data: baseContext,
101
95
  settings: baseSettings,
@@ -103,12 +97,12 @@ describe('the stall’s capacity', () => {
103
97
  });
104
98
 
105
99
  expect(screen.getByTestId('capacity')).toHaveTextContent('70 of 120');
106
- expect(screen.getByText(/Room for 50 more/)).toBeInTheDocument();
100
+ expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuenow', '58');
107
101
  });
108
102
 
109
103
  // A merged plan can exceed the stall even though no one write did, so the
110
104
  // surface has to be able to render that state rather than assume it away.
111
- it('says so when the plan is over what the stall can make', () => {
105
+ it('can show a plan over what the stall can make', () => {
112
106
  renderUserInterface(<TodayPanel />, {
113
107
  data: {
114
108
  ...baseContext,
@@ -119,7 +113,6 @@ describe('the stall’s capacity', () => {
119
113
  });
120
114
 
121
115
  expect(screen.getByTestId('capacity')).toHaveTextContent('150 of 120');
122
- expect(screen.getByText(/30 more than the stall can make/)).toBeInTheDocument();
123
116
  });
124
117
  });
125
118
 
@@ -131,10 +124,8 @@ describe('the menu', () => {
131
124
  participant: ada,
132
125
  });
133
126
 
134
- const names = screen
135
- .getAllByRole('slider')
136
- .map((slider) => slider.getAttribute('aria-label'));
137
- expect(names).toEqual(['Lemonade', 'Iced tea', 'Cookies']);
127
+ const rows = screen.getAllByTestId(/^make-/).map((row) => row.getAttribute('data-testid'));
128
+ expect(rows).toEqual(['make-lemonade', 'make-icedtea', 'make-cookies']);
138
129
  });
139
130
 
140
131
  it('marks the item this participant looks after', () => {
@@ -159,7 +150,20 @@ describe('the menu', () => {
159
150
  });
160
151
 
161
152
  expect(screen.getByTestId('make-lemonade')).toHaveTextContent(
162
- '£0.50 each, costs £0.15 to make. About 72 people will want one today.'
153
+ '£0.50 · costs £0.15 · about 72 want one'
154
+ );
155
+ expect(screen.getByTestId('made-lemonade')).toHaveTextContent('40');
156
+ });
157
+
158
+ it('says more about each item where there is room', () => {
159
+ renderUserInterface(<TodayPanel wide />, {
160
+ data: baseContext,
161
+ settings: baseSettings,
162
+ participant: ada,
163
+ });
164
+
165
+ expect(screen.getByTestId('make-lemonade')).toHaveTextContent(
166
+ '£0.50 each · costs £0.15 to make · about 72 people will want one'
163
167
  );
164
168
  });
165
169
  });
@@ -173,7 +177,7 @@ describe('observing', () => {
173
177
  });
174
178
 
175
179
  expect(screen.getByText(/watching this stall/)).toBeInTheDocument();
176
- expect(screen.getByRole('slider', { name: 'Lemonade' })).toBeDisabled();
177
180
  expect(screen.getByRole('button', { name: 'Make more Lemonade' })).toBeDisabled();
181
+ expect(screen.getByRole('button', { name: 'Make less Lemonade' })).toBeDisabled();
178
182
  });
179
183
  });
@@ -1,23 +1,26 @@
1
- import { Alert, Chip, LinearProgress, Stack, Typography } from '@mui/material';
1
+ import { Alert, Box, Card, Divider, LinearProgress, Stack, Typography } from '@mui/material';
2
2
  import { useUserInterfaceData, useUserInterfaceParticipant } from '@seriousgaming/sdk/ui';
3
- import { useTranslation } from 'react-i18next';
3
+ import { Fragment } from 'react';
4
+ import { Trans, useTranslation } from 'react-i18next';
4
5
 
5
6
  import type { Settings, Context } from '../types';
6
7
  import MakeRow from './MakeRow';
7
8
  import { menuOf, totalPlanned } from './menu';
8
- import Section from './Section';
9
9
  import { useWrite } from './writes';
10
10
 
11
11
  /**
12
- * What the stall is making today.
12
+ * What the stall is making today: the decision the screen exists for.
13
13
  *
14
- * The only screen that writes, and it writes one key per line of the menu. Two
14
+ * The only part that writes, and it writes one key per line of the menu. Two
15
15
  * people changing two different things write two different keys, and the host's
16
16
  * merge keeps both: no locks, no turn-taking, and nothing to explain to the
17
17
  * room. The capacity they share is the one thing that can still go wrong, and
18
18
  * `validators/capacity` is what catches it.
19
+ *
20
+ * One count and one bar for the whole stall, rather than a total per row: the
21
+ * limit is on the total, so that is the number the team watches.
19
22
  */
20
- export default function TodayPanel() {
23
+ export default function TodayPanel({ wide = false }: { wide?: boolean }) {
21
24
  const { data, settings, setData } = useUserInterfaceData<Context, Settings>();
22
25
  const participant = useUserInterfaceParticipant();
23
26
  const { run, pending } = useWrite();
@@ -25,7 +28,8 @@ export default function TodayPanel() {
25
28
 
26
29
  const menu = menuOf(settings.menu);
27
30
  const planned = totalPlanned(data.plan.Make);
28
- const room = settings.menu.Capacity - planned;
31
+ const capacity = settings.menu.Capacity;
32
+ const over = planned > capacity;
29
33
  const yours = participant ? data.roles.LooksAfter[participant.id] : undefined;
30
34
 
31
35
  const setCount = (id: string, next: number) => {
@@ -36,57 +40,67 @@ export default function TodayPanel() {
36
40
  };
37
41
 
38
42
  return (
39
- <Section
40
- title={t('today.title')}
41
- hint={t(`weather.${data.weather.Today}`)}
42
- action={
43
- <Chip
44
- color={room < 0 ? 'error' : room === 0 ? 'success' : 'default'}
45
- label={t('today.capacity', { planned, capacity: settings.menu.Capacity })}
43
+ <Stack component="section" aria-labelledby="make-heading" spacing={2}>
44
+ <Stack direction="row" sx={{ alignItems: 'baseline', justifyContent: 'space-between' }}>
45
+ <Typography id="make-heading" variant="h6" component="h2" sx={{ fontWeight: 600 }}>
46
+ {t('make.title')}
47
+ </Typography>
48
+ <Typography
49
+ variant="body2"
50
+ color={over ? 'error.main' : 'text.secondary'}
46
51
  data-testid="capacity"
47
- />
48
- }
49
- >
52
+ sx={{ fontVariantNumeric: 'tabular-nums' }}
53
+ >
54
+ <Trans
55
+ i18nKey="make.count"
56
+ values={{ planned, capacity }}
57
+ components={[
58
+ <Box
59
+ key="planned"
60
+ component="strong"
61
+ sx={{
62
+ fontSize: '1.15rem',
63
+ color: over ? 'error.main' : 'text.primary',
64
+ }}
65
+ />,
66
+ ]}
67
+ />
68
+ </Typography>
69
+ </Stack>
50
70
  <LinearProgress
51
71
  variant="determinate"
52
- color={room < 0 ? 'error' : 'primary'}
53
- value={Math.min(100, (planned / Math.max(1, settings.menu.Capacity)) * 100)}
54
- sx={{ mb: 3 }}
72
+ color={over ? 'error' : 'primary'}
73
+ value={Math.min(100, Math.round((planned / Math.max(1, capacity)) * 100))}
74
+ aria-label={t('make.countLabel', { planned, capacity })}
75
+ sx={{ height: 8, borderRadius: 999 }}
55
76
  />
56
77
 
57
- {!participant && (
58
- <Alert severity="info" sx={{ mb: 3 }}>
59
- {t('today.observing')}
60
- </Alert>
61
- )}
78
+ {!participant && <Alert severity="info">{t('make.observing')}</Alert>}
62
79
 
63
- <Stack spacing={3}>
64
- {menu.map(({ id, item }) => (
65
- <MakeRow
66
- key={id}
67
- id={id}
68
- item={item}
69
- value={data.plan.Make[id] ?? 0}
70
- expected={data.weather.Expected[id] ?? 0}
71
- // One item can fill the stall on its own, so the cap on
72
- // a single row is the stall's. The rule about the total
73
- // is the validator's, because only the merged plan
74
- // shows it.
75
- max={settings.menu.Capacity}
76
- step={settings.ui.Step}
77
- currencySymbol={settings.ui.CurrencySymbol}
78
- yours={yours === id}
79
- disabled={!participant || pending}
80
- onChange={(next) => setCount(id, next)}
81
- />
80
+ <Card variant="outlined">
81
+ {menu.map(({ id, item }, index) => (
82
+ <Fragment key={id}>
83
+ {index > 0 && <Divider sx={{ mx: 2 }} />}
84
+ <MakeRow
85
+ id={id}
86
+ item={item}
87
+ value={data.plan.Make[id] ?? 0}
88
+ expected={data.weather.Expected[id] ?? 0}
89
+ // One item can fill the stall on its own, so the cap
90
+ // on a single row is the stall's. The rule about the
91
+ // total is the validator's, because only the merged
92
+ // plan shows it.
93
+ max={capacity}
94
+ step={settings.ui.Step}
95
+ currencySymbol={settings.ui.CurrencySymbol}
96
+ yours={yours === id}
97
+ disabled={!participant || pending}
98
+ wide={wide}
99
+ onChange={(next) => setCount(id, next)}
100
+ />
101
+ </Fragment>
82
102
  ))}
83
- </Stack>
84
-
85
- <Typography variant="body2" color="text.secondary" sx={{ mt: 3 }}>
86
- {room < 0
87
- ? t('today.over', { over: -room })
88
- : t('today.room', { room, capacity: settings.menu.Capacity })}
89
- </Typography>
90
- </Section>
103
+ </Card>
104
+ </Stack>
91
105
  );
92
106
  }
@@ -0,0 +1,47 @@
1
+ import { Box, Typography } from '@mui/material';
2
+ import { useUserInterfaceData } from '@seriousgaming/sdk/ui';
3
+ import { useTranslation } from 'react-i18next';
4
+
5
+ import { useWeatherTone, WeatherIcon } from '../../shared/StallIcons';
6
+ import type { Context, Settings } from '../types';
7
+
8
+ /**
9
+ * The forecast for the day about to be played: the one fact every decision on
10
+ * the screen depends on, so it sits above them.
11
+ */
12
+ export default function WeatherCard() {
13
+ const { data, completedTicks } = useUserInterfaceData<Context, Settings>();
14
+ const { t } = useTranslation();
15
+ const weather = data.weather.Today;
16
+ const { wash } = useWeatherTone(weather);
17
+ const name = t(`weather.${weather}Short`);
18
+
19
+ return (
20
+ <Box
21
+ component="section"
22
+ aria-label={t('weather.today', { weather: name })}
23
+ data-testid="weather"
24
+ sx={{
25
+ display: 'flex',
26
+ alignItems: 'center',
27
+ gap: 1.75,
28
+ bgcolor: wash,
29
+ borderRadius: '16px',
30
+ px: 2,
31
+ py: 1.75,
32
+ }}
33
+ >
34
+ <WeatherIcon weather={weather} />
35
+ <Box>
36
+ <Typography variant="h6" component="p" sx={{ fontWeight: 600, lineHeight: 1.3 }}>
37
+ {completedTicks === 0
38
+ ? t('weather.onDay', { weather: name, day: 1 })
39
+ : t('weather.today', { weather: name })}
40
+ </Typography>
41
+ <Typography variant="body2" color="text.secondary">
42
+ {t(`weather.${weather}`)}
43
+ </Typography>
44
+ </Box>
45
+ </Box>
46
+ );
47
+ }