diff --git a/AideDeJeu/AideDeJeu/Models/Conditions/Condition.cs b/AideDeJeu/AideDeJeu/Models/Conditions/Condition.cs new file mode 100644 index 00000000..00b55fa0 --- /dev/null +++ b/AideDeJeu/AideDeJeu/Models/Conditions/Condition.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace AideDeJeuLib.Conditions +{ + public class Condition : Item + { + public string Text { get; set; } + + public override string Markdown + { + get + { + return + $"# {Name}\n\n" + + $"{NameVO}\n\n" + + Text; + } + } + } +} diff --git a/AideDeJeu/AideDeJeu/Tools/Helpers.cs b/AideDeJeu/AideDeJeu/Tools/Helpers.cs index 91d9abc7..b4648df0 100644 --- a/AideDeJeu/AideDeJeu/Tools/Helpers.cs +++ b/AideDeJeu/AideDeJeu/Tools/Helpers.cs @@ -60,7 +60,28 @@ namespace AideDeJeu.Tools public static string IdFromName(string name) { - return name.ToLower().Replace(" ", "-").Replace("\'","").Replace("/",""); + string id = string.Empty; + foreach(var c in name) + { + if(c >= 'A' && c <= 'Z') + { + id += c.ToString().ToLower(); + } + else if(c == ' ') + { + id += '-'; + } + else if(c== '\'' || c == '/') + { + // vide + } + else + { + id += c; + } + } + return id; + //return name.ToLower().Replace(" ", "-").Replace("\'","").Replace("/",""); //return RemoveDiacritics(name.ToLower().Replace(" ", "-").Replace("\'", "")); } diff --git a/AideDeJeu/AideDeJeu/Tools/MarkdownExtensions.cs b/AideDeJeu/AideDeJeu/Tools/MarkdownExtensions.cs index 18f53b2c..f9ecb3c8 100644 --- a/AideDeJeu/AideDeJeu/Tools/MarkdownExtensions.cs +++ b/AideDeJeu/AideDeJeu/Tools/MarkdownExtensions.cs @@ -9,6 +9,7 @@ using System.Diagnostics; using AideDeJeuLib.Monsters; using Markdig; using AideDeJeuLib; +using AideDeJeuLib.Conditions; namespace AideDeJeu.Tools { @@ -28,6 +29,13 @@ namespace AideDeJeu.Tools 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(); @@ -471,6 +479,125 @@ namespace AideDeJeu.Tools 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) { var str = string.Empty; diff --git a/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs index 5cda85f7..564872c1 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/FilterViewModel.cs @@ -112,14 +112,13 @@ namespace AideDeJeu.ViewModels { return items.Where(item => { - var spell = item as Spell; + var spell = item; return ( (Helpers.RemoveDiacritics(spell.Name).ToLower().Contains(Helpers.RemoveDiacritics(SearchText ?? string.Empty).ToLower())) || (Helpers.RemoveDiacritics(spell.NameVOText ?? string.Empty).ToLower().Contains(Helpers.RemoveDiacritics(SearchText ?? string.Empty).ToLower())) ); - }).OrderBy(spell => spell.Name) - .AsEnumerable(); + }).AsEnumerable(); }, token); } diff --git a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs index e1f01fcd..6e3685f5 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/ItemsViewModel.cs @@ -68,6 +68,21 @@ namespace AideDeJeu.ViewModels _AllItems = Tools.MarkdownExtensions.MarkdownToSpells(md); } break; + case ItemSourceType.ConditionVO: + { + resourceName = "AideDeJeu.Data.conditions_vo.md"; + var md = await Tools.Helpers.GetResourceStringAsync(resourceName); + _AllItems = Tools.MarkdownExtensions.MarkdownToConditions(md); + } + break; + case ItemSourceType.ConditionHD: + { + resourceName = "AideDeJeu.Data.conditions_hd.md"; + //var md = await Tools.Helpers.GetStringFromUrl("https://raw.githubusercontent.com/Nioux/AideDeJeu/master/Data/spells_hd.md"); + var md = await Tools.Helpers.GetResourceStringAsync(resourceName); + _AllItems = Tools.MarkdownExtensions.MarkdownToConditions(md); + } + break; } } return _AllItems; diff --git a/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs index 4a83ccd0..eeec45aa 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/MainViewModel.cs @@ -163,6 +163,35 @@ namespace AideDeJeu.ViewModels }); } + ItemSourceType MDFileToItemSourceType(string file) + { + if (file == "spells_hd") + { + return ItemSourceType.SpellHD; + } + else if (file == "spells_vo") + { + return ItemSourceType.SpellVO; + } + else if (file == "monsters_hd") + { + return ItemSourceType.MonsterHD; + } + else if (file == "monsters_vo") + { + return ItemSourceType.MonsterVO; + } + else if (file == "conditions_hd") + { + return ItemSourceType.ConditionHD; + } + else if (file == "conditions_vo") + { + return ItemSourceType.ConditionVO; + } + return ItemSourceType.SpellHD; + } + public async Task NavigateToLink(string s) { if (s != null) @@ -171,45 +200,12 @@ namespace AideDeJeu.ViewModels var match = regex.Match(s); var file = match.Groups["file"].Value; var anchor = match.Groups["anchor"].Value; - if (file == "spells_hd") + var itemSourceType = MDFileToItemSourceType(file); + var spells = await GetItemsViewModel(itemSourceType).GetAllItemsAsync(); + var spell = spells.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault(); + if (spell != null) { - var spells = await GetItemsViewModel(ItemSourceType.SpellHD).GetAllItemsAsync(); - var spell = spells.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault(); - if (spell != null) - { - await Navigator.GotoItemDetailPageAsync(spell); - } - } - else if (file == "spells_vo") - { - var spells = await GetItemsViewModel(ItemSourceType.SpellVO).GetAllItemsAsync(); - var spell = spells.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault(); - if (spell != null) - { - await Navigator.GotoItemDetailPageAsync(spell); - } - } - else if (file == "monsters_hd") - { - var monsters = await GetItemsViewModel(ItemSourceType.MonsterHD).GetAllItemsAsync(); - var monster = monsters.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault(); - if (monster != null) - { - await Navigator.GotoItemDetailPageAsync(monster); - } - } - else if (file == "monsters_vo") - { - var monsters = await GetItemsViewModel(ItemSourceType.MonsterVO).GetAllItemsAsync(); - var monster = monsters.Where(i => Tools.Helpers.IdFromName(i.Name) == anchor).FirstOrDefault(); - if (monster != null) - { - await Navigator.GotoItemDetailPageAsync(monster); - } - } - else - { - //Device.OpenUri(new Uri(s)); + await Navigator.GotoItemDetailPageAsync(spell); } } } diff --git a/AideDeJeu/AideDeJeu/Views/MainPage.xaml b/AideDeJeu/AideDeJeu/Views/MainPage.xaml index 158ae63f..9b03d3c9 100644 --- a/AideDeJeu/AideDeJeu/Views/MainPage.xaml +++ b/AideDeJeu/AideDeJeu/Views/MainPage.xaml @@ -35,10 +35,10 @@ - + diff --git a/Data/conditions_hd.md b/Data/conditions_hd.md index b6b10b85..358ef183 100644 --- a/Data/conditions_hd.md +++ b/Data/conditions_hd.md @@ -1,4 +1,4 @@ -# Les états spéciaux +# États spéciaux - NameVO: [Conditions](conditions_vo.md#conditions) diff --git a/Data/conditions_vo.md b/Data/conditions_vo.md index 94311854..2aa675eb 100644 --- a/Data/conditions_vo.md +++ b/Data/conditions_vo.md @@ -1,6 +1,6 @@ # Conditions -- NameVO: [Les états spéciaux](conditions_hd.md#les-états-spéciaux) +- NameVO: [États spéciaux](conditions_hd.md#États-spéciaux) Conditions alter a creature's capabilities in a variety of ways and can arise as a result of a spell, a class feature, a monsters attack, or other effect. Most conditions, such as blinded, are impairments, but a few, such as invisible, can be advantageous.