Commit 4f8fd00d authored by Chunchi Che's avatar Chunchi Che

fix move.ts

parent 7b1fabba
Pipeline #21410 passed with stages
in 15 minutes and 30 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: {
......
......@@ -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,
......
......@@ -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