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

Test reverse

This commit is contained in:
Yan Maniez 2018-07-11 00:45:48 +02:00
parent d01f135867
commit a83b481abf
14 changed files with 237 additions and 11 deletions

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Markdig.Syntax;
namespace AideDeJeuLib.Conditions namespace AideDeJeuLib.Conditions
{ {
@ -18,5 +19,10 @@ namespace AideDeJeuLib.Conditions
Text; Text;
} }
} }
public override void Parse(ref ContainerBlock.Enumerator enumerator)
{
throw new NotImplementedException();
}
} }
} }

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Markdig.Syntax;
namespace AideDeJeuLib.Models namespace AideDeJeuLib.Models
{ {
@ -19,5 +20,10 @@ namespace AideDeJeuLib.Models
"# [Conditions](conditions_vo.md)\n\n"; "# [Conditions](conditions_vo.md)\n\n";
} }
} }
public override void Parse(ref ContainerBlock.Enumerator enumerator)
{
throw new NotImplementedException();
}
} }
} }

View file

@ -28,8 +28,9 @@ namespace AideDeJeuLib
} }
} }
public Properties Properties { get; set; } //public Properties Properties { get; set; }
public abstract string Markdown { get; } public abstract string Markdown { get; }
public abstract void Parse(ref Markdig.Syntax.ContainerBlock.Enumerator enumerator);
} }
} }

View file

@ -0,0 +1,39 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Markdig.Syntax;
namespace AideDeJeuLib
{
public class Items : Item, IEnumerable<Item>
{
private IEnumerable<Item> _Items;
public override string Markdown => throw new NotImplementedException();
public IEnumerator<Item> GetEnumerator()
{
return _Items.GetEnumerator();
}
public override void Parse(ref ContainerBlock.Enumerator enumerator)
{
var items = new List<Item>();
enumerator.MoveNext();
while (enumerator.Current != null)
{
var item = new Spells.SpellHD();
item.Parse(ref enumerator);
items.Add(item);
//enumerator.MoveNext();
}
_Items = items;
}
IEnumerator IEnumerable.GetEnumerator()
{
return _Items.GetEnumerator();
}
}
}

View file

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Markdig.Syntax;
namespace AideDeJeuLib.Monsters namespace AideDeJeuLib.Monsters
{ {
@ -36,5 +37,10 @@ namespace AideDeJeuLib.Monsters
(LegendaryActions != null ? $"## Actions Légendaires\n\n" + LegendaryActions.Aggregate((s1, s2) => s1 + "\n\n" + s2) : ""); (LegendaryActions != null ? $"## Actions Légendaires\n\n" + LegendaryActions.Aggregate((s1, s2) => s1 + "\n\n" + s2) : "");
} }
} }
public override void Parse(ref ContainerBlock.Enumerator enumerator)
{
throw new NotImplementedException();
}
} }
} }

View file

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Markdig.Syntax;
namespace AideDeJeuLib.Monsters namespace AideDeJeuLib.Monsters
{ {
@ -36,5 +37,10 @@ namespace AideDeJeuLib.Monsters
(LegendaryActions != null ? $"## Legendary Actions\n\n" + LegendaryActions.Aggregate((s1, s2) => s1 + "\n\n" + s2) : ""); (LegendaryActions != null ? $"## Legendary Actions\n\n" + LegendaryActions.Aggregate((s1, s2) => s1 + "\n\n" + s2) : "");
} }
} }
public override void Parse(ref ContainerBlock.Enumerator enumerator)
{
throw new NotImplementedException();
}
} }
} }

View file

@ -1,7 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using AideDeJeu.Tools;
using Markdig.Syntax;
namespace AideDeJeuLib.Spells namespace AideDeJeuLib.Spells
{ {
@ -65,5 +68,128 @@ namespace AideDeJeuLib.Spells
} }
} }
public override void Parse(ref ContainerBlock.Enumerator enumerator)
{
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)
{
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("(?<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<Spell, string>>>()
{
new Tuple<string, Action<Spell, string>>("NameVO: ", (m, s) => m.NameVO = s),
new Tuple<string, Action<Spell, string>>("CastingTime: ", (m, s) => m.CastingTime = s),
new Tuple<string, Action<Spell, string>>("Components: ", (m, s) => m.Components = s),
new Tuple<string, Action<Spell, string>>("Duration: ", (m, s) => m.Duration = s),
new Tuple<string, Action<Spell, string>>("LevelType: ", (m, s) => m.LevelType = s),
new Tuple<string, Action<Spell, string>>("Range: ", (m, s) => m.Range = s),
new Tuple<string, Action<Spell, string>>("Source: ", (m, s) => m.Source = s),
new Tuple<string, Action<Spell, string>>("Classes: ", (m, s) => m.Source += s),
new Tuple<string, Action<Spell, string>>("", (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";
}
//if (enumerator.Current is Markdig.Syntax.LinkReferenceDefinitionGroup)
//{
// var linkReferenceDefinitionGroup = enumerator.Current as Markdig.Syntax.LinkReferenceDefinitionGroup;
// var linkReferenceDefinition = linkReferenceDefinitionGroup.FirstOrDefault() as Markdig.Syntax.LinkReferenceDefinition;
// var label = linkReferenceDefinition.Label;
// var title = linkReferenceDefinition.Title;
// var url = linkReferenceDefinition.Url;
// if (label == "//")
// {
// return;
// }
//}
enumerator.MoveNext();
}
}
} }
} }

View file

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Markdig.Syntax;
namespace AideDeJeuLib.Spells namespace AideDeJeuLib.Spells
{ {
@ -47,5 +48,10 @@ namespace AideDeJeuLib.Spells
} }
} }
public override void Parse(ref ContainerBlock.Enumerator enumerator)
{
throw new NotImplementedException();
}
} }
} }

View file

@ -43,6 +43,39 @@ namespace AideDeJeu.Tools
return md; return md;
} }
public static Item ToItem(string md)
{
var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build();
var document = Markdig.Parsers.MarkdownParser.Parse(md, pipeline);
var block = document.First();
var enumerator = document.GetEnumerator();
{
enumerator.MoveNext();
while (enumerator.Current != null)
{
if(enumerator.Current is Markdig.Syntax.LinkReferenceDefinitionGroup)
{
var linkReferenceDefinitionGroup = enumerator.Current as Markdig.Syntax.LinkReferenceDefinitionGroup;
var linkReferenceDefinition = linkReferenceDefinitionGroup.FirstOrDefault() as Markdig.Syntax.LinkReferenceDefinition;
var label = linkReferenceDefinition.Label;
var title = linkReferenceDefinition.Title;
var url = linkReferenceDefinition.Url;
if (label == "//")
{
var name = $"AideDeJeuLib.{title}, AideDeJeu";
var type = Type.GetType(name);
var instance = Activator.CreateInstance(type) as Item;
instance.Parse(ref enumerator);
return instance;
}
}
enumerator.MoveNext();
}
}
return null;
}
public static IEnumerable<TSpell> ToSpells<TSpell>(this Markdig.Syntax.MarkdownDocument document) where TSpell : Spell, new() public static IEnumerable<TSpell> ToSpells<TSpell>(this Markdig.Syntax.MarkdownDocument document) where TSpell : Spell, new()
{ {
var spells = new List<TSpell>(); var spells = new List<TSpell>();

View file

@ -20,16 +20,10 @@ namespace AideDeJeu.ViewModels
} }
} }
public Command LoadItemCommand { get; set; }
public ItemDetailViewModel(Item item = null) public ItemDetailViewModel(Item item = null)
{ {
Title = item?.Name; Title = item?.Name;
Item = item; Item = item;
LoadItemCommand = new Command(async () => await ExecuteLoadItemCommand());
}
async Task ExecuteLoadItemCommand()
{
} }
} }

View file

@ -65,7 +65,8 @@ namespace AideDeJeu.ViewModels
resourceName = "AideDeJeu.Data.spells_hd.md"; resourceName = "AideDeJeu.Data.spells_hd.md";
//var md = await Tools.Helpers.GetStringFromUrl("https://raw.githubusercontent.com/Nioux/AideDeJeu/master/Data/spells_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); var md = await Tools.Helpers.GetResourceStringAsync(resourceName);
_AllItems = Tools.MarkdownExtensions.MarkdownToSpells<SpellHD>(md); _AllItems = Tools.MarkdownExtensions.ToItem(md) as IEnumerable<Item>;
//_AllItems = Tools.MarkdownExtensions.MarkdownToSpells<SpellHD>(md);
} }
break; break;
case ItemSourceType.ConditionVO: case ItemSourceType.ConditionVO:

View file

@ -36,7 +36,6 @@ namespace AideDeJeu.ViewModels
return; return;
var vm = new ItemDetailViewModel(item); var vm = new ItemDetailViewModel(item);
vm.LoadItemCommand.Execute(null);
await Navigation.PushAsync(new ItemDetailPage(vm)); await Navigation.PushAsync(new ItemDetailPage(vm));
} }
@ -46,7 +45,6 @@ namespace AideDeJeu.ViewModels
// return; // return;
//var vm = new ItemDetailViewModel(item); //var vm = new ItemDetailViewModel(item);
//vm.LoadItemCommand.Execute(null);
await Navigation.PushAsync(new ItemsPage()); await Navigation.PushAsync(new ItemsPage());
} }

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<NavigationPage xmlns="http://xamarin.com/schemas/2014/forms" <NavigationPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="AideDeJeu.Views.MainNavigationPage"> x:Class="AideDeJeu.Views.MainNavigationPage" IsBusy="{Binding Main.IsBusy}">
</NavigationPage> </NavigationPage>

View file

@ -1,4 +1,8 @@
 
[//]: # (Items)
[SpellHD]
[SpellHD]: # ()
# Agrandir/rétrécir # Agrandir/rétrécir
- NameVO: [Enlarge/Reduce](spells_vo.md#enlargereduce) - NameVO: [Enlarge/Reduce](spells_vo.md#enlargereduce)
- CastingTime: 1 action - CastingTime: 1 action