From 7e9d87a8087ba4abdfe7957a6b9010ca2b21bbe0 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 11 Dec 2025 11:18:43 +0000 Subject: [PATCH] Move auto-saving settings to mod code. --- OpenRA.Game/Settings.cs | 11 ------- OpenRA.Mods.Common/Traits/World/AutoSave.cs | 31 ++++++++++++------- .../Logic/Settings/GamePlaySettingsLogic.cs | 29 ++++++++--------- 3 files changed, 32 insertions(+), 39 deletions(-) diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 1be5c888fd..7a08cfa7b4 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -300,15 +300,6 @@ namespace OpenRA public ImmutableArray CustomColors = []; } - [YamlNode("SinglePlayerSettings", shared: true)] - public class SinglePlayerGameSettings : SettingsModule - { - [Desc("Sets the Auto-save frequency, in seconds")] - public int AutoSaveInterval = 0; - [Desc("Sets the AutoSave number of max files to bes saved on the file-system")] - public int AutoSaveMaxFileCount = 10; - } - [YamlNode("Game", shared: true)] public class GameSettings : SettingsModule { @@ -382,7 +373,6 @@ namespace OpenRA public readonly GraphicSettings Graphics; public readonly ServerSettings Server; public readonly DebugSettings Debug; - public readonly SinglePlayerGameSettings SinglePlayerSettings; readonly Arguments args; readonly TypeDictionary modules = []; @@ -407,7 +397,6 @@ namespace OpenRA Graphics = GetOrCreate(null); Server = GetOrCreate(null); Debug = GetOrCreate(null); - SinglePlayerSettings = GetOrCreate(null); } public T GetOrCreate(ObjectCreator objectCreator, string mod = null) where T : SettingsModule diff --git a/OpenRA.Mods.Common/Traits/World/AutoSave.cs b/OpenRA.Mods.Common/Traits/World/AutoSave.cs index fdd22fb6b7..98e380223f 100644 --- a/OpenRA.Mods.Common/Traits/World/AutoSave.cs +++ b/OpenRA.Mods.Common/Traits/World/AutoSave.cs @@ -18,6 +18,16 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { + [YamlNode("AutoSave", shared: true)] + public class AutoSaveSettings : SettingsModule + { + [Desc("Sets the Auto-save frequency, in seconds")] + public int AutoSaveInterval = 0; + + [Desc("Sets the AutoSave number of max files to bes saved on the file-system")] + public int AutoSaveMaxFileCount = 10; + } + [TraitLocation(SystemActors.World)] [Desc("Add this trait to the world actor to enable auto-save.")] public class AutoSaveInfo : TraitInfo @@ -32,11 +42,13 @@ namespace OpenRA.Mods.Common.Traits int ticksUntilAutoSave; int lastSaveInverval; readonly bool isDisabled; + readonly AutoSaveSettings autoSaveSettings; public AutoSave(Actor self, AutoSaveInfo info) { + autoSaveSettings = self.World.GetSettings(); ticksUntilAutoSave = GetTicksBetweenAutosaves(self); - lastSaveInverval = Game.Settings.SinglePlayerSettings.AutoSaveInterval; + lastSaveInverval = autoSaveSettings.AutoSaveInterval; isDisabled = self.World.LobbyInfo.GlobalSettings.Dedicated || self.World.LobbyInfo.NonBotClients.Count() > 1; } @@ -46,18 +58,13 @@ namespace OpenRA.Mods.Common.Traits if (isDisabled || self.World.IsReplay || self.World.IsLoadingGameSave) return; - var autoSaveValue = Game.Settings.SinglePlayerSettings.AutoSaveInterval; - - if (autoSaveValue == 0) + if (autoSaveSettings.AutoSaveInterval == 0) return; - var autoSaveFileLimit = Game.Settings.SinglePlayerSettings.AutoSaveMaxFileCount; - - autoSaveFileLimit = autoSaveFileLimit < 3 ? 3 : autoSaveFileLimit; - - if (lastSaveInverval != autoSaveValue) + var autoSaveFileLimit = Math.Max(autoSaveSettings.AutoSaveMaxFileCount, 3); + if (lastSaveInverval != autoSaveSettings.AutoSaveInterval) { - lastSaveInverval = autoSaveValue; + lastSaveInverval = autoSaveSettings.AutoSaveInterval; ticksUntilAutoSave = GetTicksBetweenAutosaves(self); } @@ -91,9 +98,9 @@ namespace OpenRA.Mods.Common.Traits return autoSaveDirectoryInfo.EnumerateFiles($"{AutoSavePattern}*{SaveFileExtension}"); } - static int GetTicksBetweenAutosaves(Actor self) + int GetTicksBetweenAutosaves(Actor self) { - return 1000 / self.World.Timestep * Game.Settings.SinglePlayerSettings.AutoSaveInterval; + return 1000 / self.World.Timestep * autoSaveSettings.AutoSaveInterval; } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/GamePlaySettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/GamePlaySettingsLogic.cs index b36888f96d..95c047b311 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/GamePlaySettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/GamePlaySettingsLogic.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using OpenRA.Mods.Common.Traits; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic @@ -31,10 +32,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly int[] autoSaveSeconds = [0, 10, 30, 45, 60, 120, 180, 300, 600]; readonly int[] autoSaveFileNumbers = [3, 5, 10, 20, 50, 100]; + readonly AutoSaveSettings autoSaveSettings; [ObjectCreator.UseCtor] - public GameplaySettingsLogic(Action>, Func> registerPanel, string panelID, string label) + public GameplaySettingsLogic(ModData modData, Action>, Func> registerPanel, + string panelID, string label) { + autoSaveSettings = modData.GetSettings(); registerPanel(panelID, label, InitPanel, ResetPanel); } @@ -49,17 +53,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic autoSaveIntervalDropDown.OnClick = () => ShowAutoSaveIntervalDropdown(autoSaveIntervalDropDown, autoSaveSeconds); - autoSaveIntervalDropDown.GetText = () => GetMessageForAutoSaveInterval(Game.Settings.SinglePlayerSettings.AutoSaveInterval); + autoSaveIntervalDropDown.GetText = () => GetMessageForAutoSaveInterval(autoSaveSettings.AutoSaveInterval); // Setup dropdown for auto-save number. var autoSaveNoDropDown = panel.Get("AUTO_SAVE_FILE_NUMBER_DROP_DOWN"); - autoSaveNoDropDown.OnMouseDown = _ => - ShowAutoSaveFileNumberDropdown(autoSaveNoDropDown, autoSaveFileNumbers); - - autoSaveNoDropDown.GetText = () => FluentProvider.GetMessage(AutoSaveMaxFileNumber, "saves", Game.Settings.SinglePlayerSettings.AutoSaveMaxFileCount); - - autoSaveNoDropDown.IsDisabled = () => Game.Settings.SinglePlayerSettings.AutoSaveInterval <= 0; + autoSaveNoDropDown.OnMouseDown = _ => ShowAutoSaveFileNumberDropdown(autoSaveNoDropDown, autoSaveFileNumbers); + autoSaveNoDropDown.GetText = () => FluentProvider.GetMessage(AutoSaveMaxFileNumber, "saves", autoSaveSettings.AutoSaveMaxFileCount); + autoSaveNoDropDown.IsDisabled = () => autoSaveSettings.AutoSaveInterval <= 0; return () => false; } @@ -71,15 +72,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic void ShowAutoSaveIntervalDropdown(DropDownButtonWidget dropdown, IEnumerable options) { - var gsp = Game.Settings.SinglePlayerSettings; - ScrollItemWidget SetupItem(int o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, - () => gsp.AutoSaveInterval == o, + () => autoSaveSettings.AutoSaveInterval == o, () => { - gsp.AutoSaveInterval = o; + autoSaveSettings.AutoSaveInterval = o; Game.Settings.Save(); }); @@ -94,15 +93,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic void ShowAutoSaveFileNumberDropdown(DropDownButtonWidget dropdown, IEnumerable options) { - var gsp = Game.Settings.SinglePlayerSettings; - ScrollItemWidget SetupItem(int o, ScrollItemWidget itemTemplate) { var item = ScrollItemWidget.Setup(itemTemplate, - () => gsp.AutoSaveMaxFileCount == o, + () => autoSaveSettings.AutoSaveMaxFileCount == o, () => { - gsp.AutoSaveMaxFileCount = o; + autoSaveSettings.AutoSaveMaxFileCount = o; Game.Settings.Save(); });