Merge pull request #5163 from Mailaender/prettify-trait-documentation

Beautified the trait documentation
This commit is contained in:
Paul Chote
2014-05-02 21:32:24 +12:00
4 changed files with 76 additions and 31 deletions

View File

@@ -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)); }

View File

@@ -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)

View File

@@ -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;
/// <summary>
/// Initial search radius (in cells) from the refinery (proc) that created us.
/// </summary>
[Desc("Initial search radius (in cells) from the refinery that created us.")]
public readonly int SearchFromProcRadius = 24;
/// <summary>
/// Search radius (in cells) from the last harvest order location to find more resources.
/// </summary>
[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); }

View File

@@ -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;
@@ -248,6 +249,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;
}
@@ -257,44 +294,50 @@ 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");
"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();
foreach (var t in Game.modData.ObjectCreator.GetTypesImplementing<ITraitInfo>())
var toc = new StringBuilder();
var doc = new StringBuilder();
foreach (var t in Game.modData.ObjectCreator.GetTypesImplementing<ITraitInfo>().OrderBy(t => t.Namespace))
{
if (t.ContainsGenericParameters || t.IsAbstract)
continue; // skip helpers like TraitInfo<T>
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<DescAttribute>(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);
doc.AppendLine();
doc.AppendLine("### {0}".F(traitName));
foreach (var line in traitDescLines)
doc.AppendLine(line);
var fields = t.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
if (!fields.Any())
continue;
doc.AppendLine("<table>");
doc.AppendLine("<tr><th>Property</th><th>Default Value</th><th>Type</th><th>Description</th></tr>");
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<DescAttribute>(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);
doc.Append("<tr><td>{0}</td><td>{1}</td><td>{2}</td>".F(f.Name, defaultValue, fieldType));
doc.Append("<td>");
foreach (var line in fieldDescLines)
doc.Append(line);
doc.AppendLine("</td></tr>");
}
doc.AppendLine("</table>");
}
Console.WriteLine();
Console.WriteLine("```");
Console.Write(toc.ToString());
Console.Write(doc.ToString());
}
[Desc("MAPFILE", "Generate hash of specified oramap file.")]