Skip to content

Instantly share code, notes, and snippets.

@Dorus
Created February 15, 2020 14:14
Show Gist options
  • Save Dorus/024db1c070ec5fb139b65445179d7110 to your computer and use it in GitHub Desktop.
Save Dorus/024db1c070ec5fb139b65445179d7110 to your computer and use it in GitHub Desktop.
// config.js
export.ranked = getConfigObject(true);
export.unranked = getConfigObject(false);
function getConfigObject(isRanked) {
return {
boardsize: checkBoardSetting(getRuSetting(arv["boardsize"], isRanked)
komi: checkSetting(getRuSetting(arv["komi"], isRanked)
}
}
checkSetting(config) {
return (notification) => {
config.split(",").some((e) => {
let [min, max] = e/splt(":");
if (max === undefined) return notification === min
return min <= notification && notification <= max;
})
}
}
checkBoardSetting(config) {
return (notificationW, notificationH) => {
config.split(",").some((e) => {
let [w, h] = e.split("x");
return checkBoardSettingX(w, notificationW) && checkBoardSettingX(h, notificationH);
})
}
}
checkBoardSettingX(config, notification) {
let [min, max] = config.split(":");
if (max === undefined) return notification === min
return min <= notification && notification <= max;
}
getRuSetting(settingRu, isRanked) {
let [ranked, unarnked] = settingRu.split('/');
if (ranked === "...") { ranked = unranked }
if (unarnked === "...") {unranked = ranked }
return isRanked ? ranked : unranked
}
// notification.js:
newGame(notification, notification.ranked ? config.ranked : config.unranked)
function newGame(notification, config) {
if (config.boardsize(notification.width, notification.height)) throw 'invalid boardsize'
if (config.komi(notification.komi)) throw 'invalid komi'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment