Skip to content

Commit

Permalink
Merge branch 'pr/1705' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Laské committed Jan 25, 2025
2 parents 9b55671 + f9a5f07 commit 2adf51c
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- No Move Hint for "En passant" in Chess Activity #1707
- Info Update : Planet Activity #1709
- Minute numbers still visible in clock activity even after switching to Nice Clock #1713
- Default Promotion to Queen in Chess Activity #1704

## [1.8.0] - 2024-04-10
### Added
Expand Down
61 changes: 60 additions & 1 deletion activities/Chess.activity/css/activity.css
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,63 @@ body {
-webkit-box-shadow: 0 0 0 0rem rgba(158, 158, 158, .5);
box-shadow: 0 0 0 0rem rgba(158, 158, 158, .5);
border: 0px;
}
}

.promotion-dialog {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}

.promotion-content {
background: white;
border-radius: 8px;
text-align: center;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
min-width: 300px;
}

.dialog-header {
background:#9e9e9e;
padding: 10px 15px;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #ddd;
border-radius: 8px 8px 0 0;
}

.dialog-header h3 {
margin: 0;
font-size: 16px;
color: #ffffff;
font-weight: 500;
font-family: "Helvetica Neue", Inter, ui-sans-serif, "Apple Color Emoji", Helvetica, Arial, sans-serif;
}

.promotion-pieces {
display: flex;
justify-content: center;
gap: 20px;
margin: 15px;
padding: 10px;
}

.piece {
font-size: 96px;
cursor: pointer;
padding: 10px;
border-radius: 4px;
transition: background-color 0.2s;
}

.piece:hover {
background: #eee;
}
123 changes: 120 additions & 3 deletions activities/Chess.activity/js/chessGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ var ChessGame = {
<div id="chess-panel" class="panel">
<div v-if="showPromotionDialog" class="promotion-dialog">
<div class="promotion-content">
<div class="dialog-header">
<h3>{{ l10n.stringPromotionTitle }}</h3>
</div>
<div class="promotion-pieces">
<div v-if="playercolor === 0 " class="piece" @click="handlePromotion('Q')"><img src="./img/chesspieces/wikipedia/wQ.png" alt="Queen"></div>
<div v-if="playercolor === 0" class="piece" @click="handlePromotion('R')"><img src="./img/chesspieces/wikipedia/wR.png" alt="Rook"></div>
<div v-if="playercolor === 0" class="piece" @click="handlePromotion('B')"><img src="./img/chesspieces/wikipedia/wB.png" alt="Bishop"></div>
<div v-if="playercolor === 0" class="piece" @click="handlePromotion('N')"><img src="./img/chesspieces/wikipedia/wN.png" alt="Knight"></div>
<div v-if="playercolor === 1" class="piece" @click="handlePromotion('Q')"><img src="./img/chesspieces/wikipedia/bQ.png" alt="Queen"></div>
<div v-if="playercolor === 1" class="piece" @click="handlePromotion('R')"><img src="./img/chesspieces/wikipedia/bR.png" alt="Rook"></div>
<div v-if="playercolor === 1" class="piece" @click="handlePromotion('B')"><img src="./img/chesspieces/wikipedia/bB.png" alt="Bishop"></div>
<div v-if="playercolor === 1" class="piece" @click="handlePromotion('N')"><img src="./img/chesspieces/wikipedia/bN.png" alt="Knight"></div>
</div>
</div>
</div>
<div id="info-container">
<div id="opponent-clock">
<div class="usrlogo">
Expand Down Expand Up @@ -94,13 +112,21 @@ var ChessGame = {
clockTime: 30,
opponentClockTime: 30,
clockTotalTime: 30,
showPromotionDialog: false,
pendingMove: {
source: null,
target: null,
piece: null,
turn: null,
},
l10n: {
stringYouWon: '',
stringYouCheck: '',
stringYouLost: '',
stringMatchDraw: '',
stringVs: '',
stringTimeExpired: '',
stringPromotionTitle: '',
}
}
},
Expand Down Expand Up @@ -445,7 +471,22 @@ var ChessGame = {
var turn = this.playercolor ? this.state.moveno % 2 != 0 : this.state.moveno % 2 == 0;
if (!this.opponentuser || (this.opponentuser && turn)) {
this.removeGreySquares();

const piece = this.board.position()[source];
const isWhitePawn = piece === 'wP';
const isBlackPawn = piece === 'bP';
const isLastRank = target[1] === '8';
const isFirstRank = target[1] === '1';

if ((isWhitePawn && isLastRank) || (isBlackPawn && isFirstRank)) {
this.pendingMove = {
source: source,
target: target,
piece: piece,
turn: turn
};
this.showPromotionDialog = true;
return; // Wait for promotion choice
}
var move = this.state.move(source, target);

// illegal move
Expand Down Expand Up @@ -718,8 +759,84 @@ var ChessGame = {
}
this.opponentClockTime = this.clockTotalTime;

}

},
handlePromotion: function(pieceType) {
if (!this.pendingMove.source || !this.pendingMove.target) {
this.showPromotionDialog = false;
return;
}

this.showPromotionDialog = false;
const { source, target } = this.pendingMove;

var move = this.state.move(source, target, P4_PIECE_LUT[pieceType]);

// illegal move
if (move.flags === 0) {
this.board.position(p4_state2fen(this.state, true));
return;
}

if (move.flags === 7 || move.flags === 15 || move.flags === 23 || move.flags === 39) {
this.game_won = true;
this.board.position(p4_state2fen(this.state, true));
return;
} else if (!(move.flags & 1<<1) && (((move.flags & 1<<0) && move.flags & 1<<2) || move.flags & (1<<6))) {
this.game_draw = true;
this.board.position(p4_state2fen(this.state, true));
return;
} else {
this.game_check = false;
}

if (move.flags & (1 << 1) && !(move.flags & (1 << 2))) {
this.other_check = true;
} else {
this.other_check = false;
}

this.board.position(p4_state2fen(this.state, true));

if (this.opponentuser) {
if (this.ishost) {
this.stopClock = true;
this.stopOpponentClock = false;
}
} else {
this.stopClock = true;
this.stopOpponentClock = false;
}

$('#player-clock').css('border-style', 'none');
$('#opponent-clock').css('border-style', 'solid');

if (this.opponentuser) {
this.$emit('sendmove', {
data: {
chessColor: this.playercolor,
state: this.state,
game_won: this.game_lost,
game_lost: this.game_won,
game_draw: this.game_draw,
game_check: this.other_check,
}
});
}

this.updateMoves();

// Reset pending move
this.pendingMove = {
source: null,
target: null,
piece: null,
turn: null
};

if (!this.opponentuser) {
window.setTimeout(this.makeRandomMove, 250);
}
},
}

}
1 change: 1 addition & 0 deletions activities/Chess.activity/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"PrevShort": "Prev",
"NextShort": "Next",
"EndShort": "End",
"PromotionTitle":"Choose Promotion Piece",
"TutoWelcomeTitle": "Chess Activity",
"TutoWelcomeContent": "Chess activity is a fun way to learn and challenge your friends to a game of Chess.",
"TutoBoardTitle": "Chess Board",
Expand Down
1 change: 1 addition & 0 deletions activities/Chess.activity/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"PrevShort": "Ant",
"NextShort": "Sig",
"EndShort": "Fin",
"PromotionTitle":"Elegir pieza de promoción",
"TutoWelcomeTitle": "Actividad \"Ajedrez\"",
"TutoWelcomeContent": "La actividad \"Ajedrez\" es una manera divertida de aprender a jugar y retar a tus amigos a una partida de ajedrez.",
"TutoBoardTitle": "Tablero de ajedrez",
Expand Down
1 change: 1 addition & 0 deletions activities/Chess.activity/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"PrevShort": "Préc",
"NextShort": "Suiv",
"EndShort": "Fin",
"PromotionTitle":"Choix de la promotion",
"TutoWelcomeTitle": "Activité Chess",
"TutoWelcomeContent": "L'activité Chess vous permet d'apprendre ou défier vos amis au célèbre jeu d'échecs",
"TutoBoardTitle": "Plateau de jeu",
Expand Down

0 comments on commit 2adf51c

Please sign in to comment.