Commit 7ba35087 authored by chechunchi's avatar chechunchi

update checkCardModalV2Slice

parent 0dbc0017
Pipeline #19678 passed with stages
in 5 minutes and 18 seconds
import { AsyncThunk, createAsyncThunk } from "@reduxjs/toolkit";
import {
AsyncThunk,
CaseReducer,
createAsyncThunk,
PayloadAction,
} from "@reduxjs/toolkit";
import { CardMeta } from "../../api/cards";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { fetchCard } from "../../api/cards";
import { DuelState } from "./mod";
export type DuelReducer<T> = CaseReducer<DuelState, PayloadAction<T>>;
export interface DuelFieldState {
inner: CardState[];
......
......@@ -46,6 +46,11 @@ import {
setOptionModalIsOpenImpl,
resetOptionModalImpl,
optionModalCase,
setCheckCardModalV2IsOpenImpl,
setCheckCardModalV2CancelAbleImpl,
setCheckCardModalV2MinMaxImpl,
setCheckCardModalV2FinishAbleImpl,
resetCheckCardModalV2Impl,
} from "./modal/mod";
import {
MonsterState,
......@@ -226,6 +231,11 @@ const duelSlice = createSlice({
resetPositionModal: resetPositionModalImpl,
setOptionModalIsOpen: setOptionModalIsOpenImpl,
resetOptionModal: resetOptionModalImpl,
setCheckCardModalV2FinishAble: setCheckCardModalV2FinishAbleImpl,
setCheckCardModalV2MinMax: setCheckCardModalV2MinMaxImpl,
setCheckCardModalV2CancelAble: setCheckCardModalV2CancelAbleImpl,
setCheckCardModalV2IsOpen: setCheckCardModalV2IsOpenImpl,
resetCheckCardModalV2: resetCheckCardModalV2Impl,
},
extraReducers(builder) {
handsCase(builder);
......@@ -294,6 +304,11 @@ export const {
addFieldPlaceInteractivities,
addFieldIdleInteractivities,
clearFieldIdleInteractivities,
setCheckCardModalV2IsOpen,
setCheckCardModalV2MinMax,
setCheckCardModalV2CancelAble,
setCheckCardModalV2FinishAble,
resetCheckCardModalV2,
} = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null;
......
import { DuelState } from "../mod";
import { judgeSelf } from "../util";
import { DuelReducer } from "../generic";
import {
ActionReducerMapBuilder,
CaseReducer,
createAsyncThunk,
} from "@reduxjs/toolkit";
import { fetchCard } from "../../../api/cards";
import { RootState } from "../../../store";
// 更新打开状态
export const setCheckCardModalV2IsOpenImpl: DuelReducer<boolean> = (
state,
action
) => {
state.modalState.checkCardModalV2.isOpen = action.payload;
};
// 更新选择数目
export const setCheckCardModalV2MinMaxImpl: DuelReducer<{
min: number;
max: number;
}> = (state, action) => {
state.modalState.checkCardModalV2.selectMin = action.payload.min;
state.modalState.checkCardModalV2.selectMax = action.payload.max;
};
// 更新是否可以取消
export const setCheckCardModalV2CancelAbleImpl: DuelReducer<boolean> = (
state,
action
) => {
state.modalState.checkCardModalV2.cancelAble = action.payload;
};
// 更新是否可以结束
export const setCheckCardModalV2FinishAbleImpl: DuelReducer<boolean> = (
state,
action
) => {
state.modalState.checkCardModalV2.finishAble = action.payload;
};
// 增加卡牌选项
export const fetchCheckCardMetaV2 = createAsyncThunk(
"duel/fetchCheckCardMetaV2",
async (param: {
controler: number;
selected: boolean;
option: { code: number; response?: number };
}) => {
const meta = await fetchCard(param.option.code);
const response = {
controler: param.controler,
selected: param.selected,
meta: {
code: meta.id,
name: meta.text.name,
desc: meta.text.desc,
},
};
return response;
}
);
export const checkCardModalV2Case = (
builder: ActionReducerMapBuilder<DuelState>
) => {
builder.addCase(fetchCheckCardMetaV2.pending, (state, action) => {
const selected = action.meta.arg.selected;
const code = action.meta.arg.option.code;
const response = action.meta.arg.option.response;
const options = selected
? state.modalState.checkCardModalV2.selectedOptions
: state.modalState.checkCardModalV2.selectableOptions;
options.push({ code, response });
});
builder.addCase(fetchCheckCardMetaV2.fulfilled, (state, action) => {
const selected = action.payload.selected;
const meta = action.payload.meta;
const options = selected
? state.modalState.checkCardModalV2.selectedOptions
: state.modalState.checkCardModalV2.selectableOptions;
options.forEach((option) => {
if (option.code == meta.code) {
option.name = meta.name;
option.desc = meta.desc;
}
});
});
};
export const resetCheckCardModalV2Impl: CaseReducer<DuelState> = (state) => {
const modalState = state.modalState.checkCardModalV2;
modalState.isOpen = false;
modalState.finishAble = false;
modalState.cancelAble = false;
modalState.selectableOptions = [];
modalState.selectedOptions = [];
};
export const selectCheckCardModalV2IsOpen = (state: RootState) =>
state.duel.modalState.checkCardModalV2.isOpen;
export const selectCheckCardModalV2MinMax = (state: RootState) => {
return {
min: state.duel.modalState.checkCardModalV2.selectMin || 0,
max: state.duel.modalState.checkCardModalV2.selectMax || 0,
};
};
export const selectCheckCardModalV2CancelAble = (state: RootState) =>
state.duel.modalState.checkCardModalV2.cancelAble;
export const selectCheckCardModalV2SelectAbleOptions = (state: RootState) =>
state.duel.modalState.checkCardModalV2.selectableOptions;
export const selectCheckCardModalV2SelectedOptions = (state: RootState) =>
state.duel.modalState.checkCardModalV2.selectedOptions;
......@@ -69,6 +69,7 @@ export interface ModalState {
code: number;
name?: string;
desc?: string;
response?: number;
}[];
};
}
......@@ -79,3 +80,4 @@ export * from "./checkCardModalSlice";
export * from "./yesNoModalSlice";
export * from "./positionModalSlice";
export * from "./optionModalSlice";
export * from "./checkCardModalV2Slice";
......@@ -2,6 +2,6 @@ import React, { useState } from "react";
import { useAppSelector } from "../../hook";
import { store } from "../../store";
const CheckCardModalV2 = () => (<></>);
const CheckCardModalV2 = () => <></>;
export default CheckCardModalV2;
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