mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-12-15 14:49:42 +00:00
Utilisation de la page sorts.php au lieu de la page livre-sorts pour ne charger que les titres et surtout avoir plus d'options de filtre
This commit is contained in:
parent
87438c69c4
commit
8089e3afb0
5 changed files with 127 additions and 8 deletions
|
|
@ -58,7 +58,8 @@ namespace AideDeJeu.Services
|
||||||
public async Task<IEnumerable<Spell>> GetItemsAsync(bool forceRefresh = false)
|
public async Task<IEnumerable<Spell>> GetItemsAsync(bool forceRefresh = false)
|
||||||
{
|
{
|
||||||
var scrapper = new Scrappers();
|
var scrapper = new Scrappers();
|
||||||
items = (await scrapper.GetSpells(await scrapper.GetSpellIds(""))).ToList();
|
//items = (await scrapper.GetSpells(await scrapper.GetSpellIds(""))).ToList();
|
||||||
|
items = (await scrapper.GetSpells()).ToList();
|
||||||
|
|
||||||
//items = spells.Select(spell => new Item() { Text = spell.Title, Description = spell.DescriptionText }).ToList();
|
//items = spells.Select(spell => new Item() { Text = spell.Title, Description = spell.DescriptionText }).ToList();
|
||||||
return await Task.FromResult(items);
|
return await Task.FromResult(items);
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,54 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using AideDeJeu.Models;
|
using AideDeJeu.Models;
|
||||||
using AideDeJeuLib;
|
using AideDeJeuLib;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace AideDeJeu.ViewModels
|
namespace AideDeJeu.ViewModels
|
||||||
{
|
{
|
||||||
public class SpellDetailViewModel : BaseViewModel
|
public class SpellDetailViewModel : BaseViewModel
|
||||||
{
|
{
|
||||||
public Spell Item { get; set; }
|
Spell _Item = null;
|
||||||
|
public Spell Item
|
||||||
|
{
|
||||||
|
get { return _Item; }
|
||||||
|
set { SetProperty(ref _Item, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command LoadItemCommand { get; set; }
|
||||||
|
|
||||||
public SpellDetailViewModel(Spell item = null)
|
public SpellDetailViewModel(Spell item = null)
|
||||||
{
|
{
|
||||||
Title = item?.Title;
|
Title = item?.Title;
|
||||||
Item = item;
|
Item = item;
|
||||||
|
LoadItemCommand = new Command(async () => await ExecuteLoadItemCommand());
|
||||||
|
}
|
||||||
|
async Task ExecuteLoadItemCommand()
|
||||||
|
{
|
||||||
|
if (IsBusy)
|
||||||
|
return;
|
||||||
|
|
||||||
|
IsBusy = true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//Items.Clear();
|
||||||
|
var item = await new Scrappers().GetSpell(Item.Id);
|
||||||
|
Item = item;
|
||||||
|
//foreach (var item in items)
|
||||||
|
//{
|
||||||
|
// Items.Add(item);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine(ex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsBusy = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,9 @@ namespace AideDeJeu.Views
|
||||||
if (item == null)
|
if (item == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await Navigation.PushAsync(new SpellDetailPage(new SpellDetailViewModel(item)));
|
var spellvm = new SpellDetailViewModel(item);
|
||||||
|
spellvm.LoadItemCommand.Execute(null);
|
||||||
|
await Navigation.PushAsync(new SpellDetailPage(spellvm));
|
||||||
|
|
||||||
// Manually deselect item.
|
// Manually deselect item.
|
||||||
ItemsListView.SelectedItem = null;
|
ItemsListView.SelectedItem = null;
|
||||||
|
|
@ -34,7 +36,7 @@ namespace AideDeJeu.Views
|
||||||
|
|
||||||
async void AddItem_Clicked(object sender, EventArgs e)
|
async void AddItem_Clicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await Navigation.PushModalAsync(new NavigationPage(new NewItemPage()));
|
//await Navigation.PushModalAsync(new NavigationPage(new NewItemPage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnAppearing()
|
protected override void OnAppearing()
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Runtime.Serialization.Json;
|
using System.Runtime.Serialization.Json;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AideDeJeuLib
|
namespace AideDeJeuLib
|
||||||
|
|
@ -40,6 +41,83 @@ namespace AideDeJeuLib
|
||||||
return pack.DocumentNode.SelectNodes("//input[@name='select_sorts[]']").Select(node => node.GetAttributeValue("value", ""));
|
return pack.DocumentNode.SelectNodes("//input[@name='select_sorts[]']").Select(node => node.GetAttributeValue("value", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Spell>> GetSpells(string classe = "", int niveauMin = 0, int niveauMax = 9, string ecole = "", string rituel = "", string source = "srd")
|
||||||
|
{
|
||||||
|
string html = null;
|
||||||
|
using (var client = GetHttpClient())
|
||||||
|
{
|
||||||
|
// https://www.aidedd.org/dnd/sorts.php?vo=ray-of-frost
|
||||||
|
// 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/regles/sorts/?c={0}&min=1{1}&max=1{2}&e={3}&r={4}&s={5}", classe, niveauMin, niveauMax, ecole, rituel, source));
|
||||||
|
}
|
||||||
|
var pack = new HtmlDocument();
|
||||||
|
pack.LoadHtml(html);
|
||||||
|
var tdssort = pack.GetElementbyId("liste").Element("table").Elements("tr").ToList();
|
||||||
|
var spells = new List<Spell>();
|
||||||
|
foreach (var tdsort in tdssort)
|
||||||
|
{
|
||||||
|
var thssort = tdsort.Elements("td").ToArray();
|
||||||
|
if (thssort.Length > 0)
|
||||||
|
{
|
||||||
|
Spell spell = new Spell();
|
||||||
|
spell.Title = thssort[0].InnerText;
|
||||||
|
var href = thssort[0].Element("a").GetAttributeValue("href", "");
|
||||||
|
var regex = new Regex("vf=(?<id>.*)");
|
||||||
|
spell.Id = regex.Match(href).Groups["id"].Value;
|
||||||
|
spell.Level = thssort[1].InnerText;
|
||||||
|
spell.Type = thssort[2].InnerText;
|
||||||
|
spell.CastingTime = thssort[3].InnerText;
|
||||||
|
spell.Concentration = thssort[4].InnerText;
|
||||||
|
spell.Rituel = thssort[5].InnerText;
|
||||||
|
spells.Add(spell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return spells;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Spell> GetSpell(string id)
|
||||||
|
{
|
||||||
|
string html = null;
|
||||||
|
using (var client = GetHttpClient())
|
||||||
|
{
|
||||||
|
// https://www.aidedd.org/dnd/sorts.php?vo=ray-of-frost
|
||||||
|
// 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/dnd/sorts.php?vf={0}", id));
|
||||||
|
}
|
||||||
|
var pack = new HtmlDocument();
|
||||||
|
pack.LoadHtml(html);
|
||||||
|
var newSpells = new List<Spell>();
|
||||||
|
var divSpell = pack.DocumentNode.SelectNodes("//div[contains(@class,'bloc')]").FirstOrDefault();
|
||||||
|
var newSpell = HtmlDivToSpell(divSpell);
|
||||||
|
|
||||||
|
return newSpell;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Spell HtmlDivToSpell(HtmlNode divSpell)
|
||||||
|
{
|
||||||
|
var newSpell = new Spell();
|
||||||
|
newSpell.Title = divSpell.SelectSingleNode("h1").InnerText;
|
||||||
|
newSpell.TitleUS = divSpell.SelectSingleNode("div[@class='trad']").InnerText;
|
||||||
|
newSpell.LevelType = divSpell.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 = divSpell.SelectSingleNode("div[@class='paragraphe']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
|
||||||
|
newSpell.Range = divSpell.SelectSingleNode("div[strong/text()='Portée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
|
||||||
|
newSpell.Components = divSpell.SelectSingleNode("div[strong/text()='Composantes']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
|
||||||
|
newSpell.Duration = divSpell.SelectSingleNode("div[strong/text()='Durée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
|
||||||
|
newSpell.DescriptionDiv = divSpell.SelectSingleNode("div[contains(@class,'description')]");
|
||||||
|
newSpell.Overflow = divSpell.SelectSingleNode("div[@class='overflow']")?.InnerText;
|
||||||
|
newSpell.NoOverflow = divSpell.SelectSingleNode("div[@class='nooverflow']")?.InnerText;
|
||||||
|
newSpell.Source = divSpell.SelectSingleNode("div[@class='source']").InnerText;
|
||||||
|
|
||||||
|
return newSpell;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<IEnumerable<Spell>> GetSpells(IEnumerable<string> spellIds)
|
public async Task<IEnumerable<Spell>> GetSpells(IEnumerable<string> spellIds)
|
||||||
{
|
{
|
||||||
string html = null;
|
string html = null;
|
||||||
|
|
@ -57,7 +135,6 @@ namespace AideDeJeuLib
|
||||||
var pack = new HtmlDocument();
|
var pack = new HtmlDocument();
|
||||||
pack.LoadHtml(html);
|
pack.LoadHtml(html);
|
||||||
var newSpells = new List<Spell>();
|
var newSpells = new List<Spell>();
|
||||||
var cardDatas = new List<CardData>();
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,14 @@ namespace AideDeJeuLib
|
||||||
public string LevelType { get; set; }
|
public string LevelType { get; set; }
|
||||||
public string Level { get; set; }
|
public string Level { get; set; }
|
||||||
public string Type { get; set; }
|
public string Type { get; set; }
|
||||||
|
public string Concentration { get; set; }
|
||||||
|
public string Rituel { get; set; }
|
||||||
public string CastingTime { get; set; }
|
public string CastingTime { get; set; }
|
||||||
public string Range { get; set; }
|
public string Range { get; set; }
|
||||||
public string Components { get; set; }
|
public string Components { get; set; }
|
||||||
public string Duration { get; set; }
|
public string Duration { get; set; }
|
||||||
public string DescriptionHtml { get { return DescriptionDiv.InnerHtml; } }
|
public string DescriptionHtml { get { return DescriptionDiv?.InnerHtml; } }
|
||||||
public string Description { get { return DescriptionDiv.InnerHtml.Replace("<br>", "\r\n").Replace("<strong>","").Replace("</strong>", "").Replace("<em>", "").Replace("</em>", ""); } }
|
public string Description { get { return DescriptionDiv?.InnerHtml?.Replace("<br>", "\r\n")?.Replace("<strong>","")?.Replace("</strong>", "")?.Replace("<em>", "")?.Replace("</em>", ""); } }
|
||||||
public HtmlNode DescriptionDiv { get; set; }
|
public HtmlNode DescriptionDiv { get; set; }
|
||||||
public string Overflow { get; set; }
|
public string Overflow { get; set; }
|
||||||
public string NoOverflow { get; set; }
|
public string NoOverflow { get; set; }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue