Ejemplo n.º 1
0
        public override async Task Generate(DirectoryInfo directory, ProgrammableBlockApi api)
        {
            var fileName = Path.Combine(directory.FullName, "Namespace-Index.md");
            using (var file = File.CreateText(fileName))
            {
                var writer = new MarkdownWriter(file);
                await writer.BeginParagraphAsync();
                await writer.WriteAsync($"← {MarkdownInline.HRef("Index", "Api-Index")}");
                await writer.EndParagraphAsync();

                await writer.WriteHeaderAsync(3, "Assemblies");
                await writer.BeginParagraphAsync();
                await writer.WriteLineAsync("These are the game assemblies used by programmable block scripts.");
                await writer.WriteLineAsync();
                foreach (var assembly in api.Entries.Select(e => e.AssemblyName).Distinct().OrderBy(n => n))
                    await writer.WriteLineAsync($"{assembly}.dll  ");
                await writer.EndParagraphAsync();

                await writer.WriteHeaderAsync(3, "Types");
                await writer.BeginParagraphAsync();
                await writer.WriteAsync("This index contains all types and members available to ingame scripting - with exception to the .NET types, because including those would have made the listing far too big. There will be links to Microsoft's own documentation for those types where appropriate.");
                await writer.EndParagraphAsync();

                foreach (var blockGroup in api.Entries.Where(e => e.Member is Type).GroupBy(e => e.Member.GetNamespace()).OrderBy(g => g.Key))
                {
                    await writer.WriteHeaderAsync(3, blockGroup.Key);
                    await writer.BeginParagraphAsync();
                    foreach (var type in blockGroup.OrderBy(e => e.ToString(ApiEntryStringFlags.ShortDisplayName | ApiEntryStringFlags.DeclaringTypes)))
                        await writer.WriteLineAsync(MemberGenerator.LinkTo(WebUtility.HtmlEncode(type.ToString(ApiEntryStringFlags.ShortDisplayName | ApiEntryStringFlags.DeclaringTypes)), type));
                    await writer.EndParagraphAsync();
                }

                await writer.FlushAsync();
            }
        }
Ejemplo n.º 2
0
        async Task GenerateNamespaceDoc(DirectoryInfo directory, IGrouping <string, ApiEntry> ns)
        {
            var fileName = Path.Combine(directory.FullName, ToMdFileName(ns.Key));

            using (var file = File.CreateText(fileName))
            {
                var writer = new MarkdownWriter(file);
                await writer.BeginParagraphAsync();

                await writer.WriteAsync($"← {MarkdownInline.HRef("Index", "Api-Index")} ← {MarkdownInline.HRef("Namespace Index", "Namespace-Index")}");

                await writer.EndParagraphAsync();

                await writer.WriteHeaderAsync(1, ns.Key);

                await writer.BeginParagraphAsync();

                foreach (var typeGroup in ns.GroupBy(e => e.DeclaringEntry ?? e).OrderBy(g => g.Key.FullName))
                {
                    await writer.WriteLineAsync(MarkdownInline.Strong(MemberGenerator.LinkTo(typeGroup.Key.Name, typeGroup.Key)));
                }
                await writer.EndParagraphAsync();

                await writer.FlushAsync();
            }
        }
Ejemplo n.º 3
0
        async Task WriteTable(string title, IEnumerable <ApiEntry> entries, ProgrammableBlockApi api, ApiEntry entry, MarkdownWriter writer)
        {
            var items = entries.ToList();

            if (items.Count == 0)
            {
                return;
            }
            await writer.WriteHeaderAsync(4, title);

            await writer.BeginTableAsync("Member", "Description");

            foreach (var item in items)
            {
                await writer.BeginTableCellAsync();

                await writer.WriteAsync(MemberGenerator.LinkTo(item.ToString(ApiEntryStringFlags.ParameterTypes), item));

                await writer.EndTableCellAsync();

                await writer.BeginTableCellAsync();

                var obsoleteAttribute = item.Member.GetCustomAttribute <ObsoleteAttribute>(false);
                if (obsoleteAttribute != null)
                {
                    await writer.BeginParagraphAsync();

                    if (string.IsNullOrWhiteSpace(obsoleteAttribute.Message))
                    {
                        await writer.WriteAsync(MarkdownInline.Emphasized(MarkdownInline.Strong("Obsolete")));
                    }
                    else
                    {
                        await writer.WriteAsync(MarkdownInline.Emphasized($"{MarkdownInline.Strong("Obsolete:")} {obsoleteAttribute.Message}"));
                    }
                    await writer.EndParagraphAsync();
                }

                var context = new XmlDocWriteContext(key => ResolveTypeReference(api, key));
                item.Documentation?.Summary?.WriteMarkdown(context, writer);

                if (entry != item.DeclaringEntry)
                {
                    await writer.BeginParagraphAsync();

                    await writer.WriteAsync(MarkdownInline.Emphasized($"Inherited from {MemberGenerator.LinkTo(item.DeclaringEntry.ToString(ApiEntryStringFlags.ShortDisplayName), item.DeclaringEntry)}"));

                    await writer.EndParagraphAsync();
                }

                await writer.EndTableCellAsync();
            }

            await writer.EndTableAsync();
        }
Ejemplo n.º 4
0
        public override async Task WriteMarkdown(XmlDocWriteContext context, MarkdownWriter writer)
        {
            await writer.BeginParagraphAsync();

            foreach (var node in Content)
            {
                await node.WriteMarkdown(context, writer);
            }
            await writer.EndParagraphAsync();
        }
Ejemplo n.º 5
0
        async Task WriteInheritors(ApiEntry entry, MarkdownWriter writer)
        {
            await writer.BeginParagraphAsync();

            await writer.WriteLineAsync(MarkdownInline.Strong("Inheritors:  "));

            foreach (var iface in entry.InheritorEntries)
            {
                await writer.WriteUnorderedListItemAsync(MemberGenerator.LinkTo(iface.ToString(ApiEntryStringFlags.ShortDisplayName), iface));
            }
            await writer.EndParagraphAsync();
        }
Ejemplo n.º 6
0
        async Task WriteInheritance(ApiEntry entry, MarkdownWriter writer)
        {
            await writer.BeginParagraphAsync();

            await writer.WriteAsync(MarkdownInline.Strong("Inheritance:  "));

            await writer.WriteAsync(" ");

            await writer.WriteLineAsync(string.Join(" ˃ ", AncestorsOf(entry).Reverse()));

            await writer.EndParagraphAsync();
        }
Ejemplo n.º 7
0
        async Task GeneratePage(ProgrammableBlockApi api, DirectoryInfo directory, IGrouping <string, ApiEntry> entries)
        {
            var fileName = Path.Combine(directory.FullName, entries.Key);

            using (var file = File.CreateText(fileName))
            {
                var writer     = new MarkdownWriter(file);
                var firstEntry = entries.First();
                await writer.BeginParagraphAsync();

                await writer.WriteAsync($"← {MarkdownInline.HRef("Index", "Api-Index")} ← {MarkdownInline.HRef("Namespace Index", "Namespace-Index")} ← {LinkTo(firstEntry.DeclaringEntry.ToString(ApiEntryStringFlags.ShortDisplayName), firstEntry.DeclaringEntry)}");

                await writer.EndParagraphAsync();

                foreach (var overload in entries)
                {
                    await writer.WriteHeaderAsync(3, "Summary");

                    switch (overload.Member)
                    {
                    case ConstructorInfo constructorInfo:
                        await WriteConstructor(api, overload, writer, constructorInfo);

                        break;

                    case FieldInfo fieldInfo:
                        await WriteField(api, overload, writer, fieldInfo);

                        break;

                    case PropertyInfo propertyInfo:
                        await WriteProperty(api, overload, writer, propertyInfo);

                        break;

                    case EventInfo eventInfo:
                        await WriteEvent(api, overload, writer, eventInfo);

                        break;

                    case MethodInfo methodInfo:
                        await WriteMethod(api, overload, writer, methodInfo);

                        break;
                    }
                }

                await writer.FlushAsync();
            }
        }
Ejemplo n.º 8
0
        async Task WriteTypeDefinitions(ApiEntry entry, MarkdownWriter writer)
        {
            var defs = _typeDefinitions.Definitions.Where(d => d.TypeName == entry.FullName).ToList();

            if (!defs.Any())
            {
                return;
            }
            await writer.BeginParagraphAsync();

            await writer.WriteLineAsync(MarkdownInline.Strong("Type Definitions:  "));

            foreach (var definition in defs)
            {
                await writer.WriteUnorderedListItemAsync($"`{definition}`");
            }
            await writer.EndParagraphAsync();
        }
Ejemplo n.º 9
0
        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
            })
                        .OrderBy(o => o.Text)
                        .Select(o => MemberGenerator.LinkTo(o.Text, o.Interface))
                        .ToList();

            foreach (var line in lines)
            {
                await writer.WriteUnorderedListItemAsync(line);
            }
            await writer.EndParagraphAsync();
        }
Ejemplo n.º 10
0
        async Task WriteField(ProgrammableBlockApi api, ApiEntry overload, MarkdownWriter writer, FieldInfo fieldInfo)
        {
            await writer.BeginCodeBlockAsync();

            await writer.WriteLineAsync(overload.ToString(ApiEntryStringFlags.Modifiers | ApiEntryStringFlags.GenericParameters | ApiEntryStringFlags.ParameterTypes | ApiEntryStringFlags.ParameterNames | ApiEntryStringFlags.ReturnValue | ApiEntryStringFlags.Accessors));

            await writer.EndCodeBlockAsync();

            if (overload.Documentation?.Summary != null)
            {
                await WriteDocumentation(api, overload.Documentation?.Summary, writer);
            }
            await writer.WriteHeaderAsync(3, "Returns");

            var returnEntry = api.GetEntry(fieldInfo.FieldType, true);
            await writer.BeginParagraphAsync();

            await writer.WriteAsync(LinkTo(returnEntry.ToString(ApiEntryStringFlags.ShortDisplayName), returnEntry));

            await writer.EndParagraphAsync();

            if (overload.Documentation?.Returns != null)
            {
                await WriteDocumentation(api, overload.Documentation?.Returns, writer);
            }

            if (overload.Documentation?.Example != null)
            {
                await writer.WriteHeaderAsync(3, "Example");
                await WriteDocumentation(api, overload.Documentation?.Example, writer);
            }

            if (overload.Documentation?.Remarks != null)
            {
                await writer.WriteHeaderAsync(3, "Remarks");
                await WriteDocumentation(api, overload.Documentation?.Remarks, writer);
            }
        }
Ejemplo n.º 11
0
        async Task WriteTypeDefinitions(ApiEntry entry, MarkdownWriter writer)
        {
            var defs = _typeDefinitions.Definitions.Where(d => d.TypeName == entry.FullName).ToList();

            if (!defs.Any())
            {
                return;
            }
            await writer.BeginParagraphAsync();

            await writer.WriteLineAsync(MarkdownInline.Strong("Type Definitions:  "));

            var lines = defs.Select(d => d.ToString())
                        .OrderBy(o => o)
                        .ToList();

            foreach (var line in lines)
            {
                await writer.WriteUnorderedListItemAsync(line);
            }

            await writer.EndParagraphAsync();
        }
Ejemplo n.º 12
0
        async Task WriteMethod(ProgrammableBlockApi api, ApiEntry overload, MarkdownWriter writer, MethodInfo methodInfo)
        {
            await writer.BeginCodeBlockAsync();

            await writer.WriteLineAsync(overload.ToString(ApiEntryStringFlags.Modifiers | ApiEntryStringFlags.GenericParameters | ApiEntryStringFlags.ParameterTypes | ApiEntryStringFlags.ParameterNames | ApiEntryStringFlags.ReturnValue | ApiEntryStringFlags.Accessors));

            await writer.EndCodeBlockAsync();

            if (overload.Documentation?.Summary != null)
            {
                await WriteDocumentation(api, overload.Documentation?.Summary, writer);
            }
            else
            {
            }
            if (methodInfo.ReturnType != typeof(void))
            {
                await writer.WriteHeaderAsync(3, "Returns");

                var returnEntry = api.GetEntry(methodInfo.ReturnType, true);
                await writer.BeginParagraphAsync();

                await writer.WriteAsync(LinkTo(returnEntry.ToString(ApiEntryStringFlags.ShortDisplayName), returnEntry));

                await writer.EndParagraphAsync();

                if (overload.Documentation?.Returns != null)
                {
                    await WriteDocumentation(api, overload.Documentation?.Returns, writer);
                }
            }

            var parameters = methodInfo.GetParameters();

            if (parameters.Length > 0)
            {
                await writer.WriteHeaderAsync(3, "Parameters");

                foreach (var parameter in parameters)
                {
                    var returnEntry = api.GetEntry(parameter.GetActualParameterType(), true);
                    await writer.WriteAsync("* ");

                    await writer.WriteAsync(LinkTo(returnEntry.ToString(ApiEntryStringFlags.ShortDisplayName), returnEntry));

                    await writer.WriteAsync(" ");

                    await writer.WriteAsync(parameter.Name);

                    await writer.WriteLineAsync();
                }
            }

            if (overload.Documentation?.Example != null)
            {
                await writer.WriteHeaderAsync(3, "Example");
                await WriteDocumentation(api, overload.Documentation?.Example, writer);
            }

            if (overload.Documentation?.Remarks != null)
            {
                await writer.WriteHeaderAsync(3, "Remarks");
                await WriteDocumentation(api, overload.Documentation?.Remarks, writer);
            }
        }
Ejemplo n.º 13
0
        async Task GeneratePage(ProgrammableBlockApi api, DirectoryInfo directory, ApiEntry entry)
        {
            var fileName = Path.Combine(directory.FullName, entry.SuggestedFileName);

            Debug.WriteLine(entry.FullName + " " + fileName);
            using (var file = File.CreateText(fileName))
            {
                var writer = new MarkdownWriter(file);
                await writer.BeginParagraphAsync();

                await writer.WriteAsync($"← {MarkdownInline.HRef("Index", "Api-Index")} ← {MarkdownInline.HRef("Namespace Index", "Namespace-Index")}");

                await writer.EndParagraphAsync();

                await writer.WriteHeaderAsync(4, $"{WebUtility.HtmlEncode(entry.ToString(ApiEntryStringFlags.GenericParameters))} {ConstructOf(entry)}");

                await writer.BeginCodeBlockAsync();

                await writer.WriteLineAsync(entry.ToString(ApiEntryStringFlags.Modifiers | ApiEntryStringFlags.GenericParameters | ApiEntryStringFlags.Inheritance));

                await writer.EndCodeBlockAsync();

                if (entry.Documentation?.Summary != null)
                {
                    await WriteDocumentation(api, entry.Documentation?.Summary, writer);
                }
                await writer.BeginParagraphAsync();

                await writer.WriteLineAsync($"{MarkdownInline.Strong("Namespace:")} {MarkdownInline.HRef(entry.NamespaceName, Path.GetFileNameWithoutExtension(ToMdFileName(entry.NamespaceName)))}");

                await writer.WriteLineAsync($"{MarkdownInline.Strong("Assembly:")} {entry.AssemblyName}.dll");

                await writer.EndParagraphAsync();

                if (entry.BaseEntry != null)
                {
                    await WriteInheritance(entry, writer);
                }
                if (entry.InheritedEntries.Count > 0)
                {
                    await WriteInterfaces(entry, writer);
                }
                if (entry.InheritorEntries.Count > 0)
                {
                    await WriteInheritors(entry, writer);
                }
                await WriteTypeDefinitions(entry, writer);

                var obsoleteAttribute = entry.Member.GetCustomAttribute <ObsoleteAttribute>(false);
                if (obsoleteAttribute != null)
                {
                    await writer.WriteHeaderAsync(2, "Obsolete");

                    await writer.BeginParagraphAsync();

                    await writer.WriteLineAsync("This type should no longer be used and may be removed in the future. If you're using it, you should replace it as soon as possible.  ");

                    await writer.WriteAsync(obsoleteAttribute.Message);

                    await file.WriteLineAsync();
                }

                if (entry.Documentation?.Example != null)
                {
                    await writer.WriteHeaderAsync(4, "Example");
                    await WriteDocumentation(api, entry.Documentation?.Example, writer);
                }

                if (entry.Documentation?.Remarks != null)
                {
                    await writer.WriteHeaderAsync(4, "Remarks");
                    await WriteDocumentation(api, entry.Documentation?.Remarks, writer);
                }

                await WriteMembers(api, entry, writer);

                await writer.FlushAsync();
            }
        }
Ejemplo n.º 14
0
        private async Task GenerateAsync(string path, string output)
        {
            var loader = new TextureLoader();
            var dir    = Path.GetDirectoryName(output) ?? ".\\";

            using (var file = File.CreateText(output))
            {
                var writer = new MarkdownWriter(file);
                await writer.WriteLineAsync("All images are copyright &copy; Keen Software House.");

                await writer.WriteRulerAsync();

                await writer.BeginParagraphAsync();

                await writer.WriteAsync("See ");

                await writer.WriteLinkAsync("Whiplash' nice little tool", "https://gitlab.com/whiplash141/spritebuilder");

                await writer.WriteLineAsync(" for visually designing sprites and generating the code to display them.");

                await writer.EndParagraphAsync();

                await writer.BeginTableAsync("Id", "Size", "Thumbnail");

                int n = 1;
                foreach (var sprite in _icons.OrderBy(i => i.Id))
                {
                    await writer.BeginTableCellAsync();

                    await writer.WriteAsync(sprite.Id);

                    await writer.EndTableCellAsync();

                    var texture = loader.LoadTextureScratch(sprite.Path);
                    if (texture != null)
                    {
                        var image0 = texture.GetImage(0);
                        await writer.BeginTableCellAsync();

                        await writer.WriteAsync($"{image0.Width}x{image0.Height}");

                        await writer.EndTableCellAsync();

                        var hScale = 64.0 / image0.Width;
                        var vScale = 64.0 / image0.Height;
                        var scale  = Math.Min(hScale, vScale);
                        if (scale < 1.0)
                        {
                            var width     = (int)(image0.Width * scale);
                            var height    = (int)(image0.Height * scale);
                            var thumbnail = texture.Resize(width, height, TEX_FILTER_FLAGS.CUBIC);
                            texture.Dispose();
                            texture = thumbnail;
                        }

                        var thumbnailFile = $@"images\spritethumb_{n}.jpg";
                        n++;
                        var thumbnailPath = Path.Combine(dir, thumbnailFile);
                        texture.SaveToJPGFile(0, 1, thumbnailPath);

                        await writer.BeginTableCellAsync();

                        await writer.WriteImageLinkAsync(sprite.Id, thumbnailFile.Replace("\\", "/"));

                        await writer.EndTableCellAsync();

                        texture.Dispose();
                    }
                    else
                    {
                        await writer.BeginTableCellAsync();

                        await writer.WriteAsync("?x?");

                        await writer.EndTableCellAsync();

                        await writer.BeginTableCellAsync();

                        await writer.WriteAsync("Sprite Not Found! Bad Definition?");

                        await writer.EndTableCellAsync();
                    }
                }

                await writer.EndTableAsync();
            }
        }