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

Commit

Permalink
Fixed the problems with the documentation generator
Browse files Browse the repository at this point in the history
  • Loading branch information
malware-dev committed May 15, 2023
1 parent 440e531 commit 9d81cde
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 115 deletions.
42 changes: 26 additions & 16 deletions Source/DocGen2/Services/MarkdownGenerators/TypeGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System;
using Mal.DocGen2.Services.Markdown;
using Mal.DocGen2.Services.XmlDocs;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading.Tasks;
using Mal.DocGen2.Services.Markdown;
using Mal.DocGen2.Services.XmlDocs;

namespace Mal.DocGen2.Services.MarkdownGenerators
{
class TypeGenerator : DocumentGenerator
class TypeGenerator: DocumentGenerator
{
readonly TypeDefinitions _typeDefinitions;

Expand Down Expand Up @@ -84,7 +84,14 @@ async Task GeneratePage(ProgrammableBlockApi api, DirectoryInfo directory, ApiEn

async Task WriteTypeDefinitions(ApiEntry entry, MarkdownWriter writer)
{
var defs = _typeDefinitions.Definitions.Where(d => d.TypeName == entry.FullName).ToList();
if (entry.Name == null
|| entry.Name.EndsWith("IMyFunctionalBlock")
|| entry.Name.EndsWith("IMyTerminalBlock")
|| entry.Name.EndsWith("IMyCubeBlock")
|| entry.Name.EndsWith("IMyEntity"))
return;

var defs = _typeDefinitions.Definitions.Where(d => IsRelevantDefinition(entry, d)).ToList();
if (!defs.Any())
return;
await writer.BeginParagraphAsync();
Expand All @@ -99,9 +106,16 @@ async Task WriteTypeDefinitions(ApiEntry entry, MarkdownWriter writer)
await writer.EndParagraphAsync();
}

private bool IsRelevantDefinition(ApiEntry entry, TypeDefinitions.Definition definition)
{
if (definition.TypeName == entry.FullName)
return true;
return entry.InheritorEntries.Any(e => IsRelevantDefinition(e, definition));
}

string ConstructOf(ApiEntry entry)
{
var type = (Type) entry.Member;
var type = (Type)entry.Member;
if (typeof(Delegate).IsAssignableFrom(type))
return "Delegate";
if (type.IsEnum)
Expand All @@ -127,11 +141,7 @@ async Task WriteInterfaces(ApiEntry entry, MarkdownWriter writer)
await writer.BeginParagraphAsync();
await writer.WriteLineAsync(MarkdownInline.Strong("Implements: "));

var lines = entry.InheritedEntries.Select(iface => new
{
Text = iface.ToString(ApiEntryStringFlags.ShortDisplayName),
Interface = iface
})
var lines = entry.InheritedEntries.Select(iface => new { Text = iface.ToString(ApiEntryStringFlags.ShortDisplayName), Interface = iface })
.OrderBy(o => o.Text)
.Select(o => MemberGenerator.LinkTo(o.Text, o.Interface))
.ToList();
Expand All @@ -145,11 +155,7 @@ async Task WriteInheritors(ApiEntry entry, MarkdownWriter writer)
await writer.BeginParagraphAsync();
await writer.WriteLineAsync(MarkdownInline.Strong("Inheritors: "));

var lines = entry.InheritorEntries.Select(iface => new
{
Text = iface.ToString(ApiEntryStringFlags.ShortDisplayName),
Interface = iface
})
var lines = entry.InheritorEntries.Select(iface => new { Text = iface.ToString(ApiEntryStringFlags.ShortDisplayName), Interface = iface })
.OrderBy(o => o.Text)
.Select(o => MemberGenerator.LinkTo(o.Text, o.Interface))
.ToList();
Expand Down Expand Up @@ -190,8 +196,11 @@ IEnumerable<ApiEntry> AllInheritedEntriesOf(ApiEntry entry)
if (item.BaseEntry != null && visitedMembers.Add(item.BaseEntry))
stack.Push(item.BaseEntry);
foreach (var iface in item.InheritedEntries)
{
if (visitedMembers.Add(iface))
stack.Push(iface);
}

foreach (var member in item.MemberEntries)
yield return member;
}
Expand Down Expand Up @@ -235,6 +244,7 @@ async Task WriteTable(string title, IEnumerable<ApiEntry> entries, ProgrammableB
await writer.WriteAsync(MarkdownInline.Emphasized($"Inherited from {MemberGenerator.LinkTo(item.DeclaringEntry.ToString(ApiEntryStringFlags.ShortDisplayName), item.DeclaringEntry)}"));
await writer.EndParagraphAsync();
}

await writer.EndQuoteAsync();

//await writer.EndTableCellAsync();
Expand Down
9 changes: 5 additions & 4 deletions Source/MDKWhitelistExtractor/Digi/TempBlockSpawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Sandbox.Definitions;
using Sandbox.Game.Entities;
using Sandbox.ModAPI;
using System.Threading.Tasks;
using VRage;
using VRage.Game;
using VRage.Game.ModAPI;
Expand All @@ -17,23 +18,23 @@ namespace Digi.BuildInfo.Features.LiveData
{
public struct TempBlockSpawn
{
public static void Spawn(MyCubeBlockDefinition def, bool deleteGridOnSpawn = true, Action<IMySlimBlock> callback = null)
public static void Spawn(MyCubeBlockDefinition def, bool deleteGridOnSpawn = true, Action<IMySlimBlock> callback = null, Vector3D? spawnPos = null)
{
new TempBlockSpawn(def, deleteGridOnSpawn, callback);
new TempBlockSpawn(def, deleteGridOnSpawn, callback, spawnPos);
}

readonly bool _deleteGrid;
readonly MyCubeBlockDefinition _blockDef;
readonly Action<IMySlimBlock> _callback;

TempBlockSpawn(MyCubeBlockDefinition def, bool deleteGridOnSpawn = true, Action<IMySlimBlock> callback = null)
TempBlockSpawn(MyCubeBlockDefinition def, bool deleteGridOnSpawn = true, Action<IMySlimBlock> callback = null, Vector3D? spawnAt = null)
{
_blockDef = def;
_deleteGrid = deleteGridOnSpawn;
_callback = callback;

MatrixD camMatrix = MyAPIGateway.Session.Camera.WorldMatrix;
Vector3D spawnPos = camMatrix.Translation + camMatrix.Backward * 100;
var spawnPos = spawnAt ?? camMatrix.Translation + camMatrix.Backward * 100;

MyObjectBuilder_CubeBlock blockOB = CreateBlockOB(def.Id);

Expand Down
Loading

0 comments on commit 9d81cde

Please sign in to comment.