mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-30 23:16:09 +00:00 
			
		
		
		
	Remise en place card data json
This commit is contained in:
		
							parent
							
								
									31089eb04d
								
							
						
					
					
						commit
						c230fe4362
					
				
					 3 changed files with 42 additions and 29 deletions
				
			
		|  | @ -105,18 +105,19 @@ namespace AideDeJeuLib.Cards | |||
|             return contents.ToArray(); | ||||
|         } | ||||
| 
 | ||||
|         public static CardData ToBaseCardData(IReadOnlyDictionary<string, string> 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<string, string> context, Spell spell) | ||||
|         public static CardData[] ToCardDatas(Spell spell) | ||||
|         { | ||||
|             var cardDatas = new List<CardData>(); | ||||
|             var cardData = ToBaseCardData(context, spell); | ||||
|             var cardData = ToBaseCardData(spell); | ||||
| 
 | ||||
|             var contents = new List<CardContent>(); | ||||
|             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<CardContent>(); | ||||
|                     if (section != null) | ||||
|                     { | ||||
|  |  | |||
|  | @ -84,7 +84,7 @@ namespace AideDeJeuLib.Spells | |||
|             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; | ||||
|             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<string> OnGetAsync(IReadOnlyDictionary<string, string> context) | ||||
|         { | ||||
|  |  | |||
|  | @ -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<IEnumerable<Spell>> Get() | ||||
|         public async Task<IEnumerable<CardData>> 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<CardData>(); | ||||
|             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" }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez