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

Recablage des filtres pour les sorts en local + reparsing à la volée du html en vue détail en attendant que la bdd soit carrée

This commit is contained in:
Yan Maniez 2018-05-14 21:40:18 +02:00
parent 1c451bf795
commit 3ac3afc3aa
8 changed files with 106 additions and 46 deletions

View file

@ -85,6 +85,9 @@
<AndroidAsset Include="Assets\LinLibertine_aZL.ttf" />
<AndroidAsset Include="Assets\LinLibertine_DR.ttf" />
<AndroidAsset Include="Assets\LinLibertine_I.ttf" />
<AndroidAsset Include="..\..\Data\database.db">
<Link>Assets\database.db</Link>
</AndroidAsset>
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
</ItemGroup>

View file

@ -29,7 +29,33 @@ namespace AideDeJeu.Droid
public string GetDatabasePath(string databaseName)
{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), databaseName);
var documentsDirectoryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var path = Path.Combine(documentsDirectoryPath, databaseName);
// This is where we copy in our pre-created database
if (!File.Exists(path))
{
using (var inStream = Android.App.Application.Context.Assets.Open(databaseName))
{
using (var outStream = new FileStream(path, FileMode.Create))
{
inStream.CopyTo(outStream);
}
}
//using (var binaryReader = new BinaryReader(Android.App.Application.Context.Assets.Open(databaseName)))
//{
// using (var binaryWriter = new BinaryWriter(new FileStream(path, FileMode.Create)))
// {
// byte[] buffer = new byte[2048];
// int length = 0;
// while ((length = binaryReader.Read(buffer, 0, buffer.Length)) > 0)
// {
// binaryWriter.Write(buffer, 0, length);
// }
// }
//}
}
return path;
}
}
}

View file

@ -102,6 +102,9 @@
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<Content Include="..\..\Data\database.db">
<Link>Assets\database.db</Link>
</Content>
<None Include="AideDeJeu.UWP_TemporaryKey.pfx" />
<Content Include="Assets\Fonts\LinLibertine_R.ttf" />
<Content Include="Assets\Fonts\LinLibertine_RB.ttf" />

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
<Identity Name="4f4935f2-347d-4bfe-a2ec-9e7a8ed83a1d" Publisher="CN=899f1516-2a42-438b-8163-40d8e0e659aa" Version="1.0.0.0" />
<Identity Name="AideDeJeu-4f4935f2-347d-4bfe-a2ec-9e7a8ed83a1d" Publisher="CN=899f1516-2a42-438b-8163-40d8e0e659aa" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="ec0cc741-fd3e-485c-81be-68815c480690" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>AideDeJeu.UWP</DisplayName>
<PublisherDisplayName>899f1516-2a42-438b-8163-40d8e0e659aa</PublisherDisplayName>
<PublisherDisplayName>Nioux-899f1516-2a42-438b-8163-40d8e0e659aa</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>

View file

@ -19,14 +19,22 @@ namespace AideDeJeu.Services
return postDatabaseContext;
}
public async Task<IEnumerable<Spell>> GetSpellsAsync()
public async Task<IEnumerable<Spell>> GetSpellsAsync(string classe, string niveauMin, string niveauMax, string ecole, string rituel, string source)
{
using (var context = CreateContext())
{
//We use OrderByDescending because Posts are generally displayed from most recent to oldest
return await context.Spells
.AsNoTracking()
.OrderByDescending(spell => spell.Id)
.Where(spell =>
(int.Parse(spell.Level) >= int.Parse(niveauMin)) &&
(int.Parse(spell.Level) <= int.Parse(niveauMax)) &&
spell.Type.Contains(ecole) &&
spell.Source.Contains(source) &&
spell.Type.Contains(classe) &&
spell.Type.Contains(rituel)
)
.OrderByDescending(spell => spell.NamePHB)
.ToListAsync();
}
}

View file

@ -120,11 +120,13 @@ namespace AideDeJeu.ViewModels
try
{
using (var spellsScrappers = new SpellsScrappers())
{
var item = await spellsScrappers.GetSpell(Item.Id);
Item = item;
}
Item.ParseHtml();
Item = _Item;
//using (var spellsScrappers = new SpellsScrappers())
//{
// var item = await spellsScrappers.GetSpell(Item.Id);
// Item = item;
//}
}
catch (Exception ex)
{

View file

@ -16,19 +16,19 @@ namespace AideDeJeu.ViewModels
public List<KeyValuePair<string, string>> Classes { get; set; } = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("", "Toutes" ),
new KeyValuePair<string, string>("b", "Barde" ),
new KeyValuePair<string, string>("c", "Clerc" ),
new KeyValuePair<string, string>("d", "Druide" ),
new KeyValuePair<string, string>("s", "Ensorceleur" ),
new KeyValuePair<string, string>("w", "Magicien" ),
new KeyValuePair<string, string>("p", "Paladin" ),
new KeyValuePair<string, string>("r", "Rôdeur" ),
new KeyValuePair<string, string>("k", "Sorcier" ),
new KeyValuePair<string, string>("Barde", "Barde" ),
new KeyValuePair<string, string>("Clerc", "Clerc" ),
new KeyValuePair<string, string>("Druide", "Druide" ),
new KeyValuePair<string, string>("Ensorceleur", "Ensorceleur" ),
new KeyValuePair<string, string>("Magicien", "Magicien" ),
new KeyValuePair<string, string>("Paladin", "Paladin" ),
new KeyValuePair<string, string>("Rôdeur", "Rôdeur" ),
new KeyValuePair<string, string>("Sorcier", "Sorcier" ),
};
public List<KeyValuePair<string, string>> Niveaux { get; set; } = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("Z", "Sorts mineurs"),
new KeyValuePair<string, string>("0", "Sorts mineurs"),
new KeyValuePair<string, string>("1", "Niveau 1"),
new KeyValuePair<string, string>("2", "Niveau 2"),
new KeyValuePair<string, string>("3", "Niveau 3"),
@ -46,24 +46,24 @@ namespace AideDeJeu.ViewModels
new KeyValuePair<string, string>("abjuration", "Abjuration"),
new KeyValuePair<string, string>("divination", "Divination"),
new KeyValuePair<string, string>("enchantement", "Enchantement"),
new KeyValuePair<string, string>("evocation", "Évocation"),
new KeyValuePair<string, string>("vocation", "Évocation"),
new KeyValuePair<string, string>("illusion", "Illusion"),
new KeyValuePair<string, string>("invocation", "Invocation"),
new KeyValuePair<string, string>("necromancie", "Nécromancie"),
new KeyValuePair<string, string>("cromancie", "Nécromancie"),
new KeyValuePair<string, string>("transmutation", "Transmutation"),
};
public List<KeyValuePair<string, string>> Rituels { get; set; } = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("", "Tous"),
new KeyValuePair<string, string>("1", "Rituel"),
new KeyValuePair<string, string>("(rituel)", "Rituel"),
};
public List<KeyValuePair<string, string>> Sources { get; set; } = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("", "Toutes"),
new KeyValuePair<string, string>("srd", "SRD"),
new KeyValuePair<string, string>("ph", "PHB"),
new KeyValuePair<string, string>("(SRD)", "SRD"),
new KeyValuePair<string, string>("Player's Handbook", "PHB"),
new KeyValuePair<string, string>("sup", "SCAG, XGtE"),
};
@ -171,10 +171,14 @@ namespace AideDeJeu.ViewModels
{
AllItems.Clear();
IEnumerable<Spell> items = null;
using (var spellsScrappers = new SpellsScrappers())
{
items = await spellsScrappers.GetSpells(classe: Classes[Classe].Key, niveauMin: Niveaux[NiveauMin].Key, niveauMax: Niveaux[NiveauMax].Key, ecole: Ecoles[Ecole].Key, rituel: Rituels[Rituel].Key, source: Sources[Source].Key);
}
//using (var spellsScrappers = new SpellsScrappers())
//{
// items = await spellsScrappers.GetSpells(classe: Classes[Classe].Key, niveauMin: Niveaux[NiveauMin].Key, niveauMax: Niveaux[NiveauMax].Key, ecole: Ecoles[Ecole].Key, rituel: Rituels[Rituel].Key, source: Sources[Source].Key);
//}
ItemDatabaseHelper<ItemDatabaseContext> helper = new ItemDatabaseHelper<ItemDatabaseContext>();
items = await helper.GetSpellsAsync(classe: Classes[Classe].Key, niveauMin: Niveaux[NiveauMin].Key, niveauMax: Niveaux[NiveauMax].Key, ecole: Ecoles[Ecole].Key, rituel: Rituels[Rituel].Key, source: Sources[Source].Key);
//try
//{

View file

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;
@ -55,33 +56,46 @@ namespace AideDeJeuLib.Spells
public string NoOverflow { get; set; }
public string Source { get; set; }
public static Spell FromHtml(HtmlNode nodeSpell)
public void ParseHtml()
{
var spell = new Spell();
spell.Html = nodeSpell.OuterHtml;
spell.Name = nodeSpell.SelectSingleNode("h1").InnerText;
var pack = new HtmlDocument();
pack.LoadHtml(this.Html);
var divSpell = pack.DocumentNode.SelectNodes("//div[contains(@class,'bloc')]").FirstOrDefault();
ParseNode(divSpell);
}
public void ParseNode(HtmlNode nodeSpell)
{
this.Name = nodeSpell.SelectSingleNode("h1").InnerText;
var altNames = nodeSpell.SelectSingleNode("div[@class='trad']")?.InnerText;
if (altNames != null)
{
var matchNames = new Regex(@"\[ (?<vo>.*?) \](?: \[ (?<alt>.*?) \])?").Match(altNames);
spell.NameVO = matchNames.Groups["vo"].Value;
spell.NamePHB = string.IsNullOrEmpty(matchNames.Groups["alt"].Value) ? spell.Name : matchNames.Groups["alt"].Value;
this.NameVO = matchNames.Groups["vo"].Value;
this.NamePHB = string.IsNullOrEmpty(matchNames.Groups["alt"].Value) ? this.Name : matchNames.Groups["alt"].Value;
}
else
{
spell.NamePHB = spell.Name;
this.NamePHB = this.Name;
}
spell.LevelType = nodeSpell.SelectSingleNode("h2/em").InnerText;
spell.Level = spell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[0].Split(' ')[1];
spell.Type = spell.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[1];
spell.CastingTime = nodeSpell.SelectSingleNode("div[@class='paragraphe']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
spell.Range = nodeSpell.SelectSingleNode("div[strong/text()='Portée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
spell.Components = nodeSpell.SelectSingleNode("div[strong/text()='Composantes']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
spell.Duration = nodeSpell.SelectSingleNode("div[strong/text()='Durée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
spell.DescriptionDiv = nodeSpell.SelectSingleNode("div[contains(@class,'description')]");
spell.Overflow = nodeSpell.SelectSingleNode("div[@class='overflow']")?.InnerText;
spell.NoOverflow = nodeSpell.SelectSingleNode("div[@class='nooverflow']")?.InnerText;
spell.Source = nodeSpell.SelectSingleNode("div[@class='source']").InnerText;
this.LevelType = nodeSpell.SelectSingleNode("h2/em").InnerText;
this.Level = this.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[0].Split(' ')[1];
this.Type = this.LevelType.Split(new string[] { " - " }, StringSplitOptions.None)[1];
this.CastingTime = nodeSpell.SelectSingleNode("div[@class='paragraphe']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
this.Range = nodeSpell.SelectSingleNode("div[strong/text()='Portée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
this.Components = nodeSpell.SelectSingleNode("div[strong/text()='Composantes']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
this.Duration = nodeSpell.SelectSingleNode("div[strong/text()='Durée']").InnerText.Split(new string[] { " : " }, StringSplitOptions.None)[1];
this.DescriptionDiv = nodeSpell.SelectSingleNode("div[contains(@class,'description')]");
this.Overflow = nodeSpell.SelectSingleNode("div[@class='overflow']")?.InnerText;
this.NoOverflow = nodeSpell.SelectSingleNode("div[@class='nooverflow']")?.InnerText;
this.Source = nodeSpell.SelectSingleNode("div[@class='source']").InnerText;
}
public static Spell FromHtml(HtmlNode nodeSpell)
{
var spell = new Spell();
spell.Html = nodeSpell.OuterHtml;
spell.ParseNode(nodeSpell);
return spell;
}
}