diff --git a/AideDeJeu/AideDeJeu/Models/Conditions/Condition.cs b/AideDeJeu/AideDeJeu/Models/Conditions/Condition.cs index a1e6c62f..b5d44c9f 100644 --- a/AideDeJeu/AideDeJeu/Models/Conditions/Condition.cs +++ b/AideDeJeu/AideDeJeu/Models/Conditions/Condition.cs @@ -51,7 +51,7 @@ namespace AideDeJeuLib return; } var paragraphBlock = block as Markdig.Syntax.ParagraphBlock; - this.Text += MarkdownExtensions.MarkdownToHtml(paragraphBlock.ToMarkdownString()) + "\n"; + this.Text += paragraphBlock.ToMarkdownString() + "\n"; } if (block is Markdig.Syntax.ListBlock) { @@ -107,7 +107,7 @@ namespace AideDeJeuLib if (ininblock is Markdig.Syntax.ParagraphBlock) { var paragraphBlock = ininblock as Markdig.Syntax.ParagraphBlock; - this.Text += listBlock.BulletType + " " + MarkdownExtensions.MarkdownToHtml(paragraphBlock.ToMarkdownString()) + "\n"; + this.Text += listBlock.BulletType + " " + paragraphBlock.ToMarkdownString() + "\n"; } } } diff --git a/AideDeJeu/AideDeJeu/Models/Item.cs b/AideDeJeu/AideDeJeu/Models/Item.cs index ec4d25d0..911fd56d 100644 --- a/AideDeJeu/AideDeJeu/Models/Item.cs +++ b/AideDeJeu/AideDeJeu/Models/Item.cs @@ -4,16 +4,6 @@ using System.Xml; namespace AideDeJeuLib { - public class Property : Dictionary - { - - } - - public class Properties : Dictionary - { - - } - public abstract class Item { public string Name { get; set; } @@ -28,8 +18,6 @@ namespace AideDeJeuLib } } - //public Properties Properties { get; set; } - public abstract string Markdown { get; } public abstract void Parse(ref Markdig.Syntax.ContainerBlock.Enumerator enumerator); } diff --git a/AideDeJeu/AideDeJeu/Models/Spells/Spell.cs b/AideDeJeu/AideDeJeu/Models/Spells/Spell.cs index 80f13273..06482a83 100644 --- a/AideDeJeu/AideDeJeu/Models/Spells/Spell.cs +++ b/AideDeJeu/AideDeJeu/Models/Spells/Spell.cs @@ -53,7 +53,7 @@ namespace AideDeJeuLib } var paragraphBlock = block as Markdig.Syntax.ParagraphBlock; - this.DescriptionHtml += MarkdownExtensions.MarkdownToHtml(paragraphBlock.ToMarkdownString()) + "\n"; + this.DescriptionHtml += paragraphBlock.ToMarkdownString() + "\n"; ////DumpParagraphBlock(paragraphBlock); //Console.WriteLine(paragraphBlock.IsBreakable); //spell.DescriptionHtml += paragraphBlock.Inline.ToContainerString(); @@ -126,7 +126,7 @@ namespace AideDeJeuLib if (ininblock is Markdig.Syntax.ParagraphBlock) { var paragraphBlock = ininblock as Markdig.Syntax.ParagraphBlock; - this.DescriptionHtml += listBlock.BulletType + " " + MarkdownExtensions.MarkdownToHtml(paragraphBlock.ToMarkdownString()) + "\n"; + this.DescriptionHtml += listBlock.BulletType + " " + paragraphBlock.ToMarkdownString() + "\n"; } } } diff --git a/AideDeJeu/AideDeJeu/Tools/MarkdownExtensions.cs b/AideDeJeu/AideDeJeu/Tools/MarkdownExtensions.cs index ef24bf6e..87389719 100644 --- a/AideDeJeu/AideDeJeu/Tools/MarkdownExtensions.cs +++ b/AideDeJeu/AideDeJeu/Tools/MarkdownExtensions.cs @@ -6,44 +6,16 @@ using Markdig; using AideDeJeuLib; using Markdig.Syntax; using Markdig.Syntax.Inlines; +using Markdig.Parsers; namespace AideDeJeu.Tools { public static class MarkdownExtensions { - public static IEnumerable MarkdownToSpells(string md) where TSpell : Spell, new() - { - var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build(); - var document = Markdig.Parsers.MarkdownParser.Parse(md, pipeline); - return document.ToSpells(); - } - - public static IEnumerable MarkdownToMonsters(string md) where TMonster : Monster, new() - { - var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build(); - var document = Markdig.Parsers.MarkdownParser.Parse(md, pipeline); - return document.ToMonsters(); - } - - public static IEnumerable MarkdownToConditions(string md) where TCondition : Condition, new() - { - var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build(); - var document = Markdig.Parsers.MarkdownParser.Parse(md, pipeline); - return document.ToConditions(); - } - - public static string MarkdownToHtml(string md) - { - //var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build(); - //return Markdown.ToHtml(md, pipeline); - return md; - } - - public static Item ToItem(string md) { var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build(); - var document = Markdig.Parsers.MarkdownParser.Parse(md, pipeline); + var document = MarkdownParser.Parse(md, pipeline); var enumerator = document.GetEnumerator(); try @@ -53,7 +25,7 @@ namespace AideDeJeu.Tools { var block = enumerator.Current; - if (enumerator.Current is Markdig.Syntax.ParagraphBlock) + if (enumerator.Current is ParagraphBlock) { if(block.IsNewItem()) { @@ -108,565 +80,6 @@ namespace AideDeJeu.Tools return null; } - public static IEnumerable ToSpells(this Markdig.Syntax.MarkdownDocument document) where TSpell : Spell, new() - { - var spells = new List(); - TSpell spell = null; - foreach (var block in document) - { - //DumpBlock(block); - if (block is Markdig.Syntax.HeadingBlock) - { - var headingBlock = block as Markdig.Syntax.HeadingBlock; - //DumpHeadingBlock(headingBlock); - if (headingBlock.HeaderChar == '#' && headingBlock.Level == 1) - { - if (spell != null) - { - spells.Add(spell); - //yield return spell; - } - spell = new TSpell(); - spell.Name = headingBlock.Inline.ToMarkdownString(); - //Console.WriteLine(spell.Name); - } - } - if (block is Markdig.Syntax.ParagraphBlock) - { - var paragraphBlock = block as Markdig.Syntax.ParagraphBlock; - spell.DescriptionHtml += 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 == '-') - { - spell.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) => - { - //if (m.Alignment != null) - //{ - //App.Current.MainPage.DisplayAlert("Erreur de parsing", s, "OK"); - //} - ////Debug.Assert(monster.Alignment == null, str); - //var regexx = new Regex("(?.*) de taille (?.*), (?.*)"); - //var matchh = regexx.Match(s); - //m.Alignment = matchh.Groups["alignment"].Value; - //m.Size = matchh.Groups["size"].Value; - //m.Type = matchh.Groups["type"].Value; - }) - }; - - foreach (var property in properties) - { - if (str.StartsWith(property.Item1)) - { - property.Item2.Invoke(spell, str.Substring(property.Item1.Length)); - break; - } - } - - /*var match = regex.Match(str); - var key = match.Groups["key"].Value; - var value = match.Groups["value"].Value; - switch (key) - { - case "NameVO": - spell.NameVO = value; - break; - case "CastingTime": - spell.CastingTime = value; - break; - case "Components": - spell.Components = value; - break; - case "Duration": - spell.Duration = value; - break; - case "LevelType": - spell.LevelType = value; - break; - case "Range": - spell.Range = value; - break; - case "Source": - spell.Source += value + " "; - break; - case "Classes": - spell.Source += value; - break; - }*/ - } - } - - //DumpListItemBlock(inblock as Markdig.Syntax.ListItemBlock); - } - } - } - 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; - spell.DescriptionHtml += listBlock.BulletType + " " + MarkdownToHtml(paragraphBlock.ToMarkdownString()) + "\n"; - } - } - } - } - } - } - else if (block is Markdig.Extensions.Tables.Table) - { - var tableBlock = block as Markdig.Extensions.Tables.Table; - spell.DescriptionHtml += "\n\n" + tableBlock.ToMarkdownString() + "\n\n"; - } - - - } - if (spell != null) - { - //yield return spell; - spells.Add(spell); - } - return spells; - } - - public static IEnumerable ToMonsters(this Markdig.Syntax.MarkdownDocument document) where TMonster : Monster, new() - { - var monsters = new List(); - TMonster monster = null; - List features = null; - List specialFeatures = null; - List actions = null; - List reactions = null; - List legendaryActions = null; - foreach (var block in document) - { - //Debug.WriteLine(block.GetType()); - //DumpBlock(block); - if (block is Markdig.Syntax.HeadingBlock) - { - var headingBlock = block as Markdig.Syntax.HeadingBlock; - //DumpHeadingBlock(headingBlock); - if (headingBlock.HeaderChar == '#' && headingBlock.Level == 1) - { - if (monster != null) - { - monster.SpecialFeatures = specialFeatures; - monster.Actions = actions; - monster.Reactions = reactions; - monster.LegendaryActions = legendaryActions; - specialFeatures = null; - actions = null; - reactions = null; - legendaryActions = null; - features = null; - monsters.Add(monster); - //yield return monster; - } - monster = new TMonster(); - monster.Name = headingBlock.Inline.ToMarkdownString(); - //Console.WriteLine(spell.Name); - } - if (headingBlock.HeaderChar == '#' && headingBlock.Level == 2) - { - switch (headingBlock.Inline.ToMarkdownString()) - { - case "Capacités": - case "Special Features": - features = specialFeatures = new List(); - break; - case "Actions": - features = actions = new List(); - break; - case "Réaction": - case "Réactions": - case "Reaction": - case "Reactions": - features = reactions = new List(); - break; - case "Actions légendaires": - case "Legendary Actions": - features = legendaryActions = new List(); - break; - default: - App.Current.MainPage.DisplayAlert("Erreur de parsing", headingBlock.Inline.ToMarkdownString(), "OK"); - break; - } - } - } - else if (block is Markdig.Syntax.ParagraphBlock) - { - var paragraphBlock = block as Markdig.Syntax.ParagraphBlock; - features?.Add(paragraphBlock.ToMarkdownString()); - ////DumpParagraphBlock(paragraphBlock); - //Console.WriteLine(paragraphBlock.IsBreakable); - //spell.DescriptionHtml += paragraphBlock.Inline.ToContainerString(); - //if(paragraphBlock.IsBreakable) - //{ - // spell.DescriptionHtml += "\n"; - //} - } - else if (block is Markdig.Syntax.ListBlock) - { - var listBlock = block as Markdig.Syntax.ListBlock; - //DumpListBlock(listBlock); - if (listBlock.BulletType == '-') - { - monster.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>("**Classe d'armure** ", (m, s) => m.ArmorClass = s), - new Tuple>("**Points de vie** ", (m, s) => m.HitPoints = s), - new Tuple>("**Vitesse** ", (m, s) => m.Speed = s), - new Tuple>("**Résistance aux dégâts** ", (m, s) => m.DamageResistances = s), - new Tuple>("**Résistances aux dégâts** ", (m, s) => m.DamageResistances = s), - new Tuple>("**Résistance contre les dégâts** ", (m, s) => m.DamageResistances = s), - new Tuple>("**Résistances contre les dégâts** ", (m, s) => m.DamageResistances = s), - new Tuple>("**Immunité contre les dégâts** ", (m, s) => m.DamageImmunities = s), - new Tuple>("**Immunité contre des dégâts** ", (m, s) => m.DamageImmunities = s), - new Tuple>("**Immunité aux dégâts** ", (m, s) => m.DamageImmunities = s), - new Tuple>("**Immunité à l'état** ", (m, s) => m.ConditionImmunities = s), - new Tuple>("**Immunités à l'état** ", (m, s) => m.ConditionImmunities = s), - new Tuple>("**Immunité contre l'état** ", (m, s) => m.ConditionImmunities = s), - new Tuple>("**Immunité contre les états** ", (m, s) => m.ConditionImmunities = s), - new Tuple>("**Immunités contre les états** ", (m, s) => m.ConditionImmunities = s), - new Tuple>("**Vulnérabilité aux dégâts** ", (m, s) => m.DamageVulnerabilities = s), - new Tuple>("**Vulnérabilité contre les dégâts** ", (m, s) => m.DamageVulnerabilities = s), - new Tuple>("**Vulnérabilité** ", (m, s) => m.DamageVulnerabilities = s), - new Tuple>("**Sens** ", (m, s) => m.Senses = s), - new Tuple>("**Langue** ", (m, s) => m.Languages = s), - new Tuple>("**Langues** ", (m, s) => m.Languages = s), - new Tuple>("**Dangerosité** ", (m, s) => m.Challenge = s), - new Tuple>("**Jets de sauvegarde** ", (m, s) => m.SavingThrows = s), - new Tuple>("**Jet de sauvegarde** ", (m, s) => m.SavingThrows = s), - new Tuple>("**Compétences** ", (m, s) => m.Skills = s), - new Tuple>("**Compétence** ", (m, s) => m.Skills = s), - - new Tuple>("**Armor Class** ", (m, s) => m.ArmorClass = s), - new Tuple>("**Hit Points** ", (m, s) => m.HitPoints = s), - new Tuple>("**Speed** ", (m, s) => m.Speed = s), - new Tuple>("**Damage Resistance** ", (m, s) => m.DamageResistances = s), - new Tuple>("**Damage Resistances** ", (m, s) => m.DamageResistances = s), - new Tuple>("**Résistance contre les dégâts** ", (m, s) => m.DamageResistances = s), - new Tuple>("**Résistances contre les dégâts** ", (m, s) => m.DamageResistances = s), - new Tuple>("**Damage Immunities** ", (m, s) => m.DamageImmunities = s), - new Tuple>("**Immunité contre des dégâts** ", (m, s) => m.DamageImmunities = s), - new Tuple>("**Immunité aux dégâts** ", (m, s) => m.DamageImmunities = s), - new Tuple>("**Condition Immunities** ", (m, s) => m.ConditionImmunities = s), - new Tuple>("**Immunités à l'état** ", (m, s) => m.ConditionImmunities = s), - new Tuple>("**Immunité contre l'état** ", (m, s) => m.ConditionImmunities = s), - new Tuple>("**Immunité contre les états** ", (m, s) => m.ConditionImmunities = s), - new Tuple>("**Immunités contre les états** ", (m, s) => m.ConditionImmunities = s), - new Tuple>("**Damage Vulnerabilities** ", (m, s) => m.DamageVulnerabilities = s), - new Tuple>("**Vulnérabilité contre les dégâts** ", (m, s) => m.DamageVulnerabilities = s), - new Tuple>("**Vulnérabilité** ", (m, s) => m.DamageVulnerabilities = s), - new Tuple>("**Senses** ", (m, s) => m.Senses = s), - new Tuple>("**Languages** ", (m, s) => m.Languages = s), - new Tuple>("**Langues** ", (m, s) => m.Languages = s), - new Tuple>("**Challenge** ", (m, s) => m.Challenge = s), - new Tuple>("**Saving Throws** ", (m, s) => m.SavingThrows = s), - new Tuple>("**Jet de sauvegarde** ", (m, s) => m.SavingThrows = s), - new Tuple>("**Skills** ", (m, s) => m.Skills = s), - new Tuple>("**Compétence** ", (m, s) => m.Skills = s), - - new Tuple>("NameVO: ", (m, s) => m.NameVO = s), - - new Tuple>("", (m,s) => - { - if (!string.IsNullOrEmpty(m.Alignment)) - { - App.Current.MainPage.DisplayAlert("Erreur de parsing", s, "OK"); - } - else - { - //Debug.Assert(monster.Alignment == null, str); - var regexx = new Regex("(?.*) de taille (?.*), (?.*)"); - var matchh = regexx.Match(s); - m.Alignment = matchh.Groups["alignment"].Value; - m.Size = matchh.Groups["size"].Value; - m.Type = matchh.Groups["type"].Value; - if(string.IsNullOrEmpty(m.Alignment)) - { - regexx = new Regex("(?.*?) (?.*?), (?.*)"); - matchh = regexx.Match(s); - m.Alignment = matchh.Groups["alignment"].Value; - m.Size = matchh.Groups["size"].Value; - m.Type = matchh.Groups["type"].Value; - } - } - }) - }; - - foreach (var property in properties) - { - if (str.StartsWith(property.Item1)) - { - property.Item2.Invoke(monster, str.Substring(property.Item1.Length)); - break; - } - } - } - } - - //DumpListItemBlock(inblock as Markdig.Syntax.ListItemBlock); - } - } - } - 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; - features?.Add(listBlock.BulletType + " " + paragraphBlock.ToMarkdownString()); - } - } - } - } - } - } - else if (block is Markdig.Extensions.Tables.Table) - { - var tableBlock = block as Markdig.Extensions.Tables.Table; - var table = tableBlock.ToTable(); - if (table.ContainsKey("FOR")) - { - monster.Strength = table["FOR"].FirstOrDefault(); - monster.Dexterity = table["DEX"].FirstOrDefault(); - monster.Constitution = table["CON"].FirstOrDefault(); - monster.Intelligence = table["INT"].FirstOrDefault(); - monster.Wisdom = table["SAG"].FirstOrDefault(); - monster.Charisma = table["CHA"].FirstOrDefault(); - } - else if (table.ContainsKey("STR")) - { - monster.Strength = table["STR"].FirstOrDefault(); - monster.Dexterity = table["DEX"].FirstOrDefault(); - monster.Constitution = table["CON"].FirstOrDefault(); - monster.Intelligence = table["INT"].FirstOrDefault(); - monster.Wisdom = table["WIS"].FirstOrDefault(); - monster.Charisma = table["CHA"].FirstOrDefault(); - } - //else - //{ - features?.Add(tableBlock.ToMarkdownString()); - //} - } - else if (block is Markdig.Syntax.LinkReferenceDefinitionGroup) - { - - var linkReferenceDefinitionGroup = block as Markdig.Syntax.LinkReferenceDefinitionGroup; - - foreach (var linkBlock in linkReferenceDefinitionGroup) - { - var linkReferenceDefinition = linkBlock as Markdig.Syntax.LinkReferenceDefinition; - //linkReferenceDefinition. - } - } - else if (block is Markdig.Syntax.LinkReferenceDefinition) - { - //Debug.WriteLine(block.GetType()); - } - else - { - //Debug.WriteLine(block.GetType()); - } - } - if (monster != null) - { - monster.SpecialFeatures = specialFeatures; - monster.Actions = actions; - monster.Reactions = reactions; - monster.LegendaryActions = legendaryActions; - monsters.Add(monster); - //yield return monster; - } - return monsters; - } - - - public static IEnumerable ToConditions(this Markdig.Syntax.MarkdownDocument document) where TCondition : Condition, new() - { - var spells = new List(); - TCondition spell = null; - foreach (var block in document) - { - //DumpBlock(block); - if (block is Markdig.Syntax.HeadingBlock) - { - var headingBlock = block as Markdig.Syntax.HeadingBlock; - //DumpHeadingBlock(headingBlock); - if (headingBlock.HeaderChar == '#' && (headingBlock.Level == 1 || headingBlock.Level == 2)) - { - if (spell != null) - { - spells.Add(spell); - //yield return spell; - } - spell = new TCondition(); - spell.Name = headingBlock.Inline.ToMarkdownString(); - //Console.WriteLine(spell.Name); - } - } - if (block is Markdig.Syntax.ParagraphBlock) - { - var paragraphBlock = block as Markdig.Syntax.ParagraphBlock; - spell.Text += MarkdownToHtml(paragraphBlock.ToMarkdownString()) + "\n"; - } - if (block is Markdig.Syntax.ListBlock) - { - var listBlock = block as Markdig.Syntax.ListBlock; - //DumpListBlock(listBlock); - if (listBlock.BulletType == '-') - { - 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), - }; - - foreach (var property in properties) - { - if (str.StartsWith(property.Item1)) - { - property.Item2.Invoke(spell, 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; - spell.Text += listBlock.BulletType + " " + MarkdownToHtml(paragraphBlock.ToMarkdownString()) + "\n"; - } - } - } - } - } - } - else if (block is Markdig.Extensions.Tables.Table) - { - var tableBlock = block as Markdig.Extensions.Tables.Table; - spell.Text += "\n\n" + tableBlock.ToMarkdownString() + "\n\n"; - } - - - } - if (spell != null) - { - //yield return spell; - spells.Add(spell); - } - return spells; - } - - - - - - - - - - - - public static string ToMarkdownString(this Markdig.Syntax.Inlines.ContainerInline inlines) @@ -802,89 +215,5 @@ namespace AideDeJeu.Tools } return table; } - - public static string HtmlToMarkdownString(string html) - { - return html - .Replace("\n", "\n\n") - ; - } - - public static void Dump(this Markdig.Syntax.ParagraphBlock block) - { - //if (block.Lines != null) - //{ - // foreach (var line in block.Lines) - // { - // var stringline = line as Markdig.Helpers.StringLine?; - // Debug.WriteLine(stringline.ToString()); - // } - //} - } - public static void Dump(this Markdig.Syntax.ListBlock block) - { - //Debug.WriteLine(block.BulletType); - foreach (var inblock in block) - { - inblock.Dump(); - } - } - public static void Dump(Markdig.Syntax.ListItemBlock block) - { - foreach (var inblock in block) - { - inblock.Dump(); - } - } - public static void Dump(this Markdig.Syntax.HeadingBlock block) - { - //Debug.WriteLine(block.HeaderChar); - //Debug.WriteLine(block.Level); - //foreach(var line in block.Lines.Lines) - //{ - // DumpStringLine(line); - //} - } - public static void Dump(this Markdig.Helpers.StringLine line) - { - Console.WriteLine(line.ToString()); - } - public static void Dump(this Markdig.Syntax.Block block) - { - //Debug.WriteLine(block.Column); - //Debug.WriteLine(block.IsBreakable); - //Debug.WriteLine(block.IsOpen); - //Debug.WriteLine(block.Line); - //Debug.WriteLine(block.RemoveAfterProcessInlines); - //Debug.WriteLine(block.Span.ToString()); - //Debug.WriteLine(block.Span.ToString(MD)); - //Debug.WriteLine(block.ToString()); - if (block is Markdig.Syntax.ParagraphBlock) - { - (block as Markdig.Syntax.ParagraphBlock).Dump(); - } - if (block is Markdig.Syntax.ListBlock) - { - (block as Markdig.Syntax.ListBlock).Dump(); - } - if (block is Markdig.Syntax.HeadingBlock) - { - (block as Markdig.Syntax.HeadingBlock).Dump(); - } - if (block is Markdig.Syntax.ListItemBlock) - { - (block as Markdig.Syntax.ListItemBlock).Dump(); - } - } - public static void Dump(this Markdig.Syntax.MarkdownDocument document) - { - foreach (var block in document) - { - //Debug.WriteLine(block.GetType()); - //block.Dump(); - } - } - - } } diff --git a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs index fe7c948e..604d54cc 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs @@ -91,15 +91,45 @@ namespace AideDeJeu.ViewModels return _AllItems; } + public IEnumerable _Items = new List(); + public IEnumerable Items + { + get + { + return _Items; + } + set + { + SetProperty(ref _Items, value); + } + } + + private Item _SelectedItem; + public Item SelectedItem + { + get + { + return _SelectedItem; + } + set + { + SetProperty(ref _SelectedItem, value); + if (_SelectedItem != null) + { + Main.GotoItemCommand.Execute(_SelectedItem); + } + } + } + + async Task LoadItemsAsync(CancellationToken cancellationToken = default) { IsBusy = true; - Main.IsLoading = true; try { var filterViewModel = Main.GetFilterViewModel(ItemSourceType); var items = await filterViewModel.FilterItems(await GetAllItemsAsync(), cancellationToken: cancellationToken); - Main.Items = items.ToList(); + Items = items.ToList(); } catch (OperationCanceledException ex) { @@ -107,7 +137,6 @@ namespace AideDeJeu.ViewModels } finally { - Main.IsLoading = false; IsBusy = false; } } diff --git a/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs index fdf0a8de..e52eeadb 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs @@ -112,23 +112,6 @@ namespace AideDeJeu.ViewModels } } - private Item _SelectedItem; - public Item SelectedItem - { - get - { - return _SelectedItem; - } - set - { - SetProperty(ref _SelectedItem, value); - if (_SelectedItem != null) - { - GotoItemCommand.Execute(_SelectedItem); - } - } - } - public Command LoadItemsCommand { get; private set; } public Command GotoItemCommand { get; private set; } @@ -212,7 +195,13 @@ namespace AideDeJeu.ViewModels } else { - await Navigator.GotoItemsPageAsync(null); + var regex = new Regex("/(?.*)\\.md"); + var match = regex.Match(s); + var file = match.Groups["file"].Value; + var itemSourceType = MDFileToItemSourceType(file); + var items = GetItemsViewModel(itemSourceType); + items.LoadItemsCommand.Execute(null); + await Navigator.GotoItemsPageAsync(items); } } } diff --git a/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs b/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs index 65c8323e..0225513f 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/Navigator.cs @@ -1,5 +1,6 @@ using AideDeJeu.Views; using AideDeJeuLib; +using System.Collections.Generic; using System.Threading.Tasks; using Xamarin.Forms; @@ -33,13 +34,13 @@ namespace AideDeJeu.ViewModels await Navigation.PushAsync(new ItemDetailPage(vm)); } - public async Task GotoItemsPageAsync(Item item) + public async Task GotoItemsPageAsync(ItemsViewModel itemsVM) { //if (item == null) // return; //var vm = new ItemDetailViewModel(item); - await Navigation.PushAsync(new ItemsPage()); + await Navigation.PushAsync(new ItemsPage(itemsVM)); } } diff --git a/AideDeJeu/AideDeJeu/Views/ItemsPage.xaml.cs b/AideDeJeu/AideDeJeu/Views/ItemsPage.xaml.cs index c9e9e935..8e4fb382 100644 --- a/AideDeJeu/AideDeJeu/Views/ItemsPage.xaml.cs +++ b/AideDeJeu/AideDeJeu/Views/ItemsPage.xaml.cs @@ -18,15 +18,19 @@ namespace AideDeJeu.Views } //INavig//ator Navigator; - public ItemsPage () + public ItemsViewModel _ItemsViewModel; + public ItemsViewModel ItemsViewModel + { + get + { + return _ItemsViewModel; + } + } + public ItemsPage (ItemsViewModel itemsViewModel) { InitializeComponent (); - //DependencyService.Register(new Navigator((Detail as NavigationPage).Navigation)); - - //Navigator = new Navigator((Detail as NavigationPage).Navigation); - //BindingContext = viewModel = new MainViewModel(Navigator); - BindingContext = Main; + BindingContext = _ItemsViewModel = itemsViewModel; // Main; this.SizeChanged += (o, e) => { if(this.Width > 0 && this.Height > 0) @@ -35,6 +39,19 @@ namespace AideDeJeu.Views } }; } + public ItemsPage() + { + InitializeComponent(); + + BindingContext = Main; + + this.SizeChanged += (o, e) => { + if (this.Width > 0 && this.Height > 0) + { + this.IsPresented = this.Width > this.Height; + } + }; + } protected override void OnAppearing() { diff --git a/AideDeJeu/AideDeJeuCmd/Program.cs b/AideDeJeu/AideDeJeuCmd/Program.cs index e879f18a..7484a142 100644 --- a/AideDeJeu/AideDeJeuCmd/Program.cs +++ b/AideDeJeu/AideDeJeuCmd/Program.cs @@ -43,11 +43,11 @@ namespace AideDeJeuCmd var pipeline = new MarkdownPipelineBuilder() .UsePipeTables() .Build(); - var document = Markdig.Parsers.MarkdownParser.Parse(md, pipeline); + //var document = Markdig.Parsers.MarkdownParser.Parse(md, pipeline); //DumpMarkdownDocument(document); - var monsters = document.ToMonsters(); - document.Dump(); + var monsters = AideDeJeu.Tools.MarkdownExtensions.ToItem(md) as IEnumerable; // document.ToMonsters(); + //document.Dump(); Console.WriteLine("ok"); //var md2 = monsters.ToMarkdownString(); //if (md.CompareTo(md2) != 0) @@ -64,7 +64,7 @@ namespace AideDeJeuCmd var result = string.Empty; var md = await LoadStringAsync(dataDir + "spells_hd.md"); - var items = AideDeJeu.Tools.MarkdownExtensions.MarkdownToSpells(md); + var items = AideDeJeu.Tools.MarkdownExtensions.ToItem(md) as IEnumerable; var classes = new string[] {