FIX #220 - Players marked as executed should have the mark follow them on player swaps and seat moves

This commit is contained in:
Alexander Fletcher 2022-05-29 21:53:55 +08:00
parent d0a117297c
commit 294ce3a388
2 changed files with 37 additions and 1 deletions

View file

@ -2,6 +2,7 @@ import Vue from "vue";
import Vuex from "vuex";
import persistence from "./persistence";
import socket from "./socket";
import subscriptions from "./subscriptions";
import players from "./modules/players";
import session from "./modules/session";
import editionJSON from "../editions.json";
@ -262,5 +263,5 @@ export default new Vuex.Store({
state.modals.edition = false;
}
},
plugins: [persistence, socket]
plugins: [persistence, socket, subscriptions]
});

View file

@ -0,0 +1,35 @@
// Subscription to handle players moving/swapping when marked for execution
module.exports = store => {
const handlePlayersMove = (mutation, state) => {
const fromPlayerIndex = mutation.payload[0];
if (fromPlayerIndex === state.session.markedPlayer) {
store.commit("session/setMarkedPlayer", mutation.payload[1]);
}
};
const handlePlayersSwap = (mutation, state) => {
const fromPlayerIndex = mutation.payload[0];
if (fromPlayerIndex === state.session.markedPlayer) {
store.commit("session/setMarkedPlayer", mutation.payload[1]);
return;
}
const toPlayerIndex = mutation.payload[1];
if (toPlayerIndex === state.session.markedPlayer) {
store.commit("session/setMarkedPlayer", mutation.payload[0]);
return;
}
};
store.subscribe((mutation, state) => {
switch (mutation.type) {
case "players/move":
handlePlayersMove(mutation, state);
break;
case "players/swap":
handlePlayersSwap(mutation, state);
break;
}
});
};