Skip to content

Commit

Permalink
store: only add points to list if not already received
Browse files Browse the repository at this point in the history
Otherwise it can happen that points are counted multiple times,
especially when switching between views
  • Loading branch information
TarikViehmann committed Jan 27, 2024
1 parent 15bdbfe commit 734d462
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/store/gameStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,25 @@ export const useGameStore = defineStore('gameStore', () => {

// -> add a reward
function addReward(rewardArg: Reward) {
if (rewardArg.points > 0 && teamNameByColor.value(rewardArg.team) != '') {
const rewardExists = rewards.value.some(reward => {
return (
reward.game_time === rewardArg.game_time &&
reward.phase === rewardArg.phase &&
reward.points === rewardArg.points &&
reward.reason === rewardArg.reason &&
reward.team === rewardArg.team
);
});

// If the reward doesn't already exist, add it to the rewards array and log the event
if (!rewardExists && rewardArg.points > 0 && teamNameByColor.value(rewardArg.team) !== '') {
eventStore.addEvent({
icon: 'fa-trophy',
msg: `${teamNameByColor.value(rewardArg.team)} received ${
rewardArg.points
} points`,
msg: `${teamNameByColor.value(rewardArg.team)} received ${rewardArg.points} points`,
team: rewardArg.team,
})
});
rewards.value.push(rewardArg);
}
rewards.value.push(rewardArg)
}

// -> send a websocket message to ...
Expand Down

0 comments on commit 734d462

Please sign in to comment.