diff --git a/OpenRA.Mods.Common/Util.cs b/OpenRA.Mods.Common/Util.cs index bb9fd7f392..aa5d80629d 100644 --- a/OpenRA.Mods.Common/Util.cs +++ b/OpenRA.Mods.Common/Util.cs @@ -13,6 +13,7 @@ using System; using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; +using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; using OpenRA.Support; using OpenRA.Traits; @@ -189,5 +190,58 @@ namespace OpenRA.Mods.Common return rules.Actors.Where(a => a.Value.HasTraitInfo()) .SelectMany(a => a.Value.TraitInfos()).Max(h => h.Type.OuterRadius); } + + public static string FriendlyTypeName(Type t) + { + if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(HashSet<>)) + return "Set of {0}".F(t.GetGenericArguments().Select(FriendlyTypeName).ToArray()); + + if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Dictionary<,>)) + return "Dictionary<{0},{1}>".F(t.GetGenericArguments().Select(FriendlyTypeName).ToArray()); + + if (t.IsSubclassOf(typeof(Array))) + return "Multiple {0}".F(FriendlyTypeName(t.GetElementType())); + + if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Primitives.Cache<,>)) + return "Cached<{0},{1}>".F(t.GetGenericArguments().Select(FriendlyTypeName).ToArray()); + + if (t == typeof(int) || t == typeof(uint)) + return "Integer"; + + if (t == typeof(int2)) + return "2D Integer"; + + if (t == typeof(float) || t == typeof(decimal)) + return "Real Number"; + + if (t == typeof(float2)) + return "2D Real Number"; + + if (t == typeof(CPos)) + return "2D Cell Position"; + + if (t == typeof(CVec)) + return "2D Cell Vector"; + + if (t == typeof(WAngle)) + return "1D World Angle"; + + if (t == typeof(WRot)) + return "3D World Rotation"; + + if (t == typeof(WPos)) + return "3D World Position"; + + if (t == typeof(WDist)) + return "1D World Distance"; + + if (t == typeof(WVec)) + return "3D World Vector"; + + if (t == typeof(HSLColor)) + return "Color"; + + return t.Name; + } } } diff --git a/OpenRA.Mods.Common/UtilityCommands/ExtractTraitDocsCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ExtractTraitDocsCommand.cs index b8b8249edf..f000d93b24 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ExtractTraitDocsCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ExtractTraitDocsCommand.cs @@ -13,7 +13,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; -using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.Common.UtilityCommands @@ -92,7 +91,7 @@ namespace OpenRA.Mods.Common.UtilityCommands foreach (var info in infos) { var fieldDescLines = info.Field.GetCustomAttributes(true).SelectMany(d => d.Lines); - var fieldType = FriendlyTypeName(info.Field.FieldType); + var fieldType = Util.FriendlyTypeName(info.Field.FieldType); var loadInfo = info.Field.GetCustomAttributes(true).FirstOrDefault(); var defaultValue = loadInfo != null && loadInfo.Required ? "(required)" : FieldSaver.SaveField(liveTraitInfo, info.Field.Name).Value.Value; doc.Append("{0}{1}{2}".F(info.YamlName, defaultValue, fieldType)); @@ -118,58 +117,5 @@ namespace OpenRA.Mods.Common.UtilityCommands .OrderBy(i => i.Name) .ToArray(); } - - static string FriendlyTypeName(Type t) - { - if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(HashSet<>)) - return "Set of {0}".F(t.GetGenericArguments().Select(FriendlyTypeName).ToArray()); - - if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Dictionary<,>)) - return "Dictionary<{0},{1}>".F(t.GetGenericArguments().Select(FriendlyTypeName).ToArray()); - - if (t.IsSubclassOf(typeof(Array))) - return "Multiple {0}".F(FriendlyTypeName(t.GetElementType())); - - if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Primitives.Cache<,>)) - return "Cached<{0},{1}>".F(t.GetGenericArguments().Select(FriendlyTypeName).ToArray()); - - if (t == typeof(int) || t == typeof(uint)) - return "Integer"; - - if (t == typeof(int2)) - return "2D Integer"; - - if (t == typeof(float) || t == typeof(decimal)) - return "Real Number"; - - if (t == typeof(float2)) - return "2D Real Number"; - - if (t == typeof(CPos)) - return "2D Cell Position"; - - if (t == typeof(CVec)) - return "2D Cell Vector"; - - if (t == typeof(WAngle)) - return "1D World Angle"; - - if (t == typeof(WRot)) - return "3D World Rotation"; - - if (t == typeof(WPos)) - return "3D World Position"; - - if (t == typeof(WDist)) - return "1D World Distance"; - - if (t == typeof(WVec)) - return "3D World Vector"; - - if (t == typeof(HSLColor)) - return "Color"; - - return t.Name; - } } }