Commit fc04e90b authored by chechunchi's avatar chechunchi

add field slice

parent 2d88c2dc
Pipeline #19469 passed with stages
in 3 minutes and 18 seconds
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 } from "./generic";
export interface FieldState {
inner?: CardState;
}
// 初始化场地区状态
export const initFieldImpl: CaseReducer<DuelState, PayloadAction<number>> = (
state,
action
) => {
const player = action.payload;
if (judgeSelf(player, state)) {
state.meField = {
inner: {
location: {
controler: player,
sequence: 0,
location: ygopro.CardZone.ONFIELD,
},
idleInteractivities: [],
},
};
} else {
state.opField = {
inner: {
location: {
controler: player,
sequence: 0,
location: ygopro.CardZone.ONFIELD,
},
idleInteractivities: [],
},
};
}
};
export const selectMeField = (state: RootState) => state.duel.meField;
export const selectOpField = (state: RootState) => state.duel.opField;
......@@ -62,6 +62,7 @@ import {
exclusionCase,
} from "./exclusionSlice";
import { DeckState, initDeckImpl } from "./deckSlice";
import { FieldState, initFieldImpl } from "./fieldSlice";
export interface DuelState {
selfType?: number;
......@@ -86,6 +87,9 @@ export interface DuelState {
meDeck?: DeckState; // 自己的卡组状态
opDeck?: DeckState; // 对手的卡组状态
meField?: FieldState; // 自己的场地区状态
opField?: FieldState; // 对手的场地区状态
meTimeLimit?: TimeLimit; // 自己的计时
opTimeLimit?: TimeLimit; // 对手的计时
......@@ -146,6 +150,9 @@ const duelSlice = createSlice({
// 卡组相关`Reducer`
initDeck: initDeckImpl,
// 场地区相关`Reducer`
initField: initFieldImpl,
// UI相关`Reducer`
setCardModalIsOpen: setCardModalIsOpenImpl,
setCardModalText: setCardModalTextImpl,
......@@ -214,6 +221,8 @@ export const {
setOptionModalIsOpen,
resetOptionModal,
initDeck,
initExclusion,
initField,
} = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null;
......
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