Commit dc0d0017 authored by chechunchi's avatar chechunchi

update Exclusion.tsx

parent dd809f69
Pipeline #19447 passed with stages
in 5 minutes and 1 second
...@@ -17,6 +17,7 @@ export const DeckSlotShape = () => { ...@@ -17,6 +17,7 @@ export const DeckSlotShape = () => {
export const ExtraDeckSlotShape = () => { export const ExtraDeckSlotShape = () => {
return { width: 0.8, height: 1, depth: 0.2 }; return { width: 0.8, height: 1, depth: 0.2 };
}; };
export const SingleSlotShape = { width: 0.8, height: 1, depth: 0.2 };
export const CemeterySlotShape = () => { export const CemeterySlotShape = () => {
return { width: 0.8, height: 1, depth: 0.2 }; return { width: 0.8, height: 1, depth: 0.2 };
}; };
......
...@@ -69,5 +69,7 @@ export const exclusionCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -69,5 +69,7 @@ export const exclusionCase = (builder: ActionReducerMapBuilder<DuelState>) => {
}); });
}; };
export const selectMeExclusion = (state: RootState) => state.duel.meExclusion; export const selectMeExclusion = (state: RootState) =>
export const selectopExclusion = (state: RootState) => state.duel.opExclusion; state.duel.meExclusion || { inner: [] };
export const selectopExclusion = (state: RootState) =>
state.duel.opExclusion || { inner: [] };
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 { CardState } from "../../reducers/duel/generic";
import { import {
selectMeCemetery, selectMeCemetery,
selectOpCemetery, selectOpCemetery,
} from "../../reducers/duel/cemeretySlice"; } from "../../reducers/duel/cemeretySlice";
import { store } from "../../store";
import { useAppSelector } from "../../hook"; import { useAppSelector } from "../../hook";
import { useClick } from "./hook"; import SingleSlot from "./singleSlot";
import { useRef } from "react";
import {
setCardListModalInfo,
setCardListModalIsOpen,
} from "../../reducers/duel/mod";
const shape = CONFIG.CemeterySlotShape();
const depth = 0.02; const depth = 0.02;
const Cemeteries = () => { const Cemeteries = () => {
...@@ -23,12 +15,12 @@ const Cemeteries = () => { ...@@ -23,12 +15,12 @@ const Cemeteries = () => {
return ( return (
<> <>
<CCemetery <SingleSlot
state={meCemetery} state={meCemetery}
position={cemeteryPosition(0, meCemetery.length)} position={cemeteryPosition(0, meCemetery.length)}
rotation={CONFIG.CardSlotRotation(false)} rotation={CONFIG.CardSlotRotation(false)}
/> />
<CCemetery <SingleSlot
state={opCemetery} state={opCemetery}
position={cemeteryPosition(1, opCemetery.length)} position={cemeteryPosition(1, opCemetery.length)}
rotation={CONFIG.CardSlotRotation(true)} rotation={CONFIG.CardSlotRotation(true)}
...@@ -37,60 +29,6 @@ const Cemeteries = () => { ...@@ -37,60 +29,6 @@ const Cemeteries = () => {
); );
}; };
const CCemetery = (props: {
state: CardState[];
position: BABYLON.Vector3;
rotation: BABYLON.Vector3;
}) => {
const boxRef = useRef(null);
const dispatch = store.dispatch;
useClick(
(_event) => {
if (props.state.length != 0) {
dispatch(
setCardListModalInfo(
props.state.map((cemetery) => {
return {
name: cemetery.occupant?.text.name,
desc: cemetery.occupant?.text.desc,
imgUrl: `https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/${cemetery.occupant?.id}.jpg`,
};
})
)
);
dispatch(setCardListModalIsOpen(true));
}
},
boxRef,
[props.state]
);
return (
<box
name="cemetery"
ref={boxRef}
scaling={
new BABYLON.Vector3(
shape.width,
shape.height,
depth * props.state.length
)
}
position={props.position}
rotation={props.rotation}
>
<standardMaterial
name="cemetery-mat"
diffuseTexture={
new BABYLON.Texture(`http://localhost:3030/images/card_back.jpg`)
}
alpha={props.state.length == 0 ? 0 : 1}
/>
</box>
);
};
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;
......
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 {
selectMeExclusion,
selectopExclusion,
} from "../../reducers/duel/exclusionSlice";
import SingleSlot from "./singleSlot";
const depth = 0.02;
const Exclusion = () => { const Exclusion = () => {
const shape = CONFIG.ExclusionSlotShape(); const meExclusion = useAppSelector(selectMeExclusion).inner;
const position = new BABYLON.Vector3(3.2, CONFIG.Floating, -0.7); const opExclusion = useAppSelector(selectopExclusion).inner;
const rotation = CONFIG.ExclusionSlotRotation();
return ( return (
<box <>
name="exclusion" <SingleSlot
width={shape.width} state={meExclusion}
height={shape.height} position={exclusionPosition(0, meExclusion.length)}
depth={shape.depth} rotation={CONFIG.CardSlotRotation(false)}
position={position} />
rotation={rotation} <SingleSlot
> state={opExclusion}
<standardMaterial position={exclusionPosition(1, opExclusion.length)}
name="exclusion-mat" rotation={CONFIG.CardSlotRotation(true)}
diffuseColor={CONFIG.ExclusionColor()} />
></standardMaterial> </>
</box>
); );
}; };
const exclusionPosition = (player: number, exclusionLength: number) => {
const x = player == 0 ? 3.2 : -3.2;
const y = (depth * exclusionLength) / 2 + CONFIG.Floating;
const z = player == 0 ? -0.7 : 0.7;
return new BABYLON.Vector3(x, y, z);
};
export default Exclusion; export default Exclusion;
import * as BABYLON from "@babylonjs/core";
import * as CONFIG from "../../config/ui";
import { CardState } from "../../reducers/duel/generic";
import { store } from "../../store";
import { useClick } from "./hook";
import { useRef } from "react";
import {
setCardListModalInfo,
setCardListModalIsOpen,
} from "../../reducers/duel/mod";
const shape = CONFIG.SingleSlotShape;
const depth = 0.02;
const SingleSlot = (props: {
state: CardState[];
position: BABYLON.Vector3;
rotation: BABYLON.Vector3;
}) => {
const boxRef = useRef(null);
const dispatch = store.dispatch;
useClick(
(_event) => {
if (props.state.length != 0) {
dispatch(
setCardListModalInfo(
props.state.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));
}
},
boxRef,
[props.state]
);
return (
<box
name="single-slot"
ref={boxRef}
scaling={
new BABYLON.Vector3(
shape.width,
shape.height,
depth * props.state.length
)
}
position={props.position}
rotation={props.rotation}
>
<standardMaterial
name="single-slot-mat"
diffuseTexture={
new BABYLON.Texture(`http://localhost:3030/images/card_back.jpg`)
}
alpha={props.state.length == 0 ? 0 : 1}
/>
</box>
);
};
export default SingleSlot;
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