Ticket #4417: 4417_autosave.patch

File 4417_autosave.patch, 3.8 KB (added by Vladislav Belov, 7 years ago)

Adds autosaves

  • binaries/data/mods/public/gui/options/options.json

     
    9696            "label": "Chat Timestamp",
    9797            "tooltip": "Show time that messages are posted in the lobby, gamesetup and ingame chat.",
    9898            "parameters": { "config": "chat.timestamp" }
     99        },
     100        {
     101            "type": "boolean",
     102            "label": "Autosave",
     103            "tooltip": "Enable autosaves in the game.",
     104            "parameters": { "config": "autosave" },
     105            "dependencies": [ "autosave.period" ]
     106        },
     107        {
     108            "type": "dropdown",
     109            "label": "Autosave Period",
     110            "tooltip": "Save the game every selected period.",
     111            "parameters": { "list": [ "1 minute", "5 minutes", "10 minutes", "15 minutes", "30 minutes", "60 minutes" ], "config": "autosave.period" }
    99112        }
    100113    ],
    101114    "graphicsSetting":
  • binaries/data/mods/public/gui/options/options.xml

     
    2121            <object style="ModernLabelText" type="text" size="0 5 100% 25">
    2222                <translatableAttribute id="caption">General</translatableAttribute>
    2323            </object>
    24             <repeat count="23">
     24            <repeat count="25">
    2525                <object name="generalSetting[n]" size="0 25 100% 50" hidden="true">
    2626                    <object name="generalSettingLabel[n]" size="0 0 65% 100%" type="text" style="ModernLabelText" text_align="left"/>
    2727                    <object name="generalSettingTickbox[n]" size="90% 5 100% 100%+5" type="checkbox" style="ModernTickBox" hidden="true"/>
    2828                    <object name="generalSettingInput[n]" size="70% 0 100%-8 100%" type="input" style="ModernInput" hidden="true"/>
    29                     <object name="generalSettingDropdown[n]" size="70% 0 100%-8 100%" type="dropdown" style="ModernDropDown" hidden="true"/>
     29                    <object name="generalSettingDropdown[n]" size="60% 0 100%-8 100%" type="dropdown" style="ModernDropDown" hidden="true"/>
    3030                </object>
    3131            </repeat>
    3232        </object>
  • binaries/data/mods/public/gui/session/session.js

     
    169169 */
    170170var g_HasIdleWorker = false;
    171171
     172var g_AutosavePeriod = 0;
     173
    172174function GetSimState()
    173175{
    174176    if (!g_SimState)
     
    312314    onSimulationUpdate();
    313315    setTimeout(displayGamestateNotifications, 1000);
    314316
     317    if (!g_IsNetworked && !g_IsReplay && Engine.ConfigDB_GetValue("user", "autosave") == "true")
     318    {
     319        g_AutosavePeriod = +[1, 5, 10, 15, 30, 60][+Engine.ConfigDB_GetValue("user", "autosave.period")] * 60000; // the autosave period is set in minutes
     320        // Prevent the autosave spamming for invalid values
     321        if (g_AutosavePeriod >= 60000)
     322            setTimeout(autosaveGame, g_AutosavePeriod);
     323    }
     324
    315325    // Report the performance after 5 seconds (when we're still near
    316326    // the initial camera view) and a minute (when the profiler will
    317327    // have settled down if framerates as very low), to give some
     
    14121422
    14131423    Engine.SendGameReport(reportObject);
    14141424}
     1425
     1426function autosaveGame()
     1427{
     1428    // Get the all current simulation state
     1429    let savedGameData = getSavedGameData();
     1430    savedGameData = savedGameData && savedGameData.savedGameData || {};
     1431    let simulationState = Engine.GuiInterfaceCall("GetSimulationState");
     1432    savedGameData.timeElapsed = simulationState.timeElapsed;
     1433    savedGameData.states = simulationState.players.map(pState => pState.state);
     1434
     1435    // Rewrite the autosave
     1436    Engine.SaveGame("autosave", translate("Autosave"), savedGameData);
     1437
     1438    setTimeout(autosaveGame, g_AutosavePeriod);
     1439}