From 18729f90da3d48332ffb1235cf72353f2f36578b Mon Sep 17 00:00:00 2001 From: Jan Klinge Date: Wed, 1 Mar 2023 23:28:08 +0100 Subject: [PATCH] Bugfixes --- server/main.go | 9 +++-- src/components/game/session/SessionLeave.tsx | 5 ++- .../game/session/rows/RowBottom.tsx | 36 ++++++++++++++----- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/server/main.go b/server/main.go index d97e91e..553f17d 100644 --- a/server/main.go +++ b/server/main.go @@ -658,7 +658,7 @@ func main() { for { drawn = append(drawn, resetCard(stack[len(stack)-1])) stack = stack[:len(stack)-2] - if len(stack) > 1 && drawn[len(drawn)-1][1] != stack[0][1] { + if len(stack) <= 1 || drawn[len(drawn)-1][1] == stack[0][1] { break } } @@ -667,7 +667,7 @@ func main() { index := rand.Intn(len(stack) - 2) drawn = append(drawn, resetCard(stack[index])) stack = append(stack[:index], stack[index+1:]...) - if len(stack) <= 1 && drawn[len(drawn)-1][1] != stack[0][1] { + if len(stack) <= 1 || drawn[len(drawn)-1][1] == stack[0][1] { break } } @@ -1056,7 +1056,7 @@ func main() { } // Checking if card is wish or if previous card has matching color - if card[0] != 'w' && card[0] != 'j' && stack[0][0] != card[0] && stack[0][1] != card[1] { + if card[0] != 'w' && card[0] != 'j' && (stack[0][0] != card[0] || stack[0][1] != card[1]) { return apis.NewBadRequestError("Card not matching.", nil) } @@ -1100,6 +1100,9 @@ func main() { if card[0] == 'p' { globals.Stacking = true } + } else { + globals.Live = players[playerIndex].Name + globals.Drawable = false } // Check if player has won diff --git a/src/components/game/session/SessionLeave.tsx b/src/components/game/session/SessionLeave.tsx index 6abc36c..95ccada 100644 --- a/src/components/game/session/SessionLeave.tsx +++ b/src/components/game/session/SessionLeave.tsx @@ -9,6 +9,8 @@ export default function SessionLeave(props: { navigate: NavigateFunction }) {
{ + props.navigate("/"); + const swap = await sessionLeave(); if (swap["code"] !== 200) { showNotification({ @@ -17,10 +19,7 @@ export default function SessionLeave(props: { navigate: NavigateFunction }) { color: "red", icon: , }); - return; } - - props.navigate("/"); }} > diff --git a/src/components/game/session/rows/RowBottom.tsx b/src/components/game/session/rows/RowBottom.tsx index 4e12fa6..1b7ea06 100644 --- a/src/components/game/session/rows/RowBottom.tsx +++ b/src/components/game/session/rows/RowBottom.tsx @@ -1,6 +1,10 @@ import { SessionType } from "../../../../models/Session"; import { CardType, codeToType, typeToCode } from "../../../../models/Card"; -import { API_NOTIFICATION_GAME_TIMEOUT, gamePlay } from "../../../../api/API"; +import { + API_NOTIFICATION_GAME_TIMEOUT, + gamePlay, + gameThrow, +} from "../../../../api/API"; import { showNotification } from "@mantine/notifications"; import { PlayArrow } from "@mui/icons-material"; import CardFront from "../../../card/front/CardFront"; @@ -41,14 +45,28 @@ export default function RowBottom(props: {
{ - const play = await gamePlay(typeToCode(card)); - if (play["code"] !== 200) { - showNotification({ - autoClose: API_NOTIFICATION_GAME_TIMEOUT, - message: play["message"] ?? "An unknown error occurred.", - color: "red", - icon: , - }); + if (!props.session.me.live) { + const smash = await gameThrow(typeToCode(card)); + if (smash["code"] !== 200) { + showNotification({ + autoClose: API_NOTIFICATION_GAME_TIMEOUT, + message: + smash["message"] ?? "An unknown error occurred.", + color: "red", + icon: , + }); + } + } else { + const play = await gamePlay(typeToCode(card)); + if (play["code"] !== 200) { + showNotification({ + autoClose: API_NOTIFICATION_GAME_TIMEOUT, + message: + play["message"] ?? "An unknown error occurred.", + color: "red", + icon: , + }); + } } }} >