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

add hands slice

parent 972ed5f0
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 {
playerType?: string;
masterRule?: string;
......@@ -5,3 +8,19 @@ export interface InitInfo {
deckSize: 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 @@
*
* */
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { InitInfo } from "./initInfoSlice";
import { createSlice } from "@reduxjs/toolkit";
import { InitInfo, meInfoInitImpl, opInfoInitImpl } from "./initInfoSlice";
import { Hands, meAddHandsImpl, opAddHandsImpl } from "./handsSlice";
export interface DuelState {
meInitInfo?: InitInfo; // 自己的初始状态
opInitInfo?: InitInfo; // 对手的初始状态
meHands?: Hands; // 自己的手牌
opHands?: Hands; // 对手的手牌
}
const initialState: DuelState = {};
......@@ -17,14 +20,13 @@ const duelSlice = createSlice({
name: "duel",
initialState,
reducers: {
meInfoInit: (state, action: PayloadAction<InitInfo>) => {
state.meInitInfo = action.payload;
},
opInfoInit: (state, action: PayloadAction<InitInfo>) => {
state.opInitInfo = action.payload;
},
meInfoInit: meInfoInitImpl,
opInfoInit: opInfoInitImpl,
meAddHands: meAddHandsImpl,
opAddHands: opAddHandsImpl,
},
});
export const { meInfoInit, opInfoInit } = duelSlice.actions;
export const { meInfoInit, opInfoInit, meAddHands, opAddHands } =
duelSlice.actions;
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