forked from 0ad/0ad
Move the game speeds to the new simulation settings system. Patch by elexis. Refs #3355
This was SVN commit r17019.
This commit is contained in:
parent
ae3aad704d
commit
e7f736fd0f
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,6 +8,7 @@
|
||||
<script file="gui/common/functions_utility.js"/>
|
||||
<script file="gui/common/l10n.js"/>
|
||||
<script file="gui/common/music.js"/>
|
||||
<script file="gui/common/settings.js"/>
|
||||
<script file="gui/common/timer.js"/>
|
||||
<script file="gui/common/tooltips.js"/>
|
||||
<!-- load all scripts in this directory -->
|
||||
|
@ -453,7 +453,6 @@
|
||||
{
|
||||
"extractor": "json",
|
||||
"filemasks": [
|
||||
"simulation/data/game_speeds.json",
|
||||
"simulation/data/player_defaults.json"
|
||||
],
|
||||
"options": {
|
||||
@ -462,6 +461,15 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"extractor": "json",
|
||||
"filemasks": [
|
||||
"simulation/data/settings/game_speeds.json"
|
||||
],
|
||||
"options": {
|
||||
"keywords": ["Title"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"extractor": "json",
|
||||
"filemasks": [
|
||||
|
@ -1,38 +0,0 @@
|
||||
{
|
||||
"Speeds":
|
||||
[
|
||||
{
|
||||
"Name": "Turtle (0.1x)",
|
||||
"Speed": 0.10
|
||||
},
|
||||
{
|
||||
"Name": "Slow (0.25x)",
|
||||
"Speed": 0.25
|
||||
},
|
||||
{
|
||||
"Name": "Leisurely (0.5x)",
|
||||
"Speed": 0.50
|
||||
},
|
||||
{
|
||||
"Name": "Relaxed (0.75x)",
|
||||
"Speed": 0.75
|
||||
},
|
||||
{
|
||||
"Name": "Normal (1x)",
|
||||
"Speed": 1.0,
|
||||
"Default": true
|
||||
},
|
||||
{
|
||||
"Name": "Fast (1.25x)",
|
||||
"Speed": 1.25
|
||||
},
|
||||
{
|
||||
"Name": "Very Fast (1.5x)",
|
||||
"Speed": 1.5
|
||||
},
|
||||
{
|
||||
"Name": "Insane (2x)",
|
||||
"Speed": 2.0
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
{
|
||||
"TranslatedKeys": ["Title"],
|
||||
"Data":
|
||||
[
|
||||
{
|
||||
"Speed": 0.10,
|
||||
"Title": "Turtle (0.1x)"
|
||||
},
|
||||
{
|
||||
"Speed": 0.25,
|
||||
"Title": "Slow (0.25x)"
|
||||
},
|
||||
{
|
||||
"Speed": 0.50,
|
||||
"Title": "Leisurely (0.5x)"
|
||||
},
|
||||
{
|
||||
"Speed": 0.75,
|
||||
"Title": "Relaxed (0.75x)"
|
||||
},
|
||||
{
|
||||
"Speed": 1.0,
|
||||
"Title": "Normal (1x)",
|
||||
"Default": true
|
||||
},
|
||||
{
|
||||
"Speed": 1.25,
|
||||
"Title": "Fast (1.25x)"
|
||||
},
|
||||
{
|
||||
"Speed": 1.5,
|
||||
"Title": "Very Fast (1.5x)"
|
||||
},
|
||||
{
|
||||
"Speed": 2.0,
|
||||
"Title": "Insane (2x)"
|
||||
},
|
||||
{
|
||||
"Speed": 5.0,
|
||||
"Title": "Fast Forward (5x)",
|
||||
"ReplayOnly": true
|
||||
},
|
||||
{
|
||||
"Speed": 10.0,
|
||||
"Title": "Fast Forward (10x)",
|
||||
"ReplayOnly": true
|
||||
},
|
||||
{
|
||||
"Speed": 20.0,
|
||||
"Title": "Fast Forward (20x)",
|
||||
"ReplayOnly": true
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user