mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 18:27:24 +01:00
Prevent repeating random design
Cache the last selected random design and prevent it from being chosen again.
This commit is contained in:
parent
da46705b52
commit
cf308fc118
1 changed files with 6 additions and 1 deletions
|
|
@ -5,15 +5,20 @@ namespace Glamourer.Designs.Special;
|
|||
public class RandomDesignGenerator(DesignStorage designs, DesignFileSystem fileSystem) : IService
|
||||
{
|
||||
private readonly Random _rng = new();
|
||||
private Design? _lastDesign = null;
|
||||
|
||||
public Design? Design(IReadOnlyList<Design> localDesigns)
|
||||
{
|
||||
if (localDesigns.Count == 0)
|
||||
return null;
|
||||
|
||||
if (_lastDesign != null && localDesigns.Count > 1)
|
||||
localDesigns = localDesigns.Where(d => d != _lastDesign).ToList();
|
||||
|
||||
var idx = _rng.Next(0, localDesigns.Count);
|
||||
Glamourer.Log.Verbose($"[Random Design] Chose design {idx + 1} out of {localDesigns.Count}: {localDesigns[idx].Incognito}.");
|
||||
return localDesigns[idx];
|
||||
_lastDesign = localDesigns[idx];
|
||||
return _lastDesign;
|
||||
}
|
||||
|
||||
public Design? Design()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue