mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-29 14:35:45 +00:00
Conditions ok
This commit is contained in:
parent
6906ddbd32
commit
813191a15f
9 changed files with 226 additions and 46 deletions
22
AideDeJeu/AideDeJeu/Models/Conditions/Condition.cs
Normal file
22
AideDeJeu/AideDeJeu/Models/Conditions/Condition.cs
Normal file
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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("\'", ""));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<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();
|
||||
|
|
@ -471,6 +479,125 @@ namespace AideDeJeu.Tools
|
|||
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)
|
||||
{
|
||||
var str = string.Empty;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,21 @@ namespace AideDeJeu.ViewModels
|
|||
_AllItems = Tools.MarkdownExtensions.MarkdownToSpells<SpellHD>(md);
|
||||
}
|
||||
break;
|
||||
case ItemSourceType.ConditionVO:
|
||||
{
|
||||
resourceName = "AideDeJeu.Data.conditions_vo.md";
|
||||
var md = await Tools.Helpers.GetResourceStringAsync(resourceName);
|
||||
_AllItems = Tools.MarkdownExtensions.MarkdownToConditions<AideDeJeuLib.Conditions.Condition>(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<AideDeJeuLib.Conditions.Condition>(md);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return _AllItems;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,10 +35,10 @@
|
|||
<x:Arguments>
|
||||
<ContentPage Title="{Binding ItemSourceType,Converter={StaticResource ItemSourceTypeToTitleConverter}}">
|
||||
<ContentPage.ToolbarItems>
|
||||
<ToolbarItem Name="Sorts (H&D)" Text="Sorts (H&D)" Order="Secondary" Command="{Binding SwitchToSpellsHD}" />
|
||||
<!--<ToolbarItem Name="Sorts (H&D)" Text="Sorts (H&D)" Order="Secondary" Command="{Binding SwitchToSpellsHD}" />
|
||||
<ToolbarItem Name="Creatures (H&D)" Text="Créatures (H&D)" Order="Secondary" Command="{Binding SwitchToMonstersHD}" />
|
||||
<ToolbarItem Name="Spells (VO)" Text="Spells (VO)" Order="Secondary" Icon="spell_book.png" Command="{Binding SwitchToSpellsVO}" />
|
||||
<ToolbarItem Name="Monsters (VO)" Text="Monsters (VO)" Order="Secondary" Icon="dragon_head.png" Command="{Binding SwitchToMonstersVO}" />
|
||||
<ToolbarItem Name="Monsters (VO)" Text="Monsters (VO)" Order="Secondary" Icon="dragon_head.png" Command="{Binding SwitchToMonstersVO}" />-->
|
||||
<ToolbarItem Name="About" Text="À propos de..." Order="Secondary" Icon="wooden_sign.png" Command="{Binding AboutCommand}" />
|
||||
</ContentPage.ToolbarItems>
|
||||
<StackLayout Orientation="Vertical" VerticalOptions="Fill" HorizontalOptions="Fill">
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Les états spéciaux
|
||||
# États spéciaux
|
||||
|
||||
- NameVO: [Conditions](conditions_vo.md#conditions)
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue