From c21bf31ebcac545f3e11e6dee7be97b52914fa21 Mon Sep 17 00:00:00 2001 From: penev92 Date: Tue, 8 Mar 2022 21:11:49 +0200 Subject: [PATCH] Fixed weapon docs not including WeaponInfo Also made some code cleanups in the weapon docs export code. --- OpenRA.Game/GameRules/WeaponInfo.cs | 5 ++++ .../ExtractWeaponDocsCommand.cs | 26 +++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/OpenRA.Game/GameRules/WeaponInfo.cs b/OpenRA.Game/GameRules/WeaponInfo.cs index 86c069975f..b7bc147545 100644 --- a/OpenRA.Game/GameRules/WeaponInfo.cs +++ b/OpenRA.Game/GameRules/WeaponInfo.cs @@ -127,6 +127,11 @@ namespace OpenRA.GameRules [FieldLoader.LoadUsing(nameof(LoadWarheads))] public readonly List Warheads = new List(); + /// + /// This constructor is used solely for documentation generation! + /// + public WeaponInfo() { } + public WeaponInfo(MiniYaml content) { // Resolve any weapon-level yaml inheritance or removals diff --git a/OpenRA.Mods.Common/UtilityCommands/ExtractWeaponDocsCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ExtractWeaponDocsCommand.cs index 2312e94337..f3f5229729 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ExtractWeaponDocsCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ExtractWeaponDocsCommand.cs @@ -36,23 +36,23 @@ namespace OpenRA.Mods.Common.UtilityCommands if (args.Length > 1) version = args[1]; - Console.WriteLine( + var doc = new StringBuilder(); + + doc.AppendLine( "This documentation is aimed at modders. It displays a template for weapon definitions " + "as well as its contained types (warheads and projectiles) 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 {version} of OpenRA."); - Console.WriteLine(); - - var doc = new StringBuilder(); + doc.AppendLine(); var currentNamespace = ""; var objectCreator = utility.ModData.ObjectCreator; - var weaponInfo = objectCreator.GetTypesImplementing(); + var weaponInfo = new[] { typeof(WeaponInfo) }; var warheads = objectCreator.GetTypesImplementing().OrderBy(t => t.Namespace); var projectiles = objectCreator.GetTypesImplementing().OrderBy(t => t.Namespace); - var weaponTypes = weaponInfo.Concat(projectiles.Concat(warheads)); + var weaponTypes = weaponInfo.Concat(projectiles).Concat(warheads); foreach (var t in weaponTypes) { // skip helpers like TraitInfo @@ -80,18 +80,16 @@ namespace OpenRA.Mods.Common.UtilityCommands doc.AppendLine(); doc.AppendLine("| Property | Default Value | Type | Description |"); - doc.AppendLine("| -------- | --------------| ---- | ----------- |"); + doc.AppendLine("| -------- | ------------- | ---- | ----------- |"); - var liveTraitInfo = t == typeof(WeaponInfo) ? null : objectCreator.CreateBasic(t); + var liveTraitInfo = objectCreator.CreateBasic(t); foreach (var info in infos) { - var fieldDescLines = info.Field.GetCustomAttributes(true).SelectMany(d => d.Lines); + var defaultValue = FieldSaver.SaveField(liveTraitInfo, info.Field.Name).Value.Value; var fieldType = Util.FriendlyTypeName(info.Field.FieldType); - var defaultValue = liveTraitInfo == null ? "" : FieldSaver.SaveField(liveTraitInfo, info.Field.Name).Value.Value; - doc.Append($"| {info.YamlName} | {defaultValue} | {fieldType} | "); - foreach (var line in fieldDescLines) - doc.Append(line + " "); - doc.AppendLine("|"); + var fieldDescLines = info.Field.GetCustomAttributes(true).SelectMany(d => d.Lines); + + doc.AppendLine($"| {info.YamlName} | {defaultValue} | {fieldType} | {string.Join(" ", fieldDescLines)} |"); } }