mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 18:27:24 +01:00
Make PreventRandomc figurable, clean up logic
Will no longer hold design reference or make redundant copy of list
This commit is contained in:
parent
45981f2fee
commit
67fd65d366
3 changed files with 13 additions and 8 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Design> localDesigns)
|
||||
public Design? Design(IList<Design> 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()
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue