diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-29 02:58:54 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-29 02:58:57 +0900 |
| commit | 161d82bee9f9e65680516a9cfd392e0cf297eadf (patch) | |
| tree | 2f248715213d12d6649f32b5ddcbb0d9a0281ed8 /frontend | |
| parent | 4c7238f58dcc463d22d50bfc6cd2aaae70e41958 (diff) | |
| download | iosdc-japan-2024-albatross-161d82bee9f9e65680516a9cfd392e0cf297eadf.tar.gz iosdc-japan-2024-albatross-161d82bee9f9e65680516a9cfd392e0cf297eadf.tar.zst iosdc-japan-2024-albatross-161d82bee9f9e65680516a9cfd392e0cf297eadf.zip | |
feat: handle code and execresult messages
Diffstat (limited to 'frontend')
| -rw-r--r-- | frontend/app/components/GolfPlayApp.tsx | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/frontend/app/components/GolfPlayApp.tsx b/frontend/app/components/GolfPlayApp.tsx index 31d1c44..c6c20d4 100644 --- a/frontend/app/components/GolfPlayApp.tsx +++ b/frontend/app/components/GolfPlayApp.tsx @@ -69,8 +69,11 @@ export default function GolfPlayApp({ game }: { game: Game }) { void setCurrentScore; const onCodeChange = useDebouncedCallback((code: string) => { - void code; - // sendJsonMessage({}); + console.log("player:c2s:code"); + sendJsonMessage({ + type: "player:c2s:code", + data: { code }, + }); }, 1000); if (readyState === ReadyState.UNINSTANTIATED) { @@ -104,6 +107,14 @@ export default function GolfPlayApp({ game }: { game: Game }) { setTimeLeftSeconds(start_at - nowSec); setGameState("starting"); } + } else if (lastJsonMessage.type === "player:s2c:execresult") { + const { score } = lastJsonMessage.data; + if ( + score !== null && + (currentScore === null || score < currentScore) + ) { + setCurrentScore(score); + } } } else { setGameState("waiting"); @@ -111,7 +122,7 @@ export default function GolfPlayApp({ game }: { game: Game }) { sendJsonMessage({ type: "player:c2s:entry" }); } } - }, [sendJsonMessage, lastJsonMessage, readyState, gameState]); + }, [sendJsonMessage, lastJsonMessage, readyState, gameState, currentScore]); if (gameState === "connecting") { return <GolfPlayAppConnecting />; |
