Commit b33802fc authored by chechunchi's avatar chechunchi

update hands

parent dc0d0017
Pipeline #19448 passed with stages
in 5 minutes and 33 seconds
...@@ -8,13 +8,10 @@ import { DuelState } from "./mod"; ...@@ -8,13 +8,10 @@ import { DuelState } from "./mod";
import { RootState } from "../../store"; import { RootState } from "../../store";
import { fetchCard, CardMeta } from "../../api/cards"; import { fetchCard, CardMeta } from "../../api/cards";
import { judgeSelf } from "./util"; import { judgeSelf } from "./util";
import { CardState, Interactivity } from "./generic"; import { Interactivity, DuelFieldState } from "./generic";
import { ygopro } from "../../api/ocgcore/idl/ocgcore"; import { ygopro } from "../../api/ocgcore/idl/ocgcore";
export interface HandState { export interface HandState extends DuelFieldState {}
// 注意:手牌的位置顺序是有约束的
hands: CardState[];
}
// 增加手牌 // 增加手牌
export const fetchHandsMeta = createAsyncThunk( export const fetchHandsMeta = createAsyncThunk(
...@@ -57,15 +54,15 @@ export const handsCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -57,15 +54,15 @@ export const handsCase = (builder: ActionReducerMapBuilder<DuelState>) => {
}); });
if (judgeSelf(player, state)) { if (judgeSelf(player, state)) {
if (state.meHands) { if (state.meHands) {
state.meHands.hands = state.meHands.hands.concat(cards); state.meHands.inner = state.meHands.inner.concat(cards);
} else { } else {
state.meHands = { hands: cards }; state.meHands = { inner: cards };
} }
} else { } else {
if (state.opHands) { if (state.opHands) {
state.opHands.hands = state.opHands.hands.concat(cards); state.opHands.inner = state.opHands.inner.concat(cards);
} else { } else {
state.opHands = { hands: cards }; state.opHands = { inner: cards };
} }
} }
}); });
...@@ -76,7 +73,7 @@ export const handsCase = (builder: ActionReducerMapBuilder<DuelState>) => { ...@@ -76,7 +73,7 @@ export const handsCase = (builder: ActionReducerMapBuilder<DuelState>) => {
const hands = judgeSelf(player, state) ? state.meHands : state.opHands; const hands = judgeSelf(player, state) ? state.meHands : state.opHands;
if (hands) { if (hands) {
for (let hand of hands.hands) { for (let hand of hands.inner) {
for (let meta of metas) { for (let meta of metas) {
if (hand.occupant?.id === meta.id) { if (hand.occupant?.id === meta.id) {
hand.occupant = meta; hand.occupant = meta;
...@@ -97,7 +94,7 @@ export const clearHandsIdleInteractivityImpl: CaseReducer< ...@@ -97,7 +94,7 @@ export const clearHandsIdleInteractivityImpl: CaseReducer<
const hands = judgeSelf(player, state) ? state.meHands : state.opHands; const hands = judgeSelf(player, state) ? state.meHands : state.opHands;
if (hands) { if (hands) {
for (let hand of hands.hands) { for (let hand of hands.inner) {
hand.idleInteractivities = []; hand.idleInteractivities = [];
} }
} }
...@@ -119,7 +116,7 @@ export const addHandsIdleInteractivityImpl: CaseReducer< ...@@ -119,7 +116,7 @@ export const addHandsIdleInteractivityImpl: CaseReducer<
const sequence = action.payload.sequence; const sequence = action.payload.sequence;
const interactivity = action.payload.interactivity; const interactivity = action.payload.interactivity;
hands.hands[sequence].idleInteractivities.push(interactivity); hands.inner[sequence].idleInteractivities.push(interactivity);
} }
}; };
...@@ -133,13 +130,13 @@ export const removeHandImpl: CaseReducer< ...@@ -133,13 +130,13 @@ 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.hands = hands.hands.filter( hands.inner = hands.inner.filter(
(card) => card.location.sequence != sequence (card) => card.location.sequence != sequence
); );
} }
}; };
export const selectMeHands = (state: RootState) => export const selectMeHands = (state: RootState) =>
state.duel.meHands || { hands: [] }; state.duel.meHands || { inner: [] };
export const selectOpHands = (state: RootState) => export const selectOpHands = (state: RootState) =>
state.duel.opHands || { hands: [] }; state.duel.opHands || { inner: [] };
...@@ -22,9 +22,9 @@ const handShape = CONFIG.HandShape(); ...@@ -22,9 +22,9 @@ const handShape = CONFIG.HandShape();
const handRotation = CONFIG.HandRotation(); const handRotation = CONFIG.HandRotation();
const Hands = () => { const Hands = () => {
const meHands = useAppSelector(selectMeHands).hands; const meHands = useAppSelector(selectMeHands).inner;
const meHandPositions = handPositons(0, meHands); const meHandPositions = handPositons(0, meHands);
const opHands = useAppSelector(selectOpHands).hands; const opHands = useAppSelector(selectOpHands).inner;
const opHandPositions = handPositons(1, opHands); const opHandPositions = handPositons(1, opHands);
return ( return (
......
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