fix small issues. add end game screen
This commit is contained in:
parent
c826f04a13
commit
e18fad25a8
|
|
@ -33,3 +33,11 @@
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: min-content;
|
height: min-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.game-over-buttons {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
@ -9,11 +9,11 @@ import useWebSocket, {ReadyState} from "react-use-websocket";
|
||||||
import {BSON} from "bson";
|
import {BSON} from "bson";
|
||||||
import {GameContext} from "../GameContext.ts";
|
import {GameContext} from "../GameContext.ts";
|
||||||
|
|
||||||
type ActionState = "connecting" | "waiting-for-players" | "playing-card" | "disconnected" | "default" | "picking-card"
|
type ActionState = "connecting" | "waiting-for-players" | "playing-card" | "disconnected" | "default" | "picking-card" | "game-over"
|
||||||
|
|
||||||
const randomWaitingPrompts = [
|
const randomWaitingPrompts = [
|
||||||
"Hope your card gets picked <3",
|
"Hope your card gets picked <3",
|
||||||
"Damn. Awful card bro.",
|
"Dang. Awful card bro.",
|
||||||
"Let's see how long he takes",
|
"Let's see how long he takes",
|
||||||
"Crazy pick. Good stuff bro",
|
"Crazy pick. Good stuff bro",
|
||||||
"Erm..."
|
"Erm..."
|
||||||
|
|
@ -33,7 +33,7 @@ export function ActionScreen () {
|
||||||
|
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
const { sendMessage, lastMessage, readyState } = useWebSocket(`wss://inhumane.tv.neothedeveloper.com/live/join-game/${gameContext.channel.current}`, {
|
const { sendMessage, lastMessage, readyState } = useWebSocket(`ws://localhost:8080/live/join-game/${gameContext.channel.current}`, {
|
||||||
reconnectAttempts: 5,
|
reconnectAttempts: 5,
|
||||||
retryOnError: true,
|
retryOnError: true,
|
||||||
reconnectInterval: (lastAttemptNumber) => lastAttemptNumber * 6000
|
reconnectInterval: (lastAttemptNumber) => lastAttemptNumber * 6000
|
||||||
|
|
@ -42,8 +42,14 @@ export function ActionScreen () {
|
||||||
async function handleMessage(msg: MessageEvent | null) {
|
async function handleMessage(msg: MessageEvent | null) {
|
||||||
if (msg) {
|
if (msg) {
|
||||||
const data = await (msg.data as Blob).arrayBuffer();
|
const data = await (msg.data as Blob).arrayBuffer();
|
||||||
console.log(`Last Message Received:`, BSON.deserialize(new Uint8Array(data)));
|
const message = BSON.deserialize(new Uint8Array(data))
|
||||||
handlePacket(BSON.deserialize(new Uint8Array(data)), sendMessage)
|
console.log(`Last Message Received:`, message);
|
||||||
|
|
||||||
|
if (message.op != "ping") {
|
||||||
|
setUpdateScreen(v => ++v)
|
||||||
|
}
|
||||||
|
|
||||||
|
handlePacket(message, sendMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,7 +81,7 @@ export function ActionScreen () {
|
||||||
gameContext.me.current!.availableCards = data.cards
|
gameContext.me.current!.availableCards = data.cards
|
||||||
})
|
})
|
||||||
|
|
||||||
handlers.set("game.setScreen", (data: {screen: string, cards?: {[key: string]: string}}) => {
|
handlers.set("game.setScreen", (data: {screen: string, control?: boolean, cards?: {[key: string]: string}}) => {
|
||||||
if (data.screen == "waiting-for-cards") {
|
if (data.screen == "waiting-for-cards") {
|
||||||
setActionState("default")
|
setActionState("default")
|
||||||
setInstruction("Waiting for player responses")
|
setInstruction("Waiting for player responses")
|
||||||
|
|
@ -97,6 +103,10 @@ export function ActionScreen () {
|
||||||
if (data.screen == "reveal-winner") {
|
if (data.screen == "reveal-winner") {
|
||||||
setActionState("default")
|
setActionState("default")
|
||||||
setInstruction("Look at the hosts screen to see who got picked!")
|
setInstruction("Look at the hosts screen to see who got picked!")
|
||||||
|
if (data.control == true) {
|
||||||
|
setActionState("game-over")
|
||||||
|
setInstruction("Game over!")
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,8 +149,7 @@ export function ActionScreen () {
|
||||||
}, [readyState, sendMessage]);
|
}, [readyState, sendMessage]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleMessage(lastMessage)
|
handleMessage(lastMessage).then()
|
||||||
setUpdateScreen(v => ++v)
|
|
||||||
}, [lastMessage]);
|
}, [lastMessage]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -149,6 +158,10 @@ export function ActionScreen () {
|
||||||
}
|
}
|
||||||
}, [readyState])
|
}, [readyState])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
gameContext.isVip.current = false
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={updateScreen} className={s["game-container"]}>
|
<div key={updateScreen} className={s["game-container"]}>
|
||||||
{actionState === "connecting" && (
|
{actionState === "connecting" && (
|
||||||
|
|
@ -162,6 +175,24 @@ export function ActionScreen () {
|
||||||
<div className={s["instruction"]}>
|
<div className={s["instruction"]}>
|
||||||
{instruction}
|
{instruction}
|
||||||
</div>
|
</div>
|
||||||
|
{actionState == "game-over" && gameContext.isVip.current && (
|
||||||
|
<div className={s["game-over-buttons"]}>
|
||||||
|
<button onClick={() => {
|
||||||
|
sendMessage(ser(createPacket("vip.endAction", {
|
||||||
|
action: 1
|
||||||
|
})))
|
||||||
|
}}>
|
||||||
|
Same Players
|
||||||
|
</button>
|
||||||
|
<button onClick={() => {
|
||||||
|
sendMessage(ser(createPacket("vip.endAction", {
|
||||||
|
action: 2
|
||||||
|
})))
|
||||||
|
}}>
|
||||||
|
New Players
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{actionState == "playing-card" && (
|
{actionState == "playing-card" && (
|
||||||
<div className={s["cards-list"]}>
|
<div className={s["cards-list"]}>
|
||||||
{gameContext.me.current?.availableCards.map((card) => (
|
{gameContext.me.current?.availableCards.map((card) => (
|
||||||
|
|
@ -193,7 +224,7 @@ export function ActionScreen () {
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{(actionState == "waiting-for-players" && gameContext.isVip.current) && (
|
{(actionState == "waiting-for-players" && gameContext.isVip.current == true) && (
|
||||||
<button disabled={players.length < 3} onClick={() => {
|
<button disabled={players.length < 3} onClick={() => {
|
||||||
sendMessage(ser(createPacket("vip.startGame", {})))
|
sendMessage(ser(createPacket("vip.startGame", {})))
|
||||||
}}>
|
}}>
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ export function JoinGame() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(`https://inhumane.tv.neothedeveloper.com/api/v1/play/${code.toLowerCase()}`)
|
const res = await fetch(`http://localhost:8080/api/v1/play/${code.toLowerCase()}`)
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
setErrorMessage((await res.json()).message)
|
setErrorMessage((await res.json()).message)
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user