Skip to content

Commit

Permalink
will page loads default properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSammyM committed Feb 3, 2024
1 parent f3e9cac commit a555593
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 117 deletions.
2 changes: 1 addition & 1 deletion client/src/game/messageListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export default function messageListener(packet: ToClientPacket){
break;
case "yourNotes":
if(GAME_MANAGER.state.stateType === "game")
GAME_MANAGER.state.notes = packet.notes;
GAME_MANAGER.state.notes = packet.notes;
break;
case "yourDeathNote":
if(GAME_MANAGER.state.stateType === "game")
Expand Down
16 changes: 7 additions & 9 deletions client/src/menu/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import React from 'react';
import "./settings.css";
import translate from '../game/lang';
import GAME_MANAGER from '..';
import WikiSearch from '../components/WikiSearch';
import Anchor from './Anchor';
import { getRolesComplement, getRolesFromRoleListRemoveExclusionsAddConversions } from '../game/roleListState.d';
import StartMenu from './main/StartMenu';

type SettingsProps = {
volume: number, // 0-1
Expand Down Expand Up @@ -33,6 +32,11 @@ export default class Settings extends React.Component<SettingsProps, SettingsSta
GAME_MANAGER.saveSettings(volume);
console.log("Loaded settings: " + JSON.stringify(volume));
}
quitToMainMenu() {
GAME_MANAGER.leaveGame();
Anchor.closeSettings();
Anchor.setContent(<StartMenu/>);
}
render(): React.ReactNode {
return (
<div className="settings slide-in">
Expand All @@ -51,6 +55,7 @@ export default class Settings extends React.Component<SettingsProps, SettingsSta
</>
) : null
}
<button onClick={(e)=>{this.quitToMainMenu()}}>{translate("menu.settings.quitToMenu")}</button>
<h2>{translate("menu.settings.volume")}
<input className="settings-volume" type="range" min="0" max="1" step="0.01"
value={this.props.volume}
Expand All @@ -59,13 +64,6 @@ export default class Settings extends React.Component<SettingsProps, SettingsSta
this.props.onVolumeChange(volume);
}
}/></h2>
<section className="settings-wiki-menu wiki-menu-colors">
<h2>{translate("menu.wiki.title")}</h2>
<WikiSearch excludedRoles={
GAME_MANAGER.state.stateType === "lobby" || GAME_MANAGER.state.stateType === "game" ?
getRolesComplement(getRolesFromRoleListRemoveExclusionsAddConversions(GAME_MANAGER.state.roleList, GAME_MANAGER.state.excludedRoles)) : []
}/>
</section>
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion client/src/menu/game/HeaderMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default class HeaderMenu extends React.Component<HeaderMenuProps, HeaderM
};

return(<div className="header-menu">
{this.renderPhase()}
<h3>{this.renderPhase()}</h3>
{(()=>{
return <StyledText>
{(this.state.gameState.players[this.state.gameState.myIndex!] ?? "").toString() +
Expand Down
182 changes: 98 additions & 84 deletions client/src/menu/game/gameScreenContent/WillMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,60 @@ import { StateListener } from "../../../game/gameManager.d";


type FieldType = "will" | "notes" | "deathNote";
type Fields = { [key in FieldType]: string };

type WillMenuState = {
syncedFields : Fields
localFields: Fields
will: string,
notes: string,
deathNote: string,
}

export default class WillMenu extends React.Component<{}, WillMenuState> {
listener: StateListener
constructor(props: {}) {
super(props);



if(GAME_MANAGER.state.stateType === "game"){
let gameStateFields = {
will: GAME_MANAGER.state.will,
notes: GAME_MANAGER.state.notes,
deathNote: GAME_MANAGER.state.deathNote,
};
let localFields = {
will: GAME_MANAGER.state.will === "" ? "ROLE\nN1: \nN2: " : GAME_MANAGER.state.will,
notes: GAME_MANAGER.state.notes,
deathNote: GAME_MANAGER.state.deathNote,
};


let will = GAME_MANAGER.state.will;
let notes = GAME_MANAGER.state.notes;

if(will === ""){
console.log("Will is empty");
will = "ROLE\nNight 1: \nNight 2:";
}
if(notes === ""){
console.log("Notes is empty");
notes = GAME_MANAGER.state.players.map((player) => {
return player.toString();
}).join(" - \n") + " - \n";
}

this.state = {
syncedFields: gameStateFields,
localFields: localFields
will,
notes,
deathNote: GAME_MANAGER.state.deathNote,
};
}

this.listener = (type) => {
if(GAME_MANAGER.state.stateType === "game"){
if (type === "yourWill") {
this.setState({
syncedFields: {
will: GAME_MANAGER.state.will,
notes: this.state.syncedFields.notes,
deathNote: this.state.syncedFields.deathNote,
},
localFields: {
switch(type){
case "yourWill":
this.setState({
will: GAME_MANAGER.state.will,
notes: this.state.localFields.notes,
deathNote: this.state.localFields.deathNote,
}
});
}
else if(type === "yourNotes"){
this.setState({
syncedFields: {
will: this.state.syncedFields.will,
});
break;
case "yourNotes":
this.setState({
notes: GAME_MANAGER.state.notes,
deathNote: this.state.syncedFields.deathNote,
},
localFields: {
will: this.state.localFields.will,
notes: GAME_MANAGER.state.notes,
deathNote: this.state.localFields.deathNote,
}
});
}
else if(type === "yourDeathNote"){
this.setState({
syncedFields: {
will: this.state.syncedFields.will,
notes: this.state.syncedFields.notes,
deathNote: GAME_MANAGER.state.deathNote,
},
localFields: {
will: this.state.localFields.will,
notes: this.state.localFields.notes,
});
break;
case "yourDeathNote":
this.setState({
deathNote: GAME_MANAGER.state.deathNote,
}
});
});
break;
}
}

Expand All @@ -92,39 +72,50 @@ export default class WillMenu extends React.Component<{}, WillMenuState> {
componentWillUnmount() {
GAME_MANAGER.removeStateListener(this.listener);
}
send(type: FieldType) {
send(type: FieldType){
this.save(type);
if (GAME_MANAGER.state.stateType === "game")
GAME_MANAGER.sendSendMessagePacket('\n' + this.state.localFields[type]);
if (GAME_MANAGER.state.stateType === "game"){
switch(type){
case "will":
GAME_MANAGER.sendSendMessagePacket('\n' + this.state.will);
break;
case "notes":
GAME_MANAGER.sendSendMessagePacket('\n' + this.state.notes);
break;
case "deathNote":
GAME_MANAGER.sendSendMessagePacket('\n' + this.state.deathNote);
break;
}
}
}
save(type: FieldType) {
if (type === "will")
GAME_MANAGER.sendSaveWillPacket(this.state.localFields[type])
else if (type === "notes")
GAME_MANAGER.sendSaveNotesPacket(this.state.localFields[type])
else if (type === "deathNote")
GAME_MANAGER.sendSaveDeathNotePacket(this.state.localFields[type])
switch(type){
case "will":
GAME_MANAGER.sendSaveWillPacket(this.state.will);
break;
case "notes":
GAME_MANAGER.sendSaveNotesPacket(this.state.notes);
break;
case "deathNote":
GAME_MANAGER.sendSaveDeathNotePacket(this.state.deathNote);
break;
}
}
renderInput(type: FieldType) {
return (<details open={type === "will"}>
<summary onClick={() => {
if(type === "notes" && this.state.localFields.notes === "" && GAME_MANAGER.state.stateType === "game"){
let notes = GAME_MANAGER.state.players.map((player) => {
return player.toString();
}).join(" - \n") + " - \n";
this.setState({
localFields: {
will: this.state.localFields.will,
notes: notes,
deathNote: this.state.localFields.deathNote,
}
});
}
}}>
return (<details open={type !== "deathNote"}>
<summary>
{translate("menu.will." + type)}
<div>
<button
className={"material-icons-round " + (this.state.syncedFields[type] !== this.state.localFields[type] ? "highlighted" : "")}
className={"material-icons-round " + (
GAME_MANAGER.state.stateType === "game" &&
(
(type === "will" && GAME_MANAGER.state.will !== this.state.will) ||
(type === "notes" && GAME_MANAGER.state.notes !== this.state.notes) ||
(type === "deathNote" && GAME_MANAGER.state.deathNote !== this.state.deathNote)
)
? "highlighted" : ""
)}
onClick={() => this.save(type)}
aria-label={translate("menu.will.save")}
>
Expand All @@ -142,11 +133,34 @@ export default class WillMenu extends React.Component<{}, WillMenuState> {

<div>
<textarea
value={this.state.localFields[type]}
value={(()=>{
switch(type){
case "will":
return this.state.will;
case "notes":
return this.state.notes;
case "deathNote":
return this.state.deathNote;
}
})()}
onChange={(e) => {
let fields = {...this.state.localFields};
fields[type] = e.target.value;
this.setState({ localFields: fields });
switch(type){
case "will":
this.setState({
will: e.target.value
});
break;
case "notes":
this.setState({
notes: e.target.value
});
break;
case "deathNote":
this.setState({
deathNote: e.target.value
});
break;
}
}}
onKeyDown={(e) => {
if (e.ctrlKey) {
Expand Down
4 changes: 2 additions & 2 deletions client/src/menu/lobby/lobbyExcludedRoles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ export default class LobbyExcludedRoles extends React.Component<{}, ExcludedRole
>{translate("menu.excludedRoles.includeAll")}</button>
<div className="exclusion-preset">
<button
onClick={(e)=>this.handleExcludedRolePreset()}
onClick={(e)=>{this.handleExcludedRolePreset()}}
disabled={!this.state.host}
>{translate("menu.excludedRoles.exclude")}</button>
<select
onChange={(e)=>this.setState({selectedExcludedRolePreset: e.target.options[e.target.selectedIndex].value})}
onChange={(e)=>{this.setState({selectedExcludedRolePreset: e.target.options[e.target.selectedIndex].value})}}
disabled={!this.state.host}
>
{
Expand Down
4 changes: 1 addition & 3 deletions client/src/menu/main/StandaloneWiki.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export default function StandaloneWiki(props: { page?: WikiPage }): ReactElement
<h2>{translate("menu.wiki.title")}</h2>
</header>

<WikiSearch page={props.page} pageChangeCallback={(page) => {
window.history.replaceState(null, document.title, `/wiki/${page}`)
}}/>
<WikiSearch page={props.page}/>
</div>
</div>
}
2 changes: 2 additions & 0 deletions client/src/menu/main/StartMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import translate from "../../game/lang";
import Anchor from "../Anchor";
// import * as LoadingScreen from "../LoadingScreen";
import LoadingScreen from "../LoadingScreen";
import StandaloneWiki from "./StandaloneWiki";

type StartMenuProps = {
}
Expand Down Expand Up @@ -43,6 +44,7 @@ export default class StartMenu extends React.Component<StartMenuProps, StartMenu
<li><a href="https://www.github.com/ItsSammyM/mafia-rust">Github</a></li>
<li><a href="https://mafia-game-old.vercel.app/">Old Mafia</a></li>
<li><a href="https://netgames.io/games/">Net Games</a></li>
<li onClick={()=>{Anchor.setContent(<StandaloneWiki/>)}}>{translate("menu.wiki.title")}</li>
</ul>
</nav>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion client/src/menu/main/standaloneWiki.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
align-items: center;
flex-direction: column;
height: 100%;
width: 60%;
width: 100%;
padding: 0 2rem;
border-top: none;
border-bottom: none;
Expand Down
12 changes: 0 additions & 12 deletions client/src/menu/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@
border: 0;
padding: 0;
}
.settings .settings-wiki-menu {
max-width: 50vh;
max-height: 60vh;
overflow-y: scroll;
background-color: var(--background-color);
border: solid .13rem var(--primary-border-color);
border-bottom-color: black;
border-right-color: black;
border-radius: 1rem;
padding: 1rem;
margin-top: 1rem;
}

@keyframes slide-in {
100% { transform: translateX(0%); }
Expand Down
4 changes: 2 additions & 2 deletions client/src/resources/excludedRolePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
],
"classic": [
"tracker","seer","psychic",
"crusader","reveler",
"crusader","reveler","trapper",
"deputy",
"mafioso","necromancer",
"politician",
"doomsayer","death"
],
"smallGame": [
"spy","psychic",
"bodyguard",
"bodyguard","reveler","trapper",
"retributionist",
"mafioso",
"necromancer",
Expand Down
1 change: 1 addition & 0 deletions client/src/resources/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

"menu.settings.volume": "Volume",
"menu.settings.exit": "Exit Game",
"menu.settings.quitToMenu": "Quit to menu",

"menu.excludedRoles.exclude": "Exclude",
"menu.excludedRoles.includeAll": "Include All",
Expand Down
Loading

0 comments on commit a555593

Please sign in to comment.