Commit 4366bae1 authored by Chunchi Che's avatar Chunchi Che

handle entertain match in Match.tsx

parent c0d7b98c
Pipeline #23168 passed with stages
in 11 minutes and 13 seconds
...@@ -23,6 +23,6 @@ export default function handleSocketOpen( ...@@ -23,6 +23,6 @@ export default function handleSocketOpen(
ws.binaryType = "arraybuffer"; ws.binaryType = "arraybuffer";
sendPlayerInfo(ws, player); sendPlayerInfo(ws, player);
sendJoinGame(ws, NeosConfig.version, passWd); // todo: version use config sendJoinGame(ws, NeosConfig.version, passWd);
} }
} }
...@@ -7,7 +7,7 @@ import { useConfig } from "@/config"; ...@@ -7,7 +7,7 @@ import { useConfig } from "@/config";
import { accountStore, roomStore } from "@/stores"; import { accountStore, roomStore } from "@/stores";
import styles from "./MatchModal.module.scss"; import styles from "./MatchModal.module.scss";
import { init } from "./util"; import { connectSrvpro } from "./util";
const NeosConfig = useConfig(); const NeosConfig = useConfig();
const serverConfig = NeosConfig.servers; const serverConfig = NeosConfig.servers;
...@@ -50,7 +50,7 @@ export const MatchModal: React.FC = ({}) => { ...@@ -50,7 +50,7 @@ export const MatchModal: React.FC = ({}) => {
const handleSubmit = async () => { const handleSubmit = async () => {
setConfirmLoading(true); setConfirmLoading(true);
await init({ player, ip: server, passWd: passwd }); await connectSrvpro({ player, ip: server, passWd: passwd });
}; };
useEffect(() => { useEffect(() => {
......
...@@ -6,7 +6,7 @@ import { proxy, useSnapshot } from "valtio"; ...@@ -6,7 +6,7 @@ import { proxy, useSnapshot } from "valtio";
import { matStore } from "@/stores"; import { matStore } from "@/stores";
import { Uploader } from "../Shared"; import { Uploader } from "../Shared";
import { init } from "./util"; import { connectSrvpro } from "./util";
const localStore = proxy({ const localStore = proxy({
open: false, open: false,
...@@ -45,7 +45,7 @@ export const ReplayModal: React.FC = () => { ...@@ -45,7 +45,7 @@ export const ReplayModal: React.FC = () => {
// FIXME: 这样写应该不对,有空来修 // FIXME: 这样写应该不对,有空来修
window.myExtraDeckCodes = []; window.myExtraDeckCodes = [];
await init({ await connectSrvpro({
ip: "", ip: "",
player: "", player: "",
passWd: "", passWd: "",
......
...@@ -9,6 +9,7 @@ import { useEffect, useState } from "react"; ...@@ -9,6 +9,7 @@ import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { useSnapshot } from "valtio"; import { useSnapshot } from "valtio";
import { match } from "@/api";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import { accountStore, deckStore, IDeck, roomStore } from "@/stores"; import { accountStore, deckStore, IDeck, roomStore } from "@/stores";
import { Background, IconFont, Select } from "@/ui/Shared"; import { Background, IconFont, Select } from "@/ui/Shared";
...@@ -16,7 +17,7 @@ import { Background, IconFont, Select } from "@/ui/Shared"; ...@@ -16,7 +17,7 @@ import { Background, IconFont, Select } from "@/ui/Shared";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
import { MatchModal, matchStore } from "./MatchModal"; import { MatchModal, matchStore } from "./MatchModal";
import { ReplayModal, replayOpen } from "./ReplayModal"; import { ReplayModal, replayOpen } from "./ReplayModal";
import { init } from "./util"; import { connectSrvpro } from "./util";
const NeosConfig = useConfig(); const NeosConfig = useConfig();
...@@ -30,12 +31,13 @@ export const Component: React.FC = () => { ...@@ -30,12 +31,13 @@ export const Component: React.FC = () => {
const { user } = useSnapshot(accountStore); const { user } = useSnapshot(accountStore);
const { joined } = useSnapshot(roomStore); const { joined } = useSnapshot(roomStore);
const [singleLoading, setSingleLoading] = useState(false); // 单人模式的loading状态 const [singleLoading, setSingleLoading] = useState(false); // 单人模式的loading状态
const [matchLoading, setMatchLoading] = useState(false);
const navigate = useNavigate(); const navigate = useNavigate();
useEffect(() => { useEffect(() => {
// 人机对战跳转
if (joined) { if (joined) {
setSingleLoading(false); setSingleLoading(false);
setMatchLoading(false);
navigate(`/waitroom`); navigate(`/waitroom`);
} }
}, [joined]); }, [joined]);
...@@ -97,8 +99,31 @@ export const Component: React.FC = () => { ...@@ -97,8 +99,31 @@ export const Component: React.FC = () => {
<Mode <Mode
title="娱乐匹配" title="娱乐匹配"
desc="过去一周竞技匹配使用数最靠前的20个卡组被禁止使用。将胜负暂且搁置,尽情享受决斗的乐趣。" desc="过去一周竞技匹配使用数最靠前的20个卡组被禁止使用。将胜负暂且搁置,尽情享受决斗的乐趣。"
icon={<IconFont type="icon-coffee" size={28} />} icon={
onClick={() => alert("开发中,敬请期待")} matchLoading ? (
<LoadingOutlined />
) : (
<IconFont type="icon-coffee" size={28} />
)
}
onClick={async () => {
if (!user) {
alert("请先登录萌卡账号");
} else {
setMatchLoading(true);
const matchInfo = await match(user.name, user.external_id);
if (matchInfo) {
await connectSrvpro({
ip: matchInfo.address + ":" + (matchInfo.port + 1),
player: user.name,
passWd: matchInfo.password,
});
} else {
alert("匹配失败T_T");
}
}
}}
/> />
<Mode <Mode
title="单人模式" title="单人模式"
...@@ -114,7 +139,7 @@ export const Component: React.FC = () => { ...@@ -114,7 +139,7 @@ export const Component: React.FC = () => {
setSingleLoading(true); setSingleLoading(true);
// 初始化,然后等待后端通知成功加入房间后跳转页面 // 初始化,然后等待后端通知成功加入房间后跳转页面
await init({ await connectSrvpro({
ip: server, ip: server,
player: user?.name ?? "Guest", player: user?.name ?? "Guest",
passWd: "AI", passWd: "AI",
......
...@@ -7,8 +7,8 @@ import sqliteMiddleWare, { sqliteCmd } from "@/middleware/sqlite"; ...@@ -7,8 +7,8 @@ import sqliteMiddleWare, { sqliteCmd } from "@/middleware/sqlite";
const NeosConfig = useConfig(); const NeosConfig = useConfig();
// 进行进入房间/回放前的一些初始化操作 // 连接SRVPRO服务
export const init = async (params: { export const connectSrvpro = async (params: {
ip: string; ip: string;
player: string; player: string;
passWd: string; passWd: string;
......
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