Skip to content

Commit

Permalink
fixed queue set state crashing game
Browse files Browse the repository at this point in the history
  • Loading branch information
Idonotus committed Dec 25, 2024
1 parent ab67c21 commit a72f35e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/client/scripts/esm/chess/logic/movepiece.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ function makeMove(gamefile, move) {
* @param {Move} move
*/
function deleteEnpassantAndSpecialRightsProperties(gamefile, move) {
state.queueSetState(move.changes, "enpassant", gamefile.enpassant, undefined);
state.queueSetState(gamefile, move.changes, "enpassant", undefined);
let key = coordutil.getKeyFromCoords(move.startCoords);
state.queueSetState(move.changes, `specialRights.${key}`, gamefile.specialRights[key], undefined);
state.queueSetState(gamefile, move.changes, `specialRights.${key}`, undefined);
key = coordutil.getKeyFromCoords(move.endCoords);
state.queueSetState(move.changes, `specialRights.${key}`, gamefile.specialRights[key], undefined); // We also delete the captured pieces specialRights for ANY move.
state.queueSetState(gamefile, move.changes, `specialRights.${key}`, undefined); // We also delete the captured pieces specialRights for ANY move.
}

/**
Expand Down Expand Up @@ -145,7 +145,7 @@ function incrementMoveRule(gamefile, move, wasACapture) {

// Reset if it was a capture or pawn movement
const newMoveRule = (wasACapture || move.type.startsWith('pawns')) ? 0 : gamefile.moveRuleState + 1;
state.queueSetState(move.changes, 'moveRuleState', gamefile.moveRuleState, newMoveRule, {global: true});
state.queueSetState(gamefile, move.changes, 'moveRuleState', newMoveRule, {global: true});
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/client/scripts/esm/chess/logic/specialmove.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function kings(gamefile, piece, move) {
const landSquare = [move.endCoords[0] - specialTag.dir, move.endCoords[1]];
// Delete the rook's special move rights
const key = coordutil.getKeyFromCoords(pieceToCastleWith.coords);
state.queueSetState(moveChanges, `specialRights.${key}`, gamefile.specialRights[key], undefined);
state.queueSetState(gamefile, moveChanges, `specialRights.${key}`, undefined);

boardchanges.queueMovePiece(moveChanges, pieceToCastleWith, landSquare); // Make normal move

Expand All @@ -66,7 +66,7 @@ function pawns(gamefile, piece, move, { updateProperties = true } = {}) {

// If it was a double push, then add the enpassant flag to the gamefile, and remove its special right!
if (updateProperties && isPawnMoveADoublePush(piece.coords, move.endCoords)) {
state.queueSetState(moveChanges, "enpassant", gamefile.undefined, getEnPassantSquare(piece.coords, move.endCoords));
state.queueSetState(gamefile, moveChanges, "enpassant", getEnPassantSquare(piece.coords, move.endCoords));
}

const enpassantTag = move.enpassant; // -1/1
Expand Down

0 comments on commit a72f35e

Please sign in to comment.