From 71234f3ef90793a743213f856e72abab89b1ce2a Mon Sep 17 00:00:00 2001 From: Steffen Date: Thu, 6 May 2021 21:48:41 +0200 Subject: [PATCH] fix players being moved or removed during a nomination (closes #164) add vue linter --- .github/workflows/linter.yml | 44 ++++------------------------- CHANGELOG.md | 3 ++ package.json | 2 +- src/components/TownSquare.vue | 52 ++++++++++++++++++++++++++++++++++- src/components/Vote.vue | 2 +- src/store/modules/session.js | 1 + src/store/socket.js | 7 +++-- 7 files changed, 68 insertions(+), 43 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 26becfe..5efc82f 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,53 +1,21 @@ ---- -########################### -########################### -## Linter GitHub Actions ## -########################### -########################### name: Lint Code Base -# -# Documentation: -# https://help.github.com/en/articles/workflow-syntax-for-github-actions -# - -############################# -# Start the job on all push # -############################# on: push: branches-ignore: - 'gh-pages' pull_request: - # The branches below must be a subset of the branches above branches: [ main ] -############### -# Set the Job # -############### jobs: build: - # Name the Job name: Lint Code Base - # Set the agent to run on runs-on: ubuntu-latest - - ################## - # Load all steps # - ################## steps: - ########################## - # Checkout the code base # - ########################## - - name: Checkout Code - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '14' + - run: npm install + - run: npm run lint - ################################ - # Run Linter against code base # - ################################ - - name: Lint Code Base - uses: docker://github/super-linter:v2.2.0 - env: - VALIDATE_ALL_CODEBASE: false - VALIDATE_ANSIBLE: false - DEFAULT_BRANCH: "main" diff --git a/CHANGELOG.md b/CHANGELOG.md index 70a04bd..b4aadfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Release Notes +- fix players being moved or removed during nomination +- add vue linter + ### Version 2.12.0 - tweak reference sheet to better fit screen in single column layout - add warning icon overlay for setup roles on character assignment modal diff --git a/package.json b/package.json index 9e2878c..40c89d1 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build ./src/main.js", - "lint": "vue-cli-service lint" + "lint": "vue-cli-service lint --no-fix" }, "main": "App.vue", "dependencies": { diff --git a/src/components/TownSquare.vue b/src/components/TownSquare.vue index 729a813..4c34249 100644 --- a/src/components/TownSquare.vue +++ b/src/components/TownSquare.vue @@ -152,20 +152,52 @@ export default { this.$store.commit("toggleModal", "role"); }, removePlayer(playerIndex) { - if (this.session.isSpectator) return; + if (this.session.isSpectator || this.session.lockedVote) return; if ( confirm( `Do you really want to remove ${this.players[playerIndex].name}?` ) ) { + const { nomination } = this.session; + if (nomination) { + if (nomination.includes(playerIndex)) { + // abort vote if removed player is either nominator or nominee + this.$store.commit("session/nomination"); + } else if ( + nomination[0] > playerIndex || + nomination[1] > playerIndex + ) { + // update nomination array if removed player has lower index + this.$store.commit("session/setNomination", [ + nomination[0] > playerIndex ? nomination[0] - 1 : nomination[0], + nomination[1] > playerIndex ? nomination[1] - 1 : nomination[1] + ]); + } + } this.$store.commit("players/remove", playerIndex); } }, swapPlayer(from, to) { + if (this.session.isSpectator || this.session.lockedVote) return; if (to === undefined) { this.cancel(); this.swap = from; } else { + if (this.session.nomination) { + // update nomination if one of the involved players is swapped + const swapTo = this.players.indexOf(to); + const updatedNomination = this.session.nomination.map(nom => { + if (nom === this.swap) return swapTo; + if (nom === swapTo) return this.swap; + return nom; + }); + if ( + this.session.nomination[0] !== updatedNomination[0] || + this.session.nomination[1] !== updatedNomination[1] + ) { + this.$store.commit("session/setNomination", updatedNomination); + } + } this.$store.commit("players/swap", [ this.swap, this.players.indexOf(to) @@ -174,10 +206,27 @@ export default { } }, movePlayer(from, to) { + if (this.session.isSpectator || this.session.lockedVote) return; if (to === undefined) { this.cancel(); this.move = from; } else { + if (this.session.nomination) { + // update nomination if it is affected by the move + const moveTo = this.players.indexOf(to); + const updatedNomination = this.session.nomination.map(nom => { + if (nom === this.move) return moveTo; + if (nom > this.move && nom <= moveTo) return nom - 1; + if (nom < this.move && nom >= moveTo) return nom + 1; + return nom; + }); + if ( + this.session.nomination[0] !== updatedNomination[0] || + this.session.nomination[1] !== updatedNomination[1] + ) { + this.$store.commit("session/setNomination", updatedNomination); + } + } this.$store.commit("players/move", [ this.move, this.players.indexOf(to) @@ -186,6 +235,7 @@ export default { } }, nominatePlayer(from, to) { + if (this.session.isSpectator || this.session.lockedVote) return; if (to === undefined) { this.cancel(); if (from !== this.nominate) { diff --git a/src/components/Vote.vue b/src/components/Vote.vue index 4bdd242..7d50303 100644 --- a/src/components/Vote.vue +++ b/src/components/Vote.vue @@ -122,7 +122,7 @@ export default { const nomination = this.session.nomination[0]; return { transform: `rotate(${Math.round((nomination / players) * 360)}deg)`, - transitionDuration: this.session.votingSpeed - 0.1 + "s" + transitionDuration: this.session.votingSpeed - 100 + "ms" }; }, nominee: function() { diff --git a/src/store/modules/session.js b/src/store/modules/session.js index 80d4aaf..c9df830 100644 --- a/src/store/modules/session.js +++ b/src/store/modules/session.js @@ -45,6 +45,7 @@ const mutations = { setPing: set("ping"), setVotingSpeed: set("votingSpeed"), setVoteInProgress: set("isVoteInProgress"), + setNomination: set("nomination"), claimSeat: set("claimedSeat"), distributeRoles: set("isRolesDistributed"), setSessionId(state, sessionId) { diff --git a/src/store/socket.js b/src/store/socket.js index e193a08..bcfad1c 100644 --- a/src/store/socket.js +++ b/src/store/socket.js @@ -656,10 +656,12 @@ class LiveSession { /** * A player nomination. ST only * This also syncs the voting speed to the players. - * @param nomination [nominator, nominee] + * Payload can be an object with {nomination} property or just the nomination itself, or undefined. + * @param payload [nominator, nominee]|{nomination} */ - nomination({ nomination } = {}) { + nomination(payload) { if (this._isSpectator) return; + const nomination = payload ? payload.nomination || payload : payload; const players = this._store.state.players.players; if ( !nomination || @@ -823,6 +825,7 @@ export default store => { } break; case "session/nomination": + case "session/setNomination": session.nomination(payload); break; case "session/setVoteInProgress":