mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 10:17:23 +01:00
Merge pull request #107 from Diorik/random_no_repeat
Prevent Random Repeats
This commit is contained in:
commit
2c87077918
3 changed files with 14 additions and 3 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue