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 {
types?: string;
desc?: string;
};
position?: {
x: number;
y: number;
z: number;
};
rotation?: {
x: number;
y: number;
z: number;
};
}
/*
......
......@@ -7,6 +7,7 @@ import {
import { DuelState } from "./mod";
import { RootState } from "../../store";
import { CardMeta, fetchCard } from "../../api/cards";
import * as UICONFIG from "../../config/ui";
export interface Hands {
cards: CardMeta[];
......@@ -20,11 +21,27 @@ export const meAddHandsImpl: CaseReducer<DuelState, PayloadAction<number[]>> = (
const cards = action.payload.map((id) => {
return { id, data: {}, text: {} };
});
if (state.meHands) {
state.meHands.cards = state.meHands.cards.concat(cards);
} else {
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";
import { CardMeta } from "../../../api/cards";
export default (hands: CardMeta[], scene: BABYLON.Scene) => {
const groundShape = CONFIG.GroundShape();
const handShape = CONFIG.HandShape();
const gap = groundShape.width / (hands.length - 1);
const left = -(groundShape.width / 2);
hands.forEach((item, idx, _) => {
const hand = BABYLON.MeshBuilder.CreatePlane(
`hand${idx}`,
......@@ -15,11 +12,15 @@ export default (hands: CardMeta[], scene: BABYLON.Scene) => {
);
// 位置
hand.position = new BABYLON.Vector3(
left + gap * idx,
handShape.height / 2,
-(groundShape.height / 2) - 1
item.position?.x,
item.position?.y,
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);
// 材质贴纸
......
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