Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
DocGen no-link definition fix
Browse files Browse the repository at this point in the history
  • Loading branch information
malware-dev committed Feb 3, 2020
1 parent 1a61f06 commit 63e67c1
Showing 1 changed file with 67 additions and 44 deletions.
111 changes: 67 additions & 44 deletions Source/DocGen2/Services/TypeDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ public static async Task UpdateAsync(string path, string output, string gameBina
typeDefinitions.Generate(path, output);
}

readonly List<Definition> _definitions = new List<Definition>();

TypeDefinitions()
{
Definitions = new ReadOnlyCollection<Definition>(_definitions);
}

public ReadOnlyCollection<Definition> Definitions { get; }

public static async Task<TypeDefinitions> LoadAsync(string path)
{
var def = new TypeDefinitions();
Expand All @@ -40,6 +31,15 @@ await Task.Run(() =>
return def;
}

readonly List<Definition> _definitions = new List<Definition>();

TypeDefinitions()
{
Definitions = new ReadOnlyCollection<Definition>(_definitions);
}

public ReadOnlyCollection<Definition> Definitions { get; }

void Generate(string path, string output)
{
var document = new StringBuilder();
Expand All @@ -49,10 +49,16 @@ void Generate(string path, string output)
foreach (var item in blocks.OrderBy(g => g.DisplayName).GroupBy(g => g.DisplayName))
{
var type = item.FirstOrDefault().TypeName;
var i = type.LastIndexOf('.');
var typeDisplayName = type.Substring(i + 1);
var link = $"{type}";
document.Append("**").Append(item.Key).Append("** ([").Append(typeDisplayName).Append("](").Append(link).AppendLine(")) ");
if (type != null)
{
var i = type.LastIndexOf('.');
var typeDisplayName = type.Substring(i + 1);
var link = $"{type}";
document.Append("**").Append(item.Key).Append("** ([").Append(typeDisplayName).Append("](").Append(link).AppendLine(")) ");
}
else
document.Append("**").Append(item.Key).AppendLine("** ");

foreach (var subgroup in item.OrderBy(g => g.Size))
{
document.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")
Expand All @@ -69,6 +75,7 @@ void Generate(string path, string output)
document.Append("**").Append(item.DisplayName).AppendLine("** ");
document.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`").Append(item).AppendLine("` ");
}

document.AppendLine();
}

Expand All @@ -93,74 +100,89 @@ public void Search(string fileName, Terminals terminals, SpaceEngineersText text
var blockDefinitions = document.XPathSelectElements(@"/Definitions/CubeBlocks/Definition");
foreach (var blockDefinition in blockDefinitions)
{
var isPublic = (bool?) blockDefinition.Element("Public") ?? true;
var isPublic = (bool?)blockDefinition.Element("Public") ?? true;
if (!isPublic)
continue;
var idElement = blockDefinition.Element("Id");
var typeId = (string) idElement?.Element("TypeId") ?? (string) idElement?.Attribute("Type");
var subtypeId = (string) idElement?.Element("SubtypeId") ?? (string) idElement?.Attribute("Typeid");
var displayName = text.Get((string) blockDefinition.Element("DisplayName"));
var typeId = (string)idElement?.Element("TypeId") ?? (string)idElement?.Attribute("Type");
var subtypeId = (string)idElement?.Element("SubtypeId") ?? (string)idElement?.Attribute("Typeid");
var displayName = text.Get((string)blockDefinition.Element("DisplayName"));
var blockInfo = terminals.Blocks.FirstOrDefault(b => b.TypeId == typeId);
var size = string.Equals((string) blockDefinition.Element("CubeSize"), "Small", StringComparison.OrdinalIgnoreCase) ? "Small Grid" : "Large Grid";
if (blockInfo == null)
continue;
var size = string.Equals((string)blockDefinition.Element("CubeSize"), "Small", StringComparison.OrdinalIgnoreCase) ? "Small Grid" : "Large Grid";
//if (blockInfo == null)
// continue;

lock (_definitions)
{
_definitions.Add(new Definition("Blocks", size, displayName, blockInfo.BlockInterfaceType, typeId, subtypeId));
_definitions.Add(new Definition("Blocks", size, displayName, blockInfo?.BlockInterfaceType, typeId, subtypeId));
}
}

var componentDefinitions = document.XPathSelectElements(@"/Definitions/Components/Component");
foreach (var componentDefinition in componentDefinitions)
{
var isPublic = (bool?) componentDefinition.Element("Public") ?? true;
var isPublic = (bool?)componentDefinition.Element("Public") ?? true;
if (!isPublic)
continue;
var canSpawnFromScreen = (bool?) componentDefinition.Element("CanSpawnFromScreen") ?? true;
var canSpawnFromScreen = (bool?)componentDefinition.Element("CanSpawnFromScreen") ?? true;
if (!canSpawnFromScreen)
continue;
var idElement = componentDefinition.Element("Id");
var typeId = (string) idElement?.Element("TypeId") ?? (string) idElement?.Attribute("Type");
var subtypeId = (string) idElement?.Element("SubtypeId") ?? (string) idElement?.Attribute("Typeid");
var displayName = text.Get((string) componentDefinition.Element("DisplayName"));
var typeId = (string)idElement?.Element("TypeId") ?? (string)idElement?.Attribute("Type");
var subtypeId = (string)idElement?.Element("SubtypeId") ?? (string)idElement?.Attribute("Typeid");
var displayName = text.Get((string)componentDefinition.Element("DisplayName"));
lock (_definitions)
{
_definitions.Add(new Definition("Components", null, displayName, null, typeId, subtypeId));
}
}

//var gasDefinitions = document.XPathSelectElements(@"/Definitions/GasProperties/Gas");
//foreach (var gasDefinition in gasDefinitions)
//{
// var isPublic = (bool?)gasDefinition.Element("Public") ?? true;
// if (!isPublic)
// continue;
// var idElement = gasDefinition.Element("Id");
// var typeId = (string)idElement?.Element("TypeId") ?? (string)idElement?.Attribute("Type");
// var subtypeId = (string)idElement?.Element("SubtypeId") ?? (string)idElement?.Attribute("Typeid");
// var displayName = (string)gasDefinition.Element("DisplayName");
// lock (_definitions)
// _definitions.Add(new Definition("Gas", displayName, null, typeId, subtypeId));
//}
var gasDefinitions = document.XPathSelectElements(@"/Definitions/GasProperties/Gas");
foreach (var gasDefinition in gasDefinitions)
{
var isPublic = (bool?)gasDefinition.Element("Public") ?? true;
if (!isPublic)
continue;
var idElement = gasDefinition.Element("Id");
var typeId = (string)idElement?.Element("TypeId") ?? (string)idElement?.Attribute("Type");
var subtypeId = (string)idElement?.Element("SubtypeId") ?? (string)idElement?.Attribute("Typeid");
lock (_definitions)
{
_definitions.Add(new Definition("Gas", null, subtypeId, null, typeId, subtypeId));
}
}

var physicalItemDefinitions = document.XPathSelectElements(@"/Definitions/PhysicalItems/PhysicalItem");
foreach (var physicalItemDefinition in physicalItemDefinitions)
{
var isPublic = (bool?) physicalItemDefinition.Element("Public") ?? true;
var isPublic = (bool?)physicalItemDefinition.Element("Public") ?? true;
if (!isPublic)
continue;
var canSpawnFromScreen = (bool?) physicalItemDefinition.Element("CanSpawnFromScreen") ?? true;
var canSpawnFromScreen = (bool?)physicalItemDefinition.Element("CanSpawnFromScreen") ?? true;
if (!canSpawnFromScreen)
continue;
var idElement = physicalItemDefinition.Element("Id");
var typeId = (string) idElement?.Element("TypeId") ?? (string) idElement?.Attribute("Type");
var subtypeId = (string) idElement?.Element("SubtypeId") ?? (string) idElement?.Attribute("Typeid");
var displayName = text.Get((string) physicalItemDefinition.Element("DisplayName"));
var typeId = (string)idElement?.Element("TypeId") ?? (string)idElement?.Attribute("Type");
var subtypeId = (string)idElement?.Element("SubtypeId") ?? (string)idElement?.Attribute("Typeid");
var displayName = text.Get((string)physicalItemDefinition.Element("DisplayName"));
lock (_definitions)
{
_definitions.Add(new Definition(GroupOf(typeId), null, displayName, null, typeId, subtypeId));
}
}

var blueprintDefinitions = document.XPathSelectElements(@"/Definitions/Blueprints/Blueprint");
foreach (var blueprintDefinition in blueprintDefinitions)
{
var idElement = blueprintDefinition.Element("Id");
var typeId = (string)idElement?.Element("TypeId") ?? (string)idElement?.Attribute("Type");
var subtypeId = (string)idElement?.Element("SubtypeId") ?? (string)idElement?.Attribute("Typeid");
var displayName = text.Get((string)blueprintDefinition.Element("DisplayName"));
lock (_definitions)
{
_definitions.Add(new Definition("Blueprints", null, displayName, null, typeId, subtypeId));
}
}
}

string GroupOf(string typeId)
Expand All @@ -172,6 +194,7 @@ string GroupOf(string typeId)
case "OxygenContainerObject":
case "GasContainerObject":
case "PhysicalGunObject": return "Tools";
case "Blueprint": return "Blueprints";
default: return "Other";
}
}
Expand Down

0 comments on commit 63e67c1

Please sign in to comment.