fix: saving a game with an existing name overwrites instead of duplicating

saveCurrentGame always pushed a new entry, so re-saving under the same title
produced two dropdown entries. Now it warns + confirms, then replaces the
same-named game (case-insensitive), collapsing any existing duplicates into one.
Bump asset cache version.
This commit is contained in:
Michael Pilosov 2026-06-25 20:54:54 +00:00
parent cf24009e31
commit 8acd9ef8d2
3 changed files with 14 additions and 4 deletions

View File

@ -422,7 +422,17 @@
const name = (prompt("Save game as:", defaultGameName()) || "").trim();
if (!name) return;
const pgn = ChessPressure.toPgn(gameData.headers, gameData.moves);
const saved = getSavedGames();
let saved = getSavedGames();
// Overwrite an existing game with the same name (case-insensitive) instead of
// creating a duplicate; also collapses any pre-existing duplicates.
const key = name.toLowerCase();
const exists = saved.some((g) => g.name.toLowerCase() === key);
if (exists) {
if (!confirm(`A game named "${name}" already exists. Overwrite it?`)) return;
saved = saved.filter((g) => g.name.toLowerCase() !== key);
}
const id = "g" + Date.now().toString(36);
saved.push({ id, name, pgn, savedAt: new Date().toISOString() });
setSavedGames(saved);

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=26">
<link rel="stylesheet" href="/style.css?v=27">
<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>
@ -139,6 +139,6 @@
<script src="/chess.min.js"></script>
<script src="/gif.js"></script>
<script src="/engine.js"></script>
<script src="/app.js?v=26"></script>
<script src="/app.js?v=27"></script>
</body>
</html>

View File

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