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 { import {
clearIdleInteractivities, clearIdleInteractivities,
clearPlaceInteractivities, clearPlaceInteractivities,
DuelReducer, DuelReducer,
updateCardData,
} from "./generic"; } from "./generic";
import { judgeSelf } from "./util"; import { judgeSelf } from "./util";
...@@ -56,3 +58,61 @@ export const clearAllPlaceInteractivitiesImpl: DuelReducer<number> = ( ...@@ -56,3 +58,61 @@ export const clearAllPlaceInteractivitiesImpl: DuelReducer<number> = (
states.forEach((item) => clearPlaceInteractivities(item)); 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"; ...@@ -95,6 +95,7 @@ import { DeckState, initDeckImpl } from "./deckSlice";
import { import {
clearAllIdleInteractivitiesImpl, clearAllIdleInteractivitiesImpl,
clearAllPlaceInteractivitiesImpl, clearAllPlaceInteractivitiesImpl,
updateFieldDataImpl,
} from "./commonSlice"; } from "./commonSlice";
import { import {
ExtraDeckState, ExtraDeckState,
...@@ -256,6 +257,7 @@ const duelSlice = createSlice({ ...@@ -256,6 +257,7 @@ const duelSlice = createSlice({
// 通用的`Reducer` // 通用的`Reducer`
clearAllIdleInteractivities: clearAllIdleInteractivitiesImpl, clearAllIdleInteractivities: clearAllIdleInteractivitiesImpl,
clearAllPlaceInteractivities: clearAllPlaceInteractivitiesImpl, clearAllPlaceInteractivities: clearAllPlaceInteractivitiesImpl,
updateFieldData: updateFieldDataImpl,
// 对局结果`Reducer` // 对局结果`Reducer`
setResult: (state, action: PayloadAction<MsgWin.ActionType>) => { setResult: (state, action: PayloadAction<MsgWin.ActionType>) => {
...@@ -352,6 +354,7 @@ export const { ...@@ -352,6 +354,7 @@ export const {
setResult, setResult,
setWaiting, setWaiting,
setUnimplemented, setUnimplemented,
updateFieldData,
} = 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 { ygopro } from "../../api/ocgcore/idl/ocgcore"; import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { updateFieldData } from "../../reducers/duel/mod";
import { AppDispatch } from "../../store"; import { AppDispatch } from "../../store";
import MsgUpdateData = ygopro.StocGameMessage.MsgUpdateData; import MsgUpdateData = ygopro.StocGameMessage.MsgUpdateData;
export default (updateData: MsgUpdateData, dispatch: AppDispatch) => { 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