@gamepark/rules-api
Version:
API to implement the rules of a board game
38 lines • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMoveView = exports.getGameView = exports.hasSecretInformation = exports.hasIncompleteInformation = void 0;
function hasIncompleteInformation(rules) {
var test = rules;
return typeof test.getView === 'function' && typeof test.getMoveView === 'function';
}
exports.hasIncompleteInformation = hasIncompleteInformation;
function hasSecretInformation(rules) {
var test = rules;
return typeof test.getPlayerView === 'function';
}
exports.hasSecretInformation = hasSecretInformation;
function getGameView(rules, playerId) {
if (hasSecretInformation(rules) && playerId !== undefined) {
return rules.getPlayerView(playerId);
}
else if (hasIncompleteInformation(rules)) {
return rules.getView();
}
else {
return rules.game;
}
}
exports.getGameView = getGameView;
function getMoveView(rules, move, playerId) {
if (hasSecretInformation(rules) && rules.getPlayerMoveView && playerId !== undefined) {
return JSON.parse(JSON.stringify(rules.getPlayerMoveView(move, playerId)));
}
else if (hasIncompleteInformation(rules)) {
return JSON.parse(JSON.stringify(rules.getMoveView(move)));
}
else {
return move;
}
}
exports.getMoveView = getMoveView;
//# sourceMappingURL=IncompleteInformation.js.map