GameSettings: ensure savegameID is either a file name or undefined.

The current code could end up with savegameID being undefined, false, a filename string, or null depending on the code path taken.
Adapt C++ in consequence.
This commit is contained in:
Lancelot de Ferrière
2024-12-31 12:54:21 +01:00
committed by wraitii
parent fba5a23aad
commit a8fc3cf254
4 changed files with 5 additions and 5 deletions
@@ -20,7 +20,7 @@ class GameSettings
}); });
Object.defineProperty(this, "savegameID", { Object.defineProperty(this, "savegameID", {
"value": !!savegameID, "value": savegameID,
}); });
// Load all possible civ data - don't presume that some will be available. // Load all possible civ data - don't presume that some will be available.
@@ -30,7 +30,7 @@ class SetupWindow
const mapCache = new MapCache(); const mapCache = new MapCache();
g_GameSettings = new GameSettings(); g_GameSettings = new GameSettings();
g_GameSettings.init(mapCache, g_IsController ? savedGame : null); g_GameSettings.init(mapCache, g_IsController ? savedGame : undefined);
let netMessages = new NetMessages(); let netMessages = new NetMessages();
@@ -319,7 +319,7 @@ async function handleAuthenticated(message, loadSavedGame)
} }
g_IsConnecting = false; g_IsConnecting = false;
const savegameID = loadSavedGame ? await Engine.PushGuiPage("page_loadgame.xml") : null; const savegameID = loadSavedGame ? await Engine.PushGuiPage("page_loadgame.xml") : undefined;
if (loadSavedGame && !savegameID) if (loadSavedGame && !savegameID)
{ {
@@ -329,7 +329,7 @@ async function handleAuthenticated(message, loadSavedGame)
} }
Engine.SwitchGuiPage("page_gamesetup.xml", { Engine.SwitchGuiPage("page_gamesetup.xml", {
"savedGame": savegameID ?? message.savedGame, "savedGame": savegameID, // Undefined or the savegame ID
"serverName": g_ServerName, "serverName": g_ServerName,
"hasPassword": g_ServerHasPassword "hasPassword": g_ServerHasPassword
}); });
@@ -283,7 +283,7 @@ void StartNetworkGame(const ScriptInterface& scriptInterface, JS::HandleValue sa
JS::RootedValue attribs(rq.cx, attribs1); JS::RootedValue attribs(rq.cx, attribs1);
std::string attributesAsString{Script::StringifyJSON(rq, &attribs)}; std::string attributesAsString{Script::StringifyJSON(rq, &attribs)};
if (savegame.isFalse()) if (savegame.isUndefined())
{ {
g_NetClient->SendStartGameMessage(attributesAsString); g_NetClient->SendStartGameMessage(attributesAsString);
return; return;