|
@@ -54,8 +54,8 @@ const getters = {
|
|
|
isDiscardRule(state) {
|
|
|
return state.advRules.includes('discard');
|
|
|
},
|
|
|
- heroById: state => id => {
|
|
|
- return state.allHeroes.find(hero => hero.id === id);
|
|
|
+ heroesByIds: state => ids => {
|
|
|
+ return state.allHeroes.filter(hero => ids.includes(hero.id));
|
|
|
},
|
|
|
myTwelveHeroes(state, getters) {
|
|
|
let myHeroesIds = getters[getters.my('twelveHeroes')].map(hero => hero.id);
|
|
@@ -67,7 +67,7 @@ const getters = {
|
|
|
return getters[getters.my('draftIds')];
|
|
|
},
|
|
|
|
|
|
- filterHeroes: state =>
|
|
|
+ filterHeroes: (state, getters) =>
|
|
|
/**
|
|
|
* Get a filtered array of heroes
|
|
|
*
|
|
@@ -88,10 +88,10 @@ const getters = {
|
|
|
* @param {boolean} filter.byName - Activate filter on Hero's name
|
|
|
* @param {string} filter.name - Filter on Hero's name
|
|
|
* @param {number[]} filter.byId - Filter on Heroes Id(s). Do not filter in Ids if array is empty
|
|
|
- * @param state
|
|
|
+ * @param {boolean} draftMode - If true, only filter through the IDs in player/draftHeroesIds
|
|
|
* @returns {object[]} Filtered array of heroes
|
|
|
*/
|
|
|
- filter => {
|
|
|
+ (filter, draftMode = false) => {
|
|
|
if (!filter.faction) filter.faction = 'all';
|
|
|
if (!filter.popularity) filter.popularity = 'without';
|
|
|
if (!filter.minPower) filter.minPower = 0;
|
|
@@ -112,7 +112,11 @@ const getters = {
|
|
|
draftFilter = 'all';
|
|
|
break;
|
|
|
}
|
|
|
- return state.allHeroes.filter(hero => {
|
|
|
+ let heroesToFilter = state.allHeroes;
|
|
|
+ if (draftMode === true) {
|
|
|
+ heroesToFilter = getters.heroesByIds(getters.myDraftIds);
|
|
|
+ }
|
|
|
+ return heroesToFilter.filter(hero => {
|
|
|
if (filter.faction !== 'all' && hero.faction !== filter.faction)
|
|
|
return false;
|
|
|
if (
|
|
@@ -207,6 +211,8 @@ const actions = {
|
|
|
commit('INIT_GAME_STATE');
|
|
|
commit('bluePlayer/INIT_PLAYER_STATE');
|
|
|
commit('redPlayer/INIT_PLAYER_STATE');
|
|
|
+ // Also clear chosenIds array if we leave game during deck building phase
|
|
|
+ commit('CLEAR_CHOSEN_IDS', null, { root: true });
|
|
|
},
|
|
|
/**
|
|
|
* Submit chosen faction to the game master
|
|
@@ -217,6 +223,16 @@ const actions = {
|
|
|
*/
|
|
|
submitMyFaction: ({ dispatch, getters }, payload) => {
|
|
|
dispatch(getters.my('submitFaction'), payload);
|
|
|
+ },
|
|
|
+
|
|
|
+ submitMyChosenIds: ({ dispatch, getters }) => {
|
|
|
+ dispatch(getters.my('submitChosenIds'));
|
|
|
+ },
|
|
|
+ addInMyDraftIds: ({ dispatch, getters }, payload) => {
|
|
|
+ dispatch(getters.my('addInDraftIds'), payload);
|
|
|
+ },
|
|
|
+ removeInMyDraftIds: ({ dispatch, getters }, payload) => {
|
|
|
+ dispatch(getters.my('removeInDraftIds'), payload);
|
|
|
}
|
|
|
};
|
|
|
const bluePlayer = new AnyPlayer();
|