diff --git a/AideDeJeu/AideDeJeuLib/Cards/Converters.cs b/AideDeJeu/AideDeJeuLib/Cards/Converters.cs index 8cc04387..8b95f6ea 100644 --- a/AideDeJeu/AideDeJeuLib/Cards/Converters.cs +++ b/AideDeJeu/AideDeJeuLib/Cards/Converters.cs @@ -105,18 +105,19 @@ namespace AideDeJeuLib.Cards return contents.ToArray(); } - public static CardData ToBaseCardData(IReadOnlyDictionary context, Spell spell) + public static CardData ToBaseCardData(Spell spell) { - string color = context["color"]; - string backgroundImage = context["background_image"]; + //string color = context["color"]; + //string backgroundImage = context["background_image"]; + string color = "red"; var cardData = new CardData(); cardData.Count = 1; cardData.Color = color; - cardData.Title = spell.Name; + cardData.Title = spell.NamePHB; cardData.TitleSize = "10"; cardData.Icon = "white-book-" + spell.Level; cardData.IconBack = "robe"; - cardData.BackgroundImage = backgroundImage; + //cardData.BackgroundImage = backgroundImage; cardData.Tags = new string[] { "sort", @@ -124,10 +125,10 @@ namespace AideDeJeuLib.Cards }; return cardData; } - public static CardData[] ToCardDatas(IReadOnlyDictionary context, Spell spell) + public static CardData[] ToCardDatas(Spell spell) { var cardDatas = new List(); - var cardData = ToBaseCardData(context, spell); + var cardData = ToBaseCardData(spell); var contents = new List(); contents.AddRange(new CardContent[] @@ -164,7 +165,7 @@ namespace AideDeJeuLib.Cards cardData.Contents = contents.ToArray(); cardDatas.Add(cardData); - cardData = ToBaseCardData(context, spell); + cardData = ToBaseCardData(spell); contents = new List(); if (section != null) { diff --git a/AideDeJeu/AideDeJeuLib/Spells/SpellsScrappers.cs b/AideDeJeu/AideDeJeuLib/Spells/SpellsScrappers.cs index b473015b..5e1d6050 100644 --- a/AideDeJeu/AideDeJeuLib/Spells/SpellsScrappers.cs +++ b/AideDeJeu/AideDeJeuLib/Spells/SpellsScrappers.cs @@ -84,7 +84,7 @@ namespace AideDeJeuLib.Spells return Spell.FromHtml(divSpell); } - public async Task> GetSpellIds(string classe, int niveauMin = 0, int niveauMax = 9) + public async Task> GetSpellIds(string classe, string niveauMin = "Z", string niveauMax = "9") { string html = null; using (var client = GetHttpClient()) @@ -93,7 +93,7 @@ namespace AideDeJeuLib.Spells // https://www.aidedd.org/dnd/sorts.php?vf=rayon-de-givre // https://www.aidedd.org/regles/sorts/ - html = await client.GetStringAsync(string.Format("https://www.aidedd.org/adj/livre-sorts/?c={0}&min=1{1}&max=1{2}", classe, niveauMin, niveauMax)); + html = await client.GetStringAsync(string.Format("https://www.aidedd.org/adj/livre-sorts/?c={0}&min={1}&max={2}", classe, niveauMin, niveauMax)); } var pack = new HtmlDocument(); pack.LoadHtml(html); @@ -120,26 +120,28 @@ namespace AideDeJeuLib.Spells var spells = pack.DocumentNode.SelectNodes("//div[contains(@class,'blocCarte')]").ToList(); foreach (var spell in spells) { - var newSpell = new Spell(); - newSpell.Name = spell.SelectSingleNode("h1").InnerText; - newSpell.NameVO = spell.SelectSingleNode("div[@class='trad']").InnerText; - newSpell.LevelType = spell.SelectSingleNode("h2/em").InnerText; - newSpell.Level = newSpell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[0].Split(' ')[1]; - newSpell.Type = newSpell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[1]; - newSpell.CastingTime = spell.SelectSingleNode("div[@class='paragraphe']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; - newSpell.Range = spell.SelectSingleNode("div[strong/text()='Portée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; - newSpell.Components = spell.SelectSingleNode("div[strong/text()='Composantes']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; - newSpell.Duration = spell.SelectSingleNode("div[strong/text()='Durée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; - newSpell.DescriptionDiv = spell.SelectSingleNode("div[contains(@class,'description')]"); - //newSpell.DescriptionHtml = newSpell.DescriptionDiv.InnerHtml; - //newSpell.Description = newSpell.DescriptionDiv.InnerText; - newSpell.Overflow = spell.SelectSingleNode("div[@class='overflow']")?.InnerText; - newSpell.NoOverflow = spell.SelectSingleNode("div[@class='nooverflow']")?.InnerText; - newSpell.Source = spell.SelectSingleNode("div[@class='source']").InnerText; + //var newSpell = new Spell(); + var newSpell = Spell.FromHtml(spell); + //newSpell.Name = spell.SelectSingleNode("h1").InnerText; + //newSpell.NameVO = spell.SelectSingleNode("div[@class='trad']").InnerText; + //newSpell.LevelType = spell.SelectSingleNode("h2/em").InnerText; + //newSpell.Level = newSpell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[0].Split(' ')[1]; + //newSpell.Type = newSpell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[1]; + //newSpell.CastingTime = spell.SelectSingleNode("div[@class='paragraphe']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; + //newSpell.Range = spell.SelectSingleNode("div[strong/text()='Portée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; + //newSpell.Components = spell.SelectSingleNode("div[strong/text()='Composantes']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; + //newSpell.Duration = spell.SelectSingleNode("div[strong/text()='Durée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; + //newSpell.DescriptionDiv = spell.SelectSingleNode("div[contains(@class,'description')]"); + ////newSpell.DescriptionHtml = newSpell.DescriptionDiv.InnerHtml; + ////newSpell.Description = newSpell.DescriptionDiv.InnerText; + //newSpell.Overflow = spell.SelectSingleNode("div[@class='overflow']")?.InnerText; + //newSpell.NoOverflow = spell.SelectSingleNode("div[@class='nooverflow']")?.InnerText; + //newSpell.Source = spell.SelectSingleNode("div[@class='source']").InnerText; newSpells.Add(newSpell); } return newSpells; } + /* public async Task OnGetAsync(IReadOnlyDictionary context) { diff --git a/AideDeJeu/AideDeJeuWeb/Controllers/ValuesController.cs b/AideDeJeu/AideDeJeuWeb/Controllers/ValuesController.cs index c30ad15f..90d1ce5d 100644 --- a/AideDeJeu/AideDeJeuWeb/Controllers/ValuesController.cs +++ b/AideDeJeu/AideDeJeuWeb/Controllers/ValuesController.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using AideDeJeuLib.Cards; using AideDeJeuLib.Spells; using Microsoft.AspNetCore.Mvc; @@ -12,13 +13,22 @@ namespace AideDeJeuWeb.Controllers { // GET api/values [HttpGet] - public async Task> Get() + public async Task> Get() { var scrapper = new SpellsScrappers(); - var spells = await scrapper.GetSpells(); + var spellIds = await scrapper.GetSpellIds("c"); + var spells = await scrapper.GetSpells(spellIds); + + + var cardDatas = new List(); + foreach (var spell in spells) + { + cardDatas.AddRange(Converters.ToCardDatas(spell)); + } + return cardDatas; //var spellIds = spells.Select(spell => spell.Id); //var fullspells = await scrapper.GetSpells(spellIds); - return spells; + //return spells; //return await scrapper.GetSpellIds(""); //return await new SpellsScrappers().GetSpells(); //return new string[] { "value1", "value2" };