Compare commits

..
3 Commits
55 changed files with 565 additions and 946 deletions
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging; using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Linq;
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium; using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry
@@ -1,6 +1,8 @@
using LinqToDB.DataProvider.SapHana; using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Linq; using NpgsqlTypes;
using Npgsql; using Pf2eDataScrapper.Model;
using Pf2eDataScrapper.Model.Enum;
using System.ComponentModel;
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
{ {
@@ -10,23 +12,49 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
public readonly JObject Input = input; public readonly JObject Input = input;
public abstract void Process(); protected DataBuilderHelper Helper = DataBuilderHelper.Instance;
public Entity Entity { get; set; } = new Entity();
public abstract EntityType Type { get; }
public abstract IEntity Object { get; }
public virtual void Process()
{
Entity.Id = Helper.NextId;
Entity.Type = Type;
Entity.Name = GetRequired<string>("name");
Entity.Img = GetRequired<string>("img");
Entity.Description = GetRequired<string>("system.description.value");
Entity.DescriptionGm = GetOptional<string>("system.description.gm");
Entity.IsTranslated = false;
Entity.IsChecked = false;
Entity.Slug = Helper.GenerateSlug(Entity.Name);
Object.Id = Entity.Id;
Context.Entities.Add(Entity);
// TODO Traits, Alias
}
public void Save() public void Save()
{ {
Context.SaveChanges(); Context.SaveChanges();
} }
public T GetRequired<T>(string path)
protected T GetRequired<T>(string path)
{ {
var token = Input.SelectToken(path) ?? throw new NullReferenceException($"'{path}' is null"); var token = Input.SelectToken(path) ?? throw new NullReferenceException($"'{path}' is null");
return token.ToObject<T>() ?? throw new NullReferenceException($"'{path}' is null"); return token.ToObject<T>() ?? throw new NullReferenceException($"'{path}' is null");
} }
protected T? GetOptional<T>(string path) public T? GetOptional<T>(string path)
{ {
var token = Input.SelectToken(path) ?? null; var token = Input.SelectToken(path) ?? null;
@@ -38,6 +66,39 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
return token.ToObject<T>() ?? default; return token.ToObject<T>() ?? default;
} }
public T EnumRequired<T>(string path) where T : Enum
{
return EnumOptional<T>(path) ?? throw new Exception($"Can't resolve Enum value for {typeof(T).Name} in path {path}");
}
public T? EnumOptional<T>(string path) where T : Enum
{
string? value = GetOptional<string>(path);
if (value == null)
{
return default;
}
foreach (var field in typeof(T).GetFields())
{
if (Attribute.GetCustomAttribute(field, typeof(PgNameAttribute)) is PgNameAttribute attribute)
{
if (attribute.PgName == value)
{
return (T)field.GetValue(null);
}
}
else
{
if (field.Name == value)
{
return (T)field.GetValue(null);
}
}
}
return default;
}
} }
} }
@@ -1,5 +1,4 @@
using Newtonsoft.Json.Linq; using Slugify;
using Npgsql;
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
{ {
@@ -7,76 +6,23 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
{ {
public Pf2eDatabase Database = Pf2eDatabase.Instance; public Pf2eDatabase Database = Pf2eDatabase.Instance;
public SlugHelper Slugger = new();
private DataBuilderHelper() private DataBuilderHelper()
{ {
} }
public NpgsqlCommand PrepareInsert(string table, Dictionary<string, object?> data, bool returnId) private int _id = 0;
public int NextId { get => ++_id; }
public string GenerateSlug(string name)
{ {
List<string> columns = []; return Slugger.GenerateSlug(name);
List<string> patterns = [];
foreach (var key in data.Keys)
{
columns.Add(key);
patterns.Add($":{key.ToUpper()}");
}
string dml = $"INSERT INTO {table} (\"{string.Join("\", \"", columns)}\") VALUES ({string.Join(", ", patterns)})" + (returnId ? " RETURNING id" : "");
NpgsqlCommand cmd = Database.GetCommand(dml);
foreach (var kvp in data)
{
cmd.Parameters.AddWithValue(":" + kvp.Key.ToUpper(), kvp.Value ?? DBNull.Value);
}
Console.WriteLine(cmd.CommandText);
return cmd;
} }
public int Insert(string table, Dictionary<string, object?> data)
{
var cmd = PrepareInsert(table, data, true);
return (int)(cmd.ExecuteScalar() ?? throw new Exception("Not a number"));
}
public void InsertBlind(string table, Dictionary<string, object?> data)
{
var cmd = PrepareInsert(table, data, false);
cmd.ExecuteNonQuery();
}
public static object? JsonGet(JObject root, string path) public readonly static DataBuilderHelper Instance = new();
{
var token = root.SelectToken(path);
if (token == null)
{
return null;
}
if (token.Type == JTokenType.String)
{
return token.ToString();
}
else if (token.Type == JTokenType.Integer)
{
return token.ToObject<int>();
}
else if (token.Type == JTokenType.Float)
{
return token.ToObject<float>();
}
else if (token.Type == JTokenType.Boolean)
{
return token.ToObject<bool>();
}
else
{
return token.ToString();
}
}
public static DataBuilderHelper Instance = new();
} }
} }
@@ -1,11 +1,10 @@
using System.Reflection; namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder
{ {
[AttributeUsage(AttributeTargets.Class)] [AttributeUsage(AttributeTargets.Class)]
internal class Pf2eTypeProcessor(string type) : Attribute internal class Pf2eTypeProcessor(string type, int priority = 0) : Attribute
{ {
public readonly string Type = type; public readonly string Type = type;
public readonly int Priority = priority;
} }
} }
@@ -1,40 +1,33 @@
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Pf2eDataScrapper.Model; using Pf2eDataScrapper.Model;
using Pf2eDataScrapper.Model.Enum; using Pf2eDataScrapper.Model.Enum;
using Slugify;
using static LinqToDB.Common.Configuration;
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder.Processors namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder.Processors
{ {
[Pf2eTypeProcessor("Item.condition")] [Pf2eTypeProcessor("Item.condition")]
internal class ConditionProcessor(JObject input) : AbstractProcessor(input) internal class ConditionProcessor(JObject input) : AbstractProcessor(input)
{ {
public override EntityType Type => EntityType.Condition;
public override Condition Object { get; } = new();
public override void Process() public override void Process()
{ {
base.Process();
JObject extra = new() JObject extra = new()
{
{ "duration", Input.SelectToken("duration") },
{ "overrides", Input.SelectToken("overrides") },
{ "references", Input.SelectToken("references") },
{ "value", Input.SelectToken("value") }
};
Condition condition = new()
{ {
Name = GetRequired<string>("name"), { "duration", Input.SelectToken("system.duration") },
Img = GetRequired<string>("img"), { "overrides", Input.SelectToken("system.overrides") },
Description = GetRequired<string>("system.description.value"), { "references", Input.SelectToken("system.references") },
DescriptionGm = GetOptional<string>("system.description.gm"), { "value", Input.SelectToken("system.value") }
Type = EntityType.Condition,
IsTranslated = false,
IsChecked = false,
// Group = GetOptional<string>("system.group");
Extra = extra.ToString(Newtonsoft.Json.Formatting.Indented)
}; };
condition.Slug = new SlugHelper().GenerateSlug(condition.Name);
Context.Conditions.Add(condition); Object.Extra = extra.ToString(Newtonsoft.Json.Formatting.Indented);
Object.Group = EnumOptional<ConditionGroup>("system.group");
Context.Conditions.Add(Object);
} }
} }
} }
@@ -1,5 +1,4 @@
using Konsole; using Konsole;
using Newtonsoft.Json.Linq;
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium; using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
using Pf2eDataScrapper.SchemaBuilder; using Pf2eDataScrapper.SchemaBuilder;
@@ -1,9 +1,4 @@
using System; using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Pf2eDataScrapper.SchemaBuilder; using Pf2eDataScrapper.SchemaBuilder;
using Pf2eDataScrapper.SchemaBuilder.Types; using Pf2eDataScrapper.SchemaBuilder.Types;
+4 -18
View File
@@ -1,28 +1,14 @@
using System; using Pf2eDataScrapper.Model.Enum;
using System.Collections.Generic;
using Pf2eDataScrapper.Model.Enum;
namespace Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
public partial class Action public partial class Action : IEntity
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = null!; public Entity Entity { get; set; } = null!;
public string Img { get; set; } = null!; // TODO ActionType
public EntityType Type { get; set; } = EntityType.Action;
public string Description { get; set; } = null!;
public string? DescriptionGm { get; set; }
public string Slug { get; set; } = null!;
public bool? IsTranslated { get; set; }
public bool? IsChecked { get; set; }
public int? Actions { get; set; } public int? Actions { get; set; }
+8 -22
View File
@@ -1,28 +1,14 @@
using System; using Pf2eDataScrapper.Model.Enum;
using System.Collections.Generic;
using Pf2eDataScrapper.Model.Enum;
namespace Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
public partial class Ancestry public partial class Ancestry : IEntity
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = null!; public Entity Entity { get; set; } = null!;
public string Img { get; set; } = null!; // TODO Size Vision
public EntityType Type { get; set; } = EntityType.Ancestry;
public string Description { get; set; } = null!;
public string? DescriptionGm { get; set; }
public string Slug { get; set; } = null!;
public bool? IsTranslated { get; set; }
public bool? IsChecked { get; set; }
public int Hp { get; set; } public int Hp { get; set; }
@@ -30,11 +16,11 @@ public partial class Ancestry
public int Speed { get; set; } public int Speed { get; set; }
public virtual ICollection<AncestryBoost> AncestryBoosts { get; set; } = new List<AncestryBoost>(); public virtual ICollection<AncestryBoost> AncestryBoosts { get; set; } = [];
public virtual ICollection<AncestryItem> AncestryItems { get; set; } = new List<AncestryItem>(); public virtual ICollection<AncestryItem> AncestryItems { get; set; } = [];
public virtual ICollection<AncestryLanguage> AncestryLanguages { get; set; } = new List<AncestryLanguage>(); public virtual ICollection<AncestryLanguage> AncestryLanguages { get; set; } = [];
public virtual ICollection<Heritage> Heritages { get; set; } = new List<Heritage>(); public virtual ICollection<Heritage> Heritages { get; set; } = [];
} }
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class AncestryBoost public partial class AncestryBoost
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class AncestryItem public partial class AncestryItem
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class AncestryLanguage public partial class AncestryLanguage
{ {
+2 -18
View File
@@ -1,28 +1,12 @@
using Pf2eDataScrapper.Model.Enum; using Pf2eDataScrapper.Model.Enum;
using System;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
public partial class Background public partial class Background : IEntity
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = null!; public Entity Entity { get; set; } = null!;
public string Img { get; set; } = null!;
public EntityType Type { get; set; } = EntityType.Background;
public string Description { get; set; } = null!;
public string? DescriptionGm { get; set; }
public string Slug { get; set; } = null!;
public bool? IsTranslated { get; set; }
public bool? IsChecked { get; set; }
public virtual ICollection<BackgroundBoost> BackgroundBoosts { get; set; } = new List<BackgroundBoost>(); public virtual ICollection<BackgroundBoost> BackgroundBoosts { get; set; } = new List<BackgroundBoost>();
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class BackgroundBoost public partial class BackgroundBoost
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class BackgroundItem public partial class BackgroundItem
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class BackgroundSkill public partial class BackgroundSkill
{ {
+3 -17
View File
@@ -1,28 +1,14 @@
using Pf2eDataScrapper.Model.Enum; using Pf2eDataScrapper.Model.Enum;
using System;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
public partial class CampaignFeature public partial class CampaignFeature : IEntity
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = null!; public Entity Entity { get; set; } = null!;
public string Img { get; set; } = null!; // TODO ActionType Category
public EntityType Type { get; set; } = EntityType.CampaignFeature;
public string Description { get; set; } = null!;
public string? DescriptionGm { get; set; }
public string Slug { get; set; } = null!;
public bool? IsTranslated { get; set; }
public bool? IsChecked { get; set; }
public int? Level { get; set; } public int? Level { get; set; }
+2 -18
View File
@@ -1,28 +1,12 @@
using Pf2eDataScrapper.Model.Enum; using Pf2eDataScrapper.Model.Enum;
using System;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
public partial class Class public partial class Class : IEntity
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = null!; public Entity Entity { get; set; } = null!;
public string Img { get; set; } = null!;
public EntityType Type { get; set; } = EntityType.Class;
public string Description { get; set; } = null!;
public string? DescriptionGm { get; set; }
public string Slug { get; set; } = null!;
public bool? IsTranslated { get; set; }
public bool? IsChecked { get; set; }
public int Hp { get; set; } public int Hp { get; set; }
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class ClassKeyAbility public partial class ClassKeyAbility
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class ClassProgression public partial class ClassProgression
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class ClassTraining public partial class ClassTraining
{ {
+4 -20
View File
@@ -1,30 +1,14 @@
using Pf2eDataScrapper.Model.Enum; using Pf2eDataScrapper.Model.Enum;
using System;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
public partial class Condition public partial class Condition : IEntity
{ {
public int Id { get; set; } = -1; public int Id { get; set; }
public string Name { get; set; } = null!; public Entity Entity { get; set; } = null!;
public string Img { get; set; } = null!; public ConditionGroup? Group { get; set; }
public EntityType Type { get; set; } = EntityType.Condition;
public string Description { get; set; } = null!;
public string? DescriptionGm { get; set; }
public string Slug { get; set; } = null!;
public bool? IsTranslated { get; set; }
public bool? IsChecked { get; set; }
public ConditionGroup Group { get; set; }
public string? Extra { get; set; } public string? Extra { get; set; }
} }
+3 -17
View File
@@ -1,28 +1,14 @@
using Pf2eDataScrapper.Model.Enum; using Pf2eDataScrapper.Model.Enum;
using System;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
public partial class Deity public partial class Deity : IEntity
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = null!; public Entity Entity { get; set; } = null!;
public string Img { get; set; } = null!; // TODO Category Font Sanctification
public EntityType Type { get; set; } = EntityType.Deity;
public string Description { get; set; } = null!;
public string? DescriptionGm { get; set; }
public string Slug { get; set; } = null!;
public bool? IsTranslated { get; set; }
public bool? IsChecked { get; set; }
public bool SanctificationMust { get; set; } public bool SanctificationMust { get; set; }
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class DeityAttribute public partial class DeityAttribute
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class DeityDomain public partial class DeityDomain
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class DeitySpell public partial class DeitySpell
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class DeityWeapon public partial class DeityWeapon
{ {
+6 -17
View File
@@ -1,16 +1,17 @@
using System; using Pf2eDataScrapper.Model.Enum;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
public partial class Entity public class Entity
{ {
public int Id { get; set; } = -1; public int Id { get; set; }
public string Name { get; set; } = null!; public string Name { get; set; } = null!;
public string Img { get; set; } = null!; public string Img { get; set; } = null!;
public EntityType Type { get; set; }
public string Description { get; set; } = null!; public string Description { get; set; } = null!;
public string? DescriptionGm { get; set; } public string? DescriptionGm { get; set; }
@@ -21,17 +22,5 @@ public partial class Entity
public bool? IsChecked { get; set; } public bool? IsChecked { get; set; }
public virtual ICollection<AncestryItem> AncestryItems { get; set; } = new List<AncestryItem>(); public virtual ICollection<Trait> Traits { get; set; } = [];
public virtual ICollection<BackgroundItem> BackgroundItems { get; set; } = new List<BackgroundItem>();
public virtual ICollection<ClassProgression> ClassProgressions { get; set; } = new List<ClassProgression>();
public virtual ICollection<EntityAlias> EntityAliases { get; set; } = new List<EntityAlias>();
public virtual ICollection<EntityExternal> EntityExternals { get; set; } = new List<EntityExternal>();
public virtual Frequency? Frequency { get; set; }
public virtual ICollection<Trait> Traits { get; set; } = new List<Trait>();
} }
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class EntityAlias public partial class EntityAlias
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class EntityExternal public partial class EntityExternal
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class EntityKeyword public partial class EntityKeyword
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class EntitySource public partial class EntitySource
{ {
+1 -5
View File
@@ -1,8 +1,4 @@
using Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
using System;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class ExternalTarget public partial class ExternalTarget
{ {
+3 -17
View File
@@ -1,28 +1,14 @@
using Pf2eDataScrapper.Model.Enum; using Pf2eDataScrapper.Model.Enum;
using System;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
public partial class Feat public partial class Feat : IEntity
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = null!; public Entity Entity { get; set; } = null!;
public string Img { get; set; } = null!; // TODO ActionType Category
public EntityType Type { get; set; } = EntityType.Feat;
public string Description { get; set; } = null!;
public string? DescriptionGm { get; set; }
public string Slug { get; set; } = null!;
public bool? IsTranslated { get; set; }
public bool? IsChecked { get; set; }
public int? Actions { get; set; } public int? Actions { get; set; }
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class FeatPrerequisite public partial class FeatPrerequisite
{ {
+1 -5
View File
@@ -1,8 +1,4 @@
using Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
using System;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class Frequency public partial class Frequency
{ {
+3 -20
View File
@@ -1,29 +1,12 @@
using Pf2eDataScrapper.Model; using Pf2eDataScrapper.Model.Enum;
using System;
using System.Collections.Generic;
using Pf2eDataScrapper.Model.Enum;
namespace Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
public partial class Heritage public partial class Heritage : IEntity
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = null!; public Entity Entity { get; set; } = null!;
public string Img { get; set; } = null!;
public EntityType Type { get; set; } = EntityType.Heritage;
public string Description { get; set; } = null!;
public string? DescriptionGm { get; set; }
public string Slug { get; set; } = null!;
public bool? IsTranslated { get; set; }
public bool? IsChecked { get; set; }
public int? AncestryId { get; set; } public int? AncestryId { get; set; }
+10
View File
@@ -0,0 +1,10 @@
namespace Pf2eDataScrapper.Model
{
internal interface IEntity
{
public int Id { get; set; }
public Entity Entity { get; set; }
}
}
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class Keyword public partial class Keyword
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class KeywordAlias public partial class KeywordAlias
{ {
+1 -5
View File
@@ -1,8 +1,4 @@
using Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
using System;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class Language public partial class Language
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class Source public partial class Source
{ {
+3 -19
View File
@@ -1,28 +1,12 @@
using System; using Pf2eDataScrapper.Model.Enum;
using System.Collections.Generic;
using Pf2eDataScrapper.Model.Enum;
namespace Pf2eDataScrapper.Model; namespace Pf2eDataScrapper.Model;
public partial class Spell public partial class Spell : IEntity
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } = null!; public Entity Entity { get; set; } = null!;
public string Img { get; set; } = null!;
public EntityType Type { get; set; } = EntityType.Spell;
public string Description { get; set; } = null!;
public string? DescriptionGm { get; set; }
public string Slug { get; set; } = null!;
public bool? IsTranslated { get; set; }
public bool? IsChecked { get; set; }
public int Level { get; set; } public int Level { get; set; }
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class SpellArea public partial class SpellArea
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class SpellDamage public partial class SpellDamage
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class SpellDefense public partial class SpellDefense
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class SpellRitual public partial class SpellRitual
{ {
+1 -4
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class Training public partial class Training
{ {
+3 -6
View File
@@ -1,7 +1,4 @@
using System; namespace Pf2eDataScrapper.Model;
using System.Collections.Generic;
namespace Pf2eDataScrapper.Model;
public partial class Trait public partial class Trait
{ {
@@ -9,7 +6,7 @@ public partial class Trait
public string Name { get; set; } = null!; public string Name { get; set; } = null!;
public string Description { get; set; } = null!; public string Slug { get; set; } = null!;
public virtual ICollection<Entity> Entities { get; set; } = new List<Entity>(); public string Description { get; set; } = null!;
} }
File diff suppressed because it is too large Load Diff
+4 -3
View File
@@ -139,7 +139,8 @@ namespace Pf2eDataScrapper.SchemaBuilder
/// <returns>Строковое представление элемента.</returns> /// <returns>Строковое представление элемента.</returns>
public override string ToString() public override string ToString()
{ {
var result = new Dictionary<string, string>() { var result = new Dictionary<string, string>()
{
["type"] = GetTypeName(), ["type"] = GetTypeName(),
["path"] = Path, ["path"] = Path,
["is_null"] = IsNullable ? "true" : "false", ["is_null"] = IsNullable ? "true" : "false",
@@ -204,7 +205,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
/// </summary> /// </summary>
/// <param name="input">Словарь данных.</param> /// <param name="input">Словарь данных.</param>
/// <returns>Строка форматированных данных</returns> /// <returns>Строка форматированных данных</returns>
public static string FormatYaml(params Dictionary<string, string>[] input) public static string FormatYaml(params List<Dictionary<string, string>> input)
{ {
var result = ""; var result = "";
@@ -218,7 +219,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
return result.Trim(); return result.Trim();
} }
public static Dictionary<string, string> MergeDictionaries(params Dictionary<string, string>[] input) public static Dictionary<string, string> MergeDictionaries(params List<Dictionary<string, string>> input)
{ {
var result = new Dictionary<string, string>(); var result = new Dictionary<string, string>();
@@ -114,7 +114,8 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
/// <returns>Словарь данных</returns> /// <returns>Словарь данных</returns>
public override Dictionary<string, string> GetYamlData() public override Dictionary<string, string> GetYamlData()
{ {
return new() { return new()
{
["schema"] = SchemaNode.FormatYaml(GetSchemaYaml()) ["schema"] = SchemaNode.FormatYaml(GetSchemaYaml())
}; };
} }
@@ -1,5 +1,4 @@
using System.Linq.Expressions; using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Linq;
namespace Pf2eDataScrapper.SchemaBuilder.Types namespace Pf2eDataScrapper.SchemaBuilder.Types
{ {
@@ -91,7 +90,8 @@ namespace Pf2eDataScrapper.SchemaBuilder.Types
} }
} }
return new() { return new()
{
["different_values"] = count.ToString() + ["different_values"] = count.ToString() +
((count == Root.Values) ? " (all different)" : "") + ((count == Root.Values) ? " (all different)" : "") +
((count == 1) ? " (all same)" : ""), ((count == 1) ? " (all same)" : ""),
+33 -31
View File
@@ -142,6 +142,7 @@ CREATE TYPE "trait_type" AS ENUM (
CREATE TABLE "trait" ( CREATE TABLE "trait" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, "id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"name" varchar NOT NULL, "name" varchar NOT NULL,
"slug" varchar NOT NULL,
"description" text NOT NULL, "description" text NOT NULL,
"type" trait_type NOT NULL "type" trait_type NOT NULL
); );
@@ -210,7 +211,7 @@ CREATE TYPE "spell_damage_kinds" AS ENUM (
); );
CREATE TABLE "spell" ( CREATE TABLE "spell" (
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, "id" int PRIMARY KEY,
"level" int NOT NULL, "level" int NOT NULL,
"cost" int NOT NULL, "cost" int NOT NULL,
"counteraction" bool NOT NULL, "counteraction" bool NOT NULL,
@@ -221,8 +222,8 @@ CREATE TABLE "spell" (
"target" varchar NOT NULL, "target" varchar NOT NULL,
"time" varchar NOT NULL, "time" varchar NOT NULL,
"can_heightening" bool NOT NULL "can_heightening" bool NOT NULL
) INHERITS ("entity"); );
-- ALTER TABLE "spell" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); ALTER TABLE "spell" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
CREATE TABLE "spell_area" ( CREATE TABLE "spell_area" (
"spell_id" int PRIMARY KEY, "spell_id" int PRIMARY KEY,
@@ -287,27 +288,27 @@ CREATE TYPE "ancestry_vision" AS ENUM (
); );
CREATE TABLE "action" ( CREATE TABLE "action" (
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, "id" int PRIMARY KEY,
"action_type" action_type NOT NULL, "action_type" action_type NOT NULL,
"actions" int, "actions" int,
"category" action_category, "category" action_category,
"death_note" bool, "death_note" bool,
"extra" text "extra" text
) INHERITS ("entity"); );
-- ALTER TABLE "action" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); ALTER TABLE "action" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
-- Ancestry -- Ancestry
CREATE TABLE "ancestry" ( CREATE TABLE "ancestry" (
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, "id" int PRIMARY KEY,
"hp" int NOT NULL, "hp" int NOT NULL,
"reach" int NOT NULL, "reach" int NOT NULL,
"size" enum_size NOT NULL, "size" enum_size NOT NULL,
"speed" int NOT NULL, "speed" int NOT NULL,
"vision" ancestry_vision NOT NULL "vision" ancestry_vision NOT NULL
) INHERITS ("entity"); );
-- ALTER TABLE "ancestry" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); ALTER TABLE "ancestry" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
CREATE TABLE "ancestry_languages" ( CREATE TABLE "ancestry_languages" (
"ancestry_id" int, "ancestry_id" int,
@@ -339,9 +340,9 @@ ALTER TABLE "ancestry_items" ADD FOREIGN KEY ("item_id") REFERENCES "entity" ("i
-- Background -- Background
CREATE TABLE "background" ( CREATE TABLE "background" (
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY "id" int PRIMARY KEY
) INHERITS ("entity"); );
-- ALTER TABLE "background" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); ALTER TABLE "background" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
CREATE TABLE "background_items" ( CREATE TABLE "background_items" (
"background_id" int, "background_id" int,
@@ -380,15 +381,15 @@ CREATE TYPE "campaign_feature_category" AS ENUM (
); );
CREATE TABLE "campaign_feature" ( CREATE TABLE "campaign_feature" (
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, "id" int PRIMARY KEY,
"level" int, "level" int,
"action_type" action_type NOT NULL, "action_type" action_type NOT NULL,
"actions" int NOT NULL, "actions" int NOT NULL,
"category" campaign_feature_category NOT NULL, "category" campaign_feature_category NOT NULL,
"prerequisites" varchar, "prerequisites" varchar,
"extra" text "extra" text
) INHERITS ("entity"); );
-- ALTER TABLE "campaign_feature" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); ALTER TABLE "campaign_feature" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
-- Class -- Class
@@ -404,13 +405,13 @@ CREATE TYPE "class_progression_type" AS ENUM (
); );
CREATE TABLE "class" ( CREATE TABLE "class" (
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, "id" int PRIMARY KEY,
"hp" int NOT NULL, "hp" int NOT NULL,
"perception" int NOT NULL, "perception" int NOT NULL,
"spellcasting" bool NOT NULL, "spellcasting" bool NOT NULL,
"additionalTrainedSkills" int NOT NULL "additionalTrainedSkills" int NOT NULL
) INHERITS ("entity"); );
-- ALTER TABLE "class" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); ALTER TABLE "class" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
CREATE TABLE "class_key_abilities" ( CREATE TABLE "class_key_abilities" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, "id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
@@ -452,11 +453,11 @@ CREATE TYPE "condition_group" AS ENUM (
); );
CREATE TABLE "condition" ( CREATE TABLE "condition" (
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, "id" int PRIMARY KEY,
"group" condition_group, "group" condition_group,
"extra" text "extra" text
) INHERITS ("entity"); );
-- ALTER TABLE "condition" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); ALTER TABLE "condition" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
-- Deity -- Deity
@@ -483,13 +484,13 @@ CREATE TYPE "deity_sanctification" AS ENUM (
); );
CREATE TABLE "deity" ( CREATE TABLE "deity" (
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, "id" int PRIMARY KEY,
"category" deity_category NOT NULL, "category" deity_category NOT NULL,
"font" deity_fonts NOT NULL, "font" deity_fonts NOT NULL,
"sanctification_must" bool NOT NULL, "sanctification_must" bool NOT NULL,
"sanctification_type" deity_sanctification NOT NULL "sanctification_type" deity_sanctification NOT NULL
) INHERITS ("entity"); );
-- ALTER TABLE "deity" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); ALTER TABLE "deity" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
CREATE TABLE "deity_attributes" ( CREATE TABLE "deity_attributes" (
"deity_id" int, "deity_id" int,
@@ -549,7 +550,7 @@ CREATE TYPE "feat_category" AS ENUM (
); );
CREATE TABLE "feat" ( CREATE TABLE "feat" (
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, "id" int PRIMARY KEY,
"action_type" action_type NOT NULL, "action_type" action_type NOT NULL,
"actions" int, "actions" int,
"category" feat_category NOT NULL, "category" feat_category NOT NULL,
@@ -559,8 +560,8 @@ CREATE TABLE "feat" (
"location" varchar(12), "location" varchar(12),
"only_level_1" bool, "only_level_1" bool,
"extra" text "extra" text
) INHERITS ("entity"); );
-- ALTER TABLE "feat" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); ALTER TABLE "feat" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
CREATE TABLE "feat_prerequisites" ( CREATE TABLE "feat_prerequisites" (
"id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, "id" INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
@@ -573,10 +574,10 @@ ALTER TABLE "feat_prerequisites" ADD FOREIGN KEY ("feat_id") REFERENCES "feat" (
-- Heritage -- Heritage
CREATE TABLE "heritage" ( CREATE TABLE "heritage" (
"id" int DEFAULT nextval('entity_sequence') PRIMARY KEY, "id" int PRIMARY KEY,
"ancestry_id" int "ancestry_id" int
) INHERITS ("entity"); );
-- ALTER TABLE "heritage" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id"); ALTER TABLE "heritage" ADD FOREIGN KEY ("id") REFERENCES "entity" ("id");
ALTER TABLE "heritage" ADD FOREIGN KEY ("ancestry_id") REFERENCES "ancestry" ("id"); ALTER TABLE "heritage" ADD FOREIGN KEY ("ancestry_id") REFERENCES "ancestry" ("id");
@@ -599,6 +600,7 @@ $func$;
---------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION f_drop_tables() CREATE OR REPLACE FUNCTION f_drop_tables()
RETURNS void RETURNS void
LANGUAGE plpgsql AS LANGUAGE plpgsql AS
@@ -616,7 +618,7 @@ $func$;
---------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION f_drop_tables(_username text) CREATE OR REPLACE FUNCTION f_permission_tables(_username text)
RETURNS void RETURNS void
LANGUAGE plpgsql AS LANGUAGE plpgsql AS
$func$ $func$
+2 -3
View File
@@ -14,8 +14,6 @@ Table entity {
is_translated bool [default: false, note: "Первичный импорт идёт из англоязычного источника, перевод приходит вторым"] is_translated bool [default: false, note: "Первичный импорт идёт из англоязычного источника, перевод приходит вторым"]
is_checked bool [default: false, note: "Флаг, указывающий, что перевод был проверен вручную и не требует обновления парсером"] is_checked bool [default: false, note: "Флаг, указывающий, что перевод был проверен вручную и не требует обновления парсером"]
} }
Enum entity_type { Enum entity_type {
action action
@@ -98,6 +96,7 @@ Table entity_external {
Table trait { Table trait {
id int [pk, increment] id int [pk, increment]
name varchar [not null] name varchar [not null]
slug varchar [not null]
description text [not null] description text [not null]
type trait_type [not null] type trait_type [not null]
} }
@@ -369,7 +368,7 @@ Enum class_progression_type {
Table condition { Table condition {
id int [pk, ref: - entity.id] id int [pk, ref: - entity.id]
group condition_group [null] group condition_group [null, note: "{}.group"]
extra text [null, note: "json для того, что надо рассмотреть"] extra text [null, note: "json для того, что надо рассмотреть"]