@pretty-chitty/core 1.1.2 → 1.2.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.
- package/dist/components/BottomBarButton.d.ts +2 -1
- package/dist/components/BottomBarButton.d.ts.map +1 -1
- package/dist/components/BottomBarButton.js +2 -1
- package/dist/components/BottomBarButton.js.map +1 -1
- package/dist/components/ClientTrustMatchViewer.d.ts +4 -1
- package/dist/components/ClientTrustMatchViewer.d.ts.map +1 -1
- package/dist/components/ClientTrustMatchViewer.js +11 -4
- package/dist/components/ClientTrustMatchViewer.js.map +1 -1
- package/dist/components/ContextGalleryDisplay.js +1 -1
- package/dist/components/ContextGalleryDisplay.js.map +1 -1
- package/dist/components/DemoWrapper.d.ts +9 -0
- package/dist/components/DemoWrapper.d.ts.map +1 -0
- package/dist/components/DemoWrapper.js +76 -0
- package/dist/components/DemoWrapper.js.map +1 -0
- package/dist/components/FullScreenGalleryDisplay.d.ts +2 -0
- package/dist/components/FullScreenGalleryDisplay.d.ts.map +1 -0
- package/dist/components/FullScreenGalleryDisplay.js +56 -0
- package/dist/components/FullScreenGalleryDisplay.js.map +1 -0
- package/dist/components/Gallery/AnimationController.d.ts +19 -0
- package/dist/components/Gallery/AnimationController.d.ts.map +1 -0
- package/dist/components/Gallery/AnimationController.js +82 -0
- package/dist/components/Gallery/AnimationController.js.map +1 -0
- package/dist/components/Gallery/BuiltItem.d.ts +58 -0
- package/dist/components/Gallery/BuiltItem.d.ts.map +1 -0
- package/dist/components/Gallery/BuiltItem.js +313 -0
- package/dist/components/Gallery/BuiltItem.js.map +1 -0
- package/dist/components/Gallery/CameraManager.d.ts +14 -0
- package/dist/components/Gallery/CameraManager.d.ts.map +1 -0
- package/dist/components/Gallery/CameraManager.js +43 -0
- package/dist/components/Gallery/CameraManager.js.map +1 -0
- package/dist/components/Gallery/GalleryController.d.ts +30 -0
- package/dist/components/Gallery/GalleryController.d.ts.map +1 -0
- package/dist/components/Gallery/GalleryController.js +137 -0
- package/dist/components/Gallery/GalleryController.js.map +1 -0
- package/dist/components/Gallery/GalleryViewer.d.ts +18 -0
- package/dist/components/Gallery/GalleryViewer.d.ts.map +1 -0
- package/dist/components/Gallery/GalleryViewer.js +141 -0
- package/dist/components/Gallery/GalleryViewer.js.map +1 -0
- package/dist/components/Gallery/LayoutManager.d.ts +49 -0
- package/dist/components/Gallery/LayoutManager.d.ts.map +1 -0
- package/dist/components/Gallery/LayoutManager.js +132 -0
- package/dist/components/Gallery/LayoutManager.js.map +1 -0
- package/dist/components/Gallery/constants.d.ts +13 -0
- package/dist/components/Gallery/constants.d.ts.map +1 -0
- package/dist/components/Gallery/constants.js +13 -0
- package/dist/components/Gallery/constants.js.map +1 -0
- package/dist/components/Gallery/index.d.ts +3 -0
- package/dist/components/Gallery/index.d.ts.map +1 -0
- package/dist/components/Gallery/index.js +2 -0
- package/dist/components/Gallery/index.js.map +1 -0
- package/dist/components/Gallery/types.d.ts +45 -0
- package/dist/components/Gallery/types.d.ts.map +1 -0
- package/dist/components/Gallery/types.js +2 -0
- package/dist/components/Gallery/types.js.map +1 -0
- package/dist/components/GalleryPlayground.js +1 -1
- package/dist/components/GalleryPlayground.js.map +1 -1
- package/dist/components/GalleryViewer.d.ts +2 -47
- package/dist/components/GalleryViewer.d.ts.map +1 -1
- package/dist/components/GalleryViewer.js +3 -569
- package/dist/components/GalleryViewer.js.map +1 -1
- package/dist/components/GameDesigner.d.ts.map +1 -1
- package/dist/components/GameDesigner.js +13 -2
- package/dist/components/GameDesigner.js.map +1 -1
- package/dist/components/InlineGalleryDisplay.d.ts +2 -0
- package/dist/components/InlineGalleryDisplay.d.ts.map +1 -0
- package/dist/components/InlineGalleryDisplay.js +69 -0
- package/dist/components/InlineGalleryDisplay.js.map +1 -0
- package/dist/components/LiveButton.d.ts.map +1 -1
- package/dist/components/LiveButton.js +1 -1
- package/dist/components/LiveButton.js.map +1 -1
- package/dist/components/MatchViewer.d.ts +0 -1
- package/dist/components/MatchViewer.d.ts.map +1 -1
- package/dist/components/MatchViewer.js +20 -10
- package/dist/components/MatchViewer.js.map +1 -1
- package/dist/components/Panel/MultiPanel.d.ts.map +1 -1
- package/dist/components/Panel/MultiPanel.js +14 -7
- package/dist/components/Panel/MultiPanel.js.map +1 -1
- package/dist/components/Panel/PanelContents.d.ts +2 -1
- package/dist/components/Panel/PanelContents.d.ts.map +1 -1
- package/dist/components/Panel/PanelContents.js +16 -11
- package/dist/components/Panel/PanelContents.js.map +1 -1
- package/dist/components/Panel/SinglePanel.d.ts.map +1 -1
- package/dist/components/Panel/SinglePanel.js +4 -3
- package/dist/components/Panel/SinglePanel.js.map +1 -1
- package/dist/components/Panel/ViewerWrapper.d.ts +1 -3
- package/dist/components/Panel/ViewerWrapper.d.ts.map +1 -1
- package/dist/components/Panel/ViewerWrapper.js +2 -3
- package/dist/components/Panel/ViewerWrapper.js.map +1 -1
- package/dist/components/Playground.d.ts.map +1 -1
- package/dist/components/Playground.js +353 -50
- package/dist/components/Playground.js.map +1 -1
- package/dist/components/PromptControls.d.ts.map +1 -1
- package/dist/components/PromptControls.js +39 -6
- package/dist/components/PromptControls.js.map +1 -1
- package/dist/components/ServerTrustMatchViewer.d.ts +11 -0
- package/dist/components/ServerTrustMatchViewer.d.ts.map +1 -0
- package/dist/components/ServerTrustMatchViewer.js +26 -0
- package/dist/components/ServerTrustMatchViewer.js.map +1 -0
- package/dist/components/Viewer.d.ts.map +1 -1
- package/dist/components/Viewer.js +54 -14
- package/dist/components/Viewer.js.map +1 -1
- package/dist/game/Chit.d.ts +6 -2
- package/dist/game/Chit.d.ts.map +1 -1
- package/dist/game/Chit.js +50 -6
- package/dist/game/Chit.js.map +1 -1
- package/dist/game/ClientTimeState.d.ts +1 -0
- package/dist/game/ClientTimeState.d.ts.map +1 -1
- package/dist/game/ClientTimeState.js +4 -1
- package/dist/game/ClientTimeState.js.map +1 -1
- package/dist/game/GalleryItemChitChildrenSource.d.ts +1 -0
- package/dist/game/GalleryItemChitChildrenSource.d.ts.map +1 -1
- package/dist/game/GalleryItemChitChildrenSource.js +1 -0
- package/dist/game/GalleryItemChitChildrenSource.js.map +1 -1
- package/dist/game/GalleryItemRawSource.d.ts +1 -0
- package/dist/game/GalleryItemRawSource.d.ts.map +1 -1
- package/dist/game/GalleryItemRawSource.js +1 -0
- package/dist/game/GalleryItemRawSource.js.map +1 -1
- package/dist/game/Game.d.ts +2 -1
- package/dist/game/Game.d.ts.map +1 -1
- package/dist/game/GameButton.d.ts +1 -0
- package/dist/game/GameButton.d.ts.map +1 -1
- package/dist/game/GameButton.js +2 -0
- package/dist/game/GameButton.js.map +1 -1
- package/dist/game/GameDeckChit.d.ts +6 -0
- package/dist/game/GameDeckChit.d.ts.map +1 -1
- package/dist/game/GameDeckChit.js +32 -5
- package/dist/game/GameDeckChit.js.map +1 -1
- package/dist/game/GameMetaData.d.ts +18 -0
- package/dist/game/GameMetaData.d.ts.map +1 -0
- package/dist/game/GameMetaData.js +2 -0
- package/dist/game/GameMetaData.js.map +1 -0
- package/dist/game/GameTheme.d.ts +11 -0
- package/dist/game/GameTheme.d.ts.map +1 -1
- package/dist/game/GameTheme.js +19 -4
- package/dist/game/GameTheme.js.map +1 -1
- package/dist/game/Match.d.ts +2 -1
- package/dist/game/Match.d.ts.map +1 -1
- package/dist/game/Match.js +4 -3
- package/dist/game/Match.js.map +1 -1
- package/dist/game/MatchStorage.d.ts +10 -0
- package/dist/game/MatchStorage.d.ts.map +1 -1
- package/dist/game/MatchStorage.js +29 -0
- package/dist/game/MatchStorage.js.map +1 -1
- package/dist/game/ModalState.d.ts +1 -0
- package/dist/game/ModalState.d.ts.map +1 -1
- package/dist/game/ModalState.js +1 -0
- package/dist/game/ModalState.js.map +1 -1
- package/dist/game/OrderedOutlet.d.ts.map +1 -1
- package/dist/game/OrderedOutlet.js +6 -6
- package/dist/game/OrderedOutlet.js.map +1 -1
- package/dist/game/Pick.d.ts +11 -1
- package/dist/game/Pick.d.ts.map +1 -1
- package/dist/game/Pick.js +83 -1
- package/dist/game/Pick.js.map +1 -1
- package/dist/game/PlayerChit.d.ts +2 -1
- package/dist/game/PlayerChit.d.ts.map +1 -1
- package/dist/game/PlayerChit.js +13 -1
- package/dist/game/PlayerChit.js.map +1 -1
- package/dist/game/PlayerInfo.d.ts +2 -1
- package/dist/game/PlayerInfo.d.ts.map +1 -1
- package/dist/game/PlayerInfo.js +20 -3
- package/dist/game/PlayerInfo.js.map +1 -1
- package/dist/game/Prompt.d.ts +1 -11
- package/dist/game/Prompt.d.ts.map +1 -1
- package/dist/game/Prompt.js +0 -32
- package/dist/game/Prompt.js.map +1 -1
- package/dist/game/RootChit.d.ts +4 -0
- package/dist/game/RootChit.d.ts.map +1 -1
- package/dist/game/RootChit.js +36 -1
- package/dist/game/RootChit.js.map +1 -1
- package/dist/game/Turn.d.ts +9 -8
- package/dist/game/Turn.d.ts.map +1 -1
- package/dist/game/Turn.js +34 -34
- package/dist/game/Turn.js.map +1 -1
- package/dist/game/TurnState.d.ts +3 -2
- package/dist/game/TurnState.d.ts.map +1 -1
- package/dist/game/TurnState.js +22 -2
- package/dist/game/TurnState.js.map +1 -1
- package/dist/game/badAiTransport/BadAIClientPrompts.d.ts +14 -0
- package/dist/game/badAiTransport/BadAIClientPrompts.d.ts.map +1 -0
- package/dist/game/badAiTransport/BadAIClientPrompts.js +50 -0
- package/dist/game/badAiTransport/BadAIClientPrompts.js.map +1 -0
- package/dist/game/clientTransport/ClientTime.js +1 -1
- package/dist/game/clientTransport/ClientTime.js.map +1 -1
- package/dist/game/serverTransport/ServerTime.d.ts.map +1 -1
- package/dist/game/serverTransport/ServerTime.js +1 -1
- package/dist/game/serverTransport/ServerTime.js.map +1 -1
- package/dist/hooks/useButtonGalleriesOptions.d.ts +4 -0
- package/dist/hooks/useButtonGalleriesOptions.d.ts.map +1 -0
- package/dist/hooks/useButtonGalleriesOptions.js +7 -0
- package/dist/hooks/useButtonGalleriesOptions.js.map +1 -0
- package/dist/hooks/useEventChannelState.js +1 -1
- package/dist/hooks/useEventChannelState.js.map +1 -1
- package/dist/hooks/useLoadingStates.d.ts +17 -0
- package/dist/hooks/useLoadingStates.d.ts.map +1 -0
- package/dist/hooks/useLoadingStates.js +44 -0
- package/dist/hooks/useLoadingStates.js.map +1 -0
- package/dist/hooks/useModalState.d.ts +2 -1
- package/dist/hooks/useModalState.d.ts.map +1 -1
- package/dist/hooks/useModalState.js +2 -2
- package/dist/hooks/useModalState.js.map +1 -1
- package/dist/hooks/usePanelPositioning.d.ts +0 -1
- package/dist/hooks/usePanelPositioning.d.ts.map +1 -1
- package/dist/hooks/usePanelPositioning.js.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/rendering/CameraWrapperPerspective.d.ts.map +1 -1
- package/dist/rendering/CameraWrapperPerspective.js +1 -1
- package/dist/rendering/CameraWrapperPerspective.js.map +1 -1
- package/dist/rendering/ChitGalleryItemInstance.d.ts +2 -0
- package/dist/rendering/ChitGalleryItemInstance.d.ts.map +1 -1
- package/dist/rendering/ChitGalleryItemInstance.js +2 -0
- package/dist/rendering/ChitGalleryItemInstance.js.map +1 -1
- package/dist/rendering/ChitRenderInstance.d.ts +13 -2
- package/dist/rendering/ChitRenderInstance.d.ts.map +1 -1
- package/dist/rendering/ChitRenderInstance.js +95 -47
- package/dist/rendering/ChitRenderInstance.js.map +1 -1
- package/dist/rendering/ChitRenderSpec.d.ts +3 -0
- package/dist/rendering/ChitRenderSpec.d.ts.map +1 -1
- package/dist/rendering/ChitRenderSpec.js +3 -0
- package/dist/rendering/ChitRenderSpec.js.map +1 -1
- package/dist/rendering/RootChitRenderInstance.d.ts +5 -2
- package/dist/rendering/RootChitRenderInstance.d.ts.map +1 -1
- package/dist/rendering/RootChitRenderInstance.js +76 -13
- package/dist/rendering/RootChitRenderInstance.js.map +1 -1
- package/dist/rendering/SplayCounter.d.ts.map +1 -1
- package/dist/rendering/SplayCounter.js +1 -1
- package/dist/rendering/SplayCounter.js.map +1 -1
- package/dist/rendering/TextureReferenceCounter.d.ts +1 -1
- package/dist/rendering/TextureReferenceCounter.d.ts.map +1 -1
- package/dist/rendering/TextureReferenceCounter.js +10 -10
- package/dist/rendering/TextureReferenceCounter.js.map +1 -1
- package/dist/rendering/outline/passes/DepthOcclusionPass.js +1 -1
- package/dist/rendering/outline/passes/DepthOcclusionPass.js.map +1 -1
- package/dist/utilities/Annotations.d.ts +59 -0
- package/dist/utilities/Annotations.d.ts.map +1 -1
- package/dist/utilities/Annotations.js +63 -0
- package/dist/utilities/Annotations.js.map +1 -1
- package/dist/utilities/CanvasStack/CanvasOperations.d.ts +10 -1
- package/dist/utilities/CanvasStack/CanvasOperations.d.ts.map +1 -1
- package/dist/utilities/CanvasStack/CanvasOperations.js +8 -0
- package/dist/utilities/CanvasStack/CanvasOperations.js.map +1 -1
- package/dist/utilities/CanvasStack/ReactCanvas.d.ts +4 -2
- package/dist/utilities/CanvasStack/ReactCanvas.d.ts.map +1 -1
- package/dist/utilities/CanvasStack/ReactCanvas.js +5 -2
- package/dist/utilities/CanvasStack/ReactCanvas.js.map +1 -1
- package/dist/utilities/CanvasStack/RichTextRenderer.d.ts.map +1 -1
- package/dist/utilities/CanvasStack/RichTextRenderer.js +12 -4
- package/dist/utilities/CanvasStack/RichTextRenderer.js.map +1 -1
- package/dist/utilities/EventChannel.d.ts.map +1 -1
- package/dist/utilities/EventChannel.js +2 -3
- package/dist/utilities/EventChannel.js.map +1 -1
- package/dist/utilities/GlbLoader.d.ts +15 -0
- package/dist/utilities/GlbLoader.d.ts.map +1 -0
- package/dist/utilities/GlbLoader.js +212 -0
- package/dist/utilities/GlbLoader.js.map +1 -0
- package/dist/utilities/LayoutHelper.js +23 -2
- package/dist/utilities/LayoutHelper.js.map +1 -1
- package/dist/utilities/ObjectWithProps.d.ts.map +1 -1
- package/dist/utilities/ObjectWithProps.js +32 -3
- package/dist/utilities/ObjectWithProps.js.map +1 -1
- package/package.json +6 -5
- package/src/library/components/BottomBarButton.tsx +3 -0
- package/src/library/components/ClientTrustMatchViewer.tsx +23 -8
- package/src/library/components/ContextGalleryDisplay.tsx +2 -2
- package/src/library/components/DemoWrapper.tsx +113 -0
- package/src/library/components/{GalleryDisplay.tsx → FullScreenGalleryDisplay.tsx} +28 -2
- package/src/library/components/Gallery/AnimationController.ts +110 -0
- package/src/library/components/Gallery/BuiltItem.ts +385 -0
- package/src/library/components/Gallery/CameraManager.ts +54 -0
- package/src/library/components/Gallery/GalleryController.ts +193 -0
- package/src/library/components/Gallery/GalleryViewer.tsx +211 -0
- package/src/library/components/Gallery/LayoutManager.ts +166 -0
- package/src/library/components/Gallery/constants.ts +12 -0
- package/src/library/components/Gallery/index.ts +2 -0
- package/src/library/components/Gallery/types.ts +55 -0
- package/src/library/components/GalleryPlayground.tsx +1 -1
- package/src/library/components/GalleryViewer.tsx +4 -773
- package/src/library/components/GameDesigner.tsx +21 -4
- package/src/library/components/InlineGalleryDisplay.tsx +101 -0
- package/src/library/components/LiveButton.tsx +2 -1
- package/src/library/components/MatchViewer.tsx +32 -14
- package/src/library/components/Panel/MultiPanel.tsx +20 -8
- package/src/library/components/Panel/PanelContents.tsx +17 -12
- package/src/library/components/Panel/SinglePanel.tsx +5 -4
- package/src/library/components/Panel/ViewerWrapper.tsx +0 -5
- package/src/library/components/Playground.tsx +692 -119
- package/src/library/components/PromptControls.tsx +61 -8
- package/src/library/components/ServerTrustMatchViewer.tsx +53 -0
- package/src/library/components/Viewer.tsx +60 -20
- package/src/library/game/Chit.ts +53 -6
- package/src/library/game/ClientTimeState.ts +5 -1
- package/src/library/game/GalleryItemChitChildrenSource.ts +2 -0
- package/src/library/game/GalleryItemRawSource.ts +2 -0
- package/src/library/game/Game.ts +3 -1
- package/src/library/game/GameButton.ts +3 -0
- package/src/library/game/GameDeckChit.ts +36 -5
- package/src/library/game/GameMetaData.ts +19 -0
- package/src/library/game/GameTheme.ts +23 -5
- package/src/library/game/Match.ts +4 -3
- package/src/library/game/MatchStorage.ts +37 -0
- package/src/library/game/ModalState.ts +1 -0
- package/src/library/game/OrderedOutlet.ts +6 -6
- package/src/library/game/Pick.ts +98 -2
- package/src/library/game/PlayerChit.ts +13 -1
- package/src/library/game/PlayerInfo.ts +22 -3
- package/src/library/game/Prompt.ts +1 -36
- package/src/library/game/RootChit.ts +41 -1
- package/src/library/game/Turn.ts +37 -40
- package/src/library/game/TurnState.ts +22 -3
- package/src/library/game/badAiTransport/BadAIClientPrompts.ts +60 -0
- package/src/library/game/clientTransport/ClientTime.ts +1 -1
- package/src/library/game/serverTransport/ServerTime.ts +2 -2
- package/src/library/hooks/useButtonGalleriesOptions.tsx +9 -0
- package/src/library/hooks/useEventChannelState.ts +1 -1
- package/src/library/hooks/useLoadingStates.tsx +55 -0
- package/src/library/hooks/useModalState.tsx +2 -2
- package/src/library/hooks/usePanelPositioning.tsx +0 -1
- package/src/library/index.ts +21 -1
- package/src/library/rendering/CameraWrapperPerspective.ts +10 -12
- package/src/library/rendering/ChitGalleryItemInstance.ts +2 -0
- package/src/library/rendering/ChitRenderInstance.ts +119 -61
- package/src/library/rendering/ChitRenderSpec.ts +4 -0
- package/src/library/rendering/RootChitRenderInstance.ts +87 -13
- package/src/library/rendering/SplayCounter.tsx +2 -1
- package/src/library/rendering/TextureReferenceCounter.ts +9 -9
- package/src/library/rendering/outline/passes/DepthOcclusionPass.ts +1 -1
- package/src/library/utilities/Annotations.ts +99 -0
- package/src/library/utilities/CanvasStack/CanvasOperations.tsx +19 -1
- package/src/library/utilities/CanvasStack/ReactCanvas.tsx +10 -3
- package/src/library/utilities/CanvasStack/RichTextRenderer.ts +14 -4
- package/src/library/utilities/EventChannel.ts +2 -4
- package/src/library/utilities/GlbLoader.ts +292 -0
- package/src/library/utilities/LayoutHelper.ts +28 -2
- package/src/library/utilities/ObjectWithProps.ts +27 -3
- package/dist/components/GalleryDisplay.d.ts +0 -2
- package/dist/components/GalleryDisplay.d.ts.map +0 -1
- package/dist/components/GalleryDisplay.js +0 -42
- package/dist/components/GalleryDisplay.js.map +0 -1
- package/dist/utilities/OutlineCanvas.d.ts +0 -12
- package/dist/utilities/OutlineCanvas.d.ts.map +0 -1
- package/dist/utilities/OutlineCanvas.js +0 -31
- package/dist/utilities/OutlineCanvas.js.map +0 -1
- package/dist/utilities/OutlineGeometry.d.ts +0 -3
- package/dist/utilities/OutlineGeometry.d.ts.map +0 -1
- package/dist/utilities/OutlineGeometry.js +0 -57
- package/dist/utilities/OutlineGeometry.js.map +0 -1
- package/src/library/utilities/OutlineCanvas.tsx +0 -45
- package/src/library/utilities/OutlineGeometry.ts +0 -69
|
@@ -7,7 +7,6 @@ import { PlayerInfo } from "./PlayerInfo";
|
|
|
7
7
|
import { MismatchError, RerunError, Turn } from "./Turn";
|
|
8
8
|
import { TurnState } from "./TurnState";
|
|
9
9
|
import { IMatchStorage } from "./MatchStorage";
|
|
10
|
-
import nextTick from "next-tick";
|
|
11
10
|
import { ServerPrompts } from "./serverTransport/ServerPrompts";
|
|
12
11
|
import { EventChannel } from "../utilities/EventChannel";
|
|
13
12
|
import { RootChit } from "./RootChit";
|
|
@@ -25,6 +24,7 @@ export class Match<P extends PlayerChit, R extends RootChit<P>> {
|
|
|
25
24
|
public game: Game<P, R>,
|
|
26
25
|
public players: PlayerInfo[],
|
|
27
26
|
private matchStorage: IMatchStorage,
|
|
27
|
+
private matchOptions?: any,
|
|
28
28
|
) {}
|
|
29
29
|
|
|
30
30
|
async load() {
|
|
@@ -74,9 +74,10 @@ export class Match<P extends PlayerChit, R extends RootChit<P>> {
|
|
|
74
74
|
try {
|
|
75
75
|
this.result.value = undefined;
|
|
76
76
|
this.errorState.value = undefined;
|
|
77
|
-
const rootChit = new this.game.chitLibrary.Root();
|
|
77
|
+
const rootChit = new this.game.chitLibrary.Root() as R;
|
|
78
78
|
rootChit.id = "root";
|
|
79
79
|
rootChit.game = this.game;
|
|
80
|
+
rootChit.processMatchOptions(this.matchOptions ?? {});
|
|
80
81
|
|
|
81
82
|
this.players.forEach((p) => {
|
|
82
83
|
const Player = this.game.chitLibrary.Player;
|
|
@@ -179,7 +180,7 @@ export class Match<P extends PlayerChit, R extends RootChit<P>> {
|
|
|
179
180
|
|
|
180
181
|
public onChange(cb: () => void, callNow = true) {
|
|
181
182
|
this.onChangeCallbacks.push(cb);
|
|
182
|
-
callNow &&
|
|
183
|
+
callNow && queueMicrotask(cb);
|
|
183
184
|
return () => {
|
|
184
185
|
this.onChangeCallbacks = this.onChangeCallbacks.filter((c) => c !== cb);
|
|
185
186
|
};
|
|
@@ -49,3 +49,40 @@ export class LocalMatchStorage implements IMatchStorage {
|
|
|
49
49
|
this.onChangeCallbacks.forEach((cb) => cb(state));
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
|
|
53
|
+
export class EphemeralMatchStorage implements IMatchStorage {
|
|
54
|
+
constructor(private matchId: string) {}
|
|
55
|
+
private onChangeCallbacks: ((state: any) => void)[] = [];
|
|
56
|
+
|
|
57
|
+
private state: string = "{}";
|
|
58
|
+
|
|
59
|
+
async readState(): Promise<any> {
|
|
60
|
+
const result = this.state;
|
|
61
|
+
if (result) {
|
|
62
|
+
return JSON.parse(result);
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
async saveState(
|
|
67
|
+
newState: any,
|
|
68
|
+
players: PlayerChit[],
|
|
69
|
+
matchState: "active" | "finished",
|
|
70
|
+
winners?: PlayerChit[],
|
|
71
|
+
notify = false,
|
|
72
|
+
): Promise<void> {
|
|
73
|
+
this.state = JSON.stringify(newState);
|
|
74
|
+
if (notify) {
|
|
75
|
+
this.notify(newState);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
registerNewStateCallback(cb: (newState: any) => void): () => void {
|
|
79
|
+
this.onChangeCallbacks.push(cb);
|
|
80
|
+
return () => {
|
|
81
|
+
this.onChangeCallbacks = this.onChangeCallbacks.filter((c) => c !== cb);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private notify(state: any) {
|
|
86
|
+
this.onChangeCallbacks.forEach((cb) => cb(state));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -3,6 +3,7 @@ import { EventChannel } from "../utilities/EventChannel";
|
|
|
3
3
|
|
|
4
4
|
export class ModalState {
|
|
5
5
|
public gallerySource = new EventChannel<undefined | GalleryItemSource>(undefined);
|
|
6
|
+
public inlineGallerySource = new EventChannel<undefined | GalleryItemSource>(undefined);
|
|
6
7
|
public actionLogVisible = new EventChannel<boolean>(false);
|
|
7
8
|
public settingsVisible = new EventChannel<boolean>(false);
|
|
8
9
|
|
|
@@ -64,8 +64,9 @@ export class OrderedOutlet<C extends Chit> {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
if (c instanceof OrderedOutlet) {
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const chits = c.chits;
|
|
68
|
+
chits.forEach((c) => c.setParent());
|
|
69
|
+
chits.forEach((c) => this.chits.push(c));
|
|
69
70
|
} else {
|
|
70
71
|
c.forEach((c) => c.setParent());
|
|
71
72
|
c.forEach((c) => this.chits.push(c));
|
|
@@ -76,11 +77,10 @@ export class OrderedOutlet<C extends Chit> {
|
|
|
76
77
|
|
|
77
78
|
public async shuffle() {
|
|
78
79
|
if (this.parent) {
|
|
79
|
-
const
|
|
80
|
-
const to = await this.parent.currentTurn.takeRng(this.length);
|
|
80
|
+
const rngs = await this.parent.currentTurn.takeRng(this.length * 2);
|
|
81
81
|
for (let i = 0; i < this.chits.length; i++) {
|
|
82
|
-
const j = Math.floor(
|
|
83
|
-
const k = Math.floor(
|
|
82
|
+
const j = Math.floor(rngs() * this.chits.length);
|
|
83
|
+
const k = Math.floor(rngs() * this.chits.length);
|
|
84
84
|
const temp = this.chits[j];
|
|
85
85
|
this.chits[j] = this.chits[k];
|
|
86
86
|
this.chits[k] = temp;
|
package/src/library/game/Pick.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { Chit } from "./Chit";
|
|
|
2
2
|
import { GalleryItemChitChildrenSource } from "./GalleryItemChitChildrenSource";
|
|
3
3
|
import { IButtonLibrary } from "./Game";
|
|
4
4
|
import { Confirm, GameButton, ToggleGalleryButton } from "./GameButton";
|
|
5
|
+
import { OrderedOutlet } from "./OrderedOutlet";
|
|
5
6
|
import { PickPrompt } from "./Prompt";
|
|
6
7
|
import { MismatchError, Turn } from "./Turn";
|
|
7
8
|
|
|
8
9
|
export type FindChit = (id: string) => Chit;
|
|
9
|
-
export type PickType = "ChitPick" | "ButtonPick";
|
|
10
|
+
export type PickType = "ChitPick" | "ButtonPick" | "DragPick";
|
|
10
11
|
export type PickSerialization = {
|
|
11
12
|
type: PickType;
|
|
12
13
|
message?: string;
|
|
@@ -88,6 +89,10 @@ export abstract class Pick {
|
|
|
88
89
|
p = new ButtonPick();
|
|
89
90
|
break;
|
|
90
91
|
}
|
|
92
|
+
case "DragPick": {
|
|
93
|
+
p = new DragPick();
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
91
96
|
}
|
|
92
97
|
|
|
93
98
|
if (p) {
|
|
@@ -206,7 +211,11 @@ export class ChitPick<T extends Chit> extends Pick {
|
|
|
206
211
|
this.processFocus();
|
|
207
212
|
this.button?.computeItemSource(this);
|
|
208
213
|
if (this.button?.autoShow && this.button?.galleryItemSource) {
|
|
209
|
-
|
|
214
|
+
const inline = localStorage.galleryFullScreen !== `"modal"`; // hacky but maybe okay
|
|
215
|
+
this.closeGallery = this.chits[0]?.renderInstance?.rootRenderInstance.showGallery(
|
|
216
|
+
this.button.galleryItemSource,
|
|
217
|
+
inline,
|
|
218
|
+
);
|
|
210
219
|
}
|
|
211
220
|
}
|
|
212
221
|
|
|
@@ -242,6 +251,93 @@ export class ChitPick<T extends Chit> extends Pick {
|
|
|
242
251
|
}
|
|
243
252
|
}
|
|
244
253
|
|
|
254
|
+
export class DragTarget<C extends Chit, S extends Chit> {
|
|
255
|
+
public chits: C[] = [];
|
|
256
|
+
public cb: (sourceChit: S, targetChit: C) => void | Promise<void> = () => {};
|
|
257
|
+
|
|
258
|
+
static from<C extends Chit, S extends Chit>(
|
|
259
|
+
chit: C | C[] | OrderedOutlet<C>,
|
|
260
|
+
cb: (sourceChit: S, targetChit: C) => void | Promise<void>,
|
|
261
|
+
) {
|
|
262
|
+
const result = new DragTarget<C, S>();
|
|
263
|
+
result.chits =
|
|
264
|
+
chit instanceof OrderedOutlet ? chit.copy() : Array.isArray(chit) ? (chit.filter((c) => c) as C[]) : [chit];
|
|
265
|
+
result.cb = cb;
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export class DragPick<C extends Chit> extends Pick {
|
|
271
|
+
/** @internal */
|
|
272
|
+
type: PickType = "DragPick";
|
|
273
|
+
|
|
274
|
+
public chits: C[] = [];
|
|
275
|
+
|
|
276
|
+
public dropTargets: DragTarget<any, C>[] = [];
|
|
277
|
+
|
|
278
|
+
/** @internal */
|
|
279
|
+
serializeDetails() {
|
|
280
|
+
const result: any = {
|
|
281
|
+
c: this.chits.map((chit) => chit.id),
|
|
282
|
+
d: this.dropTargets.map((dropTarget) => dropTarget.chits.map((chit) => chit.id)),
|
|
283
|
+
};
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** @internal */
|
|
288
|
+
deserializeDetails({ c, d }: { c: string[]; d: string[][] }, findChit: FindChit): void {
|
|
289
|
+
this.chits = c.map((chitId) => findChit(chitId) as C).filter((d) => d);
|
|
290
|
+
this.dropTargets = d.map((dropIds: string[]) => {
|
|
291
|
+
const result = new DragTarget<any, C>();
|
|
292
|
+
result.chits = dropIds.map((chitId: string) => findChit(chitId)).filter((d) => d);
|
|
293
|
+
return result;
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** @internal */
|
|
298
|
+
resolveDetails({ chitId, targetChitId }: { chitId: string; targetChitId: string }): Promise<void> {
|
|
299
|
+
const selectedChit = this.chits.find((chit) => chit.id === chitId);
|
|
300
|
+
if (!selectedChit) {
|
|
301
|
+
throw new MismatchError();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
for (const dropTarget of this.dropTargets) {
|
|
305
|
+
const targetChit = dropTarget.chits.find((chit) => chit.id === targetChitId);
|
|
306
|
+
if (targetChit) {
|
|
307
|
+
return Promise.resolve(dropTarget.cb(selectedChit, targetChit));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
throw new MismatchError();
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/** @internal */
|
|
314
|
+
stageIn(prompt: PickPrompt) {
|
|
315
|
+
this.chits.forEach((c) => {
|
|
316
|
+
c.dropTargets = this.dropTargets.flatMap((dt) => dt.chits);
|
|
317
|
+
c.onDrag = (droppedChit: Chit) => {
|
|
318
|
+
prompt.resolvePick(this, { chitId: c.id!, targetChitId: droppedChit.id! });
|
|
319
|
+
};
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** @internal */
|
|
324
|
+
stageOut() {
|
|
325
|
+
this.chits.forEach((c) => (c.onDrag = undefined));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** @internal */
|
|
329
|
+
autoResolve(): Promise<void | undefined> {
|
|
330
|
+
const selectedChit = this.chits[0];
|
|
331
|
+
const targetChit = this.dropTargets[0].chits[0];
|
|
332
|
+
return Promise.resolve(this.dropTargets[0].cb(selectedChit, targetChit));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** @internal */
|
|
336
|
+
numberOfChoices(): number {
|
|
337
|
+
return this.chits.length * this.dropTargets.reduce((sum, dt) => sum + dt.chits.length, 0);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
245
341
|
export class ButtonPick extends Pick {
|
|
246
342
|
/** @internal */
|
|
247
343
|
type: PickType = "ButtonPick";
|
|
@@ -10,9 +10,21 @@ export class PlayerChit extends Chit {
|
|
|
10
10
|
|
|
11
11
|
public playerId: string = "no id";
|
|
12
12
|
public name: string = "no name";
|
|
13
|
-
public imageUrl?: string;
|
|
14
13
|
public color: string = "#000000";
|
|
15
14
|
|
|
15
|
+
/** @internal */
|
|
16
|
+
private _imageUrl?: string = undefined;
|
|
17
|
+
get imageUrl() {
|
|
18
|
+
if (!this._imageUrl) {
|
|
19
|
+
const tempPlayerInfo = new PlayerInfo(this.playerId, this.name);
|
|
20
|
+
return tempPlayerInfo.generateAvatar();
|
|
21
|
+
}
|
|
22
|
+
return this._imageUrl;
|
|
23
|
+
}
|
|
24
|
+
set imageUrl(value: string | undefined) {
|
|
25
|
+
this._imageUrl = value;
|
|
26
|
+
}
|
|
27
|
+
|
|
16
28
|
/** @internal */
|
|
17
29
|
@NonEditable public matchScoreNumber?: number;
|
|
18
30
|
|
|
@@ -8,10 +8,30 @@ export interface IPlayerInfo {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export class PlayerInfo {
|
|
11
|
-
public imageUrl?: string;
|
|
12
11
|
public id: string;
|
|
13
12
|
public name: string;
|
|
14
13
|
|
|
14
|
+
/** @internal */
|
|
15
|
+
public generateAvatar() {
|
|
16
|
+
if (!this._imageUrl && window?.URL) {
|
|
17
|
+
const data = multiavatar(`${this.name} ${this.id}`, true).replace("<svg", '<svg width="231" height="231"');
|
|
18
|
+
return `data:image/svg+xml;base64,${base64.encode(data)}`;
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** @internal */
|
|
24
|
+
private _imageUrl?: string;
|
|
25
|
+
get imageUrl() {
|
|
26
|
+
if (!this._imageUrl && window?.URL) {
|
|
27
|
+
return this.generateAvatar();
|
|
28
|
+
}
|
|
29
|
+
return this._imageUrl;
|
|
30
|
+
}
|
|
31
|
+
set imageUrl(value: string | undefined) {
|
|
32
|
+
this._imageUrl = value;
|
|
33
|
+
}
|
|
34
|
+
|
|
15
35
|
constructor(idOrPlayerInfo: string | IPlayerInfo, name?: string) {
|
|
16
36
|
if (typeof idOrPlayerInfo === "string") {
|
|
17
37
|
this.id = idOrPlayerInfo;
|
|
@@ -23,8 +43,7 @@ export class PlayerInfo {
|
|
|
23
43
|
}
|
|
24
44
|
|
|
25
45
|
if (!this.imageUrl && window?.URL) {
|
|
26
|
-
|
|
27
|
-
this.imageUrl = `data:image/svg+xml;base64,${base64.encode(data)}`;
|
|
46
|
+
this.imageUrl = this.generateAvatar();
|
|
28
47
|
}
|
|
29
48
|
}
|
|
30
49
|
}
|
|
@@ -4,7 +4,7 @@ import { Confirm, GameButton } from "./GameButton";
|
|
|
4
4
|
import { ButtonPick, ChitPick, Pick } from "./Pick";
|
|
5
5
|
import { MismatchError, Turn } from "./Turn";
|
|
6
6
|
|
|
7
|
-
type PromptType = "
|
|
7
|
+
type PromptType = "PickPrompt" | "NoValidMovesPrompt";
|
|
8
8
|
|
|
9
9
|
export type PromptSerialization = {
|
|
10
10
|
type: PromptType;
|
|
@@ -97,10 +97,6 @@ export abstract class Prompt {
|
|
|
97
97
|
public static deserialize(prompt: PromptSerialization, findChit: FindChit, buttonLibrary: IButtonLibrary): Prompt {
|
|
98
98
|
let p: Prompt | undefined = undefined;
|
|
99
99
|
switch (prompt.type) {
|
|
100
|
-
case "SelectPrompt": {
|
|
101
|
-
p = new SelectPrompt();
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
100
|
case "PickPrompt": {
|
|
105
101
|
p = new PickPrompt();
|
|
106
102
|
break;
|
|
@@ -162,37 +158,6 @@ export class NoValidMovesPrompt extends Prompt {
|
|
|
162
158
|
stageOut(): void {}
|
|
163
159
|
}
|
|
164
160
|
|
|
165
|
-
export class SelectPrompt extends Prompt {
|
|
166
|
-
type: PromptType = "SelectPrompt";
|
|
167
|
-
|
|
168
|
-
public chits: Chit[] = [];
|
|
169
|
-
public selectedChit: Chit | undefined;
|
|
170
|
-
|
|
171
|
-
serializeDetails(): any {
|
|
172
|
-
return this.chits.map((chit) => chit.id);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
deserializeDetails(chitIds: string[]): void {
|
|
176
|
-
this.chits = chitIds.map((chitId) => this.findChit(chitId));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
resolveDetails(chitId: string) {
|
|
180
|
-
this.resolved = true;
|
|
181
|
-
this.selectedChit = this.chits.find((chit) => chit.id === chitId);
|
|
182
|
-
if (!this.selectedChit) {
|
|
183
|
-
throw new MismatchError();
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
stageIn() {
|
|
188
|
-
this.chits.forEach((c) => (c.onClick = () => this.resolve(c.id)));
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
stageOut() {
|
|
192
|
-
this.chits.forEach((c) => (c.onClick = undefined));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
161
|
type PickResolution = { idx: number; value: any };
|
|
197
162
|
|
|
198
163
|
export class PickPrompt extends Prompt {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NonEditable } from "../utilities/Annotations";
|
|
1
|
+
import { NonEditable, getSelectableProperties, SelectablePropertyInfo } from "../utilities/Annotations";
|
|
2
2
|
import { Chit } from "./Chit";
|
|
3
3
|
import { DropdownChit } from "./DropdownChit";
|
|
4
4
|
import { OrderedOutlet } from "./OrderedOutlet";
|
|
@@ -8,6 +8,9 @@ import { LayoutNode, createLayoutFromTree, PanelLayoutResult } from "../utilitie
|
|
|
8
8
|
export type { PanelLayoutResult } from "../utilities/LayoutHelper";
|
|
9
9
|
|
|
10
10
|
export class RootChit<P extends PlayerChit> extends Chit {
|
|
11
|
+
minPlayers = 2;
|
|
12
|
+
maxPlayers = 4;
|
|
13
|
+
|
|
11
14
|
/** @internal */
|
|
12
15
|
@NonEditable type = "root";
|
|
13
16
|
|
|
@@ -51,4 +54,41 @@ export class RootChit<P extends PlayerChit> extends Chit {
|
|
|
51
54
|
public getDropdowns(): DropdownChit[] {
|
|
52
55
|
return [];
|
|
53
56
|
}
|
|
57
|
+
|
|
58
|
+
/** Sets up a demo game. Returns the player count to use in the demo game. */
|
|
59
|
+
public setupDemoGame(): number {
|
|
60
|
+
return this.minPlayers;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Gets all properties on this RootChit instance that are marked with the @Selectable decorator.
|
|
65
|
+
*
|
|
66
|
+
* @returns An array of SelectablePropertyInfo containing the field name, label, choices, and current value
|
|
67
|
+
*/
|
|
68
|
+
/** @internal */
|
|
69
|
+
public getConfigurationOptions(): SelectablePropertyInfo[] {
|
|
70
|
+
return getSelectableProperties(this);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** @internal */
|
|
74
|
+
public getCurrentlySelectedMatchOptions(): any {
|
|
75
|
+
const result = {};
|
|
76
|
+
const selectables = this.getConfigurationOptions();
|
|
77
|
+
for (const selectable of selectables) {
|
|
78
|
+
if ((this as any)[selectable.fieldName] !== undefined) {
|
|
79
|
+
(result as any)[selectable.fieldName] = (this as any)[selectable.fieldName];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** @internal */
|
|
86
|
+
public processMatchOptions(options: any): void {
|
|
87
|
+
const selectables = this.getConfigurationOptions();
|
|
88
|
+
for (const selectable of selectables) {
|
|
89
|
+
if (options[selectable.fieldName] !== undefined) {
|
|
90
|
+
(this as any)[selectable.fieldName] = options[selectable.fieldName];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
54
94
|
}
|
package/src/library/game/Turn.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import nextTick from "next-tick";
|
|
2
1
|
import { Chit } from "./Chit";
|
|
3
2
|
import { Match } from "./Match";
|
|
4
|
-
import { NoValidMovesPrompt, PickPrompt, Prompt
|
|
3
|
+
import { NoValidMovesPrompt, PickPrompt, Prompt } from "./Prompt";
|
|
5
4
|
import { PromptResponse, RngResponse, TurnState } from "./TurnState";
|
|
6
5
|
import { ButtonPick, Pick } from "./Pick";
|
|
7
6
|
import { Confirm, GameButton } from "./GameButton";
|
|
@@ -188,11 +187,8 @@ export class Turn<T, P extends PlayerChit, R extends RootChit<P>> {
|
|
|
188
187
|
*/
|
|
189
188
|
async takeRng(count: number, message = "confirm draw or roll"): Promise<() => number> {
|
|
190
189
|
await this.possiblyConfirm(message);
|
|
191
|
-
const results: number[] =
|
|
192
|
-
|
|
193
|
-
results.push(this.state.getOrCreateRng(this.decisionIndex));
|
|
194
|
-
this.decisionIndex++;
|
|
195
|
-
}
|
|
190
|
+
const results: number[] = this.state.getOrCreateMultipleRng(this.decisionIndex, count);
|
|
191
|
+
this.decisionIndex++;
|
|
196
192
|
|
|
197
193
|
let counter = 0;
|
|
198
194
|
return () => {
|
|
@@ -249,6 +245,35 @@ export class Turn<T, P extends PlayerChit, R extends RootChit<P>> {
|
|
|
249
245
|
step.log = message;
|
|
250
246
|
}
|
|
251
247
|
|
|
248
|
+
/**
|
|
249
|
+
* Compress the history in the timeline such that a user with maybe many moves (and changing their minds) won't
|
|
250
|
+
* clock up the replay timeline. Basically takes all of the flushes and smushes them together into a single flush.
|
|
251
|
+
* Importantly, it leaves the (maybe lots) of decisions on the decision stack. This just compresses flushes into a single
|
|
252
|
+
* flush step.
|
|
253
|
+
*
|
|
254
|
+
* This should only be done immediately after every zippable action *or* after undos are no longer possible.
|
|
255
|
+
*/
|
|
256
|
+
zip() {
|
|
257
|
+
this.flush();
|
|
258
|
+
let hasChange = false;
|
|
259
|
+
while (this.clockSteps.length >= 2) {
|
|
260
|
+
const lastStep = this.clockSteps[this.clockSteps.length - 1];
|
|
261
|
+
const previousStep = this.clockSteps[this.clockSteps.length - 2];
|
|
262
|
+
if (!(lastStep instanceof FlushClockStep) || !(previousStep instanceof FlushClockStep)) {
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
previousStep.state = { ...previousStep.state, ...lastStep.state };
|
|
267
|
+
this.clockSteps.pop();
|
|
268
|
+
hasChange = true;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (hasChange) {
|
|
272
|
+
this.pass++;
|
|
273
|
+
this.flush();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
252
277
|
/**
|
|
253
278
|
* Scan all of the chits managed by this turn. If any of them have changed, group them together into a
|
|
254
279
|
* "ClockStep". If any new chits appear, then add them to our lookup. If any chits are deleted (orphaned),
|
|
@@ -416,7 +441,7 @@ export class Turn<T, P extends PlayerChit, R extends RootChit<P>> {
|
|
|
416
441
|
this.activeSubTurns.push(turn);
|
|
417
442
|
|
|
418
443
|
//make sure flow goes to next tick
|
|
419
|
-
await new Promise((resolve) =>
|
|
444
|
+
await new Promise((resolve) => queueMicrotask(() => resolve(true)));
|
|
420
445
|
|
|
421
446
|
await this.checkPause();
|
|
422
447
|
|
|
@@ -453,34 +478,6 @@ export class Turn<T, P extends PlayerChit, R extends RootChit<P>> {
|
|
|
453
478
|
return await Promise.all(turns);
|
|
454
479
|
}
|
|
455
480
|
|
|
456
|
-
/**
|
|
457
|
-
* Basic selection prompt. All chits will appear as "selected" on the respective client.
|
|
458
|
-
* Upon clicking one, the prompt will resolve itself.
|
|
459
|
-
*
|
|
460
|
-
* @param chits The list of chits that can be selected from
|
|
461
|
-
* @returns The chit that the player selected
|
|
462
|
-
*/
|
|
463
|
-
public async select(chits: Chit[]): Promise<Chit> {
|
|
464
|
-
if (chits.length === 1) {
|
|
465
|
-
return chits[0];
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
const prompt = new SelectPrompt();
|
|
469
|
-
prompt.chits = chits;
|
|
470
|
-
|
|
471
|
-
this.prepareForPrompt(prompt);
|
|
472
|
-
|
|
473
|
-
// make sure all of these chits are locked by us - otherwise someone has made a mistake.
|
|
474
|
-
chits.forEach((chit) => chit.confirmLock(this));
|
|
475
|
-
|
|
476
|
-
await this.waitForPromptResolution(prompt);
|
|
477
|
-
if (!prompt.selectedChit) {
|
|
478
|
-
throw new Error("Prompt should have selected chit response");
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
return prompt.selectedChit;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
481
|
/**
|
|
485
482
|
* If a player has gotten themselves into a corner - i.e. no valid moves - this prompt will
|
|
486
483
|
* simply inform them of that and allow them to undo.
|
|
@@ -603,7 +600,7 @@ export class Turn<T, P extends PlayerChit, R extends RootChit<P>> {
|
|
|
603
600
|
this.pause();
|
|
604
601
|
|
|
605
602
|
// defer to next tick on starting
|
|
606
|
-
await new Promise<void>((resolve) =>
|
|
603
|
+
await new Promise<void>((resolve) => queueMicrotask(() => resolve()));
|
|
607
604
|
|
|
608
605
|
const instructions = this.handleNewSavedState(state);
|
|
609
606
|
|
|
@@ -615,7 +612,7 @@ export class Turn<T, P extends PlayerChit, R extends RootChit<P>> {
|
|
|
615
612
|
instruction.turn.rerun(instruction.turn);
|
|
616
613
|
} else if (instruction.type === "prompt") {
|
|
617
614
|
await new Promise<void>((resolve, reject) =>
|
|
618
|
-
|
|
615
|
+
queueMicrotask(() => {
|
|
619
616
|
if (instruction.turn.unresolvedPrompt !== instruction.prompt) {
|
|
620
617
|
reject("waiting on incorrect prompt");
|
|
621
618
|
}
|
|
@@ -627,7 +624,7 @@ export class Turn<T, P extends PlayerChit, R extends RootChit<P>> {
|
|
|
627
624
|
}
|
|
628
625
|
|
|
629
626
|
// always defer to next tick again when resuming
|
|
630
|
-
await new Promise<void>((resolve) =>
|
|
627
|
+
await new Promise<void>((resolve) => queueMicrotask(() => resolve()));
|
|
631
628
|
} finally {
|
|
632
629
|
this.unpause();
|
|
633
630
|
this.isProcessingSavedState = false;
|
|
@@ -922,7 +919,7 @@ export class Turn<T, P extends PlayerChit, R extends RootChit<P>> {
|
|
|
922
919
|
await this.checkPause(); // state could have gotten funky here? if we have a resolution already? maybe not so bad?
|
|
923
920
|
|
|
924
921
|
if (resolution.response !== undefined) {
|
|
925
|
-
await new Promise((resolve) =>
|
|
922
|
+
await new Promise((resolve) => queueMicrotask(() => resolve(true))); // defer to next tick to make sure replay works identically
|
|
926
923
|
prompt.resolve(resolution.response);
|
|
927
924
|
} else {
|
|
928
925
|
if (this.player.promptStatus.latestPrompt.value) {
|
|
@@ -8,7 +8,7 @@ export type PromptResponse = {
|
|
|
8
8
|
timestamp: Date;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export type RngResponse = { readonly type: "rng"; value: number };
|
|
11
|
+
export type RngResponse = { readonly type: "rng"; value: number[] };
|
|
12
12
|
|
|
13
13
|
export type Decision = PromptResponse | RngResponse | TurnState;
|
|
14
14
|
|
|
@@ -66,12 +66,12 @@ export class TurnState {
|
|
|
66
66
|
if (result.type !== "rng") {
|
|
67
67
|
throw new MismatchError();
|
|
68
68
|
}
|
|
69
|
-
return (result as RngResponse).value;
|
|
69
|
+
return (result as RngResponse).value[0];
|
|
70
70
|
} else if (index === this.decisions.length) {
|
|
71
71
|
const rng = Math.random();
|
|
72
72
|
this.decisions.push({
|
|
73
73
|
type: "rng",
|
|
74
|
-
value: rng,
|
|
74
|
+
value: [rng],
|
|
75
75
|
});
|
|
76
76
|
return rng;
|
|
77
77
|
} else {
|
|
@@ -79,6 +79,25 @@ export class TurnState {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
public getOrCreateMultipleRng(index: number, count: number): number[] {
|
|
83
|
+
if (index < this.decisions.length) {
|
|
84
|
+
const result = this.decisions[index];
|
|
85
|
+
if (result.type !== "rng" || result.value.length !== count) {
|
|
86
|
+
throw new MismatchError();
|
|
87
|
+
}
|
|
88
|
+
return (result as RngResponse).value;
|
|
89
|
+
} else if (index === this.decisions.length) {
|
|
90
|
+
const rngs = Array.from({ length: count }, () => Math.random());
|
|
91
|
+
this.decisions.push({
|
|
92
|
+
type: "rng",
|
|
93
|
+
value: rngs,
|
|
94
|
+
});
|
|
95
|
+
return rngs;
|
|
96
|
+
} else {
|
|
97
|
+
throw new MismatchError();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
82
101
|
public getOrCreateTurnState(index: number): TurnState {
|
|
83
102
|
if (index < this.decisions.length) {
|
|
84
103
|
const result = this.decisions[index];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ClockDetails } from "../ClockDetails";
|
|
2
|
+
import { Connection } from "../Connection";
|
|
3
|
+
import { ConnectionObject } from "../ConnectionObject";
|
|
4
|
+
import { PickType } from "../Pick";
|
|
5
|
+
import { PlayerChit } from "../PlayerChit";
|
|
6
|
+
import { PromptSerialization } from "../Prompt";
|
|
7
|
+
import { RootChit } from "../RootChit";
|
|
8
|
+
import { ServerPrompts } from "../serverTransport/ServerPrompts";
|
|
9
|
+
|
|
10
|
+
export class BadAIClientPrompts<P extends PlayerChit, R extends RootChit<P>> extends ConnectionObject {
|
|
11
|
+
private serverPrompts: ServerPrompts<P, R>;
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
private playerId: string,
|
|
15
|
+
private connection: Connection,
|
|
16
|
+
) {
|
|
17
|
+
super();
|
|
18
|
+
|
|
19
|
+
this.serverPrompts = connection.get<ServerPrompts<P, R>>("ServerPrompts");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public async setPromptForPlayer(playerId: string, prompt?: PromptSerialization, clockDetails?: ClockDetails) {
|
|
23
|
+
console.log("Setting prompt for player", playerId, prompt, clockDetails);
|
|
24
|
+
if (prompt && playerId === this.playerId) {
|
|
25
|
+
if (prompt.type === "PickPrompt") {
|
|
26
|
+
const picks = prompt.details.picks;
|
|
27
|
+
const pickIndex = Math.floor(Math.random() * picks.length);
|
|
28
|
+
const pick = picks[pickIndex];
|
|
29
|
+
switch (pick.type as PickType) {
|
|
30
|
+
case "ButtonPick": {
|
|
31
|
+
await this.serverPrompts.resolvePrompt({
|
|
32
|
+
idx: pickIndex,
|
|
33
|
+
});
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case "ChitPick": {
|
|
37
|
+
await this.serverPrompts.resolvePrompt({
|
|
38
|
+
idx: pickIndex,
|
|
39
|
+
value: pick.details.c[Math.floor(Math.random() * pick.details.c.length)],
|
|
40
|
+
});
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case "DragPick": {
|
|
44
|
+
const target = pick.details.d[Math.floor(Math.random() * pick.details.d.length)];
|
|
45
|
+
await this.serverPrompts.resolvePrompt({
|
|
46
|
+
idx: pickIndex,
|
|
47
|
+
value: {
|
|
48
|
+
chitId: pick.details.c[Math.floor(Math.random() * pick.details.c.length)],
|
|
49
|
+
targetChitId: target[Math.floor(Math.random() * target.length)],
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} else if (prompt.type === "NoValidMovesPrompt") {
|
|
56
|
+
await this.serverPrompts.stepBackPrompt(false);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -153,7 +153,7 @@ export class ClientTime extends ConnectionObject {
|
|
|
153
153
|
|
|
154
154
|
// make sure nothing changed while we were waiting...
|
|
155
155
|
if (this.clientTimeState.targetClock.value === newTargetClock && currentClock === this.currentClock.value) {
|
|
156
|
-
if (newTargetClock
|
|
156
|
+
if (newTargetClock >= this.startTime) {
|
|
157
157
|
this.clientTimeState.isLoading.value = false;
|
|
158
158
|
}
|
|
159
159
|
|