@tastic/hud 0.25.1 → 0.27.1

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.
@@ -1,7 +1,7 @@
1
1
  import { SeedColor } from '@rific/auto-paper'
2
2
  import { getOptionPickerContentSize, getProfilePickerContentSize, OptionPicker, Profile, ProfilePicker, type ProfilePickerColorSection } from '@tastic/profile'
3
3
  import { ReactNode } from 'react'
4
- import { StyleSheet, View } from 'react-native'
4
+ import { type StyleProp, StyleSheet, View, type ViewStyle } from 'react-native'
5
5
  import { Text } from 'react-native-paper'
6
6
 
7
7
  import { InlineColorPicker } from './InlineColorPicker'
@@ -93,6 +93,10 @@ export interface PlayerSetupPanelProps<C extends string = string> {
93
93
  // ProfilePicker's own doc for why it's never "Player"). Required whenever profiles is provided,
94
94
  // since the trigger always needs some idle text.
95
95
  guestLabel?: string
96
+ // The no-profile row's label in the seat button's dropdown (ProfilePicker's `nullLabel`), e.g.
97
+ // 'Guest' for a seat whose button reads 'GUEST' (guestLabel) until a profile is picked. Unset is
98
+ // ProfilePicker's own default.
99
+ nullLabel?: string
96
100
  onProfileSelect?: (profile: Profile | null) => void
97
101
  // Navigates to a profile-management screen - typically only ever wired up for one seat (a rotated
98
102
  // second zone often can't host a working text keyboard).
@@ -109,6 +113,21 @@ export interface PlayerSetupPanelProps<C extends string = string> {
109
113
  // than this component needing any opinion on what those states are.
110
114
  humanIcon?: string
111
115
  cpuIcon?: string
116
+ // How the seat's color is drawn, for a host that draws profile colors muted (Solitaire on its felt):
117
+ // the seat button's chip, its Color row and swatches (the color section's `previewValue`), the
118
+ // fallback swatch, the plain label and the Ready button all show previewValue(color), while `color`,
119
+ // `takenColor` and what onColorChange receives stay the saved values. Unset draws them as given.
120
+ previewValue?: (hex: string) => string
121
+ // Extra style for the seat button's trigger, e.g. a background behind its pill so it reads on a
122
+ // busy backdrop (ProfilePicker's and OptionPicker's `triggerStyle`).
123
+ triggerStyle?: StyleProp<ViewStyle>
124
+ // A placement of the host's own for the seat button's dropdown, in place of useZoneClampedAlign:
125
+ // called as a hook with whether the dropdown is open and the size it draws, and its result handed
126
+ // to the picker as `alignOverride` (for a screen turned by a fake landscape, whose button
127
+ // useAutoAlign would measure against the upright window). It replaces the zone clamp, so leave it
128
+ // unset for a panel inside a @tastic/split-screen zone. A hook: keep the same one for the panel's
129
+ // life, and remount the panel (a key) to change it.
130
+ useSeatPickerAlign?: (open: boolean, contentWidth: number, contentHeight: number) => AlignResult
112
131
  }
113
132
 
114
133
  // One panel per player slot in a local-multiplayer loadout/lobby screen: one seat button, an
@@ -125,7 +144,7 @@ export interface PlayerSetupPanelProps<C extends string = string> {
125
144
  // Owns its own popover host shared by its own pickers unless a `host` is passed in to share with
126
145
  // another panel (or a shared-controls row) instead - same convention as every popover-hosting
127
146
  // component in this package.
128
- export function PlayerSetupPanel<C extends string = string>({ idPrefix, host, label, labelFontFamily, color, onColorChange, swatches, takenColor, allowSwapTaken, colorCaption, showColor = true, colorAlignOverride, colorRotation, isHuman, secondPicker, secondPickerId, ready, onToggleReady, dark, showReadyButton = true, profiles, selectedProfileId, takenProfileId, guestLabel, onProfileSelect, onManageProfiles, cpuDifficulty, cpuDifficultyOptions, onCpuDifficultyChange, humanIcon = 'face-man', cpuIcon = 'robot' }: PlayerSetupPanelProps<C>) {
147
+ export function PlayerSetupPanel<C extends string = string>({ idPrefix, host, label, labelFontFamily, color, onColorChange, swatches, takenColor, allowSwapTaken, colorCaption, showColor = true, colorAlignOverride, colorRotation, isHuman, secondPicker, secondPickerId, ready, onToggleReady, dark, showReadyButton = true, profiles, selectedProfileId, takenProfileId, guestLabel, nullLabel, onProfileSelect, onManageProfiles, cpuDifficulty, cpuDifficultyOptions, onCpuDifficultyChange, humanIcon = 'face-man', cpuIcon = 'robot', previewValue, triggerStyle, useSeatPickerAlign }: PlayerSetupPanelProps<C>) {
129
148
  const ownHost = usePopoverHost()
130
149
  const popover = host ?? ownHost
131
150
  // Checking *this panel's own* ids, not just "is anything open on the host" - when `host` is
@@ -144,26 +163,29 @@ export function PlayerSetupPanel<C extends string = string>({ idPrefix, host, la
144
163
  // Read live from the selected profile rather than snapshotted at selection time, since a caller
145
164
  // typically has no other editing surface for it on this same screen.
146
165
  const selectedProfile = profiles?.find((p) => p.id === selectedProfileId) ?? null
166
+ // The seat's color as it's drawn (see previewValue); `color` itself stays the saved one.
167
+ const drawn = previewValue ? previewValue(color) : color
147
168
 
148
- const colorSection: ProfilePickerColorSection | undefined = showColor ? { value: color, onChange: onColorChange, swatches, takenValue: takenColor, allowSwapTaken, caption: showProfilePicker && selectedProfile ? colorCaption : undefined } : undefined
169
+ const colorSection: ProfilePickerColorSection | undefined = showColor ? { value: color, onChange: onColorChange, swatches, takenValue: takenColor, allowSwapTaken, caption: showProfilePicker && selectedProfile ? colorCaption : undefined, previewValue } : undefined
149
170
  // The seat button's dropdown is placed here rather than by the caller: inside a
150
171
  // @tastic/split-screen zone (2 Player) it has to stay in that player's half, which
151
- // useZoneClampedAlign does, and outside one it's useAutoAlign's own placement. Sized from the same
152
- // section and rows the picker draws. Rotation 0, the same as the profile, color and difficulty
153
- // dropdowns this button replaced were all placed with.
172
+ // useZoneClampedAlign does, and outside one it's useAutoAlign's own placement (or the host's own,
173
+ // useSeatPickerAlign). Sized from the same section and rows the picker draws. Rotation 0, the same
174
+ // as the profile, color and difficulty dropdowns this button replaced were all placed with.
154
175
  const seatPickerId = showProfilePicker ? getProfilePopoverId(idPrefix) : getCpuDifficultyPopoverId(idPrefix)
155
176
  const seatPickerSize = showProfilePicker ? getProfilePickerContentSize(profiles!.length, !!onManageProfiles, colorSection) : getOptionPickerContentSize(cpuDifficultyOptions?.length ?? 0, colorSection)
156
- const seatPickerAlign = useZoneClampedAlign(seatButton && popover.openId === seatPickerId, seatPickerSize.width, seatPickerSize.height)
177
+ const useSeatAlign = useSeatPickerAlign ?? useZoneClampedAlign
178
+ const seatPickerAlign = useSeatAlign(seatButton && popover.openId === seatPickerId, seatPickerSize.width, seatPickerSize.height)
157
179
 
158
180
  return (
159
181
  <View style={[styles.panel, ownPopoverOpen && styles.panelOpen]}>
160
182
  {showProfilePicker ? (
161
- <ProfilePicker idPrefix={idPrefix} host={popover} profiles={profiles!} selectedId={selectedProfileId ?? null} takenId={takenProfileId} color={color} dark={dark} guestLabel={guestLabel ?? 'GUEST'} onSelect={(profile: Profile | null) => onProfileSelect?.(profile)} onManage={onManageProfiles} colorSection={colorSection} alignOverride={seatPickerAlign} />
183
+ <ProfilePicker idPrefix={idPrefix} host={popover} profiles={profiles!} selectedId={selectedProfileId ?? null} takenId={takenProfileId} color={drawn} dark={dark} guestLabel={guestLabel ?? 'GUEST'} nullLabel={nullLabel} onSelect={(profile: Profile | null) => onProfileSelect?.(profile)} onManage={onManageProfiles} colorSection={colorSection} alignOverride={seatPickerAlign} triggerStyle={triggerStyle} />
162
184
  ) : showCpuDifficulty ? (
163
- <OptionPicker id={getCpuDifficultyPopoverId(idPrefix)} host={popover} options={cpuDifficultyOptions!} value={cpuDifficulty!} onChange={onCpuDifficultyChange!} color={color} dark={dark} icon={cpuIcon} colorSection={colorSection} alignOverride={seatPickerAlign} />
185
+ <OptionPicker id={getCpuDifficultyPopoverId(idPrefix)} host={popover} options={cpuDifficultyOptions!} value={cpuDifficulty!} onChange={onCpuDifficultyChange!} color={drawn} dark={dark} icon={cpuIcon} colorSection={colorSection} alignOverride={seatPickerAlign} triggerStyle={triggerStyle} />
164
186
  ) : (
165
187
  label && (
166
- <Text variant='labelSmall' style={{ color, fontFamily: labelFontFamily }}>
188
+ <Text variant='labelSmall' style={{ color: drawn, fontFamily: labelFontFamily }}>
167
189
  {label}
168
190
  </Text>
169
191
  )
@@ -174,13 +196,13 @@ export function PlayerSetupPanel<C extends string = string>({ idPrefix, host, la
174
196
  {/* The fallback swatch, for a seat with no button: a human slot shows the selected
175
197
  profile's own tag when it has one, falling back to humanIcon; a non-human slot always
176
198
  falls back to cpuIcon. */}
177
- {!seatButton && <InlineColorPicker id={getColorPopoverId(idPrefix)} host={popover} value={color} onChange={onColorChange} swatches={swatches} takenValue={takenColor} allowSwapTaken={allowSwapTaken} alignOverride={colorAlignOverride} rotation={colorRotation} dark={dark} tag={isHuman ? selectedProfile?.tag : undefined} icon={isHuman ? humanIcon : cpuIcon} />}
199
+ {!seatButton && <InlineColorPicker id={getColorPopoverId(idPrefix)} host={popover} value={color} onChange={onColorChange} swatches={swatches} takenValue={takenColor} allowSwapTaken={allowSwapTaken} previewValue={previewValue} alignOverride={colorAlignOverride} rotation={colorRotation} dark={dark} tag={isHuman ? selectedProfile?.tag : undefined} icon={isHuman ? humanIcon : cpuIcon} />}
178
200
 
179
201
  {secondPicker}
180
202
  </View>
181
203
  )}
182
204
 
183
- {isHuman && showReadyButton && onToggleReady && <ReadyButton color={color} ready={ready ?? false} onToggleReady={onToggleReady} />}
205
+ {isHuman && showReadyButton && onToggleReady && <ReadyButton color={drawn} ready={ready ?? false} onToggleReady={onToggleReady} />}
184
206
  </View>
185
207
  )
186
208
  }
@@ -5,6 +5,7 @@ import { ScrollView, StyleSheet, TextStyle, View } from 'react-native'
5
5
  import { Icon, Text } from 'react-native-paper'
6
6
 
7
7
  import { MONO_FONT } from './fonts'
8
+ import type { MenuOption } from './menuOption'
8
9
  import { PopoverBody } from './PopoverBody'
9
10
  import TriggerGaugeHost from './TriggerGaugeHost'
10
11
  import { AlignResult, PopoverRotation, useAutoAlign } from './useAutoAlign'
@@ -34,17 +35,9 @@ const MENU_ITEM_HEIGHT_WITH_DESCRIPTION = 58
34
35
  const MENU_DIVIDER_HEIGHT = 9
35
36
  const MENU_VERTICAL_PADDING = 12
36
37
 
37
- export interface MenuOption<T extends string | number> {
38
- value: T
39
- label: string
40
- description?: string
41
- // Optional per-option icon - when every option in a single-select section has one, the trigger
42
- // shows the currently selected option's icon instead of the static fallback, so the value is
43
- // readable at a glance without opening the dropdown. Unused by multi-select sections (there's no
44
- // single "the" selected option to show on the trigger).
45
- icon?: string
46
- iconSize?: number
47
- }
38
+ // In a module of its own (menuOption.ts) so `@tastic/hud/lobby` can export the type without
39
+ // reaching this file, which imports TriggerGaugeHost and so Skia.
40
+ export type { MenuOption } from './menuOption'
48
41
 
49
42
  // Exactly one of these can be true at a time - radio-style. Tapping a row selects it; whether that
50
43
  // also closes the popover is controlled by the dropdown's own `autoDismiss` prop.
@@ -0,0 +1,13 @@
1
+ // The loadout entry point (`@tastic/hud/lobby`): the pieces a two-seat loadout or lobby screen is built
2
+ // from, reachable without the main barrel, whose TriggerGaugeHost and loadSkiaWeb reach Skia.
3
+ // @tastic/shell's loadout is why it exists: the shell is one barrel, so every app on it loads the
4
+ // loadout, and CardTastic (Solitaire, renamed) has no Skia. Unlike `./chrome`, this entry may use
5
+ // @tastic/profile (PlayerSetupPanel's pickers) and @tastic/split-screen (useZoneClampedAlign), neither
6
+ // of which loads Skia. Everything reachable from this file must stay free of Skia and of the main barrel.
7
+ // SectionedDropdown stays out (TriggerGaugeHost), which is why MenuOption has a module of its own.
8
+ // src/__tests__/lobbyImports.test.ts walks the real import graph from here and enforces all of it.
9
+ export { type MenuOption } from '../menuOption'
10
+ export { getColorPopoverId, getCpuDifficultyPopoverId, getProfilePopoverId, PlayerSetupPanel, type PlayerSetupPanelProps } from '../PlayerSetupPanel'
11
+ export { ReadyButton } from '../ReadyButton'
12
+ export { SharedActionBand } from '../SharedActionBand'
13
+ export { useZoneClampedAlign } from '../useZoneClampedAlign'
@@ -0,0 +1,14 @@
1
+ // One option in a SectionedDropdown section, or in any menu a loadout builds from the same shape (a
2
+ // CPU's difficulty levels). Its own module, free of imports, so `@tastic/hud/lobby` can export it
3
+ // without reaching SectionedDropdown.tsx, which imports TriggerGaugeHost and so Skia.
4
+ export interface MenuOption<T extends string | number> {
5
+ value: T
6
+ label: string
7
+ description?: string
8
+ // Optional per-option icon - when every option in a single-select section has one, the trigger
9
+ // shows the currently selected option's icon instead of the static fallback, so the value is
10
+ // readable at a glance without opening the dropdown. Unused by multi-select sections (there's no
11
+ // single "the" selected option to show on the trigger).
12
+ icon?: string
13
+ iconSize?: number
14
+ }