@tastic/shell 0.8.2 → 0.9.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/README.md CHANGED
@@ -32,7 +32,8 @@ package ecosystem, on [`@tastic/hud`](https://github.com/jayrdeaton/react-native
32
32
  - **What a game builds on**: `createPlayerSettings` (its settings and controls, kept per player),
33
33
  `createGameStats` (its stats and achievements), `createGameGuideSlice` (which version of its How to
34
34
  Play a player has seen), `onProfileRemoved` (forget a deleted profile), `useActiveRound`,
35
- `useProfiles`, `useSeatColors`, `SettingsDialog`, `safeBack` and `imageGameIcon`.
35
+ `useProfiles`, `useSeatColors`, `SettingsDialog`, `safeBack`, `useBackBlock` (Android's and the
36
+ browser's back mid-match open Quit Match?) and `imageGameIcon`.
36
37
 
37
38
  ## Install
38
39
 
@@ -146,6 +147,7 @@ What a game can leave out or add, each optional, so a two-seat game sets none of
146
147
  | Field | |
147
148
  | --- | --- |
148
149
  | no `seatTwo` (nor `sideBySideWhenWide`) | A game for one player: its loadout has no opponent button, every round is solo (`useActiveRound` falls back to `'solo'`), and its How to Play describes a solo round. |
150
+ | no `'cpu'` in `seatTwo` | A game with no CPU, such as `['nobody', 'person']`. Seat 2's saved choice is the whole pack's and starts on the CPU, so `seatTwoFor` reads a choice a game doesn't offer as the CPU where it has one, and as its first choice where it has none: a fresh install opens this game's loadout on that choice, its How to Play describes it, and `useActiveRound` falls back to it. The saved choice only changes when player 1 picks another. |
149
151
  | no `useLoadout` | Nothing to set up first: Home opens its play screen straight away, after its How to Play the first time, and a link to its loadout plays it. Its rule variants go in its play screen's Settings: `<SettingsDialog>` takes `children`. |
150
152
  | no `cpuDifficulty` (in `GameLoadout`) | A CPU with no levels: player 1's opponent menu offers one plain CPU. |
151
153
  | `resumable` | A cold launch drops the player back into its play screen if they left the app there rather than backing out of it. The shell remembers only which game (`lastActiveGame`); the game saves and restores its own board. |
@@ -212,6 +214,34 @@ the window's middle.
212
214
  it stops; up all match at a computer.
213
215
  - **Look:** a 24 icon in the theme's full contrast on a translucent chip of the page's color.
214
216
 
217
+ ### Back mid-match (`useBackBlock`)
218
+
219
+ `useBackBlock(held, onHeld)` holds a play screen while `held`: every way off it but the `quit` it
220
+ returns (Android's hardware or gesture back, the browser's back, a link) runs `onHeld` instead. Hand it
221
+ the same test the back chip's Quit Match? asks with, and `requestBack` from `@tastic/hud`'s
222
+ `useQuitConfirmation`, so a system back opens the same Quit Match? the chip does; use `quit` for
223
+ Quit Match?'s and Paused's own Quit, which `safeBack` alone would be stopped by.
224
+
225
+ ```tsx
226
+ const hasProgressRef = useRef(false)
227
+ const { confirmVisible, requestBack, cancelBack } = useQuitConfirmation(() => hasProgressRef.current, safeBack)
228
+ // ... the game's state hook, which needs `paused` from confirmVisible ...
229
+ const hasProgress = phase !== 'gameOver' && (scores[0] > 0 || scores[1] > 0)
230
+ useEffect(() => {
231
+ hasProgressRef.current = hasProgress
232
+ })
233
+ const quit = useBackBlock(hasProgress, requestBack)
234
+
235
+ <ConfirmDialog visible={confirmVisible} title='Quit Match?' onConfirm={quit} onCancel={cancelBack} />
236
+ ```
237
+
238
+ - `held` is a plain boolean read as the screen renders (expo-router has to know before a back comes
239
+ in), so a game whose progress comes from a state hook that itself needs Quit Match?'s `paused` calls
240
+ this after that hook, and mirrors the value into the getter it gives `useQuitConfirmation`.
241
+ - Off when there's nothing to lose (0-0, Game Over), so a back there leaves at once, as the chip does.
242
+ - While it's on, the web also asks before the page unloads (expo-router's `usePreventRemove` adds a
243
+ `beforeunload` handler with it). iOS's swipe back is off on every screen anyway.
244
+
215
245
  ## Peer dependencies
216
246
 
217
247
  None are bundled. The floors are the versions PuckTastic and DuelTastic ran the shell on when it
@@ -226,7 +256,7 @@ became a package (the lower of the two where they differ).
226
256
  | `expo-constants` | >=58.0.12 | the web tab title |
227
257
  | `expo-blur`, `@react-native-masked-view/masked-view` | >=58.0.4, >=0.3.2 | auto-paper's blur and its scroll fade, Home's fading scrollers |
228
258
  | `expo-haptics`, `expo-keep-awake` | >=58.0.7, >=58.0.3 | the toaster's haptics, Keep Awake |
229
- | `react-native-gesture-handler`, `react-native-reanimated`, `react-native-safe-area-context` | >=3.3.0, >=4.7.1, >=5.10.1 | the gesture root, auto-paper's dialogs and the loadout's fades, insets |
259
+ | `react-native-gesture-handler`, `react-native-reanimated`, `react-native-safe-area-context` | >=3.3.0, >=4.7.1, >=5.11.0 | the gesture root, auto-paper's dialogs and the loadout's fades, insets (with room for iPadOS's window controls) |
230
260
  | `react-native-paper` | >=5.15.3 | text, icons, the toaster and feedback-press |
231
261
  | `@reduxjs/toolkit`, `redux`, `react-redux`, `redux-persist`, `@react-native-async-storage/async-storage` | >=2.13.0, >=5.0.1, >=9.3.0, >=6.0.0, >=2.2.0 | the store and where it's saved |
232
262
  | `@rific/auto-paper` | >=0.13.4 | the theme |
package/dist/index.d.mts CHANGED
@@ -445,6 +445,8 @@ declare function useAppSettings(): {
445
445
 
446
446
  declare function useAtComputer(): boolean;
447
447
 
448
+ declare function useBackBlock(held: boolean, onHeld: () => void): () => void;
449
+
448
450
  declare function useOpponent(): {
449
451
  seatTwo: SeatTwo;
450
452
  setSeatTwo: (seatTwo: SeatTwo) => void;
@@ -579,5 +581,5 @@ declare function createPlayerSettings<S extends WithControls<C>, C>({ id, defaul
579
581
  };
580
582
  };
581
583
 
582
- export { DEFAULT_APP_SETTINGS, DEFAULT_OPPONENT, GUEST_PLAYER_ID, HomeScreen, LoadoutRoute, MATCH_CHIPS_FADE_MS, MatchChips, PREVIEW_ASPECT, PackProvider, PlayRoute, ProfilesProvider, ProfilesRoute, RootLayout, SettingsDialog, StatsScreen, appSettingsActions, reducer$1 as appSettingsReducer, createGameGuideSlice, createGameStats, createPackStore, createPlayerSettings, createSeatColorsReducer, createShellReducers, defaultProfileSelectionState, defaultSeatColorsState, forgetProfileAchievements, humanSeatsFor, imageGameIcon, liveplayActions, reducer$3 as liveplayReducer, onProfileRemoved, opponentActions, reducer$2 as opponentReducer, profileSelectionActions, reducer as profileSelectionReducer, roundModeFor, seatColorsActions, seatPlayerKey, seatTwoFor, useActiveRound, useAppSettings, useAtComputer, useGameGuide, useOpponent, usePack, usePackGame, useProfiles, useSeatColors };
584
+ export { DEFAULT_APP_SETTINGS, DEFAULT_OPPONENT, GUEST_PLAYER_ID, HomeScreen, LoadoutRoute, MATCH_CHIPS_FADE_MS, MatchChips, PREVIEW_ASPECT, PackProvider, PlayRoute, ProfilesProvider, ProfilesRoute, RootLayout, SettingsDialog, StatsScreen, appSettingsActions, reducer$1 as appSettingsReducer, createGameGuideSlice, createGameStats, createPackStore, createPlayerSettings, createSeatColorsReducer, createShellReducers, defaultProfileSelectionState, defaultSeatColorsState, forgetProfileAchievements, humanSeatsFor, imageGameIcon, liveplayActions, reducer$3 as liveplayReducer, onProfileRemoved, opponentActions, reducer$2 as opponentReducer, profileSelectionActions, reducer as profileSelectionReducer, roundModeFor, seatColorsActions, seatPlayerKey, seatTwoFor, useActiveRound, useAppSettings, useAtComputer, useBackBlock, useGameGuide, useOpponent, usePack, usePackGame, useProfiles, useSeatColors };
583
585
  export type { ActiveRound, AppSettings, FeedbackSounds, GameDefinition, GameGuide, GameGuideState, GameIconProps, GameLoadout, GamePreviewProps, GameRulesProps, GuidelessGameDefinition, HeroTitleProps, HomeTab, LiveplaySliceState, LoadoutOptionsProps, MatchChipsProps, OpponentState, PackDefinition, PackGameDefinition, PackGuide, PackStatsReset, PackStatsSectionsProps, PackStatsTab, PackStore, PackStoreConfig, PackStoreSource, PickerAlign, PlayerControlsState, PlayerSettingsState, ProfileSelectionState, RecordResult, RoundMode, Seat, SeatColorsState, SeatControlLook, SeatTwo, SettingsDialogProps, ShellState, StackScreenOptions };
package/dist/index.d.ts CHANGED
@@ -445,6 +445,8 @@ declare function useAppSettings(): {
445
445
 
446
446
  declare function useAtComputer(): boolean;
447
447
 
448
+ declare function useBackBlock(held: boolean, onHeld: () => void): () => void;
449
+
448
450
  declare function useOpponent(): {
449
451
  seatTwo: SeatTwo;
450
452
  setSeatTwo: (seatTwo: SeatTwo) => void;
@@ -579,5 +581,5 @@ declare function createPlayerSettings<S extends WithControls<C>, C>({ id, defaul
579
581
  };
580
582
  };
581
583
 
582
- export { DEFAULT_APP_SETTINGS, DEFAULT_OPPONENT, GUEST_PLAYER_ID, HomeScreen, LoadoutRoute, MATCH_CHIPS_FADE_MS, MatchChips, PREVIEW_ASPECT, PackProvider, PlayRoute, ProfilesProvider, ProfilesRoute, RootLayout, SettingsDialog, StatsScreen, appSettingsActions, reducer$1 as appSettingsReducer, createGameGuideSlice, createGameStats, createPackStore, createPlayerSettings, createSeatColorsReducer, createShellReducers, defaultProfileSelectionState, defaultSeatColorsState, forgetProfileAchievements, humanSeatsFor, imageGameIcon, liveplayActions, reducer$3 as liveplayReducer, onProfileRemoved, opponentActions, reducer$2 as opponentReducer, profileSelectionActions, reducer as profileSelectionReducer, roundModeFor, seatColorsActions, seatPlayerKey, seatTwoFor, useActiveRound, useAppSettings, useAtComputer, useGameGuide, useOpponent, usePack, usePackGame, useProfiles, useSeatColors };
584
+ export { DEFAULT_APP_SETTINGS, DEFAULT_OPPONENT, GUEST_PLAYER_ID, HomeScreen, LoadoutRoute, MATCH_CHIPS_FADE_MS, MatchChips, PREVIEW_ASPECT, PackProvider, PlayRoute, ProfilesProvider, ProfilesRoute, RootLayout, SettingsDialog, StatsScreen, appSettingsActions, reducer$1 as appSettingsReducer, createGameGuideSlice, createGameStats, createPackStore, createPlayerSettings, createSeatColorsReducer, createShellReducers, defaultProfileSelectionState, defaultSeatColorsState, forgetProfileAchievements, humanSeatsFor, imageGameIcon, liveplayActions, reducer$3 as liveplayReducer, onProfileRemoved, opponentActions, reducer$2 as opponentReducer, profileSelectionActions, reducer as profileSelectionReducer, roundModeFor, seatColorsActions, seatPlayerKey, seatTwoFor, useActiveRound, useAppSettings, useAtComputer, useBackBlock, useGameGuide, useOpponent, usePack, usePackGame, useProfiles, useSeatColors };
583
585
  export type { ActiveRound, AppSettings, FeedbackSounds, GameDefinition, GameGuide, GameGuideState, GameIconProps, GameLoadout, GamePreviewProps, GameRulesProps, GuidelessGameDefinition, HeroTitleProps, HomeTab, LiveplaySliceState, LoadoutOptionsProps, MatchChipsProps, OpponentState, PackDefinition, PackGameDefinition, PackGuide, PackStatsReset, PackStatsSectionsProps, PackStatsTab, PackStore, PackStoreConfig, PackStoreSource, PickerAlign, PlayerControlsState, PlayerSettingsState, ProfileSelectionState, RecordResult, RoundMode, Seat, SeatColorsState, SeatControlLook, SeatTwo, SettingsDialogProps, ShellState, StackScreenOptions };