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

Spécialisation SpellVO / SpellHD

This commit is contained in:
Yan Maniez 2018-07-01 22:10:10 +02:00
parent 32830b4a08
commit d2f99b15c5
10 changed files with 187 additions and 27 deletions

View file

@ -13,12 +13,13 @@ namespace AideDeJeuLib
}
public class Item
public abstract class Item
{
public string Name { get; set; }
public string NameVO { get; set; }
public Properties Properties { get; set; }
public abstract string Markdown { get; }
}
}

View file

@ -37,5 +37,13 @@ namespace AideDeJeuLib.Monsters
public IEnumerable<string> Actions { get; set; }
public IEnumerable<string> Reactions { get; set; }
public IEnumerable<string> LegendaryActions { get; set; }
public override string Markdown
{
get
{
return "";
}
}
}
}

View file

@ -13,7 +13,21 @@ namespace AideDeJeuLib.Spells
{
get
{
return string.Format("{0} - {1}", this.Level, this.Type);
if (int.Parse(Level) > 0)
{
if (string.IsNullOrEmpty(Rituel))
{
return $"{Type} de niveau {Level}";
}
else
{
return $"{Type} de niveau {Level} {Rituel}";
}
}
else
{
return $"{Type}, tour de magie";
}
}
set
{
@ -57,5 +71,22 @@ namespace AideDeJeuLib.Spells
public string Source { get; set; }
public override string Markdown
{
get
{
return
$"# {Name}\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}";
}
}
}
}

View file

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace AideDeJeuLib.Spells
{
public class SpellHD : Spell
{
public new string LevelType
{
get
{
if (int.Parse(Level) > 0)
{
if (string.IsNullOrEmpty(Rituel))
{
return $"{Type} de niveau {Level}";
}
else
{
return $"{Type} de niveau {Level} {Rituel}";
}
}
else
{
return $"{Type}, tour de magie";
}
}
set
{
var re = new Regex("(?<type>.*) de niveau (?<level>\\d).?(?<rituel>\\(rituel\\))?");
var match = re.Match(value);
this.Type = match.Groups["type"].Value;
this.Level = match.Groups["level"].Value;
this.Rituel = match.Groups["rituel"].Value;
if (string.IsNullOrEmpty(this.Type))
{
re = new Regex("(?<type>.*), (?<level>tour de magie)");
match = re.Match(value);
if (match.Groups["level"].Value == "tour de magie")
{
this.Type = match.Groups["type"].Value;
this.Level = "0"; // match.Groups["level"].Value;
this.Rituel = match.Groups["rituel"].Value;
}
}
}
}
public override string Markdown
{
get
{
return
$"# {Name}\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}";
}
}
}
}

View file

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace AideDeJeuLib.Spells
{
public class SpellVO : Spell
{
public new string LevelType
{
get
{
if (string.IsNullOrEmpty(Rituel))
{
return $"Level {Level} - {Type}";
}
else
{
return $"Level {Level} - {Type} {Rituel}";
}
}
set
{
var re = new Regex("^(?<level>\\d) - (?<type>.*?)\\s?(?<rituel>\\(ritual\\))?$");
var match = re.Match(value);
this.Type = match.Groups["type"].Value;
this.Level = match.Groups["level"].Value;
this.Rituel = match.Groups["rituel"].Value;
}
}
public override string Markdown
{
get
{
return
$"# {Name}\n" +
$"{NameVO}\n" +
$"_{LevelType}_\n" +
$"**Casting Time :** {CastingTime}\n" +
$"**Range :** {Range}\n" +
$"**Components :** {Components}\n" +
$"**Duration :** {Duration}\n\n" +
$"{DescriptionHtml}\n\n" +
$"**Source :** {Source}";
}
}
}
}

View file

@ -14,11 +14,11 @@ namespace AideDeJeu.Tools
{
public static class MarkdownExtensions
{
public static IEnumerable<Spell> MarkdownToSpells(string md)
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();
return document.ToSpells<TSpell>();
}
public static IEnumerable<Monster> MarkdownToMonsters(string md)
@ -35,10 +35,10 @@ namespace AideDeJeu.Tools
return md;
}
public static IEnumerable<Spell> ToSpells(this Markdig.Syntax.MarkdownDocument document)
public static IEnumerable<TSpell> ToSpells<TSpell>(this Markdig.Syntax.MarkdownDocument document) where TSpell : Spell, new()
{
var spells = new List<Spell>();
Spell spell = null;
var spells = new List<TSpell>();
TSpell spell = null;
foreach (var block in document)
{
//DumpBlock(block);
@ -53,7 +53,7 @@ namespace AideDeJeu.Tools
spells.Add(spell);
//yield return spell;
}
spell = new Spell();
spell = new TSpell();
spell.Name = headingBlock.Inline.ToMarkdownString();
//Console.WriteLine(spell.Name);
}
@ -93,17 +93,17 @@ namespace AideDeJeu.Tools
//DumpParagraphBlock(paragraphBlock);
var str = paragraphBlock.Inline.ToMarkdownString();
var properties = new List<Tuple<string, Action<Spell, string>>>()
var properties = new List<Tuple<string, Action<TSpell, 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) =>
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)
//{

View file

@ -54,7 +54,7 @@ namespace AideDeJeu.ViewModels
{
resourceName = "AideDeJeu.Data.spells_vo.md";
var md = await Tools.Helpers.GetResourceStringAsync(resourceName);
_AllItems = Tools.MarkdownExtensions.MarkdownToSpells(md);
_AllItems = Tools.MarkdownExtensions.MarkdownToSpells<SpellVO>(md);
}
break;
case ItemSourceType.SpellHD:
@ -62,7 +62,7 @@ namespace AideDeJeu.ViewModels
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.GetResourceStringAsync(resourceName);
_AllItems = Tools.MarkdownExtensions.MarkdownToSpells(md);
_AllItems = Tools.MarkdownExtensions.MarkdownToSpells<SpellHD>(md);
}
break;
}

View file

@ -14,7 +14,7 @@
</ContentPage.Resources>
<ScrollView VerticalScrollBarVisibility="Default" HorizontalScrollBarVisibility="Default">
<StackLayout Orientation="Vertical" Padding="15">
<Label Text="{Binding Item.Name}" Style="{StaticResource Key=subsection}" />
<!--<Label Text="{Binding Item.Name}" Style="{StaticResource Key=subsection}" />
<mdview:MarkdownView x:Name="mdNameVO" Theme="{StaticResource MonsterMarkdownTheme}" Markdown="{Binding Item.NameVO}" />
<Label Text=" " />
@ -29,11 +29,11 @@
<Label FormattedText="{Binding Duration}" />
<Label Text=" " />
<Label Text=" " />-->
<mdview:MarkdownView x:Name="mdDescription" Theme="{StaticResource MonsterMarkdownTheme}" Markdown="{Binding Item.DescriptionHtml}" IsVisible="{Binding Item.DescriptionHtml, Converter={StaticResource NullToFalseConverter}}" />
<mdview:MarkdownView x:Name="mdDescription" Theme="{StaticResource MonsterMarkdownTheme}" Markdown="{Binding Item.Markdown}" />
<Label Text="{Binding Item.Source}" Style="{StaticResource Key=content}" />
<!--<Label Text="{Binding Item.Source}" Style="{StaticResource Key=content}" />-->
</StackLayout>
</ScrollView>
</ContentPage>

View file

@ -17,7 +17,7 @@ namespace AideDeJeu.Views
BindingContext = this.viewModel = viewModel;
mdNameVO.NavigateToLink = async (s) => await viewModel.Main.NavigateToLink(s);
//mdNameVO.NavigateToLink = async (s) => await viewModel.Main.NavigateToLink(s);
mdDescription.NavigateToLink = async (s) => await viewModel.Main.NavigateToLink(s);
}

View file

@ -26,7 +26,7 @@ namespace AideDeJeuCmd
var document = Markdig.Parsers.MarkdownParser.Parse(md);
//DumpMarkdownDocument(document);
var spellss = document.ToSpells();
var spellss = document.ToSpells<SpellHD>();
Console.WriteLine("ok");
var md2 = spellss.ToMarkdownString();
if (md.CompareTo(md2) != 0)
@ -66,7 +66,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.MarkdownToSpells<SpellHD>(md);
var classes = new string[]
{