Commit cfd5585e authored by Chunchi Che's avatar Chunchi Che

Merge branch 'fix/valtio' into 'main'

Fix/valtio

See merge request mycard/Neos!174
parents 2aa3893b 4f8fd00d
Pipeline #21411 passed with stages
in 13 minutes and 21 seconds
......@@ -72,7 +72,10 @@ export default (move: MsgMove) => {
case ygopro.CardZone.GRAVE:
case ygopro.CardZone.EXTRA:
case ygopro.CardZone.HAND: {
matStore.in(to.location).of(to.controler).insert(to.sequence, code);
matStore
.in(to.location)
.of(to.controler)
.insert(code, to.sequence, to.position);
break;
}
case ygopro.CardZone.OVERLAY: {
......
......@@ -6,18 +6,6 @@ type MsgShuffleHand = ygopro.StocGameMessage.MsgShuffleHand;
export default (shuffleHand: MsgShuffleHand) => {
const { hands: codes, player: controller } = shuffleHand;
const metas = codes.map((code) => {
return {
occupant: { id: code, data: {}, text: {} },
location: {
controler: controller,
location: ygopro.CardZone.HAND,
},
idleInteractivities: [],
counters: {},
};
});
matStore.hands.of(controller).length = 0;
matStore.hands.of(controller).push(...metas);
matStore.hands.of(controller).add(codes);
};
......@@ -24,11 +24,17 @@ class CardArray extends Array<CardState> implements ArrayCardState {
public __proto__ = CardArray.prototype;
public zone: ygopro.CardZone = ygopro.CardZone.MZONE;
public getController: () => number = () => 1;
private genCard = async (controller: number, id: number) => ({
private genCard = async (
controller: number,
id: number,
position?: ygopro.CardPosition
) => ({
occupant: await fetchCard(id, true),
location: {
controler: controller,
location: this.zone,
position:
position == undefined ? ygopro.CardPosition.FACEUP_ATTACK : position,
},
counters: {},
idleInteractivities: [],
......@@ -37,13 +43,13 @@ class CardArray extends Array<CardState> implements ArrayCardState {
remove(sequence: number) {
this.splice(sequence, 1);
}
async insert(sequence: number, id: number) {
const card = await this.genCard(this.getController(), id);
async insert(sequence: number, id: number, position?: ygopro.CardPosition) {
const card = await this.genCard(this.getController(), id, position);
this.splice(sequence, 0, card);
}
async add(ids: number[]) {
async add(ids: number[], position?: ygopro.CardPosition) {
const cards = await Promise.all(
ids.map(async (id) => this.genCard(this.getController(), id))
ids.map(async (id) => this.genCard(this.getController(), id, position))
);
this.splice(this.length, 0, ...cards);
}
......
......@@ -15,10 +15,14 @@ export interface BothSide<T> {
export interface DuelFieldState extends Array<CardState> {
/** 移除特定位置的卡片 */
remove: (sequence: number) => void;
/** 在末尾添加卡片 */
insert: (sequence: number, id: number) => Promise<void>;
/** 在指定位置插入卡片 */
add: (ids: number[]) => Promise<void>;
insert: (
id: number,
sequence: number,
position?: ygopro.CardPosition
) => Promise<void>;
/** 在末尾添加卡片 */
add: (ids: number[], position?: ygopro.CardPosition) => Promise<void>;
/** 设置占据这个位置的卡片信息 */
setOccupant: (
sequence: number,
......
......@@ -8,6 +8,6 @@ export interface MoraState {
export const moraStore = proxy<MoraState>({
duelStart: false,
selectHandAble: true,
selectTpAble: true,
selectHandAble: false,
selectTpAble: false,
});
......@@ -28,10 +28,6 @@ const { cardModal } = messageStore;
export const CardModal = () => {
const snapCardModal = useSnapshot(cardModal);
// const dispatch = store.dispatch;
// const isOpen = useAppSelector(selectCardModalIsOpen);
// const meta = useAppSelector(selectCardModalMeta);
const isOpen = snapCardModal.isOpen;
const meta = snapCardModal.meta;
......
......@@ -11,12 +11,12 @@ const MsgWin = ygopro.StocGameMessage.MsgWin;
const NeosConfig = useConfig();
export const HintNotification = () => {
const hintState = matStore.hint;
const hintSnap = useSnapshot(matStore.hint);
const snap = useSnapshot(matStore);
const hintState = snap.hint;
const currentPhase = matStore.phase.currentPhase;
const waiting = matStore.waiting;
const result = matStore.result;
const currentPhase = snap.phase.currentPhase;
const waiting = snap.waiting;
const result = snap.result;
const navigate = useNavigate();
......@@ -30,7 +30,7 @@ export const HintNotification = () => {
placement: "bottom",
});
}
}, [hintSnap?.msg]);
}, [hintState.msg]);
useEffect(() => {
if (currentPhase) {
......
......@@ -19,7 +19,8 @@ const {
const Mora = () => {
const snapMora = useSnapshot(moraStore);
const snapMatInitInfo = useSnapshot(matStore.initInfo);
const snapMat = useSnapshot(matStore);
const meLife = snapMat.initInfo.me.life;
const selectHandAble = snapMora.selectHandAble;
const selectTpAble = snapMora.selectTpAble;
......@@ -42,10 +43,10 @@ const Mora = () => {
useEffect(() => {
// 若对局已经开始,自动跳转
if (snapMatInitInfo.me.life > 0) {
if (meLife > 0) {
navigate(`/duel/${player}/${passWd}/${ip}`);
}
}, [snapMatInitInfo.me]);
}, [meLife]);
useEffect(() => {
if (isAiMode) {
......
......@@ -25,7 +25,13 @@ import rustInit from "rust-src";
import { useSnapshot } from "valtio";
import YGOProDeck from "ygopro-deck-encode";
import { initStrings, sendHsReady, sendHsStart, sendUpdateDeck } from "@/api";
import {
initStrings,
sendHsReady,
sendHsStart,
sendUpdateDeck,
ygopro,
} from "@/api";
import { DeckManager, fetchDeck, type IDeck } from "@/api/deck";
import { useConfig } from "@/config";
import socketMiddleWare, { socketCmd } from "@/middleware/socket";
......@@ -137,7 +143,10 @@ const WaitRoom = () => {
const onDeckReady = async (deck: IDeck) => {
sendUpdateDeck(deck);
store.matStore.extraDecks.me.add(deck.extra?.reverse() || []);
store.matStore.extraDecks.me.add(
deck.extra?.reverse() || [],
ygopro.CardPosition.FACEDOWN_ATTACK
);
setChoseDeck(true);
};
......
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