Move mapsizes to the new simulation settings system. Fixes #3355.
Notice that initMapSizes() confusingly mapped from "LongName" to "names" and from "Name" to "shortnames". Now it's identical in both parts. Also fixes a bug in the summary screen where it would show "Scenario" for a skirmish map. This was SVN commit r17373.
This commit is contained in:
parent
d50075adc4
commit
a98a44875e
@ -3,6 +3,8 @@
|
||||
<objects>
|
||||
|
||||
<script file="gui/common/settings.js"/>
|
||||
|
||||
<!-- After settings.js, which defines g_Settings -->
|
||||
<script file="gui/aiconfig/aiconfig.js"/>
|
||||
|
||||
<!-- Add a translucent black background to fade out the menu page -->
|
||||
|
@ -83,50 +83,6 @@ function escapeText(text)
|
||||
return text.substr(0, 255).replace(/\\/g, "\\\\").replace(/\[/g, "\\[");
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
// Load map size data
|
||||
function initMapSizes()
|
||||
{
|
||||
var sizes = {
|
||||
"shortNames":[],
|
||||
"names":[],
|
||||
"tiles": [],
|
||||
"default": 0
|
||||
};
|
||||
|
||||
var data = Engine.ReadJSONFile("simulation/data/map_sizes.json");
|
||||
if (!data || !data.Sizes)
|
||||
{
|
||||
error("Failed to parse map sizes in map_sizes.json (check for valid JSON data)");
|
||||
return sizes;
|
||||
}
|
||||
|
||||
translateObjectKeys(data, ["Name", "LongName"]);
|
||||
for (var i = 0; i < data.Sizes.length; ++i)
|
||||
{
|
||||
sizes.shortNames.push(data.Sizes[i].Name);
|
||||
sizes.names.push(data.Sizes[i].LongName);
|
||||
sizes.tiles.push(data.Sizes[i].Tiles);
|
||||
|
||||
if (data.Sizes[i].Default)
|
||||
sizes["default"] = i;
|
||||
}
|
||||
|
||||
return sizes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns title or placeholder. Requires g_MapSizes.
|
||||
*
|
||||
* @param mapSize {Number} - tilecount
|
||||
*/
|
||||
function translateMapSize(tiles)
|
||||
{
|
||||
var idx = g_MapSizes.tiles.indexOf(+tiles);
|
||||
return (idx == -1) ? translateWithContext("map size", "Default") : g_MapSizes.shortNames[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns map description and preview image or placeholder.
|
||||
*/
|
||||
|
@ -28,13 +28,13 @@ const g_Settings = loadSettingsValues();
|
||||
*/
|
||||
function loadSettingsValues()
|
||||
{
|
||||
// TODO: move MapSizes from functions_utility.js here
|
||||
var settings = {
|
||||
"AIDescriptions": loadAIDescriptions(),
|
||||
"AIDifficulties": loadAIDifficulties(),
|
||||
"Ceasefire": loadCeasefire(),
|
||||
"GameSpeeds": loadSettingValuesFile("game_speeds.json"),
|
||||
"MapTypes": loadMapTypes(),
|
||||
"MapSizes": loadSettingValuesFile("map_sizes.json"),
|
||||
"PlayerDefaults": loadPlayerDefaults(),
|
||||
"PopulationCapacities": loadPopulationCapacities(),
|
||||
"StartingResources": loadSettingValuesFile("starting_resources.json"),
|
||||
@ -172,7 +172,7 @@ function loadMapTypes()
|
||||
},
|
||||
{
|
||||
"Name": "scenario",
|
||||
"Title": translate("Scenario") // TODO: update the translation (but not shortly before a release)
|
||||
"Title": translateWithContext("map", "Scenario")
|
||||
}
|
||||
];
|
||||
}
|
||||
@ -218,7 +218,7 @@ function loadVictoryConditions()
|
||||
*/
|
||||
function loadPlayerDefaults()
|
||||
{
|
||||
var json = Engine.ReadJSONFile("simulation/data/settings/player_defaults.json");
|
||||
var json = Engine.ReadJSONFile(g_SettingsDirectory + "player_defaults.json");
|
||||
if (!json || !json.PlayerData)
|
||||
{
|
||||
error("Could not load player_defaults.json");
|
||||
@ -311,6 +311,7 @@ function translateAIDifficulty(index)
|
||||
* Returns title or placeholder.
|
||||
*
|
||||
* @param mapType {string} - for example "skirmish"
|
||||
* @returns {string}
|
||||
*/
|
||||
function translateMapType(mapType)
|
||||
{
|
||||
@ -318,10 +319,23 @@ function translateMapType(mapType)
|
||||
return type ? type.Title : translate("Unknown");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns title or placeholder "Default".
|
||||
*
|
||||
* @param mapSize {Number} - tilecount
|
||||
* @returns {string}
|
||||
*/
|
||||
function translateMapSize(tiles)
|
||||
{
|
||||
var mapSize = g_Settings.MapSizes.find(mapSize => mapSize.Tiles == +tiles);
|
||||
return mapSize ? mapSize.Name : translateWithContext("map size", "Default");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns title or placeholder.
|
||||
*
|
||||
* @param population {Number} - for example 300
|
||||
* @returns {string}
|
||||
*/
|
||||
function translatePopulationCapacity(population)
|
||||
{
|
||||
@ -333,6 +347,7 @@ function translatePopulationCapacity(population)
|
||||
* Returns title or placeholder.
|
||||
*
|
||||
* @param gameType {string} - for example "conquest"
|
||||
* @returns {string}
|
||||
*/
|
||||
function translateVictoryCondition(gameType)
|
||||
{
|
||||
|
@ -9,6 +9,7 @@ const DEFAULT_OFFLINE_MAP = "Acropolis 01";
|
||||
|
||||
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_MapSizes = prepareForDropdown(g_Settings ? g_Settings.MapSizes : undefined);
|
||||
const g_MapTypes = prepareForDropdown(g_Settings ? g_Settings.MapTypes : undefined);
|
||||
const g_PopulationCapacities = prepareForDropdown(g_Settings ? g_Settings.PopulationCapacities : undefined);
|
||||
const g_StartingResources = prepareForDropdown(g_Settings ? g_Settings.StartingResources : undefined);
|
||||
@ -53,8 +54,6 @@ var g_GameAttributes = {
|
||||
settings: {}
|
||||
};
|
||||
|
||||
var g_MapSizes = {};
|
||||
|
||||
var g_ChatMessages = [];
|
||||
|
||||
// Data caches
|
||||
@ -119,8 +118,6 @@ function initMain()
|
||||
for (var i = 0; i < g_DefaultPlayerData.length; ++i)
|
||||
g_DefaultPlayerData[i].Civ = "random";
|
||||
|
||||
g_MapSizes = initMapSizes();
|
||||
|
||||
// Init civs
|
||||
initCivNameList();
|
||||
|
||||
@ -234,11 +231,11 @@ function initMain()
|
||||
victoryConditions.selected = g_VictoryConditions.Default;
|
||||
|
||||
var mapSize = Engine.GetGUIObjectByName("mapSize");
|
||||
mapSize.list = g_MapSizes.names;
|
||||
mapSize.list_data = g_MapSizes.tiles;
|
||||
mapSize.list = g_MapSizes.LongName;
|
||||
mapSize.list_data = g_MapSizes.Tiles;
|
||||
mapSize.onSelectionChange = function() {
|
||||
if (this.selected != -1)
|
||||
g_GameAttributes.settings.Size = g_MapSizes.tiles[this.selected];
|
||||
g_GameAttributes.settings.Size = g_MapSizes.Tiles[this.selected];
|
||||
updateGameAttributes();
|
||||
};
|
||||
mapSize.selected = 0;
|
||||
@ -1292,7 +1289,7 @@ function onGameAttributesChange()
|
||||
var gameSpeedBox = Engine.GetGUIObjectByName("gameSpeed");
|
||||
|
||||
// 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 sizeIdx = (mapSettings.Size !== undefined && g_MapSizes.Tiles.indexOf(mapSettings.Size) != -1 ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default);
|
||||
var victoryIdx = mapSettings.GameType !== undefined && g_VictoryConditions.Name.indexOf(mapSettings.GameType) != -1 ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default;
|
||||
enableCheats.checked = (mapSettings.CheatsEnabled === undefined || !mapSettings.CheatsEnabled ? false : true);
|
||||
enableCheatsText.caption = (enableCheats.checked ? translate("Yes") : translate("No"));
|
||||
@ -1365,7 +1362,7 @@ function onGameAttributesChange()
|
||||
{
|
||||
// Client
|
||||
numPlayersText.caption = numPlayers;
|
||||
mapSizeText.caption = g_MapSizes.names[sizeIdx];
|
||||
mapSizeText.caption = g_MapSizes.LongName[sizeIdx];
|
||||
revealMapText.caption = (mapSettings.RevealMap ? translate("Yes") : translate("No"));
|
||||
exploreMapText.caption = (mapSettings.ExporeMap ? translate("Yes") : translate("No"));
|
||||
disableTreasuresText.caption = (mapSettings.DisableTreasures ? translate("Yes") : translate("No"));
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Used for game-filtering and showing details about the selected game. Requirement for translateMapSize.
|
||||
* Used for the gamelist-filtering.
|
||||
*/
|
||||
const g_MapSizes = initMapSizes();
|
||||
const g_MapSizes = prepareForDropdown(g_Settings ? g_Settings.MapSizes : undefined);
|
||||
|
||||
/**
|
||||
* Used for the gamelist-filtering.
|
||||
@ -127,8 +127,8 @@ function returnToMainMenu()
|
||||
function initGameFilters()
|
||||
{
|
||||
var mapSizeFilter = Engine.GetGUIObjectByName("mapSizeFilter");
|
||||
mapSizeFilter.list = [translateWithContext("map size", "Any")].concat(g_MapSizes.shortNames);
|
||||
mapSizeFilter.list_data = [""].concat(g_MapSizes.tiles);
|
||||
mapSizeFilter.list = [translateWithContext("map size", "Any")].concat(g_MapSizes.Name);
|
||||
mapSizeFilter.list_data = [""].concat(g_MapSizes.Tiles);
|
||||
|
||||
var playersArray = Array(g_MaxPlayers).fill(0).map((v, i) => i + 1); // 1, 2, ... MaxPlayers
|
||||
var playersNumberFilter = Engine.GetGUIObjectByName("playersNumberFilter");
|
||||
|
@ -8,6 +8,7 @@
|
||||
<script file="gui/common/settings.js"/>
|
||||
<script file="gui/common/timer.js"/>
|
||||
|
||||
<!-- After settings.js, which defines g_Settings -->
|
||||
<script file="gui/lobby/lobby.js"/>
|
||||
|
||||
<object type="image" style="ModernWindow" size="0 0 100% 100%" name="lobbyWindow">
|
||||
|
@ -53,8 +53,8 @@ function initDateFilter()
|
||||
function initMapSizeFilter()
|
||||
{
|
||||
var mapSizeFilter = Engine.GetGUIObjectByName("mapSizeFilter");
|
||||
mapSizeFilter.list = [translateWithContext("map size", "Any")].concat(g_MapSizes.shortNames);
|
||||
mapSizeFilter.list_data = [-1].concat(g_MapSizes.tiles);
|
||||
mapSizeFilter.list = [translateWithContext("map size", "Any")].concat(g_MapSizes.Name);
|
||||
mapSizeFilter.list_data = [-1].concat(g_MapSizes.Tiles);
|
||||
|
||||
if (mapSizeFilter.selected == -1 || mapSizeFilter.selected >= mapSizeFilter.list.length)
|
||||
mapSizeFilter.selected = 0;
|
||||
|
@ -1,6 +1,17 @@
|
||||
/**
|
||||
* Used for checking replay compability.
|
||||
*/
|
||||
const g_EngineInfo = Engine.GetEngineInfo();
|
||||
|
||||
/**
|
||||
* To show the titles of the selected civs in the replay details.
|
||||
*/
|
||||
const g_CivData = loadCivData();
|
||||
const g_MapSizes = initMapSizes();
|
||||
|
||||
/**
|
||||
* Used for creating the mapsize filter.
|
||||
*/
|
||||
const g_MapSizes = prepareForDropdown(g_Settings ? g_Settings.MapSizes : undefined);
|
||||
|
||||
/**
|
||||
* All replays found in the directory.
|
||||
|
@ -132,31 +132,11 @@ function init(data)
|
||||
updateObjectPlayerPosition();
|
||||
g_GameData = data;
|
||||
|
||||
// Map
|
||||
var mapDisplayType = translate("Scenario");
|
||||
|
||||
var mapSize = data.mapSettings.Size ? g_Settings.MapSizes.find(size => size.Tiles == data.mapSettings.Size) : undefined;
|
||||
var mapType = g_Settings.MapTypes.find(mapType => mapType.Name == data.mapSettings.mapType);
|
||||
Engine.GetGUIObjectByName("timeElapsed").caption = sprintf(translate("Game time elapsed: %(time)s"), { "time": timeToString(data.timeElapsed) });
|
||||
|
||||
Engine.GetGUIObjectByName("summaryText").caption = data.gameResult;
|
||||
|
||||
// This is only defined for random maps
|
||||
if (data.mapSettings.Size)
|
||||
{
|
||||
// load the map sizes from the JSON file
|
||||
var mapSizes = initMapSizes();
|
||||
|
||||
// retrieve the index of the map size
|
||||
for (var mapSizeIndex in mapSizes.tiles)
|
||||
{
|
||||
if (mapSizes.tiles[mapSizeIndex] == data.mapSettings.Size)
|
||||
{
|
||||
mapDisplayType = mapSizes.names[mapSizeIndex];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Engine.GetGUIObjectByName("mapName").caption = sprintf(translate("%(mapName)s - %(mapType)s"), { "mapName": translate(data.mapSettings.Name), "mapType": mapDisplayType });
|
||||
Engine.GetGUIObjectByName("mapName").caption = sprintf(translate("%(mapName)s - %(mapType)s"), { "mapName": translate(data.mapSettings.Name), "mapType": mapSize ? mapSize.LongName : (mapType ? mapType.Title : "") });
|
||||
|
||||
// Panels
|
||||
g_PlayerCount = data.playerStates.length - 1;
|
||||
|
@ -11,6 +11,8 @@
|
||||
<script file="gui/common/functions_civinfo.js"/>
|
||||
<script file="gui/common/functions_utility.js"/>
|
||||
<script file="gui/common/settings.js"/>
|
||||
|
||||
<!-- After settings.js, which defines g_Settings and g_MaxPlayers. -->
|
||||
<script file="gui/summary/counters.js"/>
|
||||
<script file="gui/summary/layout.js"/>
|
||||
<script file="gui/summary/summary.js"/>
|
||||
|
@ -494,7 +494,7 @@
|
||||
{
|
||||
"extractor": "json",
|
||||
"filemasks": [
|
||||
"simulation/data/map_sizes.json"
|
||||
"simulation/data/settings/map_sizes.json"
|
||||
],
|
||||
"options": {
|
||||
"keywords": [
|
||||
|
@ -1,41 +0,0 @@
|
||||
{
|
||||
"Sizes":
|
||||
[
|
||||
{
|
||||
"Name": "Tiny",
|
||||
"LongName": "Tiny",
|
||||
"Tiles": 128
|
||||
},
|
||||
{
|
||||
"Name": "Small",
|
||||
"LongName": "Small (2 players)",
|
||||
"Tiles": 192
|
||||
},
|
||||
{
|
||||
"Name": "Medium",
|
||||
"LongName": "Medium (3 players)",
|
||||
"Tiles": 256,
|
||||
"Default": true
|
||||
},
|
||||
{
|
||||
"Name": "Normal",
|
||||
"LongName": "Normal (4 players)",
|
||||
"Tiles": 320
|
||||
},
|
||||
{
|
||||
"Name": "Large",
|
||||
"LongName": "Large (6 players)",
|
||||
"Tiles": 384
|
||||
},
|
||||
{
|
||||
"Name": "Very Large",
|
||||
"LongName": "Very Large (8 players)",
|
||||
"Tiles": 448
|
||||
},
|
||||
{
|
||||
"Name": "Giant",
|
||||
"LongName": "Giant",
|
||||
"Tiles": 512
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
{
|
||||
"TranslatedKeys": ["Name", "LongName"],
|
||||
"Data":
|
||||
[
|
||||
{
|
||||
"Name": "Tiny",
|
||||
"LongName": "Tiny",
|
||||
"Tiles": 128
|
||||
},
|
||||
{
|
||||
"Name": "Small",
|
||||
"LongName": "Small (2 players)",
|
||||
"Tiles": 192
|
||||
},
|
||||
{
|
||||
"Name": "Medium",
|
||||
"LongName": "Medium (3 players)",
|
||||
"Tiles": 256,
|
||||
"Default": true
|
||||
},
|
||||
{
|
||||
"Name": "Normal",
|
||||
"LongName": "Normal (4 players)",
|
||||
"Tiles": 320
|
||||
},
|
||||
{
|
||||
"Name": "Large",
|
||||
"LongName": "Large (6 players)",
|
||||
"Tiles": 384
|
||||
},
|
||||
{
|
||||
"Name": "Very Large",
|
||||
"LongName": "Very Large (8 players)",
|
||||
"Tiles": 448
|
||||
},
|
||||
{
|
||||
"Name": "Giant",
|
||||
"LongName": "Giant",
|
||||
"Tiles": 512
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user