Commit bbe1136b authored by timel's avatar timel

refactor: rename to official names(gy & banished)

parent 2c33125b
......@@ -20,28 +20,30 @@ import {
import { DuelState } from "./mod";
import { judgeSelf } from "./util";
export interface ExclusionState extends DuelFieldState {}
export interface BanishedZoneState extends DuelFieldState {}
// 初始化除外区状态
export const initExclusionImpl: CaseReducer<
export const initBanishedZoneImpl: CaseReducer<
DuelState,
PayloadAction<number>
> = (state, action) => {
const player = action.payload;
if (judgeSelf(player, state)) {
state.meExclusion = { inner: [] };
state.meBanishedZone = { inner: [] };
} else {
state.opExclusion = { inner: [] };
state.opBanishedZone = { inner: [] };
}
};
// 增加除外区
export const fetchExclusionMeta = createAsyncMetaThunk(
"duel/fetchExclusionMeta"
export const fetchBanishedZoneMeta = createAsyncMetaThunk(
"duel/fetchBanishedZoneMeta"
);
export const exclusionCase = (builder: ActionReducerMapBuilder<DuelState>) => {
builder.addCase(fetchExclusionMeta.pending, (state, action) => {
export const banishedZoneCase = (
builder: ActionReducerMapBuilder<DuelState>
) => {
builder.addCase(fetchBanishedZoneMeta.pending, (state, action) => {
// Meta结果没返回之前先更新`ID`
const controler = action.meta.arg.controler;
const sequence = action.meta.arg.sequence;
......@@ -58,51 +60,51 @@ export const exclusionCase = (builder: ActionReducerMapBuilder<DuelState>) => {
counters: {},
};
if (judgeSelf(controler, state)) {
extendState(state.meExclusion, newExclusion);
extendState(state.meBanishedZone, newExclusion);
} else {
extendState(state.opExclusion, newExclusion);
extendState(state.opBanishedZone, newExclusion);
}
});
builder.addCase(fetchExclusionMeta.fulfilled, (state, action) => {
builder.addCase(fetchBanishedZoneMeta.fulfilled, (state, action) => {
const controler = action.payload.controler;
const sequence = action.payload.sequence;
const meta = action.payload.meta;
if (judgeSelf(controler, state)) {
extendMeta(state.meExclusion, meta, sequence);
extendMeta(state.meBanishedZone, meta, sequence);
} else {
extendMeta(state.opExclusion, meta, sequence);
extendMeta(state.opBanishedZone, meta, sequence);
}
});
};
// 删除除外区
export const removeExclusionImpl: CaseReducer<
export const removeBanishedZoneImpl: CaseReducer<
DuelState,
PayloadAction<{ controler: number; sequence: number }>
> = (state, action) => {
const exclusion = judgeSelf(action.payload.controler, state)
? state.meExclusion
: state.opExclusion;
removeCard(exclusion, action.payload.sequence);
const banishedZone = judgeSelf(action.payload.controler, state)
? state.meBanishedZone
: state.opBanishedZone;
removeCard(banishedZone, action.payload.sequence);
};
export const addExclusionIdleInteractivitiesImpl: DuelReducer<{
export const addBanishedZoneIdleInteractivitiesImpl: DuelReducer<{
player: number;
sequence: number;
interactivity: Interactivity<number>;
}> = (state, action) => {
const exclusion = judgeSelf(action.payload.player, state)
? state.meExclusion
: state.opExclusion;
const banishedZone = judgeSelf(action.payload.player, state)
? state.meBanishedZone
: state.opBanishedZone;
extendIdleInteractivities(
exclusion,
banishedZone,
action.payload.sequence,
action.payload.interactivity
);
};
export const selectMeExclusion = (state: RootState) =>
state.duel.meExclusion || { inner: [] };
export const selectopExclusion = (state: RootState) =>
state.duel.opExclusion || { inner: [] };
export const selectMeBanishedZone = (state: RootState) =>
state.duel.meBanishedZone || { inner: [] };
export const selectOpBanishedZone = (state: RootState) =>
state.duel.opBanishedZone || { inner: [] };
......@@ -20,32 +20,34 @@ import {
import { DuelState } from "./mod";
import { judgeSelf } from "./util";
export interface CemeteryState extends DuelFieldState {}
export interface GraveyardState extends DuelFieldState {}
// 初始化墓地状态
export const initCemeteryImpl: CaseReducer<DuelState, PayloadAction<number>> = (
state,
action
) => {
export const initGraveyardImpl: CaseReducer<
DuelState,
PayloadAction<number>
> = (state, action) => {
const player = action.payload;
if (judgeSelf(player, state)) {
state.meCemetery = { inner: [] };
state.meGraveyard = { inner: [] };
} else {
state.opCemetery = { inner: [] };
state.opGraveyard = { inner: [] };
}
};
// 增加墓地
export const fetchCemeteryMeta = createAsyncMetaThunk("duel/fetchCemeteryMeta");
export const fetchGraveyardMeta = createAsyncMetaThunk(
"duel/fetchGraveyardMeta"
);
export const cemeteryCase = (builder: ActionReducerMapBuilder<DuelState>) => {
builder.addCase(fetchCemeteryMeta.pending, (state, action) => {
export const graveyardCase = (builder: ActionReducerMapBuilder<DuelState>) => {
builder.addCase(fetchGraveyardMeta.pending, (state, action) => {
// Meta结果没返回之前先更新`ID`
const controler = action.meta.arg.controler;
const sequence = action.meta.arg.sequence;
const code = action.meta.arg.code;
const newCemetery = {
const newGraveyard = {
occupant: { id: code, data: {}, text: {} },
location: {
controler,
......@@ -56,51 +58,51 @@ export const cemeteryCase = (builder: ActionReducerMapBuilder<DuelState>) => {
counters: {},
};
if (judgeSelf(controler, state)) {
extendState(state.meCemetery, newCemetery);
extendState(state.meGraveyard, newGraveyard);
} else {
extendState(state.opCemetery, newCemetery);
extendState(state.opGraveyard, newGraveyard);
}
});
builder.addCase(fetchCemeteryMeta.fulfilled, (state, action) => {
builder.addCase(fetchGraveyardMeta.fulfilled, (state, action) => {
const controler = action.payload.controler;
const sequence = action.payload.sequence;
const meta = action.payload.meta;
if (judgeSelf(controler, state)) {
extendMeta(state.meCemetery, meta, sequence);
extendMeta(state.meGraveyard, meta, sequence);
} else {
extendMeta(state.opCemetery, meta, sequence);
extendMeta(state.opGraveyard, meta, sequence);
}
});
};
// 删除墓地
export const removeCemeteryImpl: CaseReducer<
export const removeGraveyardImpl: CaseReducer<
DuelState,
PayloadAction<{ controler: number; sequence: number }>
> = (state, action) => {
const cemetery = judgeSelf(action.payload.controler, state)
? state.meCemetery
: state.opCemetery;
removeCard(cemetery, action.payload.sequence);
const graveyard = judgeSelf(action.payload.controler, state)
? state.meGraveyard
: state.opGraveyard;
removeCard(graveyard, action.payload.sequence);
};
export const addCemeteryIdleInteractivitiesImpl: DuelReducer<{
export const addGraveyardIdleInteractivitiesImpl: DuelReducer<{
player: number;
sequence: number;
interactivity: Interactivity<number>;
}> = (state, action) => {
const cemetery = judgeSelf(action.payload.player, state)
? state.meCemetery
: state.opCemetery;
const graveyard = judgeSelf(action.payload.player, state)
? state.meGraveyard
: state.opGraveyard;
extendIdleInteractivities(
cemetery,
graveyard,
action.payload.sequence,
action.payload.interactivity
);
};
export const selectMeCemetery = (state: RootState) =>
state.duel.meCemetery || { inner: [] };
export const selectOpCemetery = (state: RootState) =>
state.duel.opCemetery || { inner: [] };
export const selectMeGraveyard = (state: RootState) =>
state.duel.meGraveyard || { inner: [] };
export const selectOpGraveyard = (state: RootState) =>
state.duel.opGraveyard || { inner: [] };
......@@ -24,16 +24,16 @@ export const clearAllIdleInteractivitiesImpl: DuelReducer<number> = (
state.meHands,
state.meMonsters,
state.meMagics,
state.meCemetery,
state.meExclusion,
state.meGraveyard,
state.meBanishedZone,
state.meExtraDeck,
]
: [
state.opHands,
state.opMonsters,
state.opMagics,
state.opCemetery,
state.opExclusion,
state.opGraveyard,
state.opBanishedZone,
state.opExtraDeck,
];
......@@ -51,15 +51,15 @@ export const clearAllPlaceInteractivitiesImpl: DuelReducer<number> = (
state.meHands,
state.meMonsters,
state.meMagics,
state.meCemetery,
state.meExclusion,
state.meGraveyard,
state.meBanishedZone,
]
: [
state.opHands,
state.opMonsters,
state.opMagics,
state.opCemetery,
state.opExclusion,
state.opGraveyard,
state.opBanishedZone,
];
states.forEach((item) => clearPlaceInteractivities(item));
......@@ -106,18 +106,18 @@ export const updateFieldDataImpl: DuelReducer<MsgUpdateData> = (
break;
}
case ygopro.CardZone.GRAVE: {
const cemetery = judgeSelf(player, state)
? state.meCemetery
: state.opCemetery;
updateCardData(cemetery, actions);
const graveyard = judgeSelf(player, state)
? state.meGraveyard
: state.opGraveyard;
updateCardData(graveyard, actions);
break;
}
case ygopro.CardZone.REMOVED: {
const exclusion = judgeSelf(player, state)
? state.meExclusion
: state.opExclusion;
updateCardData(exclusion, actions);
const BanishedZone = judgeSelf(player, state)
? state.meBanishedZone
: state.opBanishedZone;
updateCardData(BanishedZone, actions);
break;
}
......@@ -140,10 +140,10 @@ export const reloadFieldImpl: DuelReducer<MsgReloadField> = (state, action) => {
state.opMonsters = { inner: [] };
state.meMagics = { inner: [] };
state.opMagics = { inner: [] };
state.meCemetery = { inner: [] };
state.opCemetery = { inner: [] };
state.meExclusion = { inner: [] };
state.opExclusion = { inner: [] };
state.meGraveyard = { inner: [] };
state.opGraveyard = { inner: [] };
state.meBanishedZone = { inner: [] };
state.opBanishedZone = { inner: [] };
state.meHands = { inner: [] };
state.opHands = { inner: [] };
......@@ -183,20 +183,20 @@ export const reloadFieldImpl: DuelReducer<MsgReloadField> = (state, action) => {
player
);
// GRAVE
const cemetery = judgeSelf(player, state)
? state.meCemetery
: state.opCemetery;
const graveyard = judgeSelf(player, state)
? state.meGraveyard
: state.opGraveyard;
reloadFieldMeta(
cemetery,
graveyard,
reload.zone_actions.filter((item) => item.zone == ygopro.CardZone.GRAVE),
player
);
// REMOVED
const exclusion = judgeSelf(player, state)
? state.meExclusion
: state.opExclusion;
const banishedZone = judgeSelf(player, state)
? state.meBanishedZone
: state.opBanishedZone;
reloadFieldMeta(
exclusion,
banishedZone,
reload.zone_actions.filter(
(item) => item.zone == ygopro.CardZone.REMOVED
),
......
......@@ -9,11 +9,18 @@ import { ygopro } from "@/api/ocgcore/idl/ocgcore";
import { RootState } from "@/store";
import {
addCemeteryIdleInteractivitiesImpl,
cemeteryCase,
CemeteryState,
initCemeteryImpl,
removeCemeteryImpl,
addBanishedZoneIdleInteractivitiesImpl,
banishedZoneCase,
BanishedZoneState,
initBanishedZoneImpl,
removeBanishedZoneImpl,
} from "./banishedZoneSlice";
import {
addGraveyardIdleInteractivitiesImpl,
graveyardCase,
GraveyardState,
initGraveyardImpl,
removeGraveyardImpl,
} from "./cemeretySlice";
import {
clearAllIdleInteractivitiesImpl,
......@@ -22,13 +29,6 @@ import {
updateFieldDataImpl,
} from "./commonSlice";
import { DeckState, initDeckImpl } from "./deckSlice";
import {
addExclusionIdleInteractivitiesImpl,
exclusionCase,
ExclusionState,
initExclusionImpl,
removeExclusionImpl,
} from "./exclusionSlice";
import {
addExtraDeckIdleInteractivitiesImpl,
extraDeckCase,
......@@ -136,11 +136,11 @@ export interface DuelState {
meMagics?: MagicState; // 自己的魔法陷阱区状态
opMagics?: MagicState; // 对手的魔法陷阱区状态
meCemetery?: CemeteryState; // 自己的墓地状态
opCemetery?: CemeteryState; // 对手的墓地状态
meGraveyard?: GraveyardState; // 自己的墓地状态
opGraveyard?: GraveyardState; // 对手的墓地状态
meExclusion?: ExclusionState; // 自己的除外区状态
opExclusion?: ExclusionState; // 对手的除外区状态
meBanishedZone?: BanishedZoneState; // 自己的除外区状态
opBanishedZone?: BanishedZoneState; // 对手的除外区状态
meDeck?: DeckState; // 自己的卡组状态
opDeck?: DeckState; // 对手的卡组状态
......@@ -239,14 +239,14 @@ const duelSlice = createSlice({
removeMagic: removeMagicImpl,
// 墓地相关`Reducer`
initCemetery: initCemeteryImpl,
removeCemetery: removeCemeteryImpl,
addCemeteryIdleInteractivities: addCemeteryIdleInteractivitiesImpl,
initGraveyard: initGraveyardImpl,
removeGraveyard: removeGraveyardImpl,
addGraveyardIdleInteractivities: addGraveyardIdleInteractivitiesImpl,
// 除外区相关`Reducer`
initExclusion: initExclusionImpl,
removeExclusion: removeExclusionImpl,
addExclusionIdleInteractivities: addExclusionIdleInteractivitiesImpl,
initBanishedZone: initBanishedZoneImpl,
removeBanishedZone: removeBanishedZoneImpl,
addBanishedZoneIdleInteractivities: addBanishedZoneIdleInteractivitiesImpl,
// 卡组相关`Reducer`
initDeck: initDeckImpl,
......@@ -326,8 +326,8 @@ const duelSlice = createSlice({
hintCase(builder);
monsterCase(builder);
magicCase(builder);
cemeteryCase(builder);
exclusionCase(builder);
graveyardCase(builder);
banishedZoneCase(builder);
extraDeckCase(builder);
checkCardModalCase(builder);
YesNoModalCase(builder);
......@@ -370,9 +370,9 @@ export const {
setMagicPosition,
removeMagic,
removeHand,
initCemetery,
removeCemetery,
addCemeteryIdleInteractivities,
initGraveyard,
removeGraveyard,
addGraveyardIdleInteractivities,
setCardListModalIsOpen,
setCardListModalInfo,
setCheckCardModalIsOpen,
......@@ -390,9 +390,9 @@ export const {
initDeck,
removeExtraDeck,
addExtraDeckIdleInteractivities,
initExclusion,
removeExclusion,
addExclusionIdleInteractivities,
initBanishedZone,
removeBanishedZone,
addBanishedZoneIdleInteractivities,
setCheckCardModalV2IsOpen,
setCheckCardModalV2MinMax,
setCheckCardModalV2CancelAble,
......
......@@ -61,15 +61,15 @@ export function findCardByLocation(
return magics?.inner.find(finder);
}
case ygopro.CardZone.REMOVED: {
const exclusions = judgeSelf(controler, state)
? state.meExclusion
: state.opExclusion;
return exclusions?.inner.find(finder);
const banishedZones = judgeSelf(controler, state)
? state.meBanishedZone
: state.opBanishedZone;
return banishedZones?.inner.find(finder);
}
case ygopro.CardZone.GRAVE: {
const cemerety = judgeSelf(controler, state)
? state.meCemetery
: state.opCemetery;
? state.meGraveyard
: state.opGraveyard;
return cemerety?.inner.find(finder);
}
default: {
......
import { ygopro } from "@/api/ocgcore/idl/ocgcore";
import MsgMove = ygopro.StocGameMessage.MsgMove;
import { fetchCemeteryMeta } from "@/reducers/duel/cemeretySlice";
import { fetchExclusionMeta } from "@/reducers/duel/exclusionSlice";
import { fetchBanishedZoneMeta } from "@/reducers/duel/banishedZoneSlice";
import { fetchGraveyardMeta } from "@/reducers/duel/cemeretySlice";
import { fetchExtraDeckMeta } from "@/reducers/duel/extraDeckSlice";
import { insertHandMeta } from "@/reducers/duel/handsSlice";
import { fetchMagicMeta } from "@/reducers/duel/magicSlice";
import {
removeCemetery,
removeExclusion,
removeBanishedZone,
removeExtraDeck,
removeGraveyard,
removeHand,
removeMagic,
removeMonster,
......@@ -52,14 +52,17 @@ export default (move: MsgMove, dispatch: AppDispatch) => {
}
case ygopro.CardZone.GRAVE: {
dispatch(
removeCemetery({ controler: from.controler, sequence: from.sequence })
removeGraveyard({ controler: from.controler, sequence: from.sequence })
);
break;
}
case ygopro.CardZone.REMOVED: {
dispatch(
removeExclusion({ controler: from.controler, sequence: from.sequence })
removeBanishedZone({
controler: from.controler,
sequence: from.sequence,
})
);
break;
......@@ -128,7 +131,7 @@ export default (move: MsgMove, dispatch: AppDispatch) => {
}
case ygopro.CardZone.GRAVE: {
dispatch(
fetchCemeteryMeta({
fetchGraveyardMeta({
controler: to.controler,
sequence: to.sequence,
code,
......@@ -146,7 +149,7 @@ export default (move: MsgMove, dispatch: AppDispatch) => {
}
case ygopro.CardZone.REMOVED: {
dispatch(
fetchExclusionMeta({
fetchBanishedZoneMeta({
controler: to.controler,
sequence: to.sequence,
code,
......
import { ygopro } from "@/api/ocgcore/idl/ocgcore";
import { Interactivity, InteractType } from "@/reducers/duel/generic";
import {
addCemeteryIdleInteractivities,
addExclusionIdleInteractivities,
addBanishedZoneIdleInteractivities,
addExtraDeckIdleInteractivities,
addGraveyardIdleInteractivities,
addHandsIdleInteractivity,
addMagicIdleInteractivities,
addMonsterIdleInteractivities,
......@@ -83,12 +83,12 @@ export default (selectIdleCmd: MsgSelectIdleCmd, dispatch: AppDispatch) => {
break;
}
case ygopro.CardZone.GRAVE: {
dispatcher(data, interactType, addCemeteryIdleInteractivities);
dispatcher(data, interactType, addGraveyardIdleInteractivities);
break;
}
case ygopro.CardZone.REMOVED: {
dispatcher(data, interactType, addExclusionIdleInteractivities);
dispatcher(data, interactType, addBanishedZoneIdleInteractivities);
break;
}
......
import { ygopro } from "@/api/ocgcore/idl/ocgcore";
import {
infoInit,
initCemetery,
initBanishedZone,
initDeck,
initExclusion,
initGraveyard,
initHint,
initMagics,
initMonsters,
......@@ -40,11 +40,11 @@ export default (
dispatch(initMonsters(1));
dispatch(initMagics(0));
dispatch(initMagics(1));
dispatch(initCemetery(0));
dispatch(initCemetery(1));
dispatch(initGraveyard(0));
dispatch(initGraveyard(1));
dispatch(initDeck({ player: 0, deskSize: start.deckSize1 }));
dispatch(initDeck({ player: 1, deskSize: start.deckSize2 }));
dispatch(initExclusion(0));
dispatch(initExclusion(1));
dispatch(initBanishedZone(0));
dispatch(initBanishedZone(1));
dispatch(initHint());
};
......@@ -3,37 +3,37 @@ import * as BABYLON from "@babylonjs/core";
import { useConfig } from "@/config";
import { useAppSelector } from "@/hook";
import {
selectMeExclusion,
selectopExclusion,
} from "@/reducers/duel/exclusionSlice";
selectMeBanishedZone,
selectOpBanishedZone,
} from "@/reducers/duel/banishedZoneSlice";
import { cardSlotRotation } from "../utils";
import { Depth, SingleSlot } from "./SingleSlot";
const NeosConfig = useConfig();
export const BanishedZone = () => {
const meExclusion = useAppSelector(selectMeExclusion).inner;
const opExclusion = useAppSelector(selectopExclusion).inner;
const meBanishedZone = useAppSelector(selectMeBanishedZone).inner;
const opBanishedZone = useAppSelector(selectOpBanishedZone).inner;
return (
<>
<SingleSlot
state={meExclusion}
position={banishedZonePosition(0, meExclusion.length)}
state={meBanishedZone}
position={banishedZonePosition(0, meBanishedZone.length)}
rotation={cardSlotRotation(false)}
/>
<SingleSlot
state={opExclusion}
position={banishedZonePosition(1, opExclusion.length)}
state={opBanishedZone}
position={banishedZonePosition(1, opBanishedZone.length)}
rotation={cardSlotRotation(true)}
/>
</>
);
};
const banishedZonePosition = (player: number, exclusionLength: number) => {
const banishedZonePosition = (player: number, banishedZoneLength: number) => {
const x = player == 0 ? 3.2 : -3.2;
const y = (Depth * exclusionLength) / 2 + NeosConfig.ui.card.floating;
const y = (Depth * banishedZoneLength) / 2 + NeosConfig.ui.card.floating;
const z = player == 0 ? -0.7 : 0.7;
return new BABYLON.Vector3(x, y, z);
......
......@@ -3,8 +3,8 @@ import * as BABYLON from "@babylonjs/core";
import { useConfig } from "@/config";
import { useAppSelector } from "@/hook";
import {
selectMeCemetery,
selectOpCemetery,
selectMeGraveyard,
selectOpGraveyard,
} from "@/reducers/duel/cemeretySlice";
import { cardSlotRotation } from "../utils";
......@@ -12,28 +12,28 @@ import { Depth, SingleSlot } from "./SingleSlot";
const NeosConfig = useConfig();
export const Graveyard = () => {
const meCemetery = useAppSelector(selectMeCemetery).inner;
const opCemetery = useAppSelector(selectOpCemetery).inner;
const meGraveyard = useAppSelector(selectMeGraveyard).inner;
const opGraveyard = useAppSelector(selectOpGraveyard).inner;
return (
<>
<SingleSlot
state={meCemetery}
position={cemeteryPosition(0, meCemetery.length)}
state={meGraveyard}
position={graveyardPosition(0, meGraveyard.length)}
rotation={cardSlotRotation(false)}
/>
<SingleSlot
state={opCemetery}
position={cemeteryPosition(1, opCemetery.length)}
state={opGraveyard}
position={graveyardPosition(1, opGraveyard.length)}
rotation={cardSlotRotation(true)}
/>
</>
);
};
const cemeteryPosition = (player: number, cemeteryLength: number) => {
const graveyardPosition = (player: number, graveyardLength: number) => {
const x = player == 0 ? 3.2 : -3.2;
const y = (Depth * cemeteryLength) / 2 + NeosConfig.ui.card.floating;
const y = (Depth * graveyardLength) / 2 + NeosConfig.ui.card.floating;
const z = player == 0 ? -2.0 : 2.0;
return new BABYLON.Vector3(x, y, z);
......
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