aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/components/GolfPlayApp.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/components/GolfPlayApp.tsx')
-rw-r--r--frontend/app/components/GolfPlayApp.tsx17
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 />;