diff --git a/binaries/data/mods/public/gui/common/functions_utility.js b/binaries/data/mods/public/gui/common/functions_utility.js index b6370023cc..0c531d54fd 100644 --- a/binaries/data/mods/public/gui/common/functions_utility.js +++ b/binaries/data/mods/public/gui/common/functions_utility.js @@ -131,38 +131,6 @@ function initMapSizes() return sizes; } -// ==================================================================== - -// Load game speed data -function initGameSpeeds() -{ - var gameSpeeds = { - "names": [], - "speeds": [], - "default": 0 - }; - - var data = Engine.ReadJSONFile("simulation/data/game_speeds.json"); - if (!data || !data.Speeds) - { - error("Failed to parse game speeds in game_speeds.json (check for valid JSON data)"); - return gameSpeeds; - } - - translateObjectKeys(data, ["Name"]); - for (var i = 0; i < data.Speeds.length; ++i) - { - gameSpeeds.names.push(data.Speeds[i].Name); - gameSpeeds.speeds.push(data.Speeds[i].Speed); - - if (data.Speeds[i].Default) - gameSpeeds["default"] = i; - } - - return gameSpeeds; -} - - // ==================================================================== // Convert integer color values to string (for use in GUI objects) diff --git a/binaries/data/mods/public/gui/common/settings.js b/binaries/data/mods/public/gui/common/settings.js index 1687f3d1f9..d783498db4 100644 --- a/binaries/data/mods/public/gui/common/settings.js +++ b/binaries/data/mods/public/gui/common/settings.js @@ -31,6 +31,7 @@ function loadSettingsValues() { var settings = { "Ceasefire": loadCeasefire(), + "GameSpeeds": loadSettingValuesFile("game_speeds.json"), "PopulationCapacities": loadPopulationCapacities(), "StartingResources": loadSettingValuesFile("starting_resources.json") }; @@ -131,7 +132,7 @@ function prepareForDropdown(settingValues) if (property == "Default") continue; - if (index == 0) + if (!settings[property]) settings[property] = []; // Switch property and index diff --git a/binaries/data/mods/public/gui/gamesetup/gamesetup.js b/binaries/data/mods/public/gui/gamesetup/gamesetup.js index 416b1ee7ae..a384870fc2 100644 --- a/binaries/data/mods/public/gui/gamesetup/gamesetup.js +++ b/binaries/data/mods/public/gui/gamesetup/gamesetup.js @@ -6,6 +6,7 @@ const DEFAULT_OFFLINE_MAP = "Acropolis 01"; const VICTORY_DEFAULTIDX = 1; const g_Ceasefire = prepareForDropdown(g_Settings ? g_Settings.Ceasefire : undefined); +const g_GameSpeeds = prepareForDropdown(g_Settings ? g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly) : undefined); const g_PopulationCapacities = prepareForDropdown(g_Settings ? g_Settings.PopulationCapacities : undefined); const g_StartingResources = prepareForDropdown(g_Settings ? g_Settings.StartingResources : undefined); @@ -45,7 +46,6 @@ var g_GameAttributes = { settings: {} }; -var g_GameSpeeds = {}; var g_MapSizes = {}; var g_AIs = []; @@ -125,7 +125,6 @@ function initMain() for (var i = 0; i < g_DefaultPlayerData.length; ++i) g_DefaultPlayerData[i].Civ = "random"; - g_GameSpeeds = initGameSpeeds(); g_MapSizes = initMapSizes(); // Init civs @@ -183,15 +182,15 @@ function initMain() var gameSpeed = Engine.GetGUIObjectByName("gameSpeed"); gameSpeed.hidden = false; Engine.GetGUIObjectByName("gameSpeedText").hidden = true; - gameSpeed.list = g_GameSpeeds.names; - gameSpeed.list_data = g_GameSpeeds.speeds; + gameSpeed.list = g_GameSpeeds.Title; + gameSpeed.list_data = g_GameSpeeds.Speed; gameSpeed.onSelectionChange = function() { if (this.selected != -1) - g_GameAttributes.gameSpeed = g_GameSpeeds.speeds[this.selected]; + g_GameAttributes.gameSpeed = g_GameSpeeds.Speed[this.selected]; updateGameAttributes(); } - gameSpeed.selected = g_GameSpeeds["default"]; + gameSpeed.selected = g_GameSpeeds.Default; var populationCaps = Engine.GetGUIObjectByName("populationCap"); populationCaps.list = g_PopulationCapacities.Title; @@ -774,7 +773,7 @@ function loadGameAttributes() if (attrs.gameSpeed) { var gameSpeedBox = Engine.GetGUIObjectByName("gameSpeed"); - gameSpeedBox.selected = g_GameSpeeds.speeds.indexOf(attrs.gameSpeed); + gameSpeedBox.selected = g_GameSpeeds.Speed.indexOf(attrs.gameSpeed); } if (!Engine.HasXmppClient()) @@ -1224,7 +1223,6 @@ function onGameAttributesChange() // We have to check for undefined on these properties as not all maps define them. var sizeIdx = (mapSettings.Size !== undefined && g_MapSizes.tiles.indexOf(mapSettings.Size) != -1 ? g_MapSizes.tiles.indexOf(mapSettings.Size) : g_MapSizes["default"]); - var speedIdx = (g_GameAttributes.gameSpeed !== undefined && g_GameSpeeds.speeds.indexOf(g_GameAttributes.gameSpeed) != -1) ? g_GameSpeeds.speeds.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds["default"]; var victories = getVictoryConditions(); var victoryIdx = (mapSettings.GameType !== undefined && victories.data.indexOf(mapSettings.GameType) != -1 ? victories.data.indexOf(mapSettings.GameType) : VICTORY_DEFAULTIDX); enableCheats.checked = (mapSettings.CheatsEnabled === undefined || !mapSettings.CheatsEnabled ? false : true); @@ -1243,8 +1241,10 @@ function onGameAttributesChange() observerLateJoin.checked = g_GameAttributes.settings.ObserverLateJoin; observerLateJoinText.caption = observerLateJoin.checked ? translate("Yes") : translate("No"); - gameSpeedText.caption = g_GameSpeeds.names[speedIdx]; + var speedIdx = g_GameAttributes.gameSpeed !== undefined && g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) != -1 ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.Default; + gameSpeedText.caption = g_GameSpeeds.Title[speedIdx]; gameSpeedBox.selected = speedIdx; + populationCap.selected = mapSettings.PopulationCap !== undefined && g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) != -1 ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default; populationCapText.caption = g_PopulationCapacities.Title[populationCap.selected]; startingResources.selected = mapSettings.StartingResources !== undefined && g_StartingResources.Resources.indexOf(mapSettings.StartingResources) != -1 ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default; diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js index 4d3ef8a39b..1a79a16095 100644 --- a/binaries/data/mods/public/gui/session/session.js +++ b/binaries/data/mods/public/gui/session/session.js @@ -1,3 +1,6 @@ +const g_IsReplay = Engine.IsVisualReplay(); +const g_GameSpeeds = prepareForDropdown(g_Settings ? g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly || g_IsReplay) : undefined); + // Network Mode var g_IsNetworked = false; @@ -13,9 +16,6 @@ var g_Players = []; // Cache the useful civ data var g_CivData = {}; -var g_GameSpeeds = {}; -var g_CurrentSpeed; - var g_PlayerAssignments = { "local": { "name": translate("You"), "player": 1 } }; // Cache dev-mode settings that are frequently or widely used @@ -144,9 +144,15 @@ function GetTechnologyData(technologyName) return g_TechnologyData[technologyName]; } -// Init function init(initData, hotloadData) { + if (!g_Settings) + { + Engine.EndGame(); + Engine.SwitchGuiPage("page_pregame.xml"); + return; + } + if (initData) { g_IsNetworked = initData.isNetworked; // Set network mode @@ -177,13 +183,11 @@ function init(initData, hotloadData) updateTopPanel(); - g_GameSpeeds = initGameSpeeds(); - g_CurrentSpeed = Engine.GetSimRate(); var gameSpeed = Engine.GetGUIObjectByName("gameSpeed"); - gameSpeed.list = g_GameSpeeds.names; - gameSpeed.list_data = g_GameSpeeds.speeds; - var idx = g_GameSpeeds.speeds.indexOf(g_CurrentSpeed); - gameSpeed.selected = idx != -1 ? idx : g_GameSpeeds["default"]; + gameSpeed.list = g_GameSpeeds.Title; + gameSpeed.list_data = g_GameSpeeds.Speed; + var gameSpeedIdx = g_GameSpeeds.Speed.indexOf(Engine.GetSimRate()); + gameSpeed.selected = gameSpeedIdx != -1 ? gameSpeedIdx : g_GameSpeeds.Default; gameSpeed.onSelectionChange = function() { changeGameSpeed(+this.list_data[this.selected]); } initMenuPosition(); // set initial position @@ -400,6 +404,9 @@ var lastTickTime = new Date; */ function onTick() { + if (!g_Settings) + return; + var now = new Date; var tickLength = new Date - lastTickTime; lastTickTime = now; @@ -509,10 +516,7 @@ function changeGameSpeed(speed) { // For non-networked games only if (!g_IsNetworked) - { Engine.SetSimRate(speed); - g_CurrentSpeed = speed; - } } /** diff --git a/binaries/data/mods/public/gui/session/session.xml b/binaries/data/mods/public/gui/session/session.xml index d9ee7da96c..9e2bc57e83 100644 --- a/binaries/data/mods/public/gui/session/session.xml +++ b/binaries/data/mods/public/gui/session/session.xml @@ -8,6 +8,7 @@