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

Remise en place card data json

This commit is contained in:
Yan Maniez 2018-05-07 00:44:07 +02:00
parent 31089eb04d
commit c230fe4362
3 changed files with 42 additions and 29 deletions

View file

@ -105,18 +105,19 @@ namespace AideDeJeuLib.Cards
return contents.ToArray(); return contents.ToArray();
} }
public static CardData ToBaseCardData(IReadOnlyDictionary<string, string> context, Spell spell) public static CardData ToBaseCardData(Spell spell)
{ {
string color = context["color"]; //string color = context["color"];
string backgroundImage = context["background_image"]; //string backgroundImage = context["background_image"];
string color = "red";
var cardData = new CardData(); var cardData = new CardData();
cardData.Count = 1; cardData.Count = 1;
cardData.Color = color; cardData.Color = color;
cardData.Title = spell.Name; cardData.Title = spell.NamePHB;
cardData.TitleSize = "10"; cardData.TitleSize = "10";
cardData.Icon = "white-book-" + spell.Level; cardData.Icon = "white-book-" + spell.Level;
cardData.IconBack = "robe"; cardData.IconBack = "robe";
cardData.BackgroundImage = backgroundImage; //cardData.BackgroundImage = backgroundImage;
cardData.Tags = new string[] cardData.Tags = new string[]
{ {
"sort", "sort",
@ -124,10 +125,10 @@ namespace AideDeJeuLib.Cards
}; };
return cardData; return cardData;
} }
public static CardData[] ToCardDatas(IReadOnlyDictionary<string, string> context, Spell spell) public static CardData[] ToCardDatas(Spell spell)
{ {
var cardDatas = new List<CardData>(); var cardDatas = new List<CardData>();
var cardData = ToBaseCardData(context, spell); var cardData = ToBaseCardData(spell);
var contents = new List<CardContent>(); var contents = new List<CardContent>();
contents.AddRange(new CardContent[] contents.AddRange(new CardContent[]
@ -164,7 +165,7 @@ namespace AideDeJeuLib.Cards
cardData.Contents = contents.ToArray(); cardData.Contents = contents.ToArray();
cardDatas.Add(cardData); cardDatas.Add(cardData);
cardData = ToBaseCardData(context, spell); cardData = ToBaseCardData(spell);
contents = new List<CardContent>(); contents = new List<CardContent>();
if (section != null) if (section != null)
{ {

View file

@ -84,7 +84,7 @@ namespace AideDeJeuLib.Spells
return Spell.FromHtml(divSpell); return Spell.FromHtml(divSpell);
} }
public async Task<IEnumerable<string>> GetSpellIds(string classe, int niveauMin = 0, int niveauMax = 9) public async Task<IEnumerable<string>> GetSpellIds(string classe, string niveauMin = "Z", string niveauMax = "9")
{ {
string html = null; string html = null;
using (var client = GetHttpClient()) 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/dnd/sorts.php?vf=rayon-de-givre
// https://www.aidedd.org/regles/sorts/ // 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(); var pack = new HtmlDocument();
pack.LoadHtml(html); pack.LoadHtml(html);
@ -120,26 +120,28 @@ namespace AideDeJeuLib.Spells
var spells = pack.DocumentNode.SelectNodes("//div[contains(@class,'blocCarte')]").ToList(); var spells = pack.DocumentNode.SelectNodes("//div[contains(@class,'blocCarte')]").ToList();
foreach (var spell in spells) foreach (var spell in spells)
{ {
var newSpell = new Spell(); //var newSpell = new Spell();
newSpell.Name = spell.SelectSingleNode("h1").InnerText; var newSpell = Spell.FromHtml(spell);
newSpell.NameVO = spell.SelectSingleNode("div[@class='trad']").InnerText; //newSpell.Name = spell.SelectSingleNode("h1").InnerText;
newSpell.LevelType = spell.SelectSingleNode("h2/em").InnerText; //newSpell.NameVO = spell.SelectSingleNode("div[@class='trad']").InnerText;
newSpell.Level = newSpell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[0].Split(' ')[1]; //newSpell.LevelType = spell.SelectSingleNode("h2/em").InnerText;
newSpell.Type = newSpell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[1]; //newSpell.Level = newSpell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[0].Split(' ')[1];
newSpell.CastingTime = spell.SelectSingleNode("div[@class='paragraphe']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; //newSpell.Type = newSpell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[1];
newSpell.Range = spell.SelectSingleNode("div[strong/text()='Portée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; //newSpell.CastingTime = spell.SelectSingleNode("div[@class='paragraphe']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
newSpell.Components = spell.SelectSingleNode("div[strong/text()='Composantes']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; //newSpell.Range = spell.SelectSingleNode("div[strong/text()='Portée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
newSpell.Duration = spell.SelectSingleNode("div[strong/text()='Durée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1]; //newSpell.Components = spell.SelectSingleNode("div[strong/text()='Composantes']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
newSpell.DescriptionDiv = spell.SelectSingleNode("div[contains(@class,'description')]"); //newSpell.Duration = spell.SelectSingleNode("div[strong/text()='Durée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
//newSpell.DescriptionHtml = newSpell.DescriptionDiv.InnerHtml; //newSpell.DescriptionDiv = spell.SelectSingleNode("div[contains(@class,'description')]");
//newSpell.Description = newSpell.DescriptionDiv.InnerText; ////newSpell.DescriptionHtml = newSpell.DescriptionDiv.InnerHtml;
newSpell.Overflow = spell.SelectSingleNode("div[@class='overflow']")?.InnerText; ////newSpell.Description = newSpell.DescriptionDiv.InnerText;
newSpell.NoOverflow = spell.SelectSingleNode("div[@class='nooverflow']")?.InnerText; //newSpell.Overflow = spell.SelectSingleNode("div[@class='overflow']")?.InnerText;
newSpell.Source = spell.SelectSingleNode("div[@class='source']").InnerText; //newSpell.NoOverflow = spell.SelectSingleNode("div[@class='nooverflow']")?.InnerText;
//newSpell.Source = spell.SelectSingleNode("div[@class='source']").InnerText;
newSpells.Add(newSpell); newSpells.Add(newSpell);
} }
return newSpells; return newSpells;
} }
/* /*
public async Task<string> OnGetAsync(IReadOnlyDictionary<string, string> context) public async Task<string> OnGetAsync(IReadOnlyDictionary<string, string> context)
{ {

View file

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using AideDeJeuLib.Cards;
using AideDeJeuLib.Spells; using AideDeJeuLib.Spells;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -12,13 +13,22 @@ namespace AideDeJeuWeb.Controllers
{ {
// GET api/values // GET api/values
[HttpGet] [HttpGet]
public async Task<IEnumerable<Spell>> Get() public async Task<IEnumerable<CardData>> Get()
{ {
var scrapper = new SpellsScrappers(); 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<CardData>();
foreach (var spell in spells)
{
cardDatas.AddRange(Converters.ToCardDatas(spell));
}
return cardDatas;
//var spellIds = spells.Select(spell => spell.Id); //var spellIds = spells.Select(spell => spell.Id);
//var fullspells = await scrapper.GetSpells(spellIds); //var fullspells = await scrapper.GetSpells(spellIds);
return spells; //return spells;
//return await scrapper.GetSpellIds(""); //return await scrapper.GetSpellIds("");
//return await new SpellsScrappers().GetSpells(); //return await new SpellsScrappers().GetSpells();
//return new string[] { "value1", "value2" }; //return new string[] { "value1", "value2" };