Больше обработчиков
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Pf2eModel.Model;
|
||||
using Pf2eModel;
|
||||
using Slugify;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers;
|
||||
|
||||
@@ -42,11 +42,6 @@ internal class AonprdLoader(AonprdImporter importer)
|
||||
{
|
||||
foreach (string? file in Compendium.Files(types))
|
||||
{
|
||||
if (file is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
using StreamReader fileReader = new(Path.Combine(Importer.Dir, $"{file}.json"));
|
||||
JArray array = JArray.Parse(fileReader.ReadToEnd());
|
||||
|
||||
|
||||
+40
-61
@@ -1,5 +1,6 @@
|
||||
using LinqToDB;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Pf2eModel;
|
||||
using Pf2eModel.Model;
|
||||
using Pf2eModel.Model.Base;
|
||||
using Pf2eModel.Model.Base.Source;
|
||||
@@ -49,7 +50,7 @@ internal abstract partial class AbstractProcessor(ProcessorInput input)
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
protected string AddedDescription(string path) => $"\n\n---\n[{path}]\n\n{Input.GetOptional<string>(path) ?? ""}";
|
||||
protected string AddedDescription(string path) => $"\r\n\r\n========== [{path}] ==========\r\n\r\n{Input.GetOptional<string>(path) ?? ""}";
|
||||
|
||||
protected string AddedDescription(string[] paths) => string.Join("", paths.Select(AddedDescription));
|
||||
|
||||
@@ -60,7 +61,7 @@ internal abstract partial class AbstractProcessor(ProcessorInput input)
|
||||
Entity.Id = Helper.NextEntityId;
|
||||
Entity.Type = Type;
|
||||
Entity.Name = Input.GetRequired<string>("name");
|
||||
Entity.Img = ""; // GetRequired<string>("img");
|
||||
Entity.Img = "";
|
||||
Entity.Description = GetDescription();
|
||||
Entity.Rarity = Input.EnumOptional<EntityRarity>("rarity", EntityRarity.Common);
|
||||
Entity.Slug = Helper.GenerateSlug(Entity.Name);
|
||||
@@ -85,32 +86,33 @@ internal abstract partial class AbstractProcessor(ProcessorInput input)
|
||||
|
||||
JArray? legacyIdArray = Input.GetOptional<JArray>("legacy_id");
|
||||
|
||||
if (legacyIdArray is not null)
|
||||
if (legacyIdArray is null)
|
||||
{
|
||||
string legacyId = legacyIdArray[0].ToString();
|
||||
|
||||
if (LegacyAliases.TryGetValue(legacyId, out string? legacyName))
|
||||
{
|
||||
if (legacyName != Entity.Name)
|
||||
{
|
||||
EntityAlias legacyAlias = new()
|
||||
{
|
||||
Type = AliasType.LegacyEnglish,
|
||||
Alias = legacyName,
|
||||
Entity = Entity
|
||||
};
|
||||
|
||||
Context.EntityAliases.Add(legacyAlias);
|
||||
}
|
||||
|
||||
LegacyAliases.Remove(legacyId);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemasterWithoutLegacy.Add(legacyId, Entity);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
string legacyId = legacyIdArray[0].ToString();
|
||||
|
||||
if (LegacyAliases.TryGetValue(legacyId, out string? legacyName))
|
||||
{
|
||||
if (legacyName != Entity.Name)
|
||||
{
|
||||
EntityAlias legacyAlias = new()
|
||||
{
|
||||
Type = AliasType.LegacyEnglish,
|
||||
Alias = legacyName,
|
||||
Entity = Entity
|
||||
};
|
||||
|
||||
Context.EntityAliases.Add(legacyAlias);
|
||||
}
|
||||
|
||||
LegacyAliases.Remove(legacyId);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemasterWithoutLegacy.Add(legacyId, Entity);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void AddSource()
|
||||
@@ -185,6 +187,8 @@ internal abstract partial class AbstractProcessor(ProcessorInput input)
|
||||
.ToList();
|
||||
|
||||
List<Trait> traits = Context.Traits
|
||||
.Include(t => t.Entity)
|
||||
.ThenInclude(e => e.Aliases)
|
||||
.Where(t => traitEntities.Contains(t.Entity))
|
||||
.ToList();
|
||||
|
||||
@@ -202,47 +206,22 @@ internal abstract partial class AbstractProcessor(ProcessorInput input)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected IEnumerable<Trait> GetTraits(IEnumerable<string> names)
|
||||
{
|
||||
List<Trait> result = Context.Traits.Where(t => names.Contains(t.Entity.Name)).ToList();
|
||||
|
||||
foreach (string name in names)
|
||||
{
|
||||
if (result.Any(t => t.Entity.Name == name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
Trait trait = new()
|
||||
{
|
||||
Name = name,
|
||||
Slug = name,
|
||||
Type = TraitType.Regular,
|
||||
Description = "",
|
||||
};
|
||||
Context.Traits.Add(trait);
|
||||
result.Add(trait);
|
||||
*/
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void ProcessLegacy(string id, string name)
|
||||
{
|
||||
if (RemasterWithoutLegacy.TryGetValue(id, out Entity? remastered))
|
||||
{
|
||||
if (remastered.Name != name)
|
||||
if (remastered.Name == name)
|
||||
{
|
||||
EntityAlias alias = new()
|
||||
{
|
||||
Type = AliasType.LegacyEnglish,
|
||||
Alias = name,
|
||||
Entity = remastered!
|
||||
};
|
||||
Context.EntityAliases.Add(alias);
|
||||
return;
|
||||
}
|
||||
|
||||
EntityAlias alias = new()
|
||||
{
|
||||
Type = AliasType.LegacyEnglish,
|
||||
Alias = name,
|
||||
Entity = remastered!
|
||||
};
|
||||
Context.EntityAliases.Add(alias);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -52,7 +52,7 @@ internal class AonprdDataBuilder(AonprdLoader loader)
|
||||
|
||||
foreach (AonprdLoader.LoaderEntry entry in Loader.Entries(item.Attribute.Type))
|
||||
{
|
||||
bar2.Refresh(i++, $"{entry.Id}");
|
||||
bar2.Refresh(j++, $"{entry.Id}");
|
||||
|
||||
AonprdProcessorInput input = new(entry.Json);
|
||||
AbstractProcessor processor = (AbstractProcessor) item.Constructor.Invoke([input]);
|
||||
@@ -68,7 +68,7 @@ internal class AonprdDataBuilder(AonprdLoader loader)
|
||||
}
|
||||
}
|
||||
|
||||
bar2.Refresh(j, "Processor complited");
|
||||
bar2.Refresh(j, "Processor completed");
|
||||
}
|
||||
|
||||
bar1.Refresh(i, "Done!");
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
internal class AonprdEnumAttribute(string[] values) : Attribute
|
||||
{
|
||||
public readonly string[] Values = values;
|
||||
|
||||
public AonprdEnumAttribute(string value) : this([value])
|
||||
{
|
||||
}
|
||||
}
|
||||
+15
-2
@@ -4,7 +4,8 @@ namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder;
|
||||
public static class AonprdEnumResolver
|
||||
{
|
||||
private static readonly ICollection<Solver> Solvers = [
|
||||
new Solver<ActionType>(new() {
|
||||
new Solver<ActionType>(new()
|
||||
{
|
||||
{ "Single Action", ActionType.SingleAction },
|
||||
{ "Reaction or One Action", ActionType.SingleAction },
|
||||
{ "Free Action or One Action", ActionType.SingleAction },
|
||||
@@ -16,7 +17,8 @@ public static class AonprdEnumResolver
|
||||
{ "Single Action to Two Actions", ActionType.SingleToTwoActions },
|
||||
}),
|
||||
|
||||
new Solver<SourceCategory>(new() {
|
||||
new Solver<SourceCategory>(new()
|
||||
{
|
||||
{ "Rulebooks", SourceCategory.Rulebooks },
|
||||
{ "Adventure Paths", SourceCategory.AdventurePaths },
|
||||
{ "Lost Omens", SourceCategory.LostOmens },
|
||||
@@ -25,6 +27,17 @@ public static class AonprdEnumResolver
|
||||
{ "Blog Posts", SourceCategory.BlogPosts },
|
||||
{ "Society", SourceCategory.Society },
|
||||
}),
|
||||
|
||||
new Solver<AncestryVision>(new()
|
||||
{
|
||||
{ "Low-Light Vision", AncestryVision.LowLightVision },
|
||||
{ "Darkvision", AncestryVision.DarkVision },
|
||||
}),
|
||||
|
||||
new Solver<AttributeValues>(new()
|
||||
{
|
||||
{ "Consitution", AttributeValues.Constitution }
|
||||
})
|
||||
];
|
||||
|
||||
public static T Resolve<T>(string value) where T : Enum
|
||||
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
using LinqToDB;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Pf2eModel.Model;
|
||||
using Pf2eModel.Model.Enum;
|
||||
using Pf2eModel.Model.Structure;
|
||||
using Pf2eModel.Model.Structure.AncestryRelation;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors;
|
||||
|
||||
[AonprdProcessor("ancestry", ["trait", "language"])]
|
||||
internal class AncestryProcessor(ProcessorInput input) : AbstractProcessor(input)
|
||||
{
|
||||
public override EntityType Type { get; } = EntityType.Ancestry;
|
||||
|
||||
public override Ancestry Object { get; } = new Ancestry();
|
||||
|
||||
public override void Process()
|
||||
{
|
||||
string type = Input.GetRequired<string>("type");
|
||||
|
||||
if (type != "Ancestry")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
base.Process();
|
||||
|
||||
Object.Size = Input.GetRequired<JArray>("size").Select(t => Input.Enum<Size>(t.ToString())).ToArray();
|
||||
|
||||
string hp = Input.GetRequired<string>("hp_raw");
|
||||
Object.Hp = Convert.ToInt32((hp != "") ? hp : "0");
|
||||
|
||||
Object.Speed = Convert.ToInt32(Input.GetOptional<int>("speed.land"));
|
||||
|
||||
Object.Vision = Input.EnumOptional<AncestryVision>("vision", AncestryVision.Normal);
|
||||
|
||||
AddBoosts("attribute", true);
|
||||
AddBoosts("attribute_flaw", false);
|
||||
|
||||
// TODO - import languages from Foundry!
|
||||
// ProcessLanguages();
|
||||
}
|
||||
|
||||
protected void AddBoosts(string path, bool isBoost)
|
||||
{
|
||||
List<string> boosts = Input.GetOptional<JArray>(path)?.ToArray().Select(t => t.ToString()).ToList() ?? [];
|
||||
|
||||
if (boosts.Contains("Two free ability boosts"))
|
||||
{
|
||||
boosts.Remove("Two free ability boosts");
|
||||
boosts.Add("Free");
|
||||
boosts.Add("Free");
|
||||
}
|
||||
|
||||
foreach (string boost in boosts)
|
||||
{
|
||||
AncestryBoost ancestryBoost = new()
|
||||
{
|
||||
Ancestry = Object,
|
||||
Boost = isBoost,
|
||||
Value = Input.Enum<AttributeValues>(boost),
|
||||
};
|
||||
|
||||
Context.AncestryBoosts.Add(ancestryBoost);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override string GetDescription()
|
||||
=> base.GetDescription() + AddedDescription([
|
||||
"source_markdown",
|
||||
"summary_markdown",
|
||||
"trait_markdown",
|
||||
"search_markdown"
|
||||
]);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
using Pf2eModel.Model.Enum;
|
||||
using Pf2eModel.Model.Structure;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors;
|
||||
|
||||
[AonprdProcessor("language")]
|
||||
internal class LanguageProcessor(ProcessorInput input) : AbstractProcessor(input)
|
||||
{
|
||||
public override EntityType Type { get; } = EntityType.Language;
|
||||
|
||||
public override Language Object { get; } = new Language();
|
||||
|
||||
}
|
||||
+1
-1
@@ -21,7 +21,7 @@ internal class TraitProcessor(ProcessorInput input) : AbstractProcessor(input)
|
||||
|
||||
protected override void AddTraits()
|
||||
{
|
||||
// Во втором проходе
|
||||
// Необходимо пропускать
|
||||
}
|
||||
|
||||
protected override string GetDescription()
|
||||
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Pf2eModel;
|
||||
using Pf2eModel.Model;
|
||||
using Pf2eModel.Model.Base;
|
||||
using Pf2eModel.Model.Base.Source;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Pf2eDataScrapper;
|
||||
using Pf2eDataScrapper.Importers.Implementations.Aonprd;
|
||||
|
||||
Console.SetWindowSize(Console.LargestWindowWidth - 20, Console.LargestWindowHeight - 10);
|
||||
//Console.SetWindowSize(Console.LargestWindowWidth - 20, Console.LargestWindowHeight - 10);
|
||||
|
||||
EnvSettings.Load();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user