[fix] 斷線防呆

This commit is contained in:
建喵 2023-12-07 11:11:52 +08:00
parent 0d8a5acabc
commit 02e35e070e
3 changed files with 10 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import Image from "@/components/Image/Image";
import { useGameItems } from "@/context/GameItemsContext"; import { useGameItems } from "@/context/GameItemsContext";
import { GameLaunchRequest, GameLeaveRequest, RpcGameLaunchResponse } from "@/define/Request/GameRequest"; import { GameLaunchRequest, GameLeaveRequest, RpcGameLaunchResponse } from "@/define/Request/GameRequest";
import { SlotData } from "@/define/gameData"; import { SlotData } from "@/define/gameData";
import GameManager from "@/modules/GameManager";
import { Button, Flex } from "antd"; import { Button, Flex } from "antd";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import SDGame from "./SDGame"; import SDGame from "./SDGame";
@ -34,6 +35,7 @@ const SlotList = () => {
return; return;
} }
setIsGameIn(true); setIsGameIn(true);
GameManager.IsInGame = true;
const url: string = resp.Data; const url: string = resp.Data;
setGameData({ setGameData({
...gameData, ...gameData,
@ -55,6 +57,7 @@ const SlotList = () => {
gameLeaveReq.Send(); gameLeaveReq.Send();
setGameUrl(""); setGameUrl("");
setIsGameIn(false); setIsGameIn(false);
GameManager.IsInGame = false;
} }
useEffect(() => { useEffect(() => {

View File

@ -3,6 +3,8 @@ import SlotData from "./data/SlotData";
class GameManager { class GameManager {
/** SlotData */ /** SlotData */
public readonly SlotData: SlotData = new SlotData(); public readonly SlotData: SlotData = new SlotData();
public IsInGame: boolean = false;
} }
export default new GameManager(); export default new GameManager();

View File

@ -2,9 +2,14 @@ import CSMessage from "@/Common/Message/CSMessage";
import { INetResponse } from "@/Engine/CatanEngine/NetManagerV2/Core/INetResponse"; import { INetResponse } from "@/Engine/CatanEngine/NetManagerV2/Core/INetResponse";
import { gameObj } from "@/context/GameItemsContext"; import { gameObj } from "@/context/GameItemsContext";
import { GameInfoRequest } from "@/define/Request/GameRequest"; import { GameInfoRequest } from "@/define/Request/GameRequest";
import GameManager from "@/modules/GameManager";
export function* gameSync(): IterableIterator<any> { export function* gameSync(): IterableIterator<any> {
const { gameData, setGameData } = gameObj; const { gameData, setGameData } = gameObj;
if (GameManager.IsInGame) {
// 不用同步資料,因為已經在遊戲中,所以不用同步資料。
return;
}
let req: GameInfoRequest = new GameInfoRequest(); let req: GameInfoRequest = new GameInfoRequest();
yield req.SendAsync(); yield req.SendAsync();
let resp: INetResponse<JSON> = req.Result; let resp: INetResponse<JSON> = req.Result;