1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-30 15:06:06 +00:00

Nouvelle navigation câblée

This commit is contained in:
Yan Maniez 2018-07-13 18:42:23 +02:00
parent b560df7e37
commit d8f6d3a8bd
9 changed files with 76 additions and 723 deletions

View file

@ -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";
}
}
}

View file

@ -4,16 +4,6 @@ using System.Xml;
namespace AideDeJeuLib
{
public class Property : Dictionary<string, string>
{
}
public class Properties : Dictionary<string, Property>
{
}
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);
}

View file

@ -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";
}
}
}

View file

@ -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<TSpell> MarkdownToSpells<TSpell>(string md) where TSpell : Spell, new()
{
var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build();
var document = Markdig.Parsers.MarkdownParser.Parse(md, pipeline);
return document.ToSpells<TSpell>();
}
public static IEnumerable<Monster> MarkdownToMonsters<TMonster>(string md) where TMonster : Monster, new()
{
var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build();
var document = Markdig.Parsers.MarkdownParser.Parse(md, pipeline);
return document.ToMonsters<TMonster>();
}
public static IEnumerable<TCondition> MarkdownToConditions<TCondition>(string md) where TCondition : Condition, new()
{
var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build();
var document = Markdig.Parsers.MarkdownParser.Parse(md, pipeline);
return document.ToConditions<TCondition>();
}
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<TSpell> ToSpells<TSpell>(this Markdig.Syntax.MarkdownDocument document) where TSpell : Spell, new()
{
var spells = new List<TSpell>();
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("(?<key>.*?): (?<value>.*)");
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<Tuple<string, Action<TSpell, string>>>()
{
new Tuple<string, Action<TSpell, string>>("NameVO: ", (m, s) => m.NameVO = s),
new Tuple<string, Action<TSpell, string>>("CastingTime: ", (m, s) => m.CastingTime = s),
new Tuple<string, Action<TSpell, string>>("Components: ", (m, s) => m.Components = s),
new Tuple<string, Action<TSpell, string>>("Duration: ", (m, s) => m.Duration = s),
new Tuple<string, Action<TSpell, string>>("LevelType: ", (m, s) => m.LevelType = s),
new Tuple<string, Action<TSpell, string>>("Range: ", (m, s) => m.Range = s),
new Tuple<string, Action<TSpell, string>>("Source: ", (m, s) => m.Source = s),
new Tuple<string, Action<TSpell, string>>("Classes: ", (m, s) => m.Source += s),
new Tuple<string, Action<TSpell, string>>("", (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("(?<type>.*) de taille (?<size>.*), (?<alignment>.*)");
//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<TMonster> ToMonsters<TMonster>(this Markdig.Syntax.MarkdownDocument document) where TMonster : Monster, new()
{
var monsters = new List<TMonster>();
TMonster monster = null;
List<string> features = null;
List<string> specialFeatures = null;
List<string> actions = null;
List<string> reactions = null;
List<string> 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<string>();
break;
case "Actions":
features = actions = new List<string>();
break;
case "Réaction":
case "Réactions":
case "Reaction":
case "Reactions":
features = reactions = new List<string>();
break;
case "Actions légendaires":
case "Legendary Actions":
features = legendaryActions = new List<string>();
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("(?<key>.*?): (?<value>.*)");
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<Tuple<string, Action<Monster, string>>>()
{
new Tuple<string, Action<Monster, string>>("**Classe d'armure** ", (m, s) => m.ArmorClass = s),
new Tuple<string, Action<Monster, string>>("**Points de vie** ", (m, s) => m.HitPoints = s),
new Tuple<string, Action<Monster, string>>("**Vitesse** ", (m, s) => m.Speed = s),
new Tuple<string, Action<Monster, string>>("**Résistance aux dégâts** ", (m, s) => m.DamageResistances = s),
new Tuple<string, Action<Monster, string>>("**Résistances aux dégâts** ", (m, s) => m.DamageResistances = s),
new Tuple<string, Action<Monster, string>>("**Résistance contre les dégâts** ", (m, s) => m.DamageResistances = s),
new Tuple<string, Action<Monster, string>>("**Résistances contre les dégâts** ", (m, s) => m.DamageResistances = s),
new Tuple<string, Action<Monster, string>>("**Immunité contre les dégâts** ", (m, s) => m.DamageImmunities = s),
new Tuple<string, Action<Monster, string>>("**Immunité contre des dégâts** ", (m, s) => m.DamageImmunities = s),
new Tuple<string, Action<Monster, string>>("**Immunité aux dégâts** ", (m, s) => m.DamageImmunities = s),
new Tuple<string, Action<Monster, string>>("**Immunité à l'état** ", (m, s) => m.ConditionImmunities = s),
new Tuple<string, Action<Monster, string>>("**Immunités à l'état** ", (m, s) => m.ConditionImmunities = s),
new Tuple<string, Action<Monster, string>>("**Immunité contre l'état** ", (m, s) => m.ConditionImmunities = s),
new Tuple<string, Action<Monster, string>>("**Immunité contre les états** ", (m, s) => m.ConditionImmunities = s),
new Tuple<string, Action<Monster, string>>("**Immunités contre les états** ", (m, s) => m.ConditionImmunities = s),
new Tuple<string, Action<Monster, string>>("**Vulnérabilité aux dégâts** ", (m, s) => m.DamageVulnerabilities = s),
new Tuple<string, Action<Monster, string>>("**Vulnérabilité contre les dégâts** ", (m, s) => m.DamageVulnerabilities = s),
new Tuple<string, Action<Monster, string>>("**Vulnérabilité** ", (m, s) => m.DamageVulnerabilities = s),
new Tuple<string, Action<Monster, string>>("**Sens** ", (m, s) => m.Senses = s),
new Tuple<string, Action<Monster, string>>("**Langue** ", (m, s) => m.Languages = s),
new Tuple<string, Action<Monster, string>>("**Langues** ", (m, s) => m.Languages = s),
new Tuple<string, Action<Monster, string>>("**Dangerosité** ", (m, s) => m.Challenge = s),
new Tuple<string, Action<Monster, string>>("**Jets de sauvegarde** ", (m, s) => m.SavingThrows = s),
new Tuple<string, Action<Monster, string>>("**Jet de sauvegarde** ", (m, s) => m.SavingThrows = s),
new Tuple<string, Action<Monster, string>>("**Compétences** ", (m, s) => m.Skills = s),
new Tuple<string, Action<Monster, string>>("**Compétence** ", (m, s) => m.Skills = s),
new Tuple<string, Action<Monster, string>>("**Armor Class** ", (m, s) => m.ArmorClass = s),
new Tuple<string, Action<Monster, string>>("**Hit Points** ", (m, s) => m.HitPoints = s),
new Tuple<string, Action<Monster, string>>("**Speed** ", (m, s) => m.Speed = s),
new Tuple<string, Action<Monster, string>>("**Damage Resistance** ", (m, s) => m.DamageResistances = s),
new Tuple<string, Action<Monster, string>>("**Damage Resistances** ", (m, s) => m.DamageResistances = s),
new Tuple<string, Action<Monster, string>>("**Résistance contre les dégâts** ", (m, s) => m.DamageResistances = s),
new Tuple<string, Action<Monster, string>>("**Résistances contre les dégâts** ", (m, s) => m.DamageResistances = s),
new Tuple<string, Action<Monster, string>>("**Damage Immunities** ", (m, s) => m.DamageImmunities = s),
new Tuple<string, Action<Monster, string>>("**Immunité contre des dégâts** ", (m, s) => m.DamageImmunities = s),
new Tuple<string, Action<Monster, string>>("**Immunité aux dégâts** ", (m, s) => m.DamageImmunities = s),
new Tuple<string, Action<Monster, string>>("**Condition Immunities** ", (m, s) => m.ConditionImmunities = s),
new Tuple<string, Action<Monster, string>>("**Immunités à l'état** ", (m, s) => m.ConditionImmunities = s),
new Tuple<string, Action<Monster, string>>("**Immunité contre l'état** ", (m, s) => m.ConditionImmunities = s),
new Tuple<string, Action<Monster, string>>("**Immunité contre les états** ", (m, s) => m.ConditionImmunities = s),
new Tuple<string, Action<Monster, string>>("**Immunités contre les états** ", (m, s) => m.ConditionImmunities = s),
new Tuple<string, Action<Monster, string>>("**Damage Vulnerabilities** ", (m, s) => m.DamageVulnerabilities = s),
new Tuple<string, Action<Monster, string>>("**Vulnérabilité contre les dégâts** ", (m, s) => m.DamageVulnerabilities = s),
new Tuple<string, Action<Monster, string>>("**Vulnérabilité** ", (m, s) => m.DamageVulnerabilities = s),
new Tuple<string, Action<Monster, string>>("**Senses** ", (m, s) => m.Senses = s),
new Tuple<string, Action<Monster, string>>("**Languages** ", (m, s) => m.Languages = s),
new Tuple<string, Action<Monster, string>>("**Langues** ", (m, s) => m.Languages = s),
new Tuple<string, Action<Monster, string>>("**Challenge** ", (m, s) => m.Challenge = s),
new Tuple<string, Action<Monster, string>>("**Saving Throws** ", (m, s) => m.SavingThrows = s),
new Tuple<string, Action<Monster, string>>("**Jet de sauvegarde** ", (m, s) => m.SavingThrows = s),
new Tuple<string, Action<Monster, string>>("**Skills** ", (m, s) => m.Skills = s),
new Tuple<string, Action<Monster, string>>("**Compétence** ", (m, s) => m.Skills = s),
new Tuple<string, Action<Monster, string>>("NameVO: ", (m, s) => m.NameVO = s),
new Tuple<string, Action<Monster, string>>("", (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("(?<type>.*) de taille (?<size>.*), (?<alignment>.*)");
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("(?<size>.*?) (?<type>.*?), (?<alignment>.*)");
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<TCondition> ToConditions<TCondition>(this Markdig.Syntax.MarkdownDocument document) where TCondition : Condition, new()
{
var spells = new List<TCondition>();
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("(?<key>.*?): (?<value>.*)");
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<Tuple<string, Action<TCondition, string>>>()
{
new Tuple<string, Action<TCondition, string>>("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();
}
}
}
}

View file

@ -91,15 +91,45 @@ namespace AideDeJeu.ViewModels
return _AllItems;
}
public IEnumerable<Item> _Items = new List<Item>();
public IEnumerable<Item> 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;
}
}

View file

@ -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<Item> GotoItemCommand { get; private set; }
@ -212,7 +195,13 @@ namespace AideDeJeu.ViewModels
}
else
{
await Navigator.GotoItemsPageAsync(null);
var regex = new Regex("/(?<file>.*)\\.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);
}
}
}

View file

@ -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));
}
}

View file

@ -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<INavigator>(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()
{

View file

@ -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<MonsterHD>();
document.Dump();
var monsters = AideDeJeu.Tools.MarkdownExtensions.ToItem(md) as IEnumerable<Monster>; // document.ToMonsters<MonsterHD>();
//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<SpellHD>(md);
var items = AideDeJeu.Tools.MarkdownExtensions.ToItem(md) as IEnumerable<Spell>;
var classes = new string[]
{