From 72587c773adae98344d8c061b6acda8521efa046 Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Fri, 13 Jul 2018 15:07:25 +0200 Subject: [PATCH] Ajustements --- AideDeJeu/AideDeJeu/Models/Spells/Spell.cs | 123 ++++++++++++++++- AideDeJeu/AideDeJeu/Models/Spells/SpellHD.cs | 130 +----------------- AideDeJeu/AideDeJeu/Models/Spells/SpellVO.cs | 4 - .../AideDeJeu/ViewModels/ItemsViewModel.cs | 3 +- AideDeJeu/AideDeJeu/Views/ItemsPage.xaml | 4 +- AideDeJeu/AideDeJeu/Views/ItemsPage.xaml.cs | 7 + 6 files changed, 140 insertions(+), 131 deletions(-) diff --git a/AideDeJeu/AideDeJeu/Models/Spells/Spell.cs b/AideDeJeu/AideDeJeu/Models/Spells/Spell.cs index d784f284..80f13273 100644 --- a/AideDeJeu/AideDeJeu/Models/Spells/Spell.cs +++ b/AideDeJeu/AideDeJeu/Models/Spells/Spell.cs @@ -1,4 +1,7 @@ -using System; +using AideDeJeu.Tools; +using Markdig.Syntax; +using System; +using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.Text.RegularExpressions; @@ -21,5 +24,123 @@ namespace AideDeJeuLib public string Source { get; set; } public abstract string LevelType { get; set; } + + public override void Parse(ref ContainerBlock.Enumerator enumerator) + { + enumerator.MoveNext(); + while (enumerator.Current != null) + { + var block = enumerator.Current; + if (block is Markdig.Syntax.HeadingBlock) + { + var headingBlock = block as Markdig.Syntax.HeadingBlock; + //DumpHeadingBlock(headingBlock); + if (headingBlock.HeaderChar == '#' && headingBlock.Level == 1) + { + if (this.Name != null) + { + return; + } + this.Name = headingBlock.Inline.ToMarkdownString(); + //Console.WriteLine(spell.Name); + } + } + if (block is Markdig.Syntax.ParagraphBlock) + { + if (block.IsNewItem()) + { + return; + } + var paragraphBlock = block as Markdig.Syntax.ParagraphBlock; + + this.DescriptionHtml += MarkdownExtensions.MarkdownToHtml(paragraphBlock.ToMarkdownString()) + "\n"; + ////DumpParagraphBlock(paragraphBlock); + //Console.WriteLine(paragraphBlock.IsBreakable); + //spell.DescriptionHtml += paragraphBlock.Inline.ToContainerString(); + //if(paragraphBlock.IsBreakable) + //{ + // spell.DescriptionHtml += "\n"; + //} + } + if (block is Markdig.Syntax.ListBlock) + { + var listBlock = block as Markdig.Syntax.ListBlock; + //DumpListBlock(listBlock); + if (listBlock.BulletType == '-') + { + this.Source = ""; + foreach (var inblock in listBlock) + { + //DumpBlock(inblock); + var regex = new Regex("(?.*?): (?.*)"); + if (inblock is Markdig.Syntax.ListItemBlock) + { + var listItemBlock = inblock as Markdig.Syntax.ListItemBlock; + foreach (var ininblock in listItemBlock) + { + //DumpBlock(ininblock); + if (ininblock is Markdig.Syntax.ParagraphBlock) + { + var paragraphBlock = ininblock as Markdig.Syntax.ParagraphBlock; + //DumpParagraphBlock(paragraphBlock); + var str = paragraphBlock.Inline.ToMarkdownString(); + + var properties = new List>>() + { + new Tuple>("NameVO: ", (m, s) => m.NameVO = s), + new Tuple>("CastingTime: ", (m, s) => m.CastingTime = s), + new Tuple>("Components: ", (m, s) => m.Components = s), + new Tuple>("Duration: ", (m, s) => m.Duration = s), + new Tuple>("LevelType: ", (m, s) => m.LevelType = s), + new Tuple>("Range: ", (m, s) => m.Range = s), + new Tuple>("Source: ", (m, s) => m.Source = s), + new Tuple>("Classes: ", (m, s) => m.Source += s), + new Tuple>("", (m,s) => + { + }) + }; + + foreach (var property in properties) + { + if (str.StartsWith(property.Item1)) + { + property.Item2.Invoke(this, str.Substring(property.Item1.Length)); + break; + } + } + } + } + } + } + } + else + { + foreach (var inblock in listBlock) + { + if (inblock is Markdig.Syntax.ListItemBlock) + { + var listItemBlock = inblock as Markdig.Syntax.ListItemBlock; + foreach (var ininblock in listItemBlock) + { + //DumpBlock(ininblock); + if (ininblock is Markdig.Syntax.ParagraphBlock) + { + var paragraphBlock = ininblock as Markdig.Syntax.ParagraphBlock; + this.DescriptionHtml += listBlock.BulletType + " " + MarkdownExtensions.MarkdownToHtml(paragraphBlock.ToMarkdownString()) + "\n"; + } + } + } + } + } + } + else if (block is Markdig.Extensions.Tables.Table) + { + var tableBlock = block as Markdig.Extensions.Tables.Table; + this.DescriptionHtml += "\n\n" + tableBlock.ToMarkdownString() + "\n\n"; + } + enumerator.MoveNext(); + } + + } } } diff --git a/AideDeJeu/AideDeJeu/Models/Spells/SpellHD.cs b/AideDeJeu/AideDeJeu/Models/Spells/SpellHD.cs index 2c1edb53..53322496 100644 --- a/AideDeJeu/AideDeJeu/Models/Spells/SpellHD.cs +++ b/AideDeJeu/AideDeJeu/Models/Spells/SpellHD.cs @@ -57,134 +57,18 @@ namespace AideDeJeuLib { return $"# {Name}\n" + - $"- {NameVO}\n" + - $"- _{LevelType}_\n" + - $"- **Temps d'incantation :** {CastingTime}\n" + - $"- **Portée :** {Range}\n" + - $"- **Composantes :** {Components}\n" + - $"- **Durée :** {Duration}\n\n" + + $"{NameVO}\n" + + $"_{LevelType}_\n" + + $"**Temps d'incantation :** {CastingTime}\n" + + $"**Portée :** {Range}\n" + + $"**Composantes :** {Components}\n" + + $"**Durée :** {Duration}\n\n" + $"{DescriptionHtml}\n\n" + - $"- **Source :** {Source}"; + $"**Source :** {Source}"; } } - public override void Parse(ref ContainerBlock.Enumerator enumerator) - { - enumerator.MoveNext(); - while (enumerator.Current != null) - { - var block = enumerator.Current; - if (block is Markdig.Syntax.HeadingBlock) - { - var headingBlock = block as Markdig.Syntax.HeadingBlock; - //DumpHeadingBlock(headingBlock); - if (headingBlock.HeaderChar == '#' && headingBlock.Level == 1) - { - if(this.Name != null) - { - return; - } - this.Name = headingBlock.Inline.ToMarkdownString(); - //Console.WriteLine(spell.Name); - } - } - if (block is Markdig.Syntax.ParagraphBlock) - { - if(block.IsNewItem()) - { - return; - } - var paragraphBlock = block as Markdig.Syntax.ParagraphBlock; - this.DescriptionHtml += MarkdownExtensions.MarkdownToHtml(paragraphBlock.ToMarkdownString()) + "\n"; - ////DumpParagraphBlock(paragraphBlock); - //Console.WriteLine(paragraphBlock.IsBreakable); - //spell.DescriptionHtml += paragraphBlock.Inline.ToContainerString(); - //if(paragraphBlock.IsBreakable) - //{ - // spell.DescriptionHtml += "\n"; - //} - } - if (block is Markdig.Syntax.ListBlock) - { - var listBlock = block as Markdig.Syntax.ListBlock; - //DumpListBlock(listBlock); - if (listBlock.BulletType == '-') - { - this.Source = ""; - foreach (var inblock in listBlock) - { - //DumpBlock(inblock); - var regex = new Regex("(?.*?): (?.*)"); - if (inblock is Markdig.Syntax.ListItemBlock) - { - var listItemBlock = inblock as Markdig.Syntax.ListItemBlock; - foreach (var ininblock in listItemBlock) - { - //DumpBlock(ininblock); - if (ininblock is Markdig.Syntax.ParagraphBlock) - { - var paragraphBlock = ininblock as Markdig.Syntax.ParagraphBlock; - //DumpParagraphBlock(paragraphBlock); - var str = paragraphBlock.Inline.ToMarkdownString(); - - var properties = new List>>() - { - new Tuple>("NameVO: ", (m, s) => m.NameVO = s), - new Tuple>("CastingTime: ", (m, s) => m.CastingTime = s), - new Tuple>("Components: ", (m, s) => m.Components = s), - new Tuple>("Duration: ", (m, s) => m.Duration = s), - new Tuple>("LevelType: ", (m, s) => m.LevelType = s), - new Tuple>("Range: ", (m, s) => m.Range = s), - new Tuple>("Source: ", (m, s) => m.Source = s), - new Tuple>("Classes: ", (m, s) => m.Source += s), - new Tuple>("", (m,s) => - { - }) - }; - - foreach (var property in properties) - { - if (str.StartsWith(property.Item1)) - { - property.Item2.Invoke(this, str.Substring(property.Item1.Length)); - break; - } - } - } - } - } - } - } - else - { - foreach (var inblock in listBlock) - { - if (inblock is Markdig.Syntax.ListItemBlock) - { - var listItemBlock = inblock as Markdig.Syntax.ListItemBlock; - foreach (var ininblock in listItemBlock) - { - //DumpBlock(ininblock); - if (ininblock is Markdig.Syntax.ParagraphBlock) - { - var paragraphBlock = ininblock as Markdig.Syntax.ParagraphBlock; - this.DescriptionHtml += listBlock.BulletType + " " + MarkdownExtensions.MarkdownToHtml(paragraphBlock.ToMarkdownString()) + "\n"; - } - } - } - } - } - } - else if (block is Markdig.Extensions.Tables.Table) - { - var tableBlock = block as Markdig.Extensions.Tables.Table; - this.DescriptionHtml += "\n\n" + tableBlock.ToMarkdownString() + "\n\n"; - } - enumerator.MoveNext(); - } - - } } } diff --git a/AideDeJeu/AideDeJeu/Models/Spells/SpellVO.cs b/AideDeJeu/AideDeJeu/Models/Spells/SpellVO.cs index 8c8d7377..0dfa92e0 100644 --- a/AideDeJeu/AideDeJeu/Models/Spells/SpellVO.cs +++ b/AideDeJeu/AideDeJeu/Models/Spells/SpellVO.cs @@ -49,9 +49,5 @@ namespace AideDeJeuLib } } - public override void Parse(ref ContainerBlock.Enumerator enumerator) - { - throw new NotImplementedException(); - } } } diff --git a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs index 03ad4fb3..49b6f29b 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs @@ -54,7 +54,8 @@ namespace AideDeJeu.ViewModels { resourceName = "AideDeJeu.Data.spells_vo.md"; var md = await Tools.Helpers.GetResourceStringAsync(resourceName); - _AllItems = Tools.MarkdownExtensions.MarkdownToSpells(md); + _AllItems = Tools.MarkdownExtensions.ToItem(md) as IEnumerable; + //_AllItems = Tools.MarkdownExtensions.MarkdownToSpells(md); } break; case ItemSourceType.SpellHD: diff --git a/AideDeJeu/AideDeJeu/Views/ItemsPage.xaml b/AideDeJeu/AideDeJeu/Views/ItemsPage.xaml index 6d5155d6..a60fd85c 100644 --- a/AideDeJeu/AideDeJeu/Views/ItemsPage.xaml +++ b/AideDeJeu/AideDeJeu/Views/ItemsPage.xaml @@ -21,7 +21,7 @@ - @@ -64,7 +64,7 @@ - +