Commit 8eb301bd authored by Chunchi Che's avatar Chunchi Che

update field slice

parent 1a5e0584
Pipeline #19753 passed with stages
in 5 minutes and 51 seconds
......@@ -2,8 +2,18 @@ import { judgeSelf } from "./util";
import { DuelState } from "./mod";
import { RootState } from "../../store";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { PayloadAction, CaseReducer } from "@reduxjs/toolkit";
import { CardState, Interactivity, InteractType } from "./generic";
import {
PayloadAction,
CaseReducer,
ActionReducerMapBuilder,
} from "@reduxjs/toolkit";
import {
CardState,
createAsyncMetaThunk,
DuelReducer,
Interactivity,
InteractType,
} from "./generic";
export interface FieldState {
inner?: CardState;
......@@ -99,5 +109,47 @@ export const clearFieldIdleInteractivitiesImpl: CaseReducer<
}
};
// 增加场地区
export const fetchFieldMeta = createAsyncMetaThunk("duel/fetchFieldMeta");
export const fieldCase = (builder: ActionReducerMapBuilder<DuelState>) => {
builder.addCase(fetchFieldMeta.pending, (state, action) => {
const controler = action.meta.arg.controler;
const sequence = action.meta.arg.sequence;
const code = action.meta.arg.code;
if (sequence == 0) {
const meta = { id: code, data: {}, text: {} };
const field = judgeSelf(controler, state) ? state.meField : state.opField;
if (field && field.inner) {
field.inner.occupant = meta;
}
}
});
builder.addCase(fetchFieldMeta.fulfilled, (state, action) => {
const controler = action.payload.controler;
const meta = action.payload.meta;
const field = judgeSelf(controler, state) ? state.meField : state.opField;
if (field && field.inner) {
field.inner.occupant = meta;
}
});
};
// 删除场地区
export const removeFieldImpl: DuelReducer<{ controler: number }> = (
state,
action
) => {
const controler = action.payload.controler;
const field = judgeSelf(controler, state) ? state.meField : state.opField;
if (field && field.inner) {
field.inner.occupant = undefined;
}
};
export const selectMeField = (state: RootState) => state.duel.meField;
export const selectOpField = (state: RootState) => state.duel.opField;
......@@ -96,6 +96,8 @@ import {
addFieldPlaceInteractivitiesImpl,
addFieldIdleInteractivitiesImpl,
clearFieldIdleInteractivitiesImpl,
removeFieldImpl,
fieldCase,
} from "./fieldSlice";
export interface DuelState {
......@@ -208,6 +210,7 @@ const duelSlice = createSlice({
addFieldPlaceInteractivities: addFieldPlaceInteractivitiesImpl,
addFieldIdleInteractivities: addFieldIdleInteractivitiesImpl,
clearFieldIdleInteractivities: clearFieldIdleInteractivitiesImpl,
removeField: removeFieldImpl,
// 阶段相关
updatePhase: newPhaseImpl,
......@@ -252,6 +255,7 @@ const duelSlice = createSlice({
YesNoModalCase(builder);
optionModalCase(builder);
checkCardModalV2Case(builder);
fieldCase(builder);
},
});
......@@ -305,6 +309,7 @@ export const {
initExclusion,
removeExclusion,
initField,
removeField,
clearFieldPlaceInteractivities,
addFieldPlaceInteractivities,
addFieldIdleInteractivities,
......
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