From fc93c65c222d5ae07bae549cf4666547cb64d8d6 Mon Sep 17 00:00:00 2001 From: denadan Date: Mon, 20 May 2019 17:40:29 +0300 Subject: [PATCH] nre fix in TagRestrictionsHandler --- mod.json | 2 +- source/Control.cs | 2 +- .../TagRestrictions/TagRestrictionsHandler.cs | 57 +++++++++++-------- 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/mod.json b/mod.json index b991f98..f3c5fc2 100644 --- a/mod.json +++ b/mod.json @@ -38,7 +38,7 @@ "CategoryDescriptionColor" : "#008000", - "TestEnableAllTags": true, + "TestEnableAllTags": false, "OmniTechFlag": "cc_omnitech", "OmniTechCostBySize": false, "OmniTechInstallCost": 1, diff --git a/source/Control.cs b/source/Control.cs index 4730367..1f8138a 100644 --- a/source/Control.cs +++ b/source/Control.cs @@ -55,7 +55,7 @@ public static void Init(string directory, string settingsJSON) Registry.RegisterSimpleCustomComponents(Assembly.GetExecutingAssembly()); Validator.RegisterMechValidator(CategoryController.Shared.ValidateMech, CategoryController.Shared.ValidateMechCanBeFielded); - Logger.Log("Loaded CustomComponents v0.9.7.0 for bt 1.5.1"); + Logger.Log("Loaded CustomComponents v0.9.7.1 for bt 1.5.1"); Validator.RegisterMechValidator(TagRestrictionsHandler.Shared.ValidateMech, TagRestrictionsHandler.Shared.ValidateMechCanBeFielded); Validator.RegisterDropValidator(pre: TagRestrictionsHandler.Shared.ValidateDrop); diff --git a/source/TagRestrictions/TagRestrictionsHandler.cs b/source/TagRestrictions/TagRestrictionsHandler.cs index bc24baf..7fc1e56 100644 --- a/source/TagRestrictions/TagRestrictionsHandler.cs +++ b/source/TagRestrictions/TagRestrictionsHandler.cs @@ -321,38 +321,49 @@ private static string NameForTag(string tag) public void ProcessDescription(TagSet tags, DescriptionDef description) { - string fulltags = ""; - string shorttags = ""; - - foreach (var tag in Restrictions.Values) + try { - if (tags.Contains(tag.Tag)) - { - if (!string.IsNullOrEmpty(tag.ShortText)) - shorttags += tag.ShortText + ", "; - if (!string.IsNullOrEmpty(tag.FullText)) - fulltags += "\n" + tag.FullText; - } - } + if (tags == null || description == null) + return; - if (shorttags != "" || fulltags != "") - { - var trav = new Traverse(description).Property("Details"); + string fulltags = ""; + string shorttags = ""; - if (shorttags != "") + foreach (var tag in Restrictions.Values) { - shorttags = shorttags.Substring(0, shorttags.Length - 2); - shorttags = "\n[" + shorttags + "]"; - trav.Value = description.Details + shorttags; - ; - + if (tags.Contains(tag.Tag)) + { + if (!string.IsNullOrEmpty(tag.ShortText)) + shorttags += tag.ShortText + ", "; + if (!string.IsNullOrEmpty(tag.FullText)) + fulltags += "\n" + tag.FullText; + } } - if (fulltags != "") + if (shorttags != "" || fulltags != "") { - trav.Value = description.Details + fulltags; + var trav = new Traverse(description).Property("Details"); + + if (shorttags != "") + { + shorttags = shorttags.Substring(0, shorttags.Length - 2); + shorttags = "\n[" + shorttags + + "]"; + trav.Value = description.Details + shorttags; + ; + + } + + if (fulltags != "") + { + trav.Value = description.Details + fulltags; + } } } + catch (Exception e) + { + Control.LogError("Errpr in TagRestrictionHandler.ProcessDescription", e); + } } }