Compare commits
2 Commits
233ecb97c0
...
3974c9faab
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3974c9faab | ||
|
|
791cc35962 |
@ -347,7 +347,7 @@
|
||||
try {
|
||||
parsed = ChessPressure.parsePgn(g.pgn);
|
||||
} catch (e) {
|
||||
alert("That saved game could not be loaded (corrupted PGN).");
|
||||
modalAlert("That saved game could not be loaded (corrupted PGN).", "Couldn't load game");
|
||||
return;
|
||||
}
|
||||
applyParsed(parsed, savedId, true);
|
||||
@ -360,7 +360,7 @@
|
||||
try {
|
||||
parsed = ChessPressure.parsePgn(pgn);
|
||||
} catch (e) {
|
||||
alert("Could not parse PGN — please check the format and try again.");
|
||||
modalAlert("Could not parse PGN — please check the format and try again.", "Couldn't parse PGN");
|
||||
return;
|
||||
}
|
||||
applyParsed(parsed, null, isReference);
|
||||
@ -458,6 +458,28 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Yes/no confirmation via the in-app dialog. Resolves true (OK) / false (cancel).
|
||||
function modalConfirm(message, title) {
|
||||
const dlg = document.getElementById("confirm-dialog");
|
||||
document.getElementById("confirm-title").textContent = title || "Please confirm";
|
||||
document.getElementById("confirm-msg").textContent = message;
|
||||
dlg.querySelector("[data-cancel]").style.display = "";
|
||||
return openModal(dlg);
|
||||
}
|
||||
|
||||
// Single-button notice via the in-app dialog (replaces native alert()).
|
||||
function modalAlert(message, title) {
|
||||
const dlg = document.getElementById("confirm-dialog");
|
||||
document.getElementById("confirm-title").textContent = title || "Notice";
|
||||
document.getElementById("confirm-msg").textContent = message;
|
||||
const cancel = dlg.querySelector("[data-cancel]");
|
||||
cancel.style.display = "none";
|
||||
return openModal(dlg).then((v) => {
|
||||
cancel.style.display = "";
|
||||
return v;
|
||||
});
|
||||
}
|
||||
|
||||
async function saveCurrentGame() {
|
||||
if (!gameData) return;
|
||||
const dlg = document.getElementById("save-dialog");
|
||||
@ -502,8 +524,7 @@
|
||||
if (!currentSavedId) return;
|
||||
const g = getSavedGames().find((x) => x.id === currentSavedId);
|
||||
if (!g) return;
|
||||
document.getElementById("confirm-msg").textContent = `Delete saved game "${g.name}"?`;
|
||||
const ok = await openModal(document.getElementById("confirm-dialog"));
|
||||
const ok = await modalConfirm(`Delete saved game "${g.name}"?`, "Delete game");
|
||||
if (!ok) return;
|
||||
setSavedGames(getSavedGames().filter((x) => x.id !== currentSavedId));
|
||||
currentSavedId = null;
|
||||
@ -511,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()
|
||||
|
||||
@ -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=29">
|
||||
<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,9 +135,21 @@
|
||||
</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>Please confirm</h2>
|
||||
<h2 id="confirm-title">Please confirm</h2>
|
||||
<p id="confirm-msg" class="export-info"></p>
|
||||
<div class="dialog-buttons">
|
||||
<button type="button" data-ok>OK</button>
|
||||
@ -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=29"></script>
|
||||
<script src="/app.js?v=31"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
*
|
||||
* Bump CACHE on every deploy so clients pick up new assets.
|
||||
*/
|
||||
const CACHE = "chess-pressure-v29";
|
||||
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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user