Обработчик Правил

This commit is contained in:
2025-05-07 14:06:41 +04:00
parent 8a0cdcb943
commit bf016df060
8 changed files with 144 additions and 4 deletions
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Types;
[AonprdProcessor("rules")]
internal class RuleProcessor(AonprdProcessorInput input) : AbstractEntityProcessor(input)
{
public override EntityType Type => EntityType.Rule;
public override Rule Object { get; } = new();
public override void Add() => Context.Rules.Add(Object);
public override void Process()
{
base.Process();
Object.Breadcrumbs = (Input.GetOptional<JArray>("breadcrumbs") ?? [])
.Select(token => token.ToString())
.ToArray();
}
}
@@ -13,7 +13,7 @@ using Pf2eModel.Model.Enum;
namespace Pf2eModel.Migrations
{
[DbContext(typeof(Pf2eDbContext))]
[Migration("20250506175505_1")]
[Migration("20250507075826_1")]
partial class _1
{
/// <inheritdoc />
@@ -34,7 +34,7 @@ namespace Pf2eModel.Migrations
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_fonts", new[] { "none", "heal", "harm", "any" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_sanctification", new[] { "holy", "unholy", "any" });
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", "subclass_group", "subclass", "condition", "deity", "feat", "heritage", "spell", "ritual", "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", "ritual", "language", "rule" });
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, "locale_type", new[] { "english", "legacy_english", "russian", "legacy", "hobby", "other" });
@@ -1395,6 +1395,24 @@ namespace Pf2eModel.Migrations
b.ToTable("ritual_checks", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Rule", b =>
{
b.Property<int>("Id")
.HasColumnType("integer")
.HasColumnName("id")
.HasColumnOrder(1);
b.PrimitiveCollection<string[]>("Breadcrumbs")
.IsRequired()
.HasColumnType("text[]")
.HasColumnName("breadcrumbs");
b.HasKey("Id")
.HasName("pk_rules");
b.ToTable("rules", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Spell", b =>
{
b.Property<int>("Id")
@@ -2249,6 +2267,18 @@ namespace Pf2eModel.Migrations
b.Navigation("Training");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Rule", b =>
{
b.HasOne("Pf2eModel.Model.Base.Entity", "Entity")
.WithOne()
.HasForeignKey("Pf2eModel.Model.Structure.Rule", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_rules_entities_id");
b.Navigation("Entity");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Spell", b =>
{
b.HasOne("Pf2eModel.Model.Base.Entity", "Entity")
@@ -24,7 +24,7 @@ namespace Pf2eModel.Migrations
.Annotation("Npgsql:Enum:deity_fonts", "none,heal,harm,any")
.Annotation("Npgsql:Enum:deity_sanctification", "holy,unholy,any")
.Annotation("Npgsql:Enum:entity_rarity", "common,uncommon,rare,unique")
.Annotation("Npgsql:Enum:entity_type", "unknown,trait,action,ancestry,archetype,background,backpack,campaign_feature,class,subclass_group,subclass,condition,deity,feat,heritage,spell,ritual,language")
.Annotation("Npgsql:Enum:entity_type", "unknown,trait,action,ancestry,archetype,background,backpack,campaign_feature,class,subclass_group,subclass,condition,deity,feat,heritage,spell,ritual,language,rule")
.Annotation("Npgsql:Enum:feat_action_type", "passive,action,reaction,free")
.Annotation("Npgsql:Enum:feat_category", "uncategorized,ancestry-feature,class-feature,calling,class,skill,general,ancestry,bonus,deityboon,curse,pfsboon,campaign-feature")
.Annotation("Npgsql:Enum:locale_type", "english,legacy_english,russian,legacy,hobby,other")
@@ -324,6 +324,24 @@ namespace Pf2eModel.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "rules",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false),
breadcrumbs = table.Column<string[]>(type: "text[]", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_rules", x => x.id);
table.ForeignKey(
name: "fk_rules_entities_id",
column: x => x.id,
principalTable: "entities",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "spells",
columns: table => new
@@ -1400,6 +1418,9 @@ namespace Pf2eModel.Migrations
migrationBuilder.DropTable(
name: "ritual_checks");
migrationBuilder.DropTable(
name: "rules");
migrationBuilder.DropTable(
name: "spell_areas");
@@ -31,7 +31,7 @@ namespace Pf2eModel.Migrations
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_fonts", new[] { "none", "heal", "harm", "any" });
NpgsqlModelBuilderExtensions.HasPostgresEnum(modelBuilder, "deity_sanctification", new[] { "holy", "unholy", "any" });
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", "subclass_group", "subclass", "condition", "deity", "feat", "heritage", "spell", "ritual", "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", "ritual", "language", "rule" });
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, "locale_type", new[] { "english", "legacy_english", "russian", "legacy", "hobby", "other" });
@@ -1392,6 +1392,24 @@ namespace Pf2eModel.Migrations
b.ToTable("ritual_checks", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Rule", b =>
{
b.Property<int>("Id")
.HasColumnType("integer")
.HasColumnName("id")
.HasColumnOrder(1);
b.PrimitiveCollection<string[]>("Breadcrumbs")
.IsRequired()
.HasColumnType("text[]")
.HasColumnName("breadcrumbs");
b.HasKey("Id")
.HasName("pk_rules");
b.ToTable("rules", (string)null);
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Spell", b =>
{
b.Property<int>("Id")
@@ -2246,6 +2264,18 @@ namespace Pf2eModel.Migrations
b.Navigation("Training");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Rule", b =>
{
b.HasOne("Pf2eModel.Model.Base.Entity", "Entity")
.WithOne()
.HasForeignKey("Pf2eModel.Model.Structure.Rule", "Id")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_rules_entities_id");
b.Navigation("Entity");
});
modelBuilder.Entity("Pf2eModel.Model.Structure.Spell", b =>
{
b.HasOne("Pf2eModel.Model.Base.Entity", "Entity")
+3
View File
@@ -57,4 +57,7 @@ public enum EntityType
[PgName("language")]
Language,
[PgName("rule")]
Rule,
}
+19
View File
@@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum;
namespace Pf2eModel.Model.Structure;
[EntityOfType(EntityType.Rule)]
public class Rule : IEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Column(Order = 1)]
public int Id { get; set; }
public Entity Entity { get; set; } = null!;
public string[] Breadcrumbs { get; set; } = [];
}
+2
View File
@@ -100,6 +100,8 @@ public partial class Pf2eDbContext : DbContext
public virtual DbSet<RitualCheck> RitualChecks { get; set; }
public virtual DbSet<Rule> Rules { get; set; }
public virtual DbSet<Source> Sources { get; set; }
public virtual DbSet<Spell> Spells { get; set; }
+6
View File
@@ -503,6 +503,12 @@ public partial class Pf2eDbContext
{
BindEntity(entity);
});
// Rule
modelBuilder.Entity<Rule>(entity =>
{
BindEntity(entity);
});
}
private void DefineMethods(ModelBuilder modelBuilder)