Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33105e29c4 | ||
|
|
cabcb54816 |
+2
@@ -144,6 +144,8 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
|||||||
|
|
||||||
using var writer = new StreamWriter(path);
|
using var writer = new StreamWriter(path);
|
||||||
|
|
||||||
|
schema.Beautify();
|
||||||
|
|
||||||
writer.WriteLine(name);
|
writer.WriteLine(name);
|
||||||
writer.WriteLine($"Different values: {schema.Values}");
|
writer.WriteLine($"Different values: {schema.Values}");
|
||||||
writer.WriteLine("=====================================");
|
writer.WriteLine("=====================================");
|
||||||
|
|||||||
+9
-25
@@ -5,20 +5,17 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Pf2eDataScrapper.SchemaBuilder;
|
using Pf2eDataScrapper.SchemaBuilder;
|
||||||
|
using Pf2eDataScrapper.SchemaBuilder.Types;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
||||||
{
|
{
|
||||||
internal class CompendiumSchemaTypeResolver : TypeResolver
|
internal class CompendiumSchemaTypeResolver : TypeResolver
|
||||||
{
|
{
|
||||||
public class FoundryRulesSchemaType(SchemaNode parent) : ArraySchemaType(parent)
|
public class FoundryRulesSchemaType(SchemaNode parent) : IgnoreSchemaType(parent)
|
||||||
{
|
{
|
||||||
public override string GetTypeName()
|
public override string GetTypeName()
|
||||||
{
|
{
|
||||||
return "###FoundryRulesObject###";
|
return "ignored (Foundry rules object)";
|
||||||
}
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return GetTypeName();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,32 +31,19 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium
|
|||||||
"Item.spell.system.heightening.damage"
|
"Item.spell.system.heightening.damage"
|
||||||
];
|
];
|
||||||
|
|
||||||
protected bool ShouldBeDictionary(SchemaNode parent, JToken? value)
|
public override AbstractSchemaType Resolve(SchemaNode node, JToken? value)
|
||||||
{
|
{
|
||||||
//if (value is not JValue || value.Parent is not JProperty)
|
if (CheckPath(node, DictionaryPaths))
|
||||||
//{
|
|
||||||
// return false;
|
|
||||||
//}
|
|
||||||
|
|
||||||
//var p = (JProperty)value.Parent;
|
|
||||||
|
|
||||||
//return DictionaryPaths.Any(path => path == $"{parent.Path}.{p.Name}");
|
|
||||||
return DictionaryPaths.Any(path => path == parent.Path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override AbstractSchemaType Resolve(SchemaNode parent, JToken? value)
|
|
||||||
{
|
{
|
||||||
if (ShouldBeDictionary(parent, value))
|
return new DictionarySchemaType(node);
|
||||||
{
|
|
||||||
return new DictionarySchemaType(parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent.Path.EndsWith(".rules"))
|
if (node.Path.EndsWith(".rules"))
|
||||||
{
|
{
|
||||||
return new FoundryRulesSchemaType(parent);
|
return new FoundryRulesSchemaType(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.Resolve(parent, value);
|
return base.Resolve(node, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Pf2eDataScrapper.SchemaBuilder.Types;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder
|
namespace Pf2eDataScrapper.SchemaBuilder
|
||||||
{
|
{
|
||||||
@@ -98,7 +99,10 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
|
|
||||||
public void Beautify()
|
public void Beautify()
|
||||||
{
|
{
|
||||||
|
foreach (var type in Types)
|
||||||
|
{
|
||||||
|
type.Beautify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,35 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Pf2eDataScrapper.SchemaBuilder.Types;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder
|
namespace Pf2eDataScrapper.SchemaBuilder
|
||||||
{
|
{
|
||||||
internal class TypeResolver
|
internal class TypeResolver
|
||||||
{
|
{
|
||||||
|
public bool CheckPath(SchemaNode node, string path)
|
||||||
|
{
|
||||||
|
if (!path.Contains("*"))
|
||||||
|
{
|
||||||
|
return path == node.Path;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pathParts = path.Split('.');
|
||||||
|
var nodeParts = node.Path.Split('.');
|
||||||
|
|
||||||
|
if (pathParts.Length > nodeParts.Length)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !pathParts.Where((t, i) => t != "*" && t != nodeParts[i]).Any();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CheckPath(SchemaNode node, ICollection<string> paths)
|
||||||
|
{
|
||||||
|
return paths.Any(path => CheckPath(node, path));
|
||||||
|
}
|
||||||
|
|
||||||
public JTokenType TokenType(JToken? value)
|
public JTokenType TokenType(JToken? value)
|
||||||
{
|
{
|
||||||
if (value is null || value.Type is JTokenType.Null or JTokenType.Undefined or JTokenType.None)
|
if (value is null || value.Type is JTokenType.Null or JTokenType.Undefined or JTokenType.None)
|
||||||
@@ -19,7 +43,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
return value.Type;
|
return value.Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual AbstractSchemaType Resolve(SchemaNode parent, JToken? value)
|
public virtual AbstractSchemaType Resolve(SchemaNode node, JToken? value)
|
||||||
{
|
{
|
||||||
var type = TokenType(value);
|
var type = TokenType(value);
|
||||||
|
|
||||||
@@ -30,9 +54,9 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
|
|
||||||
return type switch
|
return type switch
|
||||||
{
|
{
|
||||||
JTokenType.Array => new ArraySchemaType(parent),
|
JTokenType.Array => new ArraySchemaType(node),
|
||||||
JTokenType.Object => new ObjectSchemaType(parent),
|
JTokenType.Object => new ObjectSchemaType(node),
|
||||||
_ => new StaticSchemaType(parent, type)
|
_ => new StaticSchemaType(node, type)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -1,7 +1,7 @@
|
|||||||
using System.ComponentModel.Design.Serialization;
|
using System.ComponentModel.Design.Serialization;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder
|
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||||
{
|
{
|
||||||
internal abstract class AbstractSchemaType(SchemaNode parent)
|
internal abstract class AbstractSchemaType(SchemaNode parent)
|
||||||
{
|
{
|
||||||
@@ -32,7 +32,10 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public abstract string GetTypeName();
|
public abstract string GetTypeName();
|
||||||
|
|
||||||
public abstract override string ToString();
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{GetTypeName()} {Parent.Path}";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
+3
-2
@@ -3,9 +3,10 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Transactions;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder
|
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||||
{
|
{
|
||||||
internal class ArraySchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
internal class ArraySchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
||||||
{
|
{
|
||||||
@@ -53,7 +54,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return string.Join("\n" + Tab, [
|
return string.Join("\n" + Tab, [
|
||||||
GetTypeName() + $" {{{Parent?.Path ?? ""}}}",
|
base.ToString(),
|
||||||
$"Length: min={MinCount} max={MaxCount}",
|
$"Length: min={MinCount} max={MaxCount}",
|
||||||
"Value type: " + Indent(ElementSchema.ToString())
|
"Value type: " + Indent(ElementSchema.ToString())
|
||||||
]);
|
]);
|
||||||
+2
-2
@@ -5,7 +5,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder
|
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||||
{
|
{
|
||||||
internal class DictionarySchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
internal class DictionarySchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
||||||
{
|
{
|
||||||
@@ -42,7 +42,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return string.Join("\n" + Tab, [
|
return string.Join("\n" + Tab, [
|
||||||
GetTypeName() + $" {{{Parent?.Path ?? ""}}}",
|
base.ToString(),
|
||||||
"Key:" + Indent(KeyNode.ToString()),
|
"Key:" + Indent(KeyNode.ToString()),
|
||||||
"Value:" + Indent(ItemNode.ToString())
|
"Value:" + Indent(ItemNode.ToString())
|
||||||
]);
|
]);
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||||
|
{
|
||||||
|
internal class IgnoreSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
||||||
|
{
|
||||||
|
public override bool IsCompatibleValue(JToken value)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public override void AddValue(JToken value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public override void Beautify()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public override string GetTypeName()
|
||||||
|
{
|
||||||
|
return "ignore";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-4
@@ -5,7 +5,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder
|
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||||
{
|
{
|
||||||
internal class ObjectSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
internal class ObjectSchemaType(SchemaNode parent) : AbstractSchemaType(parent)
|
||||||
{
|
{
|
||||||
@@ -34,7 +34,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
|
|
||||||
if (field is null)
|
if (field is null)
|
||||||
{
|
{
|
||||||
field = new SchemaNode(this.Parent, pair.Key);
|
field = new SchemaNode(Parent, pair.Key);
|
||||||
Fields.Add(field);
|
Fields.Add(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,11 +67,11 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
List<string> rows = [$"object {{{Parent?.Path ?? ""}}}"];
|
List<string> rows = [base.ToString()];
|
||||||
|
|
||||||
foreach (var field in Fields)
|
foreach (var field in Fields)
|
||||||
{
|
{
|
||||||
string s = field.Name;
|
var s = field.Name;
|
||||||
|
|
||||||
if (field.IsNullable)
|
if (field.IsNullable)
|
||||||
{
|
{
|
||||||
+2
-3
@@ -1,6 +1,6 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.SchemaBuilder
|
namespace Pf2eDataScrapper.SchemaBuilder.Types
|
||||||
{
|
{
|
||||||
internal class StaticSchemaType(SchemaNode parent, JTokenType type) : AbstractSchemaType(parent)
|
internal class StaticSchemaType(SchemaNode parent, JTokenType type) : AbstractSchemaType(parent)
|
||||||
{
|
{
|
||||||
@@ -46,7 +46,7 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var result = GetTypeName() + $" {{{Parent?.Path ?? ""}}}";
|
var result = base.ToString();
|
||||||
var count = Values.Count;
|
var count = Values.Count;
|
||||||
|
|
||||||
if (count == Root.Values)
|
if (count == Root.Values)
|
||||||
@@ -68,7 +68,6 @@ namespace Pf2eDataScrapper.SchemaBuilder
|
|||||||
return result.Trim();
|
return result.Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
result += "\n";
|
result += "\n";
|
||||||
result = Values.Aggregate(result, (current, value) => current + $"{Tab}{value.Key} (x{value.Value})\n");
|
result = Values.Aggregate(result, (current, value) => current + $"{Tab}{value.Key} (x{value.Value})\n");
|
||||||
|
|
||||||
Reference in New Issue
Block a user