Joffrey Thomas commited on
Commit
3339781
ยท
1 Parent(s): a3f099e
chess_game/static/img/wP.png ADDED
chess_game/static/room.js CHANGED
@@ -63,10 +63,22 @@
63
  return;
64
  }
65
  chess = new Chess();
66
- // chessboard.js prefers element id string in many setups
 
 
 
 
 
 
 
 
 
 
 
 
67
  board = Chessboard('boardUI', {
68
  position: 'start', draggable: true, dropOffBoard: 'snapback',
69
- pieceTheme: 'https://cdnjs.cloudflare.com/ajax/libs/chessboard.js/1.0.0/img/chesspieces/wikipedia/{piece}.png',
70
  onDragStart, onDrop, onSnapEnd
71
  });
72
  await syncFromServer();
 
63
  return;
64
  }
65
  chess = new Chess();
66
+ const pieceSvg = (piece) => {
67
+ const glyphs = { wK:'โ™”', wQ:'โ™•', wR:'โ™–', wB:'โ™—', wN:'โ™˜', wP:'โ™™', bK:'โ™š', bQ:'โ™›', bR:'โ™œ', bB:'โ™', bN:'โ™ž', bP:'โ™Ÿ' };
68
+ const isWhite = piece && piece[0] === 'w';
69
+ const glyph = glyphs[piece] || '?';
70
+ const fill = isWhite ? '#ffffff' : '#111827';
71
+ const stroke = isWhite ? '#e5e7eb' : '#0b0f19';
72
+ const svg = `<?xml version="1.0" encoding="UTF-8"?>
73
+ <svg xmlns='http://www.w3.org/2000/svg' width='64' height='64'>
74
+ <rect x='0' y='0' width='64' height='64' fill='transparent'/>
75
+ <text x='50%' y='62%' font-size='48' text-anchor='middle' fill='${fill}' stroke='${stroke}' stroke-width='1.5' font-family='Segoe UI Symbol, DejaVu Sans, Noto Sans Symbols, Arial, sans-serif'>${glyph}</text>
76
+ </svg>`;
77
+ return 'data:image/svg+xml;utf8,' + encodeURIComponent(svg);
78
+ };
79
  board = Chessboard('boardUI', {
80
  position: 'start', draggable: true, dropOffBoard: 'snapback',
81
+ pieceTheme: (p) => pieceSvg(p),
82
  onDragStart, onDrop, onSnapEnd
83
  });
84
  await syncFromServer();
chess_game/static/style.css CHANGED
@@ -9,4 +9,20 @@ button:hover { background: #1d4ed8; }
9
  input, select { padding: 8px; border-radius: 6px; border: 1px solid #334155; background: #0f172a; color: #e5e7eb; }
10
  ul { padding-left: 20px; }
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
 
9
  input, select { padding: 8px; border-radius: 6px; border: 1px solid #334155; background: #0f172a; color: #e5e7eb; }
10
  ul { padding-left: 20px; }
11
 
12
+ /* Minimal fallback styles for chessboard.js if CDN CSS fails to load */
13
+ .chessboard-63f37 { border: 1px solid #334155; background: #111827; }
14
+ .board-b72b1 { position: relative; width: 100%; padding-bottom: 100%; }
15
+ .square-55d63 { position: absolute; width: 12.5%; height: 12.5%; }
16
+ .white-1e1d7 { background: #f0d9b5; }
17
+ .black-3c85d { background: #b58863; }
18
+ img.piece-417db { position: absolute; width: 12.5%; height: 12.5%; user-select: none; -webkit-user-drag: none; }
19
+
20
+ /* Fallback board using CSS grid + Unicode pieces */
21
+ #boardUI.fallback { width: 520px; height: 520px; max-width: 90vw; max-height: 90vw; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); border: 1px solid #334155; }
22
+ #boardUI.fallback .sq { display: flex; align-items: center; justify-content: center; font-size: calc(520px / 10); user-select: none; }
23
+ #boardUI.fallback .light { background: #f0d9b5; color: #111827; }
24
+ #boardUI.fallback .dark { background: #b58863; color: #111827; }
25
+ #boardUI.fallback .pc { cursor: grab; }
26
+ #boardUI.fallback .pc:active { cursor: grabbing; }
27
+
28