Skip to content

Commit

Permalink
room code in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSammyM committed Jan 7, 2024
1 parent 12f8dc1 commit c72f29b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 27 deletions.
9 changes: 9 additions & 0 deletions client/src/game/gameManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@ export function createGameManager(): GameManager {
Anchor.playAudioFile("/audio/01. Calm Before The Storm.mp3");
},
setGameState() {
let roomCode = null;
if(GAME_MANAGER.state.stateType === "lobby"){
roomCode = GAME_MANAGER.state.roomCode;
}


Anchor.stopAudio();
GAME_MANAGER.state = createGameState();
Anchor.setContent(GameScreen.createDefault());
if(roomCode !== null){
GAME_MANAGER.state.roomCode = roomCode;
}
},
async setOutsideLobbyState() {
Anchor.stopAudio();
Expand Down
43 changes: 32 additions & 11 deletions client/src/menu/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,41 @@ export default class Settings extends React.Component<SettingsProps, SettingsSta
<h1>{translate("menu.settings.title")}</h1>
</div>
<div className="settingsContent">
<div className="settingsSection">
<h2>{translate("menu.settings.volume")}</h2>
<input type="range" min="0" max="1" step="0.01"
value={this.props.volume}
onChange={(e) => {
console.log("Volume changed to " + e.target.value);
let volume = parseFloat(e.target.value);
this.props.onVolumeChange(volume);
}
}/>
</div>
<h2>{translate("menu.settings.volume")}</h2>
<input type="range" min="0" max="1" step="0.01"
value={this.props.volume}
onChange={(e) => {
console.log("Volume changed to " + e.target.value);
let volume = parseFloat(e.target.value);
this.props.onVolumeChange(volume);
}
}/>
{
GAME_MANAGER.state.stateType === "lobby" || GAME_MANAGER.state.stateType === "game" ?
(<>
<h2>{translate("menu.play.field.roomCode")}</h2>
<RoomCodeButton/>
</>) : null
}
</div>
</div>
);
}
}

export function RoomCodeButton(props: {}): JSX.Element {
return <button onClick={() => {
let code = new URL(window.location.href);

if (GAME_MANAGER.state.stateType === "lobby" || GAME_MANAGER.state.stateType === "game")
code.searchParams.set("code", GAME_MANAGER.state.roomCode!);

if (navigator.clipboard)
navigator.clipboard.writeText(code.toString());
}}>
{
GAME_MANAGER.state.stateType === "lobby" || GAME_MANAGER.state.stateType === "game" ?
GAME_MANAGER.state.roomCode : ""
}
</button>
}
17 changes: 1 addition & 16 deletions client/src/menu/lobby/LobbyMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { StateListener } from "../../game/gameManager.d";
import LobbyExcludedRoles from "./lobbyExcludedRoles";
import Anchor from "../Anchor";
import WikiSearch from "../../components/WikiSearch";
import { RoomCodeButton } from "../Settings";

type LobbyMenuProps = {}

Expand Down Expand Up @@ -91,19 +92,3 @@ function LobbyMenuHeader(props: { host?: boolean }): JSX.Element {
</header>
}

function RoomCodeButton(props: {}): JSX.Element {
return <button onClick={() => {
let code = new URL(window.location.href);

if (GAME_MANAGER.state.stateType === "lobby")
code.searchParams.set("code", GAME_MANAGER.state.roomCode!);

if (navigator.clipboard)
navigator.clipboard.writeText(code.toString());
}}>
{
GAME_MANAGER.state.stateType === "lobby" ?
GAME_MANAGER.state.roomCode : ""
}
</button>
}

1 comment on commit c72f29b

@vercel
Copy link

@vercel vercel bot commented on c72f29b Jan 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

mafia-game – ./

mafia-game-itssammym.vercel.app
mafia-game-git-00x-main-itssammym.vercel.app
mafia-game.vercel.app

Please sign in to comment.