Merge pull request #107 from Diorik/random_no_repeat

Prevent Random Repeats
This commit is contained in:
Ottermandias 2025-05-03 23:29:29 +02:00 committed by GitHub
commit 2c87077918
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 3 deletions

View file

@ -66,6 +66,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 DesignPanelFlag HideDesignPanel { get; set; } = 0;
public DesignPanelFlag AutoExpandDesignPanel { get; set; } = 0;

View file

@ -1,18 +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 WeakReference<Design?> _lastDesign = new(null, false);
public Design? Design(IReadOnlyList<Design> localDesigns)
{
if (localDesigns.Count == 0)
return null;
var idx = _rng.Next(0, localDesigns.Count);
int idx;
do
idx = _rng.Next(0, localDesigns.Count);
while (config.PreventRandomRepeats && localDesigns.Count > 1 && _lastDesign.TryGetTarget(out var lastDesign) && lastDesign == localDesigns[idx]);
Glamourer.Log.Verbose($"[Random Design] Chose design {idx + 1} out of {localDesigns.Count}: {localDesigns[idx].Incognito}.");
_lastDesign.SetTarget(localDesigns[idx]);
return localDesigns[idx];
}

View file

@ -102,6 +102,9 @@ public class SettingsTab(
"Apply all settings as temporary settings so they will be reset when Glamourer or the game shut down."u8,
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();
}