Sex restriction for markings (#19894)

* Add sex restriction to markings

* Apply to existing systems
This commit is contained in:
Morb
2023-09-19 23:56:10 +03:00
committed by GitHub
parent 1b2fd313a0
commit 835bde4c6e
13 changed files with 169 additions and 20 deletions

View File

@@ -199,6 +199,40 @@ public sealed partial class MarkingSet
}
}
/// <summary>
/// Filters markings based on sex and it's restrictions in the marking's prototype from this marking set.
/// </summary>
/// <param name="sex">The species to filter.</param>
/// <param name="markingManager">Marking manager.</param>
public void EnsureSexes(Sex sex, MarkingManager? markingManager = null)
{
IoCManager.Resolve(ref markingManager);
var toRemove = new List<(MarkingCategories category, string id)>();
foreach (var (category, list) in Markings)
{
foreach (var marking in list)
{
if (!markingManager.TryGetMarking(marking, out var prototype))
{
toRemove.Add((category, marking.MarkingId));
continue;
}
if (prototype.SexRestriction != null && prototype.SexRestriction != sex)
{
toRemove.Add((category, marking.MarkingId));
}
}
}
foreach (var remove in toRemove)
{
Remove(remove.category, remove.id);
}
}
/// <summary>
/// Ensures that all markings in this set are valid.
/// </summary>