Commit e2380147 authored by Chunchi Che's avatar Chunchi Che

Merge branch 'dev/hot-reload' into 'main'

Dev/hot reload

See merge request !378
parents a5b8d43b 8bf56875
......@@ -28,3 +28,5 @@ yarn-error.log*
# scss type
*.module.scss.d.ts
*.yrp3d
This diff is collapsed.
import React, { useEffect } from "react";
import { LoaderFunction, useNavigate } from "react-router-dom";
import { LoaderFunction, useNavigate, useSearchParams } from "react-router-dom";
import { useSnapshot } from "valtio";
import { ygopro } from "@/api";
import { AudioActionType, changeScene } from "@/infra/audio";
import { matStore, SideStage, sideStore } from "@/stores";
......@@ -23,6 +24,7 @@ import { AnnounceModal } from "./Message/AnnounceModal";
import { LifeBar, Mat, Menu, Underlying } from "./PlayMat";
import { ChatBox } from "./PlayMat/ChatBox";
import { HandChain } from "./PlayMat/HandChain";
import { useEnv } from "@/hook";
export const loader: LoaderFunction = async () => {
// 更新场景
......@@ -35,6 +37,21 @@ export const Component: React.FC = () => {
const { duelEnd } = useSnapshot(matStore);
const navigate = useNavigate();
// 如果处于开发时的本地文件回放模式,则重新跳回Match且保持record参数,从而开始下一轮播放
const [searchParams] = useSearchParams();
const { DEV } = useEnv();
useEffect(() => {
if (!DEV) return;
const recordName = searchParams.get("record");
if (
searchParams &&
matStore.selfType === ygopro.StocTypeChange.SelfType.UNKNOWN
) {
navigate(`/match?record=${recordName}`);
}
}, []);
useEffect(() => {
if (stage === SideStage.SIDE_CHANGING) {
// 跳转更换Side
......
import { Button, message, Modal, UploadProps } from "antd";
import { Button, message, Modal, type UploadProps } from "antd";
import React, { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { useNavigate, useSearchParams } from "react-router-dom";
import { proxy, useSnapshot } from "valtio";
import { replayStore } from "@/stores";
import { Uploader } from "../../Shared";
import { connectSrvpro } from "../util";
import { useEnv } from "@/hook";
const localStore = proxy({
open: false,
......@@ -38,26 +39,34 @@ export const ReplayModal: React.FC = () => {
} else {
setLoading(true);
// 标记为回放模式
replayStore.isReplay = true;
await connectSrvpro({
ip: "",
player: "",
passWd: "",
replay: true,
replayData: replay,
});
await launchReplay(replay);
}
};
// 开发时的回放模式:路径跳转到duel
const [searchParams] = useSearchParams();
const { DEV } = useEnv();
const recordName = searchParams.get("record");
// 如处于回放模式且有回放文件,则导入播放
useEffect(() => {
if (!DEV) return;
if (recordName) {
import(
/* @vite-ignore */ `../../../../neos-assets/records/${recordName}.yrp3d?arraybuffer`
)
.then((res) => launchReplay(res.default))
.catch(() => console.error(`Local record '${recordName}' not found`));
}
}, []);
useEffect(() => {
if (hasStart) {
setLoading(false);
localStore.open = false;
localStore.hasStart = false;
// 跳转
navigate(`/duel`);
navigate(recordName ? `/duel?record=${recordName}` : "/duel");
}
}, [hasStart]);
......@@ -91,3 +100,17 @@ export const replayOpen = () => {
export const replayStart = () => {
localStore.hasStart = true;
};
/** 单独抽离出来,以便可以在 Match.tsx 中调用,跳过Modal直接加载回放,便于开发 */
export const launchReplay = async (replayData: ArrayBuffer) => {
// 标记为回放模式
replayStore.isReplay = true;
await connectSrvpro({
ip: "",
player: "",
passWd: "",
replay: true,
replayData,
});
};
......@@ -36,6 +36,7 @@
},
"include": [
"src",
"rust-src/pkg"
"rust-src/pkg",
"neos-assets"
]
}
......@@ -6,6 +6,7 @@ import tsconfigPaths from "vite-tsconfig-paths";
import wasmPack from "vite-plugin-wasm-pack";
import sassDts from "vite-plugin-sass-dts";
import path from "path";
import arraybuffer from "vite-plugin-arraybuffer";
// https://vitejs.dev/config/
export default defineConfig({
......@@ -13,6 +14,7 @@ export default defineConfig({
react(),
svgr(),
ydkLoader(),
arraybuffer(),
tsconfigPaths(),
wasmPack("./rust-src"),
sassDts({
......
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