From 5dc7d80d9aa53d558ea64418bf76a933b30858fd Mon Sep 17 00:00:00 2001 From: jhalitaksoy Date: Sun, 4 Jul 2021 00:45:00 +0300 Subject: [PATCH] now printing game crash message --- src/Home.tsx | 59 +++++++++++++++++++++--------------- src/components/InfoPanel.tsx | 33 ++++++++++++++++++++ src/const/texts.ts | 3 ++ src/rtmt/rtmt_websocket.ts | 4 +-- src/service/http_service.ts | 30 ++++++++++++------ 5 files changed, 93 insertions(+), 36 deletions(-) create mode 100644 src/components/InfoPanel.tsx diff --git a/src/Home.tsx b/src/Home.tsx index 30c180e..c50d840 100644 --- a/src/Home.tsx +++ b/src/Home.tsx @@ -9,6 +9,7 @@ import { Bytes } from './rtmt/rtmt'; import { RTMTWS } from './rtmt/rtmt_websocket'; import { channel_game_move, channel_leave_game, channel_on_game_update } from './channel_names'; import Button from './components/Button'; +import InfoPanel from './components/InfoPanel'; const testBoard = (): Board => { const board = new Board( @@ -29,6 +30,8 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => { const [connectionState, setConnetionState] = useState("connecting") + const [crashMessage, setCrashMessage] = useState(undefined) + const onConnectionDone = () => { setConnetionState("connected") } @@ -75,6 +78,13 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => { console.log(newGame); setGame(new Game(newGame.player1, newGame.player2, newGame.board, newGame.turn, newGame.state)) }) + + context.rtmt.listenMessage("on_game_crashed", (message) => { + const newCrashMessage = decodeText(message) + console.log("on_game_crash"); + console.log(newCrashMessage); + setCrashMessage(newCrashMessage) + }) } React.useEffect(() => { @@ -108,6 +118,19 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => { return map[connectionState] } + const renderNewGameButton = () => { + const newGame =