Compare commits
4 Commits
c11c1d4dce
...
7ee59c434b
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ee59c434b | |||
| 2833ead7be | |||
| d89c7e8c3f | |||
| c60d00f9d2 |
+1
-5
@@ -22,12 +22,8 @@ yarn-error.log
|
|||||||
|
|
||||||
# Visual Studio Code
|
# Visual Studio Code
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/settings.json
|
|
||||||
!.vscode/tasks.json
|
|
||||||
!.vscode/launch.json
|
|
||||||
!.vscode/extensions.json
|
|
||||||
.history/*
|
.history/*
|
||||||
|
.angualar/
|
||||||
# Miscellaneous
|
# Miscellaneous
|
||||||
/.angular/cache
|
/.angular/cache
|
||||||
.sass-cache/
|
.sass-cache/
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
.board-shell {
|
.board-shell {
|
||||||
width: min(100%, 82dvh, 760px);
|
--bottom-frame-height: clamp(18px, 4.5cqh, 40px);
|
||||||
max-width: calc(100dvw - 2rem);
|
width: min(98cqw, calc(98cqh - var(--bottom-frame-height)));
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,8 +51,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.board-bottom {
|
.board-bottom {
|
||||||
|
height: var(--bottom-frame-height);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: block;
|
display: block;
|
||||||
|
object-fit: fill;
|
||||||
border: 2px solid #5A2C28;
|
border: 2px solid #5A2C28;
|
||||||
border-top: 0;
|
border-top: 0;
|
||||||
border-radius: 0 0 10px 10px;
|
border-radius: 0 0 10px 10px;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
.piece {
|
.piece {
|
||||||
width: 90%;
|
width: clamp(40px, 9cqh, 130px);
|
||||||
height: 90%;
|
height: clamp(40px, 9cqh, 130px);
|
||||||
display: block;
|
display: block;
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
|||||||
@@ -40,35 +40,24 @@ h2 {
|
|||||||
|
|
||||||
.top-section {
|
.top-section {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 0.75rem;
|
gap: 0.5rem;
|
||||||
margin-bottom: 0.75rem;
|
margin-bottom: 0.5rem;
|
||||||
flex: 0 0 auto;
|
flex: 0 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.state-grid {
|
.content-layout {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-height: 0;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
grid-template-columns: minmax(220px, 0.95fr) minmax(0, 2.4fr) minmax(220px, 0.95fr);
|
||||||
gap: 0.75rem;
|
gap: 0.75rem;
|
||||||
margin-bottom: 0.5rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.panel {
|
.center-column {
|
||||||
background: #B9C2DA;
|
min-width: 0;
|
||||||
border-radius: 10px;
|
min-height: 0;
|
||||||
border: 2px solid #5A2C28;
|
display: flex;
|
||||||
padding: 0.75rem;
|
flex-direction: column;
|
||||||
}
|
|
||||||
|
|
||||||
.panel p {
|
|
||||||
margin: 0.3rem 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
code {
|
|
||||||
display: block;
|
|
||||||
background: #E1EAA9;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 0.5rem;
|
|
||||||
overflow-wrap: anywhere;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.move-form {
|
.move-form {
|
||||||
@@ -78,11 +67,17 @@ code {
|
|||||||
gap: 0.75rem;
|
gap: 0.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.board-hint {
|
||||||
|
margin: 0;
|
||||||
|
color: #5A2C28;
|
||||||
|
}
|
||||||
|
|
||||||
.board-section {
|
.board-section {
|
||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
min-height: 0;
|
min-height: 180px;
|
||||||
display: grid;
|
display: grid;
|
||||||
place-items: center;
|
place-items: center;
|
||||||
|
container-type: size;
|
||||||
padding: clamp(0.35rem, 1vw, 0.75rem);
|
padding: clamp(0.35rem, 1vw, 0.75rem);
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
border: 2px solid #5A2C28;
|
border: 2px solid #5A2C28;
|
||||||
@@ -90,6 +85,22 @@ code {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.import-card {
|
||||||
|
background: #E1EAA9;
|
||||||
|
border: 2px solid #5A2C28;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 0.65rem;
|
||||||
|
display: grid;
|
||||||
|
align-self: start;
|
||||||
|
align-content: start;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.import-card label {
|
||||||
|
color: #5A2C28;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
border: 2px solid #5A2C28;
|
border: 2px solid #5A2C28;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
@@ -98,6 +109,15 @@ input {
|
|||||||
min-width: 180px;
|
min-width: 180px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
border: 2px solid #5A2C28;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #B9DAD1;
|
||||||
|
padding: 0.6rem 0.75rem;
|
||||||
|
resize: vertical;
|
||||||
|
min-height: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
border: 2px solid #5A2C28;
|
border: 2px solid #5A2C28;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
@@ -117,3 +137,25 @@ button:hover {
|
|||||||
color: #5A2C28;
|
color: #5A2C28;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 920px) {
|
||||||
|
.content-layout {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
grid-template-areas:
|
||||||
|
"center"
|
||||||
|
"fen"
|
||||||
|
"pgn";
|
||||||
|
}
|
||||||
|
|
||||||
|
.center-column {
|
||||||
|
grid-area: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fen-card {
|
||||||
|
grid-area: fen;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pgn-card {
|
||||||
|
grid-area: pgn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,39 +9,50 @@
|
|||||||
@if (loading) {
|
@if (loading) {
|
||||||
<p>Loading game state...</p>
|
<p>Loading game state...</p>
|
||||||
} @else if (state) {
|
} @else if (state) {
|
||||||
<section class="top-section">
|
<section class="content-layout">
|
||||||
<div class="state-grid">
|
<aside class="import-card fen-card">
|
||||||
<div class="panel">
|
<label for="fenImport">Import FEN</label>
|
||||||
<h2>Status</h2>
|
<textarea
|
||||||
<p>Turn: <strong>{{ state.turn }}</strong></p>
|
id="fenImport"
|
||||||
<p>Status: <strong>{{ state.status }}</strong></p>
|
name="fenImport"
|
||||||
<p>FEN:</p>
|
[(ngModel)]="fenInput"
|
||||||
<code>{{ state.fen }}</code>
|
rows="4"
|
||||||
</div>
|
placeholder="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
|
||||||
|
></textarea>
|
||||||
|
<button type="button" (click)="importFen()">Load FEN</button>
|
||||||
|
</aside>
|
||||||
|
|
||||||
<div class="panel">
|
<section class="center-column">
|
||||||
<h2>Moves</h2>
|
<section class="top-section">
|
||||||
<p>PGN: {{ state.pgn || 'No moves yet' }}</p>
|
<form class="move-form" (ngSubmit)="submitMove()">
|
||||||
<p>Played UCI: {{ state.moves.length ? state.moves.join(', ') : 'None' }}</p>
|
<label for="uciMove">Play move (UCI)</label>
|
||||||
<p>Legal UCI: {{ legalMoveUciList.length ? legalMoveUciList.join(', ') : 'None' }}</p>
|
<input id="uciMove" name="uciMove" [(ngModel)]="moveInput" placeholder="e2e4" />
|
||||||
<p>Board: click your piece to highlight legal targets.</p>
|
<button type="submit">Send Move</button>
|
||||||
</div>
|
</form>
|
||||||
</div>
|
<p class="board-hint">Click your piece to highlight legal targets.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
<form class="move-form" (ngSubmit)="submitMove()">
|
<section class="board-section">
|
||||||
<label for="uciMove">Play move (UCI)</label>
|
<app-chess-board
|
||||||
<input id="uciMove" name="uciMove" [(ngModel)]="moveInput" placeholder="e2e4" />
|
[fen]="state.fen"
|
||||||
<button type="submit">Send Move</button>
|
[selectedSquare]="selectedSquare"
|
||||||
</form>
|
[highlightedSquares]="highlightedSquares"
|
||||||
</section>
|
(squareSelected)="onBoardSquareSelected($event)"
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section class="board-section">
|
<aside class="import-card pgn-card">
|
||||||
<app-chess-board
|
<label for="pgnImport">Import PGN</label>
|
||||||
[fen]="state.fen"
|
<textarea
|
||||||
[selectedSquare]="selectedSquare"
|
id="pgnImport"
|
||||||
[highlightedSquares]="highlightedSquares"
|
name="pgnImport"
|
||||||
(squareSelected)="onBoardSquareSelected($event)"
|
[(ngModel)]="pgnInput"
|
||||||
/>
|
rows="4"
|
||||||
|
placeholder="1. e4 e5 2. Nf3 Nc6 *"
|
||||||
|
></textarea>
|
||||||
|
<button type="button" (click)="importPgn()">Load PGN</button>
|
||||||
|
</aside>
|
||||||
</section>
|
</section>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { FormsModule } from '@angular/forms';
|
import { FormsModule } from '@angular/forms';
|
||||||
import { ActivatedRoute, RouterLink } from '@angular/router';
|
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||||
import { interval, startWith, Subscription, switchMap } from 'rxjs';
|
import { interval, startWith, Subscription, switchMap } from 'rxjs';
|
||||||
import { ChessBoardComponent } from '../../components/chess-board/chess-board.component';
|
import { ChessBoardComponent } from '../../components/chess-board/chess-board.component';
|
||||||
import { GameFull, GameState, GameStreamEvent, LegalMove } from '../../models/game.models';
|
import { GameFull, GameState, GameStreamEvent, LegalMove } from '../../models/game.models';
|
||||||
@@ -19,7 +19,8 @@ export class GameComponent implements OnInit, OnDestroy {
|
|||||||
game: GameFull | null = null;
|
game: GameFull | null = null;
|
||||||
errorMessage = '';
|
errorMessage = '';
|
||||||
moveInput = '';
|
moveInput = '';
|
||||||
legalMoves: LegalMove[] = [];
|
fenInput = '';
|
||||||
|
pgnInput = '';
|
||||||
loading = true;
|
loading = true;
|
||||||
selectedSquare: string | null = null;
|
selectedSquare: string | null = null;
|
||||||
highlightedSquares: string[] = [];
|
highlightedSquares: string[] = [];
|
||||||
@@ -31,6 +32,7 @@ export class GameComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly route: ActivatedRoute,
|
private readonly route: ActivatedRoute,
|
||||||
|
private readonly router: Router,
|
||||||
private readonly gameApi: GameApiService
|
private readonly gameApi: GameApiService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -38,10 +40,6 @@ export class GameComponent implements OnInit, OnDestroy {
|
|||||||
return this.game?.state ?? null;
|
return this.game?.state ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get legalMoveUciList(): string[] {
|
|
||||||
return this.legalMoves.map((move) => move.uci);
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.routeSubscription = this.route.paramMap.subscribe((paramMap) => {
|
this.routeSubscription = this.route.paramMap.subscribe((paramMap) => {
|
||||||
const id = paramMap.get('gameId');
|
const id = paramMap.get('gameId');
|
||||||
@@ -110,7 +108,6 @@ export class GameComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
this.moveInput = '';
|
this.moveInput = '';
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.loadLegalMoves();
|
|
||||||
},
|
},
|
||||||
error: (error: { error?: { message?: string } }) => {
|
error: (error: { error?: { message?: string } }) => {
|
||||||
this.errorMessage = error.error?.message ?? 'Move rejected.';
|
this.errorMessage = error.error?.message ?? 'Move rejected.';
|
||||||
@@ -118,6 +115,46 @@ export class GameComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
importFen(): void {
|
||||||
|
const fen = this.fenInput.trim();
|
||||||
|
if (!fen) {
|
||||||
|
this.errorMessage = 'Please provide a FEN string.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.errorMessage = '';
|
||||||
|
this.gameApi.importFen(fen).subscribe({
|
||||||
|
next: (game) => {
|
||||||
|
this.fenInput = '';
|
||||||
|
this.pgnInput = '';
|
||||||
|
void this.router.navigate(['/game', game.gameId]);
|
||||||
|
},
|
||||||
|
error: (error: { error?: { message?: string } }) => {
|
||||||
|
this.errorMessage = error.error?.message ?? 'FEN import failed.';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
importPgn(): void {
|
||||||
|
const pgn = this.pgnInput.trim();
|
||||||
|
if (!pgn) {
|
||||||
|
this.errorMessage = 'Please provide a PGN string.';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.errorMessage = '';
|
||||||
|
this.gameApi.importPgn(pgn).subscribe({
|
||||||
|
next: (game) => {
|
||||||
|
this.pgnInput = '';
|
||||||
|
this.fenInput = '';
|
||||||
|
void this.router.navigate(['/game', game.gameId]);
|
||||||
|
},
|
||||||
|
error: (error: { error?: { message?: string } }) => {
|
||||||
|
this.errorMessage = error.error?.message ?? 'PGN import failed.';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private loadGame(): void {
|
private loadGame(): void {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.errorMessage = '';
|
this.errorMessage = '';
|
||||||
@@ -129,7 +166,6 @@ export class GameComponent implements OnInit, OnDestroy {
|
|||||||
next: (game) => {
|
next: (game) => {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.loadLegalMoves();
|
|
||||||
this.startStream();
|
this.startStream();
|
||||||
this.startPolling();
|
this.startPolling();
|
||||||
},
|
},
|
||||||
@@ -140,17 +176,6 @@ export class GameComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadLegalMoves(): void {
|
|
||||||
this.gameApi.getLegalMoves(this.gameId).subscribe({
|
|
||||||
next: (response) => {
|
|
||||||
this.legalMoves = response.moves;
|
|
||||||
},
|
|
||||||
error: () => {
|
|
||||||
this.legalMoves = [];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private startStream(): void {
|
private startStream(): void {
|
||||||
this.streamSubscription = this.gameApi.streamGame(this.gameId).subscribe({
|
this.streamSubscription = this.gameApi.streamGame(this.gameId).subscribe({
|
||||||
next: (event) => this.applyStreamEvent(event),
|
next: (event) => this.applyStreamEvent(event),
|
||||||
@@ -172,7 +197,6 @@ export class GameComponent implements OnInit, OnDestroy {
|
|||||||
this.game = game;
|
this.game = game;
|
||||||
if (previousMoves !== game.state.moves.join(',')) {
|
if (previousMoves !== game.state.moves.join(',')) {
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.loadLegalMoves();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -182,7 +206,6 @@ export class GameComponent implements OnInit, OnDestroy {
|
|||||||
if (event.type === 'gameFull') {
|
if (event.type === 'gameFull') {
|
||||||
this.game = event.game;
|
this.game = event.game;
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
this.loadLegalMoves();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +215,6 @@ export class GameComponent implements OnInit, OnDestroy {
|
|||||||
if (event.state.moves.length !== moveCountBefore) {
|
if (event.state.moves.length !== moveCountBefore) {
|
||||||
this.clearSelection();
|
this.clearSelection();
|
||||||
}
|
}
|
||||||
this.loadLegalMoves();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,14 @@ export class GameApiService {
|
|||||||
return this.http.get<LegalMovesResponse>(`${this.apiBase}/api/board/game/${gameId}/moves`, { params });
|
return this.http.get<LegalMovesResponse>(`${this.apiBase}/api/board/game/${gameId}/moves`, { params });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
importFen(fen: string): Observable<GameFull> {
|
||||||
|
return this.http.post<GameFull>(`${this.apiBase}/api/board/game/import/fen`, { fen });
|
||||||
|
}
|
||||||
|
|
||||||
|
importPgn(pgn: string): Observable<GameFull> {
|
||||||
|
return this.http.post<GameFull>(`${this.apiBase}/api/board/game/import/pgn`, { pgn });
|
||||||
|
}
|
||||||
|
|
||||||
streamGame(gameId: string): Observable<GameStreamEvent> {
|
streamGame(gameId: string): Observable<GameStreamEvent> {
|
||||||
return new Observable<GameStreamEvent>((observer) => {
|
return new Observable<GameStreamEvent>((observer) => {
|
||||||
const wsUrl = `${this.wsBase}/api/board/game/${gameId}/stream`;
|
const wsUrl = `${this.wsBase}/api/board/game/${gameId}/stream`;
|
||||||
|
|||||||
Reference in New Issue
Block a user