mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-18 22:42:46 +00:00
created prestart message: add 2 second delay before starting public games to allow all players to connect
This commit is contained in:
@@ -21,7 +21,7 @@ import {
|
||||
WinUpdate,
|
||||
} from "../core/game/GameUpdates";
|
||||
import { GameView, PlayerView, UnitView } from "../core/game/GameView";
|
||||
import { loadTerrainMap } from "../core/game/TerrainMapLoader";
|
||||
import { loadTerrainMap, TerrainMapData } from "../core/game/TerrainMapLoader";
|
||||
import { UserSettings } from "../core/game/UserSettings";
|
||||
import { WorkerClient } from "../core/worker/WorkerClient";
|
||||
import { InputHandler, MouseMoveEvent, MouseUpEvent } from "./InputHandler";
|
||||
@@ -60,7 +60,8 @@ export interface LobbyConfig {
|
||||
|
||||
export function joinLobby(
|
||||
lobbyConfig: LobbyConfig,
|
||||
onjoin: () => void,
|
||||
onPrestart: () => void,
|
||||
onJoin: () => void,
|
||||
): () => void {
|
||||
const eventBus = new EventBus();
|
||||
initRemoteSender(eventBus);
|
||||
@@ -78,15 +79,28 @@ export function joinLobby(
|
||||
consolex.log(`Joined game lobby ${lobbyConfig.gameID}`);
|
||||
transport.joinGame(0);
|
||||
};
|
||||
let terrainLoad: Promise<TerrainMapData> | null = null;
|
||||
|
||||
const onmessage = (message: ServerMessage) => {
|
||||
if (message.type == "prestart") {
|
||||
consolex.log(`lobby: game prestarting: ${JSON.stringify(message)}`);
|
||||
terrainLoad = loadTerrainMap(message.gameMap);
|
||||
onPrestart();
|
||||
}
|
||||
if (message.type == "start") {
|
||||
// Trigger prestart for singleplayer games
|
||||
onPrestart();
|
||||
consolex.log(`lobby: game started: ${JSON.stringify(message)}`);
|
||||
onjoin();
|
||||
onJoin();
|
||||
// For multiplayer games, GameStartInfo is not known until game starts.
|
||||
lobbyConfig.gameStartInfo = message.gameStartInfo;
|
||||
createClientGame(lobbyConfig, eventBus, transport, userSettings).then(
|
||||
(r) => r.start(),
|
||||
);
|
||||
createClientGame(
|
||||
lobbyConfig,
|
||||
eventBus,
|
||||
transport,
|
||||
userSettings,
|
||||
terrainLoad,
|
||||
).then((r) => r.start());
|
||||
}
|
||||
};
|
||||
transport.connect(onconnect, onmessage);
|
||||
@@ -101,15 +115,19 @@ export async function createClientGame(
|
||||
eventBus: EventBus,
|
||||
transport: Transport,
|
||||
userSettings: UserSettings,
|
||||
terrainLoad: Promise<TerrainMapData> | null,
|
||||
): Promise<ClientGameRunner> {
|
||||
const config = await getConfig(
|
||||
lobbyConfig.gameStartInfo.config,
|
||||
userSettings,
|
||||
);
|
||||
let gameMap: TerrainMapData | null = null;
|
||||
|
||||
const gameMap = await loadTerrainMap(
|
||||
lobbyConfig.gameStartInfo.config.gameMap,
|
||||
);
|
||||
if (terrainLoad) {
|
||||
gameMap = await terrainLoad;
|
||||
} else {
|
||||
gameMap = await loadTerrainMap(lobbyConfig.gameStartInfo.config.gameMap);
|
||||
}
|
||||
const worker = new WorkerClient(
|
||||
lobbyConfig.gameStartInfo,
|
||||
lobbyConfig.clientID,
|
||||
|
||||
Reference in New Issue
Block a user