@tastic/shell 0.8.3 → 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 +31 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +33 -12
- package/dist/index.mjs +28 -8
- package/package.json +2 -1
- package/src/components/GuideHost.tsx +3 -2
- package/src/hooks/useActiveRound.ts +7 -5
- package/src/hooks/useBackBlock.ts +38 -0
- package/src/index.ts +1 -0
- package/src/redux/opponentSlice.ts +2 -2
- package/src/types.ts +8 -5
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
|
|
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
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -73,6 +73,7 @@ __export(index_exports, {
|
|
|
73
73
|
useActiveRound: () => useActiveRound,
|
|
74
74
|
useAppSettings: () => useAppSettings,
|
|
75
75
|
useAtComputer: () => useAtComputer,
|
|
76
|
+
useBackBlock: () => useBackBlock,
|
|
76
77
|
useGameGuide: () => useGameGuide,
|
|
77
78
|
useOpponent: () => useOpponent,
|
|
78
79
|
usePack: () => usePack,
|
|
@@ -146,8 +147,9 @@ function roundModeFor(seatTwo) {
|
|
|
146
147
|
return seatTwo === "person" ? "twoPlayer" : seatTwo === "nobody" ? "solo" : "vsCpu";
|
|
147
148
|
}
|
|
148
149
|
function seatTwoFor(saved, choices) {
|
|
149
|
-
if (!choices) return "nobody";
|
|
150
|
-
|
|
150
|
+
if (!choices?.length) return "nobody";
|
|
151
|
+
if (choices.includes(saved)) return saved;
|
|
152
|
+
return choices.includes("cpu") ? "cpu" : choices[0];
|
|
151
153
|
}
|
|
152
154
|
function humanSeatsFor(mode) {
|
|
153
155
|
return mode === "twoPlayer" ? [1, 2] : [1];
|
|
@@ -1646,11 +1648,29 @@ var styles6 = import_react_native12.StyleSheet.create({
|
|
|
1646
1648
|
var import_react_redux11 = require("react-redux");
|
|
1647
1649
|
function useActiveRound(game, defaults) {
|
|
1648
1650
|
const round = (0, import_react_redux11.useSelector)((state) => state.liveplay.activeRound);
|
|
1649
|
-
const
|
|
1650
|
-
if (!round || round.game !== game) return { mode:
|
|
1651
|
+
const choices = usePackGame(game)?.seatTwo;
|
|
1652
|
+
if (!round || round.game !== game) return { mode: roundModeFor(seatTwoFor(DEFAULT_OPPONENT.seatTwo, choices)), settings: defaults };
|
|
1651
1653
|
return { mode: round.mode, settings: { ...defaults, ...round.settings } };
|
|
1652
1654
|
}
|
|
1653
1655
|
|
|
1656
|
+
// src/hooks/useBackBlock.ts
|
|
1657
|
+
var import_expo_router7 = require("expo-router");
|
|
1658
|
+
var import_react19 = require("react");
|
|
1659
|
+
function useBackBlock(held, onHeld) {
|
|
1660
|
+
const leavingRef = (0, import_react19.useRef)(false);
|
|
1661
|
+
const [leaving, setLeaving] = (0, import_react19.useState)(false);
|
|
1662
|
+
(0, import_expo_router7.usePreventRemove)(held && !leaving, ({ repeat }) => {
|
|
1663
|
+
if (leavingRef.current) {
|
|
1664
|
+
setLeaving(true);
|
|
1665
|
+
repeat();
|
|
1666
|
+
} else onHeld();
|
|
1667
|
+
});
|
|
1668
|
+
return (0, import_react19.useCallback)(() => {
|
|
1669
|
+
leavingRef.current = true;
|
|
1670
|
+
(0, import_core8.safeBack)();
|
|
1671
|
+
}, []);
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1654
1674
|
// src/redux/createPackStore.ts
|
|
1655
1675
|
var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"));
|
|
1656
1676
|
var import_toolkit = require("@reduxjs/toolkit");
|
|
@@ -1785,7 +1805,7 @@ function forgetProfileAchievements(dropStats) {
|
|
|
1785
1805
|
|
|
1786
1806
|
// src/gameStats.tsx
|
|
1787
1807
|
var import_achievements2 = require("@tastic/achievements");
|
|
1788
|
-
var
|
|
1808
|
+
var import_react20 = require("react");
|
|
1789
1809
|
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
1790
1810
|
var SEATS = [1, 2];
|
|
1791
1811
|
function createGameStats({ key, defaultStats, isValidStats, catalog, getProfileStatsView }) {
|
|
@@ -1803,7 +1823,7 @@ function createGameStats({ key, defaultStats, isValidStats, catalog, getProfileS
|
|
|
1803
1823
|
};
|
|
1804
1824
|
const reducer6 = onProfileRemoved(sliceReducer, forgetProfileAchievements(dropProfileStats));
|
|
1805
1825
|
const profileViews = (stats) => Object.fromEntries(Object.entries(stats.profiles).map(([profileId, bucket]) => [profileId, getProfileStatsView(bucket)]));
|
|
1806
|
-
const Context = (0,
|
|
1826
|
+
const Context = (0, import_react20.createContext)(null);
|
|
1807
1827
|
function Provider({ children }) {
|
|
1808
1828
|
const { stats, unlockedAchievements, recordOutcome, resetAll } = (0, import_achievements2.useAchievements)({
|
|
1809
1829
|
catalog,
|
|
@@ -1811,18 +1831,18 @@ function createGameStats({ key, defaultStats, isValidStats, catalog, getProfileS
|
|
|
1811
1831
|
actions: actions6,
|
|
1812
1832
|
profileViews
|
|
1813
1833
|
});
|
|
1814
|
-
const record = (0,
|
|
1834
|
+
const record = (0, import_react20.useCallback)(
|
|
1815
1835
|
(update, profileIds) => {
|
|
1816
1836
|
const result = recordOutcome(update);
|
|
1817
1837
|
return { device: result.device, profiles: (0, import_achievements2.mapUnlocksBySeat)(SEATS, profileIds, result.profiles) };
|
|
1818
1838
|
},
|
|
1819
1839
|
[recordOutcome]
|
|
1820
1840
|
);
|
|
1821
|
-
const value = (0,
|
|
1841
|
+
const value = (0, import_react20.useMemo)(() => ({ stats, unlockedAchievements, record, resetAll }), [stats, unlockedAchievements, record, resetAll]);
|
|
1822
1842
|
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Context.Provider, { value, children });
|
|
1823
1843
|
}
|
|
1824
1844
|
function useStats() {
|
|
1825
|
-
const ctx = (0,
|
|
1845
|
+
const ctx = (0, import_react20.useContext)(Context);
|
|
1826
1846
|
if (!ctx) throw new Error(`The ${key} stats are read within their game's Provider`);
|
|
1827
1847
|
return ctx;
|
|
1828
1848
|
}
|
|
@@ -1830,7 +1850,7 @@ function createGameStats({ key, defaultStats, isValidStats, catalog, getProfileS
|
|
|
1830
1850
|
}
|
|
1831
1851
|
|
|
1832
1852
|
// src/playerSettings.ts
|
|
1833
|
-
var
|
|
1853
|
+
var import_react21 = require("react");
|
|
1834
1854
|
var import_react_redux12 = require("react-redux");
|
|
1835
1855
|
var SEATS2 = [1, 2];
|
|
1836
1856
|
function seatPlayerKey(selection, seat) {
|
|
@@ -1874,8 +1894,8 @@ function createPlayerSettings({ id, defaults, distinctControls }) {
|
|
|
1874
1894
|
const saved = (0, import_react_redux12.useSelector)((state) => state[settingsKey]);
|
|
1875
1895
|
const controls = (0, import_react_redux12.useSelector)((state) => state[controlsKey]);
|
|
1876
1896
|
const dispatch = (0, import_react_redux12.useDispatch)();
|
|
1877
|
-
const settings = (0,
|
|
1878
|
-
const setSettings = (0,
|
|
1897
|
+
const settings = (0, import_react21.useMemo)(() => compose(saved, controls, selection, seatTwoIsPerson), [saved, controls, selection, seatTwoIsPerson]);
|
|
1898
|
+
const setSettings = (0, import_react21.useCallback)(
|
|
1879
1899
|
(next) => {
|
|
1880
1900
|
const { controlScheme, ...changes } = next;
|
|
1881
1901
|
if (Object.keys(changes).length > 0) dispatch(patch(seatPlayerKey(selection, 1), changes));
|
|
@@ -1936,6 +1956,7 @@ function createPlayerSettings({ id, defaults, distinctControls }) {
|
|
|
1936
1956
|
useActiveRound,
|
|
1937
1957
|
useAppSettings,
|
|
1938
1958
|
useAtComputer,
|
|
1959
|
+
useBackBlock,
|
|
1939
1960
|
useGameGuide,
|
|
1940
1961
|
useOpponent,
|
|
1941
1962
|
usePack,
|
package/dist/index.mjs
CHANGED
|
@@ -69,8 +69,9 @@ function roundModeFor(seatTwo) {
|
|
|
69
69
|
return seatTwo === "person" ? "twoPlayer" : seatTwo === "nobody" ? "solo" : "vsCpu";
|
|
70
70
|
}
|
|
71
71
|
function seatTwoFor(saved, choices) {
|
|
72
|
-
if (!choices) return "nobody";
|
|
73
|
-
|
|
72
|
+
if (!choices?.length) return "nobody";
|
|
73
|
+
if (choices.includes(saved)) return saved;
|
|
74
|
+
return choices.includes("cpu") ? "cpu" : choices[0];
|
|
74
75
|
}
|
|
75
76
|
function humanSeatsFor(mode) {
|
|
76
77
|
return mode === "twoPlayer" ? [1, 2] : [1];
|
|
@@ -1569,11 +1570,29 @@ var styles6 = StyleSheet6.create({
|
|
|
1569
1570
|
import { useSelector as useSelector8 } from "react-redux";
|
|
1570
1571
|
function useActiveRound(game, defaults) {
|
|
1571
1572
|
const round = useSelector8((state) => state.liveplay.activeRound);
|
|
1572
|
-
const
|
|
1573
|
-
if (!round || round.game !== game) return { mode:
|
|
1573
|
+
const choices = usePackGame(game)?.seatTwo;
|
|
1574
|
+
if (!round || round.game !== game) return { mode: roundModeFor(seatTwoFor(DEFAULT_OPPONENT.seatTwo, choices)), settings: defaults };
|
|
1574
1575
|
return { mode: round.mode, settings: { ...defaults, ...round.settings } };
|
|
1575
1576
|
}
|
|
1576
1577
|
|
|
1578
|
+
// src/hooks/useBackBlock.ts
|
|
1579
|
+
import { usePreventRemove } from "expo-router";
|
|
1580
|
+
import { useCallback as useCallback11, useRef as useRef6, useState as useState8 } from "react";
|
|
1581
|
+
function useBackBlock(held, onHeld) {
|
|
1582
|
+
const leavingRef = useRef6(false);
|
|
1583
|
+
const [leaving, setLeaving] = useState8(false);
|
|
1584
|
+
usePreventRemove(held && !leaving, ({ repeat }) => {
|
|
1585
|
+
if (leavingRef.current) {
|
|
1586
|
+
setLeaving(true);
|
|
1587
|
+
repeat();
|
|
1588
|
+
} else onHeld();
|
|
1589
|
+
});
|
|
1590
|
+
return useCallback11(() => {
|
|
1591
|
+
leavingRef.current = true;
|
|
1592
|
+
safeBack();
|
|
1593
|
+
}, []);
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1577
1596
|
// src/redux/createPackStore.ts
|
|
1578
1597
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
1579
1598
|
import { combineReducers, configureStore } from "@reduxjs/toolkit";
|
|
@@ -1708,7 +1727,7 @@ function forgetProfileAchievements(dropStats) {
|
|
|
1708
1727
|
|
|
1709
1728
|
// src/gameStats.tsx
|
|
1710
1729
|
import { createAchievementsSlice, mapUnlocksBySeat, useAchievements } from "@tastic/achievements";
|
|
1711
|
-
import { createContext as createContext5, useCallback as
|
|
1730
|
+
import { createContext as createContext5, useCallback as useCallback12, useContext as useContext5, useMemo as useMemo8 } from "react";
|
|
1712
1731
|
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
1713
1732
|
var SEATS = [1, 2];
|
|
1714
1733
|
function createGameStats({ key, defaultStats, isValidStats, catalog, getProfileStatsView }) {
|
|
@@ -1734,7 +1753,7 @@ function createGameStats({ key, defaultStats, isValidStats, catalog, getProfileS
|
|
|
1734
1753
|
actions: actions6,
|
|
1735
1754
|
profileViews
|
|
1736
1755
|
});
|
|
1737
|
-
const record =
|
|
1756
|
+
const record = useCallback12(
|
|
1738
1757
|
(update, profileIds) => {
|
|
1739
1758
|
const result = recordOutcome(update);
|
|
1740
1759
|
return { device: result.device, profiles: mapUnlocksBySeat(SEATS, profileIds, result.profiles) };
|
|
@@ -1753,7 +1772,7 @@ function createGameStats({ key, defaultStats, isValidStats, catalog, getProfileS
|
|
|
1753
1772
|
}
|
|
1754
1773
|
|
|
1755
1774
|
// src/playerSettings.ts
|
|
1756
|
-
import { useCallback as
|
|
1775
|
+
import { useCallback as useCallback13, useMemo as useMemo9 } from "react";
|
|
1757
1776
|
import { useDispatch as useDispatch11, useSelector as useSelector9 } from "react-redux";
|
|
1758
1777
|
var SEATS2 = [1, 2];
|
|
1759
1778
|
function seatPlayerKey(selection, seat) {
|
|
@@ -1798,7 +1817,7 @@ function createPlayerSettings({ id, defaults, distinctControls }) {
|
|
|
1798
1817
|
const controls = useSelector9((state) => state[controlsKey]);
|
|
1799
1818
|
const dispatch = useDispatch11();
|
|
1800
1819
|
const settings = useMemo9(() => compose(saved, controls, selection, seatTwoIsPerson), [saved, controls, selection, seatTwoIsPerson]);
|
|
1801
|
-
const setSettings =
|
|
1820
|
+
const setSettings = useCallback13(
|
|
1802
1821
|
(next) => {
|
|
1803
1822
|
const { controlScheme, ...changes } = next;
|
|
1804
1823
|
if (Object.keys(changes).length > 0) dispatch(patch(seatPlayerKey(selection, 1), changes));
|
|
@@ -1858,6 +1877,7 @@ export {
|
|
|
1858
1877
|
useActiveRound,
|
|
1859
1878
|
useAppSettings,
|
|
1860
1879
|
useAtComputer,
|
|
1880
|
+
useBackBlock,
|
|
1861
1881
|
useGameGuide,
|
|
1862
1882
|
useOpponent,
|
|
1863
1883
|
usePack,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tastic/shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "The app around a pack of React Native games, two-seat or for one player: Home, the loadout, the stats screen, Profiles and Settings, the pack's Redux store and its root providers, driven by one PackDefinition",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -102,6 +102,7 @@
|
|
|
102
102
|
"expo-font": "~58.0.10",
|
|
103
103
|
"expo-haptics": "~58.0.7",
|
|
104
104
|
"expo-keep-awake": "~58.0.3",
|
|
105
|
+
"expo-linking": "~58.0.17",
|
|
105
106
|
"expo-router": "~58.0.30",
|
|
106
107
|
"expo-splash-screen": "~58.0.13",
|
|
107
108
|
"expo-system-ui": "~58.0.6",
|
|
@@ -53,8 +53,9 @@ export function GuideHost({ children }: Props) {
|
|
|
53
53
|
const seenVersion = useSelector((state: ShellState) => (packGuide ?? gameGuide)?.selectVersionSeen(state) ?? 0)
|
|
54
54
|
const dispatch = useDispatch()
|
|
55
55
|
|
|
56
|
-
// The seat-2 choice the cards describe: the one the player last picked,
|
|
57
|
-
//
|
|
56
|
+
// The seat-2 choice the cards describe: the one the player last picked, or where the game doesn't
|
|
57
|
+
// offer it the CPU (a saved 'nobody' in a game without a solo mode) or, in a game with no CPU, its
|
|
58
|
+
// first choice; nobody in a game for one.
|
|
58
59
|
const mode = roundModeFor(seatTwoFor(seatTwo, game?.seatTwo))
|
|
59
60
|
const steps = useMemo(() => (packGuide ? packGuide.getSteps({ touch }) : gameGuide ? gameGuide.getSteps(input, { touch, mode }) : []), [packGuide, gameGuide, input, touch, mode])
|
|
60
61
|
const onSeen = useCallback(
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { useSelector } from 'react-redux'
|
|
2
2
|
|
|
3
3
|
import { usePackGame } from '../PackContext'
|
|
4
|
+
import { DEFAULT_OPPONENT } from '../redux/opponentSlice'
|
|
4
5
|
import type { ShellState } from '../redux/shellState'
|
|
5
|
-
import type
|
|
6
|
+
import { type RoundMode, roundModeFor, seatTwoFor } from '../types'
|
|
6
7
|
|
|
7
8
|
// The round a play screen is playing: committed by the loadout when every human player readied up
|
|
8
9
|
// (see liveplaySlice.ts). A play screen reached without one (a direct link, a web reload, or a game
|
|
9
|
-
// with no loadout, which Home opens straight away) plays its game's defaults:
|
|
10
|
-
// solo in a game with no seat 2
|
|
10
|
+
// with no loadout, which Home opens straight away) plays its game's defaults: a fresh install's seat
|
|
11
|
+
// 2 as that game reads it (seatTwoFor), so against the CPU, solo in a game with no seat 2
|
|
12
|
+
// (GameDefinition.seatTwo), and the game's first choice in one without a CPU.
|
|
11
13
|
export function useActiveRound<S extends object>(game: string, defaults: S): { mode: RoundMode; settings: S } {
|
|
12
14
|
const round = useSelector((state: ShellState) => state.liveplay.activeRound)
|
|
13
|
-
const
|
|
14
|
-
if (!round || round.game !== game) return { mode:
|
|
15
|
+
const choices = usePackGame(game)?.seatTwo
|
|
16
|
+
if (!round || round.game !== game) return { mode: roundModeFor(seatTwoFor(DEFAULT_OPPONENT.seatTwo, choices)), settings: defaults }
|
|
15
17
|
return { mode: round.mode, settings: { ...defaults, ...(round.settings as Partial<S>) } }
|
|
16
18
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { usePreventRemove } from 'expo-router'
|
|
2
|
+
import { useCallback, useRef, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import { safeBack } from '../navigation'
|
|
5
|
+
|
|
6
|
+
// Holds a play screen while `held`: every way off it but the returned `quit` (Android's hardware or
|
|
7
|
+
// gesture back, the browser's back, a link) runs `onHeld` instead, which in a game is the
|
|
8
|
+
// `requestBack` from @tastic/hud's useQuitConfirmation, so it opens the same Quit Match? the back chip
|
|
9
|
+
// does (audit F093: Android's back and the browser's back left a match at once). iOS's swipe back is
|
|
10
|
+
// already off on every screen (RootLayout's useThemedRootBackground). `held` is a plain boolean read
|
|
11
|
+
// as the screen renders, not useQuitConfirmation's lazy getter, since expo-router needs to know before
|
|
12
|
+
// a back comes in; a game whose progress comes from a state hook that needs Quit Match?'s `paused`
|
|
13
|
+
// calls this after that hook, with the same test it hands useQuitConfirmation. Off at Game Over, so
|
|
14
|
+
// a back there leaves at once, as the chip does.
|
|
15
|
+
//
|
|
16
|
+
// The block stops every navigation off the screen while it's on, Quit's own included, so `quit` marks
|
|
17
|
+
// the way out first and the block lets that one through with `repeat` (expo-router's way to carry on
|
|
18
|
+
// with a navigation it stopped). The block goes off in the same handler as `repeat`, the order
|
|
19
|
+
// expo-router documents (it warns otherwise): turned off any sooner, it can stand aside after it has
|
|
20
|
+
// stopped the navigation and no longer hand it to this callback, so Quit would do nothing. That was a
|
|
21
|
+
// real bug in DuelTastic (2026-11-06), whose copy this is.
|
|
22
|
+
//
|
|
23
|
+
// While it's on, the web also asks before the page unloads (expo-router's usePreventRemove adds a
|
|
24
|
+
// beforeunload handler with it).
|
|
25
|
+
export function useBackBlock(held: boolean, onHeld: () => void): () => void {
|
|
26
|
+
const leavingRef = useRef(false)
|
|
27
|
+
const [leaving, setLeaving] = useState(false)
|
|
28
|
+
usePreventRemove(held && !leaving, ({ repeat }) => {
|
|
29
|
+
if (leavingRef.current) {
|
|
30
|
+
setLeaving(true)
|
|
31
|
+
repeat()
|
|
32
|
+
} else onHeld()
|
|
33
|
+
})
|
|
34
|
+
return useCallback(() => {
|
|
35
|
+
leavingRef.current = true
|
|
36
|
+
safeBack()
|
|
37
|
+
}, [])
|
|
38
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ export { SettingsDialog, type SettingsDialogProps } from './components/SettingsD
|
|
|
20
20
|
export { useActiveRound } from './hooks/useActiveRound'
|
|
21
21
|
export { useAppSettings } from './hooks/useAppSettings'
|
|
22
22
|
export { useAtComputer } from './hooks/useAtComputer'
|
|
23
|
+
export { useBackBlock } from './hooks/useBackBlock'
|
|
23
24
|
export { useOpponent } from './hooks/useOpponent'
|
|
24
25
|
export { ProfilesProvider, useProfiles } from './hooks/useProfiles'
|
|
25
26
|
export { useSeatColors } from './hooks/useSeatColors'
|
|
@@ -5,8 +5,8 @@ import type { SeatTwo } from '../types'
|
|
|
5
5
|
// Who sits in seat 2, for the whole pack: picked from player 1's opponent button in any game's loadout and
|
|
6
6
|
// kept from one game to the next and across relaunches, since it's usually the same two people.
|
|
7
7
|
// A fresh install starts on the CPU, so one person (App Review included) can tap a game and play.
|
|
8
|
-
// A game
|
|
9
|
-
// types.ts' seatTwoFor).
|
|
8
|
+
// A game that doesn't offer the saved choice reads it as the CPU, or as its first choice in a game
|
|
9
|
+
// with no CPU, so a fresh install opens a CPU-less game on that (see types.ts' seatTwoFor).
|
|
10
10
|
export interface OpponentState {
|
|
11
11
|
seatTwo: SeatTwo
|
|
12
12
|
}
|
package/src/types.ts
CHANGED
|
@@ -24,12 +24,15 @@ export function roundModeFor(seatTwo: SeatTwo): RoundMode {
|
|
|
24
24
|
return seatTwo === 'person' ? 'twoPlayer' : seatTwo === 'nobody' ? 'solo' : 'vsCpu'
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
// Seat 2's saved choice in one game (GameDefinition.seatTwo)
|
|
28
|
-
// game
|
|
29
|
-
//
|
|
27
|
+
// Seat 2's saved choice in one game (GameDefinition.seatTwo). The saved choice is the whole pack's, so
|
|
28
|
+
// a game can be handed one it doesn't offer: that reads as the CPU where the game has one (a saved
|
|
29
|
+
// 'nobody' in a game without a solo mode), and as the game's first choice where it has none (a fresh
|
|
30
|
+
// install's saved CPU, in a game offering ['nobody', 'person'], is Solo). A game with no seat 2 at all
|
|
31
|
+
// (no seatTwo) is always nobody, so it plays solo.
|
|
30
32
|
export function seatTwoFor(saved: SeatTwo, choices: readonly SeatTwo[] | undefined): SeatTwo {
|
|
31
|
-
if (!choices) return 'nobody'
|
|
32
|
-
|
|
33
|
+
if (!choices?.length) return 'nobody'
|
|
34
|
+
if (choices.includes(saved)) return saved
|
|
35
|
+
return choices.includes('cpu') ? 'cpu' : choices[0]
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
// The players who take part in a round and have to press Ready: a CPU and nobody don't.
|