Глобальный рефакторинг пространств имён

This commit is contained in:
2025-10-02 13:29:30 +04:00
parent d23d81fb53
commit 2fa94851cb
3176 changed files with 27146 additions and 30584 deletions
@@ -0,0 +1,72 @@
using System;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;
using Pf2e.Scrapper.Helpers;
using Pf2e.Scrapper.Importers.Implementations.FoundryEn.Compendium;
using Pf2e.Scrapper.Processors.Attributes;
using Pf2e.Scrapper.Processors.Definitions;
namespace Pf2e.Scrapper.Importers.Implementations.FoundryEn.Processors.Preparation;
[Processor(
"foundry-en:compendium",
Description = "Загрузка компендиума",
Group = ProcessorGroupEnum.FoundryEnPreparation,
Active = false
)]
[ProcessorDependencies(["foundry-en:repository"])]
internal class CompendiumProcessor(
FoundryEnRepository repository,
FoundryEnCompendium compendium,
ProcessProgress progress
) : IProcessor
{
public FoundryEnRepository Repository { get; } = repository;
public FoundryEnCompendium Compendium { get; } = compendium;
public ProcessProgress Progress { get; } = progress;
public void Process()
{
string packsDir = Path.Combine(Repository.RepositoryDirPath, "packs");
var jsonFiles = Directory.GetFiles(packsDir, "*.json");
Progress.Local.Reset(jsonFiles.Length);
foreach (string packFile in jsonFiles)
{
Progress.Local.Start(Path.GetFileName(packFile));
if (packFile.EndsWith("folders.json", StringComparison.OrdinalIgnoreCase))
{
Progress.Local.End();
continue;
}
using StreamReader fileReader = new(packFile, Encoding.UTF8);
string fileContent = fileReader.ReadToEnd();
JArray packData = JArray.Parse(fileContent);
foreach (JToken item in packData)
{
string id = item.SelectToken("_id")?.ToString()!;
string? type = item.SelectToken("type")?.ToString();
if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(type))
{
continue;
}
FoundryEnCompendiumItem compendiumItem = new(id, type, packFile);
Compendium.Items.Add(compendiumItem);
}
Progress.Local.End();
}
Progress.Local.Complete();
}
public void Save() { }
}
@@ -0,0 +1,40 @@
using Pf2e.Scrapper.Importers.Implementations.FoundryEn.Helpers;
using Pf2e.Scrapper.Processors.Attributes;
using Pf2e.Scrapper.Processors.Definitions;
using Pf2e.Scrapper.Importers.Implementations.Aonprd.Helpers;
using Pf2e.Database;
using Pf2e.Database.Model.Base.Targets;
namespace Pf2e.Scrapper.Importers.Implementations.FoundryEn.Processors.Preparation;
[Processor(
"foundry-en:external",
Description = "Создание цели внешних ссылок",
Group = ProcessorGroupEnum.FoundryEnPreparation
)]
[ProcessorDependencies(["foundry-en:repository"])]
internal class ExternalProcessor(FoundryEnGlobals enGlobals) : AbstractSimpleProcessor
{
public Pf2eDbContext Context { get; } = new();
public FoundryEnGlobals EnGlobals { get; } = enGlobals;
public ExternalTarget FoundryTarget = null!;
public override void Process()
{
FoundryTarget = new()
{
Name = FoundryEnImporter.TargetName,
Icon = "http://www.google.com/s2/favicons?domain=foundryvtt.com",
Prefix = "",
};
}
public override void Save()
{
Context.ExternalTargets.Add(FoundryTarget);
Context.SaveChanges();
EnGlobals.FoundryTarget = FoundryTarget;
}
}
@@ -0,0 +1,25 @@
using Pf2e.Scrapper.Helpers;
using Pf2e.Scrapper.Processors.Attributes;
using Pf2e.Scrapper.Processors.Definitions;
namespace Pf2e.Scrapper.Importers.Implementations.FoundryEn.Processors.Preparation;
[Processor(
"foundry-en:repository",
Description = "Обновление репозитория",
Group = ProcessorGroupEnum.FoundryEnPreparation,
Active = false
)]
internal class RepositoryUpdateProcessor(FoundryEnRepository repository, ProcessProgress progress)
: IProcessor
{
public FoundryEnRepository Repository { get; } = repository;
public ProcessProgress Progress { get; } = progress;
public void Process()
{
Repository.Update(Progress);
}
public void Save() { }
}
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Pf2e.Scrapper.Helpers;
using Pf2e.Scrapper.Importers.Implementations.FoundryEn.Compendium;
using Pf2e.Scrapper.Processors.Attributes;
using Pf2e.Scrapper.SchemaBuilder;
namespace Pf2e.Scrapper.Importers.Implementations.FoundryEn.Processors.Preparation;
[Processor(
"foundry-en:schema",
Description = "Построение схемы данных",
Group = ProcessorGroupEnum.FoundryEnPreparation,
Active = false
)]
[ProcessorDependencies(["foundry-en:compendium"])]
internal class SchemaBuildProcessor(
FoundryEnImporter importer,
FoundryEnRepository repository,
FoundryEnCompendium compendium,
ProcessProgress progress,
ApplicationSettings settings
) : AbstractSchemaBuildProcessor
{
/// <inheritdoc cref="FoundryEnImporter"/>
protected FoundryEnImporter Importer { get; } = importer;
/// <inheritdoc cref="FoundryEnRepository"/>
protected FoundryEnRepository Repository { get; } = repository;
/// <inheritdoc cref="FoundryEnCompendium"/>
protected override FoundryEnCompendium Compendium { get; } = compendium;
/// <inheritdoc cref="ProcessProgress"/>
protected override ProcessProgress Progress { get; } = progress;
/// <inheritdoc cref="ApplicationSettings"/>
protected ApplicationSettings Settings { get; } = settings;
/// <inheritdoc/>
protected override string SavePath => Path.Combine(Settings.OutputDirPath, Importer.Slug);
/// <summary>
/// Определитель типов данных.
/// </summary>
protected override SchemaTypeResolver Resolver { get; } = new();
/// <summary>
/// Список типов, являющихся экипировкой.
/// </summary>
private readonly string[] _equipmentTypes =
[
"equipment",
"armor",
"backpack",
"consumable",
"kit",
"shield",
"treasure",
"weapon",
];
/// <inheritdoc/>
protected override ICollection<string> GetSchemaNodes(AbstractCompendiumItem item)
{
List<string> nodes = [item.Type];
// Нода подкласса
if (_equipmentTypes.Contains(item.Type))
{
nodes.Add("_equipment");
}
return nodes;
}
}
@@ -0,0 +1,55 @@
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Pf2e.Scrapper.SchemaBuilder;
using Pf2e.Scrapper.SchemaBuilder.Types;
namespace Pf2e.Scrapper.Importers.Implementations.FoundryEn.Processors.Preparation;
internal class SchemaTypeResolver : TypeResolver
{
public class FoundryRulesSchemaType(SchemaNode parent) : IgnoreSchemaType(parent)
{
public override string GetTypeName()
{
return "ignored (Foundry rules object)";
}
}
protected readonly List<string> DictionaryPaths =
[
"character.items.[].system.items",
"character.items.[].system.overlays",
"ancestry.system.items",
"ancestry.system.boosts",
"background.system.boosts",
"background.system.items",
"class.system.items",
"consumable.system.spell.system.damage",
"consumable.system.spell.system.overlays",
"deity.system.spells",
"feat.system.subfeatures.proficiencies",
"kit.system.items",
"kit.system.items.[value].items",
"spell.system.damage",
"spell.system.heightening.damage",
"spell.system.heightening.levels",
"spell.system.heightening.levels.[value].damage",
"spell.system.overlays",
"spell.system.overlays.[value].system.damage",
"spell.system.overlays.[value].system.heightening",
"spell.system.overlays.[value].system.heightening.[value]",
];
/// <summary>
/// Частное определение типа поля.
/// </summary>
/// <param name="node">Поле схемы данных, для которого создаётся тип.</param>
/// <param name="value">Добавляемое значение.</param>
/// <returns>Новый тип для схемы данных. `null`, что бы использовать значение по умолчанию</returns>
protected override AbstractSchemaType? CustomResolve(SchemaNode node, JToken? value)
{
return CheckPath(node, DictionaryPaths) ? new DictionarySchemaType(node)
: node.Path.EndsWith(".rules") ? new FoundryRulesSchemaType(node)
: (AbstractSchemaType?)null;
}
}