From 5b00f03476f799e47ef9a910b171c18a25725abe Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Sun, 22 Jan 2023 17:13:48 +0100 Subject: [PATCH] finally usable mobile version --- client/src/lib/game.svelte | 28 +++++++++++++++++----------- client/src/routes/+layout.svelte | 13 ++++++++++++- client/src/routes/+page.svelte | 8 ++++++++ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/client/src/lib/game.svelte b/client/src/lib/game.svelte index 689b02b..9f26773 100644 --- a/client/src/lib/game.svelte +++ b/client/src/lib/game.svelte @@ -191,10 +191,11 @@ return () => clearTimeout(i); }); - let innerWidth = window.innerWidth; + let innerWidth = typeof window !== "undefined" ? window.innerWidth : 0; + let innerHeight = typeof window !== "undefined" ? window.innerHeight : 0; - + hoveredPiece = null} /> @@ -234,8 +235,8 @@ {/if} -
-
+
+
{#each classes as className, i}
cmove.i == i && cmove.j == j)} {@const move = moves[moveIndex]} +
addMove(i, j)} @@ -258,19 +260,21 @@ class:cross={move && move.p==1} class:circle={move && move.p==2} on:mouseover={() => { if(currentContainer == i) hoveredPiece = { i, j } }} - on:focus={() => { if(currentContainer == i) hoveredPiece = { i, j }}} + on:mouseleave={() => { if(hoveredPiece?.i == i && hoveredPiece.j == j) hoveredPiece = null; }} > + + {#if move} {#if move.p == 1} - - + + {:else} - + {/if} {:else} @@ -375,15 +379,15 @@
- {#if movesShown || innerWidth >= 1024} -
movesShown = false} on:keydown={() => movesShown = false} /> + {#if movesShown || innerWidth >= 1024 || innerWidth / innerHeight > 1.4} +
1.4} class="lg:hidden bg-black/40 fixed inset-0 z-10" on:click={() => movesShown = false} on:keydown={() => movesShown = false} />
Moves {#key moves.length} - {moves.length} + {moves.length} {/key}
{#if twoPlayer} @@ -433,6 +437,8 @@ } .board { @apply grid grid-cols-3 grid-rows-3 gap-10 w-max h-max m-auto my-5 flex-shrink-0; + aspect-ratio: 1 / 1; + scale: min(1, var(--vw) / 768, var(--vh) / 856); } .squares-container { @apply grid grid-cols-3 grid-rows-3 gap-5 w-max h-max opacity-35 relative; diff --git a/client/src/routes/+layout.svelte b/client/src/routes/+layout.svelte index 8bbf06c..b6ad3bf 100644 --- a/client/src/routes/+layout.svelte +++ b/client/src/routes/+layout.svelte @@ -13,9 +13,19 @@ document.documentElement.classList.remove("dark"); } } + + var el: HTMLDivElement + function clicked() { + if(innerWidth < 768 || innerHeight < 768) { + el.requestFullscreen({ + navigationUI: "hide" + }); + } + } -
+ +
@@ -27,5 +37,6 @@ } :global(*) { @apply transition-colors; + -webkit-tap-highlight-color: transparent; } \ No newline at end of file diff --git a/client/src/routes/+page.svelte b/client/src/routes/+page.svelte index 1f56606..dc20eac 100644 --- a/client/src/routes/+page.svelte +++ b/client/src/routes/+page.svelte @@ -88,6 +88,14 @@ mask: url('/network.svg') no-repeat center; -webkit-mask: url('/network.svg') no-repeat center; } + @media (max-height: 728px) { + .computer, .multiplayer { + display: none; + } + h1 { + margin: 0; + } + } :global(.dark) .computer, :global(.dark) .multiplayer { @apply bg-white; }