From c3bc429af2d6c6d431468a13413116ef9d747107 Mon Sep 17 00:00:00 2001 From: whidix Date: Mon, 2 Mar 2026 11:05:02 +0100 Subject: [PATCH] feat: add WinPanel and YesterdayCharacter components; refactor daily game page - Introduced WinPanel component to display win/loss messages based on game outcome. - Added YesterdayCharacter component to show the character from the previous day. - Refactored daily game page to utilize new components for better code organization and readability. - Updated server-side logic to fetch daily character ID and count wins more efficiently. - Cleaned up character selection logic and hint availability tracking. --- .../components/CharacterSearchInput.svelte | 167 +++++ src/lib/components/GuessHistoryTable.svelte | 246 ++++++++ src/lib/components/HintsPanel.svelte | 88 +++ src/lib/components/WinPanel.svelte | 57 ++ src/lib/components/YesterdayCharacter.svelte | 51 ++ src/routes/(admin)/admin/+page.server.ts | 14 +- src/routes/(game)/daily/+page.svelte | 581 ++---------------- 7 files changed, 649 insertions(+), 555 deletions(-) create mode 100644 src/lib/components/CharacterSearchInput.svelte create mode 100644 src/lib/components/GuessHistoryTable.svelte create mode 100644 src/lib/components/HintsPanel.svelte create mode 100644 src/lib/components/WinPanel.svelte create mode 100644 src/lib/components/YesterdayCharacter.svelte diff --git a/src/lib/components/CharacterSearchInput.svelte b/src/lib/components/CharacterSearchInput.svelte new file mode 100644 index 0000000..e7a0960 --- /dev/null +++ b/src/lib/components/CharacterSearchInput.svelte @@ -0,0 +1,167 @@ + + +
+

Entrer une supposition

+
+
+ + {#if searchInput.length > 0 && filteredCharacters.length > 0} +
+ {#each filteredCharacters as character, index (character.id)} + + {/each} +
+ {/if} +
+ +
+
diff --git a/src/lib/components/GuessHistoryTable.svelte b/src/lib/components/GuessHistoryTable.svelte new file mode 100644 index 0000000..fa0ac31 --- /dev/null +++ b/src/lib/components/GuessHistoryTable.svelte @@ -0,0 +1,246 @@ + + +
+
+
+

Historique

+
+ {#if selectedCharacters.length === 0} +

Aucune tentative pour le moment.

+ {:else} +
+
+ +
+
+

Personnage

+
+ {#if columnVisibility.status !== false} +
+

Statut

+
+ {/if} + {#if columnVisibility.gender !== false} +
+

Genre

+
+ {/if} + {#if columnVisibility.affiliations !== false} +
+

Affiliations

+
+ {/if} + {#if columnVisibility.devilFruitType !== false} +
+

Fruit

+
+ {/if} + {#if columnVisibility.haki !== false} +
+

Haki

+
+ {/if} + {#if columnVisibility.bounty !== false} +
+

Prime

+
+ {/if} + {#if columnVisibility.height !== false} +
+

Taille

+
+ {/if} + {#if columnVisibility.origin !== false} +
+

Origine

+
+ {/if} + {#if columnVisibility.arc !== false} +
+

Arc

+
+ {/if} +
+ + + {#each selectedCharacters as character (character.id)} +
+ +
+ {#if character.pictureUrl} + + {character.name} + + {:else} +
+ {character.name} +
+ {/if} +
+ + + {#if columnVisibility.status !== false} +
+

+ {character.status === 'Alive' ? 'Vivant' : character.status === 'Deceased' || character.status === 'Dead' ? 'Mort' : character.status || 'Inconnu'} +

+
+ {/if} + + + {#if columnVisibility.gender !== false} +
+

+ {character.gender === 'Male' ? 'Homme' : character.gender === 'Female' ? 'Femme' : character.gender || 'Inconnu'} +

+
+ {/if} + + + {#if columnVisibility.affiliations !== false} +
+ {#if character.affiliations} + {@const parsedAffiliations = typeof character.affiliations === 'string' + ? (character.affiliations.includes('[') ? JSON.parse(character.affiliations) : character.affiliations.split(',').map((a: string) => a.trim())) + : character.affiliations} + {#if Array.isArray(parsedAffiliations) && parsedAffiliations.length > 0} +

{parsedAffiliations[0]}

+ {:else} +

{parsedAffiliations}

+ {/if} + {:else} +

-

+ {/if} +
+ {/if} + + + {#if columnVisibility.devilFruitType !== false} +
+ {#if character.devilFruitType} +

{character.devilFruitType}

+ {:else} +

+ {/if} +
+ {/if} + + + {#if columnVisibility.haki !== false} +
+

+ {#if character.hakiObservation}👁️{/if} + {#if character.hakiArmament}🦾{/if} + {#if character.hakiConqueror}👑{/if} + {#if !character.hakiObservation && !character.hakiArmament && !character.hakiConqueror} + + {/if} +

+
+ {/if} + + + {#if columnVisibility.bounty !== false} +
+ {#if character.bounty != null && dailyCharacter.bounty != null && character.bounty !== dailyCharacter.bounty} +
+ {/if} + {#if character.bounty != null} +

{formatBounty(character.bounty)} ฿

+ {:else} +

Inconnue

+ {/if} +
+ {/if} + + + {#if columnVisibility.height !== false} +
+ {#if character.height && dailyCharacter.height && character.height !== dailyCharacter.height} +
+ {/if} + {#if character.height} +

{character.height} m

+ {:else} +

Inconnue

+ {/if} +
+ {/if} + + + {#if columnVisibility.origin !== false} +
+

{character.origin || 'Inconnue'}

+
+ {/if} + + + {#if columnVisibility.arc !== false} +
+ {#if character.arcName !== dailyCharacter.arcName && character.firstAppearance && dailyCharacter.firstAppearance && character.firstAppearance !== dailyCharacter.firstAppearance} +
+ {/if} +

{character.arcName || 'Inconnu'}

+
+ {/if} +
+ {/each} +
+
+ {/if} +
+
diff --git a/src/lib/components/HintsPanel.svelte b/src/lib/components/HintsPanel.svelte new file mode 100644 index 0000000..4f1d529 --- /dev/null +++ b/src/lib/components/HintsPanel.svelte @@ -0,0 +1,88 @@ + + + + + + +
+
+ + + +
+
diff --git a/src/lib/components/WinPanel.svelte b/src/lib/components/WinPanel.svelte new file mode 100644 index 0000000..6ff97d5 --- /dev/null +++ b/src/lib/components/WinPanel.svelte @@ -0,0 +1,57 @@ + + +{#if isGeckoMoriaWin} +
+
+
🌑
+

Moria vous contrôle...

+

Vous avez succombé à l'ombre en {selectedCharacters.length} {selectedCharacters.length > 1 ? 'tentatives' : 'tentative'} !

+
+ {#if dailyCharacter.pictureUrl} + + {dailyCharacter.name} + + {/if} +

{dailyCharacter.name}

+
+
+
+{:else} +
+
+
🎉
+

Félicitations !

+

Vous avez trouvé le personnage en {selectedCharacters.length} {selectedCharacters.length > 1 ? 'tentatives' : 'tentative'} !

+
+ {#if dailyCharacter.pictureUrl} + + {dailyCharacter.name} + + {/if} +

{dailyCharacter.name}

+
+
+
+{/if} diff --git a/src/lib/components/YesterdayCharacter.svelte b/src/lib/components/YesterdayCharacter.svelte new file mode 100644 index 0000000..3ef4908 --- /dev/null +++ b/src/lib/components/YesterdayCharacter.svelte @@ -0,0 +1,51 @@ + + +
+ {#if yesterdayCharacter} +
+ {#if yesterdayCharacter.pictureUrl} + {yesterdayCharacter.name} + {:else} +
+ Photo +
+ {/if} +
+

Personnage d'hier

+

{yesterdayCharacter.name}

+ {#if yesterdayCharacter.epithets} +

+ {typeof yesterdayCharacter.epithets === 'string' + ? JSON.parse(yesterdayCharacter.epithets).join(', ') + : (yesterdayCharacter.epithets as string[]).join(', ')} +

+ {/if} +
+ + Voir la page + +
+ {:else} +
+
+ Photo +
+
+

Personnage d'hier

+

Aucun personnage

+

Aucun personnage d'hier disponible

+
+
+ {/if} +
diff --git a/src/routes/(admin)/admin/+page.server.ts b/src/routes/(admin)/admin/+page.server.ts index 521e3e4..8e78a0a 100644 --- a/src/routes/(admin)/admin/+page.server.ts +++ b/src/routes/(admin)/admin/+page.server.ts @@ -1,7 +1,7 @@ import { db } from '$lib/server/db'; import { character, devilFruit, arc, user, config, characterHistory } from '$lib/server/db/schema'; -import { eq } from 'drizzle-orm'; import type { PageServerLoad } from './$types'; +import { getDailyCharacterId } from '$lib/server/dailyCharacter'; export const load: PageServerLoad = async () => { const [characters, devilFruits, arcs, users, configEntries, history] = await Promise.all([ @@ -13,15 +13,9 @@ export const load: PageServerLoad = async () => { db.select().from(characterHistory) ]); - // Get daily character ID from config - const dailyCharIdEntry = configEntries.find((c) => c.key === 'dailyCharacterId'); - const dailyCharId = dailyCharIdEntry?.value; - - // Count how many times today's daily character was won/found - const today = new Date().toISOString().split('T')[0]; - const dailyCharacterWins = dailyCharId - ? history.filter((h) => h.characterId === dailyCharId && h.date === today && h.won === 1).length - : 0; + const dailyCharacterId = await getDailyCharacterId(); + // Return count of wins for the daily character , count is stored in won field of characterHistory + const dailyCharacterWins = history.filter((h) => h.characterId === dailyCharacterId && h.won).length; return { stats: { diff --git a/src/routes/(game)/daily/+page.svelte b/src/routes/(game)/daily/+page.svelte index dc981f3..7798dac 100644 --- a/src/routes/(game)/daily/+page.svelte +++ b/src/routes/(game)/daily/+page.svelte @@ -1,18 +1,16 @@ OnePieceDle - Mode du jour