From 67fd65d366133ba0569ce9a3a70760e8f43fec5a Mon Sep 17 00:00:00 2001 From: Diorik Date: Thu, 6 Feb 2025 12:49:23 -0600 Subject: [PATCH] Make PreventRandomc figurable, clean up logic Will no longer hold design reference or make redundant copy of list --- Glamourer/Configuration.cs | 1 + .../Designs/Special/RandomDesignGenerator.cs | 17 +++++++++-------- Glamourer/Gui/Tabs/SettingsTab/SettingsTab.cs | 3 +++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Glamourer/Configuration.cs b/Glamourer/Configuration.cs index 4b59191..5f838a8 100644 --- a/Glamourer/Configuration.cs +++ b/Glamourer/Configuration.cs @@ -67,6 +67,7 @@ public class Configuration : IPluginConfiguration, ISavable public bool UseTemporarySettings { get; set; } = true; public bool AllowDoubleClickToApply { get; set; } = false; public bool RespectManualOnAutomationUpdate { get; set; } = false; + public bool PreventRandomRepeats { get; set; } = false; public DefaultDesignSettings DefaultDesignSettings { get; set; } = new(); diff --git a/Glamourer/Designs/Special/RandomDesignGenerator.cs b/Glamourer/Designs/Special/RandomDesignGenerator.cs index 1bee8ad..3ff353b 100644 --- a/Glamourer/Designs/Special/RandomDesignGenerator.cs +++ b/Glamourer/Designs/Special/RandomDesignGenerator.cs @@ -1,24 +1,25 @@ -using OtterGui.Services; +using OtterGui; +using OtterGui.Services; namespace Glamourer.Designs.Special; -public class RandomDesignGenerator(DesignStorage designs, DesignFileSystem fileSystem) : IService +public class RandomDesignGenerator(DesignStorage designs, DesignFileSystem fileSystem, Configuration config) : IService { private readonly Random _rng = new(); - private Design? _lastDesign = null; + private Guid? _lastDesignID = null; - public Design? Design(IReadOnlyList localDesigns) + public Design? Design(IList localDesigns) { if (localDesigns.Count == 0) return null; - if (_lastDesign != null && localDesigns.Count > 1) - localDesigns = localDesigns.Where(d => d != _lastDesign).ToList(); + if (config.PreventRandomRepeats && _lastDesignID != null && localDesigns.Count > 1 && localDesigns.FindFirst(d => d.Identifier == _lastDesignID, out var found)) + localDesigns.Remove(found); var idx = _rng.Next(0, localDesigns.Count); Glamourer.Log.Verbose($"[Random Design] Chose design {idx + 1} out of {localDesigns.Count}: {localDesigns[idx].Incognito}."); - _lastDesign = localDesigns[idx]; - return _lastDesign; + _lastDesignID = localDesigns[idx].Identifier; + return localDesigns[idx]; } public Design? Design() diff --git a/Glamourer/Gui/Tabs/SettingsTab/SettingsTab.cs b/Glamourer/Gui/Tabs/SettingsTab/SettingsTab.cs index ab40a48..2b9548f 100644 --- a/Glamourer/Gui/Tabs/SettingsTab/SettingsTab.cs +++ b/Glamourer/Gui/Tabs/SettingsTab/SettingsTab.cs @@ -109,6 +109,9 @@ public class SettingsTab( Checkbox("Use Temporary Mod Settings", "Apply all settings as temporary settings so they will be reset when Glamourer or the game shut down.", config.UseTemporarySettings, v => config.UseTemporarySettings = v); + Checkbox("Prevent Random Design Repeats", + "When using random designs, prevent the same design from being chosen twice in a row.", + config.PreventRandomRepeats, v => config.PreventRandomRepeats = v); ImGui.NewLine(); }