mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-29 22:45:44 +00:00
Préparation multilingue
This commit is contained in:
parent
ee98ddea9d
commit
ac7c57a956
8 changed files with 123 additions and 78 deletions
|
|
@ -53,6 +53,10 @@ namespace AideDeJeu.Tools
|
|||
{
|
||||
HtmlNodesToFormatedString(node.ChildNodes, fs, attributes);
|
||||
}
|
||||
else if (node.NodeType == HtmlNodeType.Document)
|
||||
{
|
||||
HtmlNodesToFormatedString(node.ChildNodes, fs, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
//public static void HtmlToFormatedString(HtmlNode parentNode, FormattedString fs, FontAttributes attributes = FontAttributes.None)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,21 @@
|
|||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\..\Data\monsters.json" Link="monsters.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="..\..\Data\spells.json" Link="spells.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\..\Data\database.db" Link="database.db">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.0.3" />
|
||||
|
|
|
|||
|
|
@ -25,24 +25,24 @@ namespace AideDeJeu.Services
|
|||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (DatabasePath == null)
|
||||
{
|
||||
switch (Device.RuntimePlatform)
|
||||
{
|
||||
case Device.iOS:
|
||||
SQLitePCL.Batteries_V2.Init();
|
||||
DatabasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library", DatabaseName); ;
|
||||
break;
|
||||
case Device.Android:
|
||||
DatabasePath = DependencyService.Get<INativeAPI>().GetDatabasePath(DatabaseName);
|
||||
break;
|
||||
case Device.UWP:
|
||||
DatabasePath = DependencyService.Get<INativeAPI>().GetDatabasePath(DatabaseName);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException("Platform not supported");
|
||||
}
|
||||
}
|
||||
//if (DatabasePath == null)
|
||||
//{
|
||||
// switch (Device.RuntimePlatform)
|
||||
// {
|
||||
// case Device.iOS:
|
||||
// SQLitePCL.Batteries_V2.Init();
|
||||
// DatabasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library", DatabaseName); ;
|
||||
// break;
|
||||
// case Device.Android:
|
||||
// DatabasePath = DependencyService.Get<INativeAPI>().GetDatabasePath(DatabaseName);
|
||||
// break;
|
||||
// case Device.UWP:
|
||||
// DatabasePath = DependencyService.Get<INativeAPI>().GetDatabasePath(DatabaseName);
|
||||
// break;
|
||||
// default:
|
||||
// throw new NotImplementedException("Platform not supported");
|
||||
// }
|
||||
//}
|
||||
// Specify that we will use sqlite and the path of the database here
|
||||
optionsBuilder.UseSqlite($"Filename={DatabasePath}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
using AideDeJeu.Services;
|
||||
using AideDeJeuLib.Monsters;
|
||||
using AideDeJeuLib.Spells;
|
||||
using HtmlAgilityPack;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
|
@ -12,21 +15,61 @@ namespace AideDeJeuCmd
|
|||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
var documentsDirectoryPath = @"C:\Users\yanma\Documents\Visual Studio 2017\Projects\AideDeJeu\Data\database.db"; // Windows.Storage.ApplicationData.Current.LocalFolder.Path;
|
||||
ItemDatabaseHelper helper = new ItemDatabaseHelper(documentsDirectoryPath);
|
||||
//var items = await helper.GetSpellsAsync(classe: "", niveauMin: "0", niveauMax: "9", ecole: "", rituel: "", source: "(SRD)");
|
||||
var items = await helper.GetMonstersAsync(category: "", type: "", minPower: " 0 (0 PX)", maxPower: " 30 (155000 PX)", size: "", legendary: "", source: "(SRD)");
|
||||
//var documentsDirectoryPath = @"database.db"; // Windows.Storage.ApplicationData.Current.LocalFolder.Path;
|
||||
//ItemDatabaseHelper helper = new ItemDatabaseHelper(documentsDirectoryPath);
|
||||
//var spells = await helper.GetSpellsAsync(classe: "", niveauMin: "0", niveauMax: "9", ecole: "", rituel: "", source: "(SRD)");
|
||||
//var monsters = await helper.GetMonstersAsync(category: "", type: "", minPower: " 0 (0 PX)", maxPower: " 30 (155000 PX)", size: "", legendary: "", source: "(SRD)");
|
||||
var pack = new HtmlDocument();
|
||||
var client = new HttpClient();
|
||||
|
||||
foreach (var item in items)
|
||||
var spells = LoadJSon<IEnumerable<Spell>>("spells.json");
|
||||
var monsters = LoadJSon<IEnumerable<Monster>>("monsters.json");
|
||||
var spellsVO = new List<Spell>();
|
||||
foreach(var spell in spells)
|
||||
{
|
||||
spell.ParseHtml();
|
||||
var htmlVO = await client.GetStringAsync(string.Format("https://www.aidedd.org/dnd/sorts.php?vo={0}", spell.IdVO));
|
||||
pack.LoadHtml(htmlVO);
|
||||
var spellVO = Spell.FromHtml(pack.DocumentNode.SelectSingleNode("//div[contains(@class,'bloc')]"));
|
||||
spellVO.IdVO = spell.IdVO;
|
||||
spell.IdVF = spellVO.IdVF;
|
||||
spellsVO.Add(spellVO);
|
||||
|
||||
Console.WriteLine(string.Format("{0} : {1} / {2} : {3}", spell.IdVF, spell.NamePHB, spellVO.IdVO, spellVO.NameVO));
|
||||
}
|
||||
DataContractJsonSerializer serializer = new DataContractJsonSerializer(items.GetType());
|
||||
MemoryStream stream = new MemoryStream();
|
||||
serializer.WriteObject(stream, items);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
string text = await new StreamReader(stream).ReadToEndAsync();
|
||||
|
||||
foreach(var monster in monsters)
|
||||
{
|
||||
monster.ParseHtml();
|
||||
}
|
||||
SaveJSon<IEnumerable<Monster>>("monsters_vf.json", monsters);
|
||||
SaveJSon<IEnumerable<Spell>>("spells_vf.json", spells);
|
||||
//SaveJSon<IEnumerable<Monster>>("monsters_fr.json", monsters);
|
||||
SaveJSon<IEnumerable<Spell>>("spells_vo.json", spellsVO);
|
||||
//DataContractJsonSerializer serializer = new DataContractJsonSerializer(items.GetType());
|
||||
//MemoryStream stream = new MemoryStream();
|
||||
//serializer.WriteObject(stream, items);
|
||||
//stream.Seek(0, SeekOrigin.Begin);
|
||||
//string text = await new StreamReader(stream).ReadToEndAsync();
|
||||
Console.WriteLine("Hello World!");
|
||||
}
|
||||
|
||||
private static T LoadJSon<T>(string filename) where T : class
|
||||
{
|
||||
var serializer = new DataContractJsonSerializer(typeof(T));
|
||||
using (var stream = new FileStream(filename, FileMode.Open))
|
||||
{
|
||||
return serializer.ReadObject(stream) as T;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SaveJSon<T>(string filename, T objT) where T : class
|
||||
{
|
||||
var serializer = new DataContractJsonSerializer(typeof(T));
|
||||
using (var stream = new FileStream(filename, FileMode.Create))
|
||||
{
|
||||
serializer.WriteObject(stream, objT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,4 @@
|
|||
<PackageReference Include="HtmlAgilityPack" Version="1.8.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System.ComponentModel.Annotations">
|
||||
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\microsoft.netcore.universalwindowsplatform\6.1.4\ref\uap10.0.15138\System.ComponentModel.Annotations.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text;
|
||||
|
||||
namespace AideDeJeuLib
|
||||
namespace AideDeJeuLib
|
||||
{
|
||||
public class Item
|
||||
{
|
||||
[Key]
|
||||
public string Id { get; set; }
|
||||
public string IdVO { get; set; }
|
||||
public string IdVF { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string NameVO { get; set; }
|
||||
public string NamePHB { get; set; }
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
using HtmlAgilityPack;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace AideDeJeuLib.Monsters
|
||||
|
|
@ -54,7 +51,6 @@ namespace AideDeJeuLib.Monsters
|
|||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
[NotMapped]
|
||||
public List<HtmlNode> SpecialFeatures { get; set; }
|
||||
//public List<string> SpecialFeaturesPersist
|
||||
//{
|
||||
|
|
@ -76,10 +72,8 @@ namespace AideDeJeuLib.Monsters
|
|||
//}
|
||||
|
||||
[IgnoreDataMember]
|
||||
[NotMapped]
|
||||
public List<HtmlNode> Actions { get; set; }
|
||||
[IgnoreDataMember]
|
||||
[NotMapped]
|
||||
public List<HtmlNode> LegendaryActions { get; set; }
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
using HtmlAgilityPack;
|
||||
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;
|
||||
|
||||
namespace AideDeJeuLib.Spells
|
||||
|
|
@ -21,26 +17,7 @@ namespace AideDeJeuLib.Spells
|
|||
public string Range { get; set; }
|
||||
public string Components { get; set; }
|
||||
public string Duration { get; set; }
|
||||
public string DescriptionHtml
|
||||
{
|
||||
get
|
||||
{
|
||||
return DescriptionDiv?.InnerHtml;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
HtmlDocument doc = new HtmlDocument();
|
||||
doc.LoadHtml(value);
|
||||
DescriptionDiv = doc.DocumentNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
DescriptionDiv = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
public string DescriptionHtml { get; set; }
|
||||
public string DescriptionText
|
||||
{
|
||||
get
|
||||
|
|
@ -49,8 +26,23 @@ namespace AideDeJeuLib.Spells
|
|||
}
|
||||
}
|
||||
[IgnoreDataMember]
|
||||
[NotMapped]
|
||||
public HtmlNode DescriptionDiv { get; set; }
|
||||
public HtmlNode DescriptionDiv
|
||||
{
|
||||
get
|
||||
{
|
||||
if(DescriptionHtml != null)
|
||||
{
|
||||
HtmlDocument doc = new HtmlDocument();
|
||||
doc.LoadHtml(DescriptionHtml);
|
||||
return doc.DocumentNode;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
DescriptionHtml = value?.OuterHtml;
|
||||
}
|
||||
}
|
||||
|
||||
public string Overflow { get; set; }
|
||||
public string NoOverflow { get; set; }
|
||||
|
|
@ -67,7 +59,14 @@ namespace AideDeJeuLib.Spells
|
|||
public void ParseNode(HtmlNode nodeSpell)
|
||||
{
|
||||
this.Name = nodeSpell.SelectSingleNode("h1").InnerText;
|
||||
var altNames = nodeSpell.SelectSingleNode("div[@class='trad']")?.InnerText;
|
||||
var divTrad = nodeSpell.SelectSingleNode("div[@class='trad']");
|
||||
|
||||
var linkVO = divTrad.SelectSingleNode("a").GetAttributeValue("href", "");
|
||||
var matchIdVF = new Regex(@"\?vf=(?<idvf>.*)").Match(linkVO);
|
||||
this.IdVF = matchIdVF?.Groups["idvf"]?.Value;
|
||||
var matchIdVO = new Regex(@"\?vo=(?<idvo>.*)").Match(linkVO);
|
||||
this.IdVO = matchIdVO?.Groups["idvo"]?.Value;
|
||||
var altNames = divTrad?.InnerText;
|
||||
if (altNames != null)
|
||||
{
|
||||
var matchNames = new Regex(@"\[ (?<vo>.*?) \](?: \[ (?<alt>.*?) \])?").Match(altNames);
|
||||
|
|
@ -81,10 +80,10 @@ namespace AideDeJeuLib.Spells
|
|||
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.CastingTime = nodeSpell.SelectSingleNode("div[@class='paragraphe']").InnerText.Split(new string[] { ": " }, StringSplitOptions.None)[1];
|
||||
this.Range = nodeSpell.SelectSingleNode("div[strong/text()='Portée' or strong/text()='Range']").InnerText.Split(new string[] { ": " }, StringSplitOptions.None)[1];
|
||||
this.Components = nodeSpell.SelectSingleNode("div[strong/text()='Composantes' or strong/text()='Components']")?.InnerText?.Split(new string[] { ": " }, StringSplitOptions.None)?[1];
|
||||
this.Duration = nodeSpell.SelectSingleNode("div[strong/text()='Durée' or strong/text()='Duration']").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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue