Работа с подклассами

This commit is contained in:
2025-04-25 17:06:10 +04:00
parent a66aa834bd
commit 311a14a39d
15 changed files with 1708 additions and 1601 deletions
@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pf2eModel;
using Pf2eModel.Model;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Common.I18n;
using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors;
internal abstract class AbstractSubclassProcessor(AonprdProcessorInput input)
: AbstractProcessor(input)
{
public override EntityType Type => EntityType.Subclass;
public abstract override Subclass Object { get; }
public abstract string? ClassName { get; }
public abstract string GroupName { get; }
protected override void Add() => Context.Subclasses.Add(Object);
public override void Process()
{
base.Process();
Object.Group = GetGroup();
}
public abstract void ProcessObject();
public SubclassGroup GetGroup()
{
SubclassGroup? group = Context.SubclassGroups.FirstOrDefault(g =>
Pf2eDbContext.LocaleSearch(g.Entity.Name, GroupName)
);
if (group is null)
{
Class? cl =
(ClassName is not null)
? Context.Classes.FirstOrDefault(c =>
Pf2eDbContext.LocaleSearch(c.Entity.Name, GroupName)
)
: null;
Entity groupEntity = new()
{
Id = Helper.NextEntityId,
Type = EntityType.SubclassGroup,
Img = "",
Description = "",
Rarity = EntityRarity.Common,
IsTranslated = false,
IsChecked = false,
};
groupEntity.Name[LocaleType.English] = GroupName;
groupEntity.Slug = Helper.GenerateSlug(GroupName);
Context.Entities.Add(groupEntity);
/*
Entity.Id = Helper.NextEntityId;
Entity.Type = Type;
Entity.Name[LocaleType.English] = Input.GetRequired<string>("name");
Entity.Img = "";
Entity.Description = GetDescription();
Entity.Rarity = Input.EnumOptional<EntityRarity>("rarity", EntityRarity.Common);
Entity.Slug = Helper.GenerateSlug(Entity.Name[LocaleType.English]);
Entity.IsTranslated = false;
Entity.IsChecked = false;
*/
group = new SubclassGroup() { Entity = groupEntity, Class = cl };
Context.SubclassGroups.Add(group);
}
return group;
}
}
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pf2eModel.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Subclasses;
[AonprdProcessor("apparition", ["class"])]
internal class ApparitionProcessor(AonprdProcessorInput input) : AbstractSubclassProcessor(input)
{
public override Subclass Object { get; } = new();
public override string? ClassName => "Animist";
public override string GroupName => "Apparition";
public override void ProcessObject() { }
protected override string GetDescription() =>
base.GetDescription()
+ AddedDescription(["skill_markdown", "spell_markdown", "summary_markdown"]);
}
@@ -5,7 +5,7 @@ using Pf2eModel.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Types; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Types;
[AonprdProcessor("feat", ["trait", "source", "archetype"])] // [AonprdProcessor("feat", ["trait", "source", "archetype"])]
internal class FeatProcessor(AonprdProcessorInput input) : AbstractProcessor(input) internal class FeatProcessor(AonprdProcessorInput input) : AbstractProcessor(input)
{ {
public override EntityType Type => EntityType.Feat; public override EntityType Type => EntityType.Feat;
-3
View File
@@ -32,7 +32,4 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Importers\Implementations\Aonprd\DataBuilder\Processors\Subclasses\" />
</ItemGroup>
</Project> </Project>
+2 -2
View File
@@ -11,5 +11,5 @@ Pf2EFoundryImporter importer = new();
AonprdImporter importer = new(); AonprdImporter importer = new();
importer.Prepare(); importer.Prepare();
// importer.Import(); importer.Import();
importer.BuildSchemas(); // importer.BuildSchemas();
File diff suppressed because it is too large Load Diff
@@ -13,7 +13,7 @@ using Pf2eModel.Model.Enum;
namespace Pf2eModel.Migrations namespace Pf2eModel.Migrations
{ {
[DbContext(typeof(Pf2eDbContext))] [DbContext(typeof(Pf2eDbContext))]
[Migration("20250424112427_1")] [Migration("20250425111349_1")]
partial class _1 partial class _1
{ {
/// <inheritdoc /> /// <inheritdoc />
@@ -33,7 +33,7 @@ namespace Pf2eModel.Migrations
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_fonts", new[] { "none", "heal", "harm", "any" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_fonts", new[] { "none", "heal", "harm", "any" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_sanctification", new[] { "holy", "unholy", "any" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_sanctification", new[] { "holy", "unholy", "any" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "entity_rarity", new[] { "common", "uncommon", "rare", "unique" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "entity_rarity", new[] { "common", "uncommon", "rare", "unique" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "entity_type", new[] { "unknown", "trait", "action", "ancestry", "archetype", "background", "backpack", "campaign_feature", "class", "condition", "deity", "feat", "heritage", "spell", "language" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "entity_type", new[] { "unknown", "trait", "action", "ancestry", "archetype", "background", "backpack", "campaign_feature", "class", "subclass_group", "subclass", "condition", "deity", "feat", "heritage", "spell", "language" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "feat_action_type", new[] { "passive", "action", "reaction", "free" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "feat_action_type", new[] { "passive", "action", "reaction", "free" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "feat_category", new[] { "uncategorized", "ancestry-feature", "class-feature", "calling", "class", "skill", "general", "ancestry", "bonus", "deityboon", "curse", "pfsboon", "campaign-feature" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "feat_category", new[] { "uncategorized", "ancestry-feature", "class-feature", "calling", "class", "skill", "general", "ancestry", "bonus", "deityboon", "curse", "pfsboon", "campaign-feature" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "locale_type", new[] { "english", "legacy_english", "russian", "legacy", "hobby", "other" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "locale_type", new[] { "english", "legacy_english", "russian", "legacy", "hobby", "other" });
@@ -1441,6 +1441,59 @@ namespace Pf2eModel.Migrations
b.ToTable("spell_rituals", (string)null); b.ToTable("spell_rituals", (string)null);
}); });
modelBuilder.Entity("Pf2eModel.Model.Structure.Subclass", b =>
{
b.Property<int>("Id")
.HasColumnType("integer")
.HasColumnName("id")
.HasColumnOrder(1);
b.Property<string>("Additional")
.IsRequired()
.HasColumnType("jsonb")
.HasColumnName("additional")
.HasColumnOrder(3);
b.Property<string>("Extra")
.IsRequired()
.HasColumnType("text")
.HasColumnName("extra");
b.Property<int>("GroupId")
.HasColumnType("integer")
.HasColumnName("group_id")
.HasColumnOrder(2);
b.HasKey("Id")
.HasName("pk_subclasses");
b.HasIndex("GroupId")
.HasDatabaseName("ix_subclasses_group_id");
b.ToTable("subclasses", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Structure.SubclassGroup", b =>
{
b.Property<int>("Id")
.HasColumnType("integer")
.HasColumnName("id")
.HasColumnOrder(1);
b.Property<int?>("ClassId")
.HasColumnType("integer")
.HasColumnName("class_id")
.HasColumnOrder(2);
b.HasKey("Id")
.HasName("pk_subclass_groups");
b.HasIndex("ClassId")
.HasDatabaseName("ix_subclass_groups_class_id");
b.ToTable("subclass_groups", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Trait", b => modelBuilder.Entity("Pf2eModel.Model.Structure.Trait", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@@ -2004,6 +2057,47 @@ namespace Pf2eModel.Migrations
b.Navigation("Spell"); b.Navigation("Spell");
}); });
modelBuilder.Entity("Pf2eModel.Model.Structure.Subclass", b =>
{
b.HasOne("Pf2eModel.Model.Structure.SubclassGroup", "Group")
.WithMany("Subclasses")
.HasForeignKey("GroupId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_subclasses_subclass_groups_group_id");
b.HasOne("Pf2eModel.Model.Base.Entity", "Entity")
.WithOne()
.HasForeignKey("Pf2eModel.Model.Structure.Subclass", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_subclasses_entities_id");
b.Navigation("Entity");
b.Navigation("Group");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.SubclassGroup", b =>
{
b.HasOne("Pf2eModel.Model.Structure.Class", "Class")
.WithMany("SubclassGroups")
.HasForeignKey("ClassId")
.OnDelete(DeleteBehavior.Cascade)
.HasConstraintName("fk_subclass_groups_classes_class_id");
b.HasOne("Pf2eModel.Model.Base.Entity", "Entity")
.WithOne()
.HasForeignKey("Pf2eModel.Model.Structure.SubclassGroup", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_subclass_groups_entities_id");
b.Navigation("Class");
b.Navigation("Entity");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Trait", b => modelBuilder.Entity("Pf2eModel.Model.Structure.Trait", b =>
{ {
b.HasOne("Pf2eModel.Model.Base.Entity", "Entity") b.HasOne("Pf2eModel.Model.Base.Entity", "Entity")
@@ -2065,6 +2159,8 @@ namespace Pf2eModel.Migrations
b.Navigation("ClassProgressions"); b.Navigation("ClassProgressions");
b.Navigation("ClassTrainings"); b.Navigation("ClassTrainings");
b.Navigation("SubclassGroups");
}); });
modelBuilder.Entity("Pf2eModel.Model.Structure.Deity", b => modelBuilder.Entity("Pf2eModel.Model.Structure.Deity", b =>
@@ -2093,6 +2189,11 @@ namespace Pf2eModel.Migrations
b.Navigation("SpellRitual"); b.Navigation("SpellRitual");
}); });
modelBuilder.Entity("Pf2eModel.Model.Structure.SubclassGroup", b =>
{
b.Navigation("Subclasses");
});
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
} }
File diff suppressed because it is too large Load Diff
@@ -30,7 +30,7 @@ namespace Pf2eModel.Migrations
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_fonts", new[] { "none", "heal", "harm", "any" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_fonts", new[] { "none", "heal", "harm", "any" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_sanctification", new[] { "holy", "unholy", "any" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_sanctification", new[] { "holy", "unholy", "any" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "entity_rarity", new[] { "common", "uncommon", "rare", "unique" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "entity_rarity", new[] { "common", "uncommon", "rare", "unique" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "entity_type", new[] { "unknown", "trait", "action", "ancestry", "archetype", "background", "backpack", "campaign_feature", "class", "condition", "deity", "feat", "heritage", "spell", "language" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "entity_type", new[] { "unknown", "trait", "action", "ancestry", "archetype", "background", "backpack", "campaign_feature", "class", "subclass_group", "subclass", "condition", "deity", "feat", "heritage", "spell", "language" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "feat_action_type", new[] { "passive", "action", "reaction", "free" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "feat_action_type", new[] { "passive", "action", "reaction", "free" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "feat_category", new[] { "uncategorized", "ancestry-feature", "class-feature", "calling", "class", "skill", "general", "ancestry", "bonus", "deityboon", "curse", "pfsboon", "campaign-feature" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "feat_category", new[] { "uncategorized", "ancestry-feature", "class-feature", "calling", "class", "skill", "general", "ancestry", "bonus", "deityboon", "curse", "pfsboon", "campaign-feature" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "locale_type", new[] { "english", "legacy_english", "russian", "legacy", "hobby", "other" }); NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "locale_type", new[] { "english", "legacy_english", "russian", "legacy", "hobby", "other" });
@@ -1438,6 +1438,59 @@ namespace Pf2eModel.Migrations
b.ToTable("spell_rituals", (string)null); b.ToTable("spell_rituals", (string)null);
}); });
modelBuilder.Entity("Pf2eModel.Model.Structure.Subclass", b =>
{
b.Property<int>("Id")
.HasColumnType("integer")
.HasColumnName("id")
.HasColumnOrder(1);
b.Property<string>("Additional")
.IsRequired()
.HasColumnType("jsonb")
.HasColumnName("additional")
.HasColumnOrder(3);
b.Property<string>("Extra")
.IsRequired()
.HasColumnType("text")
.HasColumnName("extra");
b.Property<int>("GroupId")
.HasColumnType("integer")
.HasColumnName("group_id")
.HasColumnOrder(2);
b.HasKey("Id")
.HasName("pk_subclasses");
b.HasIndex("GroupId")
.HasDatabaseName("ix_subclasses_group_id");
b.ToTable("subclasses", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Structure.SubclassGroup", b =>
{
b.Property<int>("Id")
.HasColumnType("integer")
.HasColumnName("id")
.HasColumnOrder(1);
b.Property<int?>("ClassId")
.HasColumnType("integer")
.HasColumnName("class_id")
.HasColumnOrder(2);
b.HasKey("Id")
.HasName("pk_subclass_groups");
b.HasIndex("ClassId")
.HasDatabaseName("ix_subclass_groups_class_id");
b.ToTable("subclass_groups", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Trait", b => modelBuilder.Entity("Pf2eModel.Model.Structure.Trait", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@@ -2001,6 +2054,47 @@ namespace Pf2eModel.Migrations
b.Navigation("Spell"); b.Navigation("Spell");
}); });
modelBuilder.Entity("Pf2eModel.Model.Structure.Subclass", b =>
{
b.HasOne("Pf2eModel.Model.Structure.SubclassGroup", "Group")
.WithMany("Subclasses")
.HasForeignKey("GroupId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_subclasses_subclass_groups_group_id");
b.HasOne("Pf2eModel.Model.Base.Entity", "Entity")
.WithOne()
.HasForeignKey("Pf2eModel.Model.Structure.Subclass", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_subclasses_entities_id");
b.Navigation("Entity");
b.Navigation("Group");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.SubclassGroup", b =>
{
b.HasOne("Pf2eModel.Model.Structure.Class", "Class")
.WithMany("SubclassGroups")
.HasForeignKey("ClassId")
.OnDelete(DeleteBehavior.Cascade)
.HasConstraintName("fk_subclass_groups_classes_class_id");
b.HasOne("Pf2eModel.Model.Base.Entity", "Entity")
.WithOne()
.HasForeignKey("Pf2eModel.Model.Structure.SubclassGroup", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_subclass_groups_entities_id");
b.Navigation("Class");
b.Navigation("Entity");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Trait", b => modelBuilder.Entity("Pf2eModel.Model.Structure.Trait", b =>
{ {
b.HasOne("Pf2eModel.Model.Base.Entity", "Entity") b.HasOne("Pf2eModel.Model.Base.Entity", "Entity")
@@ -2062,6 +2156,8 @@ namespace Pf2eModel.Migrations
b.Navigation("ClassProgressions"); b.Navigation("ClassProgressions");
b.Navigation("ClassTrainings"); b.Navigation("ClassTrainings");
b.Navigation("SubclassGroups");
}); });
modelBuilder.Entity("Pf2eModel.Model.Structure.Deity", b => modelBuilder.Entity("Pf2eModel.Model.Structure.Deity", b =>
@@ -2090,6 +2186,11 @@ namespace Pf2eModel.Migrations
b.Navigation("SpellRitual"); b.Navigation("SpellRitual");
}); });
modelBuilder.Entity("Pf2eModel.Model.Structure.SubclassGroup", b =>
{
b.Navigation("Subclasses");
});
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
} }
+6
View File
@@ -31,6 +31,12 @@ public enum EntityType
[PgName("class")] [PgName("class")]
Class, Class,
[PgName("subclass_group")]
SubclassGroup,
[PgName("subclass")]
Subclass,
[PgName("condition")] [PgName("condition")]
Condition, Condition,
+2
View File
@@ -35,4 +35,6 @@ public partial class Class : IEntity
public virtual ICollection<ClassProgression> ClassProgressions { get; set; } = []; public virtual ICollection<ClassProgression> ClassProgressions { get; set; } = [];
public virtual ICollection<ClassTraining> ClassTrainings { get; set; } = []; public virtual ICollection<ClassTraining> ClassTrainings { get; set; } = [];
public virtual ICollection<SubclassGroup> SubclassGroups { get; set; } = [];
} }
+6 -4
View File
@@ -2,9 +2,11 @@
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Base; using Pf2eModel.Model.Base;
using Pf2eModel.Model.Common.I18n; using Pf2eModel.Model.Common.I18n;
using Pf2eModel.Model.Enum;
namespace Pf2eModel.Model.Structure; namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.Subclass)]
public class Subclass : IEntity public class Subclass : IEntity
{ {
[Key] [Key]
@@ -14,12 +16,12 @@ public class Subclass : IEntity
public Entity Entity { get; set; } = null!; public Entity Entity { get; set; } = null!;
[Column(Order = 2)] [Column(Order = 2)]
public int? ClassId { get; set; } = null; public int GroupId { get; set; }
public Class? Class { get; set; } = null!; public SubclassGroup Group { get; set; } = null!;
[Column(Order = 3)] [Column(Order = 3)]
public LocaleString Additional { get; set; } = null!; public LocaleString Additional { get; set; } = new();
public string Extra { get; set; } = null!; public string Extra { get; set; } = "{}";
} }
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure.ClassRelation;
namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.SubclassGroup)]
public class SubclassGroup : IEntity
{
[Key]
[Column(Order = 1)]
public int Id { get; set; }
public Entity Entity { get; set; } = null!;
[Column(Order = 2)]
public int? ClassId { get; set; } = null;
public Class? Class { get; set; } = null!;
public virtual ICollection<Subclass> Subclasses { get; set; } = [];
}
+4
View File
@@ -55,6 +55,10 @@ public partial class Pf2eDbContext : DbContext
public virtual DbSet<ClassTraining> ClassTrainings { get; set; } public virtual DbSet<ClassTraining> ClassTrainings { get; set; }
public virtual DbSet<SubclassGroup> SubclassGroups { get; set; }
public virtual DbSet<Subclass> Subclasses { get; set; }
public virtual DbSet<Condition> Conditions { get; set; } public virtual DbSet<Condition> Conditions { get; set; }
public virtual DbSet<Deity> Deities { get; set; } public virtual DbSet<Deity> Deities { get; set; }
+24
View File
@@ -309,6 +309,30 @@ public partial class Pf2eDbContext
.OnDelete(DeleteBehavior.SetNull); .OnDelete(DeleteBehavior.SetNull);
}); });
// Subclass
modelBuilder.Entity<SubclassGroup>(entity =>
{
BindEntity(entity);
entity
.HasOne(g => g.Class)
.WithMany(c => c.SubclassGroups)
.HasForeignKey(g => g.ClassId)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Subclass>(entity =>
{
BindEntity(entity);
BindLocaleString(entity, s => s.Additional);
entity
.HasOne(s => s.Group)
.WithMany(g => g.Subclasses)
.HasForeignKey(s => s.GroupId)
.OnDelete(DeleteBehavior.Cascade);
});
// Condition // Condition
modelBuilder.Entity<Condition>(entity => modelBuilder.Entity<Condition>(entity =>
{ {