From 411411271a78d0337747d03f7cbf88d09ea36487 Mon Sep 17 00:00:00 2001 From: Yan Maniez Date: Sun, 29 Apr 2018 18:25:06 +0200 Subject: [PATCH] Avancement fiche monstre --- AideDeJeu/AideDeJeu/Tools/Converters.cs | 34 +++++ .../ViewModels/MonsterDetailViewModel.cs | 124 +++++++++++++++++- .../AideDeJeu/Views/MonsterDetailPage.xaml | 92 ++++++++----- AideDeJeu/AideDeJeuLib/Monsters/Monster.cs | 52 ++++---- 4 files changed, 240 insertions(+), 62 deletions(-) create mode 100644 AideDeJeu/AideDeJeu/Tools/Converters.cs diff --git a/AideDeJeu/AideDeJeu/Tools/Converters.cs b/AideDeJeu/AideDeJeu/Tools/Converters.cs new file mode 100644 index 00000000..26ffec11 --- /dev/null +++ b/AideDeJeu/AideDeJeu/Tools/Converters.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Xamarin.Forms; + +namespace AideDeJeu.Tools +{ + public class NullToTrueConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value == null; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return null; + } + } + + public class NullToFalseConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value != null; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return null; + } + } +} diff --git a/AideDeJeu/AideDeJeu/ViewModels/MonsterDetailViewModel.cs b/AideDeJeu/AideDeJeu/ViewModels/MonsterDetailViewModel.cs index 6ab3aa80..66b21a4d 100644 --- a/AideDeJeu/AideDeJeu/ViewModels/MonsterDetailViewModel.cs +++ b/AideDeJeu/AideDeJeu/ViewModels/MonsterDetailViewModel.cs @@ -19,12 +19,126 @@ namespace AideDeJeu.ViewModels set { SetProperty(ref _Item, value); - //OnPropertyChanged(nameof(Description)); - //OnPropertyChanged(nameof(TypeLevel)); - //OnPropertyChanged(nameof(CastingTime)); - //OnPropertyChanged(nameof(Range)); - //OnPropertyChanged(nameof(Components)); + OnPropertyChanged(nameof(TypeSizeAlignment)); + OnPropertyChanged(nameof(ArmorClass)); + OnPropertyChanged(nameof(HitPoints)); + OnPropertyChanged(nameof(Speed)); + OnPropertyChanged(nameof(SavingThrows)); + OnPropertyChanged(nameof(Skills)); + OnPropertyChanged(nameof(Senses)); + OnPropertyChanged(nameof(Languages)); + OnPropertyChanged(nameof(Challenge)); //OnPropertyChanged(nameof(Duration)); + //OnPropertyChanged(nameof(Duration)); + } + } + + public FormattedString TypeSizeAlignment + { + get + { + var fd = FormatedTextHelpers.FontData.FromResource("contentital"); + var fs = new FormattedString(); + fs.Spans.Add(new Span() { Text = string.Format("{0} de taille {1}, {2}", Item.Type, Item.Size, Item.Alignment), FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); + return fs; + } + } + + public FormattedString ArmorClass + { + get + { + var fd = FormatedTextHelpers.FontData.FromResource("content"); + var fs = new FormattedString(); + fs.Spans.Add(new Span() { Text = string.Format("Classe d'armure {0}", Item.ArmorClass), FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); + return fs; + } + } + + public FormattedString HitPoints + { + get + { + var fd = FormatedTextHelpers.FontData.FromResource("content"); + var fs = new FormattedString(); + fs.Spans.Add(new Span() { Text = string.Format("Points de vie {0}", Item.HitPoints), FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); + return fs; + } + } + + public FormattedString Speed + { + get + { + var fd = FormatedTextHelpers.FontData.FromResource("content"); + var fs = new FormattedString(); + fs.Spans.Add(new Span() { Text = string.Format("Vitesse {0}", Item.Speed), FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); + return fs; + } + } + + public FormattedString SavingThrows + { + get + { + var fd = FormatedTextHelpers.FontData.FromResource("content"); + var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); + var fs = new FormattedString(); + fs.Spans.Add(new Span() { Text = "Jets de sauvegarde : ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); + fs.Spans.Add(new Span() { Text = Item.SavingThrows, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); + return fs; + } + } + + public FormattedString Skills + { + get + { + var fd = FormatedTextHelpers.FontData.FromResource("content"); + var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); + var fs = new FormattedString(); + fs.Spans.Add(new Span() { Text = "Compétences : ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); + fs.Spans.Add(new Span() { Text = Item.Skills, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); + return fs; + } + } + + public FormattedString Senses + { + get + { + var fd = FormatedTextHelpers.FontData.FromResource("content"); + var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); + var fs = new FormattedString(); + fs.Spans.Add(new Span() { Text = "Sens : ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); + fs.Spans.Add(new Span() { Text = Item.Senses, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); + return fs; + } + } + + public FormattedString Languages + { + get + { + var fd = FormatedTextHelpers.FontData.FromResource("content"); + var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); + var fs = new FormattedString(); + fs.Spans.Add(new Span() { Text = "Langues : ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); + fs.Spans.Add(new Span() { Text = Item.Languages, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); + return fs; + } + } + + public FormattedString Challenge + { + get + { + var fd = FormatedTextHelpers.FontData.FromResource("content"); + var fdb = FormatedTextHelpers.FontData.FromResource("contentbold"); + var fs = new FormattedString(); + fs.Spans.Add(new Span() { Text = "Puissance : ", FontFamily = fdb.FontFamily, FontAttributes = fdb.FontAttributes, FontSize = fdb.FontSize, ForegroundColor = fdb.TextColor }); + fs.Spans.Add(new Span() { Text = Item.Challenge, FontFamily = fd.FontFamily, FontAttributes = fd.FontAttributes, FontSize = fd.FontSize, ForegroundColor = fd.TextColor }); + return fs; } } diff --git a/AideDeJeu/AideDeJeu/Views/MonsterDetailPage.xaml b/AideDeJeu/AideDeJeu/Views/MonsterDetailPage.xaml index 0fff3d84..2f045c28 100644 --- a/AideDeJeu/AideDeJeu/Views/MonsterDetailPage.xaml +++ b/AideDeJeu/AideDeJeu/Views/MonsterDetailPage.xaml @@ -1,49 +1,71 @@  - + + + + + + diff --git a/AideDeJeu/AideDeJeuLib/Monsters/Monster.cs b/AideDeJeu/AideDeJeuLib/Monsters/Monster.cs index d81784de..88eb2ec8 100644 --- a/AideDeJeu/AideDeJeuLib/Monsters/Monster.cs +++ b/AideDeJeu/AideDeJeuLib/Monsters/Monster.cs @@ -39,28 +39,36 @@ namespace AideDeJeuLib.Monsters public static Monster FromHtml(HtmlNode divBloc) { var monster = new Monster(); - var divMonster = divBloc.SelectSingleNode("div[contains(@class,'monstre')]"); - monster.Name = divMonster.SelectSingleNode("h1").InnerText; - monster.NameVO = divMonster.SelectSingleNode("div[contains(@class,'trad')]/a").InnerText; - var divSansSerif = divMonster.SelectSingleNode("div[contains(@class,'sansSerif')]"); - var typeSizeAlignment = divSansSerif.SelectSingleNode("h2/em").InnerText; - var matchesTypeSizeAlignment = new Regex("(?.*) de taille (?.*), (?.*)").Match(typeSizeAlignment); - monster.Type = matchesTypeSizeAlignment.Groups["type"].Value; - monster.Size = matchesTypeSizeAlignment.Groups["size"].Value; - monster.Alignment = matchesTypeSizeAlignment.Groups["alignment"].Value; - var divRed = divSansSerif.SelectSingleNode("div[contains(@class,'red')]"); - monster.Strength = divRed.SelectSingleNode("strong").NextSibling.InnerText; - //monster.LevelType = nodeSpell.SelectSingleNode("h2/em").InnerText; - //monster.Level = spell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[0].Split(' ')[1]; - //monster.Type = spell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[1]; - //monster.CastingTime = nodeSpell.SelectSingleNode("div[@class='paragraphe']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; - //monster.Range = nodeSpell.SelectSingleNode("div[strong/text()='Portée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; - //monster.Components = nodeSpell.SelectSingleNode("div[strong/text()='Composantes']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; - //monster.Duration = nodeSpell.SelectSingleNode("div[strong/text()='Durée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; - //monster.DescriptionDiv = nodeSpell.SelectSingleNode("div[contains(@class,'description')]"); - //monster.Overflow = nodeSpell.SelectSingleNode("div[@class='overflow']")?.InnerText; - //monster.NoOverflow = nodeSpell.SelectSingleNode("div[@class='nooverflow']")?.InnerText; - //monster.Source = nodeSpell.SelectSingleNode("div[@class='source']").InnerText; + var divMonster = divBloc?.SelectSingleNode("div[contains(@class,'monstre')]"); + monster.Name = divMonster?.SelectSingleNode("h1").InnerText; + monster.NameVO = divMonster?.SelectSingleNode("div[contains(@class,'trad')]/a")?.InnerText; + var divSansSerif = divMonster?.SelectSingleNode("div[contains(@class,'sansSerif')]"); + var typeSizeAlignment = divSansSerif?.SelectSingleNode("h2/em")?.InnerText; + if (typeSizeAlignment != null) + { + var matchesTypeSizeAlignment = new Regex("(?.*) de taille (?.*), (?.*)").Match(typeSizeAlignment); + monster.Type = matchesTypeSizeAlignment?.Groups["type"]?.Value?.Trim(); + monster.Size = matchesTypeSizeAlignment?.Groups["size"]?.Value?.Trim(); + monster.Alignment = matchesTypeSizeAlignment?.Groups["alignment"]?.Value?.Trim(); + } + var divRed = divSansSerif?.SelectSingleNode("div[contains(@class,'red')]"); + monster.ArmorClass = divRed?.SelectSingleNode("strong[contains(text(),'armure')]")?.NextSibling?.InnerText; + monster.HitPoints = divRed?.SelectSingleNode("strong[contains(text(),'Points de vie')]")?.NextSibling?.InnerText; + monster.Speed = divRed?.SelectSingleNode("strong[contains(text(),'Vitesse')]")?.NextSibling?.InnerText; + + monster.Strength = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'FOR')]")?.NextSibling?.NextSibling?.InnerText; + monster.Dexterity = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'DEX')]")?.NextSibling?.NextSibling?.InnerText; + monster.Constitution = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'CON')]")?.NextSibling?.NextSibling?.InnerText; + monster.Intelligence = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'INT')]")?.NextSibling?.NextSibling?.InnerText; + monster.Wisdom = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'SAG')]")?.NextSibling?.NextSibling?.InnerText; + monster.Charisma = divRed?.SelectSingleNode("div[contains(@class,'carac')]/strong[contains(text(),'CHA')]")?.NextSibling?.NextSibling?.InnerText; + + + monster.SavingThrows = divRed?.SelectSingleNode("strong[contains(text(),'Jets de sauvegarde')]")?.NextSibling?.InnerText; + monster.Skills = divRed?.SelectSingleNode("strong[contains(text(),'Compétences')]")?.NextSibling?.InnerText; + monster.Senses = divRed?.SelectSingleNode("strong[contains(text(),'Sens')]")?.NextSibling?.InnerText; + monster.Languages = divRed?.SelectSingleNode("strong[contains(text(),'Langues')]")?.NextSibling?.InnerText; + monster.Power = divRed?.SelectSingleNode("strong[contains(text(),'Puissance')]")?.NextSibling?.InnerText; return monster; }