Добавление поддержки источника Foundry, добавление алиаса, обработка Action

This commit is contained in:
2025-04-15 19:16:10 +04:00
parent 414ac03f83
commit bf6d600c4b
12 changed files with 181 additions and 69 deletions
@@ -21,7 +21,6 @@ internal class CompendiumFolderCollection : List<CompendiumFolder>
/// <returns></returns>
public CompendiumFolderCollection Filter()
{
// return [.. this.FindAll(x => x.Type != CompendiumDocumentType.Actor)];
return [.. this.FindAll(x => x.Type != CompendiumDocumentType.Actor && x.Name == "Conditions")];
return [.. this.FindAll(x => x.Type != CompendiumDocumentType.Actor)];
}
}
@@ -8,7 +8,7 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder;
internal abstract class AbstractProcessor(JObject input)
{
public readonly Pf2eTestContext Context = new();
public readonly Pf2eDbContext Context = new();
public readonly JObject Input = input;
@@ -38,6 +38,34 @@ internal abstract class AbstractProcessor(JObject input)
Context.Entities.Add(Entity);
// Alias
EntityAlias alias = new()
{
Type = AliasType.English,
Alias = Entity.Name,
EntityId = Entity.Id,
Entity = Entity
};
Context.EntityAliases.Add(alias);
// Source
EntitySource source = new()
{
EntityId = Entity.Id,
Entity = Entity,
Source = GetSource(),
Suffix = GetRequired<string>("_id"),
IsRemaster = GetRequired<bool>("system.publication.remaster")
};
Context.EntitySources.Add(source);
// Traits
JToken? traits = Input.SelectToken("system.traits");
Console.WriteLine($"{Entity.Name} - Traits: {traits}");
// TODO Traits, Alias
}
@@ -57,7 +85,7 @@ internal abstract class AbstractProcessor(JObject input)
{
JToken? token = Input.SelectToken(path) ?? null;
return token is null ? default! : token.ToObject<T>() ?? default;
return (token is null || token.Type == JTokenType.Null) ? default! : token.ToObject<T>() ?? default;
}
public T EnumRequired<T>(string path) where T : Enum
@@ -94,4 +122,26 @@ internal abstract class AbstractProcessor(JObject input)
return default;
}
protected Source GetSource()
{
string name = "pf2e - Foundry module";
Source? source = Context.Sources.Where(s => s.Name == name).FirstOrDefault();
if (source != null)
{
return source;
}
source = new()
{
Name = "pf2e - Foundry module",
Url = "https://github.com/foundryvtt/pf2e"
};
Context.Sources.Add(source);
return source;
}
}
@@ -0,0 +1,32 @@
using Newtonsoft.Json.Linq;
using Pf2eDataScrapper.Model.Enum;
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder.Processors;
[Pf2eTypeProcessor("Item.action")]
internal class ActionProcessor(JObject input) : AbstractProcessor(input)
{
public override EntityType Type => EntityType.Action;
public override Model.Structure.Action Object { get; } = new();
public override void Process()
{
base.Process();
Object.Type = EnumRequired<ActionType>("system.actionType.value");
Object.Category = EnumRequired<ActionCategory>("system.category");
Object.Actions = GetOptional<int>("system.actions.value");
Object.DeathNote = GetOptional<bool>("system.deathNote");
JObject extra = new()
{
{ "selfEffect", Input.SelectToken("system.selfEffect") }
};
Object.Extra = extra.ToString(Newtonsoft.Json.Formatting.None);
Context.Actions.Add(Object);
}
}
@@ -1,6 +1,6 @@
using Newtonsoft.Json.Linq;
using Pf2eDataScrapper.Model;
using Pf2eDataScrapper.Model.Enum;
using Pf2eDataScrapper.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder.Processors;
@@ -23,8 +23,7 @@ internal class ConditionProcessor(JObject input) : AbstractProcessor(input)
{ "value", Input.SelectToken("system.value") }
};
Object.Extra = extra.ToString(Newtonsoft.Json.Formatting.Indented);
Object.Extra = extra.ToString(Newtonsoft.Json.Formatting.None);
Object.Group = EnumOptional<ConditionGroup>("system.group");
Context.Conditions.Add(Object);
-18
View File
@@ -1,18 +0,0 @@
using Pf2eDataScrapper.Model.Common;
namespace Pf2eDataScrapper.Model;
public partial class Action : IEntity
{
public int Id { get; set; }
public Entity Entity { get; set; } = null!;
// TODO ActionType
public int? Actions { get; set; }
public bool? DeathNote { get; set; }
public string? Extra { get; set; }
}
@@ -1,6 +1,4 @@
using Pf2eDataScrapper.Model.Common;
namespace Pf2eDataScrapper.Model;
namespace Pf2eDataScrapper.Model.Common;
public partial class EntitySource
{
@@ -1,4 +1,4 @@
namespace Pf2eDataScrapper.Model;
namespace Pf2eDataScrapper.Model.Common;
public partial class Source
{
@@ -0,0 +1,25 @@
using Pf2eDataScrapper.Model.Common;
using Pf2eDataScrapper.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eDataScrapper.Model.Structure;
public partial class Action : IEntity
{
[Key]
[Column("id", Order = 1)]
public int Id { get; set; }
public Entity Entity { get; set; } = null!;
public ActionType Type { get; set; }
public ActionCategory Category { get; set; }
public int? Actions { get; set; }
public bool? DeathNote { get; set; }
public string? Extra { get; set; }
}
@@ -1,15 +1,22 @@
using Pf2eDataScrapper.Model.Common;
using Pf2eDataScrapper.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eDataScrapper.Model;
namespace Pf2eDataScrapper.Model.Structure;
[Table("condition")]
public partial class Condition : IEntity
{
[Key]
[Column("id", Order = 1)]
public int Id { get; set; }
public Entity Entity { get; set; } = null!;
[Column("group", Order = 2)]
public ConditionGroup? Group { get; set; }
[Column("extra", Order = 3)]
public string? Extra { get; set; }
}
+2 -2
View File
@@ -6,7 +6,7 @@ public partial class Training
public string Key { get; set; } = null!;
public virtual ICollection<ClassTraining> ClassTrainings { get; set; } = new List<ClassTraining>();
public virtual ICollection<ClassTraining> ClassTrainings { get; set; } = [];
public virtual ICollection<Deity> Deities { get; set; } = new List<Deity>();
public virtual ICollection<Deity> Deities { get; set; } = [];
}
@@ -2,23 +2,24 @@
using Pf2eDataScrapper.Model;
using Pf2eDataScrapper.Model.Common;
using Pf2eDataScrapper.Model.Enum;
using Pf2eDataScrapper.Model.Structure;
namespace Pf2eDataScrapper;
public partial class Pf2eTestContext : DbContext
public partial class Pf2eDbContext : DbContext
{
public Pf2eTestContext()
public Pf2eDbContext()
{
}
public Pf2eTestContext(DbContextOptions<Pf2eTestContext> options)
public Pf2eDbContext(DbContextOptions<Pf2eDbContext> options)
: base(options)
{
}
#region DbSets
public virtual DbSet<Model.Action> Actions { get; set; }
public virtual DbSet<Model.Structure.Action> Actions { get; set; }
public virtual DbSet<Ancestry> Ancestries { get; set; }
@@ -110,7 +111,25 @@ public partial class Pf2eTestContext : DbContext
{
builder
.MapEnum<EntityType>("entity_type")
.MapEnum<ConditionGroup>("condition_group");
.MapEnum<EntityRarity>("entity_rarity")
.MapEnum<AliasType>("alias_type")
.MapEnum<TraitType>("trait_type")
.MapEnum<ActionType>("action_type")
.MapEnum<ActionCategory>("action_category")
.MapEnum<Size>("enum_size")
.MapEnum<AncestryVision>("ancestry_vision")
.MapEnum<CampaignFeatureCategory>("campaign_feature_category")
.MapEnum<ClassProgressionType>("class_progression_type")
.MapEnum<ConditionGroup>("condition_group")
.MapEnum<DeityCategory>("deity_category")
.MapEnum<DeityFonts>("deity_fonts")
.MapEnum<DeitySanctification>("deity_sanctification")
.MapEnum<FeatActionType>("feat_action_type")
.MapEnum<FeatCategory>("feat_category")
.MapEnum<SpellAreaType>("spell_area_type")
.MapEnum<SpellDamageCategory>("spell_damage_category")
.MapEnum<SpellDamageKinds>("spell_damage_kinds")
;
}
);
}
@@ -121,30 +140,26 @@ public partial class Pf2eTestContext : DbContext
modelBuilder
.HasPostgresEnum<EntityType>("entity_type")
.HasPostgresEnum<EntityRarity>("entity_rarity")
.HasPostgresEnum<AliasType>("alias_type")
.HasPostgresEnum<TraitType>("trait_type")
.HasPostgresEnum<ActionType>("action_type")
.HasPostgresEnum<ActionCategory>("action_category")
.HasPostgresEnum<Size>("enum_size")
.HasPostgresEnum<AncestryVision>("ancestry_vision")
.HasPostgresEnum<CampaignFeatureCategory>("campaign_feature_category")
.HasPostgresEnum<ClassProgressionType>("class_progression_type")
.HasPostgresEnum<ConditionGroup>("condition_group")
.HasPostgresEnum<DeityCategory>("deity_category")
.HasPostgresEnum<DeityFonts>("deity_fonts")
.HasPostgresEnum<DeitySanctification>("deity_sanctification")
.HasPostgresEnum<FeatActionType>("feat_action_type")
.HasPostgresEnum<FeatCategory>("feat_category")
.HasPostgresEnum<SpellAreaType>("spell_area_type")
.HasPostgresEnum<SpellDamageCategory>("spell_damage_category")
.HasPostgresEnum<SpellDamageKinds>("spell_damage_kinds")
;
modelBuilder
.HasPostgresEnum("action_category", new[] { "offensive", "defensive", "interaction", "familiar" })
.HasPostgresEnum("action_type", new[] { "action", "free", "reaction", "passive" })
.HasPostgresEnum("alias_type", new[] { "old", "english", "hobby" })
.HasPostgresEnum("ancestry_vision", new[] { "normal", "low_light_vision", "darkvision" })
.HasPostgresEnum("campaign_feature_category", new[] { "army_tactic", "army_war_action", "kingdom_activity", "kingdom_feat", "kingdom_feature" })
.HasPostgresEnum("class_progression_type", new[] { "entity", "ancestry_feat", "class_feat", "general_feat", "skill_feat", "skill_increase" })
// .HasPostgresEnum("condition_group", new[] { "senses", "abilities", "death", "attitudes", "detection" })
.HasPostgresEnum("deity_category", new[] { "deity", "pantheon", "covenant", "philosophy" })
.HasPostgresEnum("deity_fonts", new[] { "none", "heal", "harm", "any" })
.HasPostgresEnum("deity_sanctification", new[] { "holy", "unholy", "any" })
.HasPostgresEnum("entity_rarity", new[] { "common", "uncommon", "rare", "unique" })
// .HasPostgresEnum("entity_type", new[] { "action", "ancestry", "background", "backpack", "campaign_feature", "class", "condition", "deity", "feat", "heritage", "spell" })
.HasPostgresEnum("enum_size", new[] { "med", "lanuages", "system", "tiny" })
.HasPostgresEnum("feat_category", new[] { "ancestryfeature", "classfeature", "calling", "class", "skill", "general", "ancestry", "bonus", "deityboon", "curse", "pfsboon" })
.HasPostgresEnum("spell_area_type", new[] { "burst", "emanation", "cone", "line", "square", "cube", "cylinder" })
.HasPostgresEnum("spell_damage_category", new[] { "persistent", "splash" })
.HasPostgresEnum("spell_damage_kinds", new[] { "damage", "healing", "any" })
.HasPostgresEnum("trait_type", new[] { "regular", "tradition" });
modelBuilder.Entity<Entity>(entity =>
{
entity.HasKey(e => e.Id).HasName("entity_pkey");
@@ -153,7 +168,6 @@ public partial class Pf2eTestContext : DbContext
entity.Property(e => e.Id).HasColumnName("id");
entity.Property(e => e.Description).HasColumnName("description");
entity.Property(e => e.DescriptionGm).HasColumnName("description_gm");
entity.Property(e => e.Type).HasColumnName("type");
entity.Property(e => e.Img)
.HasMaxLength(150)
@@ -171,7 +185,7 @@ public partial class Pf2eTestContext : DbContext
.HasMaxLength(150)
.HasColumnName("slug");
entity.HasMany(d => d.Traits).WithMany()
entity.HasMany(d => d.Traits).WithMany(t => t.Entities)
.UsingEntity<Dictionary<string, object>>(
"EntityTrait",
r => r.HasOne<Trait>().WithMany()
@@ -261,9 +275,9 @@ public partial class Pf2eTestContext : DbContext
modelBuilder.Entity<EntitySource>(entity =>
{
entity
.HasNoKey()
.ToTable("entity_sources");
entity.HasKey(p => new { p.EntityId, p.SourceId }).HasName("entity_sources_pkey");
entity.ToTable("entity_sources");
entity.Property(e => e.EntityId).HasColumnName("entity_id");
entity.Property(e => e.IsRemaster).HasColumnName("is_remaster");
@@ -407,7 +421,7 @@ public partial class Pf2eTestContext : DbContext
modelBuilder.Entity<Model.Action>(entity =>
modelBuilder.Entity<Model.Structure.Action>(entity =>
{
entity.HasKey(e => e.Id).HasName("action_pkey");
@@ -417,11 +431,15 @@ public partial class Pf2eTestContext : DbContext
.ValueGeneratedNever()
.HasColumnName("id");
entity.HasOne(e => e.Entity).WithOne()
.HasForeignKey<Model.Action>(e => e.Id)
.HasForeignKey<Model.Structure.Action>(e => e.Id)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("action_id_fkey");
entity.Property(e => e.Actions).HasColumnName("actions");
entity.Property(e => e.DeathNote).HasColumnName("death_note");
entity.Property(e => e.Type).HasColumnName("action_type");
entity.Property(e => e.Category).HasColumnName("category");
entity.Property(e => e.Extra).HasColumnName("extra");
});
+6 -4
View File
@@ -1,14 +1,16 @@
using Pf2eDataScrapper;
using Pf2eDataScrapper.Importers.Implementations.Aonprd;
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry;
EnvSettings.Load();
AonprdImporter importer = new AonprdImporter();
/*
AonprdImporter importer = new();
importer.Prepare();
importer.BuildSchemas();
*/
/*
var importer = new Pf2EFoundryImporter();
Pf2EFoundryImporter importer = new();
importer.Prepare();
importer.Import();
*/