Commit b3f03bdf authored by Chunchi Che's avatar Chunchi Che

optimize replay navigate

parent 95e5da5f
Pipeline #22617 passed with stages
in 11 minutes and 36 seconds
...@@ -7,6 +7,7 @@ import { fetchCard, ygopro } from "@/api"; ...@@ -7,6 +7,7 @@ import { fetchCard, ygopro } from "@/api";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import { sleep } from "@/infra"; import { sleep } from "@/infra";
import { cardStore, CardType, matStore } from "@/stores"; import { cardStore, CardType, matStore } from "@/stores";
import { replayStart } from "@/ui/Replay";
const TOKEN_SIZE = 13; // 每人场上最多就只可能有13个token const TOKEN_SIZE = 13; // 每人场上最多就只可能有13个token
export default async (start: ygopro.StocGameMessage.MsgStart) => { export default async (start: ygopro.StocGameMessage.MsgStart) => {
...@@ -74,6 +75,10 @@ export default async (start: ygopro.StocGameMessage.MsgStart) => { ...@@ -74,6 +75,10 @@ export default async (start: ygopro.StocGameMessage.MsgStart) => {
.at(ygopro.CardZone.EXTRA, 1 - opponent) .at(ygopro.CardZone.EXTRA, 1 - opponent)
.forEach((card) => (card.code = myExtraDeckCodes.pop() ?? 0)); .forEach((card) => (card.code = myExtraDeckCodes.pop() ?? 0));
if (matStore.isReplay) {
replayStart();
}
// 初始化完后,sleep 1s,让UI初始化完成, // 初始化完后,sleep 1s,让UI初始化完成,
// 否则在和AI对战时,由于后端给传给前端的`MSG`频率太高,会导致一些问题。 // 否则在和AI对战时,由于后端给传给前端的`MSG`频率太高,会导致一些问题。
await sleep(useConfig().startDelay); await sleep(useConfig().startDelay);
......
...@@ -80,6 +80,7 @@ export const matStore: MatState = proxy<MatState>({ ...@@ -80,6 +80,7 @@ export const matStore: MatState = proxy<MatState>({
enableM2: false, // 允许进入M2阶段 enableM2: false, // 允许进入M2阶段
enableEp: false, // 允许回合结束 enableEp: false, // 允许回合结束
}, },
isReplay: false,
unimplemented: 0, unimplemented: 0,
handResults: { handResults: {
me: 0, me: 0,
......
...@@ -28,6 +28,8 @@ export interface MatState { ...@@ -28,6 +28,8 @@ export interface MatState {
phase: PhaseState; phase: PhaseState;
isReplay: boolean; // 是否是回放模式
result?: { result?: {
isWin: boolean; isWin: boolean;
reason: string; reason: string;
......
...@@ -2,17 +2,24 @@ import "../../styles/core.scss"; ...@@ -2,17 +2,24 @@ import "../../styles/core.scss";
import { UploadOutlined } from "@ant-design/icons"; import { UploadOutlined } from "@ant-design/icons";
import { Button, message, Modal, Upload, UploadProps } from "antd"; import { Button, message, Modal, Upload, UploadProps } from "antd";
import React, { useState } from "react"; import React, { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import rustInit from "rust-src"; import rustInit from "rust-src";
import { proxy, useSnapshot } from "valtio";
import { initStrings } from "@/api"; import { initStrings } from "@/api";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import socketMiddleWare, { socketCmd } from "@/middleware/socket"; import socketMiddleWare, { socketCmd } from "@/middleware/socket";
import sqliteMiddleWare, { sqliteCmd } from "@/middleware/sqlite"; import sqliteMiddleWare, { sqliteCmd } from "@/middleware/sqlite";
import { matStore } from "@/stores";
const NeosConfig = useConfig(); const NeosConfig = useConfig();
const localStore = proxy({
hasStart: false,
});
const ReplayModal: React.FC = () => { const ReplayModal: React.FC = () => {
const { hasStart } = useSnapshot(localStore);
const [replay, setReplay] = useState<null | ArrayBuffer>(null); const [replay, setReplay] = useState<null | ArrayBuffer>(null);
const uploadProps: UploadProps = { const uploadProps: UploadProps = {
name: "replay", name: "replay",
...@@ -29,6 +36,13 @@ const ReplayModal: React.FC = () => { ...@@ -29,6 +36,13 @@ const ReplayModal: React.FC = () => {
const navigate = useNavigate(); const navigate = useNavigate();
useEffect(() => {
if (hasStart) {
// 跳转
navigate(`/duel/neos/replay/${NeosConfig.replayUrl}`);
}
}, [hasStart]);
return ( return (
<Modal <Modal
title="选择回放" title="选择回放"
...@@ -38,6 +52,9 @@ const ReplayModal: React.FC = () => { ...@@ -38,6 +52,9 @@ const ReplayModal: React.FC = () => {
if (replay === null) { if (replay === null) {
message.error("请先上传录像文件"); message.error("请先上传录像文件");
} else { } else {
// 标记为回放模式
matStore.isReplay = true;
// 初始化wasm // 初始化wasm
const url = const url =
import.meta.env.BASE_URL === "/" import.meta.env.BASE_URL === "/"
...@@ -70,9 +87,6 @@ const ReplayModal: React.FC = () => { ...@@ -70,9 +87,6 @@ const ReplayModal: React.FC = () => {
// 初始化文案 // 初始化文案
await initStrings(); await initStrings();
// 跳转
navigate(`/duel/neos/replay/${NeosConfig.replayUrl}`);
} }
}} }}
onCancel={() => { onCancel={() => {
...@@ -89,4 +103,8 @@ const ReplayModal: React.FC = () => { ...@@ -89,4 +103,8 @@ const ReplayModal: React.FC = () => {
); );
}; };
export const replayStart = () => {
localStore.hasStart = true;
};
export default ReplayModal; export default ReplayModal;
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