Commit 6b2d3fe5 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'feat/deck' into 'main'

Feat/deck

See merge request !72
parents 90419ce0 07f8fde7
Pipeline #19467 passed with stages
in 4 minutes and 18 seconds
import { judgeSelf } from "./util";
import { PayloadAction, CaseReducer } from "@reduxjs/toolkit";
import { DuelState } from "./mod";
import { RootState } from "../../store";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
import { DuelFieldState, CardState } from "./generic";
export interface DeckState extends DuelFieldState {}
// 初始化卡组状态
export const initDeckImpl: CaseReducer<
DuelState,
PayloadAction<{ player: number; deskSize: number }>
> = (state, action) => {
const player = action.payload.player;
const deckSize = action.payload.deskSize;
let deck: CardState[] = new Array(deckSize);
for (let i = 0; i < deckSize; i++) {
deck.push({
occupant: { id: 0, data: {}, text: {} },
location: {
controler: player,
location: ygopro.CardZone.DECK,
sequence: i,
},
idleInteractivities: [],
});
}
if (judgeSelf(player, state)) {
state.meDeck = { inner: deck };
} else {
state.opDeck = { inner: deck };
}
};
export const selectMeDeck = (state: RootState) =>
state.duel.meDeck || { inner: [] };
export const selectOpDeck = (state: RootState) =>
state.duel.opDeck || { inner: [] };
...@@ -61,6 +61,7 @@ import { ...@@ -61,6 +61,7 @@ import {
initExclusionImpl, initExclusionImpl,
exclusionCase, exclusionCase,
} from "./exclusionSlice"; } from "./exclusionSlice";
import { DeckState, initDeckImpl } from "./deckSlice";
export interface DuelState { export interface DuelState {
selfType?: number; selfType?: number;
...@@ -82,6 +83,9 @@ export interface DuelState { ...@@ -82,6 +83,9 @@ export interface DuelState {
meExclusion?: ExclusionState; // 自己的除外区状态 meExclusion?: ExclusionState; // 自己的除外区状态
opExclusion?: ExclusionState; // 对手的除外区状态 opExclusion?: ExclusionState; // 对手的除外区状态
meDeck?: DeckState; // 自己的卡组状态
opDeck?: DeckState; // 对手的卡组状态
meTimeLimit?: TimeLimit; // 自己的计时 meTimeLimit?: TimeLimit; // 自己的计时
opTimeLimit?: TimeLimit; // 对手的计时 opTimeLimit?: TimeLimit; // 对手的计时
...@@ -139,6 +143,9 @@ const duelSlice = createSlice({ ...@@ -139,6 +143,9 @@ const duelSlice = createSlice({
// 除外区相关`Reducer` // 除外区相关`Reducer`
initExclusion: initExclusionImpl, initExclusion: initExclusionImpl,
// 卡组相关`Reducer`
initDeck: initDeckImpl,
// UI相关`Reducer` // UI相关`Reducer`
setCardModalIsOpen: setCardModalIsOpenImpl, setCardModalIsOpen: setCardModalIsOpenImpl,
setCardModalText: setCardModalTextImpl, setCardModalText: setCardModalTextImpl,
...@@ -206,6 +213,7 @@ export const { ...@@ -206,6 +213,7 @@ export const {
resetPositionModal, resetPositionModal,
setOptionModalIsOpen, setOptionModalIsOpen,
resetOptionModal, resetOptionModal,
initDeck,
} = duelSlice.actions; } = duelSlice.actions;
export const selectDuelHsStart = (state: RootState) => { export const selectDuelHsStart = (state: RootState) => {
return state.duel.meInitInfo != null; return state.duel.meInitInfo != null;
......
...@@ -6,6 +6,7 @@ import { ...@@ -6,6 +6,7 @@ import {
initMonsters, initMonsters,
initMagics, initMagics,
initCemetery, initCemetery,
initDeck,
} from "../../reducers/duel/mod"; } from "../../reducers/duel/mod";
export default ( export default (
...@@ -39,4 +40,6 @@ export default ( ...@@ -39,4 +40,6 @@ export default (
dispatch(initMagics(1)); dispatch(initMagics(1));
dispatch(initCemetery(0)); dispatch(initCemetery(0));
dispatch(initCemetery(1)); dispatch(initCemetery(1));
dispatch(initDeck({ player: 0, deskSize: start.deckSize1 }));
dispatch(initDeck({ player: 1, deskSize: start.deckSize2 }));
}; };
...@@ -5,9 +5,7 @@ import { ...@@ -5,9 +5,7 @@ import {
selectOpCemetery, selectOpCemetery,
} from "../../reducers/duel/cemeretySlice"; } from "../../reducers/duel/cemeretySlice";
import { useAppSelector } from "../../hook"; import { useAppSelector } from "../../hook";
import SingleSlot from "./singleSlot"; import SingleSlot, { Depth } from "./singleSlot";
const depth = 0.02;
const Cemeteries = () => { const Cemeteries = () => {
const meCemetery = useAppSelector(selectMeCemetery).inner; const meCemetery = useAppSelector(selectMeCemetery).inner;
...@@ -31,7 +29,7 @@ const Cemeteries = () => { ...@@ -31,7 +29,7 @@ const Cemeteries = () => {
const cemeteryPosition = (player: number, cemeteryLength: number) => { const cemeteryPosition = (player: number, cemeteryLength: number) => {
const x = player == 0 ? 3.2 : -3.2; const x = player == 0 ? 3.2 : -3.2;
const y = (depth * cemeteryLength) / 2 + CONFIG.Floating; const y = (Depth * cemeteryLength) / 2 + CONFIG.Floating;
const z = player == 0 ? -2.0 : 2.0; const z = player == 0 ? -2.0 : 2.0;
return new BABYLON.Vector3(x, y, z); return new BABYLON.Vector3(x, y, z);
......
import * as BABYLON from "@babylonjs/core"; import * as BABYLON from "@babylonjs/core";
import * as CONFIG from "../../config/ui"; import * as CONFIG from "../../config/ui";
import { useAppSelector } from "../../hook";
import { selectMeDeck, selectOpDeck } from "../../reducers/duel/deckSlice";
import SingleSlot, { Depth } from "./singleSlot";
const Deck = () => ( const Deck = () => (
<> <>
...@@ -9,28 +12,22 @@ const Deck = () => ( ...@@ -9,28 +12,22 @@ const Deck = () => (
); );
const CommonDeck = () => { const CommonDeck = () => {
const shape = CONFIG.DeckSlotShape(); const meDeck = useAppSelector(selectMeDeck).inner;
const position = new BABYLON.Vector3( const opDeck = useAppSelector(selectOpDeck).inner;
3.2,
shape.depth / 2 + CONFIG.Floating,
-3.3
);
const rotation = CONFIG.DeckSlotRotation();
return ( return (
<box <>
name="common-deck" <SingleSlot
width={shape.width} state={meDeck}
height={shape.height} position={deckPosition(0, meDeck.length)}
depth={shape.depth} rotation={CONFIG.CardSlotRotation(false)}
position={position}
rotation={rotation}
>
<standardMaterial
name="common-deck-mat"
diffuseColor={CONFIG.DeckColor()}
/> />
</box> <SingleSlot
state={opDeck}
position={deckPosition(1, opDeck.length)}
rotation={CONFIG.CardSlotRotation(true)}
/>
</>
); );
}; };
...@@ -60,4 +57,12 @@ const ExtraDeck = () => { ...@@ -60,4 +57,12 @@ const ExtraDeck = () => {
); );
}; };
const deckPosition = (player: number, deckLength: number) => {
const x = player == 0 ? 3.2 : -3.2;
const y = (Depth * deckLength) / 2 + CONFIG.Floating;
const z = player == 0 ? -3.3 : 3.3;
return new BABYLON.Vector3(x, y, z);
};
export default Deck; export default Deck;
...@@ -5,9 +5,7 @@ import { ...@@ -5,9 +5,7 @@ import {
selectMeExclusion, selectMeExclusion,
selectopExclusion, selectopExclusion,
} from "../../reducers/duel/exclusionSlice"; } from "../../reducers/duel/exclusionSlice";
import SingleSlot from "./singleSlot"; import SingleSlot, { Depth } from "./singleSlot";
const depth = 0.02;
const Exclusion = () => { const Exclusion = () => {
const meExclusion = useAppSelector(selectMeExclusion).inner; const meExclusion = useAppSelector(selectMeExclusion).inner;
...@@ -31,7 +29,7 @@ const Exclusion = () => { ...@@ -31,7 +29,7 @@ const Exclusion = () => {
const exclusionPosition = (player: number, exclusionLength: number) => { const exclusionPosition = (player: number, exclusionLength: number) => {
const x = player == 0 ? 3.2 : -3.2; const x = player == 0 ? 3.2 : -3.2;
const y = (depth * exclusionLength) / 2 + CONFIG.Floating; const y = (Depth * exclusionLength) / 2 + CONFIG.Floating;
const z = player == 0 ? -0.7 : 0.7; const z = player == 0 ? -0.7 : 0.7;
return new BABYLON.Vector3(x, y, z); return new BABYLON.Vector3(x, y, z);
......
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
} from "../../reducers/duel/mod"; } from "../../reducers/duel/mod";
const shape = CONFIG.SingleSlotShape; const shape = CONFIG.SingleSlotShape;
const depth = 0.02; export const Depth = 0.005;
const SingleSlot = (props: { const SingleSlot = (props: {
state: CardState[]; state: CardState[];
...@@ -25,13 +25,17 @@ const SingleSlot = (props: { ...@@ -25,13 +25,17 @@ const SingleSlot = (props: {
if (props.state.length != 0) { if (props.state.length != 0) {
dispatch( dispatch(
setCardListModalInfo( setCardListModalInfo(
props.state.map((item) => { props.state
return { .filter(
name: item.occupant?.text.name, (item) => item.occupant !== undefined && item.occupant.id !== 0
desc: item.occupant?.text.desc, )
imgUrl: `https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/${item.occupant?.id}.jpg`, .map((item) => {
}; return {
}) name: item.occupant?.text.name,
desc: item.occupant?.text.desc,
imgUrl: `https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/${item.occupant?.id}.jpg`,
};
})
) )
); );
dispatch(setCardListModalIsOpen(true)); dispatch(setCardListModalIsOpen(true));
...@@ -49,7 +53,7 @@ const SingleSlot = (props: { ...@@ -49,7 +53,7 @@ const SingleSlot = (props: {
new BABYLON.Vector3( new BABYLON.Vector3(
shape.width, shape.width,
shape.height, shape.height,
depth * props.state.length Depth * props.state.length
) )
} }
position={props.position} position={props.position}
......
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