1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-29 22:45:44 +00:00

Sorts H&D

This commit is contained in:
Yan Maniez 2018-05-24 21:40:16 +02:00
parent 38f9ea177a
commit d45d8ef994
3 changed files with 9258 additions and 7 deletions

View file

@ -15,15 +15,18 @@ namespace AideDeJeuCmd
{
static async Task Main(string[] args)
{
string baseDir = @"..\..\..\..\..\Data\";
string dataDir = @"..\..\..\..\..\Data\";
//string ignoreDir = @"..\..\..\..\..\Ignore\";
//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();
var spells = LoadJSon<IEnumerable<Spell>>(baseDir + "spells.json");
var spells = LoadJSon<IEnumerable<Spell>>(dataDir + "spells.json");
var spellsVO = new List<Spell>();
foreach (var spell in spells)
{
@ -37,10 +40,10 @@ namespace AideDeJeuCmd
Console.WriteLine(string.Format("{0} : {1} / {2} : {3}", spell.IdVF, spell.NamePHB, spellVO.IdVO, spellVO.NamePHB));
}
SaveJSon<IEnumerable<Spell>>(baseDir + "spells_vf.json", spells);
SaveJSon<IEnumerable<Spell>>(baseDir + "spells_vo.json", spellsVO);
SaveJSon<IEnumerable<Spell>>(dataDir + "spells_vf.json", spells);
SaveJSon<IEnumerable<Spell>>(dataDir + "spells_vo.json", spellsVO);
var monsters = LoadJSon<IEnumerable<Monster>>(baseDir + "monsters.json");
var monsters = LoadJSon<IEnumerable<Monster>>(dataDir + "monsters.json");
var monstersVO = new List<Monster>();
foreach (var monster in monsters)
{
@ -54,12 +57,118 @@ namespace AideDeJeuCmd
Console.WriteLine(string.Format("{0} : {1} / {2} : {3}", monster.IdVF, monster.NamePHB, monsterVO.IdVO, monsterVO.NamePHB));
}
SaveJSon<IEnumerable<Monster>>(baseDir + "monsters_vf.json", monsters);
SaveJSon<IEnumerable<Monster>>(baseDir + "monsters_vo.json", monstersVO);
SaveJSon<IEnumerable<Monster>>(dataDir + "monsters_vf.json", monsters);
SaveJSon<IEnumerable<Monster>>(dataDir + "monsters_vo.json", monstersVO);
*/
var spellsHD = new List<Spell>();
var spell = new Spell();
using (var reader = new StreamReader(dataDir + "spells_hd.txt"))
{
var line = await reader.ReadLineAsync();
while (line != null)
{
if (line.Length == 0)
{
Console.WriteLine(spell.NamePHB);
spell.DescriptionHtml = await FormatDescriptionAsync(spell.DescriptionHtml);
spellsHD.Add(spell);
spell = new Spell();
}
else
{
if (spell.NamePHB == null)
{
spell.NamePHB = line;
}
else if (spell.LevelType == null)
{
spell.LevelType = line;
}
else
{
if(line.StartsWith("Temps dincantation : "))
{
spell.CastingTime = line.Substring(23);
}
else if(line.StartsWith("Portée : "))
{
spell.Range = line.Substring(9);
}
else if (line.StartsWith("Composantes : "))
{
spell.Components = line.Substring(14);
}
else if (line.StartsWith("Durée : "))
{
spell.Duration = line.Substring(8);
}
else
{
spell.DescriptionHtml += line + "\n";
//if (line.EndsWith("."))
//{
// spell.DescriptionHtml += line + "\n";
//}
//else if (line.EndsWith("-"))
//{
// spell.DescriptionHtml += line.Substring(0, line.Length - 1);
//}
//else
//{
// spell.DescriptionHtml += line + " ";
//}
}
}
}
line = await reader.ReadLineAsync();
}
}
SaveJSon<IEnumerable<Spell>>(dataDir + "spells_hd.json", spellsHD);
Console.WriteLine("Hello World!");
}
static async Task<string> FormatDescriptionAsync(string description)
{
string formattedDescription = "";
using (var reader = new StringReader(description))
{
var line = await reader.ReadLineAsync();
var li = false;
while (line != null)
{
if (line.StartsWith("»» "))
{
li = true;
formattedDescription += "<li>" + line.Substring(3);
}
if (line.EndsWith("."))
{
formattedDescription += line;
if (li)
{
formattedDescription += "</li>";
li = false;
}
formattedDescription += "\n";
}
else
{
formattedDescription += line + " ";
}
line = await reader.ReadLineAsync();
}
if (li)
{
formattedDescription += "</li>";
}
}
return formattedDescription;
}
private static T LoadJSon<T>(string filename) where T : class
{
var serializer = new DataContractJsonSerializer(typeof(T));

1
Data/spells_hd.json Normal file

File diff suppressed because one or more lines are too long

9141
Data/spells_hd.txt Normal file

File diff suppressed because it is too large Load diff