From 1cc7944437e2ca74af5547b0a419dd33c2591a28 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 13 Nov 2016 15:10:39 +0000 Subject: [PATCH] Add FieldLoader and linter support for BooleanExpression. --- OpenRA.Game/FieldLoader.cs | 18 ++++++++++++++++++ OpenRA.Game/Support/BooleanExpression.cs | 2 ++ OpenRA.Mods.Common/Lint/LintExts.cs | 9 ++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/FieldLoader.cs b/OpenRA.Game/FieldLoader.cs index 5fff2b49ea..bf6a6dc457 100644 --- a/OpenRA.Game/FieldLoader.cs +++ b/OpenRA.Game/FieldLoader.cs @@ -15,12 +15,14 @@ using System.ComponentModel; using System.Drawing; using System.Drawing.Imaging; using System.Globalization; +using System.IO; using System.Linq; using System.Reflection; using System.Runtime.Serialization; using System.Text.RegularExpressions; using OpenRA.Graphics; using OpenRA.Primitives; +using OpenRA.Support; namespace OpenRA { @@ -396,6 +398,22 @@ namespace OpenRA return InvalidValueAction(value, fieldType, fieldName); } + else if (fieldType == typeof(BooleanExpression)) + { + if (value != null) + { + try + { + return new BooleanExpression(value); + } + catch (InvalidDataException e) + { + throw new YamlException(e.Message); + } + } + + return InvalidValueAction(value, fieldType, fieldName); + } else if (fieldType.IsEnum) { try diff --git a/OpenRA.Game/Support/BooleanExpression.cs b/OpenRA.Game/Support/BooleanExpression.cs index 00b56181a1..c11d35ab02 100644 --- a/OpenRA.Game/Support/BooleanExpression.cs +++ b/OpenRA.Game/Support/BooleanExpression.cs @@ -18,6 +18,7 @@ namespace OpenRA.Support { public class BooleanExpression { + public readonly string Expression; readonly HashSet variables = new HashSet(); public IEnumerable Variables { get { return variables; } } @@ -68,6 +69,7 @@ namespace OpenRA.Support public BooleanExpression(string expression) { + Expression = expression; var openParens = 0; var closeParens = 0; var tokens = new List(); diff --git a/OpenRA.Mods.Common/Lint/LintExts.cs b/OpenRA.Mods.Common/Lint/LintExts.cs index cfebb72fae..582573790e 100644 --- a/OpenRA.Mods.Common/Lint/LintExts.cs +++ b/OpenRA.Mods.Common/Lint/LintExts.cs @@ -11,7 +11,9 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; +using OpenRA.Support; namespace OpenRA.Mods.Common.Lint { @@ -26,8 +28,13 @@ namespace OpenRA.Mods.Common.Lint return (string[])fieldInfo.GetValue(ruleInfo); if (type == typeof(HashSet)) return (HashSet)fieldInfo.GetValue(ruleInfo); + if (type == typeof(BooleanExpression)) + { + var expr = (BooleanExpression)fieldInfo.GetValue(ruleInfo); + return expr != null ? expr.Variables : Enumerable.Empty(); + } - emitError("Bad type for reference on {0}.{1}. Supported types: string, string[], HashSet" + emitError("Bad type for reference on {0}.{1}. Supported types: string, string[], HashSet, BooleanExpression" .F(ruleInfo.GetType().Name, fieldInfo.Name)); return new string[] { };