Skip to content

Commit

Permalink
Added PlayerScore details
Browse files Browse the repository at this point in the history
  • Loading branch information
khaled-0 committed Jan 19, 2024
1 parent 31728a6 commit 9b66717
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 28 deletions.
10 changes: 0 additions & 10 deletions src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,3 @@ body {
@apply bg-platinum-900 dark:bg-rich_black-500;
@apply text-rich_black-500 dark:text-platinum-900;
}

@layer components {
.global-container-bg {
@apply bg-platinum-600 dark:bg-glaucous-100;
}

.global-subcontainer-bg {
@apply bg-platinum-800 dark:bg-glaucous-200;
}
}
2 changes: 2 additions & 0 deletions src/lib/components/Board/Board.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export let boardSize: BoardSize;
export let playerCount: PlayerCount;
export let boardHint: boolean;
export let focusColor: string;
const words = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
let boardData: HTMLInputElement[][] = Array.from(Array(boardSize), () =>
Expand Down Expand Up @@ -125,6 +126,7 @@
<BoardView
{boardData}
{boardHint}
{focusColor}
on:fieldFocus={(event) => (focusedInputIndex = event.detail)}
on:fieldUnfocus={() => setTimeout(() => (focusedInputIndex = null), 200)}
on:keyPress={(event) => handleKeyPress(event.detail.event, event.detail.row, event.detail.column)}
Expand Down
9 changes: 7 additions & 2 deletions src/lib/components/Board/BoardView.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
export let boardData: HTMLInputElement[][];
export let boardHint: boolean;
export let focusColor: string;
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher<{
Expand All @@ -17,7 +18,7 @@
}
</script>

<div class="rows-container" style="--row:{boardData.length}">
<div class="rows-container" style="--row:{boardData.length}; --focusColor:{focusColor}">
{#each boardData as row, rowIndex}
<div class="row">
{#each row as columnField, columnIndex}
Expand Down Expand Up @@ -56,9 +57,13 @@
@apply text-center cursor-pointer caret-transparent;
@apply text-xl large:text-2xl;
@apply rounded-md;
@apply rounded-md outline-none;
color: var(--color);
@apply focus-visible:bg-platinum-700 dark:focus-visible:bg-glaucous-200;
}
.input:focus {
outline-color: var(--focusColor);
}
</style>
26 changes: 16 additions & 10 deletions src/lib/components/Interaction/Interaction.svelte
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<script lang="ts">
import type { Player } from '$lib/data/Player';
import type { PlayerScore } from '$lib/data/PlayerScore';
import Letter from '../Letter.svelte';
import Letter from './Letter.svelte';
import { createEventDispatcher } from 'svelte';
import PlayerScoreChip from '../PlayerScoreChip.svelte';
import PlayerScoreChip from '../Player/PlayerScoreChip.svelte';
import PlayerDetailsDialog from '../Player/PlayerDetailsDialog.svelte';
export let color: string;
export let playersList: Player[];
export let currentPlayer: Player;
export let playerScores: PlayerScore[];
let playerDetailsDialog: HTMLDialogElement;
let playerDetailsDialogData: { player: Player; score: PlayerScore };
const dispatch = createEventDispatcher<{
showPlayerScoreDetails: { player: Player; score: PlayerScore };
preferenceClicked: void;
}>();
</script>

<div class="interaction-area global-container-bg">
<div class="letters-container">
{#each 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('') as value}
<Letter {value} {color} />
<Letter {value} color={currentPlayer.color} />
{/each}
</div>
<div class="gap-0.5 large:gap-2 flex flex-col">
Expand All @@ -29,11 +30,10 @@
player={playersList[score.playerId]}
myTurn={playersList[score.playerId] == currentPlayer}
playerScore={score}
on:onPlayerClick={() =>
dispatch('showPlayerScoreDetails', {
player: playersList[score.playerId],
score: score
})}
on:onPlayerClick={() => {
playerDetailsDialogData = { player: playersList[score.playerId], score: score };
playerDetailsDialog.showModal();
}}
/>
{/each}
</div>
Expand All @@ -54,6 +54,12 @@
</div>
</div>

<PlayerDetailsDialog
bind:dialog={playerDetailsDialog}
player={playerDetailsDialogData?.player}
playerScore={playerDetailsDialogData?.score}
/>

<style lang="postcss">
.interaction-area {
@apply h-full p-2 large:p-4;
Expand Down
File renamed without changes.
66 changes: 66 additions & 0 deletions src/lib/components/Player/PlayerDetailsDialog.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<script lang="ts">
// import { createEventDispatcher } from 'svelte';
export let dialog: HTMLDialogElement;
import type { Player } from '$lib/data/Player';
import type { PlayerScore } from '$lib/data/PlayerScore';
export let player: Player | undefined;
export let playerScore: PlayerScore | undefined;
// const dispatch = createEventDispatcher<{}>();
</script>

<!-- https://svelte.dev/repl/885653f873284f7880490dcdd1200238?version=3.48.0 -->

<dialog bind:this={dialog} class="global-container-bg">
<div class="title">
<span>Player Details</span>
<button class="rounded-xl h-5 w-5 bg-red-600" on:click={() => dialog.close()} />
</div>

<div class="body">
<div class="global-field flex items-center justify-between">
<span>
Name: {player?.name}
</span>
<div class="h-4 w-4 rounded-md border-1" style="background-color: {player?.color};" />
</div>
<div class="global-field">
Score: {playerScore?.score}
</div>
{#if playerScore?.words.length}
<div class="global-field">
<label for="message" class="block mb-2"
>Words <span class="float-end">({playerScore.words.length})</span></label
>
<textarea
readonly
rows="4"
value={playerScore.words.map((w) => `${w}(${w.length})`).join(', ')}
class="p-2 w-full rounded-lg global-container-bg outline-none resize-none"
/>
</div>
{/if}
</div>
</dialog>

<style lang="postcss">
dialog {
@apply w-9/12 large:w-5/12 h-5/6 large:h-3/6;
@apply p-4 rounded-xl;
@apply dark:text-platinum-800 text-rich_black-100;
}
.title {
@apply text-xl;
@apply flex gap-4 justify-between items-center;
}
.body {
@apply p-2 my-2 rounded-xl;
@apply text-sm font-medium;
}
.global-field {
@apply p-2;
}
</style>
File renamed without changes.
2 changes: 1 addition & 1 deletion src/lib/components/Preference/PreferenceDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<dialog bind:this={dialog} class="global-subcontainer-bg">
<div class="title">
<span>Preferences</span>
<button class="rounded-xl h-6 w-6 bg-red-600 border-2" on:click={() => dialog.close()} />
<button class="rounded-xl h-5 w-5 bg-red-600" on:click={() => dialog.close()} />
</div>
<Preference />
</dialog>
Expand Down
23 changes: 23 additions & 0 deletions src/lib/components/Spinner.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- <script lang="ts">
let customClass: string = '';
export { customClass as class };
</script> -->

<div role="status" class="w-fit">
<svg
aria-hidden="true"
class="w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-glaucous-600"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
</div>
10 changes: 9 additions & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<script>
import '../app.css';
import { navigating } from '$app/stores';
import Spinner from '$lib/components/Spinner.svelte';
</script>

<slot />
{#if $navigating}
<div class="flex justify-center items-center absolute bottom-0 top-0 left-0 right-0">
<Spinner />
</div>
{:else}
<slot />
{/if}
3 changes: 1 addition & 2 deletions src/routes/game/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
{boardSize}
{playerCount}
{boardHint}
focusColor={currentPlayer.color}
on:playerSubmit={handlePlayerSubmit}
on:gameOver={handleGameOver}
/>
Expand All @@ -93,11 +94,9 @@
<!-- TODO Toggle Preference Window -->

<Interaction
{color}
{currentPlayer}
{playersList}
{playerScores}
on:showPlayerScoreDetails={() => {}}
on:preferenceClicked={() => preferenceDialog.showModal()}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/game/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { PageLoad } from './$types';
export const load = (async ({ url }) => {
return {
board: (parseInt(url.searchParams.get('board')!) || 10) as BoardSize,
players: (parseInt(url.searchParams.get('players')!) || 4) as PlayerCount,
players: (parseInt(url.searchParams.get('players')!) || 4) as PlayerCount, //todoo limit err
colors: url.searchParams.get('colors')?.split(','),
names: url.searchParams.get('names')?.split(',')
} satisfies GameParameter;
Expand Down
32 changes: 31 additions & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,35 @@ export default {
}
}
},
plugins: []
plugins: [
({ addComponents, theme }) => {
addComponents({
'.global-container-bg': {
backgroundColor: theme('colors.platinum.600'),
'@media (prefers-color-scheme: dark)': {
backgroundColor: theme('colors.glaucous.100')
}
},
'.global-subcontainer-bg': {
backgroundColor: theme('colors.platinum.800'),
'@media (prefers-color-scheme: dark)': {
backgroundColor: theme('colors.glaucous.200')
}
},

'.global-field': {
'@apply global-subcontainer-bg': {},
'@apply my-1': {}
},
'.global-field:first-child': {
'border-top-left-radius': '0.75rem',
'border-top-right-radius': '0.75rem'
},
'.global-field:last-child ': {
'border-bottom-left-radius': ' 0.75rem',
'border-bottom-right-radius': '0.75rem'
}
});
}
]
};

0 comments on commit 9b66717

Please sign in to comment.