Commit 5020a162 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'optimize/ui/move' into 'main'

Optimize/ui/move

See merge request mycard/Neos!55
parents 451e94e1 a856f58b
Pipeline #18941 passed with stages
in 4 minutes and 11 seconds
import { ygopro } from "../../../idl/ocgcore"; import { ygopro } from "../../../idl/ocgcore";
import { BufferReader } from "../../bufferIO"; import { BufferReader } from "../../bufferIO";
import { cardZoneToNumber, numberToCardZone } from "../../util"; import {
cardZoneToNumber,
numberToCardPosition,
numberToCardZone,
} from "../../util";
import MsgMove = ygopro.StocGameMessage.MsgMove; import MsgMove = ygopro.StocGameMessage.MsgMove;
/* /*
...@@ -28,7 +32,10 @@ export default (data: Uint8Array) => { ...@@ -28,7 +32,10 @@ export default (data: Uint8Array) => {
}); });
if (location != cardZoneToNumber(ygopro.CardZone.OVERLAY)) { if (location != cardZoneToNumber(ygopro.CardZone.OVERLAY)) {
cardLocation.position = ss; const position = numberToCardPosition(ss);
if (position) {
cardLocation.position = position;
}
} else { } else {
cardLocation.overlay_sequence = ss; cardLocation.overlay_sequence = ss;
} }
......
...@@ -156,3 +156,37 @@ export function numberToCardZone( ...@@ -156,3 +156,37 @@ export function numberToCardZone(
} }
} }
} }
export function numberToCardPosition(
position: number
): ygopro.CardPosition | undefined {
switch (position) {
case 0x1: {
return ygopro.CardPosition.FACEUP_ATTACK;
}
case 0x2: {
return ygopro.CardPosition.FACEDOWN_ATTACK;
}
case 0x3: {
return ygopro.CardPosition.ATTACK;
}
case 0x4: {
return ygopro.CardPosition.FACEUP_DEFENSE;
}
case 0x5: {
return ygopro.CardPosition.FACEUP;
}
case 0x8: {
return ygopro.CardPosition.FACEDOWN_DEFENSE;
}
case 0xa: {
return ygopro.CardPosition.FACEDOWN;
}
case 0xc: {
return ygopro.CardPosition.DEFENSE;
}
default: {
return undefined;
}
}
}
...@@ -27,19 +27,22 @@ export const FieldSlotShape = () => { ...@@ -27,19 +27,22 @@ export const FieldSlotShape = () => {
return { width: 0.8, height: 1, depth: 0.2 }; return { width: 0.8, height: 1, depth: 0.2 };
}; };
export const CardSlotRotation = () => { export const CardSlotRotation = () => {
return new BABYLON.Vector3(1.5, 0, 0); return new BABYLON.Vector3(1.55, 0, 0);
};
export const CardSlotDefenceRotation = () => {
return new BABYLON.Vector3(1.55, 1.55, 0);
}; };
export const DeckSlotRotation = () => { export const DeckSlotRotation = () => {
return new BABYLON.Vector3(1.5, 0, 0); return new BABYLON.Vector3(1.55, 0, 0);
}; };
export const CemeterySlotRotation = () => { export const CemeterySlotRotation = () => {
return new BABYLON.Vector3(1.5, 0, 0); return new BABYLON.Vector3(1.55, 0, 0);
}; };
export const ExclusionSlotRotation = () => { export const ExclusionSlotRotation = () => {
return new BABYLON.Vector3(1.5, 0, 0); return new BABYLON.Vector3(1.55, 0, 0);
}; };
export const FieldSlotRotation = () => { export const FieldSlotRotation = () => {
return new BABYLON.Vector3(1.5, 0, 0); return new BABYLON.Vector3(1.55, 0, 0);
}; };
// 浮空 // 浮空
......
...@@ -89,13 +89,20 @@ export const clearMagicSelectInfoImpl: CaseReducer< ...@@ -89,13 +89,20 @@ export const clearMagicSelectInfoImpl: CaseReducer<
// 增加魔法陷阱 // 增加魔法陷阱
export const fetchMagicMeta = createAsyncThunk( export const fetchMagicMeta = createAsyncThunk(
"duel/fetchMagicMeta", "duel/fetchMagicMeta",
async (param: [number, number, number]) => { async (param: {
const controler = param[0]; controler: number;
const sequence = param[1]; sequence: number;
const code = param[2]; position: ygopro.CardPosition;
code: number;
}) => {
const code = param.code;
const meta = await fetchCard(code); const meta = await fetchCard(code);
const response: [number, number, CardMeta] = [controler, sequence, meta]; const response = {
controler: param.controler,
sequence: param.sequence,
meta,
};
return response; return response;
} }
...@@ -104,9 +111,10 @@ export const fetchMagicMeta = createAsyncThunk( ...@@ -104,9 +111,10 @@ export const fetchMagicMeta = createAsyncThunk(
export const magicCase = (builder: ActionReducerMapBuilder<DuelState>) => { export const magicCase = (builder: ActionReducerMapBuilder<DuelState>) => {
builder.addCase(fetchMagicMeta.pending, (state, action) => { builder.addCase(fetchMagicMeta.pending, (state, action) => {
// Meta结果没返回之前先更新`ID` // Meta结果没返回之前先更新`ID`
const controler = action.meta.arg[0]; const controler = action.meta.arg.controler;
const sequence = action.meta.arg[1]; const sequence = action.meta.arg.sequence;
const code = action.meta.arg[2]; const position = action.meta.arg.position;
const code = action.meta.arg.code;
const meta = { id: code, data: {}, text: {} }; const meta = { id: code, data: {}, text: {} };
if (judgeSelf(controler, state)) { if (judgeSelf(controler, state)) {
...@@ -114,6 +122,7 @@ export const magicCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -114,6 +122,7 @@ export const magicCase = (builder: ActionReducerMapBuilder<DuelState>) => {
for (const magic of state.meMagics.magics) { for (const magic of state.meMagics.magics) {
if (magic.sequence == sequence) { if (magic.sequence == sequence) {
magic.occupant = meta; magic.occupant = meta;
magic.position = position;
} }
} }
} }
...@@ -122,15 +131,16 @@ export const magicCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -122,15 +131,16 @@ export const magicCase = (builder: ActionReducerMapBuilder<DuelState>) => {
for (const magic of state.opMagics.magics) { for (const magic of state.opMagics.magics) {
if (magic.sequence == sequence) { if (magic.sequence == sequence) {
magic.occupant = meta; magic.occupant = meta;
magic.position = position;
} }
} }
} }
} }
}); });
builder.addCase(fetchMagicMeta.fulfilled, (state, action) => { builder.addCase(fetchMagicMeta.fulfilled, (state, action) => {
const controler = action.payload[0]; const controler = action.payload.controler;
const sequence = action.payload[1]; const sequence = action.payload.sequence;
const meta = action.payload[2]; const meta = action.payload.meta;
if (judgeSelf(controler, state)) { if (judgeSelf(controler, state)) {
if (state.meMagics) { if (state.meMagics) {
......
...@@ -93,13 +93,20 @@ export const clearMonsterSelectInfoImpl: CaseReducer< ...@@ -93,13 +93,20 @@ export const clearMonsterSelectInfoImpl: CaseReducer<
// 增加怪兽 // 增加怪兽
export const fetchMonsterMeta = createAsyncThunk( export const fetchMonsterMeta = createAsyncThunk(
"duel/fetchMonsterMeta", "duel/fetchMonsterMeta",
async (param: [number, number, number]) => { async (param: {
const controler = param[0]; controler: number;
const sequence = param[1]; sequence: number;
const code = param[2]; position: ygopro.CardPosition;
code: number;
}) => {
const code = param.code;
const meta = await fetchCard(code); const meta = await fetchCard(code);
const response: [number, number, CardMeta] = [controler, sequence, meta]; const response = {
controler: param.controler,
sequence: param.sequence,
meta,
};
return response; return response;
} }
...@@ -108,16 +115,18 @@ export const fetchMonsterMeta = createAsyncThunk( ...@@ -108,16 +115,18 @@ export const fetchMonsterMeta = createAsyncThunk(
export const monsterCase = (builder: ActionReducerMapBuilder<DuelState>) => { export const monsterCase = (builder: ActionReducerMapBuilder<DuelState>) => {
builder.addCase(fetchMonsterMeta.pending, (state, action) => { builder.addCase(fetchMonsterMeta.pending, (state, action) => {
// Meta结果没返回之前先更新`ID` // Meta结果没返回之前先更新`ID`
const controler = action.meta.arg[0]; const controler = action.meta.arg.controler;
const sequence = action.meta.arg[1]; const sequence = action.meta.arg.sequence;
const code = action.meta.arg[2]; const position = action.meta.arg.position;
const code = action.meta.arg.code;
const cardMeta = { id: code, data: {}, text: {} }; const meta = { id: code, data: {}, text: {} };
if (judgeSelf(controler, state)) { if (judgeSelf(controler, state)) {
if (state.meMonsters) { if (state.meMonsters) {
for (const monster of state.meMonsters.monsters) { for (const monster of state.meMonsters.monsters) {
if (monster.sequence == sequence) { if (monster.sequence == sequence) {
monster.occupant = cardMeta; monster.occupant = meta;
monster.position = position;
} }
} }
} }
...@@ -125,16 +134,17 @@ export const monsterCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -125,16 +134,17 @@ export const monsterCase = (builder: ActionReducerMapBuilder<DuelState>) => {
if (state.opMonsters) { if (state.opMonsters) {
for (const monster of state.opMonsters.monsters) { for (const monster of state.opMonsters.monsters) {
if (monster.sequence == sequence) { if (monster.sequence == sequence) {
monster.occupant = cardMeta; monster.occupant = meta;
monster.position = position;
} }
} }
} }
} }
}); });
builder.addCase(fetchMonsterMeta.fulfilled, (state, action) => { builder.addCase(fetchMonsterMeta.fulfilled, (state, action) => {
const controler = action.payload[0]; const controler = action.payload.controler;
const sequence = action.payload[1]; const sequence = action.payload.sequence;
const meta = action.payload[2]; const meta = action.payload.meta;
if (judgeSelf(controler, state)) { if (judgeSelf(controler, state)) {
if (state.meMonsters) { if (state.meMonsters) {
......
...@@ -72,6 +72,7 @@ export interface Interactivity<T> { ...@@ -72,6 +72,7 @@ export interface Interactivity<T> {
export interface SlotState { export interface SlotState {
sequence: number; sequence: number;
occupant?: CardMeta; occupant?: CardMeta;
position?: ygopro.CardPosition;
selectInfo?: Interactivity<{ selectInfo?: Interactivity<{
controler: number; controler: number;
zone: ygopro.CardZone; zone: ygopro.CardZone;
......
...@@ -25,12 +25,26 @@ export default (move: MsgMove, dispatch: AppDispatch) => { ...@@ -25,12 +25,26 @@ export default (move: MsgMove, dispatch: AppDispatch) => {
switch (to.location) { switch (to.location) {
case ygopro.CardZone.MZONE: { case ygopro.CardZone.MZONE: {
dispatch(fetchMonsterMeta([to.controler, to.sequence, code])); dispatch(
fetchMonsterMeta({
controler: to.controler,
sequence: to.sequence,
position: to.position,
code,
})
);
break; break;
} }
case ygopro.CardZone.SZONE: { case ygopro.CardZone.SZONE: {
dispatch(fetchMagicMeta([to.controler, to.sequence, code])); dispatch(
fetchMagicMeta({
controler: to.controler,
sequence: to.sequence,
position: to.position,
code,
})
);
break; break;
} }
......
...@@ -8,6 +8,7 @@ import { useAppSelector } from "../../hook"; ...@@ -8,6 +8,7 @@ import { useAppSelector } from "../../hook";
import { useRef } from "react"; import { useRef } from "react";
import { sendSelectPlaceResponse } from "../../api/ocgcore/ocgHelper"; import { sendSelectPlaceResponse } from "../../api/ocgcore/ocgHelper";
import { clearMagicSelectInfo } from "../../reducers/duel/mod"; import { clearMagicSelectInfo } from "../../reducers/duel/mod";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
// TODO: use config // TODO: use config
const left = -2.15; const left = -2.15;
...@@ -19,7 +20,7 @@ const Magics = () => { ...@@ -19,7 +20,7 @@ const Magics = () => {
return ( return (
<> <>
{magics.map((magic) => { {magics.map((magic) => {
return <CMagic state={magic} />; return <CMagic state={magic} key={magic.sequence} />;
})} })}
</> </>
); );
...@@ -36,6 +37,10 @@ const CMagic = (props: { state: Magic }) => { ...@@ -36,6 +37,10 @@ const CMagic = (props: { state: Magic }) => {
-2.6 -2.6
); );
const rotation = CONFIG.CardSlotRotation(); const rotation = CONFIG.CardSlotRotation();
const faceDown =
state.position === ygopro.CardPosition.FACEDOWN ||
state.position === ygopro.CardPosition.FACEDOWN_ATTACK ||
state.position === ygopro.CardPosition.FACEDOWN_DEFENSE;
const edgesWidth = 2.0; const edgesWidth = 2.0;
const edgesColor = BABYLON.Color4.FromColor3(BABYLON.Color3.Yellow()); const edgesColor = BABYLON.Color4.FromColor3(BABYLON.Color3.Yellow());
const dispatch = store.dispatch; const dispatch = store.dispatch;
...@@ -68,7 +73,13 @@ const CMagic = (props: { state: Magic }) => { ...@@ -68,7 +73,13 @@ const CMagic = (props: { state: Magic }) => {
name={`magic-mat-${props.state.sequence}`} name={`magic-mat-${props.state.sequence}`}
diffuseTexture={ diffuseTexture={
state.occupant state.occupant
? new BABYLON.Texture(`http://localhost:3030/images/card_back.jpg`) ? faceDown
? new BABYLON.Texture(
`http://localhost:3030/images/card_back.jpg`
)
: new BABYLON.Texture(
`https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/${state.occupant.id}.jpg`
)
: new BABYLON.Texture(`http://localhost:3030/images/card_slot.png`) : new BABYLON.Texture(`http://localhost:3030/images/card_slot.png`)
} }
alpha={state.occupant ? 1 : 0} alpha={state.occupant ? 1 : 0}
......
...@@ -9,6 +9,7 @@ import { sendSelectPlaceResponse } from "../../api/ocgcore/ocgHelper"; ...@@ -9,6 +9,7 @@ import { sendSelectPlaceResponse } from "../../api/ocgcore/ocgHelper";
import { clearMonsterSelectInfo } from "../../reducers/duel/mod"; import { clearMonsterSelectInfo } from "../../reducers/duel/mod";
import { useAppSelector } from "../../hook"; import { useAppSelector } from "../../hook";
import { selectMeMonsters } from "../../reducers/duel/monstersSlice"; import { selectMeMonsters } from "../../reducers/duel/monstersSlice";
import { ygopro } from "../../api/ocgcore/idl/ocgcore";
const left = -2.15; // TODO: config const left = -2.15; // TODO: config
const gap = 1.05; const gap = 1.05;
...@@ -34,11 +35,21 @@ const CommonMonster = (props: { state: Monster }) => { ...@@ -34,11 +35,21 @@ const CommonMonster = (props: { state: Monster }) => {
shape.depth / 2 + CONFIG.Floating, shape.depth / 2 + CONFIG.Floating,
-1.35 -1.35
); );
const rotation = CONFIG.CardSlotRotation(); const rotation =
props.state.position === ygopro.CardPosition.DEFENSE ||
props.state.position === ygopro.CardPosition.FACEUP_DEFENSE ||
props.state.position === ygopro.CardPosition.FACEDOWN_DEFENSE
? CONFIG.CardSlotDefenceRotation()
: CONFIG.CardSlotRotation();
const edgesWidth = 2.0; const edgesWidth = 2.0;
const edgesColor = BABYLON.Color4.FromColor3(BABYLON.Color3.Yellow()); const edgesColor = BABYLON.Color4.FromColor3(BABYLON.Color3.Yellow());
const dispatch = store.dispatch; const dispatch = store.dispatch;
const faceDown =
props.state.position === ygopro.CardPosition.FACEDOWN_DEFENSE ||
ygopro.CardPosition.FACEDOWN_ATTACK ||
ygopro.CardPosition.FACEDOWN;
useClick( useClick(
(_event) => { (_event) => {
if (props.state.selectInfo) { if (props.state.selectInfo) {
...@@ -67,9 +78,13 @@ const CommonMonster = (props: { state: Monster }) => { ...@@ -67,9 +78,13 @@ const CommonMonster = (props: { state: Monster }) => {
name={`monster-mat-${props.state.sequence}`} name={`monster-mat-${props.state.sequence}`}
diffuseTexture={ diffuseTexture={
props.state.occupant props.state.occupant
? new BABYLON.Texture( ? faceDown
`https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/${props.state.occupant.id}.jpg` ? new BABYLON.Texture(
) `http://localhost:3030/images/card_back.jpg`
)
: new BABYLON.Texture(
`https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/${props.state.occupant.id}.jpg`
)
: new BABYLON.Texture(`http://localhost:3030/images/card_slot.png`) : new BABYLON.Texture(`http://localhost:3030/images/card_slot.png`)
} }
alpha={props.state.occupant ? 1 : 0} alpha={props.state.occupant ? 1 : 0}
...@@ -91,6 +106,7 @@ const ExtraMonsters = () => { ...@@ -91,6 +106,7 @@ const ExtraMonsters = () => {
{xs.map((x, idx) => ( {xs.map((x, idx) => (
<plane <plane
name={`extra-monster-${idx}`} name={`extra-monster-${idx}`}
key={idx}
position={position(x)} position={position(x)}
rotation={rotation} rotation={rotation}
> >
......
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