Commit f8b686d1 authored by Chunchi Che's avatar Chunchi Che

finsh enter room logic

parent ab0be43d
Pipeline #22930 failed with stages
in 15 minutes and 16 seconds
...@@ -7,7 +7,12 @@ export default function handleHsPlayerEnter(pb: ygopro.YgoStocMsg) { ...@@ -7,7 +7,12 @@ export default function handleHsPlayerEnter(pb: ygopro.YgoStocMsg) {
if (pos > 1) { if (pos > 1) {
console.log("Currently only supported 2v2 mode."); console.log("Currently only supported 2v2 mode.");
} else { } else if (pos < roomStore.players.length) {
roomStore.players[pos].name = name; roomStore.players[pos].name = name;
} else {
roomStore.players.push({
name,
state: ygopro.StocHsPlayerChange.State.NO_READY,
});
} }
} }
...@@ -17,8 +17,13 @@ export default function handleTypeChange(pb: ygopro.YgoStocMsg) { ...@@ -17,8 +17,13 @@ export default function handleTypeChange(pb: ygopro.YgoStocMsg) {
break; break;
} }
default: { default: {
roomStore.players[selfType - 1].state = const player = roomStore.players[selfType - 1];
ygopro.StocHsPlayerChange.State.NO_READY; const state = ygopro.StocHsPlayerChange.State.NO_READY;
if (player) {
player.state = state;
} else {
roomStore.players.push({ name: "?", state });
}
break; break;
} }
} }
......
...@@ -37,7 +37,6 @@ export const Component = () => { ...@@ -37,7 +37,6 @@ export const Component = () => {
<NavLink to="/">主页</NavLink> <NavLink to="/">主页</NavLink>
<NavLink to="/match">匹配</NavLink> <NavLink to="/match">匹配</NavLink>
<NavLink to="/build">组卡</NavLink> <NavLink to="/build">组卡</NavLink>
<NavLink to="/waitroom">waitroom(temp)</NavLink>
<span style={{ flexGrow: 1 }} /> <span style={{ flexGrow: 1 }} />
<span className={styles.profile}> <span className={styles.profile}>
<NeosAvatar /> <NeosAvatar />
......
import { createBrowserRouter, RouterProvider } from "react-router-dom"; import { createBrowserRouter, RouterProvider } from "react-router-dom";
// import LazyLoad, { Loading } from "./LazyLoad";
// const Match = React.lazy(() => import("./Match"));
// const WaitRoom = React.lazy(() => import("./WaitRoom"));
// const Mora = React.lazy(() => import("./Mora"));
// const NeosDuel = React.lazy(() => import("./Duel/Main"));
// const Replay = React.lazy(() => import("./Replay"));
// const SSO = React.lazy(() => import("./SSO"));
// const Profile = React.lazy(() => import("./Profile"));
// const Build = React.lazy(() => import("./Build"));
// TODO: finish this // TODO: finish this
const _router = createBrowserRouter([ const _router = createBrowserRouter([
{ {
...@@ -34,7 +23,7 @@ const _router = createBrowserRouter([ ...@@ -34,7 +23,7 @@ const _router = createBrowserRouter([
lazy: () => import("./NewProfile"), lazy: () => import("./NewProfile"),
}, },
{ {
path: "/waitroom/:ip?/:player?/:passWd?", path: "/waitroom",
lazy: () => import("./NewWaitRoom"), lazy: () => import("./NewWaitRoom"),
}, },
{ {
...@@ -44,41 +33,4 @@ const _router = createBrowserRouter([ ...@@ -44,41 +33,4 @@ const _router = createBrowserRouter([
}, },
]); ]);
// 暂且先这么写,为后重构为createBrowserRouter打基础
// const router = createBrowserRouter(
// createRoutesFromElements(
// <Route path="/" element={<NeosLayout />}>
// <Route path="/" element={<LazyLoad lazy={<Start />} />} />
// <Route path="/profile" element={<LazyLoad lazy={<Profile />} />} />
// <Route path="/match" element={<LazyLoad lazy={<Match />} />} />
// <Route
// path="/room/:player/:passWd/:ip"
// element={
// <Suspense fallback={<Loading />}>
// <WaitRoom />
// </Suspense>
// }
// />
// <Route
// path="/mora/:player/:passWd/:ip"
// element={
// <Suspense fallback={<Loading />}>
// <Mora />
// </Suspense>
// }
// />
// <Route path="/replay" element={<LazyLoad lazy={<Replay />} />} />
// <Route
// path="/duel/:player/:passWd/:ip"
// element={
// <Suspense fallback={<Loading />}>
// <NeosDuel />
// </Suspense>
// }
// />
// <Route path="/sso/*" element={<LazyLoad lazy={<SSO />} />} />
// </Route>
// )
// );
export const NeosRouter = () => <RouterProvider router={_router} />; export const NeosRouter = () => <RouterProvider router={_router} />;
...@@ -4,9 +4,10 @@ import { useNavigate } from "react-router-dom"; ...@@ -4,9 +4,10 @@ import { useNavigate } from "react-router-dom";
import { proxy, useSnapshot } from "valtio"; import { proxy, useSnapshot } from "valtio";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import { accountStore } from "@/stores"; import { accountStore, roomStore } from "@/stores";
import styles from "./Modal.module.scss"; import styles from "./Modal.module.scss";
import { init } from "./util";
const NeosConfig = useConfig(); const NeosConfig = useConfig();
const serverConfig = NeosConfig.servers; const serverConfig = NeosConfig.servers;
...@@ -28,6 +29,7 @@ export const localStore = proxy<Props>(defaultProps); ...@@ -28,6 +29,7 @@ export const localStore = proxy<Props>(defaultProps);
export const MatchModal: React.FC = ({}) => { export const MatchModal: React.FC = ({}) => {
const { open } = useSnapshot(localStore); const { open } = useSnapshot(localStore);
const { user } = useSnapshot(accountStore); const { user } = useSnapshot(accountStore);
const { joined } = useSnapshot(roomStore);
const [player, setPlayer] = useState(user?.name ?? defaultPlayer); const [player, setPlayer] = useState(user?.name ?? defaultPlayer);
const [passwd, setPasswd] = useState(defaultPassword); const [passwd, setPasswd] = useState(defaultPassword);
const [server, setServer] = useState( const [server, setServer] = useState(
...@@ -47,10 +49,9 @@ export const MatchModal: React.FC = ({}) => { ...@@ -47,10 +49,9 @@ export const MatchModal: React.FC = ({}) => {
}; };
// 因为萌卡服务器的房间密码会有`#`等特殊字符,因此这里用`encodeURIComponent`做下转义 // 因为萌卡服务器的房间密码会有`#`等特殊字符,因此这里用`encodeURIComponent`做下转义
const handleSubmit = () => { const handleSubmit = async () => {
setConfirmLoading(true); setConfirmLoading(true);
// TODO: 这里应该进行WASM,websocket等的初始化,成功加入房间后才跳转 await init({ player, ip: server, passWd: passwd });
// navigate(`/room/${player}/${encodeURIComponent(passwd)}/${server}`);
}; };
useEffect(() => { useEffect(() => {
...@@ -60,6 +61,13 @@ export const MatchModal: React.FC = ({}) => { ...@@ -60,6 +61,13 @@ export const MatchModal: React.FC = ({}) => {
} }
}, []); }, []);
useEffect(() => {
// 如果一切顺利的话,后端传来已加入房间的信号,这时候跳转到房间页面
if (joined) {
navigate(`/waitroom`);
}
}, [joined]);
return ( return (
<Modal <Modal
open={open} open={open}
......
...@@ -7,7 +7,7 @@ import sqliteMiddleWare, { sqliteCmd } from "@/middleware/sqlite"; ...@@ -7,7 +7,7 @@ import sqliteMiddleWare, { sqliteCmd } from "@/middleware/sqlite";
const NeosConfig = useConfig(); const NeosConfig = useConfig();
// 进行进入房间的一些初始化操作 // 进行进入房间的一些初始化操作
export const init = async (params: { export const init = async (params: {
ip: string; ip: string;
player: string; player: string;
......
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
} }
} }
.name { .name {
font-size: 14px; font-size: 18px;
color: white; color: white;
z-index: 1; z-index: 1;
} }
......
...@@ -5,11 +5,10 @@ import PlayerState = ygopro.StocHsPlayerChange.State; ...@@ -5,11 +5,10 @@ import PlayerState = ygopro.StocHsPlayerChange.State;
import { Avatar, Button, ConfigProvider, Popover, Skeleton, Space } from "antd"; import { Avatar, Button, ConfigProvider, Popover, Skeleton, Space } from "antd";
import classNames from "classnames"; import classNames from "classnames";
import React, { useState } from "react"; import React, { useState } from "react";
import { type LoaderFunction, useLoaderData } from "react-router-dom";
import { useSnapshot } from "valtio"; import { useSnapshot } from "valtio";
import { useConfig } from "@/config"; import { useConfig } from "@/config";
import { accountStore, Player, roomStore, type User } from "@/stores"; import { accountStore, Player, roomStore } from "@/stores";
import { Background, IconFont, Select } from "@/ui/Shared"; import { Background, IconFont, Select } from "@/ui/Shared";
import { Chat } from "./Chat"; import { Chat } from "./Chat";
...@@ -17,14 +16,6 @@ import styles from "./index.module.scss"; ...@@ -17,14 +16,6 @@ import styles from "./index.module.scss";
const NeosConfig = useConfig(); const NeosConfig = useConfig();
interface Params {
player?: string;
passWd?: string;
ip?: string;
}
export const loader: LoaderFunction = async ({ params }) => params;
const theme = { const theme = {
components: { components: {
Button: { Button: {
...@@ -42,10 +33,10 @@ const theme = { ...@@ -42,10 +33,10 @@ const theme = {
}; };
export const Component: React.FC = () => { export const Component: React.FC = () => {
const _params = useLoaderData<Params>();
const { user } = useSnapshot(accountStore); const { user } = useSnapshot(accountStore);
const [collapsed, setCollapsed] = useState(false); const [collapsed, setCollapsed] = useState(false);
const room = useSnapshot(roomStore); const room = useSnapshot(roomStore);
return ( return (
<ConfigProvider theme={theme}> <ConfigProvider theme={theme}>
<div <div
......
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