Commit 51bd0e23 authored by Chunchi Che's avatar Chunchi Che

add hands slice

parent 972ed5f0
Pipeline #18014 passed with stages
in 3 minutes and 47 seconds
import { PayloadAction, CaseReducer } from "@reduxjs/toolkit";
import { DuelState } from "./mod";
export interface Hands {
cards: number[]; // TODO: use Card struct Unitly
}
// 自己增加手牌
export const meAddHandsImpl: CaseReducer<DuelState, PayloadAction<number[]>> = (
state,
action
) => {
if (state.meHands) {
state.meHands.cards = state.meHands.cards.concat(action.payload);
} else {
state.meHands = { cards: action.payload };
}
};
// 对手增加手牌
export const opAddHandsImpl: CaseReducer<DuelState, PayloadAction<number[]>> = (
state,
action
) => {
if (state.opHands) {
state.opHands.cards = state.opHands.cards.concat(action.payload);
} else {
state.opHands = { cards: action.payload };
}
};
import { PayloadAction, CaseReducer } from "@reduxjs/toolkit";
import { DuelState } from "./mod";
export interface InitInfo { export interface InitInfo {
playerType?: string; playerType?: string;
masterRule?: string; masterRule?: string;
...@@ -5,3 +8,19 @@ export interface InitInfo { ...@@ -5,3 +8,19 @@ export interface InitInfo {
deckSize: number; deckSize: number;
extraSize: number; extraSize: number;
} }
// 更新自己的初始生命值,卡组信息
export const meInfoInitImpl: CaseReducer<DuelState, PayloadAction<InitInfo>> = (
state,
action
) => {
state.meInitInfo = action.payload;
};
// 更新对手的初始生命值,卡组信息
export const opInfoInitImpl: CaseReducer<DuelState, PayloadAction<InitInfo>> = (
state,
action
) => {
state.opInitInfo = action.payload;
};
...@@ -3,12 +3,15 @@ ...@@ -3,12 +3,15 @@
* *
* */ * */
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { createSlice } from "@reduxjs/toolkit";
import { InitInfo } from "./initInfoSlice"; import { InitInfo, meInfoInitImpl, opInfoInitImpl } from "./initInfoSlice";
import { Hands, meAddHandsImpl, opAddHandsImpl } from "./handsSlice";
export interface DuelState { export interface DuelState {
meInitInfo?: InitInfo; // 自己的初始状态 meInitInfo?: InitInfo; // 自己的初始状态
opInitInfo?: InitInfo; // 对手的初始状态 opInitInfo?: InitInfo; // 对手的初始状态
meHands?: Hands; // 自己的手牌
opHands?: Hands; // 对手的手牌
} }
const initialState: DuelState = {}; const initialState: DuelState = {};
...@@ -17,14 +20,13 @@ const duelSlice = createSlice({ ...@@ -17,14 +20,13 @@ const duelSlice = createSlice({
name: "duel", name: "duel",
initialState, initialState,
reducers: { reducers: {
meInfoInit: (state, action: PayloadAction<InitInfo>) => { meInfoInit: meInfoInitImpl,
state.meInitInfo = action.payload; opInfoInit: opInfoInitImpl,
}, meAddHands: meAddHandsImpl,
opInfoInit: (state, action: PayloadAction<InitInfo>) => { opAddHands: opAddHandsImpl,
state.opInitInfo = action.payload;
},
}, },
}); });
export const { meInfoInit, opInfoInit } = duelSlice.actions; export const { meInfoInit, opInfoInit, meAddHands, opAddHands } =
duelSlice.actions;
export default duelSlice.reducer; export default duelSlice.reducer;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment