Commit 734de2d9 authored by Chunchi Che's avatar Chunchi Che

update NewMatch

parent 4427068c
Pipeline #22950 passed with stages
in 14 minutes and 5 seconds
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"version":4960, "version":4960,
"servers":[ "servers":[
{ {
"name":"koishi",
"ip":"koishi.momobako.com", "ip":"koishi.momobako.com",
"port":"7211" "port":"7211"
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"version":4960, "version":4960,
"servers":[ "servers":[
{ {
"name":"koishi",
"ip":"koishi-r.momobako.com", "ip":"koishi-r.momobako.com",
"port":"7211" "port":"7211"
} }
......
import { EditFilled, SettingFilled } from "@ant-design/icons"; import { EditFilled, SettingFilled } from "@ant-design/icons";
import { Space } from "antd"; import { Space } from "antd";
import { type LoaderFunction } from "react-router-dom"; import { useEffect, useState } from "react";
import { type LoaderFunction, useNavigate } from "react-router-dom";
import { useSnapshot } from "valtio";
import { CookieKeys, setCookie } from "@/api"; import { CookieKeys, setCookie } from "@/api";
import { accountStore, type User } from "@/stores"; import { useConfig } from "@/config";
import { accountStore, deckStore, IDeck, roomStore, type User } from "@/stores";
import { Background, IconFont, Select } from "@/ui/Shared"; 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";
export const loader: LoaderFunction = () => { export const loader: LoaderFunction = () => {
const sso = new URLSearchParams(location.search).get("sso"); const sso = new URLSearchParams(location.search).get("sso");
...@@ -21,7 +25,26 @@ export const loader: LoaderFunction = () => { ...@@ -21,7 +25,26 @@ export const loader: LoaderFunction = () => {
return null; return null;
}; };
const NeosConfig = useConfig();
export const Component: React.FC = () => { export const Component: React.FC = () => {
const serverList = NeosConfig.servers;
const [server, setServer] = useState(
`${serverList[0].ip}:${serverList[0].port}`
);
const { decks } = useSnapshot(deckStore);
const [deck, setDeck] = useState<IDeck>(JSON.parse(JSON.stringify(decks[0])));
const { user } = useSnapshot(accountStore);
const { joined } = useSnapshot(roomStore);
const navigate = useNavigate();
useEffect(() => {
// 人机对战跳转
if (joined) {
navigate(`/waitroom`);
}
}, [joined]);
return ( return (
<> <>
<Background /> <Background />
...@@ -31,26 +54,35 @@ export const Component: React.FC = () => { ...@@ -31,26 +54,35 @@ export const Component: React.FC = () => {
<Select <Select
title="服务器" title="服务器"
showSearch showSearch
defaultValue="lucy" value={server}
style={{ width: 200 }} style={{ width: 200 }}
options={[ onChange={
{ value: "jack", label: "Jack" }, // @ts-ignore
{ value: "lucy", label: "Lucy" }, (value) => setServer(value)
{ value: "Yiminghe", label: "yiminghe" }, }
{ value: "disabled", label: "Disabled", disabled: true }, options={serverList.map((item) => ({
]} value: `${item.ip}:${item.port}`,
label: item.name,
}))}
/> />
<Select <Select
title="卡组" title="卡组"
showSearch showSearch
defaultValue="lucy" value={deck.deckName}
style={{ width: 200 }} style={{ width: 200 }}
options={[ onChange={(value) => {
{ value: "jack", label: "Jack" }, // @ts-ignore
{ value: "lucy", label: "Lucy" }, const item = deckStore.get(value);
{ value: "Yiminghe", label: "yiminghe" }, if (item) {
{ value: "disabled", label: "Disabled", disabled: true }, setDeck(item);
]} } else {
alert(`Deck ${value} not found`);
}
}}
options={decks.map((deck) => ({
value: deck.deckName,
label: deck.deckName,
}))}
/> />
</Space> </Space>
<div className={styles["mode-select"]}> <div className={styles["mode-select"]}>
...@@ -68,6 +100,16 @@ export const Component: React.FC = () => { ...@@ -68,6 +100,16 @@ export const Component: React.FC = () => {
title="单人模式" title="单人模式"
desc="开启与AI的决斗,验证自己的卡组,或者只是打发时间。" desc="开启与AI的决斗,验证自己的卡组,或者只是打发时间。"
icon={<IconFont type="icon-chip" size={26} />} icon={<IconFont type="icon-chip" size={26} />}
onClick={async () => {
// TODO: 有时间可以做一个Loading
// 初始化,然后等待后端通知成功加入房间后跳转页面
await init({
ip: server,
player: user?.name ?? "Guest",
passWd: "AI",
});
}}
/> />
<Mode <Mode
title="自定义房间" title="自定义房间"
......
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