diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bde787..db32eb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ A preview of major changes can be found in the Wiki ([Latest Changes](https://gi - New set of larger Compact buttons - Ability to configure: "Announcement Volume", "Auto Busting" and "Auto Leg Finish" from frontend - Holding score buttons to score same dart three times +- Support `Max Rounds` to play for `x01` - Lots of new Badges #### Changed diff --git a/routes/index.js b/routes/index.js index 6c7f674..21dd2fe 100644 --- a/routes/index.js +++ b/routes/index.js @@ -31,7 +31,8 @@ router.get('/', function (req, res, next) { outshots: outshots.data, lives: [{ id: 1, name: 1 }, { id: 3, name: 3 }, { id: 5, name: 5 }, { id: 7, name: 7 }, { id: 10, name: 10 }], points_to_win: [{ id: 1, name: 1 }, { id: 2, name: 2 }, { id: 3, name: 3 }, { id: 4, name: 4 }, { id: 5, name: 5 }], - max_rounds: [{ id: -1, name: 'Unlimited' }, { id: 3, name: 3 }, { id: 5, name: 5 }, { id: 7, name: 7 }, { id: 10, name: 10 }, { id: 15, name: 15 }], + max_rounds_170: [{ id: -1, name: '-' }, { id: 3, name: 3 }, { id: 5, name: 5 }, { id: 7, name: 7 }, { id: 10, name: 10 }, { id: 15, name: 15 }], + max_rounds_x01: [{ id: -1, name: '-' }, { id: 10, name: 10 }, { id: 12, name: 12 }, { id: 16, name: 16 }, { id: 20, name: 20 }, { id: 30, name: 30 }], venues: venues.data, stakes: oweTypes.data, offices: offices.data, diff --git a/routes/legs.js b/routes/legs.js index 668bc83..b369327 100644 --- a/routes/legs.js +++ b/routes/legs.js @@ -173,6 +173,60 @@ router.put('/:id/order', function (req, res, next) { }); }); +/** Method to finish a leg */ +router.put('/:id/finish', function (req, res, next) { + let legId = req.params.id; + axios.put(`${req.app.locals.kcapp.api}/leg/${legId}/finish`, req.body) + .then(response => { + axios.all([ + axios.get(`${req.app.locals.kcapp.api}/leg/${legId}`), + axios.get(`${req.app.locals.kcapp.api}/leg/${legId}/players`), + axios.get(`${req.app.locals.kcapp.api}/statistics/global/fnc`) + ]).then(axios.spread((legData, playersData, globalData) => { + const leg = legData.data; + const players = playersData.data; + const currentPlayer = _.findWhere(players, { is_current_player: true }); + const globalstat = globalData.data[0]; + + axios.get(`${req.app.locals.kcapp.api}/match/${leg.match_id}`) + .then((response) => { + const match = response.data; + + const winnerPlayer = _.findWhere(players, { player_id: leg.winner_player_id }); + //announceLegFinished(winnerPlayer, match) + + if (!match.is_finished) { + this.socketHandler.setupLegsNamespace(match.current_leg_id); + + // Forward all spectating clients to next leg + this.socketHandler.emitMessage(`/legs/${legId}`, 'new_leg', { match: match, leg: leg }); + } + this.socketHandler.emitMessage(`/active`, 'leg_finished', { match: match, leg: leg }); + this.socketHandler.emitMessage(`/legs/${legId}`, 'score_update', { leg: leg, players: players, match: match }); + this.socketHandler.emitMessage(`/legs/${legId}`,'leg_finished', { leg: leg, match: match }); + + setTimeout(() => { + // Remove the namespace in a bit, once announcements are finished + this.socketHandler.removeNamespace(legId); + }, 15000); + res.status(200).send({ leg_id: match.current_leg_id, match: match }).end(); + }).catch(error => { + const message = `${error.message}(${error})`; + debug(`[${legId}] Error when getting match: ${message}`); + next(error); + }); + })).catch(error => { + const message = `${error.message} (${error})`; + debug(`[${legId}] Error when getting leg: ${message}`); + next(error); + }); + }).catch(error => { + debug(`[${legId}] Unable to finish leg: ${error}`); + next(error); + }); +}); + + /** Method to undo leg finish */ router.put('/:id/undo', function (req, res, next) { axios.put(`${req.app.locals.kcapp.api}/leg/${req.params.id}/undo`) diff --git a/src/components/scorecard/components/x01.js b/src/components/scorecard/components/x01.js index 99d9b4f..8af3715 100644 --- a/src/components/scorecard/components/x01.js +++ b/src/components/scorecard/components/x01.js @@ -32,6 +32,15 @@ exports.isBust = (player, dart, totalScore, leg) => { return currentScore < 2; } +exports.isMaxRound = (player, dartsThrown, leg, players) => { + if (player.player_id === players[players.length - 1].player_id && + dartsThrown > 3 && + leg.parameters.max_rounds && leg.parameters.max_rounds === leg.round) { + return true; + } + return false; +} + exports.isCheckout = (player, dart, totalScore, leg) => { let currentScore = player.current_score - dart.getValue(); if (player.player.options && !player.player.options.subtract_per_dart) { @@ -65,6 +74,7 @@ exports.confirmThrow = function (external) { const isCheckout = module.exports.isCheckout(this.state.player, dart, this.state.totalScore, this.state.leg); const isBust = module.exports.isBust(this.state.player, dart, this.state.totalScore, this.state.leg); + const isMaxRound = module.exports.isMaxRound(this.state.player, this.state.currentDart, this.state.leg, this.input.players); if (isCheckout) { submitting = true; } @@ -89,6 +99,11 @@ exports.confirmThrow = function (external) { this.emit('player-busted', true); } } + else if (isMaxRound) { + alertify.notify(`Maximum numbers of rounds reached.`, 'warning'); + this.emit('max-rounds-reached', true); + } + if (!this.state.player.player.options || this.state.player.player.options.subtract_per_dart) { this.state.player.current_score -= scored; } @@ -98,4 +113,3 @@ exports.confirmThrow = function (external) { } return submitting; } - diff --git a/src/pages/index/components/new-game-form/new-game-form.component.js b/src/pages/index/components/new-game-form/new-game-form.component.js index 0778b2e..5f07e8d 100644 --- a/src/pages/index/components/new-game-form/new-game-form.component.js +++ b/src/pages/index/components/new-game-form/new-game-form.component.js @@ -22,6 +22,7 @@ module.exports = { stake: null, venue_id: null }, + maxRounds: input.max_rounds_x01, playerId: "", socket: {}, demo_mode: false, @@ -104,7 +105,7 @@ module.exports = { for (const file of data.audios) { audioPlayers.push(new Audio(file.file)); } - + for (let i = 0; i < audioPlayers.length; i++) { const current = audioPlayers[i]; const next = audioPlayers[i + 1]; @@ -314,6 +315,13 @@ module.exports = { } this.state.options.starting_score = scoreComponent.state.index + + if (this.state.options.game_type === types.X01) { + this.state.maxRounds = this.input.max_rounds_x01; + } else if (this.state.options.game_type === types.ONESEVENTY) { + this.state.maxRounds = this.input.max_rounds_170; + } + let selectedPlayers = this.getComponents('players'); for (let i = 0; i < selectedPlayers.length; i++) { selectedPlayers[i].handleTypeChange(this.state.options.game_type); diff --git a/src/pages/index/components/new-game-form/new-game-form.marko b/src/pages/index/components/new-game-form/new-game-form.marko index b58a2db..b45f51e 100644 --- a/src/pages/index/components/new-game-form/new-game-form.marko +++ b/src/pages/index/components/new-game-form/new-game-form.marko @@ -64,7 +64,11 @@ $ const types = require('../../../../components/scorecard/components/match_types