Ticket #3355: t3355_move_game_speeds_v1.patch

File t3355_move_game_speeds_v1.patch, 15.9 KB (added by elexis, 9 years ago)
  • binaries/data/mods/public/gui/common/functions_utility.js

     
    131131    return sizes;
    132132}
    133133
    134134// ====================================================================
    135135
    136 // Load game speed data
    137 function initGameSpeeds()
    138 {
    139     var gameSpeeds = {
    140         "names": [],
    141         "speeds": [],
    142         "default": 0
    143     };
    144 
    145     var data = Engine.ReadJSONFile("simulation/data/game_speeds.json");
    146     if (!data || !data.Speeds)
    147     {
    148         error("Failed to parse game speeds in game_speeds.json (check for valid JSON data)");
    149         return gameSpeeds;
    150     }
    151 
    152     translateObjectKeys(data, ["Name"]);
    153     for (var i = 0; i < data.Speeds.length; ++i)
    154     {
    155         gameSpeeds.names.push(data.Speeds[i].Name);
    156         gameSpeeds.speeds.push(data.Speeds[i].Speed);
    157 
    158         if (data.Speeds[i].Default)
    159             gameSpeeds["default"] = i;
    160     }
    161 
    162     return gameSpeeds;
    163 }
    164 
    165 
    166 // ====================================================================
    167 
    168136// Convert integer color values to string (for use in GUI objects)
    169137function rgbToGuiColor(color, alpha)
    170138{
    171139    var ret;
    172140    if (color && ("r" in color) && ("g" in color) && ("b" in color))
  • binaries/data/mods/public/gui/common/settings.js

     
    2929 */
    3030function loadSettingsValues()
    3131{
    3232    var settings = {
    3333        "Ceasefire": loadCeasefire(),
     34        "GameSpeeds": loadSettingValuesFile("game_speeds.json"),
    3435        "PopulationCapacities": loadPopulationCapacities(),
    3536        "StartingResources": loadSettingValuesFile("starting_resources.json")
    3637    };
    3738
    3839    if (Object.keys(settings).some(key => settings[key] === undefined))
     
    129130        for (let property in settingValues[index])
    130131        {
    131132            if (property == "Default")
    132133                continue;
    133134
    134             if (index == 0)
     135            if (!(property in settings))
    135136                settings[property] = [];
    136137
    137138            // Switch property and index
    138139            settings[property][index] = settingValues[index][property];
    139140        }
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    44const DEFAULT_OFFLINE_MAP = "Acropolis 01";
    55
    66const VICTORY_DEFAULTIDX = 1;
    77
    88const g_Ceasefire = prepareForDropdown(g_Settings ? g_Settings.Ceasefire : undefined);
     9const g_GameSpeeds = prepareForDropdown(g_Settings ? g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly) : undefined);
    910const g_PopulationCapacities = prepareForDropdown(g_Settings ? g_Settings.PopulationCapacities : undefined);
    1011const g_StartingResources = prepareForDropdown(g_Settings ? g_Settings.StartingResources : undefined);
    1112
    1213////////////////////////////////////////////////////////////////////////////////////////////////
    1314
     
    4344var g_DefaultPlayerData = [];
    4445var g_GameAttributes = {
    4546    settings: {}
    4647};
    4748
    48 var g_GameSpeeds = {};
    4949var g_MapSizes = {};
    5050
    5151var g_AIs = [];
    5252
    5353var g_ChatMessages = [];
     
    123123    g_DefaultPlayerData = initPlayerDefaults();
    124124    g_DefaultPlayerData.shift();
    125125    for (var i = 0; i < g_DefaultPlayerData.length; ++i)
    126126        g_DefaultPlayerData[i].Civ = "random";
    127127
    128     g_GameSpeeds = initGameSpeeds();
    129128    g_MapSizes = initMapSizes();
    130129
    131130    // Init civs
    132131    initCivNameList();
    133132
     
    181180        numPlayersSelection.selected = g_MaxPlayers - 1;
    182181
    183182        var gameSpeed = Engine.GetGUIObjectByName("gameSpeed");
    184183        gameSpeed.hidden = false;
    185184        Engine.GetGUIObjectByName("gameSpeedText").hidden = true;
    186         gameSpeed.list = g_GameSpeeds.names;
    187         gameSpeed.list_data = g_GameSpeeds.speeds;
     185        gameSpeed.list = g_GameSpeeds.Title;
     186        gameSpeed.list_data = g_GameSpeeds.Speed;
    188187        gameSpeed.onSelectionChange = function() {
    189188            if (this.selected != -1)
    190                 g_GameAttributes.gameSpeed = g_GameSpeeds.speeds[this.selected];
     189                g_GameAttributes.gameSpeed = g_GameSpeeds.Speed[this.selected];
    191190
    192191            updateGameAttributes();
    193192        }
    194         gameSpeed.selected = g_GameSpeeds["default"];
     193        gameSpeed.selected = g_GameSpeeds.Default;
    195194
    196195        var populationCaps = Engine.GetGUIObjectByName("populationCap");
    197196        populationCaps.list = g_PopulationCapacities.Title;
    198197        populationCaps.list_data = g_PopulationCapacities.Population;
    199198        populationCaps.selected = g_PopulationCapacities.Default;
     
    772771    }
    773772
    774773    if (attrs.gameSpeed)
    775774    {
    776775        var gameSpeedBox = Engine.GetGUIObjectByName("gameSpeed");
    777         gameSpeedBox.selected = g_GameSpeeds.speeds.indexOf(attrs.gameSpeed);
     776        gameSpeedBox.selected = g_GameSpeeds.Speed.indexOf(attrs.gameSpeed);
    778777    }
    779778
    780779    if (!Engine.HasXmppClient())
    781780    {
    782781        g_GameAttributes.settings.RatingEnabled = false;
     
    12221221    var gameSpeedText = Engine.GetGUIObjectByName("gameSpeedText");
    12231222    var gameSpeedBox = Engine.GetGUIObjectByName("gameSpeed");
    12241223
    12251224    // We have to check for undefined on these properties as not all maps define them.
    12261225    var sizeIdx = (mapSettings.Size !== undefined && g_MapSizes.tiles.indexOf(mapSettings.Size) != -1 ? g_MapSizes.tiles.indexOf(mapSettings.Size) : g_MapSizes["default"]);
    1227     var speedIdx = (g_GameAttributes.gameSpeed !== undefined && g_GameSpeeds.speeds.indexOf(g_GameAttributes.gameSpeed) != -1) ? g_GameSpeeds.speeds.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds["default"];
    12281226    var victories = getVictoryConditions();
    12291227    var victoryIdx = (mapSettings.GameType !== undefined && victories.data.indexOf(mapSettings.GameType) != -1 ? victories.data.indexOf(mapSettings.GameType) : VICTORY_DEFAULTIDX);
    12301228    enableCheats.checked = (mapSettings.CheatsEnabled === undefined || !mapSettings.CheatsEnabled ? false : true);
    12311229    enableCheatsText.caption = (enableCheats.checked ? translate("Yes") : translate("No"));
    12321230    if (mapSettings.RatingEnabled !== undefined)
     
    12411239        enableRatingText.caption = "Unknown";
    12421240
    12431241    observerLateJoin.checked = g_GameAttributes.settings.ObserverLateJoin;
    12441242    observerLateJoinText.caption = observerLateJoin.checked ? translate("Yes") : translate("No");
    12451243
    1246     gameSpeedText.caption = g_GameSpeeds.names[speedIdx];
     1244    var speedIdx = g_GameAttributes.gameSpeed !== undefined && g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) != -1 ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.Default;
     1245    gameSpeedText.caption = g_GameSpeeds.Title[speedIdx];
    12471246    gameSpeedBox.selected = speedIdx;
     1247
    12481248    populationCap.selected = mapSettings.PopulationCap !== undefined && g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) != -1 ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default;
    12491249    populationCapText.caption = g_PopulationCapacities.Title[populationCap.selected];
    12501250    startingResources.selected = mapSettings.StartingResources !== undefined && g_StartingResources.Resources.indexOf(mapSettings.StartingResources) != -1 ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default;
    12511251    startingResourcesText.caption = g_StartingResources.Title[startingResources.selected];
    12521252    ceasefire.selected = mapSettings.Ceasefire !== undefined && g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) != -1 ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default;
  • binaries/data/mods/public/gui/session/session.js

     
     1const g_IsReplay = Engine.IsVisualReplay();
     2const g_GameSpeeds = prepareForDropdown(g_Settings ? g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly || g_IsReplay) : undefined);
     3
    14// Network Mode
    25var g_IsNetworked = false;
    36
    47// Is this user in control of game settings (i.e. is a network server, or offline player)
    58var g_IsController;
     
    1114// Cache the basic player data (name, civ, color)
    1215var g_Players = [];
    1316// Cache the useful civ data
    1417var g_CivData = {};
    1518
    16 var g_GameSpeeds = {};
    17 var g_CurrentSpeed;
    18 
    1919var g_PlayerAssignments = { "local": { "name": translate("You"), "player": 1 } };
    2020
    2121// Cache dev-mode settings that are frequently or widely used
    2222var g_DevSettings = {
    2323    controlAll: false
     
    142142    }
    143143
    144144    return g_TechnologyData[technologyName];
    145145}
    146146
    147 // Init
    148147function init(initData, hotloadData)
    149148{
     149    if (!g_Settings)
     150    {
     151        Engine.EndGame();
     152        Engine.SwitchGuiPage("page_pregame.xml");
     153        return;
     154    }
     155
    150156    if (initData)
    151157    {
    152158        g_IsNetworked = initData.isNetworked; // Set network mode
    153159        g_IsController = initData.isController; // Set controller mode
    154160        g_PlayerAssignments = initData.playerAssignments;
     
    175181    if (Engine.GetPlayerID() <= 0)
    176182        g_IsObserver = true;
    177183
    178184    updateTopPanel();
    179185
    180     g_GameSpeeds = initGameSpeeds();
    181     g_CurrentSpeed = Engine.GetSimRate();
    182186    var gameSpeed = Engine.GetGUIObjectByName("gameSpeed");
    183     gameSpeed.list = g_GameSpeeds.names;
    184     gameSpeed.list_data = g_GameSpeeds.speeds;
    185     var idx = g_GameSpeeds.speeds.indexOf(g_CurrentSpeed);
    186     gameSpeed.selected = idx != -1 ? idx : g_GameSpeeds["default"];
     187    gameSpeed.list = g_GameSpeeds.Title;
     188    gameSpeed.list_data = g_GameSpeeds.Speed;
     189    var gameSpeedIdx = g_GameSpeeds.Speed.indexOf(Engine.GetSimRate());
     190    gameSpeed.selected = gameSpeedIdx != -1 ? gameSpeedIdx : g_GameSpeeds.Default;
    187191    gameSpeed.onSelectionChange = function() { changeGameSpeed(+this.list_data[this.selected]); }
    188192    initMenuPosition(); // set initial position
    189193
    190194    // Populate player selection dropdown
    191195    var playerNames = [];
     
    398402/**
    399403 * Called every frame.
    400404 */
    401405function onTick()
    402406{
     407    if (!g_Settings)
     408        return;
     409
    403410    var now = new Date;
    404411    var tickLength = new Date - lastTickTime;
    405412    lastTickTime = now;
    406413
    407414    checkPlayerState();
     
    507514
    508515function changeGameSpeed(speed)
    509516{
    510517    // For non-networked games only
    511518    if (!g_IsNetworked)
    512     {
    513519        Engine.SetSimRate(speed);
    514         g_CurrentSpeed = speed;
    515     }
    516520}
    517521
    518522/**
    519523 * Recomputes GUI state that depends on simulation state or selection state. Called directly every simulation
    520524 * update (see session.xml), or from onTick when the selection has changed.
  • binaries/data/mods/public/gui/session/session.xml

     
    66<script file="gui/common/functions_civinfo.js"/>
    77<script file="gui/common/functions_global_object.js"/>
    88<script file="gui/common/functions_utility.js"/>
    99<script file="gui/common/l10n.js"/>
    1010<script file="gui/common/music.js"/>
     11<script file="gui/common/settings.js"/>
    1112<script file="gui/common/timer.js"/>
    1213<script file="gui/common/tooltips.js"/>
    1314<!-- load all scripts in this directory -->
    1415<script directory="gui/session/"/>
    1516
  • binaries/data/mods/public/l10n/messages.json

     
    451451                }
    452452            },
    453453            {
    454454                "extractor": "json",
    455455                "filemasks": [
    456                     "simulation/data/game_speeds.json",
    457456                    "simulation/data/player_defaults.json"
    458457                ],
    459458                "options": {
    460459                    "keywords": [
    461460                        "Name"
     
    463462                }
    464463            },
    465464            {
    466465                "extractor": "json",
    467466                "filemasks": [
     467                    "simulation/data/settings/game_speeds.json"
     468                ],
     469                "options": {
     470                    "keywords": ["Title"]
     471                }
     472            },
     473            {
     474                "extractor": "json",
     475                "filemasks": [
    468476                    "simulation/data/settings/starting_resources.json"
    469477                ],
    470478                "options": {
    471479                    "keywords": ["Title"],
    472480                    "context": "startingResources"
  • binaries/data/mods/public/simulation/data/game_speeds.json

     
    1 {
    2     "Speeds":
    3     [
    4         {
    5             "Name": "Turtle (0.1x)",
    6             "Speed": 0.10
    7         },
    8         {
    9             "Name": "Slow (0.25x)",
    10             "Speed": 0.25
    11         },
    12         {
    13             "Name": "Leisurely (0.5x)",
    14             "Speed": 0.50
    15         },
    16         {
    17             "Name": "Relaxed (0.75x)",
    18             "Speed": 0.75
    19         },
    20         {
    21             "Name": "Normal (1x)",
    22             "Speed": 1.0,
    23             "Default": true
    24         },
    25         {
    26             "Name": "Fast (1.25x)",
    27             "Speed": 1.25
    28         },
    29         {
    30             "Name": "Very Fast (1.5x)",
    31             "Speed": 1.5
    32         },
    33         {
    34             "Name": "Insane (2x)",
    35             "Speed": 2.0
    36         }
    37     ]
    38 }
  • binaries/data/mods/public/simulation/data/settings/game_speeds.json

     
     1{
     2    "TranslatedKeys": ["Title"],
     3    "Data":
     4    [
     5        {
     6            "Speed": 0.10,
     7            "Title": "Turtle (0.1x)"
     8        },
     9        {
     10            "Speed": 0.25,
     11            "Title": "Slow (0.25x)"
     12        },
     13        {
     14            "Speed": 0.50,
     15            "Title": "Leisurely (0.5x)"
     16        },
     17        {
     18            "Speed": 0.75,
     19            "Title": "Relaxed (0.75x)"
     20        },
     21        {
     22            "Speed": 1.0,
     23            "Title": "Normal (1x)",
     24            "Default": true
     25        },
     26        {
     27            "Speed": 1.25,
     28            "Title": "Fast (1.25x)"
     29        },
     30        {
     31            "Speed": 1.5,
     32            "Title": "Very Fast (1.5x)"
     33        },
     34        {
     35            "Speed": 2.0,
     36            "Title": "Insane (2x)"
     37        },
     38        {
     39            "Speed": 5.0,
     40            "Title": "Fast Forward (5x)",
     41            "ReplayOnly": true
     42        },
     43        {
     44            "Speed": 10.0,
     45            "Title": "Faster Forward (10x)",
     46            "ReplayOnly": true
     47        },
     48        {
     49            "Speed": 20.0,
     50            "Title": "Very Fast Forward (20x)",
     51            "ReplayOnly": true
     52        }
     53    ]
     54}
  • source/gui/scripting/ScriptFunctions.cpp

     
    179179    std::wstring old = g_CursorName;
    180180    g_CursorName = name;
    181181    return old;
    182182}
    183183
     184bool IsVisualReplay(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
     185{
     186    return g_Game ? g_Game->IsReplay() : false;
     187}
     188
    184189int GetPlayerID(ScriptInterface::CxPrivate* UNUSED(pCxPrivate))
    185190{
    186191    if (g_Game)
    187192        return g_Game->GetPlayerID();
    188193    return -1;
     
    976981    scriptInterface.RegisterFunction<void, &QuickSave>("QuickSave");
    977982    scriptInterface.RegisterFunction<void, &QuickLoad>("QuickLoad");
    978983
    979984    // Misc functions
    980985    scriptInterface.RegisterFunction<std::wstring, std::wstring, &SetCursor>("SetCursor");
     986    scriptInterface.RegisterFunction<bool, &IsVisualReplay>("IsVisualReplay");
    981987    scriptInterface.RegisterFunction<int, &GetPlayerID>("GetPlayerID");
    982988    scriptInterface.RegisterFunction<void, int, &SetPlayerID>("SetPlayerID");
    983989    scriptInterface.RegisterFunction<void, std::string, &OpenURL>("OpenURL");
    984990    scriptInterface.RegisterFunction<std::wstring, &GetMatchID>("GetMatchID");
    985991    scriptInterface.RegisterFunction<void, &RestartInAtlas>("RestartInAtlas");
  • source/ps/Game.h

     
    114114    {
    115115        return m_GameStarted;
    116116    }
    117117
    118118    /**
     119     * Get m_IsReplay.
     120     *
     121     * @return bool the value of m_IsReplay.
     122     **/
     123    inline bool IsReplay()
     124    {   return m_IsReplay; }
     125
     126    /**
    119127     * Get the pointer to the game world object.
    120128     *
    121129     * @return CWorld * the value of m_World.
    122130     **/
    123131    inline CWorld *GetWorld()