Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesetup/Controls/StartGameControl.js
Show All 14 Lines | class StartGameControl | ||||
constructor(netMessages) | constructor(netMessages) | ||||
{ | { | ||||
this.gameLaunchHandlers = new Set(); | this.gameLaunchHandlers = new Set(); | ||||
// This may be read from publicly | // This may be read from publicly | ||||
this.gameStarted = false; | this.gameStarted = false; | ||||
netMessages.registerNetMessageHandler("start", this.switchToLoadingPage.bind(this)); | netMessages.registerNetMessageHandler("start", this.switchToLoadingPage.bind(this)); | ||||
netMessages.registerNetMessageHandler("startfailed", this.switchBack.bind(this)); | |||||
} | } | ||||
registerLaunchGameHandler(handler) | registerLaunchGameHandler(handler) | ||||
{ | { | ||||
this.gameLaunchHandlers.add(handler); | this.gameLaunchHandlers.add(handler); | ||||
} | } | ||||
launchGame() | launchGame() | ||||
{ | { | ||||
this.gameStarted = true; | this.gameStarted = true; | ||||
for (let handler of this.gameLaunchHandlers) | for (let handler of this.gameLaunchHandlers) | ||||
handler(); | handler(); | ||||
if (g_IsNetworked) | if (g_IsNetworked) | ||||
Engine.StartNetworkGame(); | Engine.StartNetworkGame(); | ||||
else | else | ||||
{ | |||||
Engine.StartGame(g_GameAttributes, g_PlayerAssignments.local.player); | Engine.StartGame(g_GameAttributes, g_PlayerAssignments.local.player); | ||||
this.switchToLoadingPage(); | this.switchToLoadingPage(); | ||||
} | } | ||||
} | |||||
switchToLoadingPage() | switchToLoadingPage() | ||||
{ | { | ||||
Engine.SwitchGuiPage("page_loading.xml", { | Engine.PushGuiPage("page_loading.xml", { | ||||
"attribs": g_GameAttributes, | "attribs": g_GameAttributes, | ||||
"playerAssignments": g_PlayerAssignments | "playerAssignments": g_PlayerAssignments | ||||
}); | }); | ||||
} | } | ||||
switchBack(msg) | |||||
{ | |||||
error(sprintf(translate("Game start failed: %s"), | |||||
msg.reason || translate("Unknown reason"))); | |||||
Engine.PopGuiPage(); | |||||
Engine.ResetCursor(); | |||||
} | |||||
} | } |
Wildfire Games · Phabricator