From d9bd5f4d7fdf5ea660648e043a5699117a0221e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 21 Apr 2014 16:45:06 +0200 Subject: [PATCH 1/5] tabular view, sorted by namespace and given headers --- OpenRA.Utility/Command.cs | 41 ++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/OpenRA.Utility/Command.cs b/OpenRA.Utility/Command.cs index 1605106831..6a54b607b1 100644 --- a/OpenRA.Utility/Command.cs +++ b/OpenRA.Utility/Command.cs @@ -257,44 +257,41 @@ namespace OpenRA.Utility Game.modData = new ModData(args[1]); Rules.LoadRules(Game.modData.Manifest, new Map()); - Console.WriteLine("## Documentation"); Console.WriteLine( - "This documentation is aimed at modders and contributors of OpenRA. It displays all traits with default values and developer commentary. " + - "Please do not edit it directly, but add new `[Desc(\"String\")]` tags to the source code. This file has been automatically generated on {0}. " + - "Type `make docs` to create a new one. A copy of this is uploaded to https://github.com/OpenRA/OpenRA/wiki/Traits " + - "as well as compiled to HTML and shipped with every release during the automated packaging process.", DateTime.Now); - Console.WriteLine(); - Console.WriteLine("```yaml"); - Console.WriteLine(); + "This documentation is aimed at modders. It displays all traits with default values and developer commentary. " + + "Please do not edit it directly, but add new `[Desc(\"String\")]` tags to the source code. This file has been " + + "automatically generated for version {0} of OpenRA.", Game.modData.Manifest.Mod.Version); - foreach (var t in Game.modData.ObjectCreator.GetTypesImplementing()) + foreach (var t in Game.modData.ObjectCreator.GetTypesImplementing().OrderBy(t => t.Namespace)) { if (t.ContainsGenericParameters || t.IsAbstract) continue; // skip helpers like TraitInfo var traitName = t.Name.EndsWith("Info") ? t.Name.Substring(0, t.Name.Length - 4) : t.Name; var traitDescLines = t.GetCustomAttributes(false).SelectMany(d => d.Lines); - Console.WriteLine("\t{0}:{1}", traitName, traitDescLines.Count() == 1 ? " # " + traitDescLines.First() : ""); - if (traitDescLines.Count() >= 2) - foreach (var line in traitDescLines) - Console.WriteLine("\t\t# {0}", line); + Console.WriteLine("### {0}", traitName); + foreach (var line in traitDescLines) + Console.WriteLine(line); + var fields = t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy); + if (!fields.Any()) + continue; + Console.WriteLine(""); + Console.WriteLine(""); var liveTraitInfo = Game.modData.ObjectCreator.CreateBasic(t); - - foreach (var f in t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy)) + foreach (var f in fields) { var fieldDescLines = f.GetCustomAttributes(true).SelectMany(d => d.Lines); var fieldType = FriendlyTypeName(f.FieldType); var defaultValue = FieldSaver.SaveField(liveTraitInfo, f.Name).Value.Value; - Console.WriteLine("\t\t{0}: {1} # Type: {2}{3}", f.Name, defaultValue, fieldType, fieldDescLines.Count() == 1 ? ". " + fieldDescLines.First() : ""); - if (fieldDescLines.Count() >= 2) - foreach (var line in fieldDescLines) - Console.WriteLine("\t\t# {0}", line); + Console.Write("", f.Name, defaultValue, fieldType); + Console.Write(""); } + Console.WriteLine("
PropertyDefault ValueTypeDescription
{0}{1}{2}"); + foreach (var line in fieldDescLines) + Console.Write(line); + Console.WriteLine("
"); } - - Console.WriteLine(); - Console.WriteLine("```"); } [Desc("MAPFILE", "Generate hash of specified oramap file.")] From 5120cdf6d4134a5ecc2f824660b183872f9c312e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 28 Apr 2014 07:50:03 +0200 Subject: [PATCH 2/5] more non-technical type names --- OpenRA.Utility/Command.cs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/OpenRA.Utility/Command.cs b/OpenRA.Utility/Command.cs index 6a54b607b1..fb4ce9addb 100644 --- a/OpenRA.Utility/Command.cs +++ b/OpenRA.Utility/Command.cs @@ -248,6 +248,42 @@ namespace OpenRA.Utility 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 == 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(WRange)) + return "3D World Range"; + + if (t == typeof(WVec)) + return "3D World Vector"; + return t.Name; } From e861e7c07ecc9029e375210d9f1af099c8d3b09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 21 Apr 2014 16:56:39 +0200 Subject: [PATCH 3/5] port harvester documentation to the new inline Desc format --- OpenRA.Mods.RA/Harvester.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index 2222a5186c..e06d681ee9 100644 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; +using OpenRA.FileFormats; using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Move; using OpenRA.Mods.RA.Orders; @@ -21,20 +22,21 @@ namespace OpenRA.Mods.RA public class HarvesterInfo : ITraitInfo { public readonly string[] DeliveryBuildings = { }; + [Desc("How much resources it can carry.")] public readonly int Capacity = 28; public readonly int LoadTicksPerBale = 4; + [Desc("How fast it can dump it's carryage.")] public readonly int UnloadTicksPerBale = 4; + [Desc("How many squares to show the fill level.")] public readonly int PipCount = 7; public readonly int HarvestFacings = 0; + [Desc("Which resources it can harvest.")] public readonly string[] Resources = { }; + [Desc("How much it is slowed down when returning to the refinery.")] public readonly decimal FullyLoadedSpeed = .85m; - /// - /// Initial search radius (in cells) from the refinery (proc) that created us. - /// + [Desc("Initial search radius (in cells) from the refinery that created us.")] public readonly int SearchFromProcRadius = 24; - /// - /// Search radius (in cells) from the last harvest order location to find more resources. - /// + [Desc("Search radius (in cells) from the last harvest order location to find more resources.")] public readonly int SearchFromOrderRadius = 12; public object Create(ActorInitializer init) { return new Harvester(init.self, this); } From abf5c5a0ebaa54a84e3a9544a657fe392cd51edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 28 Apr 2014 07:37:36 +0200 Subject: [PATCH 4/5] remove brackets from float2.ToString conversion --- OpenRA.Game/Primitives/float2.cs | 2 +- OpenRA.Game/Primitives/int2.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/OpenRA.Game/Primitives/float2.cs b/OpenRA.Game/Primitives/float2.cs index 83aa4fc000..b7a9bbc9ef 100644 --- a/OpenRA.Game/Primitives/float2.cs +++ b/OpenRA.Game/Primitives/float2.cs @@ -89,7 +89,7 @@ namespace OpenRA public static float Dot(float2 a, float2 b) { return a.X * b.X + a.Y * b.Y; } public float2 Round() { return new float2((float)Math.Round(X), (float)Math.Round(Y)); } - public override string ToString() { return "({0},{1})".F(X, Y); } + public override string ToString() { return "{0},{1}".F(X, Y); } public int2 ToInt2() { return new int2((int)X, (int)Y); } public static float2 Max(float2 a, float2 b) { return new float2(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); } diff --git a/OpenRA.Game/Primitives/int2.cs b/OpenRA.Game/Primitives/int2.cs index 89399682cd..d5e35483e5 100644 --- a/OpenRA.Game/Primitives/int2.cs +++ b/OpenRA.Game/Primitives/int2.cs @@ -60,14 +60,14 @@ namespace OpenRA return (uint)((orig & 0xff000000) >> 24) | ((orig & 0x00ff0000) >> 8) | ((orig & 0x0000ff00) << 8) | ((orig & 0x000000ff) << 24); } - public static int Lerp( int a, int b, int mul, int div ) + public static int Lerp(int a, int b, int mul, int div) { - return a + ( b - a ) * mul / div; + return a + (b - a) * mul / div; } - public static int2 Lerp( int2 a, int2 b, int mul, int div ) + public static int2 Lerp(int2 a, int2 b, int mul, int div) { - return a + ( b - a ) * mul / div; + return a + (b - a) * mul / div; } public int2 Clamp(Rectangle r) From 589c7642d1b54d87790a530ccdeb2912b0b8c977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 28 Apr 2014 10:28:17 +0200 Subject: [PATCH 5/5] add a table of contents --- OpenRA.Utility/Command.cs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/OpenRA.Utility/Command.cs b/OpenRA.Utility/Command.cs index fb4ce9addb..94bb043c42 100644 --- a/OpenRA.Utility/Command.cs +++ b/OpenRA.Utility/Command.cs @@ -16,6 +16,7 @@ using System.IO; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; +using System.Text; using OpenRA.FileFormats; using OpenRA.FileSystem; using OpenRA.GameRules; @@ -297,6 +298,10 @@ namespace OpenRA.Utility "This documentation is aimed at modders. It displays all traits with default values and developer commentary. " + "Please do not edit it directly, but add new `[Desc(\"String\")]` tags to the source code. This file has been " + "automatically generated for version {0} of OpenRA.", Game.modData.Manifest.Mod.Version); + Console.WriteLine(); + + var toc = new StringBuilder(); + var doc = new StringBuilder(); foreach (var t in Game.modData.ObjectCreator.GetTypesImplementing().OrderBy(t => t.Namespace)) { @@ -304,30 +309,35 @@ namespace OpenRA.Utility continue; // skip helpers like TraitInfo var traitName = t.Name.EndsWith("Info") ? t.Name.Substring(0, t.Name.Length - 4) : t.Name; + toc.AppendLine("* [{0}](#{1})".F(traitName, traitName.ToLowerInvariant())); var traitDescLines = t.GetCustomAttributes(false).SelectMany(d => d.Lines); - Console.WriteLine("### {0}", traitName); + doc.AppendLine(); + doc.AppendLine("### {0}".F(traitName)); foreach (var line in traitDescLines) - Console.WriteLine(line); + doc.AppendLine(line); var fields = t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy); if (!fields.Any()) continue; - Console.WriteLine(""); - Console.WriteLine(""); + doc.AppendLine("
PropertyDefault ValueTypeDescription
"); + doc.AppendLine(""); var liveTraitInfo = Game.modData.ObjectCreator.CreateBasic(t); foreach (var f in fields) { var fieldDescLines = f.GetCustomAttributes(true).SelectMany(d => d.Lines); var fieldType = FriendlyTypeName(f.FieldType); var defaultValue = FieldSaver.SaveField(liveTraitInfo, f.Name).Value.Value; - Console.Write("", f.Name, defaultValue, fieldType); - Console.Write("".F(f.Name, defaultValue, fieldType)); + doc.Append(""); + doc.Append(line); + doc.AppendLine(""); } - Console.WriteLine("
PropertyDefault ValueTypeDescription
{0}{1}{2}"); + doc.Append("
{0}{1}{2}"); foreach (var line in fieldDescLines) - Console.Write(line); - Console.WriteLine("
"); + doc.AppendLine(""); } + + Console.Write(toc.ToString()); + Console.Write(doc.ToString()); } [Desc("MAPFILE", "Generate hash of specified oramap file.")]