diff --git a/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/Compendium/CompendiumSchemaTypeResolver.cs b/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/Compendium/CompendiumSchemaTypeResolver.cs index ab9420a..f3d8f93 100644 --- a/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/Compendium/CompendiumSchemaTypeResolver.cs +++ b/Pf2eDataScrapper/Importers/Implementations/Pf2eFoundry/Compendium/CompendiumSchemaTypeResolver.cs @@ -31,32 +31,19 @@ namespace Pf2eDataScrapper.Importers.Implementations.Pf2eFoundry.Compendium "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) - //{ - // 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)) + if (CheckPath(node, DictionaryPaths)) { - return new DictionarySchemaType(parent); + return new DictionarySchemaType(node); + } + + if (node.Path.EndsWith(".rules")) + { + return new FoundryRulesSchemaType(node); } - if (parent.Path.EndsWith(".rules")) - { - return new FoundryRulesSchemaType(parent); - } - - return base.Resolve(parent, value); + return base.Resolve(node, value); } } } diff --git a/Pf2eDataScrapper/SchemaBuilder/TypeResolver.cs b/Pf2eDataScrapper/SchemaBuilder/TypeResolver.cs index bd52f34..f334db0 100644 --- a/Pf2eDataScrapper/SchemaBuilder/TypeResolver.cs +++ b/Pf2eDataScrapper/SchemaBuilder/TypeResolver.cs @@ -10,6 +10,29 @@ namespace Pf2eDataScrapper.SchemaBuilder { 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 paths) + { + return paths.Any(path => CheckPath(node, path)); + } + public JTokenType TokenType(JToken? value) { if (value is null || value.Type is JTokenType.Null or JTokenType.Undefined or JTokenType.None) @@ -20,7 +43,7 @@ namespace Pf2eDataScrapper.SchemaBuilder return value.Type; } - public virtual AbstractSchemaType Resolve(SchemaNode parent, JToken? value) + public virtual AbstractSchemaType Resolve(SchemaNode node, JToken? value) { var type = TokenType(value); @@ -31,9 +54,9 @@ namespace Pf2eDataScrapper.SchemaBuilder return type switch { - JTokenType.Array => new ArraySchemaType(parent), - JTokenType.Object => new ObjectSchemaType(parent), - _ => new StaticSchemaType(parent, type) + JTokenType.Array => new ArraySchemaType(node), + JTokenType.Object => new ObjectSchemaType(node), + _ => new StaticSchemaType(node, type) }; }