From cc7e97b6ff9bb3e1bbee238984a1397648445377 Mon Sep 17 00:00:00 2001 From: kozhilya Date: Thu, 24 Apr 2025 17:58:58 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=82=D1=87=D0=B8=D1=81=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Aonprd/DataBuilder/AonprdEnumResolver.cs | 73 +- .../Processors/AbstractProcessor.cs | 38 +- .../Processors/Types/ActionProcessor.cs | 33 +- .../Processors/Types/AncestryProcessor.cs | 15 +- .../Processors/Types/ArchetypeProcessor.cs | 15 +- .../Processors/Types/BackgroundProcessor.cs | 23 +- .../Processors/Types/ClassProcessor.cs | 115 +- .../Processors/Types/FeatProcessor.cs | 40 +- .../Processors/Types/SourceProcessor.cs | 10 +- .../Processors/Types/TrainingProcessor.cs | 12 +- .../Migrations/20250418062358_Function.cs | 26 +- Pf2eModel/Migrations/20250424112427_1.cs | 2726 +++++++++-------- .../Model/Common/I18n/LocaleExtension.cs | 19 +- Pf2eModel/Model/Common/I18n/LocaleString.cs | 27 +- Pf2eModel/Model/Structure/Archetype.cs | 11 +- .../ArchetypeRelation/ArchetypeFeats.cs | 7 +- Pf2eModel/Model/Structure/Language.cs | 9 +- Pf2eModel/Pf2eDbContextModel.cs | 209 +- Pf2eViewer/EntityConverter.cs | 23 +- Pf2eViewer/MainViewForm.cs | 103 +- 20 files changed, 1972 insertions(+), 1562 deletions(-) diff --git a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/AonprdEnumResolver.cs b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/AonprdEnumResolver.cs index 25422bc..a8cf14d 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/AonprdEnumResolver.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/AonprdEnumResolver.cs @@ -1,35 +1,42 @@ using Pf2eModel.Model.Enum; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder; + public static class AonprdEnumResolver { - private static readonly ICollection Solvers = [ - new Solver(new() - { - { "Rulebooks", SourceCategory.Rulebooks }, - { "Adventure Paths", SourceCategory.AdventurePaths }, - { "Lost Omens", SourceCategory.LostOmens }, - { "Adventures", SourceCategory.Adventures }, - { "Comics", SourceCategory.Comics }, - { "Blog Posts", SourceCategory.BlogPosts }, - { "Society", SourceCategory.Society }, - }), - - new Solver(new() - { - { "Low-Light Vision", AncestryVision.LowLightVision }, - { "Darkvision", AncestryVision.DarkVision }, - }), - - new Solver(new() - { - { "Consitution", AttributeValues.Constitution }, - { "Other", AttributeValues.Free }, - { "other", AttributeValues.Free }, - }) + private static readonly ICollection Solvers = + [ + new Solver( + new() + { + { "Rulebooks", SourceCategory.Rulebooks }, + { "Adventure Paths", SourceCategory.AdventurePaths }, + { "Lost Omens", SourceCategory.LostOmens }, + { "Adventures", SourceCategory.Adventures }, + { "Comics", SourceCategory.Comics }, + { "Blog Posts", SourceCategory.BlogPosts }, + { "Society", SourceCategory.Society }, + } + ), + new Solver( + new() + { + { "Low-Light Vision", AncestryVision.LowLightVision }, + { "Darkvision", AncestryVision.DarkVision }, + } + ), + new Solver( + new() + { + { "Consitution", AttributeValues.Constitution }, + { "Other", AttributeValues.Free }, + { "other", AttributeValues.Free }, + } + ), ]; - public static T Resolve(string value) where T : Enum + public static T Resolve(string value) + where T : Enum { Type type = typeof(T); @@ -40,9 +47,11 @@ public static class AonprdEnumResolver throw new EnumResolverEnumUnknownException(type); } - Solver tSolver = (Solver) solver; + Solver tSolver = (Solver)solver; - return tSolver.Data.TryGetValue(value, out T? data) ? data : throw new EnumResolverValueUnknownException(type, value); + return tSolver.Data.TryGetValue(value, out T? data) + ? data + : throw new EnumResolverValueUnknownException(type, value); } private abstract class Solver @@ -50,14 +59,16 @@ public static class AonprdEnumResolver public abstract Type Type { get; } } - private class Solver(Dictionary data) : Solver where T : Enum + private class Solver(Dictionary data) : Solver + where T : Enum { public override Type Type { get; } = typeof(T); public Dictionary Data { get; } = data; } - public class EnumResolverEnumUnknownException(Type t) : Exception($"Can't resolve type '{t.FullName}': Solver not defined"); - - public class EnumResolverValueUnknownException(Type t, string value) : Exception($"Can't resolve type '{t.FullName}': Value '{value}' is not matched"); + public class EnumResolverEnumUnknownException(Type t) + : Exception($"Can't resolve type '{t.FullName}': Solver not defined"); + public class EnumResolverValueUnknownException(Type t, string value) + : Exception($"Can't resolve type '{t.FullName}': Value '{value}' is not matched"); } diff --git a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/AbstractProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/AbstractProcessor.cs index 4b9cc6d..b746f42 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/AbstractProcessor.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/AbstractProcessor.cs @@ -1,4 +1,6 @@ -using LinqToDB.Reflection; +using System.Security.Cryptography; +using System.Text; +using System.Text.RegularExpressions; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -10,10 +12,6 @@ using Pf2eModel.Model.Base.Targets; using Pf2eModel.Model.Common.I18n; using Pf2eModel.Model.Enum; using Pf2eModel.Model.Structure; -using System.Collections.Generic; -using System.Security.Cryptography; -using System.Text; -using System.Text.RegularExpressions; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors; @@ -32,7 +30,7 @@ internal abstract partial class AbstractProcessor(AonprdProcessorInput input) public abstract IEntity Object { get; } protected abstract void Add(); - + public virtual void Process() { if (Input.GetOptional("remaster_id") is not null) @@ -57,9 +55,11 @@ internal abstract partial class AbstractProcessor(AonprdProcessorInput input) Context.SaveChanges(); } - protected string AddedDescription(string path) => $"\r\n\r\n========== [{path}] ==========\r\n\r\n{Input.GetOptional(path) ?? ""}"; + protected string AddedDescription(string path) => + $"\r\n\r\n========== [{path}] ==========\r\n\r\n{Input.GetOptional(path) ?? ""}"; - protected string AddedDescription(string[] paths) => string.Join("", paths.Select(AddedDescription)); + protected string AddedDescription(string[] paths) => + string.Join("", paths.Select(AddedDescription)); protected virtual string GetDescription() => Input.GetRequired("markdown"); @@ -130,7 +130,7 @@ internal abstract partial class AbstractProcessor(AonprdProcessorInput input) Entity = Entity, Source = source, Suffix = ((match?.Captures.Count > 0) ? match?.Captures[0]?.Value : "") ?? "", - IsRemaster = Input.GetOptional("legacy_id") is not null + IsRemaster = Input.GetOptional("legacy_id") is not null, }; Context.EntitySources.Add(entitySource); @@ -140,7 +140,9 @@ internal abstract partial class AbstractProcessor(AonprdProcessorInput input) { if (AonprdTarget is null) { - AonprdTarget = Context.ExternalTargets.FirstOrDefault(t => t.Name == AonprdImporter.SourceName); + AonprdTarget = Context.ExternalTargets.FirstOrDefault(t => + t.Name == AonprdImporter.SourceName + ); AonprdTarget ??= new() { @@ -155,7 +157,7 @@ internal abstract partial class AbstractProcessor(AonprdProcessorInput input) Entity = Entity, Target = AonprdTarget, Suffix = Input.GetRequired("url"), - Md5 = Md5(Input.Input.ToString()) + Md5 = Md5(Input.Input.ToString()), }; Context.EntityExternals.Add(external); } @@ -170,13 +172,13 @@ internal abstract partial class AbstractProcessor(AonprdProcessorInput input) } IEnumerable names = traitsJson.ToArray().Select(jToken => jToken.ToString()); - List traitEntities = Context.Traits - .Select(t => t.Entity) + List traitEntities = Context + .Traits.Select(t => t.Entity) .Where(e => Pf2eDbContext.LocaleSearchArray(e.Name, names)) .ToList(); - List traits = Context.Traits - .Include(t => t.Entity) + List traits = Context + .Traits.Include(t => t.Entity) .Where(t => traitEntities.Contains(t.Entity)) .ToList(); @@ -238,7 +240,9 @@ internal abstract partial class AbstractProcessor(AonprdProcessorInput input) [GeneratedRegex(@"^\[.*?\]\(.*?\)\s+(.*)$")] private static partial Regex SourceSuffixRegex(); - public class LegacyItemException(string name) : Exception($"Item '{name}' is linked with newer version, skipping.") { } + public class LegacyItemException(string name) + : Exception($"Item '{name}' is linked with newer version, skipping.") { } - public class SkipItemException(string name, string reason) : Exception($"Item '{name}' is skipped, reason: {reason}.") { } + public class SkipItemException(string name, string reason) + : Exception($"Item '{name}' is skipped, reason: {reason}.") { } } diff --git a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/ActionProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/ActionProcessor.cs index 7315223..1b3cabe 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/ActionProcessor.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/ActionProcessor.cs @@ -1,6 +1,4 @@ -using Newtonsoft.Json.Linq; -using Pf2eModel.Model; -using Pf2eModel.Model.Enum; +using Pf2eModel.Model.Enum; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Types; @@ -17,25 +15,30 @@ internal class ActionProcessor(AonprdProcessorInput input) : AbstractProcessor(i { base.Process(); - AonprdProcessorInput.ActionStruct action = Input.ResolveActionString(Input.GetOptional("actions") ?? ""); + AonprdProcessorInput.ActionStruct action = Input.ResolveActionString( + Input.GetOptional("actions") ?? "" + ); Object.Actions = action.Actions; Object.MaxActions = action.MaxActions; Object.IsFreeAction = action.IsFreeAction; Object.IsPassive = action.IsPassive; Object.IsReaction = action.IsReaction; -; + ; Object.Extra = GenerateExtra("school"); } - protected override string GetDescription() - => base.GetDescription() + AddedDescription([ - "cost_markdown", - "trait_markdown", - "source_markdown", - "search_markdown", - "requirement_markdown", - "trigger_markdown", - "summary_markdown", - ]); + protected override string GetDescription() => + base.GetDescription() + + AddedDescription( + [ + "cost_markdown", + "trait_markdown", + "source_markdown", + "search_markdown", + "requirement_markdown", + "trigger_markdown", + "summary_markdown", + ] + ); } diff --git a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/AncestryProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/AncestryProcessor.cs index 554fd0d..01651ff 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/AncestryProcessor.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/AncestryProcessor.cs @@ -1,10 +1,8 @@ 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.Types; @@ -28,8 +26,11 @@ internal class AncestryProcessor(AonprdProcessorInput input) : AbstractProcessor base.Process(); - Object.Size = Input.GetRequired("size").Select(t => Input.Enum(t.ToString())).ToArray(); - + Object.Size = Input + .GetRequired("size") + .Select(t => Input.Enum(t.ToString())) + .ToArray(); + string hp = Input.GetRequired("hp_raw"); Object.Hp = Convert.ToInt32((hp != "") ? hp : "0"); @@ -46,7 +47,8 @@ internal class AncestryProcessor(AonprdProcessorInput input) : AbstractProcessor protected void AddBoosts(string path, bool isBoost) { - List boosts = Input.GetOptional(path)?.ToArray().Select(t => t.ToString()).ToList() ?? []; + List boosts = + Input.GetOptional(path)?.ToArray().Select(t => t.ToString()).ToList() ?? []; if (boosts.Contains("Two free ability boosts")) { @@ -67,5 +69,4 @@ internal class AncestryProcessor(AonprdProcessorInput input) : AbstractProcessor Context.AncestryBoosts.Add(ancestryBoost); } } - -} \ No newline at end of file +} diff --git a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/ArchetypeProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/ArchetypeProcessor.cs index 9a4c09f..8166620 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/ArchetypeProcessor.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/ArchetypeProcessor.cs @@ -1,10 +1,5 @@ using Pf2eModel.Model.Enum; using Pf2eModel.Model.Structure; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Types; @@ -22,13 +17,9 @@ internal class ArchetypeProcessor(AonprdProcessorInput input) : AbstractProcesso base.Process(); Object.Level = Input.GetOptional("level"); - } - protected override string GetDescription() - => base.GetDescription() + AddedDescription([ - "prerequisite_markdown", - "requirement_markdown", - "summary_markdown" - ]); + protected override string GetDescription() => + base.GetDescription() + + AddedDescription(["prerequisite_markdown", "requirement_markdown", "summary_markdown"]); } diff --git a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/BackgroundProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/BackgroundProcessor.cs index 63640ee..b14b78c 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/BackgroundProcessor.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/BackgroundProcessor.cs @@ -1,13 +1,7 @@ using Newtonsoft.Json.Linq; -using Pf2eModel.Model; using Pf2eModel.Model.Enum; using Pf2eModel.Model.Structure; using Pf2eModel.Model.Structure.BackgroundRelation; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Types; @@ -29,22 +23,17 @@ internal class BackgroundProcessor(AonprdProcessorInput input) : AbstractProcess BackgroundBoost boost = new() { Background = Object, - Attribute = Input.Enum(token.ToString()) + Attribute = Input.Enum(token.ToString()), }; Object.BackgroundBoosts.Add(boost); Context.BackgroundBoosts.Add(boost); } - } - - protected override string GetDescription() - => base.GetDescription() + AddedDescription([ - "feat_markdown", - "summary_markdown", - "skill_markdown", - "prerequisite_markdown", - ]); + protected override string GetDescription() => + base.GetDescription() + + AddedDescription( + ["feat_markdown", "summary_markdown", "skill_markdown", "prerequisite_markdown"] + ); } - diff --git a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/ClassProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/ClassProcessor.cs index d271e3b..2b20449 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/ClassProcessor.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/ClassProcessor.cs @@ -1,18 +1,11 @@ -using LinqToDB; +using System.Text.RegularExpressions; +using LinqToDB; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Options; using Newtonsoft.Json.Linq; -using Pf2eModel.Model; using Pf2eModel.Model.Common; using Pf2eModel.Model.Enum; using Pf2eModel.Model.Structure; using Pf2eModel.Model.Structure.ClassRelation; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Types; @@ -28,10 +21,11 @@ internal class ClassProcessor(AonprdProcessorInput input) : AbstractProcessor(in public override void Process() { base.Process(); - + Object.Hp = Convert.ToInt32(Input.GetRequired("hp_raw")); - AttributeValues[] attributes = Input.GetRequired("attribute") + AttributeValues[] attributes = Input + .GetRequired("attribute") .Select(token => Input.Enum(token.ToString())) .ToArray(); @@ -39,18 +33,24 @@ internal class ClassProcessor(AonprdProcessorInput input) : AbstractProcessor(in { ClassKeyAbility classKeyAbility = new ClassKeyAbility() { - Class = Object, - Value = attribute + Class = Object, + Value = attribute, }; Context.ClassKeyAbilities.Add(classKeyAbility); Object.ClassKeyAbilities.Add(classKeyAbility); } - + ClassTraining[] classTrainings = [ - .. ProcessTraining(Input.GetRequired("attack_proficiency"), TrainingType.Weapon), - .. ProcessTraining(Input.GetRequired("defense_proficiency"), TrainingType.Armor), + .. ProcessTraining( + Input.GetRequired("attack_proficiency"), + TrainingType.Weapon + ), + .. ProcessTraining( + Input.GetRequired("defense_proficiency"), + TrainingType.Armor + ), .. GetSkillTrainings(), .. GetSaveTrainings(), ]; @@ -84,19 +84,22 @@ internal class ClassProcessor(AonprdProcessorInput input) : AbstractProcessor(in protected ICollection GetSkillTrainings() { - string[] skillNames = Input.GetRequired("skill_proficiency") + string[] skillNames = Input + .GetRequired("skill_proficiency") .Select(token => token.ToString()) .ToArray(); Training[] skills = Context.Trainings.Where(t => skillNames.Contains(t.Name)).ToArray(); // Training[] skills = Context.Trainings.Where(t => Pf2eDbContext.LocaleSearchArray(t.Name, skillNames)).ToArray(); - return skills.Select(skill => new ClassTraining() - { - Class = Object, - Training = skill, - Stage = TrainingStage.Trained, - }).ToArray(); + return skills + .Select(skill => new ClassTraining() + { + Class = Object, + Training = skill, + Stage = TrainingStage.Trained, + }) + .ToArray(); } protected ICollection ProcessTraining(JArray array, TrainingType type) @@ -119,16 +122,13 @@ internal class ClassProcessor(AonprdProcessorInput input) : AbstractProcessor(in foreach (string part in parts) { - Training? training = Context.Trainings - .FirstOrDefault(t => t.Name == part && t.Type == type); + Training? training = Context.Trainings.FirstOrDefault(t => + t.Name == part && t.Type == type + ); if (training == null) { - training = new Training() - { - Name = part, - Type = type, - }; + training = new Training() { Name = part, Type = type }; Context.Trainings.Add(training); } @@ -137,7 +137,7 @@ internal class ClassProcessor(AonprdProcessorInput input) : AbstractProcessor(in { Class = Object, Training = training, - Stage = stage + Stage = stage, }; trainings.Add(classTraining); @@ -149,27 +149,20 @@ internal class ClassProcessor(AonprdProcessorInput input) : AbstractProcessor(in protected string[] GetTrainingString(string value) { - if (value.StartsWith("favored weapon of your deity")) - { - return ["Favored weapon of your deity"]; - } - - if (value == "simple and martial weapons") - { - return ["Simple weapon", "Martial weapon"]; - } - - return Regex.Split(value, @"\s*(?:,|and)\s*") - .Where(s => s != "") - .Select(s => string.Concat(s[0].ToString().ToUpper(), s.AsSpan(1))) - .ToArray(); - ; + return value.StartsWith("favored weapon of your deity") ? ["Favored weapon of your deity"] + : value == "simple and martial weapons" ? ["Simple weapon", "Martial weapon"] + : Regex + .Split(value, @"\s*(?:,|and)\s*") + .Where(s => s != "") + .Select(s => string.Concat(s[0].ToString().ToUpper(), s.AsSpan(1))) + .ToArray(); + ; } protected ICollection GetSaveTrainings() { - Dictionary result = Context.Trainings - .Where(t => t.Type == TrainingType.Save) + Dictionary result = Context + .Trainings.Where(t => t.Type == TrainingType.Save) .ToDictionary(t => t.Name); foreach (string name in new[] { "Will", "Fortitude", "Reflex", "Perception" }) @@ -179,23 +172,29 @@ internal class ClassProcessor(AonprdProcessorInput input) : AbstractProcessor(in continue; } - Training training = new() { Name = name, Type = (name == "Perception") ? TrainingType.Perception : TrainingType.Save }; + Training training = new() + { + Name = name, + Type = (name == "Perception") ? TrainingType.Perception : TrainingType.Save, + }; result.Add(name, training); Context.Trainings.Add(training); } - return result.Select(pair => - { - ClassTraining classTraining = new() + return result + .Select(pair => { - Class = Object, - Training = pair.Value, - Stage = Input.EnumRequired($"{pair.Key.ToLower()}_proficiency"), - }; + ClassTraining classTraining = new() + { + Class = Object, + Training = pair.Value, + Stage = Input.EnumRequired($"{pair.Key.ToLower()}_proficiency"), + }; - return classTraining; - }).ToList(); + return classTraining; + }) + .ToList(); } protected void ProcessDependecies() diff --git a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/FeatProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/FeatProcessor.cs index 91310af..f1ddb3e 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/FeatProcessor.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/FeatProcessor.cs @@ -20,11 +20,13 @@ internal class FeatProcessor(AonprdProcessorInput input) : AbstractProcessor(inp Object.Level = Input.GetRequired("level"); - Object.Category = (Entity.Traits.Any(t => t.Type == TraitType.Class)) - ? ActionCategory.ClassFeat + Object.Category = Entity.Traits.Any(t => t.Type == TraitType.Class) + ? ActionCategory.ClassFeat : ActionCategory.Unknown; - AonprdProcessorInput.ActionStruct action = Input.ResolveActionString(Input.GetOptional("actions") ?? ""); + AonprdProcessorInput.ActionStruct action = Input.ResolveActionString( + Input.GetOptional("actions") ?? "" + ); Object.Actions = action.Actions; Object.MaxActions = action.MaxActions; Object.IsFreeAction = action.IsFreeAction; @@ -39,12 +41,13 @@ internal class FeatProcessor(AonprdProcessorInput input) : AbstractProcessor(inp "heighten_level", "school", "frequency" - ); + ); - string[] archetypeStrings = Input.GetOptional("archetype")?.Select(t => t.ToString()).ToArray() ?? []; + string[] archetypeStrings = + Input.GetOptional("archetype")?.Select(t => t.ToString()).ToArray() ?? []; - var archetypes = Context.Archetypes - .Where(a => Pf2eDbContext.LocaleSearchArray(a.Entity.Name, archetypeStrings)) + Archetype[] archetypes = Context + .Archetypes.Where(a => Pf2eDbContext.LocaleSearchArray(a.Entity.Name, archetypeStrings)) // .Where(a => archetypeStrings.Contains(a.Entity.Name.ToString())) .ToArray(); @@ -53,7 +56,7 @@ internal class FeatProcessor(AonprdProcessorInput input) : AbstractProcessor(inp Object.Category = ActionCategory.Archetype; } - foreach (var archetype in archetypes) + foreach (Archetype? archetype in archetypes) { Object.Archetypes.Add(archetype); @@ -64,13 +67,16 @@ internal class FeatProcessor(AonprdProcessorInput input) : AbstractProcessor(inp } } - protected override string GetDescription() - => base.GetDescription() + AddedDescription([ - "cost_markdown", - "feat_markdown", - "summary_markdown", - "prerequisite_markdown", - "requirement_markdown", - "trigger_markdown" - ]); + protected override string GetDescription() => + base.GetDescription() + + AddedDescription( + [ + "cost_markdown", + "feat_markdown", + "summary_markdown", + "prerequisite_markdown", + "requirement_markdown", + "trigger_markdown", + ] + ); } diff --git a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/SourceProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/SourceProcessor.cs index 9493f16..8c16078 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/SourceProcessor.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/SourceProcessor.cs @@ -1,12 +1,6 @@ -using Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder; -using Pf2eModel.Model; +using Pf2eModel.Model; using Pf2eModel.Model.Base.Source; using Pf2eModel.Model.Enum; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Types; @@ -15,7 +9,7 @@ internal class SourceProcessor(AonprdProcessorInput input) : AbstractProcessor(i { public override EntityType Type => EntityType.Unknown; - public override IEntity Object => null; + public override IEntity? Object => null; protected override void Add() { } diff --git a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/TrainingProcessor.cs b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/TrainingProcessor.cs index fae7d7b..eca7c59 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/TrainingProcessor.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Aonprd/DataBuilder/Processors/Types/TrainingProcessor.cs @@ -1,12 +1,6 @@ -using Pf2eModel.Model.Base.Source; -using Pf2eModel.Model.Enum; -using Pf2eModel.Model; +using Pf2eModel.Model; using Pf2eModel.Model.Common; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Pf2eModel.Model.Enum; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Types; @@ -15,7 +9,7 @@ internal class TrainingProcessor(AonprdProcessorInput input) : AbstractProcessor { public override EntityType Type => EntityType.Unknown; - public override IEntity Object => null; + public override IEntity? Object => null; protected override void Add() { } diff --git a/Pf2eModel/Migrations/20250418062358_Function.cs b/Pf2eModel/Migrations/20250418062358_Function.cs index f5a7f8c..d735d1d 100644 --- a/Pf2eModel/Migrations/20250418062358_Function.cs +++ b/Pf2eModel/Migrations/20250418062358_Function.cs @@ -1,8 +1,4 @@ using Microsoft.EntityFrameworkCore.Migrations; -using Pf2eModel.Model.Structure; -using static LinqToDB.Common.Configuration; -using static System.Runtime.InteropServices.JavaScript.JSType; -using System.Buffers; #nullable disable @@ -14,7 +10,8 @@ public partial class Function : Migration /// protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.Sql(""" + migrationBuilder.Sql( + """ CREATE OR REPLACE FUNCTION f_truncate_tables() RETURNS void LANGUAGE plpgsql AS @@ -30,8 +27,10 @@ BEGIN ); END $func$; -"""); - migrationBuilder.Sql(""" +""" + ); + migrationBuilder.Sql( + """ CREATE OR REPLACE FUNCTION f_drop_tables() RETURNS void LANGUAGE plpgsql AS @@ -46,8 +45,10 @@ BEGIN ); END $func$; -"""); - migrationBuilder.Sql(""" +""" + ); + migrationBuilder.Sql( + """ CREATE OR REPLACE FUNCTION f_permission_tables(_username text) RETURNS void LANGUAGE plpgsql AS @@ -68,7 +69,8 @@ $func$; """ ); - migrationBuilder.Sql(""" + migrationBuilder.Sql( + """ CREATE OR REPLACE FUNCTION locale_search(data jsonb, search_value text) RETURNS boolean LANGUAGE plpgsql AS @@ -80,7 +82,8 @@ $func$; """ ); - migrationBuilder.Sql(""" + migrationBuilder.Sql( + """ CREATE OR REPLACE FUNCTION locale_search_array(data jsonb, search_values text[]) RETURNS boolean LANGUAGE plpgsql AS @@ -95,7 +98,6 @@ END; $func$; """ ); - } /// diff --git a/Pf2eModel/Migrations/20250424112427_1.cs b/Pf2eModel/Migrations/20250424112427_1.cs index 9ace4b0..8d7ec08 100644 --- a/Pf2eModel/Migrations/20250424112427_1.cs +++ b/Pf2eModel/Migrations/20250424112427_1.cs @@ -1,1252 +1,1588 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Pf2eModel.Model.Enum; #nullable disable -namespace Pf2eModel.Migrations +namespace Pf2eModel.Migrations; + +/// +public partial class _1 : Migration { /// - public partial class _1 : Migration + protected override void Up(MigrationBuilder migrationBuilder) { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterDatabase() - .Annotation("Npgsql:Enum:action_category", "unknown,archetype,class-feature,class-feat,offensive,defensive,interaction,familiar,army_tactic,army_war_action,kingdom_activity,kingdom_feat,kingdom_feature") - .Annotation("Npgsql:Enum:ancestry_vision", "normal,low-light-vision,dark-vision") - .Annotation("Npgsql:Enum:attribute_values", "free,str,dex,con,int,wis,cha") - .Annotation("Npgsql:Enum:class_progression_type", "entity,ancestry_feat,class_feat,general_feat,skill_feat,skill_increase") - .Annotation("Npgsql:Enum:condition_group", "unknown,senses,abilities,death,attitudes,detection") - .Annotation("Npgsql:Enum:deity_category", "deity,pantheon,covenant,philosophy") - .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,condition,deity,feat,heritage,spell,language") - .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") - .Annotation("Npgsql:Enum:size", "tiny,small,medium,large") - .Annotation("Npgsql:Enum:source_category", "rulebook,adventure-path,lost-omens,adventures,comics,blog-posts,society") - .Annotation("Npgsql:Enum:spell_area_type", "burst,emanation,cone,line,square,cube,cylinder") - .Annotation("Npgsql:Enum:spell_damage_category", "persistent,splash") - .Annotation("Npgsql:Enum:spell_damage_kinds", "damage,healing,any") - .Annotation("Npgsql:Enum:training_stage", "untrained,trained,expert,master,legendary") - .Annotation("Npgsql:Enum:trait_type", "regular,class,tradition"); - - migrationBuilder.CreateTable( - name: "entities", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - name = table.Column(type: "jsonb", nullable: false, comment: "Отображаемое имя"), - type = table.Column(type: "entity_type", nullable: false, comment: "Тип объекта"), - slug = table.Column(type: "character varying(255)", maxLength: 255, nullable: false, comment: "Часть имени в URL"), - img = table.Column(type: "character varying(255)", maxLength: 255, nullable: false, comment: "Изображение объекта"), - description = table.Column(type: "text", nullable: false, comment: "Текстовое описание объекта"), - rarity = table.Column(type: "entity_rarity", nullable: false), - is_translated = table.Column(type: "boolean", nullable: true, comment: "Флаг, указывающий, что у объекта существует перевод"), - is_checked = table.Column(type: "boolean", nullable: true, comment: "Флаг, указывающий, что объект был проверен и не требует автоматической перезаписи") - }, - constraints: table => - { - table.PrimaryKey("pk_entities", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "external_targets", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - name = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - icon = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - prefix = table.Column(type: "character varying(255)", maxLength: 255, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_external_targets", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "frequencies", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - max = table.Column(type: "integer", nullable: false), - per = table.Column(type: "integer", nullable: false), - value = table.Column(type: "integer", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_frequencies", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "keywords", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - slug = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_keywords", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "sources", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - name = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - category = table.Column(type: "source_category", nullable: false), - release_date = table.Column(type: "date", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_sources", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "trainings", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - name = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - type = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_trainings", x => x.id); - }); - - migrationBuilder.CreateTable( - name: "actions", - columns: table => new - { - id = table.Column(type: "integer", nullable: false), - actions = table.Column(type: "integer", nullable: true), - max_actions = table.Column(type: "integer", nullable: true), - is_reaction = table.Column(type: "boolean", nullable: false), - is_free_action = table.Column(type: "boolean", nullable: false), - is_passive = table.Column(type: "boolean", nullable: false), - extra = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_actions", x => x.id); - table.ForeignKey( - name: "fk_actions_entities_id", - column: x => x.id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "ancestries", - columns: table => new - { - id = table.Column(type: "integer", nullable: false), - size = table.Column(type: "size[]", nullable: false), - hp = table.Column(type: "integer", nullable: false), - speed = table.Column(type: "integer", nullable: false), - vision = table.Column(type: "ancestry_vision", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_ancestries", x => x.id); - table.ForeignKey( - name: "fk_ancestries_entities_id", - column: x => x.id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "backgrounds", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_backgrounds", x => x.id); - table.ForeignKey( - name: "fk_backgrounds_entities_id", - column: x => x.id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "classes", - columns: table => new - { - id = table.Column(type: "integer", nullable: false), - hp = table.Column(type: "integer", nullable: false), - perception = table.Column(type: "integer", nullable: false), - spellcasting = table.Column(type: "boolean", nullable: false), - tradition = table.Column(type: "integer", nullable: false), - additional_trained_skills = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_classes", x => x.id); - table.ForeignKey( - name: "fk_classes_entities_id", - column: x => x.id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "conditions", - columns: table => new - { - id = table.Column(type: "integer", nullable: false), - group = table.Column(type: "condition_group", nullable: true), - extra = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_conditions", x => x.id); - table.ForeignKey( - name: "fk_conditions_entities_id", - column: x => x.id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "deities", - columns: table => new - { - id = table.Column(type: "integer", nullable: false), - category = table.Column(type: "deity_category", nullable: false), - fonts = table.Column(type: "deity_fonts", nullable: false), - sanctification = table.Column(type: "deity_sanctification", nullable: false), - sanctification_must = table.Column(type: "boolean", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_deities", x => x.id); - table.ForeignKey( - name: "fk_deities_entities_id", - column: x => x.id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "feats", - columns: table => new - { - id = table.Column(type: "integer", nullable: false), - category = table.Column(type: "action_category", nullable: false), - level = table.Column(type: "integer", nullable: false), - actions = table.Column(type: "integer", nullable: true), - max_actions = table.Column(type: "integer", nullable: true), - is_reaction = table.Column(type: "boolean", nullable: false), - is_free_action = table.Column(type: "boolean", nullable: false), - is_passive = table.Column(type: "boolean", nullable: false), - extra = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_feats", x => x.id); - table.ForeignKey( - name: "fk_feats_entities_id", - column: x => x.id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "languages", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - entity_id = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_languages", x => x.id); - table.ForeignKey( - name: "fk_languages_entities_entity_id", - column: x => x.entity_id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "spells", - columns: table => new - { - id = table.Column(type: "integer", nullable: false), - level = table.Column(type: "integer", nullable: false), - cost = table.Column(type: "integer", nullable: false), - counteraction = table.Column(type: "boolean", nullable: false), - sustained = table.Column(type: "boolean", nullable: false), - duration = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - range = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - requirements = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - target = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - time = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - can_heightening = table.Column(type: "boolean", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_spells", x => x.id); - table.ForeignKey( - name: "fk_spells_entities_id", - column: x => x.id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "traits", - columns: table => new - { - id = table.Column(type: "integer", nullable: false), - type = table.Column(type: "trait_type", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_traits", x => x.id); - table.ForeignKey( - name: "fk_traits_entities_id", - column: x => x.id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "entity_externals", - columns: table => new - { - entity_id = table.Column(type: "integer", nullable: false), - target_id = table.Column(type: "integer", nullable: false), - suffix = table.Column(type: "character varying(255)", maxLength: 255, nullable: false, comment: "Часть URL до объекта. Для источников Foundry - полный UUID объекта"), - md5 = table.Column(type: "character varying(32)", maxLength: 32, nullable: false, comment: "Контроль версии объекта") - }, - constraints: table => - { - table.PrimaryKey("pk_entity_externals", x => new { x.entity_id, x.target_id }); - table.ForeignKey( - name: "fk_entity_externals_entities_entity_id", - column: x => x.entity_id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_entity_externals_external_targets_target_id", - column: x => x.target_id, - principalTable: "external_targets", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "entity_keyword", - columns: table => new - { - entities_id = table.Column(type: "integer", nullable: false), - keywords_id = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_entity_keyword", x => new { x.entities_id, x.keywords_id }); - table.ForeignKey( - name: "fk_entity_keyword_entities_entities_id", - column: x => x.entities_id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_entity_keyword_keywords_keywords_id", - column: x => x.keywords_id, - principalTable: "keywords", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "keyword_aliases", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - keyword_id = table.Column(type: "integer", nullable: false), - value = table.Column(type: "character varying(255)", maxLength: 255, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_keyword_aliases", x => x.id); - table.ForeignKey( - name: "fk_keyword_aliases_keywords_keyword_id", - column: x => x.keyword_id, - principalTable: "keywords", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "entity_sources", - columns: table => new - { - entity_id = table.Column(type: "integer", nullable: false), - source_id = table.Column(type: "integer", nullable: false), - suffix = table.Column(type: "character varying(255)", maxLength: 255, nullable: false, comment: "Номер страницы, эррата и т.д."), - is_remaster = table.Column(type: "boolean", nullable: false, comment: "Флаг, указывающий, что объект является частью ремастера") - }, - constraints: table => - { - table.PrimaryKey("pk_entity_sources", x => new { x.entity_id, x.source_id }); - table.ForeignKey( - name: "fk_entity_sources_entities_entity_id", - column: x => x.entity_id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_entity_sources_sources_source_id", - column: x => x.source_id, - principalTable: "sources", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "ancestry_boosts", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - ancestry_id = table.Column(type: "integer", nullable: false), - boost = table.Column(type: "boolean", nullable: false), - value = table.Column(type: "attribute_values", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_ancestry_boosts", x => x.id); - table.ForeignKey( - name: "fk_ancestry_boosts_ancestries_ancestry_id", - column: x => x.ancestry_id, - principalTable: "ancestries", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "ancestry_items", - columns: table => new - { - ancestry_id = table.Column(type: "integer", nullable: false), - item_id = table.Column(type: "integer", nullable: false), - level = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_ancestry_items", x => new { x.ancestry_id, x.item_id }); - table.ForeignKey( - name: "fk_ancestry_items_ancestries_ancestry_id", - column: x => x.ancestry_id, - principalTable: "ancestries", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_ancestry_items_entities_item_id", - column: x => x.item_id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "heritages", - columns: table => new - { - id = table.Column(type: "integer", nullable: false), - ancestry_id = table.Column(type: "integer", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_heritages", x => x.id); - table.ForeignKey( - name: "fk_heritages_ancestries_ancestry_id", - column: x => x.ancestry_id, - principalTable: "ancestries", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_heritages_entities_id", - column: x => x.id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "background_boosts", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - background_id = table.Column(type: "integer", nullable: false), - attribute = table.Column(type: "attribute_values", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_background_boosts", x => x.id); - table.ForeignKey( - name: "fk_background_boosts_backgrounds_background_id", - column: x => x.background_id, - principalTable: "backgrounds", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "background_items", - columns: table => new - { - background_id = table.Column(type: "integer", nullable: false), - entity_id = table.Column(type: "integer", nullable: false), - level = table.Column(type: "integer", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_background_items", x => new { x.background_id, x.entity_id }); - table.ForeignKey( - name: "fk_background_items_backgrounds_background_id", - column: x => x.background_id, - principalTable: "backgrounds", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_background_items_entities_entity_id", - column: x => x.entity_id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "background_skills", - columns: table => new - { - id = table.Column(type: "integer", nullable: false), - background_id = table.Column(type: "integer", nullable: false), - training_id = table.Column(type: "integer", nullable: false), - level = table.Column(type: "training_stage", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_background_skills", x => x.id); - table.ForeignKey( - name: "fk_background_skills_backgrounds_background_id", - column: x => x.background_id, - principalTable: "backgrounds", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_background_skills_trainings_training_id", - column: x => x.training_id, - principalTable: "trainings", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "class_key_abilities", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - class_id = table.Column(type: "integer", nullable: false), - value = table.Column(type: "attribute_values", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_class_key_abilities", x => x.id); - table.ForeignKey( - name: "fk_class_key_abilities_classes_class_id", - column: x => x.class_id, - principalTable: "classes", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "class_progressions", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - class_id = table.Column(type: "integer", nullable: false), - type = table.Column(type: "class_progression_type", nullable: false), - entity_id = table.Column(type: "integer", nullable: true), - level = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_class_progressions", x => x.id); - table.ForeignKey( - name: "fk_class_progressions_classes_class_id", - column: x => x.class_id, - principalTable: "classes", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_class_progressions_entities_entity_id", - column: x => x.entity_id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.SetNull); - }); - - migrationBuilder.CreateTable( - name: "class_trainings", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - class_id = table.Column(type: "integer", nullable: false), - training_id = table.Column(type: "integer", nullable: true), - name = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), - stage = table.Column(type: "training_stage", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_class_trainings", x => x.id); - table.ForeignKey( - name: "fk_class_trainings_classes_class_id", - column: x => x.class_id, - principalTable: "classes", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_class_trainings_trainings_training_id", - column: x => x.training_id, - principalTable: "trainings", - principalColumn: "id", - onDelete: ReferentialAction.SetNull); - }); - - migrationBuilder.CreateTable( - name: "deity_attributes", - columns: table => new - { - deity_id = table.Column(type: "integer", nullable: false), - attribute = table.Column(type: "attribute_values", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_deity_attributes", x => new { x.deity_id, x.attribute }); - table.ForeignKey( - name: "fk_deity_attributes_deities_deity_id", - column: x => x.deity_id, - principalTable: "deities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "deity_domains", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - deity_id = table.Column(type: "integer", nullable: false), - is_primary = table.Column(type: "boolean", nullable: false), - value = table.Column(type: "character varying(255)", maxLength: 255, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_deity_domains", x => x.id); - table.ForeignKey( - name: "fk_deity_domains_deities_deity_id", - column: x => x.deity_id, - principalTable: "deities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "deity_training", - columns: table => new - { - deity_id = table.Column(type: "integer", nullable: false), - skills_id = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_deity_training", x => new { x.deity_id, x.skills_id }); - table.ForeignKey( - name: "fk_deity_training_deities_deity_id", - column: x => x.deity_id, - principalTable: "deities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_deity_training_trainings_skills_id", - column: x => x.skills_id, - principalTable: "trainings", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "deity_weapons", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - deity_id = table.Column(type: "integer", nullable: false), - weapon = table.Column(type: "character varying(255)", maxLength: 255, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_deity_weapons", x => x.id); - table.ForeignKey( - name: "fk_deity_weapons_deities_deity_id", - column: x => x.deity_id, - principalTable: "deities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "archetypes", - columns: table => new - { - id = table.Column(type: "integer", nullable: false), - level = table.Column(type: "integer", nullable: false), - dedication_feat_id = table.Column(type: "integer", nullable: true), - extra = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("pk_archetypes", x => x.id); - table.ForeignKey( - name: "fk_archetypes_entities_id", - column: x => x.id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_archetypes_feats_dedication_feat_id", - column: x => x.dedication_feat_id, - principalTable: "feats", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "feat_prerequisites", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - feat_id = table.Column(type: "integer", nullable: false), - value = table.Column(type: "character varying(255)", maxLength: 255, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_feat_prerequisites", x => x.id); - table.ForeignKey( - name: "fk_feat_prerequisites_feats_feat_id", - column: x => x.feat_id, - principalTable: "feats", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "ancestry_languages", - columns: table => new - { - ancestry_id = table.Column(type: "integer", nullable: false), - language_id = table.Column(type: "integer", nullable: false), - is_additional = table.Column(type: "boolean", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_ancestry_languages", x => new { x.ancestry_id, x.language_id }); - table.ForeignKey( - name: "fk_ancestry_languages_ancestries_ancestry_id", - column: x => x.ancestry_id, - principalTable: "ancestries", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_ancestry_languages_languages_language_id", - column: x => x.language_id, - principalTable: "languages", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "deity_spells", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - deity_id = table.Column(type: "integer", nullable: false), - level = table.Column(type: "integer", nullable: false), - spell_id = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_deity_spells", x => x.id); - table.ForeignKey( - name: "fk_deity_spells_deities_deity_id", - column: x => x.deity_id, - principalTable: "deities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_deity_spells_spells_spell_id", - column: x => x.spell_id, - principalTable: "spells", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "spell_areas", - columns: table => new - { - spell_id = table.Column(type: "integer", nullable: false), - details = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), - type = table.Column(type: "spell_area_type", nullable: false), - value = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_spell_areas", x => x.spell_id); - table.ForeignKey( - name: "fk_spell_areas_spells_spell_id", - column: x => x.spell_id, - principalTable: "spells", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "spell_damages", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - spell_id = table.Column(type: "integer", nullable: false), - key = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - apply_mod = table.Column(type: "boolean", nullable: true), - category = table.Column(type: "spell_damage_category", nullable: true), - formula = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - kinds = table.Column(type: "spell_damage_kinds", nullable: false), - materials = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), - type = table.Column(type: "character varying(255)", maxLength: 255, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_spell_damages", x => x.id); - table.ForeignKey( - name: "fk_spell_damages_spells_spell_id", - column: x => x.spell_id, - principalTable: "spells", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "spell_defenses", - columns: table => new - { - id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - spell_id = table.Column(type: "integer", nullable: false), - is_passive = table.Column(type: "boolean", nullable: false), - is_basic = table.Column(type: "boolean", nullable: true), - statistic = table.Column(type: "character varying(255)", maxLength: 255, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_spell_defenses", x => x.id); - table.ForeignKey( - name: "fk_spell_defenses_spells_spell_id", - column: x => x.spell_id, - principalTable: "spells", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "spell_rituals", - columns: table => new - { - spell_id = table.Column(type: "integer", nullable: false), - primary_check = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), - secondary_casters = table.Column(type: "integer", nullable: false), - secondary_checks = table.Column(type: "character varying(255)", maxLength: 255, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_spell_rituals", x => x.spell_id); - table.ForeignKey( - name: "fk_spell_rituals_spells_spell_id", - column: x => x.spell_id, - principalTable: "spells", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "entity_trait", - columns: table => new - { - entities_id = table.Column(type: "integer", nullable: false), - traits_id = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_entity_trait", x => new { x.entities_id, x.traits_id }); - table.ForeignKey( - name: "fk_entity_trait_entities_entities_id", - column: x => x.entities_id, - principalTable: "entities", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_entity_trait_traits_traits_id", - column: x => x.traits_id, - principalTable: "traits", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "archetype_feats", - columns: table => new - { - archetype_id = table.Column(type: "integer", nullable: false), - feat_id = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("pk_archetype_feats", x => new { x.archetype_id, x.feat_id }); - table.ForeignKey( - name: "fk_archetype_feats_archetypes_archetype_id", - column: x => x.archetype_id, - principalTable: "archetypes", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "fk_archetype_feats_feats_feat_id", - column: x => x.feat_id, - principalTable: "feats", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "ix_ancestry_boosts_ancestry_id", - table: "ancestry_boosts", - column: "ancestry_id"); - - migrationBuilder.CreateIndex( - name: "ix_ancestry_items_item_id", - table: "ancestry_items", - column: "item_id"); - - migrationBuilder.CreateIndex( - name: "ix_ancestry_languages_language_id", - table: "ancestry_languages", - column: "language_id"); - - migrationBuilder.CreateIndex( - name: "ix_archetype_feats_feat_id", - table: "archetype_feats", - column: "feat_id"); - - migrationBuilder.CreateIndex( - name: "ix_archetypes_dedication_feat_id", - table: "archetypes", - column: "dedication_feat_id", - unique: true); - - migrationBuilder.CreateIndex( - name: "ix_background_boosts_background_id", - table: "background_boosts", - column: "background_id"); - - migrationBuilder.CreateIndex( - name: "ix_background_items_entity_id", - table: "background_items", - column: "entity_id"); - - migrationBuilder.CreateIndex( - name: "ix_background_skills_background_id", - table: "background_skills", - column: "background_id"); - - migrationBuilder.CreateIndex( - name: "ix_background_skills_training_id", - table: "background_skills", - column: "training_id"); - - migrationBuilder.CreateIndex( - name: "ix_class_key_abilities_class_id", - table: "class_key_abilities", - column: "class_id"); - - migrationBuilder.CreateIndex( - name: "ix_class_progressions_class_id", - table: "class_progressions", - column: "class_id"); - - migrationBuilder.CreateIndex( - name: "ix_class_progressions_entity_id", - table: "class_progressions", - column: "entity_id"); - - migrationBuilder.CreateIndex( - name: "ix_class_trainings_class_id", - table: "class_trainings", - column: "class_id"); - - migrationBuilder.CreateIndex( - name: "ix_class_trainings_training_id", - table: "class_trainings", - column: "training_id"); - - migrationBuilder.CreateIndex( - name: "ix_deity_domains_deity_id", - table: "deity_domains", - column: "deity_id"); - - migrationBuilder.CreateIndex( - name: "ix_deity_spells_deity_id", - table: "deity_spells", - column: "deity_id"); - - migrationBuilder.CreateIndex( - name: "ix_deity_spells_spell_id", - table: "deity_spells", - column: "spell_id"); - - migrationBuilder.CreateIndex( - name: "ix_deity_training_skills_id", - table: "deity_training", - column: "skills_id"); - - migrationBuilder.CreateIndex( - name: "ix_deity_weapons_deity_id", - table: "deity_weapons", - column: "deity_id"); - - migrationBuilder.CreateIndex( - name: "ix_entity_externals_target_id", - table: "entity_externals", - column: "target_id"); - - migrationBuilder.CreateIndex( - name: "ix_entity_keyword_keywords_id", - table: "entity_keyword", - column: "keywords_id"); - - migrationBuilder.CreateIndex( - name: "ix_entity_sources_source_id", - table: "entity_sources", - column: "source_id"); - - migrationBuilder.CreateIndex( - name: "ix_entity_trait_traits_id", - table: "entity_trait", - column: "traits_id"); - - migrationBuilder.CreateIndex( - name: "ix_feat_prerequisites_feat_id", - table: "feat_prerequisites", - column: "feat_id"); - - migrationBuilder.CreateIndex( - name: "ix_heritages_ancestry_id", - table: "heritages", - column: "ancestry_id"); + migrationBuilder + .AlterDatabase() + .Annotation( + "Npgsql:Enum:action_category", + "unknown,archetype,class-feature,class-feat,offensive,defensive,interaction,familiar,army_tactic,army_war_action,kingdom_activity,kingdom_feat,kingdom_feature" + ) + .Annotation("Npgsql:Enum:ancestry_vision", "normal,low-light-vision,dark-vision") + .Annotation("Npgsql:Enum:attribute_values", "free,str,dex,con,int,wis,cha") + .Annotation( + "Npgsql:Enum:class_progression_type", + "entity,ancestry_feat,class_feat,general_feat,skill_feat,skill_increase" + ) + .Annotation( + "Npgsql:Enum:condition_group", + "unknown,senses,abilities,death,attitudes,detection" + ) + .Annotation("Npgsql:Enum:deity_category", "deity,pantheon,covenant,philosophy") + .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,condition,deity,feat,heritage,spell,language" + ) + .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" + ) + .Annotation("Npgsql:Enum:size", "tiny,small,medium,large") + .Annotation( + "Npgsql:Enum:source_category", + "rulebook,adventure-path,lost-omens,adventures,comics,blog-posts,society" + ) + .Annotation( + "Npgsql:Enum:spell_area_type", + "burst,emanation,cone,line,square,cube,cylinder" + ) + .Annotation("Npgsql:Enum:spell_damage_category", "persistent,splash") + .Annotation("Npgsql:Enum:spell_damage_kinds", "damage,healing,any") + .Annotation("Npgsql:Enum:training_stage", "untrained,trained,expert,master,legendary") + .Annotation("Npgsql:Enum:trait_type", "regular,class,tradition"); + + migrationBuilder.CreateTable( + name: "entities", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + name = table.Column( + type: "jsonb", + nullable: false, + comment: "Отображаемое имя" + ), + type = table.Column( + type: "entity_type", + nullable: false, + comment: "Тип объекта" + ), + slug = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false, + comment: "Часть имени в URL" + ), + img = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false, + comment: "Изображение объекта" + ), + description = table.Column( + type: "text", + nullable: false, + comment: "Текстовое описание объекта" + ), + rarity = table.Column(type: "entity_rarity", nullable: false), + is_translated = table.Column( + type: "boolean", + nullable: true, + comment: "Флаг, указывающий, что у объекта существует перевод" + ), + is_checked = table.Column( + type: "boolean", + nullable: true, + comment: "Флаг, указывающий, что объект был проверен и не требует автоматической перезаписи" + ), + }, + constraints: table => + { + table.PrimaryKey("pk_entities", x => x.id); + } + ); + + migrationBuilder.CreateTable( + name: "external_targets", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + name = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + icon = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + prefix = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + }, + constraints: table => + { + table.PrimaryKey("pk_external_targets", x => x.id); + } + ); + + migrationBuilder.CreateTable( + name: "frequencies", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + max = table.Column(type: "integer", nullable: false), + per = table.Column(type: "integer", nullable: false), + value = table.Column(type: "integer", nullable: true), + }, + constraints: table => + { + table.PrimaryKey("pk_frequencies", x => x.id); + } + ); + + migrationBuilder.CreateTable( + name: "keywords", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + slug = table.Column(type: "text", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_keywords", x => x.id); + } + ); + + migrationBuilder.CreateTable( + name: "sources", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + name = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + category = table.Column(type: "source_category", nullable: false), + release_date = table.Column(type: "date", nullable: true), + }, + constraints: table => + { + table.PrimaryKey("pk_sources", x => x.id); + } + ); + + migrationBuilder.CreateTable( + name: "trainings", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + name = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + type = table.Column(type: "integer", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_trainings", x => x.id); + } + ); + + migrationBuilder.CreateTable( + name: "actions", + columns: table => new + { + id = table.Column(type: "integer", nullable: false), + actions = table.Column(type: "integer", nullable: true), + max_actions = table.Column(type: "integer", nullable: true), + is_reaction = table.Column(type: "boolean", nullable: false), + is_free_action = table.Column(type: "boolean", nullable: false), + is_passive = table.Column(type: "boolean", nullable: false), + extra = table.Column(type: "text", nullable: true), + }, + constraints: table => + { + table.PrimaryKey("pk_actions", x => x.id); + table.ForeignKey( + name: "fk_actions_entities_id", + column: x => x.id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "ancestries", + columns: table => new + { + id = table.Column(type: "integer", nullable: false), + size = table.Column(type: "size[]", nullable: false), + hp = table.Column(type: "integer", nullable: false), + speed = table.Column(type: "integer", nullable: false), + vision = table.Column(type: "ancestry_vision", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_ancestries", x => x.id); + table.ForeignKey( + name: "fk_ancestries_entities_id", + column: x => x.id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "backgrounds", + columns: table => new { id = table.Column(type: "integer", nullable: false) }, + constraints: table => + { + table.PrimaryKey("pk_backgrounds", x => x.id); + table.ForeignKey( + name: "fk_backgrounds_entities_id", + column: x => x.id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "classes", + columns: table => new + { + id = table.Column(type: "integer", nullable: false), + hp = table.Column(type: "integer", nullable: false), + perception = table.Column(type: "integer", nullable: false), + spellcasting = table.Column(type: "boolean", nullable: false), + tradition = table.Column(type: "integer", nullable: false), + additional_trained_skills = table.Column(type: "integer", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_classes", x => x.id); + table.ForeignKey( + name: "fk_classes_entities_id", + column: x => x.id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "conditions", + columns: table => new + { + id = table.Column(type: "integer", nullable: false), + group = table.Column(type: "condition_group", nullable: true), + extra = table.Column(type: "text", nullable: true), + }, + constraints: table => + { + table.PrimaryKey("pk_conditions", x => x.id); + table.ForeignKey( + name: "fk_conditions_entities_id", + column: x => x.id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "deities", + columns: table => new + { + id = table.Column(type: "integer", nullable: false), + category = table.Column(type: "deity_category", nullable: false), + fonts = table.Column(type: "deity_fonts", nullable: false), + sanctification = table.Column( + type: "deity_sanctification", + nullable: false + ), + sanctification_must = table.Column(type: "boolean", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_deities", x => x.id); + table.ForeignKey( + name: "fk_deities_entities_id", + column: x => x.id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "feats", + columns: table => new + { + id = table.Column(type: "integer", nullable: false), + category = table.Column(type: "action_category", nullable: false), + level = table.Column(type: "integer", nullable: false), + actions = table.Column(type: "integer", nullable: true), + max_actions = table.Column(type: "integer", nullable: true), + is_reaction = table.Column(type: "boolean", nullable: false), + is_free_action = table.Column(type: "boolean", nullable: false), + is_passive = table.Column(type: "boolean", nullable: false), + extra = table.Column(type: "text", nullable: true), + }, + constraints: table => + { + table.PrimaryKey("pk_feats", x => x.id); + table.ForeignKey( + name: "fk_feats_entities_id", + column: x => x.id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "languages", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + entity_id = table.Column(type: "integer", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_languages", x => x.id); + table.ForeignKey( + name: "fk_languages_entities_entity_id", + column: x => x.entity_id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "spells", + columns: table => new + { + id = table.Column(type: "integer", nullable: false), + level = table.Column(type: "integer", nullable: false), + cost = table.Column(type: "integer", nullable: false), + counteraction = table.Column(type: "boolean", nullable: false), + sustained = table.Column(type: "boolean", nullable: false), + duration = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + range = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + requirements = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + target = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + time = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + can_heightening = table.Column(type: "boolean", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_spells", x => x.id); + table.ForeignKey( + name: "fk_spells_entities_id", + column: x => x.id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "traits", + columns: table => new + { + id = table.Column(type: "integer", nullable: false), + type = table.Column(type: "trait_type", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_traits", x => x.id); + table.ForeignKey( + name: "fk_traits_entities_id", + column: x => x.id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "entity_externals", + columns: table => new + { + entity_id = table.Column(type: "integer", nullable: false), + target_id = table.Column(type: "integer", nullable: false), + suffix = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false, + comment: "Часть URL до объекта. Для источников Foundry - полный UUID объекта" + ), + md5 = table.Column( + type: "character varying(32)", + maxLength: 32, + nullable: false, + comment: "Контроль версии объекта" + ), + }, + constraints: table => + { + table.PrimaryKey("pk_entity_externals", x => new { x.entity_id, x.target_id }); + table.ForeignKey( + name: "fk_entity_externals_entities_entity_id", + column: x => x.entity_id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_entity_externals_external_targets_target_id", + column: x => x.target_id, + principalTable: "external_targets", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "entity_keyword", + columns: table => new + { + entities_id = table.Column(type: "integer", nullable: false), + keywords_id = table.Column(type: "integer", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_entity_keyword", x => new { x.entities_id, x.keywords_id }); + table.ForeignKey( + name: "fk_entity_keyword_entities_entities_id", + column: x => x.entities_id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_entity_keyword_keywords_keywords_id", + column: x => x.keywords_id, + principalTable: "keywords", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "keyword_aliases", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + keyword_id = table.Column(type: "integer", nullable: false), + value = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + }, + constraints: table => + { + table.PrimaryKey("pk_keyword_aliases", x => x.id); + table.ForeignKey( + name: "fk_keyword_aliases_keywords_keyword_id", + column: x => x.keyword_id, + principalTable: "keywords", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "entity_sources", + columns: table => new + { + entity_id = table.Column(type: "integer", nullable: false), + source_id = table.Column(type: "integer", nullable: false), + suffix = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false, + comment: "Номер страницы, эррата и т.д." + ), + is_remaster = table.Column( + type: "boolean", + nullable: false, + comment: "Флаг, указывающий, что объект является частью ремастера" + ), + }, + constraints: table => + { + table.PrimaryKey("pk_entity_sources", x => new { x.entity_id, x.source_id }); + table.ForeignKey( + name: "fk_entity_sources_entities_entity_id", + column: x => x.entity_id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_entity_sources_sources_source_id", + column: x => x.source_id, + principalTable: "sources", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "ancestry_boosts", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + ancestry_id = table.Column(type: "integer", nullable: false), + boost = table.Column(type: "boolean", nullable: false), + value = table.Column(type: "attribute_values", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_ancestry_boosts", x => x.id); + table.ForeignKey( + name: "fk_ancestry_boosts_ancestries_ancestry_id", + column: x => x.ancestry_id, + principalTable: "ancestries", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "ancestry_items", + columns: table => new + { + ancestry_id = table.Column(type: "integer", nullable: false), + item_id = table.Column(type: "integer", nullable: false), + level = table.Column(type: "integer", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_ancestry_items", x => new { x.ancestry_id, x.item_id }); + table.ForeignKey( + name: "fk_ancestry_items_ancestries_ancestry_id", + column: x => x.ancestry_id, + principalTable: "ancestries", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_ancestry_items_entities_item_id", + column: x => x.item_id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "heritages", + columns: table => new + { + id = table.Column(type: "integer", nullable: false), + ancestry_id = table.Column(type: "integer", nullable: true), + }, + constraints: table => + { + table.PrimaryKey("pk_heritages", x => x.id); + table.ForeignKey( + name: "fk_heritages_ancestries_ancestry_id", + column: x => x.ancestry_id, + principalTable: "ancestries", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_heritages_entities_id", + column: x => x.id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "background_boosts", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + background_id = table.Column(type: "integer", nullable: false), + attribute = table.Column( + type: "attribute_values", + nullable: false + ), + }, + constraints: table => + { + table.PrimaryKey("pk_background_boosts", x => x.id); + table.ForeignKey( + name: "fk_background_boosts_backgrounds_background_id", + column: x => x.background_id, + principalTable: "backgrounds", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "background_items", + columns: table => new + { + background_id = table.Column(type: "integer", nullable: false), + entity_id = table.Column(type: "integer", nullable: false), + level = table.Column(type: "integer", nullable: true), + }, + constraints: table => + { + table.PrimaryKey("pk_background_items", x => new { x.background_id, x.entity_id }); + table.ForeignKey( + name: "fk_background_items_backgrounds_background_id", + column: x => x.background_id, + principalTable: "backgrounds", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_background_items_entities_entity_id", + column: x => x.entity_id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "background_skills", + columns: table => new + { + id = table.Column(type: "integer", nullable: false), + background_id = table.Column(type: "integer", nullable: false), + training_id = table.Column(type: "integer", nullable: false), + level = table.Column(type: "training_stage", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_background_skills", x => x.id); + table.ForeignKey( + name: "fk_background_skills_backgrounds_background_id", + column: x => x.background_id, + principalTable: "backgrounds", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_background_skills_trainings_training_id", + column: x => x.training_id, + principalTable: "trainings", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "class_key_abilities", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + class_id = table.Column(type: "integer", nullable: false), + value = table.Column(type: "attribute_values", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_class_key_abilities", x => x.id); + table.ForeignKey( + name: "fk_class_key_abilities_classes_class_id", + column: x => x.class_id, + principalTable: "classes", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "class_progressions", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + class_id = table.Column(type: "integer", nullable: false), + type = table.Column( + type: "class_progression_type", + nullable: false + ), + entity_id = table.Column(type: "integer", nullable: true), + level = table.Column(type: "integer", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_class_progressions", x => x.id); + table.ForeignKey( + name: "fk_class_progressions_classes_class_id", + column: x => x.class_id, + principalTable: "classes", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_class_progressions_entities_entity_id", + column: x => x.entity_id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.SetNull + ); + } + ); + + migrationBuilder.CreateTable( + name: "class_trainings", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + class_id = table.Column(type: "integer", nullable: false), + training_id = table.Column(type: "integer", nullable: true), + name = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: true + ), + stage = table.Column(type: "training_stage", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_class_trainings", x => x.id); + table.ForeignKey( + name: "fk_class_trainings_classes_class_id", + column: x => x.class_id, + principalTable: "classes", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_class_trainings_trainings_training_id", + column: x => x.training_id, + principalTable: "trainings", + principalColumn: "id", + onDelete: ReferentialAction.SetNull + ); + } + ); + + migrationBuilder.CreateTable( + name: "deity_attributes", + columns: table => new + { + deity_id = table.Column(type: "integer", nullable: false), + attribute = table.Column( + type: "attribute_values", + nullable: false + ), + }, + constraints: table => + { + table.PrimaryKey("pk_deity_attributes", x => new { x.deity_id, x.attribute }); + table.ForeignKey( + name: "fk_deity_attributes_deities_deity_id", + column: x => x.deity_id, + principalTable: "deities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "deity_domains", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + deity_id = table.Column(type: "integer", nullable: false), + is_primary = table.Column(type: "boolean", nullable: false), + value = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + }, + constraints: table => + { + table.PrimaryKey("pk_deity_domains", x => x.id); + table.ForeignKey( + name: "fk_deity_domains_deities_deity_id", + column: x => x.deity_id, + principalTable: "deities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "deity_training", + columns: table => new + { + deity_id = table.Column(type: "integer", nullable: false), + skills_id = table.Column(type: "integer", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_deity_training", x => new { x.deity_id, x.skills_id }); + table.ForeignKey( + name: "fk_deity_training_deities_deity_id", + column: x => x.deity_id, + principalTable: "deities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_deity_training_trainings_skills_id", + column: x => x.skills_id, + principalTable: "trainings", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "deity_weapons", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + deity_id = table.Column(type: "integer", nullable: false), + weapon = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + }, + constraints: table => + { + table.PrimaryKey("pk_deity_weapons", x => x.id); + table.ForeignKey( + name: "fk_deity_weapons_deities_deity_id", + column: x => x.deity_id, + principalTable: "deities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "archetypes", + columns: table => new + { + id = table.Column(type: "integer", nullable: false), + level = table.Column(type: "integer", nullable: false), + dedication_feat_id = table.Column(type: "integer", nullable: true), + extra = table.Column(type: "text", nullable: true), + }, + constraints: table => + { + table.PrimaryKey("pk_archetypes", x => x.id); + table.ForeignKey( + name: "fk_archetypes_entities_id", + column: x => x.id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_archetypes_feats_dedication_feat_id", + column: x => x.dedication_feat_id, + principalTable: "feats", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "feat_prerequisites", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + feat_id = table.Column(type: "integer", nullable: false), + value = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + }, + constraints: table => + { + table.PrimaryKey("pk_feat_prerequisites", x => x.id); + table.ForeignKey( + name: "fk_feat_prerequisites_feats_feat_id", + column: x => x.feat_id, + principalTable: "feats", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "ancestry_languages", + columns: table => new + { + ancestry_id = table.Column(type: "integer", nullable: false), + language_id = table.Column(type: "integer", nullable: false), + is_additional = table.Column(type: "boolean", nullable: false), + }, + constraints: table => + { + table.PrimaryKey( + "pk_ancestry_languages", + x => new { x.ancestry_id, x.language_id } + ); + table.ForeignKey( + name: "fk_ancestry_languages_ancestries_ancestry_id", + column: x => x.ancestry_id, + principalTable: "ancestries", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_ancestry_languages_languages_language_id", + column: x => x.language_id, + principalTable: "languages", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "deity_spells", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + deity_id = table.Column(type: "integer", nullable: false), + level = table.Column(type: "integer", nullable: false), + spell_id = table.Column(type: "integer", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_deity_spells", x => x.id); + table.ForeignKey( + name: "fk_deity_spells_deities_deity_id", + column: x => x.deity_id, + principalTable: "deities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_deity_spells_spells_spell_id", + column: x => x.spell_id, + principalTable: "spells", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "spell_areas", + columns: table => new + { + spell_id = table.Column(type: "integer", nullable: false), + details = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: true + ), + type = table.Column(type: "spell_area_type", nullable: false), + value = table.Column(type: "integer", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_spell_areas", x => x.spell_id); + table.ForeignKey( + name: "fk_spell_areas_spells_spell_id", + column: x => x.spell_id, + principalTable: "spells", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "spell_damages", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + spell_id = table.Column(type: "integer", nullable: false), + key = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + apply_mod = table.Column(type: "boolean", nullable: true), + category = table.Column( + type: "spell_damage_category", + nullable: true + ), + formula = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + kinds = table.Column(type: "spell_damage_kinds", nullable: false), + materials = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: true + ), + type = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + }, + constraints: table => + { + table.PrimaryKey("pk_spell_damages", x => x.id); + table.ForeignKey( + name: "fk_spell_damages_spells_spell_id", + column: x => x.spell_id, + principalTable: "spells", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "spell_defenses", + columns: table => new + { + id = table + .Column(type: "integer", nullable: false) + .Annotation( + "Npgsql:ValueGenerationStrategy", + NpgsqlValueGenerationStrategy.IdentityByDefaultColumn + ), + spell_id = table.Column(type: "integer", nullable: false), + is_passive = table.Column(type: "boolean", nullable: false), + is_basic = table.Column(type: "boolean", nullable: true), + statistic = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + }, + constraints: table => + { + table.PrimaryKey("pk_spell_defenses", x => x.id); + table.ForeignKey( + name: "fk_spell_defenses_spells_spell_id", + column: x => x.spell_id, + principalTable: "spells", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "spell_rituals", + columns: table => new + { + spell_id = table.Column(type: "integer", nullable: false), + primary_check = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + secondary_casters = table.Column(type: "integer", nullable: false), + secondary_checks = table.Column( + type: "character varying(255)", + maxLength: 255, + nullable: false + ), + }, + constraints: table => + { + table.PrimaryKey("pk_spell_rituals", x => x.spell_id); + table.ForeignKey( + name: "fk_spell_rituals_spells_spell_id", + column: x => x.spell_id, + principalTable: "spells", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "entity_trait", + columns: table => new + { + entities_id = table.Column(type: "integer", nullable: false), + traits_id = table.Column(type: "integer", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_entity_trait", x => new { x.entities_id, x.traits_id }); + table.ForeignKey( + name: "fk_entity_trait_entities_entities_id", + column: x => x.entities_id, + principalTable: "entities", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_entity_trait_traits_traits_id", + column: x => x.traits_id, + principalTable: "traits", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateTable( + name: "archetype_feats", + columns: table => new + { + archetype_id = table.Column(type: "integer", nullable: false), + feat_id = table.Column(type: "integer", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("pk_archetype_feats", x => new { x.archetype_id, x.feat_id }); + table.ForeignKey( + name: "fk_archetype_feats_archetypes_archetype_id", + column: x => x.archetype_id, + principalTable: "archetypes", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + table.ForeignKey( + name: "fk_archetype_feats_feats_feat_id", + column: x => x.feat_id, + principalTable: "feats", + principalColumn: "id", + onDelete: ReferentialAction.Cascade + ); + } + ); + + migrationBuilder.CreateIndex( + name: "ix_ancestry_boosts_ancestry_id", + table: "ancestry_boosts", + column: "ancestry_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_ancestry_items_item_id", + table: "ancestry_items", + column: "item_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_ancestry_languages_language_id", + table: "ancestry_languages", + column: "language_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_archetype_feats_feat_id", + table: "archetype_feats", + column: "feat_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_archetypes_dedication_feat_id", + table: "archetypes", + column: "dedication_feat_id", + unique: true + ); + + migrationBuilder.CreateIndex( + name: "ix_background_boosts_background_id", + table: "background_boosts", + column: "background_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_background_items_entity_id", + table: "background_items", + column: "entity_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_background_skills_background_id", + table: "background_skills", + column: "background_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_background_skills_training_id", + table: "background_skills", + column: "training_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_class_key_abilities_class_id", + table: "class_key_abilities", + column: "class_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_class_progressions_class_id", + table: "class_progressions", + column: "class_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_class_progressions_entity_id", + table: "class_progressions", + column: "entity_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_class_trainings_class_id", + table: "class_trainings", + column: "class_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_class_trainings_training_id", + table: "class_trainings", + column: "training_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_deity_domains_deity_id", + table: "deity_domains", + column: "deity_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_deity_spells_deity_id", + table: "deity_spells", + column: "deity_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_deity_spells_spell_id", + table: "deity_spells", + column: "spell_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_deity_training_skills_id", + table: "deity_training", + column: "skills_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_deity_weapons_deity_id", + table: "deity_weapons", + column: "deity_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_entity_externals_target_id", + table: "entity_externals", + column: "target_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_entity_keyword_keywords_id", + table: "entity_keyword", + column: "keywords_id" + ); + + migrationBuilder.CreateIndex( + name: "ix_entity_sources_source_id", + table: "entity_sources", + column: "source_id" + ); - migrationBuilder.CreateIndex( - name: "ix_keyword_aliases_keyword_id", - table: "keyword_aliases", - column: "keyword_id"); + migrationBuilder.CreateIndex( + name: "ix_entity_trait_traits_id", + table: "entity_trait", + column: "traits_id" + ); - migrationBuilder.CreateIndex( - name: "ix_languages_entity_id", - table: "languages", - column: "entity_id"); + migrationBuilder.CreateIndex( + name: "ix_feat_prerequisites_feat_id", + table: "feat_prerequisites", + column: "feat_id" + ); - migrationBuilder.CreateIndex( - name: "ix_spell_damages_spell_id", - table: "spell_damages", - column: "spell_id"); + migrationBuilder.CreateIndex( + name: "ix_heritages_ancestry_id", + table: "heritages", + column: "ancestry_id" + ); - migrationBuilder.CreateIndex( - name: "ix_spell_defenses_spell_id", - table: "spell_defenses", - column: "spell_id"); - } + migrationBuilder.CreateIndex( + name: "ix_keyword_aliases_keyword_id", + table: "keyword_aliases", + column: "keyword_id" + ); - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "actions"); + migrationBuilder.CreateIndex( + name: "ix_languages_entity_id", + table: "languages", + column: "entity_id" + ); - migrationBuilder.DropTable( - name: "ancestry_boosts"); + migrationBuilder.CreateIndex( + name: "ix_spell_damages_spell_id", + table: "spell_damages", + column: "spell_id" + ); - migrationBuilder.DropTable( - name: "ancestry_items"); + migrationBuilder.CreateIndex( + name: "ix_spell_defenses_spell_id", + table: "spell_defenses", + column: "spell_id" + ); + } - migrationBuilder.DropTable( - name: "ancestry_languages"); + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable(name: "actions"); - migrationBuilder.DropTable( - name: "archetype_feats"); + migrationBuilder.DropTable(name: "ancestry_boosts"); - migrationBuilder.DropTable( - name: "background_boosts"); + migrationBuilder.DropTable(name: "ancestry_items"); - migrationBuilder.DropTable( - name: "background_items"); + migrationBuilder.DropTable(name: "ancestry_languages"); - migrationBuilder.DropTable( - name: "background_skills"); + migrationBuilder.DropTable(name: "archetype_feats"); - migrationBuilder.DropTable( - name: "class_key_abilities"); + migrationBuilder.DropTable(name: "background_boosts"); - migrationBuilder.DropTable( - name: "class_progressions"); + migrationBuilder.DropTable(name: "background_items"); - migrationBuilder.DropTable( - name: "class_trainings"); + migrationBuilder.DropTable(name: "background_skills"); - migrationBuilder.DropTable( - name: "conditions"); + migrationBuilder.DropTable(name: "class_key_abilities"); - migrationBuilder.DropTable( - name: "deity_attributes"); + migrationBuilder.DropTable(name: "class_progressions"); - migrationBuilder.DropTable( - name: "deity_domains"); + migrationBuilder.DropTable(name: "class_trainings"); - migrationBuilder.DropTable( - name: "deity_spells"); + migrationBuilder.DropTable(name: "conditions"); - migrationBuilder.DropTable( - name: "deity_training"); + migrationBuilder.DropTable(name: "deity_attributes"); - migrationBuilder.DropTable( - name: "deity_weapons"); + migrationBuilder.DropTable(name: "deity_domains"); - migrationBuilder.DropTable( - name: "entity_externals"); + migrationBuilder.DropTable(name: "deity_spells"); - migrationBuilder.DropTable( - name: "entity_keyword"); + migrationBuilder.DropTable(name: "deity_training"); - migrationBuilder.DropTable( - name: "entity_sources"); + migrationBuilder.DropTable(name: "deity_weapons"); - migrationBuilder.DropTable( - name: "entity_trait"); + migrationBuilder.DropTable(name: "entity_externals"); - migrationBuilder.DropTable( - name: "feat_prerequisites"); + migrationBuilder.DropTable(name: "entity_keyword"); - migrationBuilder.DropTable( - name: "frequencies"); + migrationBuilder.DropTable(name: "entity_sources"); - migrationBuilder.DropTable( - name: "heritages"); + migrationBuilder.DropTable(name: "entity_trait"); - migrationBuilder.DropTable( - name: "keyword_aliases"); + migrationBuilder.DropTable(name: "feat_prerequisites"); - migrationBuilder.DropTable( - name: "spell_areas"); + migrationBuilder.DropTable(name: "frequencies"); - migrationBuilder.DropTable( - name: "spell_damages"); + migrationBuilder.DropTable(name: "heritages"); - migrationBuilder.DropTable( - name: "spell_defenses"); + migrationBuilder.DropTable(name: "keyword_aliases"); - migrationBuilder.DropTable( - name: "spell_rituals"); + migrationBuilder.DropTable(name: "spell_areas"); - migrationBuilder.DropTable( - name: "languages"); + migrationBuilder.DropTable(name: "spell_damages"); - migrationBuilder.DropTable( - name: "archetypes"); + migrationBuilder.DropTable(name: "spell_defenses"); - migrationBuilder.DropTable( - name: "backgrounds"); + migrationBuilder.DropTable(name: "spell_rituals"); - migrationBuilder.DropTable( - name: "classes"); + migrationBuilder.DropTable(name: "languages"); - migrationBuilder.DropTable( - name: "trainings"); + migrationBuilder.DropTable(name: "archetypes"); - migrationBuilder.DropTable( - name: "deities"); + migrationBuilder.DropTable(name: "backgrounds"); - migrationBuilder.DropTable( - name: "external_targets"); + migrationBuilder.DropTable(name: "classes"); - migrationBuilder.DropTable( - name: "sources"); + migrationBuilder.DropTable(name: "trainings"); - migrationBuilder.DropTable( - name: "traits"); + migrationBuilder.DropTable(name: "deities"); - migrationBuilder.DropTable( - name: "ancestries"); + migrationBuilder.DropTable(name: "external_targets"); - migrationBuilder.DropTable( - name: "keywords"); + migrationBuilder.DropTable(name: "sources"); - migrationBuilder.DropTable( - name: "spells"); + migrationBuilder.DropTable(name: "traits"); - migrationBuilder.DropTable( - name: "feats"); + migrationBuilder.DropTable(name: "ancestries"); - migrationBuilder.DropTable( - name: "entities"); - } + migrationBuilder.DropTable(name: "keywords"); + + migrationBuilder.DropTable(name: "spells"); + + migrationBuilder.DropTable(name: "feats"); + + migrationBuilder.DropTable(name: "entities"); } } diff --git a/Pf2eModel/Model/Common/I18n/LocaleExtension.cs b/Pf2eModel/Model/Common/I18n/LocaleExtension.cs index d3bc1a5..b2c5453 100644 --- a/Pf2eModel/Model/Common/I18n/LocaleExtension.cs +++ b/Pf2eModel/Model/Common/I18n/LocaleExtension.cs @@ -1,30 +1,33 @@ -using Microsoft.EntityFrameworkCore; -using Pf2eModel.Model.Base; -using System.ComponentModel; -using System.Linq.Expressions; +using System.ComponentModel; using System.Reflection; namespace Pf2eModel.Model.Common.I18n; + public static class LocaleExtension { public static string GetTypeString(this LocaleType localeType) { FieldInfo fi = localeType.GetType().GetField(localeType.ToString())!; - DescriptionAttribute[] attributes = (DescriptionAttribute[]) fi.GetCustomAttributes(typeof(DescriptionAttribute), false); + DescriptionAttribute[] attributes = (DescriptionAttribute[]) + fi.GetCustomAttributes(typeof(DescriptionAttribute), false); - return (attributes.Length != 0 ? attributes.FirstOrDefault()?.Description : null) ?? localeType.ToString(); + return (attributes.Length != 0 ? attributes.FirstOrDefault()?.Description : null) + ?? localeType.ToString(); } public static LocaleType GetTypeByString(this string localeType) { foreach (System.Reflection.FieldInfo field in typeof(LocaleType).GetFields()) { - if (Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) is DescriptionAttribute descriptionAttribute) + if ( + Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) + is DescriptionAttribute descriptionAttribute + ) { if (descriptionAttribute.Description == localeType) { - return (LocaleType) field.GetValue(null)!; + return (LocaleType)field.GetValue(null)!; } } } diff --git a/Pf2eModel/Model/Common/I18n/LocaleString.cs b/Pf2eModel/Model/Common/I18n/LocaleString.cs index 1e7a169..043d607 100644 --- a/Pf2eModel/Model/Common/I18n/LocaleString.cs +++ b/Pf2eModel/Model/Common/I18n/LocaleString.cs @@ -1,18 +1,12 @@ -using Newtonsoft.Json.Linq; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Runtime.Serialization.Json; -using System.Text; -using System.Threading.Tasks; +using System.Collections; +using Newtonsoft.Json.Linq; namespace Pf2eModel.Model.Common.I18n; public class LocaleString : ICollection { private readonly List _items = []; + private void AssureDefault() { if (_items.Count == 0) @@ -34,16 +28,19 @@ public class LocaleString : ICollection private LocaleType _E(string localeString) => LocaleExtension.GetTypeByString(localeString); - private LocaleType RealLocale(LocaleType locale) => Contains(locale) ? locale : LocaleType.English; + private LocaleType RealLocale(LocaleType locale) => + Contains(locale) ? locale : LocaleType.English; + private LocaleType RealLocale(string localeString) => RealLocale(_E(localeString)); public LocaleItem GetItem(LocaleType locale) => this.First(c => c.Locale == RealLocale(locale)); + public LocaleItem GetItem(string locale) => this.First(c => c.Locale == RealLocale(locale)); public string this[LocaleType locale] { get => GetItem(locale).Value; - set + set { if (Types.Contains(locale)) { @@ -65,6 +62,7 @@ public class LocaleString : ICollection { this[item.Locale] = item.Value; } + public void Add(LocaleType locale, string value) { this[locale] = value; @@ -80,10 +78,12 @@ public class LocaleString : ICollection { return _items.Contains(item); } + public bool Contains(LocaleType locale) { return Types.Contains(locale); } + public bool Contains(string value) { return this.Any(item => item.Value == value); @@ -111,6 +111,7 @@ public class LocaleString : ICollection { return _items.GetEnumerator(); } + IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); @@ -132,17 +133,17 @@ public class LocaleString : ICollection return json.ToString(); } + public static LocaleString Deserialize(string input) { JObject json = JObject.Parse(input); LocaleString result = new(); - foreach (var item in json) + foreach (KeyValuePair item in json) { result[item.Key] = item.ToString(); } return result; } - } diff --git a/Pf2eModel/Model/Structure/Archetype.cs b/Pf2eModel/Model/Structure/Archetype.cs index 39fde77..5fa510d 100644 --- a/Pf2eModel/Model/Structure/Archetype.cs +++ b/Pf2eModel/Model/Structure/Archetype.cs @@ -1,12 +1,7 @@ -using Pf2eModel.Model.Base; -using Pf2eModel.Model.Enum; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; +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; namespace Pf2eModel.Model.Structure; diff --git a/Pf2eModel/Model/Structure/ArchetypeRelation/ArchetypeFeats.cs b/Pf2eModel/Model/Structure/ArchetypeRelation/ArchetypeFeats.cs index 6410d0c..23dbba2 100644 --- a/Pf2eModel/Model/Structure/ArchetypeRelation/ArchetypeFeats.cs +++ b/Pf2eModel/Model/Structure/ArchetypeRelation/ArchetypeFeats.cs @@ -1,9 +1,4 @@ using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Pf2eModel.Model.Structure.ArchetypeRelation; @@ -11,6 +6,6 @@ namespace Pf2eModel.Model.Structure.ArchetypeRelation; internal class ArchetypeFeats { public int ArchetypeId { get; set; } - + public int FeatId { get; set; } } diff --git a/Pf2eModel/Model/Structure/Language.cs b/Pf2eModel/Model/Structure/Language.cs index 9c367d6..5f652b3 100644 --- a/Pf2eModel/Model/Structure/Language.cs +++ b/Pf2eModel/Model/Structure/Language.cs @@ -1,12 +1,12 @@ -using Pf2eModel.Model.Base; -using Pf2eModel.Model.Enum; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using Pf2eModel.Model.Base; +using Pf2eModel.Model.Enum; namespace Pf2eModel.Model.Structure; [EntityOfType(EntityType.Language)] -public partial class Language: IEntity +public partial class Language : IEntity { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] @@ -14,5 +14,4 @@ public partial class Language: IEntity public int Id { get; set; } public Entity Entity { get; set; } = null!; - } diff --git a/Pf2eModel/Pf2eDbContextModel.cs b/Pf2eModel/Pf2eDbContextModel.cs index 7ac5965..740e592 100644 --- a/Pf2eModel/Pf2eDbContextModel.cs +++ b/Pf2eModel/Pf2eDbContextModel.cs @@ -1,6 +1,7 @@ -using Microsoft.EntityFrameworkCore; +using System.Linq.Expressions; +using System.Reflection; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Pf2eModel.Model; using Pf2eModel.Model.Base; using Pf2eModel.Model.Base.Keywords; @@ -17,8 +18,6 @@ using Pf2eModel.Model.Structure.ClassRelation; using Pf2eModel.Model.Structure.DeityRelation; using Pf2eModel.Model.Structure.FeatRelation; using Pf2eModel.Model.Structure.SpellRelation; -using System.Linq.Expressions; -using System.Reflection; namespace Pf2eModel; @@ -37,15 +36,21 @@ public partial class Pf2eDbContext DefineMethods(modelBuilder); } - private void BindEntity(EntityTypeBuilder entity) where T : class, IEntity + private void BindEntity(EntityTypeBuilder entity) + where T : class, IEntity { - entity.HasOne(entity => entity.Entity) + entity + .HasOne(entity => entity.Entity) .WithOne() .HasForeignKey(entity => entity.Id) .IsRequired(); } - private void BindLocaleString(EntityTypeBuilder entity, Expression> func) where T : class + private void BindLocaleString( + EntityTypeBuilder entity, + Expression> func + ) + where T : class { /* entity.OwnsMany(func, d => @@ -54,11 +59,9 @@ public partial class Pf2eDbContext }); */ - entity.Property(func) - .HasConversion( - v => v.Serialize(), - v => LocaleString.Deserialize(v) - ) + entity + .Property(func) + .HasConversion(v => v.Serialize(), v => LocaleString.Deserialize(v)) .HasColumnType("jsonb"); } @@ -84,8 +87,7 @@ public partial class Pf2eDbContext .HasPostgresEnum() .HasPostgresEnum() .HasPostgresEnum() - .HasPostgresEnum() - ; + .HasPostgresEnum(); } private void DefineBase(ModelBuilder modelBuilder) @@ -99,12 +101,16 @@ public partial class Pf2eDbContext entity.HasMany(e => e.Keywords).WithMany(t => t.Entities); // EntitySource - entity.HasMany(e => e.Sources).WithOne(e => e.Entity) + entity + .HasMany(e => e.Sources) + .WithOne(e => e.Entity) .HasForeignKey(e => e.EntityId) .OnDelete(DeleteBehavior.Cascade); // EntityExternal - entity.HasMany(e => e.Externals).WithOne(e => e.Entity) + entity + .HasMany(e => e.Externals) + .WithOne(e => e.Entity) .HasForeignKey(e => e.EntityId) .OnDelete(DeleteBehavior.Cascade); }); @@ -114,7 +120,9 @@ public partial class Pf2eDbContext { entity.Property(e => e.Id).HasColumnName("id"); - entity.HasMany(s => s.EntitySources).WithOne(e => e.Source) + entity + .HasMany(s => s.EntitySources) + .WithOne(e => e.Source) .HasForeignKey(e => e.SourceId) .OnDelete(DeleteBehavior.Cascade); @@ -125,7 +133,9 @@ public partial class Pf2eDbContext // External modelBuilder.Entity(entity => { - entity.HasMany(t => t.EntityExternals).WithOne(e => e.Target) + entity + .HasMany(t => t.EntityExternals) + .WithOne(e => e.Target) .HasForeignKey(e => e.TargetId) .OnDelete(DeleteBehavior.Cascade); }); @@ -134,7 +144,9 @@ public partial class Pf2eDbContext // Keywords modelBuilder.Entity(entity => { - entity.HasMany(e => e.Aliases).WithOne(e => e.Keyword) + entity + .HasMany(e => e.Aliases) + .WithOne(e => e.Keyword) .HasForeignKey(e => e.KeywordId) .OnDelete(DeleteBehavior.Cascade); }); @@ -163,28 +175,38 @@ public partial class Pf2eDbContext { BindEntity(entity); - entity.HasMany(e => e.AncestryBoosts).WithOne(e => e.Ancestry) + entity + .HasMany(e => e.AncestryBoosts) + .WithOne(e => e.Ancestry) .HasForeignKey(e => e.AncestryId) .OnDelete(DeleteBehavior.Cascade); - entity.HasMany(e => e.AncestryItems).WithOne(e => e.Ancestry) + entity + .HasMany(e => e.AncestryItems) + .WithOne(e => e.Ancestry) .HasForeignKey(e => e.AncestryId) .OnDelete(DeleteBehavior.Cascade); - entity.HasMany(e => e.AncestryLanguages).WithOne(e => e.Ancestry) + entity + .HasMany(e => e.AncestryLanguages) + .WithOne(e => e.Ancestry) .HasForeignKey(e => e.AncestryId) .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity(entity => { }); modelBuilder.Entity(entity => { - entity.HasOne(d => d.Item).WithMany() + entity + .HasOne(d => d.Item) + .WithMany() .HasForeignKey(d => d.ItemId) .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity(entity => { - entity.HasOne(d => d.Language).WithMany() + entity + .HasOne(d => d.Language) + .WithMany() .HasForeignKey(d => d.LanguageId) .OnDelete(DeleteBehavior.Cascade); }); @@ -194,11 +216,15 @@ public partial class Pf2eDbContext { BindEntity(entity); - entity.HasOne(a => a.DedicationFeat).WithOne() + entity + .HasOne(a => a.DedicationFeat) + .WithOne() .HasForeignKey(a => a.DedicationFeatId) .OnDelete(DeleteBehavior.Cascade); - entity.HasMany(a => a.Feats).WithMany(f => f.Archetypes) + entity + .HasMany(a => a.Feats) + .WithMany(f => f.Archetypes) .UsingEntity( l => l.HasOne().WithMany().HasForeignKey(af => af.FeatId), r => r.HasOne().WithMany().HasForeignKey(af => af.ArchetypeId) @@ -212,23 +238,31 @@ public partial class Pf2eDbContext }); modelBuilder.Entity(entity => { - entity.HasOne(d => d.Background).WithMany(p => p.BackgroundBoosts) + entity + .HasOne(d => d.Background) + .WithMany(p => p.BackgroundBoosts) .HasForeignKey(d => d.BackgroundId) .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity(entity => { - entity.HasOne(d => d.Background).WithMany(p => p.BackgroundItems) + entity + .HasOne(d => d.Background) + .WithMany(p => p.BackgroundItems) .HasForeignKey(d => d.BackgroundId) .OnDelete(DeleteBehavior.Cascade); - entity.HasOne(d => d.Entity).WithMany() + entity + .HasOne(d => d.Entity) + .WithMany() .HasForeignKey(d => d.EntityId) .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity(entity => { - entity.HasOne(d => d.Background).WithMany(p => p.BackgroundSkills) + entity + .HasOne(d => d.Background) + .WithMany(p => p.BackgroundSkills) .HasForeignKey(d => d.BackgroundId) .OnDelete(DeleteBehavior.Cascade); }); @@ -240,27 +274,37 @@ public partial class Pf2eDbContext }); modelBuilder.Entity(entity => { - entity.HasOne(d => d.Class).WithMany(p => p.ClassKeyAbilities) + entity + .HasOne(d => d.Class) + .WithMany(p => p.ClassKeyAbilities) .HasForeignKey(d => d.ClassId) .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity(entity => { - entity.HasOne(d => d.Class).WithMany(p => p.ClassProgressions) + entity + .HasOne(d => d.Class) + .WithMany(p => p.ClassProgressions) .HasForeignKey(d => d.ClassId) .OnDelete(DeleteBehavior.Cascade); - entity.HasOne(d => d.Entity).WithMany() + entity + .HasOne(d => d.Entity) + .WithMany() .HasForeignKey(d => d.EntityId) .OnDelete(DeleteBehavior.SetNull); }); modelBuilder.Entity(entity => { - entity.HasOne(d => d.Class).WithMany(p => p.ClassTrainings) + entity + .HasOne(d => d.Class) + .WithMany(p => p.ClassTrainings) .HasForeignKey(d => d.ClassId) .OnDelete(DeleteBehavior.Cascade); - entity.HasOne(d => d.Training).WithMany() + entity + .HasOne(d => d.Training) + .WithMany() .HasForeignKey(d => d.TrainingId) .OnDelete(DeleteBehavior.SetNull); }); @@ -276,19 +320,27 @@ public partial class Pf2eDbContext { BindEntity(entity); - entity.HasMany(e => e.DeityAttributes).WithOne(e => e.Deity) + entity + .HasMany(e => e.DeityAttributes) + .WithOne(e => e.Deity) .HasForeignKey(e => e.DeityId) .OnDelete(DeleteBehavior.Cascade); - entity.HasMany(e => e.DeityDomains).WithOne(e => e.Deity) + entity + .HasMany(e => e.DeityDomains) + .WithOne(e => e.Deity) .HasForeignKey(e => e.DeityId) .OnDelete(DeleteBehavior.Cascade); - entity.HasMany(e => e.DeitySpells).WithOne(e => e.Deity) + entity + .HasMany(e => e.DeitySpells) + .WithOne(e => e.Deity) .HasForeignKey(e => e.DeityId) .OnDelete(DeleteBehavior.Cascade); - entity.HasMany(e => e.DeityWeapons).WithOne(e => e.Deity) + entity + .HasMany(e => e.DeityWeapons) + .WithOne(e => e.Deity) .HasForeignKey(e => e.DeityId) .OnDelete(DeleteBehavior.Cascade); @@ -298,7 +350,9 @@ public partial class Pf2eDbContext modelBuilder.Entity(entity => { }); modelBuilder.Entity(entity => { - entity.HasOne(d => d.Spell).WithMany() + entity + .HasOne(d => d.Spell) + .WithMany() .HasForeignKey(d => d.SpellId) .OnDelete(DeleteBehavior.Cascade); }); @@ -309,7 +363,9 @@ public partial class Pf2eDbContext { BindEntity(entity); - entity.HasMany(e => e.FeatPrerequisites).WithOne(e => e.Feat) + entity + .HasMany(e => e.FeatPrerequisites) + .WithOne(e => e.Feat) .HasForeignKey(e => e.FeatId) .OnDelete(DeleteBehavior.Cascade); }); @@ -320,7 +376,9 @@ public partial class Pf2eDbContext { BindEntity(entity); - entity.HasOne(d => d.Ancestry).WithMany(p => p.Heritages) + entity + .HasOne(d => d.Ancestry) + .WithMany(p => p.Heritages) .HasForeignKey(d => d.AncestryId) .OnDelete(DeleteBehavior.Cascade); }); @@ -330,21 +388,29 @@ public partial class Pf2eDbContext { BindEntity(entity); - entity.HasOne(e => e.SpellArea).WithOne(e => e.Spell) + entity + .HasOne(e => e.SpellArea) + .WithOne(e => e.Spell) .HasForeignKey(e => e.SpellId) .OnDelete(DeleteBehavior.Cascade) .IsRequired(false); - entity.HasOne(e => e.SpellRitual).WithOne(e => e.Spell) + entity + .HasOne(e => e.SpellRitual) + .WithOne(e => e.Spell) .HasForeignKey(e => e.SpellId) .OnDelete(DeleteBehavior.Cascade) .IsRequired(false); - entity.HasMany(e => e.SpellDamages).WithOne(e => e.Spell) + entity + .HasMany(e => e.SpellDamages) + .WithOne(e => e.Spell) .HasForeignKey(e => e.SpellId) .OnDelete(DeleteBehavior.Cascade); - entity.HasMany(e => e.SpellDefenses).WithOne(e => e.Spell) + entity + .HasMany(e => e.SpellDefenses) + .WithOne(e => e.Spell) .HasForeignKey(e => e.SpellId) .OnDelete(DeleteBehavior.Cascade); }); @@ -362,27 +428,40 @@ public partial class Pf2eDbContext private void DefineMethods(ModelBuilder modelBuilder) { - MethodInfo localeSearch = typeof(Pf2eDbContext).GetMethod(nameof(LocaleSearch), BindingFlags.Static | BindingFlags.Public, [typeof(LocaleString), typeof(string)])!; - modelBuilder.HasDbFunction(localeSearch, builder => - { - builder.HasName("locale_search"); - builder.HasParameter("data").HasStoreType("jsonb"); - builder.HasParameter("search_value"); - }); + MethodInfo localeSearch = typeof(Pf2eDbContext).GetMethod( + nameof(LocaleSearch), + BindingFlags.Static | BindingFlags.Public, + [typeof(LocaleString), typeof(string)] + )!; + modelBuilder.HasDbFunction( + localeSearch, + builder => + { + builder.HasName("locale_search"); + builder.HasParameter("data").HasStoreType("jsonb"); + builder.HasParameter("search_value"); + } + ); - MethodInfo localeSearchArray = typeof(Pf2eDbContext).GetMethod(nameof(LocaleSearchArray), BindingFlags.Static | BindingFlags.Public, [typeof(LocaleString), typeof(IEnumerable)])!; - modelBuilder.HasDbFunction(localeSearchArray, builder => - { - builder.HasName("locale_search_array"); - builder.HasParameter("data").HasStoreType("jsonb"); - builder.HasParameter("search_values"); - }); + MethodInfo localeSearchArray = typeof(Pf2eDbContext).GetMethod( + nameof(LocaleSearchArray), + BindingFlags.Static | BindingFlags.Public, + [typeof(LocaleString), typeof(IEnumerable)] + )!; + modelBuilder.HasDbFunction( + localeSearchArray, + builder => + { + builder.HasName("locale_search_array"); + builder.HasParameter("data").HasStoreType("jsonb"); + builder.HasParameter("search_values"); + } + ); } - public static bool LocaleSearch(LocaleString data, string search_value) - => throw new InvalidOperationException("Only for LINQ translation"); - - public static bool LocaleSearchArray(LocaleString data, IEnumerable search_values) - => throw new InvalidOperationException("Only for LINQ translation"); + public static bool LocaleSearch(LocaleString data, string search_value) => + throw new InvalidOperationException("Only for LINQ translation"); + public static bool LocaleSearchArray(LocaleString data, IEnumerable search_values) => + throw new InvalidOperationException("Only for LINQ translation"); } diff --git a/Pf2eViewer/EntityConverter.cs b/Pf2eViewer/EntityConverter.cs index 3618477..47eacbe 100644 --- a/Pf2eViewer/EntityConverter.cs +++ b/Pf2eViewer/EntityConverter.cs @@ -1,15 +1,13 @@ -using Microsoft.EntityFrameworkCore; +using System.ComponentModel; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using Pf2eModel; using Pf2eModel.Model; using Pf2eModel.Model.Base; -using Pf2eModel.Model.Base.Source; using Pf2eModel.Model.Common.I18n; using Pf2eModel.Model.Structure; -using System.ComponentModel; namespace Pf2eViewer; + internal class EntityConverter : JsonConverter { private readonly Pf2eDbContext _context = new(); @@ -71,7 +69,9 @@ internal class EntityConverter : JsonConverter private void ProcessTrait(Dictionary dictionary, Trait trait) { - LocaleString name = trait.Entity?.Name ?? _context.Entities.Where(e => e.Id == trait.Id).Select(e => e.Name).FirstOrDefault()!; + LocaleString name = + trait.Entity?.Name + ?? _context.Entities.Where(e => e.Id == trait.Id).Select(e => e.Name).FirstOrDefault()!; dictionary.Remove("Entity"); dictionary.Remove("Entities"); @@ -82,11 +82,18 @@ internal class EntityConverter : JsonConverter { dictionary.Remove("Description"); } - + public override bool CanRead => false; - public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) + public override object? ReadJson( + JsonReader reader, + Type objectType, + object? existingValue, + JsonSerializer serializer + ) { - throw new NotImplementedException("Unnecessary because CanRead is false. The type will skip the converter."); + throw new NotImplementedException( + "Unnecessary because CanRead is false. The type will skip the converter." + ); } } diff --git a/Pf2eViewer/MainViewForm.cs b/Pf2eViewer/MainViewForm.cs index e500cb3..380dfcd 100644 --- a/Pf2eViewer/MainViewForm.cs +++ b/Pf2eViewer/MainViewForm.cs @@ -1,5 +1,4 @@ -using LinqToDB.Tools; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Linq; @@ -7,8 +6,8 @@ using Newtonsoft.Json.Serialization; using Pf2eModel; using Pf2eModel.Model; using Pf2eModel.Model.Base; +using Pf2eModel.Model.Common.I18n; using Pf2eModel.Model.Enum; -using static LinqToDB.Common.Configuration; namespace Pf2eViewer; @@ -49,11 +48,10 @@ public partial class MainViewForm : Form public int MaxPage => Convert.ToInt32(Math.Ceiling(1.0 * Count / PerPage)); - private void UpdateTreeView() { EntityTreeView.Nodes.Clear(); - EntityType type = (EntityType) TypesListBox.SelectedItem!; + EntityType type = (EntityType)TypesListBox.SelectedItem!; Count = Context.Entities.Count(e => e.Type == type); @@ -63,8 +61,8 @@ public partial class MainViewForm : Form return; } - EntityGridView.DataSource = Context.Entities - .Where(e => e.Type == (EntityType) TypesListBox.SelectedItem) + EntityGridView.DataSource = Context + .Entities.Where(e => e.Type == (EntityType)TypesListBox.SelectedItem) .OrderBy(e => e.Id) .Select(e => new EntityGridRow(e)) .Skip((Page - 1) * PerPage) @@ -90,22 +88,27 @@ public partial class MainViewForm : Form Page = 1; } + private void FirstPageButton_Click(object sender, EventArgs e) { Page = 1; } + private void PrevPageButton_Click(object sender, EventArgs e) { Page--; } + private void NextPageButton_Click(object sender, EventArgs e) { Page++; } + private void LastPageButton_Click(object sender, EventArgs e) { Page = MaxPage; } + private void PageTextBox_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)) @@ -113,14 +116,16 @@ public partial class MainViewForm : Form e.Handled = true; } - if (e.KeyChar == (char) Keys.Return) + if (e.KeyChar == (char)Keys.Return) { UpdateTreeView(); } } - - private void EntityGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e) + private void EntityGridView_RowStateChanged( + object sender, + DataGridViewRowStateChangedEventArgs e + ) { int rowsCount = EntityGridView.SelectedRows.Count; if (rowsCount is 0 or > 1) @@ -130,7 +135,7 @@ public partial class MainViewForm : Form DataGridViewRow row = EntityGridView.SelectedRows[0]; - EntityGridRow data = (EntityGridRow) row.DataBoundItem; + EntityGridRow data = (EntityGridRow)row.DataBoundItem; ViewEntity(data.Id); } @@ -139,18 +144,16 @@ public partial class MainViewForm : Form { EntityTreeView.Nodes.Clear(); - Entity? entity = Context.Entities - .Where(e => e.Id == id && e.Type == (EntityType) TypesListBox.SelectedItem!) - .Include(e => e.Sources) - .ThenInclude(s => s.Source) - .Include(e => e.Aliases) - .Include(e => e.Keywords) - .Include(e => e.Externals) - .ThenInclude(x => x.Target) - .Include(e => e.Traits) - .ThenInclude(t => t.Entity) - .FirstOrDefault() - ; + Entity? entity = Context + .Entities.Where(e => e.Id == id && e.Type == (EntityType)TypesListBox.SelectedItem!) + .Include(e => e.Sources) + .ThenInclude(s => s.Source) + .Include(e => e.Keywords) + .Include(e => e.Externals) + .ThenInclude(x => x.Target) + .Include(e => e.Traits) + .ThenInclude(t => t.Entity) + .FirstOrDefault(); if (entity == null) { @@ -158,7 +161,6 @@ public partial class MainViewForm : Form return; } - string json = SerializeEntity(entity); JsonToTreeview(EntityTreeView, json, "Entity"); @@ -166,13 +168,12 @@ public partial class MainViewForm : Form DescriptionTextBox.Text = entity.Description.Replace("\\r", "").Replace("\\n", "\\r\\n"); } - - public string SerializeEntity(Entity entity) { JsonSerializerSettings settings = new() { - Converters = [ + Converters = + [ new EntityConverter(), new StringEnumConverter { NamingStrategy = new CamelCaseNamingStrategy() }, ], @@ -192,51 +193,51 @@ public partial class MainViewForm : Form switch (entity.Type) { case EntityType.Ancestry: - return Context.Ancestries - .Include(a => a.AncestryBoosts) + return Context + .Ancestries.Include(a => a.AncestryBoosts) .FirstOrDefault(e => e.Id == entity.Id); case EntityType.Archetype: - return Context.Archetypes - .Include(a => a.DedicationFeat) + return Context + .Archetypes.Include(a => a.DedicationFeat) .ThenInclude(f => f.Entity) .Include(a => a.Feats) .ThenInclude(f => f.Entity) .FirstOrDefault(a => a.Id == entity.Id); case EntityType.Background: - return Context.Backgrounds - .Include(b => b.BackgroundBoosts) + return Context + .Backgrounds.Include(b => b.BackgroundBoosts) .Include(b => b.BackgroundSkills) .ThenInclude(t => t.Training) .Include(b => b.BackgroundItems) .FirstOrDefault(e => e.Id == entity.Id); case EntityType.Class: - return Context.Classes - .Include(c => c.ClassKeyAbilities) + return Context + .Classes.Include(c => c.ClassKeyAbilities) .Include(c => c.ClassTrainings) .ThenInclude(t => t.Training) .Include(c => c.ClassProgressions) .FirstOrDefault(c => c.Id == entity.Id); case EntityType.Feat: - return Context.Feats - .Include(f => f.Archetypes) + return Context + .Feats.Include(f => f.Archetypes) .ThenInclude(a => a.Entity) .FirstOrDefault(f => f.Id == entity.Id); default: Type type = EntityOfTypeAttribute.Resolve(entity); - return (IEntity?) Context.Find(type, entity.Id); + return (IEntity?)Context.Find(type, entity.Id); } } public static void JsonToTreeview(TreeView treeView, string jsonString, string rootName) { object json = jsonString.StartsWith('[') - ? JArray.Parse(jsonString) - : JObject.Parse(jsonString); + ? JArray.Parse(jsonString) + : JObject.Parse(jsonString); treeView.Nodes.Clear(); foreach (TreeNode node in Element2TreeNode(json, rootName).Nodes) @@ -253,7 +254,7 @@ public partial class MainViewForm : Form switch (element.GetType().Name) { case "JObject": - JObject jObject = (JObject) element; + JObject jObject = (JObject)element; foreach (KeyValuePair token in jObject) { subNodes.Add(Element2TreeNode(token.Value, token.Key)); @@ -261,7 +262,7 @@ public partial class MainViewForm : Form break; case "JArray": - JArray jArray = (JArray) element; + JArray jArray = (JArray)element; int i = 0; subNodes.AddRange(jArray.Select(token => Element2TreeNode(token, $"[{i++}]"))); @@ -272,22 +273,23 @@ public partial class MainViewForm : Form break; case "JValue": - JValue jValue = (JValue) element; + JValue jValue = (JValue)element; text += $": ({jValue.Type}) {jValue}"; break; default: - throw new Exception("clsJSON2Treeview can't interpret object:" + element.GetType().Name); + throw new Exception( + "clsJSON2Treeview can't interpret object:" + element.GetType().Name + ); } TreeNode treeNode = new(text); if (subNodes.Count > 0) { - treeNode.Nodes.AddRange(subNodes - .OrderBy(node => node.Nodes.Count > 0 ? 1 : 0) - .ToArray() - ); + treeNode.Nodes.AddRange( + subNodes.OrderBy(node => node.Nodes.Count > 0 ? 1 : 0).ToArray() + ); } return treeNode; @@ -296,12 +298,11 @@ public partial class MainViewForm : Form private class EntityGridRow(Entity e) { public int Id { get; set; } = e.Id; - public string Name { get; set; } = e.Name.ToString(); + public string Name { get; set; } = e.Name[LocaleType.English]; public EntityRarity Rarity { get; set; } = e.Rarity; private readonly Entity _e = e; + public Entity GetEntity() => _e; - } - }