예제 #1
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();
        }
예제 #2
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();
            }
        }