Commit 29d6bb2e authored by Chunchi Che's avatar Chunchi Che

update handSlice and handRenders but remain bug

parent 7ff008a8
Pipeline #18287 passed with stages
in 2 minutes and 53 seconds
...@@ -17,6 +17,16 @@ export interface CardMeta { ...@@ -17,6 +17,16 @@ export interface CardMeta {
types?: string; types?: string;
desc?: string; desc?: string;
}; };
position?: {
x: number;
y: number;
z: number;
};
rotation?: {
x: number;
y: number;
z: number;
};
} }
/* /*
......
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
import { DuelState } from "./mod"; import { DuelState } from "./mod";
import { RootState } from "../../store"; import { RootState } from "../../store";
import { CardMeta, fetchCard } from "../../api/cards"; import { CardMeta, fetchCard } from "../../api/cards";
import * as UICONFIG from "../../config/ui";
export interface Hands { export interface Hands {
cards: CardMeta[]; cards: CardMeta[];
...@@ -20,11 +21,27 @@ export const meAddHandsImpl: CaseReducer<DuelState, PayloadAction<number[]>> = ( ...@@ -20,11 +21,27 @@ export const meAddHandsImpl: CaseReducer<DuelState, PayloadAction<number[]>> = (
const cards = action.payload.map((id) => { const cards = action.payload.map((id) => {
return { id, data: {}, text: {} }; return { id, data: {}, text: {} };
}); });
if (state.meHands) { if (state.meHands) {
state.meHands.cards = state.meHands.cards.concat(cards); state.meHands.cards = state.meHands.cards.concat(cards);
} else { } else {
state.meHands = { cards }; state.meHands = { cards };
} }
// 更新手牌的位置和旋转信息
const groundShape = UICONFIG.GroundShape();
const handShape = UICONFIG.HandShape();
const gap = groundShape.width / (state.meHands.cards.length - 1);
const left = -(groundShape.width / 2);
state.meHands.cards.forEach((hand, idx, _) => {
hand.position = {
x: left + gap * idx,
y: handShape.height / 2,
z: -(groundShape.height / 2) - 1,
};
hand.rotation = UICONFIG.HandRotation();
});
}; };
// 对手增加手牌 // 对手增加手牌
......
...@@ -3,10 +3,7 @@ import * as CONFIG from "../../../config/ui"; ...@@ -3,10 +3,7 @@ import * as CONFIG from "../../../config/ui";
import { CardMeta } from "../../../api/cards"; import { CardMeta } from "../../../api/cards";
export default (hands: CardMeta[], scene: BABYLON.Scene) => { export default (hands: CardMeta[], scene: BABYLON.Scene) => {
const groundShape = CONFIG.GroundShape();
const handShape = CONFIG.HandShape(); const handShape = CONFIG.HandShape();
const gap = groundShape.width / (hands.length - 1);
const left = -(groundShape.width / 2);
hands.forEach((item, idx, _) => { hands.forEach((item, idx, _) => {
const hand = BABYLON.MeshBuilder.CreatePlane( const hand = BABYLON.MeshBuilder.CreatePlane(
`hand${idx}`, `hand${idx}`,
...@@ -15,11 +12,15 @@ export default (hands: CardMeta[], scene: BABYLON.Scene) => { ...@@ -15,11 +12,15 @@ export default (hands: CardMeta[], scene: BABYLON.Scene) => {
); );
// 位置 // 位置
hand.position = new BABYLON.Vector3( hand.position = new BABYLON.Vector3(
left + gap * idx, item.position?.x,
handShape.height / 2, item.position?.y,
-(groundShape.height / 2) - 1 item.position?.z
);
hand.rotation = new BABYLON.Vector3(
item.rotation?.x,
item.rotation?.y,
item.rotation?.z
); );
hand.rotation = CONFIG.HandRotation();
// 材质 // 材质
const handMaterial = new BABYLON.StandardMaterial("handMaterial", scene); const handMaterial = new BABYLON.StandardMaterial("handMaterial", scene);
// 材质贴纸 // 材质贴纸
......
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