Commit 86e4e7f3 authored by Chunchi Che's avatar Chunchi Che

finish handling MsgUpdateData

parent a1013c25
Pipeline #20806 passed with stages
in 16 minutes and 36 seconds
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import {
clearIdleInteractivities,
clearPlaceInteractivities,
DuelReducer,
updateCardData,
} from "./generic";
import { judgeSelf } from "./util";
......@@ -56,3 +58,61 @@ export const clearAllPlaceInteractivitiesImpl: DuelReducer<number> = (
states.forEach((item) => clearPlaceInteractivities(item));
};
export const updateFieldDataImpl: DuelReducer<
ygopro.StocGameMessage.MsgUpdateData
> = (state, action) => {
const player = action.payload.player;
const zone = action.payload.zone;
const actions = action.payload.actions;
switch (zone) {
case ygopro.CardZone.HAND: {
const hand = judgeSelf(player, state) ? state.meHands : state.opHands;
updateCardData(hand, actions);
break;
}
case ygopro.CardZone.EXTRA: {
const extra = judgeSelf(player, state)
? state.meExtraDeck
: state.opExtraDeck;
updateCardData(extra, actions);
break;
}
case ygopro.CardZone.MZONE: {
const monster = judgeSelf(player, state)
? state.meMonsters
: state.opMonsters;
updateCardData(monster, actions);
break;
}
case ygopro.CardZone.SZONE: {
const magics = judgeSelf(player, state) ? state.meMagics : state.opMagics;
updateCardData(magics, actions);
break;
}
case ygopro.CardZone.GRAVE: {
const cemetery = judgeSelf(player, state)
? state.meCemetery
: state.opCemetery;
updateCardData(cemetery, actions);
break;
}
case ygopro.CardZone.REMOVED: {
const exclusion = judgeSelf(player, state)
? state.meExclusion
: state.opExclusion;
updateCardData(exclusion, actions);
break;
}
default: {
break;
}
}
};
......@@ -95,6 +95,7 @@ import { DeckState, initDeckImpl } from "./deckSlice";
import {
clearAllIdleInteractivitiesImpl,
clearAllPlaceInteractivitiesImpl,
updateFieldDataImpl,
} from "./commonSlice";
import {
ExtraDeckState,
......@@ -256,6 +257,7 @@ const duelSlice = createSlice({
// 通用的`Reducer`
clearAllIdleInteractivities: clearAllIdleInteractivitiesImpl,
clearAllPlaceInteractivities: clearAllPlaceInteractivitiesImpl,
updateFieldData: updateFieldDataImpl,
// 对局结果`Reducer`
setResult: (state, action: PayloadAction<MsgWin.ActionType>) => {
......@@ -352,6 +354,7 @@ export const {
setResult,
setWaiting,
setUnimplemented,
updateFieldData,
} = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null;
......
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { updateFieldData } from "../../reducers/duel/mod";
import { AppDispatch } from "../../store";
import MsgUpdateData = ygopro.StocGameMessage.MsgUpdateData;
export default (updateData: MsgUpdateData, dispatch: AppDispatch) => {
console.log(updateData);
dispatch(updateFieldData(updateData));
};
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