Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"core-js": "^3.6.4",
"easytimer.js": "^2.2.3",
"loglevel": "^1.6.8",
"vue": "^2.6.11",
"vue-router": "^3.1.6",
"vuex": "^3.1.3"
Expand Down
18 changes: 18 additions & 0 deletions src/store/actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { bus } from '@/components/shared/Bus'
import router from '@/router'

// loging framework
const log = require('loglevel');

/**
* All actions that are taken involving the vuex state.
* These actions should be used when combining multiple mutations or
Expand Down Expand Up @@ -62,13 +65,16 @@ export default {

let draw = true
if (payload.playType === "DISCARD") {
log.warn({DiscardBy:payload.player.name, card:payload.card.type, value: payload.card.value})
context.commit('discardCard', payload)
} else if (payload.playType === "REDRAW") {
log.warn({RedrawBy:payload.player.name})
context.commit('giveNewHand', payload)
draw = false
} else if (payload.card.isMimic) {
context.dispatch('playMimic', payload)
} else {
log.warn({Player:payload.player.name, card_played:payload.card.type, value: payload.card.value})
context.dispatch(payload.playType, payload)
}

Expand All @@ -93,6 +99,10 @@ export default {
let scores = context.getters.getPlayerScores()
for (let scoreInfo of scores) {
if (scoreInfo.score >= context.state.scoreLimit) {
//Winner Info added on log
let winner = context.state.players.find (p => p.id === scoreInfo.playerId)
log.warn({Winner:winner.name, WinnerScores:scoreInfo.score})

bus.$emit('game-over')
context.commit('changeGameState', {newState: 'winner'})
return
Expand Down Expand Up @@ -129,6 +139,7 @@ export default {
* Payload same as executeTurn.
*/
playCardOnStack (context, payload) {
log.warn(payload.player.name, payload.card.type, payload.card.value, payload.target.getScore())
context.commit('removeFromHand', payload)
context.commit('addToStack', payload)
},
Expand All @@ -147,6 +158,7 @@ export default {
* Payload same as executeTurn.
*/
playSpecialCard (context, payload) {
log.warn(payload.player.name, payload.card.type)
context.commit('addCardEffect', payload)
context.commit('discardCard', payload)
},
Expand All @@ -157,9 +169,15 @@ export default {
* Payload same as executeTurn.
*/
groupStacks (context, payload) {
let stackValue= []
for (let stack of payload.target.values()) {
stackValue.push(stack.getScore())
}

context.commit('removeStacks', {stacks: payload.target})
context.commit('newStack', payload)
context.commit('removeFromHand', payload)
log.warn(payload.player.name, payload.card.type, payload.card.value, stackValue)
},

/**
Expand Down
44 changes: 34 additions & 10 deletions tests/unit/actions.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import actions from '@/store/actions.js'

jest.mock('loglevel')

function mockValue (value) { return jest.fn(() => {return value}) }


Expand Down Expand Up @@ -41,6 +43,8 @@ describe('vuex actions', () => {
test('play type is DISCARD', () => {
let payload = {
playType: 'DISCARD',
player: {name: 'jeff'},
card: {type: 'GROUP', value: 4}
}
context.state = {gameState: 'game', turnPlays: []}

Expand Down Expand Up @@ -70,6 +74,8 @@ describe('vuex actions', () => {
// will not test all the intermediate steps already tested above
let payload = {
playType: 'REDRAW',
player: {name: 'jeff'},
card: {type: 'GROUP', value: 4}
}
context.state = {gameState: 'game', turnPlays: []}

Expand Down Expand Up @@ -98,7 +104,8 @@ describe('vuex actions', () => {
// will not test all the intermediate steps already tested above
let payload = {
playType: 'playCardOnStack',
card: {isMimic: false}
player: {name: 'jeff'},
card: {type: 'GROUP', value: 4, isMimic: false}
}
context.state = {gameState: 'game', turnPlays: []}

Expand Down Expand Up @@ -148,12 +155,13 @@ describe('vuex actions', () => {
})
test('game is over', () => {
context.getters = {
getPlayerScores: mockValue([ {score: 60}, {score: 80} ])
getPlayerScores: mockValue([ {playerId: 0, score: 60}, {playerId: 1, score: 80} ])
}
context.state = {
scoreLimit: 75,
activeCard: 'card',
activePlayer: {isAi: true}
activePlayer: {isAi: true},
players: [{id: 0}, {id: 1, name: 'jeff'}]
}
actions.endTurn(context)
expect(context.getters.getPlayerScores.mock.calls.length).toEqual(1)
Expand Down Expand Up @@ -184,10 +192,15 @@ describe('vuex actions', () => {
// does not check bus.$emit
})
test('playCardOnStack', () => {
actions.playCardOnStack(context, 'payload')
let payload = {
player: {name: 'jeff'},
card: {type: 'REPEAT', value: 3},
target: {getScore: mockValue(10)}
}
actions.playCardOnStack(context, payload)
expect(context.commit.mock.calls.length).toEqual(2)
expect(context.commit.mock.calls[0]).toEqual([ 'removeFromHand', 'payload' ])
expect(context.commit.mock.calls[1]).toEqual([ 'addToStack', 'payload' ])
expect(context.commit.mock.calls[0]).toEqual([ 'removeFromHand', payload ])
expect(context.commit.mock.calls[1]).toEqual([ 'addToStack', payload ])
})
test('startNewStack', () => {
actions.startNewStack(context, 'payload')
Expand All @@ -196,13 +209,24 @@ describe('vuex actions', () => {
expect(context.commit.mock.calls[1]).toEqual([ 'newStack', 'payload' ])
})
test('playSpecialCard', () => {
actions.playSpecialCard(context, 'payload')
let payload = {
player: {name: 'jeff'},
card: {type: 'RANSOM'},
target: {name: 'phil'}
}
actions.playSpecialCard(context, payload)
expect(context.commit.mock.calls.length).toEqual(2)
expect(context.commit.mock.calls[0]).toEqual([ 'addCardEffect', 'payload' ])
expect(context.commit.mock.calls[1]).toEqual([ 'discardCard', 'payload' ])
expect(context.commit.mock.calls[0]).toEqual([ 'addCardEffect', payload ])
expect(context.commit.mock.calls[1]).toEqual([ 'discardCard', payload ])
})
test('groupStacks', () => {
let payload = {target: 'stacks'}
let payload = {
target: new Set([
{getScore: mockValue(2)}, {getScore: mockValue(2)}
]),
card: {type: 'GROUP', value: 4},
player: {name: 'jeff'},
}
actions.groupStacks(context, payload)
expect(context.commit.mock.calls.length).toEqual(3)
expect(context.commit.mock.calls[0]).toEqual([ 'removeStacks', {stacks: payload.target} ])
Expand Down