From 6648182f1811870d7c49ca363d4346611f7e9ac0 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Tue, 17 Sep 2019 15:17:58 +0200 Subject: [PATCH] Add vuex actions/mutations for draft --- src/store/draft/actions.ts | 12 ++++++++++++ src/store/draft/getters.ts | 12 ++++++++++++ src/store/draft/index.ts | 18 +++++++++++++----- src/store/draft/mutations.ts | 37 ++++++++++++++++++++++++++++++++++++ src/store/draft/types.ts | 14 ++++++++++++++ src/store/network/index.ts | 3 ++- src/views/Draft.vue | 8 +------- 7 files changed, 91 insertions(+), 13 deletions(-) create mode 100644 src/store/draft/actions.ts create mode 100644 src/store/draft/getters.ts create mode 100644 src/store/draft/mutations.ts diff --git a/src/store/draft/actions.ts b/src/store/draft/actions.ts new file mode 100644 index 0000000..0f45d61 --- /dev/null +++ b/src/store/draft/actions.ts @@ -0,0 +1,12 @@ +import { ActionTree } from "vuex"; +import { AppState } from "../types"; +import { DraftState } from "./types"; +import { Card } from "@/mlpccg"; + +const actions: ActionTree = { + pickCard({ commit }, card: Card) { + //TODO + } +}; + +export default actions; diff --git a/src/store/draft/getters.ts b/src/store/draft/getters.ts new file mode 100644 index 0000000..e082c81 --- /dev/null +++ b/src/store/draft/getters.ts @@ -0,0 +1,12 @@ +import { GetterTree } from "vuex"; +import { AppState } from "../types"; +import { DraftState } from "./types"; +import { createPonyheadURL } from "@/mlpccg"; + +const getters: GetterTree = { + ponyheadURL(state): string { + return createPonyheadURL(state.picks); + } +}; + +export default getters; diff --git a/src/store/draft/index.ts b/src/store/draft/index.ts index 691f0f4..6e55ea1 100644 --- a/src/store/draft/index.ts +++ b/src/store/draft/index.ts @@ -4,16 +4,24 @@ import { Module } from "vuex"; const namespaced = true; +import actions from "./actions"; +import mutations from "./mutations"; +import getters from "./getters"; + export const state: DraftState = { - picks: [] + cards: [], + picks: [], + pod: [], + packCount: 0, + currentPack: 0 }; export const draft: Module = { namespaced, - state - //actions, - //mutations, - //getters, + state, + actions, + mutations, + getters }; export default draft; diff --git a/src/store/draft/mutations.ts b/src/store/draft/mutations.ts new file mode 100644 index 0000000..94d2494 --- /dev/null +++ b/src/store/draft/mutations.ts @@ -0,0 +1,37 @@ +import { MutationTree } from "vuex"; +import { DraftState, PlayerStatus } from "./types"; +import { Card } from "@/mlpccg"; + +const mutations: MutationTree = { + 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; diff --git a/src/store/draft/types.ts b/src/store/draft/types.ts index 3a25e1b..3de4bf7 100644 --- a/src/store/draft/types.ts +++ b/src/store/draft/types.ts @@ -3,5 +3,19 @@ import { Card } from "@/mlpccg"; export interface DraftState { session?: Session; + + pod: PlayerStatus[]; + cards: Card[]; picks: Card[]; + + // Multiple pack draft + packCount: number; + currentPack: number; +} + +export interface PlayerStatus { + name: string; + isBot: boolean; + isMe: boolean; + picked: boolean; } diff --git a/src/store/network/index.ts b/src/store/network/index.ts index ed54c6c..9a0ca12 100644 --- a/src/store/network/index.ts +++ b/src/store/network/index.ts @@ -3,6 +3,7 @@ import { AppState } from "../types"; import { Module } from "vuex"; import actions from "./actions"; +import mutations from "./mutations"; import getters from "./getters"; const namespaced = true; @@ -16,7 +17,7 @@ export const network: Module = { namespaced, state, actions, - //mutations, + mutations, getters }; diff --git a/src/views/Draft.vue b/src/views/Draft.vue index 9a699b0..6a68139 100644 --- a/src/views/Draft.vue +++ b/src/views/Draft.vue @@ -152,13 +152,7 @@ import { Component, Vue } from "vue-property-decorator"; import { getCards, CardSlot, cardLimit, Card } from "@/mlpccg"; import CardPicker from "@/components/DeckBuilder/CardPicker.vue"; import DeckList from "@/components/DeckBuilder/DeckList.vue"; - -interface PlayerStatus { - name: string; - isBot: boolean; - isMe: boolean; - picked: boolean; -} +import { PlayerStatus } from "@/store/draft/types"; @Component({ components: {