Commit 5e1e0834 authored by chechunchi's avatar chechunchi

remove sequence in CardState

parent d521a1cd
Pipeline #19505 passed with stages
in 5 minutes and 7 seconds
...@@ -22,7 +22,6 @@ export const initDeckImpl: CaseReducer< ...@@ -22,7 +22,6 @@ export const initDeckImpl: CaseReducer<
location: { location: {
controler: player, controler: player,
location: ygopro.CardZone.DECK, location: ygopro.CardZone.DECK,
sequence: i,
}, },
idleInteractivities: [], idleInteractivities: [],
}); });
......
...@@ -20,7 +20,6 @@ export const initFieldImpl: CaseReducer<DuelState, PayloadAction<number>> = ( ...@@ -20,7 +20,6 @@ export const initFieldImpl: CaseReducer<DuelState, PayloadAction<number>> = (
inner: { inner: {
location: { location: {
controler: player, controler: player,
sequence: 0,
location: ygopro.CardZone.ONFIELD, location: ygopro.CardZone.ONFIELD,
}, },
idleInteractivities: [], idleInteractivities: [],
...@@ -31,7 +30,6 @@ export const initFieldImpl: CaseReducer<DuelState, PayloadAction<number>> = ( ...@@ -31,7 +30,6 @@ export const initFieldImpl: CaseReducer<DuelState, PayloadAction<number>> = (
inner: { inner: {
location: { location: {
controler: player, controler: player,
sequence: 0,
location: ygopro.CardZone.ONFIELD, location: ygopro.CardZone.ONFIELD,
}, },
idleInteractivities: [], idleInteractivities: [],
......
...@@ -12,7 +12,6 @@ export interface CardState { ...@@ -12,7 +12,6 @@ export interface CardState {
location: { location: {
controler: number; controler: number;
location?: number; location?: number;
sequence: number;
position?: ygopro.CardPosition; position?: ygopro.CardPosition;
overlay_sequence?: number; overlay_sequence?: number;
}; // 位置信息 }; // 位置信息
...@@ -97,12 +96,11 @@ export function extendOccupant<T extends DuelFieldState>( ...@@ -97,12 +96,11 @@ export function extendOccupant<T extends DuelFieldState>(
position?: ygopro.CardPosition position?: ygopro.CardPosition
) { ) {
if (state) { if (state) {
for (const item of state.inner) { const target = state.inner.find((_, idx) => idx == sequence);
if (item.location.sequence == sequence) { if (target) {
item.occupant = newMeta; target.occupant = newMeta;
if (position) { if (position) {
item.location.position = position; target.location.position = position;
}
} }
} }
} }
...@@ -114,10 +112,9 @@ export function extendMeta<T extends DuelFieldState>( ...@@ -114,10 +112,9 @@ export function extendMeta<T extends DuelFieldState>(
sequence: number sequence: number
) { ) {
if (state) { if (state) {
for (const item of state.inner) { const target = state.inner.find((_, idx) => idx == sequence);
if (item.location.sequence == sequence) { if (target) {
item.occupant = newMeta; target.occupant = newMeta;
}
} }
} }
} }
...@@ -129,17 +126,16 @@ export function extendPlaceInteractivity<T extends DuelFieldState>( ...@@ -129,17 +126,16 @@ export function extendPlaceInteractivity<T extends DuelFieldState>(
zone: ygopro.CardZone zone: ygopro.CardZone
) { ) {
if (state) { if (state) {
for (let item of state.inner) { const target = state.inner.find((_, idx) => idx == sequence);
if (item.location.sequence == sequence) { if (target) {
item.placeInteractivities = { target.placeInteractivities = {
interactType: InteractType.PLACE_SELECTABLE, interactType: InteractType.PLACE_SELECTABLE,
response: { response: {
controler, controler,
zone, zone,
sequence, sequence,
}, },
}; };
}
} }
} }
} }
......
...@@ -130,9 +130,7 @@ export const removeHandImpl: CaseReducer< ...@@ -130,9 +130,7 @@ export const removeHandImpl: CaseReducer<
const hands = judgeSelf(controler, state) ? state.meHands : state.opHands; const hands = judgeSelf(controler, state) ? state.meHands : state.opHands;
if (hands) { if (hands) {
hands.inner = hands.inner.filter( hands.inner = hands.inner.filter((_, idx) => idx != sequence);
(card) => card.location.sequence != sequence
);
} }
}; };
......
...@@ -14,6 +14,7 @@ const Field = () => { ...@@ -14,6 +14,7 @@ const Field = () => {
{meField ? ( {meField ? (
<FixedSlot <FixedSlot
state={meField} state={meField}
sequence={0}
position={fieldPosition(0)} position={fieldPosition(0)}
rotation={CONFIG.CardSlotRotation(false)} rotation={CONFIG.CardSlotRotation(false)}
/> />
...@@ -23,6 +24,7 @@ const Field = () => { ...@@ -23,6 +24,7 @@ const Field = () => {
{opField ? ( {opField ? (
<FixedSlot <FixedSlot
state={opField} state={opField}
sequence={0}
position={fieldPosition(1)} position={fieldPosition(1)}
rotation={CONFIG.CardSlotRotation(true)} rotation={CONFIG.CardSlotRotation(true)}
/> />
......
...@@ -18,6 +18,7 @@ const shape = CONFIG.CardSlotShape(); ...@@ -18,6 +18,7 @@ const shape = CONFIG.CardSlotShape();
const FixedSlot = (props: { const FixedSlot = (props: {
state: CardState; state: CardState;
sequence: number;
position: BABYLON.Vector3; position: BABYLON.Vector3;
rotation: BABYLON.Vector3; rotation: BABYLON.Vector3;
deffenseRotation?: BABYLON.Vector3; deffenseRotation?: BABYLON.Vector3;
...@@ -67,7 +68,7 @@ const FixedSlot = (props: { ...@@ -67,7 +68,7 @@ const FixedSlot = (props: {
return ( return (
<plane <plane
name={`fixedslot-${props.state.location.sequence}`} name={`fixedslot-${props.sequence}`}
ref={planeRef} ref={planeRef}
width={shape.width} width={shape.width}
height={shape.height} height={shape.height}
...@@ -83,7 +84,7 @@ const FixedSlot = (props: { ...@@ -83,7 +84,7 @@ const FixedSlot = (props: {
edgesColor={edgesColor} edgesColor={edgesColor}
> >
<standardMaterial <standardMaterial
name={`fixedslot-mat-${props.state.location.sequence}`} name={`fixedslot-mat-${props.sequence}`}
diffuseTexture={ diffuseTexture={
props.state.occupant props.state.occupant
? faceDown ? faceDown
......
...@@ -19,21 +19,23 @@ const Magics = () => { ...@@ -19,21 +19,23 @@ const Magics = () => {
return ( return (
<> <>
{zip(meMagics, meMagicPositions).map(([magic, position]) => { {zip(meMagics, meMagicPositions).map(([magic, position], sequence) => {
return ( return (
<FixedSlot <FixedSlot
state={magic} state={magic}
key={magic.location.sequence} key={sequence}
sequence={sequence}
position={position} position={position}
rotation={CONFIG.CardSlotRotation(false)} rotation={CONFIG.CardSlotRotation(false)}
/> />
); );
})} })}
{zip(opMagics, opMagicPositions).map(([magic, position]) => { {zip(opMagics, opMagicPositions).map(([magic, position], sequence) => {
return ( return (
<FixedSlot <FixedSlot
state={magic} state={magic}
key={magic.location.sequence} key={sequence}
sequence={sequence}
position={position} position={position}
rotation={CONFIG.CardSlotRotation(true)} rotation={CONFIG.CardSlotRotation(true)}
/> />
...@@ -49,9 +51,7 @@ const magicPositions = (player: number, magics: CardState[]) => { ...@@ -49,9 +51,7 @@ const magicPositions = (player: number, magics: CardState[]) => {
const y = shape.depth / 2 + CONFIG.Floating; const y = shape.depth / 2 + CONFIG.Floating;
const z = player == 0 ? -2.6 : 2.6; const z = player == 0 ? -2.6 : 2.6;
return magics.map( return magics.map((_, sequence) => new BABYLON.Vector3(x(sequence), y, z));
(magic) => new BABYLON.Vector3(x(magic.location.sequence), y, z)
);
}; };
export default Magics; export default Magics;
...@@ -22,28 +22,34 @@ const Monsters = () => { ...@@ -22,28 +22,34 @@ const Monsters = () => {
return ( return (
<> <>
{zip(meMonsters, meMonsterPositions).map(([monster, position], idx) => { {zip(meMonsters, meMonsterPositions).map(
return ( ([monster, position], sequence) => {
<FixedSlot return (
state={monster} <FixedSlot
key={idx} state={monster}
position={position} key={sequence}
rotation={CONFIG.CardSlotRotation(false)} sequence={sequence}
deffenseRotation={CONFIG.CardSlotDefenceRotation()} position={position}
/> rotation={CONFIG.CardSlotRotation(false)}
); deffenseRotation={CONFIG.CardSlotDefenceRotation()}
})} />
{zip(opMonsters, opMonsterPositions).map(([monster, position], idx) => { );
return ( }
<FixedSlot )}
state={monster} {zip(opMonsters, opMonsterPositions).map(
key={idx} ([monster, position], sequence) => {
position={position} return (
rotation={CONFIG.CardSlotRotation(true)} <FixedSlot
deffenseRotation={CONFIG.CardSlotDefenceRotation()} state={monster}
/> key={sequence}
); sequence={sequence}
})} position={position}
rotation={CONFIG.CardSlotRotation(true)}
deffenseRotation={CONFIG.CardSlotDefenceRotation()}
/>
);
}
)}
<ExtraMonsters /> <ExtraMonsters />
<ExtraMonsters /> <ExtraMonsters />
</> </>
...@@ -86,9 +92,7 @@ const monsterPositions = (player: number, monsters: CardState[]) => { ...@@ -86,9 +92,7 @@ const monsterPositions = (player: number, monsters: CardState[]) => {
const y = shape.depth / 2 + CONFIG.Floating; const y = shape.depth / 2 + CONFIG.Floating;
const z = player == 0 ? -1.35 : 1.35; const z = player == 0 ? -1.35 : 1.35;
return monsters.map( return monsters.map((_, sequence) => new BABYLON.Vector3(x(sequence), y, z));
(monster) => new BABYLON.Vector3(x(monster.location.sequence), y, z)
);
}; };
export default Monsters; export default Monsters;
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