Commit b2f71ef0 authored by Chunchi Che's avatar Chunchi Che

impl onMsgNewTurn

parent c5d4e353
...@@ -11,6 +11,7 @@ import { ...@@ -11,6 +11,7 @@ import {
opAddHandsImpl, opAddHandsImpl,
meHandsCase, meHandsCase,
} from "./handsSlice"; } from "./handsSlice";
import { newTurnImpl } from "./turnSlice";
import { RootState } from "../../store"; import { RootState } from "../../store";
export interface DuelState { export interface DuelState {
...@@ -18,6 +19,7 @@ export interface DuelState { ...@@ -18,6 +19,7 @@ export interface DuelState {
opInitInfo?: InitInfo; // 对手的初始状态 opInitInfo?: InitInfo; // 对手的初始状态
meHands?: Hands; // 自己的手牌 meHands?: Hands; // 自己的手牌
opHands?: Hands; // 对手的手牌 opHands?: Hands; // 对手的手牌
currentPlayer?: number; // 当前的操作方
} }
const initialState: DuelState = {}; const initialState: DuelState = {};
...@@ -30,13 +32,14 @@ const duelSlice = createSlice({ ...@@ -30,13 +32,14 @@ const duelSlice = createSlice({
opInfoInit: opInfoInitImpl, opInfoInit: opInfoInitImpl,
meAddHands: meAddHandsImpl, meAddHands: meAddHandsImpl,
opAddHands: opAddHandsImpl, opAddHands: opAddHandsImpl,
updateTurn: newTurnImpl,
}, },
extraReducers(builder) { extraReducers(builder) {
meHandsCase(builder); meHandsCase(builder);
}, },
}); });
export const { meInfoInit, opInfoInit, meAddHands, opAddHands } = export const { meInfoInit, opInfoInit, meAddHands, opAddHands, updateTurn } =
duelSlice.actions; duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => { export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null; return state.duel.meInitInfo != null;
......
import { PayloadAction, CaseReducer } from "@reduxjs/toolkit";
import { DuelState } from "./mod";
export const newTurnImpl: CaseReducer<DuelState, PayloadAction<number>> = (
state,
action
) => {
state.currentPlayer = action.payload;
};
import { ygopro } from "../../api/ocgcore/idl/ocgcore"; import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { AppDispatch } from "../../store"; import { AppDispatch } from "../../store";
import { updateTurn } from "../../reducers/duel/mod";
export default ( export default (
newTurn: ygopro.StocGameMessage.MsgNewTurn, newTurn: ygopro.StocGameMessage.MsgNewTurn,
dispatch: AppDispatch dispatch: AppDispatch
) => { ) => {
// TODO const player = newTurn.player;
dispatch(updateTurn(player));
}; };
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