From 30337d9abc352b9c2e23df38934c763eacfa6201 Mon Sep 17 00:00:00 2001 From: Laurent <58115082+naaturel@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:52:52 +0100 Subject: [PATCH] Add tooltip error allegedly stolen codepen.io --- front/src/lib/models/game.ts | 17 +-- front/src/routes/play/+page.svelte | 170 +++++++++++++++++++++++++++-- 2 files changed, 164 insertions(+), 23 deletions(-) diff --git a/front/src/lib/models/game.ts b/front/src/lib/models/game.ts index 48f9cc0..8dedf7c 100644 --- a/front/src/lib/models/game.ts +++ b/front/src/lib/models/game.ts @@ -1,30 +1,23 @@ -import {scoreStore} from "../stores/scoreStore"; - export class Game { - public name : string; + public playerName : string; public result : number; public state : GameState; private readonly range : number; constructor() { - this.name = ""; + this.playerName = ""; this.result = -1; this.state = GameState.Unplayed; this.range = 100 } - public async play() { + public play() { this.result = this.getRandomNumber(); - await scoreStore.add(this.name, this.result) } - public hasBeenPlayed() : boolean { - return this.state == GameState.Played; - } - - public isRunning() : boolean { - return this.state == GameState.Running; + public playerExists() : boolean{ + return false; } private getRandomNumber() : number{ diff --git a/front/src/routes/play/+page.svelte b/front/src/routes/play/+page.svelte index 183e375..97a105f 100644 --- a/front/src/routes/play/+page.svelte +++ b/front/src/routes/play/+page.svelte @@ -1,18 +1,56 @@ @@ -27,15 +65,23 @@
Massacre en cours...
{/if} - {#if !isRunning && !hasBeenPlayed} -

Evaluez vos chances de survie

-
- - Bomb +

Evaluez vos chances de survie

+
+ debounce(value)} + on:blur={({ target: { value } }) => debounce(value)} + />
+ + Bomb + {/if} {#if hasBeenPlayed} @@ -80,7 +126,7 @@ text-align: left; - margin: 1.5vh; + margin: 0 1.5vh 1.5vh 1.5vh; padding-left: 30px; padding-right: 30px; @@ -113,4 +159,106 @@ to{transform: rotate(360deg)} } + /*=============TOOLTIP=============*/ + + /* START TOOLTIP STYLES */ + [tooltip] { + position: relative; /* opinion 1 */ + } + + /* Applies to all tooltips */ + [tooltip]::before, + [tooltip]::after { + text-transform: none; /* opinion 2 */ + font-size: .9em; /* opinion 3 */ + line-height: 1; + user-select: none; + pointer-events: none; + position: absolute; + display: none; + opacity: 0; + } + [tooltip]::before { + content: ''; + border: 5px solid transparent; /* opinion 4 */ + z-index: 1001; /* absurdity 1 */ + } + [tooltip]::after { + content: attr(tooltip); /* magic! */ + + /* most of the rest of this is opinion */ + font-family: Helvetica, sans-serif; + text-align: center; + + /* + Let the content set the size of the tooltips + but this will also keep them from being obnoxious + */ + min-width: 3em; + max-width: 21em; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + padding: 1ch 1.5ch; + border-radius: .3ch; + box-shadow: 0 1em 2em -.5em rgba(0, 0, 0, 0.35); + background: #333; + color: #fff; + z-index: 1000; /* absurdity 2 */ + } + + /* Make the tooltips respond to hover */ + [tooltip]::before, + [tooltip]::after { + display: block; + } + + /* don't show empty tooltips */ + [tooltip='']::before, + [tooltip='']::after { + display: none !important; + } + + /* FLOW: UP */ + [tooltip]:not([flow])::before, + [tooltip][flow^="up"]::before { + bottom: 100%; + border-bottom-width: 0; + border-top-color: #333; + } + [tooltip]:not([flow])::after, + [tooltip][flow^="up"]::after { + bottom: calc(100% + 5px); + } + [tooltip]:not([flow])::before, + [tooltip]:not([flow])::after, + [tooltip][flow^="up"]::before, + [tooltip][flow^="up"]::after { + left: 50%; + transform: translate(-50%, -.5em); + } + + /* KEYFRAMES */ + @keyframes tooltips-vert { + to { + opacity: .9; + transform: translate(-50%, 0); + } + } + + @keyframes tooltips-horz { + to { + opacity: .9; + transform: translate(0, -50%); + } + } + + /* FX All The Things */ + [tooltip]:not([flow])::before, + [tooltip]:not([flow])::after, + [tooltip][flow^="up"]::before, + [tooltip][flow^="up"]::after { + animation: tooltips-vert 300ms ease-out forwards; + } + \ No newline at end of file