feat: set White/Black player names when exporting a PGN

Export PGN now opens a dialog with White/Black fields (pre-filled from the game
headers, placeholders treated as blank). Entered names are written back, so they
appear in the exported PGN, update the on-screen 'X vs Y' line, and persist if the
game is saved — instead of always exporting 'You vs Opponent'. Bump cache version.
This commit is contained in:
Michael Pilosov 2026-06-25 21:45:03 +00:00
parent 791cc35962
commit 3974c9faab
3 changed files with 34 additions and 4 deletions

View File

@ -532,8 +532,26 @@
updateSavedControls();
}
function exportPGN() {
async function exportPGN() {
if (!gameData) return;
// Let the user set player names before download; pre-fill from headers,
// treating placeholders ("?") as blank. Names are written back so they show
// on screen and persist on Save too.
const whiteEl = document.getElementById("pgn-white");
const blackEl = document.getElementById("pgn-black");
const real = (v) => (v && v !== "?" && v !== "????.??.??" ? v : "");
whiteEl.value = real(gameData.headers.White);
blackEl.value = real(gameData.headers.Black);
setTimeout(() => { whiteEl.focus(); whiteEl.select(); }, 0);
const ok = await openModal(document.getElementById("export-pgn-dialog"));
if (!ok) return;
gameData.headers.White = whiteEl.value.trim() || "White";
gameData.headers.Black = blackEl.value.trim() || "Black";
updateGameInfo();
const pgn = ChessPressure.toPgn(gameData.headers, gameData.moves);
const slug = (defaultGameName() || "game")
.toLowerCase()

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chess Pressure</title>
<link rel="stylesheet" href="/style.css?v=30">
<link rel="stylesheet" href="/style.css?v=31">
<link rel="stylesheet" href="https://unpkg.com/@chrisoakman/chessboardjs@1.0.0/dist/chessboard-1.0.0.min.css">
<link rel="manifest" href="/manifest.json">
</head>
@ -135,6 +135,18 @@
</form>
</dialog>
<dialog id="export-pgn-dialog">
<form method="dialog">
<h2>Export PGN</h2>
<label>White: <input type="text" id="pgn-white" autocomplete="off" placeholder="White player"></label>
<label>Black: <input type="text" id="pgn-black" autocomplete="off" placeholder="Black player"></label>
<div class="dialog-buttons">
<button type="button" data-ok>Download</button>
<button type="button" data-cancel>Cancel</button>
</div>
</form>
</dialog>
<dialog id="confirm-dialog">
<form method="dialog">
<h2 id="confirm-title">Please confirm</h2>
@ -164,6 +176,6 @@
<script src="/chess.min.js"></script>
<script src="/gif.js"></script>
<script src="/engine.js"></script>
<script src="/app.js?v=30"></script>
<script src="/app.js?v=31"></script>
</body>
</html>

View File

@ -7,7 +7,7 @@
*
* Bump CACHE on every deploy so clients pick up new assets.
*/
const CACHE = "chess-pressure-v30";
const CACHE = "chess-pressure-v31";
// Same-origin app shell. Cached by canonical path; the fetch handler matches
// with ignoreSearch so cache-busting query strings (?v=NN) still hit.