diff --git a/binaries/data/mods/public/gui/common/functions_global_object.js b/binaries/data/mods/public/gui/common/functions_global_object.js index 5291930059..f896ec8a75 100644 --- a/binaries/data/mods/public/gui/common/functions_global_object.js +++ b/binaries/data/mods/public/gui/common/functions_global_object.js @@ -31,27 +31,3 @@ function displayGamestateNotifications() setTimeout(displayGamestateNotifications, 1000); } - -/** - * This function is called from the engine whenever starting a game fails. - */ -function cancelOnLoadGameError(msg) -{ - Engine.EndGame(); - - if (Engine.HasXmppClient()) - Engine.StopXmppClient(); - - Engine.SwitchGuiPage("page_pregame.xml"); - - if (msg) - Engine.OpenChildPage("page_msgbox.xml", { - "width": 500, - "height": 200, - "message": msg, - "title": translate("Loading Aborted"), - "mode": 2 - }); - - Engine.ResetCursor(); -} diff --git a/binaries/data/mods/public/gui/loading/loading.js b/binaries/data/mods/public/gui/loading/loading.js index 80c95e0f91..f3e217b108 100644 --- a/binaries/data/mods/public/gui/loading/loading.js +++ b/binaries/data/mods/public/gui/loading/loading.js @@ -1,6 +1,6 @@ var g_LoadingPage; -function init(data) +async function init(data) { g_LoadingPage = { "initData": data, @@ -11,14 +11,38 @@ function init(data) }; Engine.SetCursor("cursor-wait"); -} -/** - * This is a reserved function name that is executed by the engine when it is ready - * to start the game (i.e. loading progress has reached 100%). - */ -function reallyStartGame() -{ - Engine.SwitchGuiPage("page_session.xml", g_LoadingPage.initData); - Engine.ResetCursor(); + // reallyStartGame and cancelOnLoadGameError are reserved names that are called by the engine. + // reallyStartGame is called when it is ready to start the game (i.e. loading progress has reached + // 100%). + // cancnelOnLoadGameError is called when there is an error. + return new Promise(closePageCallback => + { + globalThis.reallyStartGame = () => + { + Engine.ResetCursor(); + closePageCallback({ [Engine.openRequest]: { + "page": "page_session.xml", + "argument": data + } }); + }; + globalThis.cancelOnLoadGameError = async() => + { + Engine.ResetCursor(); + Engine.EndGame(); + + if (Engine.HasXmppClient()) + Engine.StopXmppClient(); + + await Engine.OpenChildPage("page_msgbox.xml", { + "width": 500, + "height": 200, + "message": errorMessage, + "title": translate("Loading Aborted"), + "mode": 2 + }); + + closePageCallback({ [Engine.openRequest]: { "page": "page_pregame.xml" } }); + }; + }); }