Skip to content

Commit

Permalink
Adds an option to change the pawn promotion + adds more keyboard shor…
Browse files Browse the repository at this point in the history
…tcuts.
  • Loading branch information
LabinatorSolutions committed May 26, 2024
1 parent 4a8c445 commit 546ec66
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description" content="Expert free chess app with full opening book and analysis board powered by Stockfish 16.1. Professional GUI for all your chess needs.">
<meta name="description" content="Expert free chess app with full opening book and analysis board powered by Stockfish 16. Professional GUI for all your chess needs.">
<meta name="author" content="BoldChess.com">
<link rel="canonical" href="https://app.boldchess.com">
<link rel="preload" href="styles.css" as="style">
<link rel="stylesheet" href="styles.css">
<link rel="icon" type="image/svg+xml" sizes="96x96" href="BoldChess-Logo.svg">
<title>Expert Free Chess App | Stockfish 16.1 GUI - BoldChess.com</title>
<title>Expert Free Chess App | Stockfish 16 GUI - BoldChess.com</title>
<script>
let _mobile = false;
document.addEventListener("DOMContentLoaded", function() {
Expand Down
46 changes: 36 additions & 10 deletions public/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ function getCurFEN() {
return getElemText(document.getElementById('fen'));
}

function togglePromotionPiece() {
let promotionItem = document.querySelector(".menuItem.menuPromote span:first-child");
let currentText = promotionItem.innerText;
let newText = currentText.includes("Queen") ? "Pawn Promotion: Knight" : "Pawn Promotion: Queen";
promotionItem.innerText = newText;
localStorage.setItem('promotionPiece', newText.includes("Queen") ? 'Q' : 'N');
}

function getPromotionPiece() {
return localStorage.getItem('promotionPiece') || 'Q';
}


// Opening Book
let _open = [
["A00", "Amar/Paris Opening", "1.Nh3", 43, 0],
Expand Down Expand Up @@ -3509,7 +3522,7 @@ function doMove(pos, from, to, promotion) {
}
}
if (pos.b[from.x][from.y] == 'P' && to.y == 0) {
r.b[to.x][to.y] = promotion != null ? promotion : 'Q';
r.b[to.x][to.y] = promotion != null ? promotion : getPromotionPiece();
} else if (pos.b[from.x][from.y] == 'P' &&
pos.e != null && to.x == pos.e[0] && to.y == pos.e[1] &&
Math.abs(from.x - to.x) == 1) {
Expand Down Expand Up @@ -4347,6 +4360,12 @@ function onKeyDown(e) {
case 'R':
showBoard(false, true);
break;
case 'P':
togglePromotionPiece();
break;
case 'K':
command("keep");
break;
case 'Escape':
command("revert");
break;
Expand All @@ -4356,6 +4375,9 @@ function onKeyDown(e) {
case 'T':
command("sidetomove");
break;
case '0':
command("reset");
break;
case 'C':
showHideWindow("Chessboard");
break;
Expand Down Expand Up @@ -5304,39 +5326,43 @@ function reloadMenu() {
addMenuLine();
addMenuItemEngine("menuEngine", _play != null ? "Engine level" : "Engine depth");
addMenuLine();
addMenuItem("menuKeep", "Keep changes", null, document.getElementById("buttonRevert").className == "on", function() {
addMenuItem("menuPromote", "Pawn Promotion: Queen", "P", true, function() {
togglePromotionPiece();
});
addMenuLine();
addMenuItem("menuKeep", "Keep Changes", "K", document.getElementById("buttonRevert").className == "on", function() {
command("keep");
showHideMenu(false);
});
addMenuItem("menuRevert", "Revert changes", "ESC", document.getElementById("buttonRevert").className == "on", function() {
addMenuItem("menuRevert", "Revert Changes", "ESC", document.getElementById("buttonRevert").className == "on", function() {
command("revert");
showHideMenu(false);
});
addMenuLine();
addMenuItem("menuFlip", "Flip board", "F", true, function() {
addMenuItem("menuFlip", "Flip Board", "F", true, function() {
command("flip");
showHideMenu(false);
});
addMenuItem("menuStm", "Change side to move", "T", true, function() {
addMenuItem("menuStm", "Change Side To Move", "T", true, function() {
command("sidetomove");
showHideMenu(false);
});
addMenuLine();
addMenuItem("menuStart", "Go to game start", "Home", document.getElementById("buttonBack").className == "on", function() {
addMenuItem("menuStart", "Go To First Move", "Home", document.getElementById("buttonBack").className == "on", function() {
historyMove(-1, null, true);
showHideMenu(false);
});
addMenuItem("menuEnd", "Go to game end", "End", document.getElementById("buttonForward").className == "on", function() {
addMenuItem("menuEnd", "Go To Last Move", "End", document.getElementById("buttonForward").className == "on", function() {
historyMove(+1, null, true);
showHideMenu(false);
});
addMenuItem("menuReset", "Reset game/position", null, true, function() {
addMenuItem("menuReset", "Reset Game", "0", true, function() {
command("reset");
showHideMenu(false);
});
addMenuLine();
addMenuItemColor("menuColor", "Chessboard color");
addMenuItem("menuWindow", "Open in new window...", null, true, function() {
addMenuItemColor("menuColor", "Chessboard Theme");
addMenuItem("menuWindow", "Open Board In New Window", null, true, function() {
command("window");
showHideMenu(false);
});
Expand Down
4 changes: 4 additions & 0 deletions public/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,10 @@ li {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238e8f91' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-layers'%3E%3Cpolygon points='12 2 2 7 12 12 22 7 12 2'%3E%3C/polygon%3E%3Cpolyline points='2 17 12 22 22 17'%3E%3C/polyline%3E%3Cpolyline points='2 12 12 17 22 12'%3E%3C/polyline%3E%3C/svg%3E%0A");
}

.menuItem.menuPromote {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 320 512' fill='%238e8f91' stroke='%238e8f91' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M240 144A80 80 0 1 0 80 144a80 80 0 1 0 160 0zm16 112H235.4L254 352H221.4l-18.6-96H160 117.2L98.6 352H66l18.6-96H64c-8.8 0-16-7.2-16-16s7.2-16 16-16H81.6C60.9 203.7 48 175.3 48 144C48 82.1 98.1 32 160 32s112 50.1 112 112c0 31.3-12.9 59.7-33.6 80H256c8.8 0 16 7.2 16 16s-7.2 16-16 16zM65.8 416L33.1 468.7c-.7 1.2-1.1 2.5-1.1 3.9c0 4.1 3.3 7.4 7.4 7.4H280.6c4.1 0 7.4-3.3 7.4-7.4c0-1.4-.4-2.7-1.1-3.9L254.2 416 65.8 416zm188.4-32c11.1 0 21.4 5.7 27.2 15.1l32.7 52.7c3.9 6.2 5.9 13.4 5.9 20.8c0 21.8-17.7 39.4-39.4 39.4H39.4C17.7 512 0 494.3 0 472.6c0-7.3 2.1-14.5 5.9-20.8l32.7-52.7c5.8-9.4 16.1-15.1 27.2-15.1H254.2z'/%3E%3C/svg%3E");
}

.menuItem.menuReset {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238e8f91' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-home'%3E%3Cpath d='M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z'%3E%3C/path%3E%3Cpolyline points='9 22 9 12 15 12 15 22'%3E%3C/polyline%3E%3C/svg%3E%0A");
}
Expand Down

0 comments on commit 546ec66

Please sign in to comment.