From e4489c36a193661a5e312a407907990b227a0528 Mon Sep 17 00:00:00 2001 From: CptMoore <39010654+cptmoore@users.noreply.github.com> Date: Thu, 28 Dec 2023 10:58:44 +0100 Subject: [PATCH] Removed unnecessary fields in TagsChecker. --- .../TagRestrictions/TagsChecker.cs | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/source/CustomComponents/TagRestrictions/TagsChecker.cs b/source/CustomComponents/TagRestrictions/TagsChecker.cs index 777126e..f614707 100644 --- a/source/CustomComponents/TagRestrictions/TagsChecker.cs +++ b/source/CustomComponents/TagRestrictions/TagsChecker.cs @@ -8,9 +8,6 @@ namespace CustomComponents; internal class TagsChecker { - private readonly ChassisDef chassisDef; - private readonly List inventory; - private readonly Dictionary> tagsOnLocations = new(); private readonly HashSet tagsOnMech = new(); private string error; @@ -18,16 +15,9 @@ internal class TagsChecker internal TagsChecker(MechDef mechDef) { - chassisDef = mechDef.Chassis; - inventory = mechDef.Inventory.ToList(); - - if (Control.Settings.TagRestrictionUseMechTags) - { - tagsOnMech.UnionWith(mechDef.MechTags); - } - - CollectChassisTags(); - CollectComponentTags(); + CollectMechTags(mechDef); + CollectChassisTags(mechDef.Chassis); + CollectComponentTags(mechDef.Inventory); } internal string Validate(Dictionary> errors = null) @@ -333,7 +323,21 @@ private bool IncompatiblesCheck( return false; } - private void CollectChassisTags() + private void CollectMechTags(MechDef mechDef) + { + if (!Control.Settings.TagRestrictionUseMechTags) + { + return; + } + + // tags + if (mechDef.MechTags != null) + { + tagsOnMech.UnionWith(mechDef.MechTags); + } + } + + private void CollectChassisTags(ChassisDef chassisDef) { // tags if (chassisDef.ChassisTags != null) @@ -346,7 +350,7 @@ private void CollectChassisTags() tagsOnMech.Add(identifier); } - private void CollectComponentTags() + private void CollectComponentTags(MechComponentRef[] inventory) { foreach (var def in inventory) {