From 39f268945f09efee330e2092d4687f4113da99bb Mon Sep 17 00:00:00 2001 From: IO Date: Sat, 6 Jan 2024 16:40:36 +0100 Subject: [PATCH] Make usage of expressions in Contract Requirement possible (#36) An expression in "contractType" would cause a nullReferenceException before this change. Added validation for mutually exclusive "tag" and "contractType". --- .../Requirement/ContractCheckRequirement.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/source/ContractConfigurator/Requirement/ContractCheckRequirement.cs b/source/ContractConfigurator/Requirement/ContractCheckRequirement.cs index d15cff15..48555984 100644 --- a/source/ContractConfigurator/Requirement/ContractCheckRequirement.cs +++ b/source/ContractConfigurator/Requirement/ContractCheckRequirement.cs @@ -28,24 +28,18 @@ public override bool LoadFromConfig(ConfigNode configNode) const string nullString = null; // to get around the fact this is overloaded. valid &= ConfigNodeUtil.ParseValue(configNode, "tag", x => tag = x, this, nullString); - // Get type - string contractType = null; - valid &= tag != null || ConfigNodeUtil.ParseValue(configNode, "contractType", x => contractType = x, this); - // By default, always check the requirement for active contracts valid &= ConfigNodeUtil.ParseValue(configNode, "checkOnActiveContract", x => checkOnActiveContract = x, this, true); - if (valid) - { - if (tag == null) - valid &= SetValues(contractType); - else - ccType = null; - } + // Get type + string dummy = null; + valid &= ConfigNodeUtil.ParseValue(configNode, "contractType", x => dummy = x, this, SetValues); valid &= ConfigNodeUtil.ParseValue(configNode, "minCount", x => minCount = x, this, 1); valid &= ConfigNodeUtil.ParseValue(configNode, "maxCount", x => maxCount = x, this, UInt32.MaxValue); + valid &= ConfigNodeUtil.MutuallyExclusive(configNode, new string[] { "tag" }, new string[] { "contractType" }, this); + return valid; }