-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Host Settings Menu #767
base: main
Are you sure you want to change the base?
Host Settings Menu #767
Changes from all commits
4d325be
5af4a01
f03f690
f009fbb
9b7a612
65ee19b
c8f9dcd
879b321
4714877
3a081dc
ad545b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { ANCHOR_CONTROLLER, chatMessageToAudio } from "./../menu/Anchor"; | |
import GAME_MANAGER from "./../index"; | ||
import GameScreen from "./../menu/game/GameScreen"; | ||
import { ToClientPacket } from "./packet"; | ||
import { PlayerIndex, Tag } from "./gameState.d"; | ||
import { GameClient, PlayerIndex, Tag } from "./gameState.d"; | ||
import { Role } from "./roleState.d"; | ||
import translate from "./lang"; | ||
import { computePlayerKeywordData, computePlayerKeywordDataForLobby } from "../components/StyledText"; | ||
|
@@ -23,7 +23,6 @@ import { defaultAlibi } from "../menu/game/gameScreenContent/WillMenu"; | |
import ListMap from "../ListMap"; | ||
import { sortControllerIdCompare } from "./abilityInput"; | ||
|
||
|
||
function sendDefaultName() { | ||
const defaultName = loadSettingsParsed().defaultName; | ||
if(defaultName !== null && defaultName !== undefined && defaultName !== ""){ | ||
|
@@ -32,10 +31,8 @@ function sendDefaultName() { | |
} | ||
|
||
export default function messageListener(packet: ToClientPacket){ | ||
|
||
console.log(JSON.stringify(packet, null, 2)); | ||
|
||
|
||
switch(packet.type) { | ||
case "pong": | ||
if (GAME_MANAGER.state.stateType !== "disconnected") { | ||
|
@@ -149,7 +146,19 @@ export default function messageListener(packet: ToClientPacket){ | |
} | ||
GAME_MANAGER.state.players = new ListMap(GAME_MANAGER.state.players.entries()); | ||
}else if(GAME_MANAGER.state.stateType === "game"){ | ||
GAME_MANAGER.state.host = packet.hosts.includes(GAME_MANAGER.state.myId ?? -1) | ||
if (packet.hosts.includes(GAME_MANAGER.state.myId ?? -1)) { | ||
if (GAME_MANAGER.state.host === null) { | ||
GAME_MANAGER.state.host = { | ||
clients: new ListMap() | ||
} | ||
} | ||
|
||
for (const [id, client] of GAME_MANAGER.state.host.clients.entries()) { | ||
client.host = packet.hosts.includes(id); | ||
} | ||
} else { | ||
GAME_MANAGER.state.host = null | ||
} | ||
} | ||
break; | ||
case "playersReady": | ||
|
@@ -193,11 +202,10 @@ export default function messageListener(packet: ToClientPacket){ | |
break; | ||
case "lobbyClients": | ||
if(GAME_MANAGER.state.stateType === "lobby"){ | ||
|
||
const oldMySpectator = GAME_MANAGER.state.players.get(GAME_MANAGER.state.myId!)?.clientType.type === "spectator"; | ||
|
||
GAME_MANAGER.state.players = new ListMap(); | ||
for(let [clientId, lobbyClient] of packet.clients){ | ||
for(const [clientId, lobbyClient] of packet.clients){ | ||
GAME_MANAGER.state.players.insert(clientId, lobbyClient); | ||
} | ||
const newMySpectator = GAME_MANAGER.state.players.get(GAME_MANAGER.state.myId!)?.clientType.type === "spectator"; | ||
|
@@ -215,6 +223,13 @@ export default function messageListener(packet: ToClientPacket){ | |
); | ||
} | ||
break; | ||
case "hostData": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. crazy |
||
if (GAME_MANAGER.state.stateType === "game") { | ||
GAME_MANAGER.state.host = { | ||
clients: new ListMap<number, GameClient>(packet.clients) | ||
} | ||
} | ||
break; | ||
case "lobbyName": | ||
if(GAME_MANAGER.state.stateType === "lobby" || GAME_MANAGER.state.stateType === "game"){ | ||
GAME_MANAGER.state.lobbyName = packet.name; | ||
|
@@ -322,14 +337,6 @@ export default function messageListener(packet: ToClientPacket){ | |
if(GAME_MANAGER.state.stateType === "game") | ||
GAME_MANAGER.state.timeLeftMs = packet.secondsLeft * 1000; | ||
break; | ||
case "playerOnTrial": | ||
if(GAME_MANAGER.state.stateType === "game" && ( | ||
GAME_MANAGER.state.phaseState.type === "testimony" || | ||
GAME_MANAGER.state.phaseState.type === "judgement" || | ||
GAME_MANAGER.state.phaseState.type === "finalWords" | ||
)) | ||
GAME_MANAGER.state.phaseState.playerOnTrial = packet.playerIndex; | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldnt be in this PR but whateva There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick |
||
case "playerAlive": | ||
if(GAME_MANAGER.state.stateType === "game"){ | ||
for(let i = 0; i < GAME_MANAGER.state.players.length && i < packet.alive.length; i++){ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { PhaseType, PlayerIndex, Verdict, PhaseTimes, Tag, LobbyClientID, ChatGroup, PhaseState, LobbyClient, ModifierType, InsiderGroup } from "./gameState.d" | ||
import { PhaseType, PlayerIndex, Verdict, PhaseTimes, Tag, LobbyClientID, ChatGroup, PhaseState, LobbyClient, ModifierType, InsiderGroup, GameClient } from "./gameState.d" | ||
import { Grave } from "./graveState" | ||
import { ChatMessage } from "../components/ChatMessage" | ||
import { RoleList, RoleOutline } from "./roleListState.d" | ||
|
@@ -16,6 +16,9 @@ export type LobbyPreviewData = { | |
|
||
export type ToClientPacket = { | ||
type: "pong", | ||
} | { | ||
type: "hostData", | ||
clients: ListMapData<LobbyClientID, GameClient> | ||
} | { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wild |
||
type: "rateLimitExceeded", | ||
} | { | ||
|
@@ -102,9 +105,6 @@ export type ToClientPacket = { | |
type: "phaseTimeLeft", | ||
secondsLeft: number | ||
} |{ | ||
type: "playerOnTrial", | ||
playerIndex: PlayerIndex | ||
} | { | ||
type: "playerAlive", | ||
alive: [boolean] | ||
} | { | ||
|
@@ -178,6 +178,8 @@ export type ToServerPacket = { | |
type: "ping", | ||
} | { | ||
type: "lobbyListRequest", | ||
} | { | ||
type: "hostDataRequest", | ||
} | { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i like |
||
type: "reJoin", | ||
roomCode: number, | ||
|
@@ -289,4 +291,12 @@ export type ToServerPacket = { | |
} | { | ||
type: "voteFastForwardPhase", | ||
fastForward: boolean | ||
} | { | ||
type: "endGame", | ||
} | { | ||
type: "skipPhase", | ||
} | { | ||
type: "setPlayerName", | ||
id: number, | ||
name: string | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we name these something more specific? HostForceEndGame |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { ReactElement, useContext, useEffect, useState } from "react"; | ||
import translate from "../game/lang"; | ||
import GAME_MANAGER from ".."; | ||
import { Button } from "../components/Button"; | ||
import { usePacketListener } from "../components/useHooks"; | ||
import { AnchorControllerContext } from "./Anchor"; | ||
import "./lobby/lobbyMenu.css" | ||
import LobbyPlayerList from "./lobby/LobbyPlayerList"; | ||
|
||
export default function HostMenu(): ReactElement { | ||
const anchorController = useContext(AnchorControllerContext)!; | ||
|
||
useEffect(() => { | ||
GAME_MANAGER.sendHostDataRequest(); | ||
}, []) | ||
|
||
const [lastRefreshed, setLastRefreshed] = useState(new Date()); | ||
|
||
usePacketListener(type => { | ||
// Check on every packet since like 1 million packets can affect this | ||
if (!(GAME_MANAGER.state.stateType === "game" && GAME_MANAGER.state.host !== null)) { | ||
anchorController.clearCoverCard(); | ||
} | ||
|
||
if (type === "hostData") { | ||
setLastRefreshed(new Date(Date.now())) | ||
} | ||
}); | ||
|
||
return <div className="settings-menu-card"> | ||
<header> | ||
<h1>{translate("menu.hostSettings.title")}</h1> | ||
{translate("menu.hostSettings.lastRefresh", lastRefreshed.toLocaleTimeString())} | ||
</header> | ||
|
||
<Button onClick={() => GAME_MANAGER.sendHostDataRequest()} | ||
>{translate("refresh")}</Button> | ||
|
||
<main className="settings-menu"> | ||
<LobbyPlayerList /> | ||
<div className="chat-menu-colors"> | ||
<h2>{translate("menu.hostSettings.lobby")}</h2> | ||
<section> | ||
<Button onClick={()=>GAME_MANAGER.sendBackToLobbyPacket()}> | ||
{translate("backToLobby")} | ||
</Button> | ||
<Button onClick={()=>GAME_MANAGER.sendHostEndGamePacket()}> | ||
{translate("menu.hostSettings.endGame")} | ||
</Button> | ||
<Button onClick={()=>GAME_MANAGER.sendHostSkipPhase()}> | ||
{translate("menu.hostSettings.skipPhase")} | ||
</Button> | ||
</section> | ||
</div> | ||
</main> | ||
</div> | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cant call this game client and then have it only exist if you are the host. Right you just like??? I guess the clients dont need it
This code is not self-explanatory