Add vuex actions/mutations for draft
Some checks reported errors
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build was killed

This commit is contained in:
Hamcha 2019-09-17 15:17:58 +02:00
parent d230808af8
commit 6648182f18
Signed by: hamcha
GPG key ID: 44AD3571EB09A39E
7 changed files with 91 additions and 13 deletions

View file

@ -0,0 +1,12 @@
import { ActionTree } from "vuex";
import { AppState } from "../types";
import { DraftState } from "./types";
import { Card } from "@/mlpccg";
const actions: ActionTree<DraftState, AppState> = {
pickCard({ commit }, card: Card) {
//TODO
}
};
export default actions;

View file

@ -0,0 +1,12 @@
import { GetterTree } from "vuex";
import { AppState } from "../types";
import { DraftState } from "./types";
import { createPonyheadURL } from "@/mlpccg";
const getters: GetterTree<DraftState, AppState> = {
ponyheadURL(state): string {
return createPonyheadURL(state.picks);
}
};
export default getters;

View file

@ -4,16 +4,24 @@ import { Module } from "vuex";
const namespaced = true; const namespaced = true;
import actions from "./actions";
import mutations from "./mutations";
import getters from "./getters";
export const state: DraftState = { export const state: DraftState = {
picks: [] cards: [],
picks: [],
pod: [],
packCount: 0,
currentPack: 0
}; };
export const draft: Module<DraftState, AppState> = { export const draft: Module<DraftState, AppState> = {
namespaced, namespaced,
state state,
//actions, actions,
//mutations, mutations,
//getters, getters
}; };
export default draft; export default draft;

View file

@ -0,0 +1,37 @@
import { MutationTree } from "vuex";
import { DraftState, PlayerStatus } from "./types";
import { Card } from "@/mlpccg";
const mutations: MutationTree<DraftState> = {
playerPicked(state, payload: { name: string; picked: boolean }) {
const idx = state.pod.findIndex(p => p.name == payload.name);
state.pod[idx].picked = payload.picked;
},
resetPickStatus(state) {
state.pod = state.pod.map(p => ({ ...p, picked: false }));
},
setCardPool(state, pool: Card[]) {
state.cards = pool;
},
setPackInfo(state, payload: { current: number; total: number }) {
state.currentPack = payload.current;
state.packCount = payload.total;
},
addPicks(state, pick: Card) {
state.picks.push(pick);
},
setPod(state, pod: PlayerStatus[]) {
state.pod = pod;
},
resetPicks(state) {
state.picks = [];
}
};
export default mutations;

View file

@ -3,5 +3,19 @@ import { Card } from "@/mlpccg";
export interface DraftState { export interface DraftState {
session?: Session; session?: Session;
pod: PlayerStatus[];
cards: Card[];
picks: Card[]; picks: Card[];
// Multiple pack draft
packCount: number;
currentPack: number;
}
export interface PlayerStatus {
name: string;
isBot: boolean;
isMe: boolean;
picked: boolean;
} }

View file

@ -3,6 +3,7 @@ import { AppState } from "../types";
import { Module } from "vuex"; import { Module } from "vuex";
import actions from "./actions"; import actions from "./actions";
import mutations from "./mutations";
import getters from "./getters"; import getters from "./getters";
const namespaced = true; const namespaced = true;
@ -16,7 +17,7 @@ export const network: Module<NetworkState, AppState> = {
namespaced, namespaced,
state, state,
actions, actions,
//mutations, mutations,
getters getters
}; };

View file

@ -152,13 +152,7 @@ import { Component, Vue } from "vue-property-decorator";
import { getCards, CardSlot, cardLimit, Card } from "@/mlpccg"; import { getCards, CardSlot, cardLimit, Card } from "@/mlpccg";
import CardPicker from "@/components/DeckBuilder/CardPicker.vue"; import CardPicker from "@/components/DeckBuilder/CardPicker.vue";
import DeckList from "@/components/DeckBuilder/DeckList.vue"; import DeckList from "@/components/DeckBuilder/DeckList.vue";
import { PlayerStatus } from "@/store/draft/types";
interface PlayerStatus {
name: string;
isBot: boolean;
isMe: boolean;
picked: boolean;
}
@Component({ @Component({
components: { components: {