Skip to content

Commit

Permalink
When converting old gamefile formats to new, the winConditions are al…
Browse files Browse the repository at this point in the history
…ways specified
  • Loading branch information
Naviary2 committed Jan 18, 2025
1 parent 4f042e5 commit 19d124f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/client/scripts/esm/chess/logic/backcompatible.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ function getLongformatInNewNotation(longformat) {
// // koth: 'both'
// }
// }
const newGameRules = {};
newGameRules.turnOrder = turnOrder;
if (longformat.gameRules.slideLimit && longformat.gameRules.slideLimit !== "Infinity") newGameRules.slideLimit = longformat.gameRules.slideLimit;
const newGameRules = {
turnOrder,
winConditions: { white: ['checkmate'], black: ['checkmate'] }
};
if (longformat.gameRules.winConditions) {
const newWinConditions = { white: [], black: [] };
for (const condition in longformat.gameRules.winConditions) {
Expand All @@ -103,6 +104,7 @@ function getLongformatInNewNotation(longformat) {
// The old gamefiles did not specify promotions allowed, because it's determined by the pieces the game starts with
newGameRules.promotionsAllowed = variant.getPromotionsAllowed(longformat.startingPosition, newGameRules.promotionRanks);
}
if (longformat.gameRules.slideLimit && longformat.gameRules.slideLimit !== "Infinity") newGameRules.slideLimit = longformat.gameRules.slideLimit;
converted.gameRules = newGameRules;
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/scripts/esm/chess/logic/formatconverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ function ShortToLong_Format(shortformat/*, reconstruct_optional_move_flags = tru
// Splice the extra gamerules out of the ICN, so that its nested [ and ] don't break the metadata parser
shortformat = shortformat.substring(0, indexOfGameRulesStart) + shortformat.substring(indexOfGameRulesEnd + 1, shortformat.length);

if (!isJson(stringifiedExtraGamerules)) throw new Error("Extra optional arguments not in JSON format");
if (!isJson(stringifiedExtraGamerules)) throw new Error(`Extra optional arguments not in valid JSON format: ${stringifiedExtraGamerules}`);

const parsedGameRules = JSON.parse(stringifiedExtraGamerules);
Object.assign(longformat.gameRules, parsedGameRules); // Copy over the parsed gamerules to the longformat
Expand Down

0 comments on commit 19d124f

Please sign in to comment.