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] 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.")]