tsgammon-core
Version:
A Backgammon library for Typescript, formerly developed as a part of tsgammon-ui
47 lines (46 loc) • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.eogEventHandlersSG = exports.eogEventHandler = void 0;
const CubeGameDispatcher_1 = require("./CubeGameDispatcher");
const SingleGameDispatcher_1 = require("./SingleGameDispatcher");
const concat_1 = require("./utils/concat");
function eogEventHandler(...listeners) {
const listener = Object.assign({}, listeners.reduce((prev, cur) => concatEOGListeners(prev, cur)));
return {
onEndOfBGGame: (bgState, sgResult, eog) => {
const result = CubeGameDispatcher_1.cubeGameDispatcher.doEndOfCubeGame(bgState.cbState, sgResult, eog);
result({
onEndOfCubeGame: (nextState) => {
var _a;
(_a = listener.onEndOfBGGame) === null || _a === void 0 ? void 0 : _a.call(listener, {
cbState: nextState,
sgState: bgState.sgState,
});
},
});
},
};
function concatEOGListeners(listener1, listener2) {
return {
onEndOfBGGame: (0, concat_1.concat1)(listener1.onEndOfBGGame, listener2.onEndOfBGGame),
};
}
}
exports.eogEventHandler = eogEventHandler;
function eogEventHandlersSG(...listeners) {
const listener = Object.assign({ onEndOfGame: () => {
//
} }, listeners.reduce((prev, cur) => concatEOGListeners(prev, cur)));
return {
onEndOfGame: (sgState, sgResult, eog) => {
const result = SingleGameDispatcher_1.singleGameDispatcher.doEndOfGame(sgState, sgResult, eog);
result(listener);
},
};
function concatEOGListeners(listener1, listener2) {
return {
onEndOfGame: (0, concat_1.concat1)(listener1.onEndOfGame, listener2.onEndOfGame),
};
}
}
exports.eogEventHandlersSG = eogEventHandlersSG;