Работа с порядком правил
This commit is contained in:
+92
-6
@@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data;
|
||||
using Microsoft.EntityFrameworkCore.Migrations.Operations;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Pf2eModel.Model.Common.I18n;
|
||||
using Pf2eModel.Model.Enum;
|
||||
using Pf2eModel.Model.Structure;
|
||||
using Rule = Pf2eModel.Model.Structure.Rule;
|
||||
|
||||
namespace Pf2eDataScrapper.Importers.Implementations.Aonprd.DataBuilder.Processors.Types;
|
||||
|
||||
@@ -22,8 +21,95 @@ internal class RuleProcessor(AonprdProcessorInput input) : AbstractEntityProcess
|
||||
{
|
||||
base.Process();
|
||||
|
||||
Object.Breadcrumbs = (Input.GetOptional<JArray>("breadcrumbs") ?? [])
|
||||
string[] breadcrumbs = (Input.GetOptional<JArray>("breadcrumbs") ?? [])
|
||||
.Select(token => token.ToString())
|
||||
.ToArray();
|
||||
|
||||
RuleStructureItem item = GetStructureItem(
|
||||
[.. breadcrumbs, Entity.Name[LocaleType.English]]
|
||||
);
|
||||
|
||||
item.IsHandled = true;
|
||||
item.RuleId = Object.Id;
|
||||
item.Id = Input.GetRequired<string>("id");
|
||||
|
||||
if (item.Parent?.IsHandled ?? false)
|
||||
{
|
||||
Object.ParentId = item.Parent.RuleId!;
|
||||
// Object.Order = item.Parent.ChildrenOrder?.IndexOf(item.Id) ?? 0;
|
||||
Object.Order = 0;
|
||||
}
|
||||
|
||||
item.ChildrenOrder = [];
|
||||
|
||||
List<int> childrenIds = item
|
||||
.Children.Select(i => i.RuleId)
|
||||
.Where(id => id != null)
|
||||
.OfType<int>()
|
||||
.ToList();
|
||||
|
||||
List<Rule> rules = Context.Rules.Where(i => childrenIds.Contains(i.Id)).ToList();
|
||||
|
||||
foreach (Rule rule in rules)
|
||||
{
|
||||
rule.Order = 0;
|
||||
}
|
||||
/*
|
||||
* TODO
|
||||
* Обработка порядка из полей
|
||||
*
|
||||
"next_link": {
|
||||
"label": "Chapter 3: Classes",
|
||||
"url": "/Rules.aspx?ID=134"
|
||||
},
|
||||
"previous_link": {
|
||||
"label": "Chapter 1: Introduction",
|
||||
"url": "/Rules.aspx?ID=1"
|
||||
},
|
||||
*/
|
||||
}
|
||||
|
||||
private static readonly List<RuleStructureItem> Roots = [];
|
||||
|
||||
private RuleStructureItem GetStructureItem(string[] breadcrumbs, RuleStructureItem? from = null)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
List<RuleStructureItem> children = from?.Children ?? Roots;
|
||||
|
||||
if (breadcrumbs.Length == 0)
|
||||
{
|
||||
return from!;
|
||||
}
|
||||
|
||||
string root = breadcrumbs[0];
|
||||
RuleStructureItem? item = children.FirstOrDefault(i => i.Name == root);
|
||||
|
||||
if (item is null)
|
||||
{
|
||||
item = new(root, from);
|
||||
children.Add(item);
|
||||
}
|
||||
|
||||
breadcrumbs = breadcrumbs[1..];
|
||||
from = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class RuleStructureItem(string name, RuleStructureItem? parent)
|
||||
{
|
||||
public string? Id { get; set; } = null;
|
||||
|
||||
public string Name { get; set; } = name;
|
||||
|
||||
public int? RuleId { get; set; } = null;
|
||||
|
||||
public bool IsHandled { get; set; } = false;
|
||||
|
||||
public RuleStructureItem? Parent { get; set; } = parent;
|
||||
|
||||
public List<string>? ChildrenOrder { get; set; } = null;
|
||||
|
||||
public List<RuleStructureItem> Children { get; } = [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user