feat: added bot, light and dark mode

This commit was merged in pull request #1.
This commit is contained in:
2026-04-22 10:22:22 +02:00
parent e83ec814d9
commit 2de003e497
36 changed files with 2047 additions and 498 deletions
+550 -37
View File
@@ -1,99 +1,459 @@
.welcome-shell {
min-height: 100vh;
display: grid;
place-items: center;
padding: 2rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: var(--size-xl);
position: relative;
}
.theme-toggle-container {
position: absolute;
top: 20px;
right: 20px;
z-index: 100;
}
.switch {
display: inline-block;
position: relative;
}
.switch__input {
clip: rect(1px, 1px, 1px, 1px);
clip-path: inset(50%);
height: 1px;
width: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
}
.switch__label {
position: relative;
display: inline-block;
width: 120px;
height: 60px;
background-color: #2B2B2B;
border: 5px solid #5B5B5B;
border-radius: 9999px;
cursor: pointer;
transition: all 0.4s cubic-bezier(.46,.03,.52,.96);
}
.switch__indicator {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) translateX(-72%);
display: block;
width: 40px;
height: 40px;
background-color: #7B7B7B;
border-radius: 9999px;
box-shadow: 10px 0px 0 0 rgba(0, 0, 0, 0.2) inset;
transition: all 0.4s cubic-bezier(.46,.03,.52,.96);
}
.switch__indicator::before,
.switch__indicator::after {
position: absolute;
content: '';
display: block;
background-color: #FFFFFF;
border-radius: 9999px;
transition: all 0.4s cubic-bezier(.46,.03,.52,.96);
}
.switch__indicator::before {
top: 7px;
left: 7px;
width: 9px;
height: 9px;
opacity: 0.6;
}
.switch__indicator::after {
bottom: 8px;
right: 6px;
width: 14px;
height: 14px;
opacity: 0.8;
}
.switch__decoration {
position: absolute;
top: 65%;
left: 50%;
display: block;
width: 5px;
height: 5px;
background-color: #FFFFFF;
border-radius: 9999px;
animation: twinkle-stars 0.8s infinite -0.6s;
transition: all 0.4s cubic-bezier(.46,.03,.52,.96);
}
.switch__decoration::before,
.switch__decoration::after {
position: absolute;
display: block;
content: '';
width: 5px;
height: 5px;
background-color: #FFFFFF;
border-radius: 9999px;
}
.switch__decoration::before {
top: -20px;
left: 10px;
opacity: 1;
animation: twinkle-stars 0.6s infinite;
}
.switch__decoration::after {
top: -7px;
left: 30px;
animation: twinkle-stars 0.6s infinite -0.2s;
}
@keyframes twinkle-stars {
50% { opacity: 0.2; }
}
.switch__input:checked + .switch__label {
background-color: #8FB5F5;
border-color: #347CF8;
}
.switch__input:checked + .switch__label .switch__indicator {
background-color: #ECD21F;
box-shadow: none;
transform: translate(-50%, -50%) translateX(72%);
}
.switch__input:checked + .switch__label .switch__indicator::before,
.switch__input:checked + .switch__label .switch__indicator::after {
display: none;
}
.switch__input:checked + .switch__label .switch__decoration {
top: 50%;
transform: translate(0%, -50%);
animation: cloud 8s linear infinite;
width: 20px;
height: 20px;
}
.switch__input:checked + .switch__label .switch__decoration::before {
width: 10px;
height: 10px;
top: auto;
bottom: 0;
left: -8px;
animation: none;
}
.switch__input:checked + .switch__label .switch__decoration::after {
width: 15px;
height: 15px;
top: auto;
bottom: 0;
left: 16px;
animation: none;
}
.switch__input:checked + .switch__label .switch__decoration,
.switch__input:checked + .switch__label .switch__decoration::before,
.switch__input:checked + .switch__label .switch__decoration::after {
border-radius: 9999px 9999px 0 0;
}
.switch__input:checked + .switch__label .switch__decoration::after {
border-bottom-right-radius: 9999px;
}
@keyframes cloud {
0% { transform: translate(0%, -50%); }
50% { transform: translate(-50%, -50%); }
100% { transform: translate(0%, -50%); }
}
.clouds-container {
display: flex;
justify-content: center;
align-items: flex-start;
gap: 60px;
width: 100%;
max-width: 900px;
margin-bottom: var(--size-xl);
position: relative;
z-index: 1;
}
.plane {
position: relative;
width: 320px;
height: 140px;
display: flex;
align-items: center;
justify-content: center;
filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.12));
}
.plane-body {
width: 240%;
height: 240%;
object-fit: contain;
position: absolute;
}
.plane-gif {
width: 70px;
height: 70px;
object-fit: contain;
z-index: 10;
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
position: relative;
transform: translateX(-25px) translateY(15px);
}
.cloud {
position: relative;
width: 220px;
height: 90px;
display: flex;
align-items: center;
justify-content: center;
filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.12));
}
.cloud::before {
content: '';
position: absolute;
width: 90px;
height: 90px;
background: #ffffff;
border-radius: 50%;
top: 0;
left: 0;
box-shadow: 55px 0 0 9px #ffffff, 110px 0 0 5px #ffffff, 27px -18px 0 13px #ffffff, 82px -13px 0 11px #ffffff;
}
.cloud::after {
content: '';
position: absolute;
width: 220px;
height: 45px;
background: #ffffff;
border-radius: 50px;
bottom: 0;
left: 0;
}
.cloud-gif {
width: 150px;
height: 100px;
object-fit: contain;
z-index: 10;
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
position: relative;
}
.gif-with-halo {
position: relative;
display: inline-block;
}
.gif-with-halo::before {
content: '';
position: absolute;
top: -10px;
left: 50%;
transform: translateX(-50%);
width: 75px;
height: 15px;
border: 2px solid rgba(255, 215, 0, 0.7);
border-radius: 50%;
box-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
z-index: 5;
}
.welcome-card {
width: min(900px, 100%);
border-radius: 12px;
border: 2px solid #5A2C28;
background: #F3C8A0;
padding: 2rem;
box-shadow: 0 8px 24px rgba(90, 44, 40, 0.2);
border-radius: var(--border-radius-lg);
border: var(--border-width) solid var(--color-border);
background: var(--color-bg-main);
padding: var(--size-xl-padding);
box-shadow: var(--shadow-md);
}
h1 {
margin: 0 0 0.25rem;
color: #5A2C28;
margin: 0 0 var(--size-xs);
color: var(--color-text-primary);
font-size: var(--heading-h1);
}
p {
margin: 0 0 1.25rem;
margin: 0 0 var(--size-lg);
}
.mode-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 1rem;
gap: var(--size-xl-gap);
}
.mode {
border: 2px solid #5A2C28;
border-radius: 10px;
padding: 1rem;
border: var(--border-width) solid var(--color-border);
border-radius: var(--border-radius-md);
padding: var(--size-lg-padding);
text-align: left;
display: grid;
gap: 0.25rem;
gap: var(--size-xs);
}
.mode span {
font-size: 1.15rem;
color: #5A2C28;
color: var(--color-text-primary);
}
.mode small {
color: #5A2C28;
color: var(--color-text-primary);
opacity: 0.9;
}
.mode-active {
background: #B9DAD1;
background: var(--color-secondary-mint);
cursor: pointer;
}
.mode-active:hover:enabled {
background: #B9C2DA;
background: var(--color-secondary-blue);
}
.mode-disabled {
background: #E1EAA9;
background: var(--color-bg-card);
opacity: 0.75;
}
.error {
color: #5A2C28;
color: var(--color-text-primary);
font-weight: 700;
margin-top: 1rem;
margin-top: var(--size-xl);
}
.plane-left {
animation: float 3s ease-in-out infinite;
}
.cloud-left {
animation: float 3s ease-in-out infinite;
animation-delay: 0.25s;
}
.cloud-right {
animation: float 3s ease-in-out infinite;
animation-delay: 0.5s;
}
@keyframes float {
0%, 100% {
transform: translateY(0px);
}
50% {
transform: translateY(-15px);
}
}
@media (max-width: 768px) {
.theme-toggle-container {
top: 10px;
right: 10px;
}
.switch__label {
width: 100px;
height: 50px;
}
.switch__indicator {
width: 33px;
height: 33px;
}
.welcome-shell {
padding: 1rem;
padding: var(--size-lg);
}
.clouds-container {
gap: 30px;
margin-bottom: var(--size-lg);
}
.plane {
width: 240px;
height: 110px;
}
.plane-gif {
width: 55px;
height: 55px;
transform: translateX(-20px) translateY(12px);
}
.cloud {
width: 170px;
height: 75px;
}
.cloud::before {
width: 65px;
height: 65px;
box-shadow: 40px 0 0 7px #ffffff, 80px 0 0 3px #ffffff, 20px -13px 0 10px #ffffff, 60px -10px 0 8px #ffffff;
}
.cloud::after {
width: 170px;
height: 38px;
}
.cloud-gif {
width: 140px;
height: 140px;
}
.gif-with-halo::before {
top: -8px;
width: 80px;
height: 12px;
border: 1.5px solid rgba(255, 215, 0, 0.7);
}
.welcome-card {
padding: 1.5rem;
padding: var(--size-xl);
}
h1 {
font-size: 1.5rem;
font-size: var(--heading-h1-mobile);
}
p {
font-size: 0.875rem;
margin: 0 0 1rem;
margin: 0 0 var(--size-lg);
}
.mode-grid {
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 0.75rem;
gap: var(--size-md-gap);
}
.mode {
padding: 0.75rem;
gap: 0.15rem;
padding: var(--size-md-padding);
gap: var(--size-xs-gap);
}
.mode span {
@@ -111,22 +471,22 @@ p {
@media (max-width: 480px) {
.welcome-shell {
padding: 0.5rem;
padding: var(--size-sm);
}
.welcome-card {
padding: 1rem;
border-radius: 8px;
padding: var(--size-lg-padding);
border-radius: var(--border-radius-md);
}
h1 {
font-size: 1.25rem;
margin: 0 0 0.15rem;
font-size: var(--heading-h1-small);
margin: 0 0 var(--size-xs);
}
p {
font-size: 0.8rem;
margin: 0 0 0.75rem;
margin: 0 0 var(--size-md);
}
.mode-grid {
@@ -134,10 +494,163 @@ p {
}
.mode {
padding: 0.65rem;
padding: var(--size-md-padding);
}
.mode span {
font-size: 0.95rem;
}
}
.difficulty-selector {
grid-column: 1 / -1;
background: var(--color-bg-card);
border: var(--border-width) solid var(--color-border);
border-radius: var(--border-radius-md);
padding: var(--size-lg-padding);
margin: var(--size-md) 0;
}
.difficulty-selector p {
margin: 0 0 var(--size-md);
font-weight: 600;
}
.difficulty-buttons {
display: flex;
gap: var(--size-md-gap);
flex-wrap: wrap;
}
.difficulty-btn {
flex: 1;
min-width: 80px;
padding: var(--size-md-padding);
border: var(--border-width) solid var(--color-border);
border-radius: var(--border-radius-md);
cursor: pointer;
font-weight: 600;
transition: all 0.3s ease;
}
.difficulty-btn.easy {
background: var(--color-success-light, #d4edda);
color: var(--color-text-primary);
}
.difficulty-btn.easy:hover:enabled {
background: var(--color-success, #28a745);
color: white;
}
.difficulty-btn.medium {
background: var(--color-warning-light, #fff3cd);
color: var(--color-text-primary);
}
.difficulty-btn.medium:hover:enabled {
background: var(--color-warning, #ffc107);
color: var(--color-text-primary);
}
.difficulty-btn.hard {
background: var(--color-danger-light, #f8d7da);
color: var(--color-text-primary);
}
.difficulty-btn.hard:hover:enabled {
background: var(--color-danger, #dc3545);
color: white;
}
.join-game-form {
grid-column: 1 / -1;
background: var(--color-bg-card);
border: var(--border-width) solid var(--color-border);
border-radius: var(--border-radius-md);
padding: var(--size-lg-padding);
margin: var(--size-md) 0;
}
.join-game-form p {
margin: 0 0 var(--size-md);
font-weight: 600;
}
.join-game-input-group {
display: flex;
gap: var(--size-md-gap);
flex-wrap: wrap;
}
.join-game-input {
flex: 1;
min-width: 150px;
padding: var(--size-md-padding);
border: var(--border-width) solid var(--color-border);
border-radius: var(--border-radius-md);
background: white;
color: var(--color-text-primary);
font-family: inherit;
font-size: 1rem;
transition: border-color 0.3s ease;
}
.join-game-input:focus {
outline: none;
border-color: var(--color-secondary-mint);
box-shadow: 0 0 0 3px rgba(185, 218, 209, 0.2);
}
.join-game-input:disabled {
background: var(--color-bg-card);
opacity: 0.6;
}
.join-game-btn {
padding: var(--size-md-padding) var(--size-lg);
border: var(--border-width) solid var(--color-border);
border-radius: var(--border-radius-md);
cursor: pointer;
font-weight: 600;
font-size: 0.95rem;
transition: all 0.3s ease;
}
.join-game-btn.join {
background: var(--color-secondary-mint);
color: var(--color-text-primary);
}
.join-game-btn.join:hover:enabled {
background: var(--color-secondary-blue);
}
.join-game-btn.join:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.join-game-btn.cancel {
background: var(--color-bg-card);
color: var(--color-text-primary);
}
.join-game-btn.cancel:hover:enabled {
background: var(--color-border);
}
.join-game-btn.cancel:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.difficulty-btn.hard:hover:enabled {
background: var(--color-danger, #dc3545);
color: white;
}
.difficulty-btn:disabled {
opacity: 0.6;
cursor: not-allowed;
}
+77 -5
View File
@@ -1,25 +1,97 @@
<main class="welcome-shell">
<div class="theme-toggle-container">
<div class="switch">
<input type="checkbox" class="switch__input" id="themeToggle" (change)="toggleDarkMode()" [checked]="!isDarkMode()">
<label class="switch__label" for="themeToggle">
<span class="switch__indicator"></span>
<span class="switch__decoration"></span>
</label>
</div>
</div>
<div class="clouds-container">
<div class="cloud cloud-left">
<img src="arabian-chess/player-one.gif" alt="Player One" class="cloud-gif" />
</div>
<div class="plane plane-left">
<img src="arabian-chess/plane.png" alt="Plane" class="plane-body" />
<img src="arabian-chess/raf.gif" alt="Raf" class="plane-gif" />
</div>
<div class="cloud cloud-right">
<div class="gif-with-halo">
<img src="arabian-chess/player-two.gif" alt="Player Two" class="cloud-gif" />
</div>
</div>
</div>
<section class="welcome-card">
<h1>Welcome to NowChess</h1>
<p>Pick a mode to begin.</p>
<div class="mode-grid">
<button type="button" class="mode mode-disabled" disabled>
<button type="button" class="mode mode-active" (click)="toggleDifficultySelector()" [disabled]="creating">
<span>Bot</span>
<small>Coming soon</small>
<small>{{ creating ? 'Creating game...' : 'Choose difficulty' }}</small>
</button>
@if (showDifficultySelector) {
<div class="difficulty-selector">
<p>Select difficulty:</p>
<div class="difficulty-buttons">
<button type="button" class="difficulty-btn easy" (click)="startVsBot('easy')" [disabled]="creating">
Easy
</button>
<button type="button" class="difficulty-btn medium" (click)="startVsBot('medium')" [disabled]="creating">
Medium
</button>
<button type="button" class="difficulty-btn hard" (click)="startVsBot('hard')" [disabled]="creating">
Hard
</button>
</div>
</div>
}
<button type="button" class="mode mode-active" (click)="startOneVsOne()" [disabled]="creating">
<span>1 vs 1</span>
<small>{{ creating ? 'Creating game...' : 'Start now' }}</small>
</button>
<button type="button" class="mode mode-disabled" disabled>
<span>Future Technique</span>
<small>Placeholder</small>
<button type="button" class="mode mode-active" (click)="toggleJoinGameForm()" [disabled]="joiningGame">
<span>Join Game</span>
<small>{{ joiningGame ? 'Joining...' : 'Enter game ID' }}</small>
</button>
</div>
@if (showJoinGameForm) {
<div class="join-game-form">
<p>Enter the game ID:</p>
<div class="join-game-input-group">
<input
type="text"
class="join-game-input"
[(ngModel)]="gameIdInput"
placeholder="Paste game ID here"
[disabled]="joiningGame"
(keyup.enter)="joinGame()"
/>
<button
type="button"
class="join-game-btn join"
(click)="joinGame()"
[disabled]="joiningGame || !gameIdInput.trim()"
>
{{ joiningGame ? 'Joining...' : 'Join' }}
</button>
<button
type="button"
class="join-game-btn cancel"
(click)="clearJoinGameForm()"
[disabled]="joiningGame"
>
Cancel
</button>
</div>
</div>
}
@if (errorMessage) {
<p class="error">{{ errorMessage }}</p>
}
+95 -2
View File
@@ -1,5 +1,6 @@
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { Router } from '@angular/router';
import { finalize } from 'rxjs';
import { getErrorMessage } from '../../core/http/error-message.util';
@@ -8,18 +9,31 @@ import { GameApiService } from '../../services/game-api.service';
@Component({
selector: 'app-welcome',
standalone: true,
imports: [CommonModule],
imports: [CommonModule, FormsModule],
templateUrl: './welcome.component.html',
styleUrl: './welcome.component.css'
})
export class WelcomeComponent {
creating = false;
errorMessage = '';
showDifficultySelector = false;
showJoinGameForm = false;
gameIdInput = '';
joiningGame = false;
constructor(
private readonly router: Router,
private readonly gameApi: GameApiService
) {}
) {
this.initTheme();
}
private initTheme(): void {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.documentElement.setAttribute('data-theme', 'dark');
}
}
startOneVsOne(): void {
if (this.creating) {
@@ -41,4 +55,83 @@ export class WelcomeComponent {
}
});
}
startVsBot(difficulty: 'easy' | 'medium' | 'hard'): void {
if (this.creating) {
return;
}
this.errorMessage = '';
this.creating = true;
this.showDifficultySelector = false;
this.gameApi
.createGameVsBot(difficulty)
.pipe(finalize(() => (this.creating = false)))
.subscribe({
next: (game) => {
void this.router.navigate(['/game', game.gameId]);
},
error: (error) => {
this.errorMessage = getErrorMessage(error, 'Unable to create a game against bot.');
}
});
}
toggleDifficultySelector(): void {
this.showDifficultySelector = !this.showDifficultySelector;
this.showJoinGameForm = false;
this.errorMessage = '';
}
toggleJoinGameForm(): void {
this.showJoinGameForm = !this.showJoinGameForm;
this.showDifficultySelector = false;
this.errorMessage = '';
this.gameIdInput = '';
}
joinGame(): void {
if (this.joiningGame || !this.gameIdInput.trim()) {
return;
}
this.errorMessage = '';
this.joiningGame = true;
this.gameApi
.getGame(this.gameIdInput.trim())
.pipe(finalize(() => (this.joiningGame = false)))
.subscribe({
next: (game) => {
void this.router.navigate(['/game', game.gameId]);
},
error: (error) => {
this.errorMessage = getErrorMessage(error, 'Unable to find or join the game.');
}
});
}
clearJoinGameForm(): void {
this.showJoinGameForm = false;
this.gameIdInput = '';
this.errorMessage = '';
}
toggleDarkMode(): void {
const htmlElement = document.documentElement;
const isDarkMode = htmlElement.getAttribute('data-theme') === 'dark';
if (isDarkMode) {
htmlElement.removeAttribute('data-theme');
localStorage.removeItem('theme');
} else {
htmlElement.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark');
}
}
isDarkMode(): boolean {
return document.documentElement.getAttribute('data-theme') === 'dark';
}
}