JS GUI cleanup.

Mark g_CivData as const and don't use optional arguments at loadCivData.
Translate the infinity symbol in the summary screen.

Refs D829
Reviewed By: s0600204
This was SVN commit r20043.
This commit is contained in:
elexis
2017-08-26 18:53:37 +00:00
parent c4cef0d289
commit b5ea27904d
10 changed files with 27 additions and 35 deletions
@@ -1,7 +1,7 @@
/**
* Load playable civs.
* Display selectable civs only.
*/
const g_CivData = loadCivData(true);
const g_CivData = loadCivData(true, false);
/**
* Initialize the dropdown containing all the available civs.
@@ -3,15 +3,16 @@
*
* @param selectableOnly {boolean} - Only load those which can be selected
* in the gamesetup. Scenario maps might set non-selectable civs.
* @param gaia {boolean} - Whether to include gaia as a mock civ.
*/
function loadCivData(selectableOnly = false)
function loadCivData(selectableOnly, gaia)
{
var civData = {};
var civFiles = Engine.BuildDirEntList("simulation/data/civs/", "*.json", false);
let civData = {};
let civFiles = Engine.BuildDirEntList("simulation/data/civs/", "*.json", false);
for (let filename of civFiles)
{
var data = Engine.ReadJSONFile(filename);
let data = Engine.ReadJSONFile(filename);
if (!data)
continue;
@@ -26,5 +27,8 @@ function loadCivData(selectableOnly = false)
error(filename + " doesn't contain " + prop);
}
if (gaia)
civData.gaia = { "Code": "gaia", "Name": translate("Gaia") };
return civData;
}
@@ -10,6 +10,12 @@ const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.Starting
const g_VictoryConditions = prepareForDropdown(g_Settings && g_Settings.VictoryConditions);
const g_VictoryDurations = prepareForDropdown(g_Settings && g_Settings.VictoryDurations);
/**
* Offer users to select playable civs only.
* Load unselectable civs as they could appear in scenario maps.
*/
const g_CivData = loadCivData(false, false);
/**
* Highlight the "random" dropdownlist item.
*/
@@ -56,12 +62,6 @@ var g_PlayerTeamList = prepareForDropdown([{
)
);
/**
* Offer users to select playable civs only.
* Load unselectable civs as they could appear in scenario maps.
*/
var g_CivData = loadCivData();
/**
* Number of relics: [1, ..., NumCivs]
*/
@@ -1,14 +1,6 @@
var g_SelectedCiv = "";
var g_CallbackSet = false;
/**
* Initialises civ data. Not done automatically in case a page doesn't want it.
*/
function init_civs()
{
g_CivData = loadCivData(true);
}
function closePage()
{
if (g_CallbackSet)
@@ -8,9 +8,9 @@ const g_AuraPath = "simulation/data/auras/";
* Raw Data Caches.
*/
var g_AuraData = {};
var g_CivData = {};
var g_TemplateData = {};
var g_TechnologyData = {};
var g_CivData = loadCivData(true, false);
/**
* Parsed Data Stores.
@@ -18,8 +18,6 @@ function init(data = {})
if (data.callback)
g_CallbackSet = true;
init_civs();
let civList = Object.keys(g_CivData).map(civ => ({
"name": g_CivData[civ].Name,
"code": civ,
@@ -6,7 +6,7 @@ const g_EngineInfo = Engine.GetEngineInfo();
/**
* Needed for formatPlayerInfo to show the player civs in the details.
*/
const g_CivData = loadCivData();
const g_CivData = loadCivData(false, false);
/**
* Used for creating the mapsize filter.
@@ -3,7 +3,7 @@ var g_SavedGamesMetadata = [];
/**
* Needed for formatPlayerInfo to show the player civs in the details.
*/
const g_CivData = loadCivData();
const g_CivData = loadCivData(false, false);
function init()
{
@@ -1,5 +1,7 @@
const g_IsReplay = Engine.IsVisualReplay();
const g_CivData = loadCivData(false, true);
const g_Ceasefire = prepareForDropdown(g_Settings && g_Settings.Ceasefire);
const g_GameSpeeds = prepareForDropdown(g_Settings && g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly || g_IsReplay));
const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.MapSizes);
@@ -103,11 +105,6 @@ var g_LastTickTime = Date.now();
*/
const g_StatusBarUpdate = 200;
/**
* Not constant as we add "gaia".
*/
var g_CivData = {};
/**
* For restoring selection, order and filters when returning to the replay menu
*/
@@ -277,9 +274,6 @@ function init(initData, hotloadData)
updatePlayerData();
g_CivData = loadCivData();
g_CivData.gaia = { "Code": "gaia", "Name": translate("Gaia") };
g_BarterSell = g_ResourceData.GetCodes()[0];
initializeMusic(); // before changing the perspective
@@ -1,3 +1,5 @@
const g_CivData = loadCivData(false, false);
const g_MaxHeadingTitle= 9;
// const for filtering long collective headings
@@ -97,9 +99,11 @@ var g_SummaryTypes = {
}
};
const g_InfinitySymbol = "\u221E";
/**
* Translation: Unicode encoded infinity symbol indicating a division by zero in the summary screen.
*/
var g_InfinitySymbol = translate("\u221E");
var g_CivData = loadCivData();
var g_Teams = [];
// TODO set g_PlayerCount as playerCounters.length