Обработка через CSharper

This commit is contained in:
2025-04-24 18:10:05 +04:00
parent cc7e97b6ff
commit 7dcf582c3e
89 changed files with 377 additions and 324 deletions
+13
View File
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"csharpier": {
"version": "1.0.0",
"commands": [
"csharpier"
],
"rollForward": false
}
}
}
+6 -6
View File
@@ -2,16 +2,20 @@
using Slugify; using Slugify;
namespace Pf2eDataScrapper.Importers; namespace Pf2eDataScrapper.Importers;
public class DatabaseHelper public class DatabaseHelper
{ {
public Pf2eDbContext Context = new(); public Pf2eDbContext Context = new();
public SlugHelper Slugger = new(); public SlugHelper Slugger = new();
private int _id = 0; private int _id = 0;
public int NextEntityId { get => ++_id; set => _id = value; } public int NextEntityId
{
get => ++_id;
set => _id = value;
}
private DatabaseHelper() private DatabaseHelper()
{ {
@@ -23,11 +27,7 @@ public class DatabaseHelper
return Slugger.GenerateSlug(name); return Slugger.GenerateSlug(name);
} }
public static readonly DatabaseHelper Instance = new(); public static readonly DatabaseHelper Instance = new();
public static readonly Pf2eDbContext DbContext = Instance.Context; public static readonly Pf2eDbContext DbContext = Instance.Context;
} }
@@ -10,7 +10,8 @@ internal class AonprdImporter : AbstractImporter
public override string Slug => "aonprd"; public override string Slug => "aonprd";
public override AbstractImporterRepository Repository => new AonprdRepository(this, "https://elasticsearch.aonprd.com"); public override AbstractImporterRepository Repository =>
new AonprdRepository(this, "https://elasticsearch.aonprd.com");
public AonprdLoader Loader { get; } public AonprdLoader Loader { get; }
@@ -19,7 +19,7 @@ internal class AonprdLoader(AonprdImporter importer)
foreach (KeyValuePair<string, JToken?> kvp in indexJson) foreach (KeyValuePair<string, JToken?> kvp in indexJson)
{ {
string file = kvp.Key.ToString(); string file = kvp.Key.ToString();
JArray items = (JArray) kvp.Value!; JArray items = (JArray)kvp.Value!;
foreach (JToken item in items) foreach (JToken item in items)
{ {
@@ -54,7 +54,7 @@ internal class AonprdLoader(AonprdImporter importer)
continue; continue;
} }
LoaderEntry entry = new(id, file, (JObject) item); LoaderEntry entry = new(id, file, (JObject)item);
if (types.Contains(entry.Type)) if (types.Contains(entry.Type))
{ {
@@ -64,7 +64,6 @@ internal class AonprdLoader(AonprdImporter importer)
} }
} }
public class LoaderEntry(string id, string file, JObject itemJson) : AonprdReference(id, file) public class LoaderEntry(string id, string file, JObject itemJson) : AonprdReference(id, file)
{ {
public JObject Json { get; } = itemJson; public JObject Json { get; } = itemJson;
@@ -4,7 +4,8 @@ using Pf2eDataScrapper.Importers.Repositories;
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd; namespace Pf2eDataScrapper.Importers.Implementations.Aonprd;
internal class AonprdRepository(AbstractImporter importer, string searchUrl) : AbstractImporterRepository(importer) internal class AonprdRepository(AbstractImporter importer, string searchUrl)
: AbstractImporterRepository(importer)
{ {
public readonly string SearchUrl = searchUrl; public readonly string SearchUrl = searchUrl;
@@ -24,7 +25,6 @@ internal class AonprdRepository(AbstractImporter importer, string searchUrl) : A
return reader.ReadToEnd(); return reader.ReadToEnd();
} }
public override void Update() public override void Update()
{ {
if (CheckRevision()) if (CheckRevision())
@@ -33,7 +33,9 @@ internal class AonprdRepository(AbstractImporter importer, string searchUrl) : A
return; return;
} }
Console.WriteLine($"Данные Aonprd устарели, обновляем {RepositoryDirPath} до ревизии {Revision}..."); Console.WriteLine(
$"Данные Aonprd устарели, обновляем {RepositoryDirPath} до ревизии {Revision}..."
);
if (Directory.Exists(RepositoryDirPath)) if (Directory.Exists(RepositoryDirPath))
{ {
@@ -63,7 +65,6 @@ internal class AonprdRepository(AbstractImporter importer, string searchUrl) : A
WriteFile($"{fileName}.json", fileContent); WriteFile($"{fileName}.json", fileContent);
} }
bar.Refresh(indexJson.Count, "Готово!"); bar.Refresh(indexJson.Count, "Готово!");
} }
@@ -75,7 +76,10 @@ internal class AonprdRepository(AbstractImporter importer, string searchUrl) : A
{ {
JObject page = JObject.Parse(Load("/aon/_doc/feat-1")); JObject page = JObject.Parse(Load("/aon/_doc/feat-1"));
Revision = Convert.ToInt32(page.SelectToken("_index")?.ToObject<string>()?.Replace("aon", "") ?? throw new Exception("Can't get revision")); Revision = Convert.ToInt32(
page.SelectToken("_index")?.ToObject<string>()?.Replace("aon", "")
?? throw new Exception("Can't get revision")
);
string revisionFile = Path.Combine(RepositoryDirPath, "revision.txt"); string revisionFile = Path.Combine(RepositoryDirPath, "revision.txt");
if (!File.Exists(revisionFile)) if (!File.Exists(revisionFile))
@@ -19,13 +19,10 @@ internal class AonprdCompendium
} }
public int Count() => Types.Values.Sum(t => t.Count); public int Count() => Types.Values.Sum(t => t.Count);
public int Count(IEnumerable<string> types) => Types.Values
.Where(t => types.Contains(t.Type))
.Sum(t => t.Count);
public IEnumerable<string> Files(IEnumerable<string> types) => Types.Values public int Count(IEnumerable<string> types) =>
.Where(t => types.Contains(t.Type)) Types.Values.Where(t => types.Contains(t.Type)).Sum(t => t.Count);
.SelectMany(t => t.Files)
.Distinct();
public IEnumerable<string> Files(IEnumerable<string> types) =>
Types.Values.Where(t => types.Contains(t.Type)).SelectMany(t => t.Files).Distinct();
} }
@@ -12,7 +12,11 @@ internal class AonprdReference(string id, string file)
{ {
static string? subType(string type, string cat) static string? subType(string type, string cat)
{ {
return type.StartsWith($"{cat}-") && type != cat ? type.EndsWith("-bonus") ? $"{cat}-bonus" : $"{cat}-sub" : null; return type.StartsWith($"{cat}-") && type != cat
? type.EndsWith("-bonus")
? $"{cat}-bonus"
: $"{cat}-sub"
: null;
} }
string type = string.Join('-', id.Split('-')[0..^1]); string type = string.Join('-', id.Split('-')[0..^1]);
@@ -6,7 +6,8 @@ internal class AonprdType(string type)
public readonly List<AonprdReference> Items = []; public readonly List<AonprdReference> Items = [];
public AonprdType(AonprdReference reference) : this(reference.Type) public AonprdType(AonprdReference reference)
: this(reference.Type)
{ {
Items.Add(reference); Items.Add(reference);
} }
@@ -34,9 +34,19 @@ internal class AonprdDataBuilder(AonprdLoader loader)
{ {
Console.WriteLine("Building data..."); Console.WriteLine("Building data...");
ConcurrentWriter window = new Window(0, 0, Console.WindowWidth, Console.WindowHeight).Concurrent(); ConcurrentWriter window = new Window(
0,
0,
Console.WindowWidth,
Console.WindowHeight
).Concurrent();
IConsole bars = window.OpenBox("Progress", Console.WindowWidth, 4, new BoxStyle { Body = Colors.WhiteOnBlack }); IConsole bars = window.OpenBox(
"Progress",
Console.WindowWidth,
4,
new BoxStyle { Body = Colors.WhiteOnBlack }
);
Window output = new(0, 4, Console.WindowWidth, Console.WindowHeight - 4, window); Window output = new(0, 4, Console.WindowWidth, Console.WindowHeight - 4, window);
@@ -56,7 +66,7 @@ internal class AonprdDataBuilder(AonprdLoader loader)
bar2.Refresh(j++, $"{entry.Id}"); bar2.Refresh(j++, $"{entry.Id}");
AonprdProcessorInput input = new(entry.Json); AonprdProcessorInput input = new(entry.Json);
AbstractProcessor processor = (AbstractProcessor) item.Constructor.Invoke([input]); AbstractProcessor processor = (AbstractProcessor)item.Constructor.Invoke([input]);
try try
{ {
@@ -90,5 +90,4 @@ internal class AonprdProcessorInput(JObject input) : ProcessorInput(input)
public bool IsReaction = false; public bool IsReaction = false;
public bool IsFreeAction = false; public bool IsFreeAction = false;
} }
} }
@@ -9,13 +9,12 @@ public class AonprdProcessorAttribute(string name, string type, string[] depende
public readonly IEnumerable<string> Dependencies = dependencies; public readonly IEnumerable<string> Dependencies = dependencies;
public AonprdProcessorAttribute(string type) : this(type, type, ["trait", "source"]) public AonprdProcessorAttribute(string type)
{ : this(type, type, ["trait", "source"]) { }
}
public AonprdProcessorAttribute(string type, string[] dependencies) : this(type, type, dependencies) public AonprdProcessorAttribute(string type, string[] dependencies)
{ : this(type, type, dependencies) { }
}
public AonprdProcessorAttribute(string name, string type) : this(name, type, ["trait", "source"]) public AonprdProcessorAttribute(string name, string type)
{ : this(name, type, ["trait", "source"]) { }
}
} }
@@ -26,18 +26,25 @@ internal class AonprdProcessorCollection
if (!type.IsSubclassOf(typeof(AbstractProcessor))) if (!type.IsSubclassOf(typeof(AbstractProcessor)))
{ {
throw new Exception($"'AonprdProcessor' attribute should only be applied to children of 'AbstractProcessor' class. '{type.FullName}' is not."); throw new Exception(
$"'AonprdProcessor' attribute should only be applied to children of 'AbstractProcessor' class. '{type.FullName}' is not."
);
} }
AonprdProcessorAttribute attribute = type.GetCustomAttribute<AonprdProcessorAttribute>()!; AonprdProcessorAttribute attribute =
type.GetCustomAttribute<AonprdProcessorAttribute>()!;
ConstructorInfo constructor = type.GetConstructor([typeof(AonprdProcessorInput)])!; ConstructorInfo constructor = type.GetConstructor([typeof(AonprdProcessorInput)])!;
ProcessorItem? collision = Items.FirstOrDefault(i => i.Attribute.Name == attribute.Name); ProcessorItem? collision = Items.FirstOrDefault(i =>
i.Attribute.Name == attribute.Name
);
if (collision is not null) if (collision is not null)
{ {
throw new Exception($"Multiply attributes 'AonprdProcessor' have same name '{attribute.Name}'." + throw new Exception(
$" They are added to classes: '{type.FullName}' and '{collision.Constructor.DeclaringType!.FullName}'"); $"Multiply attributes 'AonprdProcessor' have same name '{attribute.Name}'."
+ $" They are added to classes: '{type.FullName}' and '{collision.Constructor.DeclaringType!.FullName}'"
);
} }
Items.Add(new ProcessorItem(attribute, constructor)); Items.Add(new ProcessorItem(attribute, constructor));
@@ -57,7 +64,9 @@ internal class AonprdProcessorCollection
continue; continue;
} }
IEnumerable<int> dependencyPriorities = item.Attribute.Dependencies.Select(d => priorities.TryGetValue(d, out int value) ? value : -1); IEnumerable<int> dependencyPriorities = item.Attribute.Dependencies.Select(d =>
priorities.TryGetValue(d, out int value) ? value : -1
);
if (dependencyPriorities.Any(p => p == -1)) if (dependencyPriorities.Any(p => p == -1))
{ {
@@ -81,8 +90,4 @@ internal class AonprdProcessorCollection
yield return item; yield return item;
} }
} }
} }
@@ -26,9 +26,6 @@ internal class TraitProcessor(AonprdProcessorInput input) : AbstractProcessor(in
// Необходимо пропускать // Необходимо пропускать
} }
protected override string GetDescription() protected override string GetDescription() =>
=> base.GetDescription() + AddedDescription([ base.GetDescription() + AddedDescription(["summary_markdown", "search_markdown"]);
"summary_markdown",
"search_markdown"
]);
} }
@@ -22,7 +22,7 @@ internal class AonprdSchemaBuilder(AonprdLoader loader)
value = new SchemaNode() value = new SchemaNode()
{ {
// Resolver = Resolver, // Resolver = Resolver,
Path = key Path = key,
}; };
Schemas[key] = value; Schemas[key] = value;
} }
@@ -64,7 +64,11 @@ internal class AonprdSchemaBuilder(AonprdLoader loader)
protected void SaveSchema(string dir, string name, SchemaNode schema) protected void SaveSchema(string dir, string name, SchemaNode schema)
{ {
char[] invalids = Path.GetInvalidFileNameChars(); char[] invalids = Path.GetInvalidFileNameChars();
string fileName = string.Join("_", schema.Path.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.'); string fileName = string.Join(
"_",
schema.Path.Split(invalids, StringSplitOptions.RemoveEmptyEntries)
)
.TrimEnd('.');
string path = Path.Combine(dir, fileName + ".yaml"); string path = Path.Combine(dir, fileName + ".yaml");
string? dirPath = Path.GetDirectoryName(path); string? dirPath = Path.GetDirectoryName(path);
@@ -77,10 +81,15 @@ internal class AonprdSchemaBuilder(AonprdLoader loader)
schema.Beautify(); schema.Beautify();
writer.WriteLine(SchemaNode.FormatYaml(new Dictionary<string, string>() writer.WriteLine(
SchemaNode.FormatYaml(
new Dictionary<string, string>()
{ {
["name"] = name, ["name"] = name,
["values"] = schema.Values.ToString() ["values"] = schema.Values.ToString(),
}, schema.Types[0].GetYamlData())); },
schema.Types[0].GetYamlData()
)
);
} }
} }
@@ -13,5 +13,5 @@ internal enum CompendiumDocumentType
Macro, Macro,
Playlist, Playlist,
RollTable, RollTable,
Scene Scene,
} }
@@ -60,7 +60,8 @@ internal class CompendiumFolder
IsContained = false; IsContained = false;
} }
Type = (CompendiumDocumentType) Enum.Parse(typeof(CompendiumDocumentType), json["type"]!.ToString()); Type = (CompendiumDocumentType)
Enum.Parse(typeof(CompendiumDocumentType), json["type"]!.ToString());
} }
/// <summary> /// <summary>
@@ -38,15 +38,12 @@ internal class CompendiumLoader(Pf2EFoundryImporter importer)
{ {
foreach (JToken token in folders) foreach (JToken token in folders)
{ {
JObject obj = (JObject) token; JObject obj = (JObject)token;
string id = $"folder-{_folderCount++}"; string id = $"folder-{_folderCount++}";
string name = obj["name"]!.ToString(); string name = obj["name"]!.ToString();
CompendiumFolder folder = new(id, name) CompendiumFolder folder = new(id, name) { Parent = parent };
{
Parent = parent
};
Collection.Add(folder); Collection.Add(folder);
if (obj.TryGetValue("packs", out JToken? packs)) if (obj.TryGetValue("packs", out JToken? packs))
@@ -65,7 +62,7 @@ internal class CompendiumLoader(Pf2EFoundryImporter importer)
if (obj.TryGetValue("folders", out JToken? innerFolders)) if (obj.TryGetValue("folders", out JToken? innerFolders))
{ {
ProcessPackFolders((JArray) innerFolders!, folder); ProcessPackFolders((JArray)innerFolders!, folder);
} }
} }
@@ -82,14 +79,14 @@ internal class CompendiumLoader(Pf2EFoundryImporter importer)
foreach (JToken pack in systemData["packs"]!) foreach (JToken pack in systemData["packs"]!)
{ {
CompendiumFolder folder = new((JObject) pack); CompendiumFolder folder = new((JObject)pack);
Collection.Add(folder); Collection.Add(folder);
} }
if (systemData.TryGetValue("packFolders", out JToken? packFolders)) if (systemData.TryGetValue("packFolders", out JToken? packFolders))
{ {
ProcessPackFolders((JArray) packFolders, null); ProcessPackFolders((JArray)packFolders, null);
} }
// Поиск _folders.json // Поиск _folders.json
@@ -102,10 +99,15 @@ internal class CompendiumLoader(Pf2EFoundryImporter importer)
string dirPath = Path.Combine(Importer.Dir, parent.Path); string dirPath = Path.Combine(Importer.Dir, parent.Path);
ItemCount += Directory.GetFiles(dirPath, "*.json", SearchOption.AllDirectories) ItemCount += Directory.GetFiles(dirPath, "*.json", SearchOption.AllDirectories).Length;
.Length;
foreach (string foldersFilePath in Directory.GetFiles(dirPath, "_folders.json", SearchOption.AllDirectories)) foreach (
string foldersFilePath in Directory.GetFiles(
dirPath,
"_folders.json",
SearchOption.AllDirectories
)
)
{ {
ItemCount--; ItemCount--;
using StreamReader file = new(foldersFilePath); using StreamReader file = new(foldersFilePath);
@@ -113,7 +115,7 @@ internal class CompendiumLoader(Pf2EFoundryImporter importer)
foreach (JToken pack in data) foreach (JToken pack in data)
{ {
CompendiumFolder folder = new((JObject) pack) { Parent = parent }; CompendiumFolder folder = new((JObject)pack) { Parent = parent };
Collection.Add(folder); Collection.Add(folder);
} }
} }
@@ -135,7 +137,13 @@ internal class CompendiumLoader(Pf2EFoundryImporter importer)
{ {
string dirPath = Path.Combine(Importer.Dir, folder.Path!); string dirPath = Path.Combine(Importer.Dir, folder.Path!);
foreach (string filePath in Directory.GetFiles(dirPath, "*.json", SearchOption.AllDirectories)) foreach (
string filePath in Directory.GetFiles(
dirPath,
"*.json",
SearchOption.AllDirectories
)
)
{ {
FileInfo file = new(filePath); FileInfo file = new(filePath);
@@ -163,7 +171,8 @@ internal class CompendiumLoader(Pf2EFoundryImporter importer)
public FileInfo File { get; } = file; public FileInfo File { get; } = file;
public JObject Json { get; } = itemJson; public JObject Json { get; } = itemJson;
public CompendiumFolder Folder { get; } = folder; public CompendiumFolder Folder { get; } = folder;
public string Type { get; } = itemJson["type"]?.ToString() public string Type { get; } =
itemJson["type"]?.ToString()
?? throw new Exception($"Expected to have `type` field in file {file.FullName}"); ?? throw new Exception($"Expected to have `type` field in file {file.FullName}");
} }
} }
@@ -1,4 +1,6 @@
using Newtonsoft.Json.Linq; using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json.Linq;
using Pf2eModel; using Pf2eModel;
using Pf2eModel.Model; using Pf2eModel.Model;
using Pf2eModel.Model.Base; using Pf2eModel.Model.Base;
@@ -7,8 +9,6 @@ using Pf2eModel.Model.Base.Targets;
using Pf2eModel.Model.Common.I18n; using Pf2eModel.Model.Common.I18n;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure; using Pf2eModel.Model.Structure;
using System.Security.Cryptography;
using System.Text;
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder; namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder;
@@ -39,7 +39,10 @@ internal abstract class AbstractProcessor(ProcessorInput input)
Entity.IsChecked = false; Entity.IsChecked = false;
Entity.Slug = Helper.GenerateSlug(Entity.Name[LocaleType.English]); Entity.Slug = Helper.GenerateSlug(Entity.Name[LocaleType.English]);
Entity.Rarity = Input.EnumOptional<EntityRarity>("system.traits.rarity", EntityRarity.Common); Entity.Rarity = Input.EnumOptional<EntityRarity>(
"system.traits.rarity",
EntityRarity.Common
);
Object.Id = Entity.Id; Object.Id = Entity.Id;
@@ -64,7 +67,7 @@ internal abstract class AbstractProcessor(ProcessorInput input)
Source = GetSource(Input.GetRequired<string>("system.publication.title")), Source = GetSource(Input.GetRequired<string>("system.publication.title")),
Suffix = "", Suffix = "",
IsRemaster = Input.GetRequired<bool>("system.publication.remaster") IsRemaster = Input.GetRequired<bool>("system.publication.remaster"),
}; };
Context.EntitySources.Add(source); Context.EntitySources.Add(source);
@@ -74,7 +77,7 @@ internal abstract class AbstractProcessor(ProcessorInput input)
Entity = Entity, Entity = Entity,
Target = GetTarget(), Target = GetTarget(),
Suffix = Input.GetRequired<string>("_id"), Suffix = Input.GetRequired<string>("_id"),
Md5 = Md5(Input.Input.ToString()) Md5 = Md5(Input.Input.ToString()),
}; };
Context.EntityExternals.Add(external); Context.EntityExternals.Add(external);
@@ -97,7 +100,6 @@ internal abstract class AbstractProcessor(ProcessorInput input)
Context.SaveChanges(); Context.SaveChanges();
} }
protected Source GetSource(string name) protected Source GetSource(string name)
{ {
Source? source = Context.Sources.FirstOrDefault(s => s.Name == name); Source? source = Context.Sources.FirstOrDefault(s => s.Name == name);
@@ -107,10 +109,7 @@ internal abstract class AbstractProcessor(ProcessorInput input)
return source; return source;
} }
source = new() source = new() { Name = name };
{
Name = name
};
Context.Sources.Add(source); Context.Sources.Add(source);
return source; return source;
@@ -140,7 +139,9 @@ internal abstract class AbstractProcessor(ProcessorInput input)
protected IEnumerable<Trait> GetTraits(IEnumerable<string> names) protected IEnumerable<Trait> GetTraits(IEnumerable<string> names)
{ {
List<Trait> result = Context.Traits.Where(t => names.Contains(t.Entity.ToString())).ToList(); List<Trait> result = Context
.Traits.Where(t => names.Contains(t.Entity.ToString()))
.ToList();
foreach (string name in names) foreach (string name in names)
{ {
@@ -1,7 +1,7 @@
using Konsole; using System.Reflection;
using Konsole;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium; using Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium;
using System.Reflection;
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder; namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.DataBuilder;
@@ -42,7 +42,9 @@ internal class PF2eFoundryDataBuilder
public AbstractProcessor? GetProcessor(string type, JObject input) public AbstractProcessor? GetProcessor(string type, JObject input)
{ {
return Processors.TryGetValue(type, out ConstructorInfo? constructor) ? (AbstractProcessor) constructor.Invoke([new ProcessorInput(input)]) : null; return Processors.TryGetValue(type, out ConstructorInfo? constructor)
? (AbstractProcessor)constructor.Invoke([new ProcessorInput(input)])
: null;
} }
public void TruncateTables() public void TruncateTables()
@@ -65,7 +67,10 @@ internal class PF2eFoundryDataBuilder
{ {
bar.Refresh(i++, $"{entry.Folder.Name}/{entry.File.Name}"); bar.Refresh(i++, $"{entry.Folder.Name}/{entry.File.Name}");
AbstractProcessor? processor = GetProcessor($"{entry.Folder.Type}.{entry.Type}", entry.Json); AbstractProcessor? processor = GetProcessor(
$"{entry.Folder.Type}.{entry.Type}",
entry.Json
);
if (processor is null) if (processor is null)
{ {
continue; continue;
@@ -19,10 +19,7 @@ internal class ActionProcessor(ProcessorInput input) : AbstractProcessor(input)
Object.Actions = GetOptional<int>("system.actions.value"); Object.Actions = GetOptional<int>("system.actions.value");
Object.DeathNote = GetOptional<bool>("system.deathNote"); Object.DeathNote = GetOptional<bool>("system.deathNote");
*/ */
JObject extra = new() JObject extra = new() { { "selfEffect", Input.Input.SelectToken("system.selfEffect") } };
{
{ "selfEffect", Input.Input.SelectToken("system.selfEffect") }
};
Object.Extra = extra.ToString(Newtonsoft.Json.Formatting.None); Object.Extra = extra.ToString(Newtonsoft.Json.Formatting.None);
@@ -20,7 +20,7 @@ internal class ConditionProcessor(ProcessorInput input) : AbstractProcessor(inpu
{ "duration", Input.Input.SelectToken("system.duration") }, { "duration", Input.Input.SelectToken("system.duration") },
{ "overrides", Input.Input.SelectToken("system.overrides") }, { "overrides", Input.Input.SelectToken("system.overrides") },
{ "references", Input.Input.SelectToken("system.references") }, { "references", Input.Input.SelectToken("system.references") },
{ "value", Input.Input.SelectToken("system.value") } { "value", Input.Input.SelectToken("system.value") },
}; };
Object.Extra = extra.ToString(Newtonsoft.Json.Formatting.None); Object.Extra = extra.ToString(Newtonsoft.Json.Formatting.None);
@@ -19,7 +19,8 @@ internal class Pf2EFoundryImporter : AbstractImporter
/// </summary> /// </summary>
public override string Slug => "pf2e"; public override string Slug => "pf2e";
public override AbstractImporterRepository Repository => new GitRepository(this, "https://github.com/foundryvtt/pf2e.git"); public override AbstractImporterRepository Repository =>
new GitRepository(this, "https://github.com/foundryvtt/pf2e.git");
/// <summary> /// <summary>
/// Загрузчик данных компендиума. /// Загрузчик данных компендиума.
@@ -35,17 +35,23 @@ internal class CompendiumSchemaBuilder(CompendiumLoader loader)
/// </summary> /// </summary>
public Dictionary<string, SchemaNode> TypeSchemas = []; public Dictionary<string, SchemaNode> TypeSchemas = [];
private readonly string[] _equipmentTypes = ["equipment", "armor", "backpack", "consumable", "kit", "shield", "treasure", "weapon"]; private readonly string[] _equipmentTypes =
[
"equipment",
"armor",
"backpack",
"consumable",
"kit",
"shield",
"treasure",
"weapon",
];
private SchemaNode GetPackSchema(CompendiumFolder folder) private SchemaNode GetPackSchema(CompendiumFolder folder)
{ {
if (!PackSchemas.TryGetValue(folder, out SchemaNode? value)) if (!PackSchemas.TryGetValue(folder, out SchemaNode? value))
{ {
value = new SchemaNode() value = new SchemaNode() { Resolver = Resolver, Path = folder.Name };
{
Resolver = Resolver,
Path = folder.Name
};
PackSchemas[folder] = value; PackSchemas[folder] = value;
} }
@@ -56,11 +62,7 @@ internal class CompendiumSchemaBuilder(CompendiumLoader loader)
{ {
if (!TypeSchemas.TryGetValue(key, out SchemaNode? value)) if (!TypeSchemas.TryGetValue(key, out SchemaNode? value))
{ {
value = new SchemaNode() value = new SchemaNode() { Resolver = Resolver, Path = key };
{
Resolver = Resolver,
Path = key
};
TypeSchemas[key] = value; TypeSchemas[key] = value;
} }
@@ -157,7 +159,11 @@ internal class CompendiumSchemaBuilder(CompendiumLoader loader)
protected void SaveSchema(string dir, string name, SchemaNode schema) protected void SaveSchema(string dir, string name, SchemaNode schema)
{ {
char[] invalids = Path.GetInvalidFileNameChars(); char[] invalids = Path.GetInvalidFileNameChars();
string fileName = string.Join("_", schema.Path.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.'); string fileName = string.Join(
"_",
schema.Path.Split(invalids, StringSplitOptions.RemoveEmptyEntries)
)
.TrimEnd('.');
string path = Path.Combine(dir, fileName + ".yaml"); string path = Path.Combine(dir, fileName + ".yaml");
@@ -172,11 +178,16 @@ internal class CompendiumSchemaBuilder(CompendiumLoader loader)
schema.Beautify(); schema.Beautify();
writer.WriteLine(SchemaNode.FormatYaml(new Dictionary<string, string>() writer.WriteLine(
SchemaNode.FormatYaml(
new Dictionary<string, string>()
{ {
["name"] = name, ["name"] = name,
["values"] = schema.Values.ToString() ["values"] = schema.Values.ToString(),
}, schema.Types[0].GetYamlData())); },
schema.Types[0].GetYamlData()
)
);
//writer.WriteLine(name); //writer.WriteLine(name);
//writer.WriteLine($"Different values: {schema.Values}"); //writer.WriteLine($"Different values: {schema.Values}");
@@ -14,7 +14,8 @@ internal class CompendiumSchemaTypeResolver : TypeResolver
} }
} }
protected readonly List<string> DictionaryPaths = [ protected readonly List<string> DictionaryPaths =
[
"Actor.character.items.[].system.items", "Actor.character.items.[].system.items",
"Actor.character.items.[].system.overlays", "Actor.character.items.[].system.overlays",
"Item.ancestry.system.items", "Item.ancestry.system.items",
@@ -35,7 +36,7 @@ internal class CompendiumSchemaTypeResolver : TypeResolver
"Item.spell.system.overlays", "Item.spell.system.overlays",
"Item.spell.system.overlays.[value].system.damage", "Item.spell.system.overlays.[value].system.damage",
"Item.spell.system.overlays.[value].system.heightening", "Item.spell.system.overlays.[value].system.heightening",
"Item.spell.system.overlays.[value].system.heightening.[value]" "Item.spell.system.overlays.[value].system.heightening.[value]",
]; ];
/// <summary> /// <summary>
@@ -46,8 +47,8 @@ internal class CompendiumSchemaTypeResolver : TypeResolver
/// <returns>Новый тип для схемы данных. `null`, что бы использовать значение по умолчанию</returns> /// <returns>Новый тип для схемы данных. `null`, что бы использовать значение по умолчанию</returns>
protected override AbstractSchemaType? CustomResolve(SchemaNode node, JToken? value) protected override AbstractSchemaType? CustomResolve(SchemaNode node, JToken? value)
{ {
return CheckPath(node, DictionaryPaths) return CheckPath(node, DictionaryPaths) ? new DictionarySchemaType(node)
? new DictionarySchemaType(node) : node.Path.EndsWith(".rules") ? new FoundryRulesSchemaType(node)
: node.Path.EndsWith(".rules") ? new FoundryRulesSchemaType(node) : (AbstractSchemaType?) null; : (AbstractSchemaType?)null;
} }
} }
+21 -11
View File
@@ -9,7 +9,8 @@ internal class ProcessorInput(JObject input)
public virtual T GetRequired<T>(string path) public virtual T GetRequired<T>(string path)
{ {
JToken token = Input.SelectToken(path) ?? throw new NullReferenceException($"'{path}' is null"); JToken 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");
} }
@@ -18,17 +19,23 @@ internal class ProcessorInput(JObject input)
{ {
JToken? token = Input.SelectToken(path) ?? null; JToken? token = Input.SelectToken(path) ?? null;
return (token is null || token.Type == JTokenType.Null) ? default! : token.ToObject<T>() ?? default; return (token is null || token.Type == JTokenType.Null)
? default!
: token.ToObject<T>() ?? default;
} }
public virtual T EnumRequired<T>(string path) where T : Enum public virtual T EnumRequired<T>(string path)
where T : Enum
{ {
string value = GetOptional<string>(path) ?? throw new NullReferenceException($"Value in path {path} null or not exists"); string value =
GetOptional<string>(path)
?? throw new NullReferenceException($"Value in path {path} null or not exists");
return Enum<T>(value); return Enum<T>(value);
} }
public virtual T EnumOptional<T>(string path, T defaultValue) where T : Enum public virtual T EnumOptional<T>(string path, T defaultValue)
where T : Enum
{ {
string? value = GetOptional<string>(path); string? value = GetOptional<string>(path);
@@ -47,27 +54,30 @@ internal class ProcessorInput(JObject input)
} }
} }
public virtual T Enum<T>(string value) where T : Enum public virtual T Enum<T>(string value)
where T : Enum
{ {
foreach (System.Reflection.FieldInfo field in typeof(T).GetFields()) foreach (System.Reflection.FieldInfo field in typeof(T).GetFields())
{ {
List<string> variants = [field.Name]; List<string> variants = [field.Name];
if (Attribute.GetCustomAttribute(field, typeof(PgNameAttribute)) is PgNameAttribute pgAttribute) if (
Attribute.GetCustomAttribute(field, typeof(PgNameAttribute))
is PgNameAttribute pgAttribute
)
{ {
variants.Add(pgAttribute.PgName); variants.Add(pgAttribute.PgName);
} }
if (variants.Contains(value)) if (variants.Contains(value))
{ {
return (T) field.GetValue(null)!; return (T)field.GetValue(null)!;
} }
} }
throw new InvalidEnumStringException(typeof(T), value); throw new InvalidEnumStringException(typeof(T), value);
} }
public class InvalidEnumStringException(Type type, string value) : Exception($"Invalid value '{value}' for enum type {type.FullName}.") public class InvalidEnumStringException(Type type, string value)
{ : Exception($"Invalid value '{value}' for enum type {type.FullName}.") { }
}
} }
@@ -6,7 +6,8 @@ namespace Pf2eDataScrapper.Importers.Repositories;
/// Загрузчик данных из git-репозиториев /// Загрузчик данных из git-репозиториев
/// </summary> /// </summary>
/// <param name="repositoryDirPath"></param> /// <param name="repositoryDirPath"></param>
internal class GitRepository(AbstractImporter importer, string url) : AbstractImporterRepository(importer) internal class GitRepository(AbstractImporter importer, string url)
: AbstractImporterRepository(importer)
{ {
public readonly string Url = url; public readonly string Url = url;
@@ -27,7 +28,7 @@ internal class GitRepository(AbstractImporter importer, string url) : AbstractIm
FileName = "git", FileName = "git",
WorkingDirectory = gitPath, WorkingDirectory = gitPath,
Arguments = "pull", Arguments = "pull",
} },
}; };
process.Start(); process.Start();
} }
@@ -41,10 +42,9 @@ internal class GitRepository(AbstractImporter importer, string url) : AbstractIm
FileName = "git", FileName = "git",
WorkingDirectory = RepositoryDirPath, WorkingDirectory = RepositoryDirPath,
Arguments = $"clone {Url} {Importer.Slug}", Arguments = $"clone {Url} {Importer.Slug}",
} },
}; };
process.Start(); process.Start();
} }
} }
} }
-6
View File
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<LangVersion>13.0</LangVersion> <LangVersion>13.0</LangVersion>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
@@ -7,7 +6,6 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="dotenv.net" Version="3.2.1" /> <PackageReference Include="dotenv.net" Version="3.2.1" />
<PackageReference Include="EFCore.NamingConventions" Version="9.0.0" /> <PackageReference Include="EFCore.NamingConventions" Version="9.0.0" />
@@ -23,11 +21,9 @@
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
<PackageReference Include="Slugify.Core" Version="5.1.1" /> <PackageReference Include="Slugify.Core" Version="5.1.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Pf2eModel\Pf2eModel.csproj" /> <ProjectReference Include="..\Pf2eModel\Pf2eModel.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Update=".env"> <None Update=".env">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -36,9 +32,7 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Importers\Implementations\Aonprd\DataBuilder\Processors\Subclasses\" /> <Folder Include="Importers\Implementations\Aonprd\DataBuilder\Processors\Subclasses\" />
</ItemGroup> </ItemGroup>
</Project> </Project>
+2 -6
View File
@@ -1,5 +1,5 @@
using Npgsql; using System.Text.RegularExpressions;
using System.Text.RegularExpressions; using Npgsql;
namespace Pf2eDataScrapper; namespace Pf2eDataScrapper;
@@ -10,7 +10,6 @@ public partial class Pf2eDatabase
public readonly string Username; public readonly string Username;
public readonly string DatabaseName; public readonly string DatabaseName;
private Pf2eDatabase() private Pf2eDatabase()
{ {
Username = UsernamePattern().Match(EnvSettings.DatabaseConnection).Groups[1].Value; Username = UsernamePattern().Match(EnvSettings.DatabaseConnection).Groups[1].Value;
@@ -61,9 +60,6 @@ public partial class Pf2eDatabase
return new NpgsqlCommand(sql, Connection); return new NpgsqlCommand(sql, Connection);
} }
/* /*
public void RebuildDatabase() public void RebuildDatabase()
{ {
+4 -4
View File
@@ -144,7 +144,7 @@ internal class SchemaNode
["type"] = GetTypeName(), ["type"] = GetTypeName(),
["path"] = Path, ["path"] = Path,
["is_null"] = IsNullable ? "true" : "false", ["is_null"] = IsNullable ? "true" : "false",
["values"] = Values.ToString() ["values"] = Values.ToString(),
}; };
if (IsSimple) if (IsSimple)
@@ -178,8 +178,6 @@ internal class SchemaNode
} }
} }
/// <summary> /// <summary>
/// Отступ для строкового представления. /// Отступ для строкового представления.
/// </summary> /// </summary>
@@ -219,7 +217,9 @@ internal class SchemaNode
return result.Trim(); return result.Trim();
} }
public static Dictionary<string, string> MergeDictionaries(params List<Dictionary<string, string>> input) public static Dictionary<string, string> MergeDictionaries(
params List<Dictionary<string, string>> input
)
{ {
Dictionary<string, string> result = []; Dictionary<string, string> result = [];
@@ -24,7 +24,9 @@ internal class TypeResolver
string[] pathParts = path.Split('.'); string[] pathParts = path.Split('.');
string[] nodeParts = node.Path.Split('.'); string[] nodeParts = node.Path.Split('.');
return pathParts.Length > nodeParts.Length ? false : !pathParts.Where((t, i) => t != "*" && t != nodeParts[i]).Any(); return pathParts.Length > nodeParts.Length
? false
: !pathParts.Where((t, i) => t != "*" && t != nodeParts[i]).Any();
} }
/// <summary> /// <summary>
@@ -45,7 +47,11 @@ internal class TypeResolver
/// <returns>Типа значения.</returns> /// <returns>Типа значения.</returns>
public JTokenType TokenType(JToken? value) public JTokenType TokenType(JToken? value)
{ {
return value is null || value.Type is JTokenType.Null or JTokenType.Undefined or JTokenType.None ? JTokenType.Null : value.Type; return
value is null
|| value.Type is JTokenType.Null or JTokenType.Undefined or JTokenType.None
? JTokenType.Null
: value.Type;
} }
/// <summary> /// <summary>
@@ -90,7 +96,7 @@ internal class TypeResolver
{ {
JTokenType.Array => new ArraySchemaType(node), JTokenType.Array => new ArraySchemaType(node),
JTokenType.Object => new ObjectSchemaType(node), JTokenType.Object => new ObjectSchemaType(node),
_ => new StaticSchemaType(node, type) _ => new StaticSchemaType(node, type),
}; };
} }
@@ -44,7 +44,7 @@ internal class ArraySchemaType(SchemaNode parent) : AbstractSchemaType(parent)
throw new Exception("Value is not an array, did you forget to call IsCompatibleValue?"); throw new Exception("Value is not an array, did you forget to call IsCompatibleValue?");
} }
JArray array = (JArray) value; JArray array = (JArray)value;
MinCount = Math.Min(MinCount, array.Count); MinCount = Math.Min(MinCount, array.Count);
MaxCount = Math.Max(MaxCount, array.Count); MaxCount = Math.Max(MaxCount, array.Count);
@@ -82,7 +82,7 @@ internal class ArraySchemaType(SchemaNode parent) : AbstractSchemaType(parent)
{ {
["min_count"] = MinCount.ToString(), ["min_count"] = MinCount.ToString(),
["max_count"] = MaxCount.ToString(), ["max_count"] = MaxCount.ToString(),
["value_type"] = ElementSchema.ToString() ["value_type"] = ElementSchema.ToString(),
}; };
} }
} }
@@ -34,7 +34,7 @@ internal class DictionarySchemaType(SchemaNode parent) : AbstractSchemaType(pare
/// <param name="value">Новое значение.</param> /// <param name="value">Новое значение.</param>
public override void AddValue(JToken value) public override void AddValue(JToken value)
{ {
JObject obj = (JObject) value; JObject obj = (JObject)value;
foreach (KeyValuePair<string, JToken?> pair in obj) foreach (KeyValuePair<string, JToken?> pair in obj)
{ {
@@ -70,7 +70,7 @@ internal class DictionarySchemaType(SchemaNode parent) : AbstractSchemaType(pare
return new Dictionary<string, string>() return new Dictionary<string, string>()
{ {
["_key"] = KeyNode.ToString(), ["_key"] = KeyNode.ToString(),
["_value"] = ItemNode.ToString() ["_value"] = ItemNode.ToString(),
}; };
} }
} }
@@ -22,16 +22,12 @@ internal class IgnoreSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
/// Добавление нового значения. /// Добавление нового значения.
/// </summary> /// </summary>
/// <param name="value">Новое значение.</param> /// <param name="value">Новое значение.</param>
public override void AddValue(JToken value) public override void AddValue(JToken value) { }
{
}
/// <summary> /// <summary>
/// Подготовка типа к красивому представлению. /// Подготовка типа к красивому представлению.
/// </summary> /// </summary>
public override void Beautify() public override void Beautify() { }
{
}
/// <summary> /// <summary>
/// Получение строкового представоения типа элемента. /// Получение строкового представоения типа элемента.
@@ -42,7 +38,6 @@ internal class IgnoreSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
return "ignore"; return "ignore";
} }
/// <summary> /// <summary>
/// Получение данных для форматирования в YAML. /// Получение данных для форматирования в YAML.
/// </summary> /// </summary>
@@ -29,7 +29,7 @@ internal class ObjectSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
/// <param name="value">Новое значение.</param> /// <param name="value">Новое значение.</param>
public override void AddValue(JToken value) public override void AddValue(JToken value)
{ {
JObject obj = (JObject) value; JObject obj = (JObject)value;
foreach (SchemaNode field in Fields) foreach (SchemaNode field in Fields)
{ {
@@ -58,10 +58,14 @@ internal class ObjectSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
/// </summary> /// </summary>
public override void Beautify() public override void Beautify()
{ {
Fields.Sort((a, b) => Fields.Sort(
(a, b) =>
{ {
return a.IsNullable && !b.IsNullable ? 0 : string.Compare(a.Name, b.Name, StringComparison.Ordinal); return a.IsNullable && !b.IsNullable
}); ? 0
: string.Compare(a.Name, b.Name, StringComparison.Ordinal);
}
);
foreach (SchemaNode field in Fields) foreach (SchemaNode field in Fields)
{ {
@@ -102,9 +106,6 @@ internal class ObjectSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
/// <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())
};
} }
} }
@@ -59,7 +59,9 @@ internal class StaticSchemaType(SchemaNode parent, JTokenType type) : AbstractSc
Values = newValues; Values = newValues;
} }
Values = Values.OrderByDescending(pair => pair.Value).ToDictionary(pair => pair.Key, pair => pair.Value); Values = Values
.OrderByDescending(pair => pair.Value)
.ToDictionary(pair => pair.Key, pair => pair.Value);
} }
/// <summary> /// <summary>
@@ -82,7 +84,10 @@ internal class StaticSchemaType(SchemaNode parent, JTokenType type) : AbstractSc
string prefix = (count == 1) ? "" : "- "; string prefix = (count == 1) ? "" : "- ";
if (count is <= SchemaNode.ElementLimit and > 0 && (Type != JTokenType.String || !Values.Any(s => s.ToString().Contains('\n')))) if (
count is <= SchemaNode.ElementLimit and > 0
&& (Type != JTokenType.String || !Values.Any(s => s.ToString().Contains('\n')))
)
{ {
foreach (KeyValuePair<JToken, int> kvp in Values) foreach (KeyValuePair<JToken, int> kvp in Values)
{ {
@@ -92,10 +97,11 @@ internal class StaticSchemaType(SchemaNode parent, JTokenType type) : AbstractSc
return new() return new()
{ {
["different_values"] = count.ToString() + ["different_values"] =
((count == Root.Values) ? " (all different)" : "") + count.ToString()
((count == 1) ? " (all same)" : ""), + ((count == Root.Values) ? " (all different)" : "")
["variants"] = (values.Count > 0) ? string.Join("\r\n", values) : "[omitted]" + ((count == 1) ? " (all same)" : ""),
["variants"] = (values.Count > 0) ? string.Join("\r\n", values) : "[omitted]",
}; };
} }
} }
+5 -3
View File
@@ -1,7 +1,7 @@
using Pf2eModel.Model; using System.Reflection;
using Pf2eModel.Model;
using Pf2eModel.Model.Base; using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using System.Reflection;
namespace Pf2eModel; namespace Pf2eModel;
@@ -21,7 +21,9 @@ public class EntityOfTypeAttribute(EntityType type) : Attribute
if (!type.IsAssignableTo(typeof(IEntity))) if (!type.IsAssignableTo(typeof(IEntity)))
{ {
throw new Exception($"'EntityOfTypeAttribute' attribute should only be applied to children of 'IEntity' class. '{type.FullName}' is not."); throw new Exception(
$"'EntityOfTypeAttribute' attribute should only be applied to children of 'IEntity' class. '{type.FullName}' is not."
);
} }
EntityOfTypeAttribute attribute = type.GetCustomAttribute<EntityOfTypeAttribute>()!; EntityOfTypeAttribute attribute = type.GetCustomAttribute<EntityOfTypeAttribute>()!;
+3 -3
View File
@@ -1,12 +1,12 @@
using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Pf2eModel.Model.Base.Keywords; using Pf2eModel.Model.Base.Keywords;
using Pf2eModel.Model.Base.Source; using Pf2eModel.Model.Base.Source;
using Pf2eModel.Model.Base.Targets; using Pf2eModel.Model.Base.Targets;
using Pf2eModel.Model.Common.I18n; using Pf2eModel.Model.Common.I18n;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure; using Pf2eModel.Model.Structure;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Base; namespace Pf2eModel.Model.Base;
-1
View File
@@ -17,5 +17,4 @@ public partial class Keyword
public virtual ICollection<Entity> Entities { get; set; } = []; public virtual ICollection<Entity> Entities { get; set; } = [];
public virtual ICollection<KeywordAlias> Aliases { get; set; } = []; public virtual ICollection<KeywordAlias> Aliases { get; set; } = [];
} }
+2 -2
View File
@@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace Pf2eModel.Model.Base.Source; namespace Pf2eModel.Model.Base.Source;
+2 -3
View File
@@ -1,6 +1,6 @@
using Pf2eModel.Model.Enum; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Enum;
namespace Pf2eModel.Model.Base.Source; namespace Pf2eModel.Model.Base.Source;
@@ -21,7 +21,6 @@ public partial class Source
[Column(Order = 4)] [Column(Order = 4)]
public DateOnly? ReleaseDate { get; set; } public DateOnly? ReleaseDate { get; set; }
[Newtonsoft.Json.JsonIgnore] [Newtonsoft.Json.JsonIgnore]
public ICollection<EntitySource> EntitySources { get; set; } = []; public ICollection<EntitySource> EntitySources { get; set; } = [];
} }
@@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace Pf2eModel.Model.Base.Targets; namespace Pf2eModel.Model.Base.Targets;
+2 -1
View File
@@ -6,5 +6,6 @@ public class LocaleItem(LocaleType type, string value)
public string Value { get; set; } = value; public string Value { get; set; } = value;
public LocaleItem(KeyValuePair<string, string> item) : this(LocaleExtension.GetTypeByString(item.Key), item.Value) { } public LocaleItem(KeyValuePair<string, string> item)
: this(LocaleExtension.GetTypeByString(item.Key), item.Value) { }
} }
+2 -2
View File
@@ -1,6 +1,6 @@
using Pf2eModel.Model.Enum; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Enum;
namespace Pf2eModel.Model.Common; namespace Pf2eModel.Model.Common;
-4
View File
@@ -15,10 +15,6 @@ public enum ActionCategory
[PgName("class-feat")] [PgName("class-feat")]
ClassFeat, ClassFeat,
[PgName("offensive")] [PgName("offensive")]
Offensive, Offensive,
+1 -1
View File
@@ -23,5 +23,5 @@ public enum AttributeValues
Wisdom, Wisdom,
[PgName("cha")] [PgName("cha")]
Charisma Charisma,
} }
+1 -2
View File
@@ -2,7 +2,6 @@
namespace Pf2eModel.Model.Enum; namespace Pf2eModel.Model.Enum;
public enum ConditionGroup public enum ConditionGroup
{ {
[PgName("unknown")] [PgName("unknown")]
@@ -21,5 +20,5 @@ public enum ConditionGroup
Attitudes, Attitudes,
[PgName("detection")] [PgName("detection")]
Detection Detection,
} }
+1 -1
View File
@@ -14,5 +14,5 @@ public enum EntityRarity
Rare, Rare,
[PgName("unique")] [PgName("unique")]
Unique Unique,
} }
+1 -1
View File
@@ -47,5 +47,5 @@ public enum EntityType
Spell, Spell,
[PgName("language")] [PgName("language")]
Language Language,
} }
+1
View File
@@ -1,6 +1,7 @@
using NpgsqlTypes; using NpgsqlTypes;
namespace Pf2eModel.Model.Enum; namespace Pf2eModel.Model.Enum;
public enum SourceCategory public enum SourceCategory
{ {
[PgName("rulebook")] [PgName("rulebook")]
+1
View File
@@ -1,4 +1,5 @@
namespace Pf2eModel.Model.Enum; namespace Pf2eModel.Model.Enum;
public enum TrainingStage public enum TrainingStage
{ {
Untrained = 0, Untrained = 0,
+1
View File
@@ -1,6 +1,7 @@
using NpgsqlTypes; using NpgsqlTypes;
namespace Pf2eModel.Model.Enum; namespace Pf2eModel.Model.Enum;
public enum TrainingType public enum TrainingType
{ {
[PgName("perception")] [PgName("perception")]
+1 -1
View File
@@ -11,5 +11,5 @@ public enum TraitType
Class, Class,
[PgName("tradition")] [PgName("tradition")]
Tradition Tradition,
} }
-1
View File
@@ -9,5 +9,4 @@ public interface IEntity
[JsonIgnore] [JsonIgnore]
public Entity Entity { get; set; } public Entity Entity { get; set; }
} }
+2 -3
View File
@@ -1,6 +1,6 @@
using Pf2eModel.Model.Base; using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure; namespace Pf2eModel.Model.Structure;
@@ -30,6 +30,5 @@ public partial class Action : IEntity
[Column(Order = 6)] [Column(Order = 6)]
public string? Extra { get; set; } public string? Extra { get; set; }
public Entity Entity { get; set; } = null!; public Entity Entity { get; set; } = null!;
} }
+2 -2
View File
@@ -1,7 +1,7 @@
using Pf2eModel.Model.Base; using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure.AncestryRelation; using Pf2eModel.Model.Structure.AncestryRelation;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure; namespace Pf2eModel.Model.Structure;
@@ -1,6 +1,6 @@
using Newtonsoft.Json; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
namespace Pf2eModel.Model.Structure.AncestryRelation; namespace Pf2eModel.Model.Structure.AncestryRelation;
@@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Pf2eModel.Model.Base; using Pf2eModel.Model.Base;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure.AncestryRelation; namespace Pf2eModel.Model.Structure.AncestryRelation;
@@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations.Schema; using Microsoft.EntityFrameworkCore;
namespace Pf2eModel.Model.Structure.AncestryRelation; namespace Pf2eModel.Model.Structure.AncestryRelation;
+3 -3
View File
@@ -1,8 +1,8 @@
using Pf2eModel.Model.Base; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure.BackgroundRelation; using Pf2eModel.Model.Structure.BackgroundRelation;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure; namespace Pf2eModel.Model.Structure;
@@ -1,7 +1,7 @@
using Newtonsoft.Json; using System.ComponentModel.DataAnnotations;
using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
using Pf2eModel.Model.Enum;
namespace Pf2eModel.Model.Structure.BackgroundRelation; namespace Pf2eModel.Model.Structure.BackgroundRelation;
@@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json; using Newtonsoft.Json;
using Pf2eModel.Model.Base; using Pf2eModel.Model.Base;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure.BackgroundRelation; namespace Pf2eModel.Model.Structure.BackgroundRelation;
@@ -1,8 +1,8 @@
using Newtonsoft.Json; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
using Pf2eModel.Model.Common; using Pf2eModel.Model.Common;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure.BackgroundRelation; namespace Pf2eModel.Model.Structure.BackgroundRelation;
+3 -3
View File
@@ -1,8 +1,8 @@
using Pf2eModel.Model.Base; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure.ClassRelation; using Pf2eModel.Model.Structure.ClassRelation;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure; namespace Pf2eModel.Model.Structure;
@@ -1,7 +1,7 @@
using Newtonsoft.Json; using System.ComponentModel.DataAnnotations;
using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
using Pf2eModel.Model.Enum;
namespace Pf2eModel.Model.Structure.ClassRelation; namespace Pf2eModel.Model.Structure.ClassRelation;
@@ -1,10 +1,11 @@
using Newtonsoft.Json; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
using Pf2eModel.Model.Base; using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure.ClassRelation; namespace Pf2eModel.Model.Structure.ClassRelation;
public partial class ClassProgression public partial class ClassProgression
{ {
[Key] [Key]
@@ -1,8 +1,8 @@
using Newtonsoft.Json; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
using Pf2eModel.Model.Common; using Pf2eModel.Model.Common;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure.ClassRelation; namespace Pf2eModel.Model.Structure.ClassRelation;
+3 -3
View File
@@ -1,7 +1,7 @@
using Pf2eModel.Model.Base; using System.ComponentModel.DataAnnotations;
using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum;
namespace Pf2eModel.Model.Structure; namespace Pf2eModel.Model.Structure;
+5 -4
View File
@@ -1,9 +1,9 @@
using Pf2eModel.Model.Base; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Common; using Pf2eModel.Model.Common;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure.DeityRelation; using Pf2eModel.Model.Structure.DeityRelation;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure; namespace Pf2eModel.Model.Structure;
@@ -29,7 +29,8 @@ public partial class Deity : IEntity
[Column(Order = 5)] [Column(Order = 5)]
public bool SanctificationMust { get; set; } public bool SanctificationMust { get; set; }
public virtual ICollection<DeityAttribute> DeityAttributes { get; set; } = new List<DeityAttribute>(); public virtual ICollection<DeityAttribute> DeityAttributes { get; set; } =
new List<DeityAttribute>();
public virtual ICollection<DeityDomain> DeityDomains { get; set; } = new List<DeityDomain>(); public virtual ICollection<DeityDomain> DeityDomains { get; set; } = new List<DeityDomain>();
@@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure.DeityRelation; namespace Pf2eModel.Model.Structure.DeityRelation;
+3 -4
View File
@@ -1,8 +1,8 @@
using Pf2eModel.Model.Base; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure.FeatRelation; using Pf2eModel.Model.Structure.FeatRelation;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure; namespace Pf2eModel.Model.Structure;
@@ -37,7 +37,6 @@ public partial class Feat : IEntity
[Column(Order = 9)] [Column(Order = 9)]
public bool IsPassive { get; set; } = false; public bool IsPassive { get; set; } = false;
[Column(Order = 10)] [Column(Order = 10)]
public string? Extra { get; set; } public string? Extra { get; set; }
+3 -3
View File
@@ -1,7 +1,7 @@
using Pf2eModel.Model.Base; using System.ComponentModel.DataAnnotations;
using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum;
namespace Pf2eModel.Model.Structure; namespace Pf2eModel.Model.Structure;
+3 -3
View File
@@ -1,8 +1,8 @@
using Pf2eModel.Model.Base; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum; using Pf2eModel.Model.Enum;
using Pf2eModel.Model.Structure.SpellRelation; using Pf2eModel.Model.Structure.SpellRelation;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Pf2eModel.Model.Structure; namespace Pf2eModel.Model.Structure;
@@ -1,6 +1,6 @@
using Pf2eModel.Model.Enum; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Enum;
namespace Pf2eModel.Model.Structure.SpellRelation; namespace Pf2eModel.Model.Structure.SpellRelation;
@@ -1,6 +1,6 @@
using Pf2eModel.Model.Enum; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Enum;
namespace Pf2eModel.Model.Structure.SpellRelation; namespace Pf2eModel.Model.Structure.SpellRelation;
+3 -3
View File
@@ -1,7 +1,7 @@
using Pf2eModel.Model.Base; using System.ComponentModel.DataAnnotations;
using Pf2eModel.Model.Enum;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using Pf2eModel.Model.Base;
using Pf2eModel.Model.Enum;
namespace Pf2eModel.Model.Structure; namespace Pf2eModel.Model.Structure;
+5 -10
View File
@@ -20,14 +20,10 @@ namespace Pf2eModel;
public partial class Pf2eDbContext : DbContext public partial class Pf2eDbContext : DbContext
{ {
public Pf2eDbContext() public Pf2eDbContext() { }
{
}
public Pf2eDbContext(DbContextOptions<Pf2eDbContext> options) public Pf2eDbContext(DbContextOptions<Pf2eDbContext> options)
: base(options) : base(options) { }
{
}
#region DbSets #region DbSets
@@ -118,7 +114,8 @@ public partial class Pf2eDbContext : DbContext
// optionsBuilder.LogTo(Console.WriteLine); // optionsBuilder.LogTo(Console.WriteLine);
optionsBuilder.UseSnakeCaseNamingConvention(); optionsBuilder.UseSnakeCaseNamingConvention();
optionsBuilder.UseNpgsql(databaseCnnection, optionsBuilder.UseNpgsql(
databaseCnnection,
builder => builder =>
{ {
builder builder
@@ -141,10 +138,8 @@ public partial class Pf2eDbContext : DbContext
.MapEnum<SpellDamageKinds>() .MapEnum<SpellDamageKinds>()
.MapEnum<AttributeValues>() .MapEnum<AttributeValues>()
.MapEnum<TrainingStage>() .MapEnum<TrainingStage>()
.MapEnum<SourceCategory>() .MapEnum<SourceCategory>();
;
} }
); );
} }
} }
-7
View File
@@ -1,18 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles> <GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<None Include="..\Pf2eDataScrapper\.env" Link=".env"> <None Include="..\Pf2eDataScrapper\.env" Link=".env">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="dotenv.net" Version="3.2.1" /> <PackageReference Include="dotenv.net" Version="3.2.1" />
<PackageReference Include="EFCore.NamingConventions" Version="9.0.0" /> <PackageReference Include="EFCore.NamingConventions" Version="9.0.0" />
@@ -27,17 +24,14 @@
<PackageReference Include="Npgsql" Version="9.0.3" /> <PackageReference Include="Npgsql" Version="9.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="RebuildDatabase.bat"> <None Update="RebuildDatabase.bat">
<Generator></Generator> <Generator></Generator>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" /> <Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="RebuildDatabase.cs"> <Compile Update="RebuildDatabase.cs">
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
@@ -45,5 +39,4 @@
<DependentUpon>RebuildDatabase.bat</DependentUpon> <DependentUpon>RebuildDatabase.bat</DependentUpon>
</Compile> </Compile>
</ItemGroup> </ItemGroup>
</Project> </Project>
-5
View File
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework> <TargetFramework>net8.0-windows</TargetFramework>
@@ -7,17 +6,13 @@
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Pf2eModel\Pf2eModel.csproj" /> <ProjectReference Include="..\Pf2eModel\Pf2eModel.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Properties\" /> <Folder Include="Properties\" />
</ItemGroup> </ItemGroup>
</Project> </Project>