Game page CSS adjustements and hidden header.

This commit is contained in:
LuckyLaszlo
2023-01-17 14:31:20 +01:00
parent d8317350b0
commit 44f9f8e21b
4 changed files with 88 additions and 52 deletions

View File

@@ -4,18 +4,17 @@
import { location } from 'svelte-spa-router'; import { location } from 'svelte-spa-router';
import Chat from './pieces/chat/Chat.svelte'; import Chat from './pieces/chat/Chat.svelte';
import Header from './pieces/Header.svelte'; import Header from './pieces/Header.svelte';
import { showHeader } from './pieces/store_showHeader';
const conditionsFailed = (event) => { const conditionsFailed = (event) => {
console.error('conditionsFailed event', event.detail); console.error('conditionsFailed event', event.detail);
// i mean i guess i can just leave this in there permanently?
// replace('/unauthorized-access'); // replace('/unauthorized-access');
replace('/'); replace('/');
}; };
</script> </script>
{#if ($location !== '/')} {#if ($location !== '/' && $showHeader)}
<Header/> <Header/>
{/if} {/if}

View File

@@ -9,6 +9,7 @@
import { gameState } from "./client/ws"; import { gameState } from "./client/ws";
import { invited_username } from '../../pieces/store_invitation'; import { invited_username } from '../../pieces/store_invitation';
import { showHeader } from '../../pieces/store_showHeader';
//user's stuff //user's stuff
let user; let user;
@@ -61,6 +62,7 @@
clearTimeout(value); clearTimeout(value);
}); });
pong.destroy(); pong.destroy();
setHiddenGame(true);
}) })
function resetPage() { function resetPage() {
@@ -73,6 +75,12 @@
pong.destroy(); pong.destroy();
}; };
function leaveMatch() {
clearInterval(watchMatchStartInterval);
clearInterval(watchGameStateInterval);
resetPage();
};
const initGame = async() => const initGame = async() =>
{ {
showWaitPage = true; showWaitPage = true;
@@ -239,20 +247,18 @@
}); });
} }
function leaveMatch() {
clearInterval(watchMatchStartInterval);
clearInterval(watchGameStateInterval);
resetPage();
};
let game_page_class = ""; let game_page_class = "";
function setHiddenGame(value: boolean) function setHiddenGame(value: boolean)
{ {
if (value) { if (value === true) {
game_page_class = ""; game_page_class = "";
window.document.body.classList.remove('dim_background');
showHeader.set(true);
} }
else { else {
game_page_class = "dim_background"; game_page_class = "dim_background";
window.document.body.classList.add('dim_background');
showHeader.set(false);
} }
hiddenGame = value; hiddenGame = value;
} }
@@ -323,7 +329,7 @@
{#if hiddenGame} {#if hiddenGame}
{#if showGameOptions} {#if showGameOptions}
<div class="div_game" id="game_options"> <div class="div_game" id="game_options">
<button class="pong_button" on:click={fetchInvitations}>Show invitations</button> <button class="pong_button game_options_button" on:click={fetchInvitations}>Show invitations</button>
<fieldset in:fly="{{ y: 10, duration: 1000 }}"> <fieldset in:fly="{{ y: 10, duration: 1000 }}">
<legend>game options</legend> <legend>game options</legend>
@@ -370,7 +376,7 @@
{#if showInvitations} {#if showInvitations}
<div class="div_game" id="game_invitations"> <div class="div_game" id="game_invitations">
<button class="pong_button" on:click={switchToGameOptions}>Play a Game</button> <button class="pong_button game_options_button" on:click={switchToGameOptions}>Play a Game</button>
<fieldset in:fly="{{ y: 10, duration: 1000 }}"> <fieldset in:fly="{{ y: 10, duration: 1000 }}">
<legend>invitations</legend> <legend>invitations</legend>
<button class="pong_button" on:click={fetchInvitations}>Reload</button> <button class="pong_button" on:click={fetchInvitations}>Reload</button>
@@ -408,6 +414,10 @@
background-color: #222; background-color: #222;
} }
:global(body.dim_background) {
background-color: #222;
}
#game_page { #game_page {
margin: 0; margin: 0;
position: relative; position: relative;
@@ -418,8 +428,9 @@
flex-grow: 1; flex-grow: 1;
} }
#game_options, #game_invitations { .game_options_button {
margin-top: 20px; margin-top: 15px;
margin-bottom: 15px;
} }
#canvas_container { #canvas_container {
@@ -430,11 +441,9 @@
/* overflow: hidden; */ /* overflow: hidden; */
} }
canvas { canvas {
/* background-color: #ff0000; */
background-color: #333;
max-width: 75vw;
font-family: "Bit5x3"; font-family: "Bit5x3";
/* max-height: 100vh; */ background-color: #333;
max-width: 65vw;
width: 80%; width: 80%;
} }
@@ -460,10 +469,10 @@ canvas {
padding: 10px; padding: 10px;
} }
.avatar { .avatar {
min-height: 100px; min-height: 5vw;
min-width: 100px; min-width: 5vw;
max-width: 100px; max-width: 5vw;
max-height: 100px; max-height: 5vw;
} }
</style> </style>

View File

@@ -10,6 +10,8 @@
import * as pongSpectator from "./client/pongSpectator"; import * as pongSpectator from "./client/pongSpectator";
import { gameState } from "./client/ws"; import { gameState } from "./client/ws";
import { showHeader } from '../../pieces/store_showHeader';
let playerOneAvatar = ""; let playerOneAvatar = "";
let playerTwoAvatar = ""; let playerTwoAvatar = "";
@@ -26,7 +28,7 @@
let timeoutArr = []; let timeoutArr = [];
onMount( async() => { onMount( async() => {
matchList = await fetchMatchList(); await fetchMatchList();
}) })
onDestroy( async() => { onDestroy( async() => {
@@ -35,8 +37,20 @@
clearTimeout(value); clearTimeout(value);
}); });
pongSpectator.destroy(); pongSpectator.destroy();
setHiddenGame(true);
}) })
async function resetPage() {
setHiddenGame(true);
pongSpectator.destroy();
await fetchMatchList();
};
function leaveMatch() {
clearInterval(watchGameStateInterval);
resetPage();
};
async function initGameSpectator(match: Match) async function initGameSpectator(match: Match)
{ {
watchGameStateInterval = setInterval(watchGameState, watchGameStateIntervalRate); watchGameStateInterval = setInterval(watchGameState, watchGameStateIntervalRate);
@@ -68,20 +82,9 @@
} }
} }
function leaveMatch() {
clearInterval(watchGameStateInterval);
resetPage();
};
async function resetPage() {
setHiddenGame(true);
pongSpectator.destroy();
matchList = await fetchMatchList();
};
async function fetchMatchList() async function fetchMatchList()
{ {
return fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/match/all`) matchList = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/match/all`)
.then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {
throw new Error("All matchs not retrieved"); throw new Error("All matchs not retrieved");
@@ -100,11 +103,15 @@
let game_page_class = ""; let game_page_class = "";
function setHiddenGame(value: boolean) function setHiddenGame(value: boolean)
{ {
if (value) { if (value === true) {
game_page_class = ""; game_page_class = "";
window.document.body.classList.remove('dim_background');
showHeader.set(true);
} }
else { else {
game_page_class = "dim_background"; game_page_class = "dim_background";
window.document.body.classList.add('dim_background');
showHeader.set(false);
} }
hiddenGame = value; hiddenGame = value;
} }
@@ -145,7 +152,7 @@
<!-- --> <!-- -->
{#if hiddenGame} {#if hiddenGame}
<div class="div_game" in:fly="{{ y: 10, duration: 1000 }}"> <div class="div_game game_options" in:fly="{{ y: 10, duration: 1000 }}">
<fieldset> <fieldset>
<legend>options</legend> <legend>options</legend>
<button class="pong_button" on:click={fetchMatchList}>Reload</button> <button class="pong_button" on:click={fetchMatchList}>Reload</button>
@@ -194,14 +201,34 @@
background-color: #222; background-color: #222;
} }
#game_page { :global(body.dim_background) {
background-color: #222;
}
/* Possible rollback, demander à Hugo */
/* #game_page {
margin: 0; margin: 0;
padding: 20px; padding: 20px;
position: relative; position: relative;
width: 100%; width: 100%;
height: 100%; height: 100%;
box-sizing: border-box; box-sizing: border-box;
} */
#game_page {
margin: 0;
position: relative;
width: 100%;
height: auto;
display: flex;
flex-direction: column;
flex-grow: 1;
} }
.game_options {
margin-top: 15px;
margin-bottom: 15px;
}
#canvas_container { #canvas_container {
margin-top: 20px; margin-top: 20px;
text-align: center; text-align: center;
@@ -210,14 +237,11 @@
/* overflow: hidden; */ /* overflow: hidden; */
} }
canvas { canvas {
/* background-color: #ff0000; */
background-color: #333333;
max-width: 75vw;
font-family: "Bit5x3"; font-family: "Bit5x3";
/* max-height: 100vh; */ background-color: #333;
max-width: 65vw;
width: 80%; width: 80%;
} }
.div_game { .div_game {
text-align: center; text-align: center;
font-family: "PressStart2P"; font-family: "PressStart2P";
@@ -244,10 +268,10 @@ canvas {
font-size: 1vw; font-size: 1vw;
} }
.avatar { .avatar {
min-height: 100px; min-height: 5vw;
min-width: 100px; min-width: 5vw;
max-width: 100px; max-width: 5vw;
max-height: 100px; max-height: 5vw;
} }
</style> </style>

View File

@@ -0,0 +1,4 @@
import { writable } from 'svelte/store';
export const showHeader = writable(true);