From 00daece00342592bf3dd824803720ba517da3b11 Mon Sep 17 00:00:00 2001 From: frozenreflex Date: Sun, 14 Jul 2024 00:48:37 -0500 Subject: [PATCH 1/5] Json nodes partial rewrite, add constraint support to binding generator, cleanup This should also allow for switching away from Newtonsoft.Json without affecting existing nodes... whenever we get around to doing so. This current change will break existing node setups, but future changes should not. --- .../BindingGenerator.cs | 20 +- ProjectObsidian/Elements/JsonTypes.cs | 255 ++++++++++++++++++ .../ProtoFlux/JSON/JsonAddToObject.cs | 42 --- .../ProtoFlux/JSON/JsonAddToObjectNode.cs | 36 +++ .../ProtoFlux/JSON/JsonAppendToArray.cs | 41 --- .../ProtoFlux/JSON/JsonAppendToArrayNode.cs | 29 ++ .../JSON/JsonCountArrayChildrenNode.cs | 8 +- .../JSON/JsonCountObjectChildrenNode.cs | 3 +- ProjectObsidian/ProtoFlux/JSON/JsonEmpty.cs | 36 +-- .../ProtoFlux/JSON/JsonGetFromArrayNode.cs | 38 --- .../ProtoFlux/JSON/JsonGetFromObject.cs | 37 --- .../JSON/JsonGetObjectFromArrayNode.cs | 29 ++ .../JSON/JsonGetObjectFromObjectNode.cs | 28 ++ .../JSON/JsonGetValueFromArrayNode.cs | 27 ++ .../JSON/JsonGetValueFromObjectNode.cs | 29 ++ ProjectObsidian/ProtoFlux/JSON/JsonInfo.cs | 27 -- .../ProtoFlux/JSON/JsonInsertToArrayNode.cs | 28 +- ...ngArray.cs => JsonParseStringArrayNode.cs} | 19 +- .../ProtoFlux/JSON/JsonParseStringNode.cs | 33 --- .../JSON/JsonParseStringObjectNode.cs | 22 ++ .../ProtoFlux/JSON/JsonQuickGetObject.cs | 38 --- .../JSON/JsonQuickGetObjectFromObjectNode.cs | 29 ++ .../JSON/JsonQuickGetValueFromObjectNode.cs | 30 +++ .../ProtoFlux/JSON/JsonRemoveFromArrayNode.cs | 19 +- .../JSON/JsonRemoveFromObjectNode.cs | 13 +- .../ProtoFlux/JSON/JsonToStringNode.cs | 6 +- .../{NodeExstensions.cs => NodeExtensions.cs} | 66 ++--- 27 files changed, 606 insertions(+), 382 deletions(-) create mode 100644 ProjectObsidian/Elements/JsonTypes.cs delete mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonAddToObject.cs create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonAddToObjectNode.cs delete mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonAppendToArray.cs create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonAppendToArrayNode.cs delete mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonGetFromArrayNode.cs delete mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonGetFromObject.cs create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromObjectNode.cs create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.cs delete mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonInfo.cs rename ProjectObsidian/ProtoFlux/JSON/{JsonParseStringArray.cs => JsonParseStringArrayNode.cs} (50%) delete mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonParseStringNode.cs create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonParseStringObjectNode.cs delete mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObject.cs create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObjectFromObjectNode.cs create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValueFromObjectNode.cs rename ProjectObsidian/ProtoFlux/{NodeExstensions.cs => NodeExtensions.cs} (61%) diff --git a/ProjectObsidian.SourceGenerators/BindingGenerator.cs b/ProjectObsidian.SourceGenerators/BindingGenerator.cs index 6c591f4..9a8af23 100644 --- a/ProjectObsidian.SourceGenerators/BindingGenerator.cs +++ b/ProjectObsidian.SourceGenerators/BindingGenerator.cs @@ -147,10 +147,11 @@ public string Result namespace {BindingPrefix}{_currentNameSpace}; [Category(new string[] {{""ProtoFlux/Runtimes/Execution/Nodes/{_category}""}})] -public partial class {_fullName} : global::FrooxEngine.ProtoFlux.Runtimes.Execution.{_baseType} +public partial class {_fullName} : global::FrooxEngine.ProtoFlux.Runtimes.Execution.{_baseType} {_constraints} {{ +{(string.IsNullOrEmpty(_debug) ? "" : "//")}{_debug} {Declarations} -{_nodeNameOverride} +{(_isValidGenericTypeMethod ? $" public static bool IsValidGenericType => global::{_currentNameSpace}.{_fullName}.IsValidGenericType;" : "")} public override System.Type NodeType => typeof (global::{_currentNameSpace}.{_fullName}); public global::{_currentNameSpace}.{_fullName} TypedNodeInstance {{ get; private set; }} public override INode NodeInstance => (INode)this.TypedNodeInstance; @@ -181,6 +182,9 @@ public override N Instantiate() private string _match; private string _category; private string _nodeNameOverride = ""; + private string _debug = ""; + private bool _isValidGenericTypeMethod; + private string _constraints = ""; private bool TypedFieldDetection(string type, string name, string targetTypeName, string declarationFormat, OrderedCount counter) { @@ -237,7 +241,12 @@ public override void VisitFieldDeclaration(FieldDeclarationSyntax node) base.VisitFieldDeclaration(node); } - + public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node) + { + if (node.Identifier.ValueText.Contains("IsValidGenericType")) _isValidGenericTypeMethod = true; + base.VisitPropertyDeclaration(node); + + } public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node) { _currentNameSpace = node.Name.ToString(); @@ -279,6 +288,11 @@ public override void VisitClassDeclaration(ClassDeclarationSyntax node) BaseName = baseName; _fullName = fullName; + + if (node.ConstraintClauses.Any()) + { + _constraints = node.ConstraintClauses.ToString(); + } var firstBaseType = node.BaseList.Types.First(); var baseTypeName = firstBaseType.Type.ToString(); diff --git a/ProjectObsidian/Elements/JsonTypes.cs b/ProjectObsidian/Elements/JsonTypes.cs new file mode 100644 index 0000000..108b605 --- /dev/null +++ b/ProjectObsidian/Elements/JsonTypes.cs @@ -0,0 +1,255 @@ +using System; +using System.Linq; +using Elements.Core; +using Newtonsoft.Json.Linq; + +namespace Obsidian.Elements; + +public static class JsonTypeHelper +{ + public static readonly Type[] JsonTokens = + { + typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray), + }; + public static readonly Type[] AllValidTypes = + { + typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), + typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), + typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray), + }; + public static readonly Type[] AllValidGetTypes = + { + typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), + typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), + typeof(JsonObject), typeof(JsonArray), + }; + public static readonly Type[] ValidValueGetTypes = + { + typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), + typeof(long), typeof(ulong), typeof(float), typeof(double) + }; + public static readonly Type[] ValidObjectTypes = + { + typeof(string), typeof(Uri), typeof(JsonObject), typeof(JsonArray), + }; +} + +[DataModelType] +public interface IJsonToken +{ + public JToken Wrapped { get; } +} +[DataModelType] +public class JsonObject : IJsonToken +{ + public JObject WrappedObject { get; private set; } + public JToken Wrapped => WrappedObject; + public JsonObject(JObject wrap) => WrappedObject = wrap; + public int Count => WrappedObject.Count; + public override string ToString() => WrappedObject.ToString(); + public static JsonObject FromString(string str) + { + try + { + return new JsonObject(JObject.Parse(str)); + } + catch + { + return null; + } + } + public T Get(string tag) + { + try + { + //TODO: theres probably a better way to do this than boxing the value + if (typeof(T) == typeof(JsonObject)) return (T)(object)new JsonObject(WrappedObject[tag].Value()); + if (typeof(T) == typeof(JsonArray)) return (T)(object)new JsonArray(WrappedObject[tag].Value()); + return WrappedObject[tag].Value() ?? default; + } + catch + { + return default; + } + } + public T GetValue(string tag) where T : unmanaged + { + try + { + return WrappedObject[tag]?.Value() ?? default; + } + catch + { + return default; + } + } + public T GetObject(string tag) where T : class + { + try + { + if (typeof(T) == typeof(JsonObject)) + { + var value = WrappedObject[tag]?.Value(); + if (value is null) return null; + return new JsonObject(value) as T; + } + if (typeof(T) == typeof(JsonArray)) + { + var value = WrappedObject[tag]?.Value(); + if (value is null) return null; + return new JsonArray(value) as T; + } + return WrappedObject[tag]?.Value(); + } + catch + { + return null; + } + } + public JsonObject Add(string tag, T value) + { + var cloned = (JObject)WrappedObject.DeepClone(); + var token = value is IJsonToken jToken ? jToken.Wrapped.DeepClone() : new JValue(value); + cloned.Add(tag, token); + var output = new JsonObject(cloned); + return output; + } + public JsonObject Remove(string tag) + { + try + { + if (!WrappedObject.ContainsKey(tag)) return this; + var output = (JObject)WrappedObject.DeepClone(); + output.Remove(tag); + return new JsonObject(output); + } + catch + { + return null; + } + } +} + +[DataModelType] +public class JsonArray : IJsonToken +{ + public JArray WrappedObject { get; private set; } + public JToken Wrapped => WrappedObject; + + public JsonArray(JArray wrap) => WrappedObject = wrap; + + public int Count => WrappedObject.Count; + public override string ToString() => WrappedObject.ToString(); + public static JsonArray FromString(string str) + { + try + { + return new JsonArray(JArray.Parse(str)); + } + catch + { + return null; + } + } + public T Get(int index) + { + try + { + if (typeof(T) == typeof(JsonObject)) return (T)(object)new JsonObject(WrappedObject[index].Value()); + if (typeof(T) == typeof(JsonArray)) return (T)(object)new JsonArray(WrappedObject[index].Value()); + return WrappedObject[index].Value() ?? default; + } + catch + { + return default; + } + } + public T GetValue(int index) where T : unmanaged + { + try + { + return WrappedObject[index].Value(); + } + catch + { + return default; + } + } + public T GetObject(int index) where T : class + { + try + { + if (typeof(T) == typeof(JsonObject)) + { + var value = WrappedObject[index].Value(); + if (value is null) return null; + return new JsonObject(value) as T; + } + if (typeof(T) == typeof(JsonArray)) + { + var value = WrappedObject[index].Value(); + if (value is null) return null; + return new JsonArray(value) as T; + } + return WrappedObject[index].Value(); + } + catch + { + return null; + } + } + public JsonArray Insert(int index, T value) + { + try + { + var cloned = (JArray)WrappedObject.DeepClone(); + var token = value switch + { + null => JValue.CreateNull(), + IJsonToken jToken => jToken.Wrapped.DeepClone(), + _ => new JValue(value), + }; + cloned.Insert(index, token); + var output = new JsonArray(cloned); + return output; + } + catch + { + return null; + } + } + public JsonArray Append(T value) + { + try + { + var cloned = (JArray)WrappedObject.DeepClone(); + var token = value switch + { + null => JValue.CreateNull(), + IJsonToken jToken => jToken.Wrapped.DeepClone(), + _ => new JValue(value), + }; + cloned.Add(token); + var output = new JsonArray(cloned); + return output; + } + catch + { + return null; + } + } + public JsonArray Remove(int index) + { + try + { + if (index < 0 || index >= Count) return this; + var output = (JArray)WrappedObject.DeepClone(); + output.RemoveAt(index); + return new JsonArray(output); + } + catch + { + return null; + } + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAddToObject.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAddToObject.cs deleted file mode 100644 index 1088fd6..0000000 --- a/ProjectObsidian/ProtoFlux/JSON/JsonAddToObject.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using Newtonsoft.Json.Linq; -using ProtoFlux.Core; -using ProtoFlux.Runtimes.Execution; -using Elements.Core; -using FrooxEngine; -using FrooxEngine.ProtoFlux; - -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json -{ - [NodeName("Add To Object")] - [NodeCategory("Obsidian/Json")] - [GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), - typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), - typeof(JToken), typeof(JObject), typeof(JArray))] - public class JsonAddToObjectNode : ObjectFunctionNode - { - public readonly ObjectInput Input; - public readonly ObjectInput Tag; - public readonly ObjectInput Object; - - protected override JObject Compute(FrooxEngineContext context) - { - var input = Input.Evaluate(context); - if (input == null) return null; - - var tag = Tag.Evaluate(context); - var obj = Object.Evaluate(context); - if (string.IsNullOrEmpty(tag) || obj == null) return input; - - var in2 = (JObject)input.DeepClone(); - in2[tag] = obj switch - { - JArray jArray => jArray, - JObject jObject => jObject, - JToken token => token, - _ => new JValue(obj) - }; - return in2; - } - } -} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAddToObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAddToObjectNode.cs new file mode 100644 index 0000000..867e749 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonAddToObjectNode.cs @@ -0,0 +1,36 @@ +using System; +using System.Linq; +using Newtonsoft.Json.Linq; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using Obsidian.Elements; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeName("Add To Object")] +[NodeCategory("Obsidian/Json")] +[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), + typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), + typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray))] +public class JsonAddToObjectNode : ObjectFunctionNode +{ + public readonly ObjectInput Input; + public readonly ObjectInput Tag; + public readonly ObjectInput Object; + + public static bool IsValidGenericType => JsonTypeHelper.AllValidTypes.Contains(typeof(T)); + + protected override JsonObject Compute(FrooxEngineContext context) + { + var input = Input.Evaluate(context); + if (input == null) return null; + + var tag = Tag.Evaluate(context); + var obj = Object.Evaluate(context); + + return string.IsNullOrEmpty(tag) ? input : input.Add(tag, obj); + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAppendToArray.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAppendToArray.cs deleted file mode 100644 index 37c5037..0000000 --- a/ProjectObsidian/ProtoFlux/JSON/JsonAppendToArray.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using Newtonsoft.Json.Linq; -using ProtoFlux.Core; -using ProtoFlux.Runtimes.Execution; -using FrooxEngine; -using Elements.Core; -using FrooxEngine.ProtoFlux; - -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json -{ - [NodeCategory("Obsidian/Json")] - [GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), - typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), typeof(JToken), typeof(JObject), - typeof(JArray))] - public class JsonAppendToArrayNode : ObjectFunctionNode - { - public readonly ObjectInput Array; - public readonly ObjectInput Object; - protected override JArray Compute(FrooxEngineContext context) - { - var array = Array.Evaluate(context); - var obj = Object.Evaluate(context); - if (array == null || obj == null) return null; - - try - { - var output = (JArray)array.DeepClone(); - output.Add(obj switch - { - JToken token => token, - _ => new JValue(obj) - }); - return output; - } - catch - { - return null; - } - } - } -} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAppendToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAppendToArrayNode.cs new file mode 100644 index 0000000..d5d3781 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonAppendToArrayNode.cs @@ -0,0 +1,29 @@ +using System; +using System.Linq; +using Newtonsoft.Json.Linq; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using FrooxEngine; +using Elements.Core; +using FrooxEngine.ProtoFlux; +using Obsidian.Elements; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeCategory("Obsidian/Json")] +[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), + typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), typeof(IJsonToken), typeof(JsonObject), + typeof(JsonArray))] +public class JsonAppendToArrayNode : ObjectFunctionNode +{ + public readonly ObjectInput Array; + public readonly ObjectInput Object; + + public static bool IsValidGenericType => JsonTypeHelper.AllValidTypes.Contains(typeof(T)); + protected override JsonArray Compute(FrooxEngineContext context) + { + var array = Array.Evaluate(context); + var obj = Object.Evaluate(context); + return array?.Append(obj); + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonCountArrayChildrenNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonCountArrayChildrenNode.cs index 3517dd2..21d25ec 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonCountArrayChildrenNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonCountArrayChildrenNode.cs @@ -1,5 +1,7 @@ -using FrooxEngine.ProtoFlux; +using System.Linq; +using FrooxEngine.ProtoFlux; using Newtonsoft.Json.Linq; +using Obsidian.Elements; using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; @@ -8,8 +10,8 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json [NodeCategory("Obsidian/Json")] public class JsonCountArrayChildrenNode : ValueFunctionNode { - public readonly ObjectInput Input; - + public readonly ObjectInput Input; + protected override int Compute(FrooxEngineContext context) { var input = Input.Evaluate(context); diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonCountObjectChildrenNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonCountObjectChildrenNode.cs index a4086da..0002bdf 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonCountObjectChildrenNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonCountObjectChildrenNode.cs @@ -1,5 +1,6 @@ using FrooxEngine.ProtoFlux; using Newtonsoft.Json.Linq; +using Obsidian.Elements; using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; @@ -8,7 +9,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json [NodeCategory("Obsidian/Json")] public class JsonCountObjectChildrenNode : ValueFunctionNode { - public readonly ObjectInput Input; + public readonly ObjectInput Input; protected override int Compute(FrooxEngineContext context) { diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonEmpty.cs b/ProjectObsidian/ProtoFlux/JSON/JsonEmpty.cs index fc712e5..9b1de8b 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonEmpty.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonEmpty.cs @@ -1,33 +1,19 @@ using FrooxEngine.ProtoFlux; using Newtonsoft.Json.Linq; +using Obsidian.Elements; using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeCategory("Obsidian/Json")] +public class JsonEmptyObjectNode : ObjectFunctionNode { - [NodeCategory("Obsidian/Json")] - public class JsonEmptyObjectNode : ObjectFunctionNode - { - protected override JObject Compute(FrooxEngineContext context) - { - return new JObject(); - } - } + protected override JsonObject Compute(FrooxEngineContext context) => new(new JObject()); +} - [NodeCategory("Obsidian/Json")] - public class JsonEmptyArrayNode : ObjectFunctionNode - { - protected override JArray Compute(FrooxEngineContext context) - { - return new JArray(); - } - } - [NodeCategory("Obsidian/Json")] - public class JsonNullValueNode : ObjectFunctionNode - { - protected override JToken Compute(FrooxEngineContext context) - { - return JValue.CreateNull(); - } - } +[NodeCategory("Obsidian/Json")] +public class JsonEmptyArrayNode : ObjectFunctionNode +{ + protected override JsonArray Compute(FrooxEngineContext context) => new(new JArray()); } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetFromArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetFromArrayNode.cs deleted file mode 100644 index 2524b5a..0000000 --- a/ProjectObsidian/ProtoFlux/JSON/JsonGetFromArrayNode.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using Newtonsoft.Json.Linq; -using ProtoFlux.Core; -using ProtoFlux.Runtimes.Execution; -using Elements.Core; -using FrooxEngine; -using FrooxEngine.ProtoFlux; - -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json -{ - [NodeCategory("Obsidian/Json")] - [GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), - typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), typeof(JToken), typeof(JObject), - typeof(JArray))] - public class JsonGetFromArrayNode : ObjectFunctionNode - { - public readonly ObjectInput Input; - public readonly ObjectInput Index; - - - protected override T Compute(FrooxEngineContext context) - { - var input = Input.Evaluate(context); - var index = Index.Evaluate(context); - if (input == null || index < 0 || index >= input.Count) - return default; - - try - { - return input[index].Value(); - } - catch - { - return default; - } - } - } -} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetFromObject.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetFromObject.cs deleted file mode 100644 index 64f8da4..0000000 --- a/ProjectObsidian/ProtoFlux/JSON/JsonGetFromObject.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using Newtonsoft.Json.Linq; -using ProtoFlux.Core; -using ProtoFlux.Runtimes.Execution; -using Elements.Core; -using FrooxEngine; -using FrooxEngine.ProtoFlux; - -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json -{ - [NodeCategory("Obsidian/Json")] - [GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), - typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), typeof(JToken), typeof(JObject), - typeof(JArray))] - public class JsonGetFromObjectNode : ObjectFunctionNode - { - public readonly ObjectInput Input; - public readonly ObjectInput Tag; - - protected override T Compute(FrooxEngineContext context) - { - var input = Input.Evaluate(context); - var tag = Tag.Evaluate(context); - if (input == null || string.IsNullOrEmpty(tag)) - return default; - - try - { - return input[tag].Value(); - } - catch - { - return default; - } - } - } -} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs new file mode 100644 index 0000000..180061f --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs @@ -0,0 +1,29 @@ +using System; +using System.Linq; +using Newtonsoft.Json.Linq; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using Obsidian.Elements; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeCategory("Obsidian/Json")] +[GenericTypes(typeof(string), typeof(Uri), typeof(JsonObject), typeof(JsonArray))] +public class JsonGetObjectFromArrayNode : ObjectFunctionNode where T : class +{ + public readonly ObjectInput Input; + public readonly ObjectInput Index; + public static bool IsValidGenericType => JsonTypeHelper.ValidObjectTypes.Contains(typeof(T)); + protected override T Compute(FrooxEngineContext context) + { + var input = Input.Evaluate(context); + var index = Index.Evaluate(context); + if (input == null || index < 0 || index >= input.Count) + return default; + + return input.GetObject(index); + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromObjectNode.cs new file mode 100644 index 0000000..48a3cfe --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromObjectNode.cs @@ -0,0 +1,28 @@ +using System; +using System.Linq; +using Newtonsoft.Json.Linq; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using Obsidian.Elements; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeCategory("Obsidian/Json")] +[GenericTypes(typeof(string), typeof(Uri), typeof(JsonObject), typeof(JsonArray))] +public class JsonGetObjectFromObjectNode : ObjectFunctionNode where T : class +{ + public readonly ObjectInput Input; + public readonly ObjectInput Tag; + public static bool IsValidGenericType => JsonTypeHelper.ValidObjectTypes.Contains(typeof(T)); + protected override T Compute(FrooxEngineContext context) + { + var input = Input.Evaluate(context); + var tag = Tag.Evaluate(context); + if (input == null || string.IsNullOrEmpty(tag)) + return default; + return input.GetObject(tag); + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs new file mode 100644 index 0000000..5fbe8f2 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs @@ -0,0 +1,27 @@ +using System.Linq; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using Obsidian.Elements; +using ProtoFlux.Runtimes.Execution; +using ProtoFlux.Core; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeCategory("Obsidian/Json")] +[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), + typeof(ulong), typeof(float), typeof(double))] +public class JsonGetValueFromArrayNode : ValueFunctionNode where T : unmanaged +{ + public readonly ObjectInput Input; + public readonly ObjectInput Index; + public static bool IsValidGenericType => JsonTypeHelper.ValidValueGetTypes.Contains(typeof(T)); + protected override T Compute(FrooxEngineContext context) + { + var input = Input.Evaluate(context); + var index = Index.Evaluate(context); + if (input == null || index < 0 || index >= input.Count) + return default; + + return input.GetValue(index); + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.cs new file mode 100644 index 0000000..9a5f4a4 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.cs @@ -0,0 +1,29 @@ +using System; +using System.Linq; +using Newtonsoft.Json.Linq; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using Obsidian.Elements; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeCategory("Obsidian/Json")] +[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), + typeof(ulong), typeof(float), typeof(double))] +public class JsonGetValueFromObjectNode : ValueFunctionNode where T : unmanaged +{ + public readonly ObjectInput Input; + public readonly ObjectInput Tag; + public static bool IsValidGenericType => JsonTypeHelper.ValidValueGetTypes.Contains(typeof(T)); + protected override T Compute(FrooxEngineContext context) + { + var input = Input.Evaluate(context); + var tag = Tag.Evaluate(context); + if (input == null || string.IsNullOrEmpty(tag)) + return default; + return input.GetValue(tag); + } +} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonInfo.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInfo.cs deleted file mode 100644 index 47f60c6..0000000 --- a/ProjectObsidian/ProtoFlux/JSON/JsonInfo.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using Newtonsoft.Json.Linq; - -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json -{ - public static class JsonInfo - { - public static readonly Type[] JsonTypes = - { - typeof(byte), - typeof(sbyte), - typeof(short), - typeof(ushort), - typeof(int), - typeof(uint), - typeof(long), - typeof(ulong), - typeof(float), - typeof(double), - typeof(string), - typeof(Uri), - typeof(JToken), - typeof(JObject), - typeof(JArray), - }; - } -} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonInsertToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInsertToArrayNode.cs index 044c924..abf4660 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonInsertToArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonInsertToArrayNode.cs @@ -1,42 +1,34 @@ using System; +using System.Linq; using Newtonsoft.Json.Linq; using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; using Elements.Core; using FrooxEngine; using FrooxEngine.ProtoFlux; +using Obsidian.Elements; namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json { [NodeCategory("Obsidian/Json")] [GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), - typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), typeof(JToken), typeof(JObject), - typeof(JArray))] - public class JsonInsertToArrayNode : ObjectFunctionNode + typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), + typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray))] + public class JsonInsertToArrayNode : ObjectFunctionNode { - public readonly ObjectInput Array; + public readonly ObjectInput Array; public readonly ObjectInput Object; public readonly ObjectInput Index; - - protected override JArray Compute(FrooxEngineContext context) + public static bool IsValidGenericType => JsonTypeHelper.AllValidTypes.Contains(typeof(T)); + protected override JsonArray Compute(FrooxEngineContext context) { var array = Array.Evaluate(context); var obj = Object.Evaluate(context); var index = Index.Evaluate(context); - if (array == null || obj == null || index < 0 || index > array.Count) + if (array == null || index < 0 || index > array.Count) return null; - try - { - var output = (JArray)array.DeepClone(); - var token = obj is JToken jToken ? jToken : new JValue(obj); - output.Insert(index, token); - return output; - } - catch - { - return null; - } + return array.Insert(index, obj); } } } diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArray.cs b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArrayNode.cs similarity index 50% rename from ProjectObsidian/ProtoFlux/JSON/JsonParseStringArray.cs rename to ProjectObsidian/ProtoFlux/JSON/JsonParseStringArrayNode.cs index 7d18d4d..df553dd 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArray.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArrayNode.cs @@ -1,32 +1,21 @@ using System; using FrooxEngine.ProtoFlux; using Newtonsoft.Json.Linq; +using Obsidian.Elements; using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json { [NodeCategory("Obsidian/Json")] - public class JsonParseStringArrayNode : ObjectFunctionNode + public class JsonParseStringArrayNode : ObjectFunctionNode { public readonly ObjectInput Input; - protected override JArray Compute(FrooxEngineContext context) + protected override JsonArray Compute(FrooxEngineContext context) { var input = Input.Evaluate(context); - if (string.IsNullOrEmpty(input)) - return null; - - try - { - var output = JArray.Parse(input); - return output; - } - catch - { - // In case of parsing error, return null - return null; - } + return string.IsNullOrEmpty(input) ? null : JsonArray.FromString(input); } } } diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringNode.cs deleted file mode 100644 index 1624cd1..0000000 --- a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringNode.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using FrooxEngine.ProtoFlux; -using Newtonsoft.Json.Linq; -using ProtoFlux.Core; -using ProtoFlux.Runtimes.Execution; - -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json -{ - [NodeCategory("Obsidian/Json")] - public class JsonParseStringNode : ObjectFunctionNode - { - public readonly ObjectInput Input; - - - protected override JObject Compute(FrooxEngineContext context) - { - var input = Input.Evaluate(context); - if (string.IsNullOrEmpty(input)) - return null; - - try - { - var output = JObject.Parse(input); - return output; - } - catch - { - // In case of parsing error, return null - return null; - } - } - } -} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringObjectNode.cs new file mode 100644 index 0000000..360143d --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringObjectNode.cs @@ -0,0 +1,22 @@ +using System; +using FrooxEngine.ProtoFlux; +using Newtonsoft.Json.Linq; +using Obsidian.Elements; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json +{ + [NodeCategory("Obsidian/Json")] + public class JsonParseStringObjectNode : ObjectFunctionNode + { + public readonly ObjectInput Input; + + + protected override JsonObject Compute(FrooxEngineContext context) + { + var input = Input.Evaluate(context); + return string.IsNullOrEmpty(input) ? null : JsonObject.FromString(input); + } + } +} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObject.cs b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObject.cs deleted file mode 100644 index b5e491d..0000000 --- a/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObject.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using Newtonsoft.Json.Linq; -using ProtoFlux.Core; -using ProtoFlux.Runtimes.Execution; -using Elements.Core; -using FrooxEngine; -using FrooxEngine.ProtoFlux; - -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json -{ - [NodeCategory("Obsidian/Json")] - [GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), - typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), typeof(JToken), typeof(JObject), - typeof(JArray))] - public class JsonQuickGetFromObjectNode : ObjectFunctionNode - { - public readonly ObjectInput Input; - public readonly ObjectInput Tag; - protected override T Compute(FrooxEngineContext context) - { - var input = Input.Evaluate(context); - var tag = Tag.Evaluate(context); - if (string.IsNullOrEmpty(input) || string.IsNullOrEmpty(tag)) - return default; - - try - { - var inputObject = JObject.Parse(input); - return inputObject[tag].Value() ?? default; - } - catch - { - // In case of parsing error or if the tag is not found - return default; - } - } - } -} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObjectFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObjectFromObjectNode.cs new file mode 100644 index 0000000..14b9b83 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObjectFromObjectNode.cs @@ -0,0 +1,29 @@ +using System; +using System.Linq; +using Newtonsoft.Json.Linq; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using Obsidian.Elements; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeCategory("Obsidian/Json")] +[GenericTypes(typeof(string), typeof(Uri), typeof(JsonObject), typeof(JsonArray))] +public class JsonQuickGetObjectFromObjectNode : ObjectFunctionNode where T : class +{ + public readonly ObjectInput Input; + public readonly ObjectInput Tag; + public static bool IsValidGenericType => JsonTypeHelper.ValidObjectTypes.Contains(typeof(T)); + protected override T Compute(FrooxEngineContext context) + { + var input = Input.Evaluate(context); + var tag = Tag.Evaluate(context); + if (string.IsNullOrEmpty(input) || string.IsNullOrEmpty(tag)) + return default; + var from = JsonObject.FromString(input); + return from?.GetObject(tag); + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValueFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValueFromObjectNode.cs new file mode 100644 index 0000000..2ead36d --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValueFromObjectNode.cs @@ -0,0 +1,30 @@ +using System; +using System.Linq; +using Newtonsoft.Json.Linq; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using Obsidian.Elements; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeCategory("Obsidian/Json")] +[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), + typeof(ulong), typeof(float), typeof(double))] +public class JsonQuickGetValueFromObjectNode : ValueFunctionNode where T : unmanaged +{ + public readonly ObjectInput Input; + public readonly ObjectInput Tag; + public static bool IsValidGenericType => JsonTypeHelper.ValidValueGetTypes.Contains(typeof(T)); + protected override T Compute(FrooxEngineContext context) + { + var input = Input.Evaluate(context); + var tag = Tag.Evaluate(context); + if (string.IsNullOrEmpty(input) || string.IsNullOrEmpty(tag)) + return default; + var from = JsonObject.FromString(input); + return from?.GetValue(tag) ?? default; + } +} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromArrayNode.cs index 25ea200..72c42b0 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromArrayNode.cs @@ -1,36 +1,27 @@ using System; using FrooxEngine.ProtoFlux; using Newtonsoft.Json.Linq; +using Obsidian.Elements; using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json { [NodeCategory("Obsidian/Json")] - public class JsonRemoveFromArrayNode : ObjectFunctionNode + public class JsonRemoveFromArrayNode : ObjectFunctionNode { - public readonly ObjectInput Array; + public readonly ObjectInput Array; public readonly ObjectInput Index; - protected override JArray Compute(FrooxEngineContext context) + protected override JsonArray Compute(FrooxEngineContext context) { var array = Array.Evaluate(context); var index = Index.Evaluate(context); if (array == null || index < 0 || index >= array.Count) return null; - try - { - var output = (JArray)array.DeepClone(); - output.RemoveAt(index); - return output; - } - catch - { - // In case of an error, return null - return null; - } + return array.Remove(index); } } } diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromObjectNode.cs index 7fa503b..0751c39 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromObjectNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromObjectNode.cs @@ -1,29 +1,26 @@ using System; using FrooxEngine.ProtoFlux; using Newtonsoft.Json.Linq; +using Obsidian.Elements; using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json { [NodeCategory("Obsidian/Json")] - public class JsonRemoveFromObjectNode : ObjectFunctionNode + public class JsonRemoveFromObjectNode : ObjectFunctionNode { - public readonly ObjectInput Input; + public readonly ObjectInput Input; public readonly ObjectInput Tag; - protected override JObject Compute(FrooxEngineContext context) + protected override JsonObject Compute(FrooxEngineContext context) { var input = Input.Evaluate(context); if (input == null) return null; var tag = Tag.Evaluate(context); - if (string.IsNullOrEmpty(tag)) return input; - - var output = (JObject)input.DeepClone(); - output.Remove(tag); - return output; + return string.IsNullOrEmpty(tag) ? input : input.Remove(tag); } } } diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonToStringNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonToStringNode.cs index 6d2ddd5..a1ed246 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonToStringNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonToStringNode.cs @@ -1,18 +1,20 @@ using System; +using System.Linq; using FrooxEngine; using FrooxEngine.ProtoFlux; using Newtonsoft.Json.Linq; +using Obsidian.Elements; using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; [NodeCategory("Obsidian/Json")] -[GenericTypes(typeof(JToken), typeof(JObject), typeof(JArray))] +[GenericTypes(typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray))] public class JsonToStringNode : ObjectFunctionNode { public readonly ObjectInput Input; - + public static bool IsValidGenericType => JsonTypeHelper.JsonTokens.Contains(typeof(T)); protected override string Compute(FrooxEngineContext context) { var input = Input.Evaluate(context); diff --git a/ProjectObsidian/ProtoFlux/NodeExstensions.cs b/ProjectObsidian/ProtoFlux/NodeExtensions.cs similarity index 61% rename from ProjectObsidian/ProtoFlux/NodeExstensions.cs rename to ProjectObsidian/ProtoFlux/NodeExtensions.cs index 7cb2128..2ccf4b4 100644 --- a/ProjectObsidian/ProtoFlux/NodeExstensions.cs +++ b/ProjectObsidian/ProtoFlux/NodeExtensions.cs @@ -24,7 +24,9 @@ public static class NodeExtensions public static readonly Dictionary MorseToChar = CharToMorse.ToDictionary(i => i.Value, j => j.Key); - private static readonly int[] permutation = { 151,160,137,91,90,15, + private static readonly int[] Permutation = + { + 151,160,137,91,90,15, 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142, 8,99,37,240,21,10,23,190, 6,148,247,120,234,75,0,26, 197,62,94,252,219,203,117,35,11,32,57,177,33,88,237, @@ -44,59 +46,49 @@ public static class NodeExtensions 67,29,24,72,243,141,128,195,78,66,215,61,156,180 }; - private static readonly int[] p; + private static readonly int[] P = new int[512]; static NodeExtensions() { - p = new int[512]; - for (int x = 0; x < 512; x++) - { - p[x] = permutation[x % 256]; - } + for (var x = 0; x < 512; x++) P[x] = Permutation[x % 256]; } public static float PerlinNoise(float x, float y, float z) { - int X = (int)MathX.Floor(x) & 255; - int Y = (int)MathX.Floor(y) & 255; - int Z = (int)MathX.Floor(z) & 255; + var X = (int)MathX.Floor(x) & 255; + var Y = (int)MathX.Floor(y) & 255; + var Z = (int)MathX.Floor(z) & 255; - x -= (float)MathX.Floor(x); - y -= (float)MathX.Floor(y); - z -= (float)MathX.Floor(z); + x -= MathX.Floor(x); + y -= MathX.Floor(y); + z -= MathX.Floor(z); - float u = Fade(x); - float v = Fade(y); - float w = Fade(z); + var u = Fade(x); + var v = Fade(y); + var w = Fade(z); - int A = p[X] + Y; - int AA = p[A] + Z; - int AB = p[A + 1] + Z; - int B = p[X + 1] + Y; - int BA = p[B] + Z; - int BB = p[B + 1] + Z; + var A = P[X] + Y; + var AA = P[A] + Z; + var AB = P[A + 1] + Z; + var B = P[X + 1] + Y; + var BA = P[B] + Z; + var BB = P[B + 1] + Z; - return Lerp(w, Lerp(v, Lerp(u, Grad(p[AA], x, y, z), Grad(p[BA], x - 1, y, z)), - Lerp(u, Grad(p[AB], x, y - 1, z), Grad(p[BB], x - 1, y - 1, z))), - Lerp(v, Lerp(u, Grad(p[AA + 1], x, y, z - 1), Grad(p[BA + 1], x - 1, y, z - 1)), - Lerp(u, Grad(p[AB + 1], x, y - 1, z - 1), Grad(p[BB + 1], x - 1, y - 1, z - 1)))); + return Lerp(w, Lerp(v, Lerp(u, Grad(P[AA], x, y, z), Grad(P[BA], x - 1, y, z)), + Lerp(u, Grad(P[AB], x, y - 1, z), Grad(P[BB], x - 1, y - 1, z))), + Lerp(v, Lerp(u, Grad(P[AA + 1], x, y, z - 1), Grad(P[BA + 1], x - 1, y, z - 1)), + Lerp(u, Grad(P[AB + 1], x, y - 1, z - 1), Grad(P[BB + 1], x - 1, y - 1, z - 1)))); } - private static float Fade(float t) - { - return t * t * t * (t * (t * 6 - 15) + 10); - } + private static float Fade(float t) => t * t * t * (t * (t * 6 - 15) + 10); - private static float Lerp(float t, float a, float b) - { - return a + t * (b - a); - } + private static float Lerp(float t, float a, float b) => a + t * (b - a); private static float Grad(int hash, float x, float y, float z) { - int h = hash & 15; - float u = h < 8 ? x : y; - float v = h < 4 ? y : h == 12 || h == 14 ? x : z; + var h = hash & 15; + var u = h < 8 ? x : y; + var v = h < 4 ? y : h is 12 or 14 ? x : z; return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v); } } From a39f384fdeba7ed7cfb43d8550764cb0a16e7e9e Mon Sep 17 00:00:00 2001 From: frozenreflex Date: Sun, 14 Jul 2024 00:50:01 -0500 Subject: [PATCH 2/5] Restore NodeNameOverride --- ProjectObsidian.SourceGenerators/BindingGenerator.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ProjectObsidian.SourceGenerators/BindingGenerator.cs b/ProjectObsidian.SourceGenerators/BindingGenerator.cs index 9a8af23..4bfc162 100644 --- a/ProjectObsidian.SourceGenerators/BindingGenerator.cs +++ b/ProjectObsidian.SourceGenerators/BindingGenerator.cs @@ -151,6 +151,7 @@ public partial class {_fullName} : global::FrooxEngine.ProtoFlux.Runtimes.Execut {{ {(string.IsNullOrEmpty(_debug) ? "" : "//")}{_debug} {Declarations} +{_nodeNameOverride} {(_isValidGenericTypeMethod ? $" public static bool IsValidGenericType => global::{_currentNameSpace}.{_fullName}.IsValidGenericType;" : "")} public override System.Type NodeType => typeof (global::{_currentNameSpace}.{_fullName}); public global::{_currentNameSpace}.{_fullName} TypedNodeInstance {{ get; private set; }} From a33a54fa1e364f73919bd50e8e746d90923009af Mon Sep 17 00:00:00 2001 From: frozenreflex Date: Sun, 14 Jul 2024 02:45:37 -0500 Subject: [PATCH 3/5] Fix Json value inputs --- ProjectObsidian/Elements/JsonTypes.cs | 8 +++-- .../JSON/JsonAddObjectToObjectNode.cs | 34 +++++++++++++++++++ ...ectNode.cs => JsonAddValueToObjectNode.cs} | 13 ++++--- .../JSON/JsonAppendObjectToArrayNode.cs | 28 +++++++++++++++ ...yNode.cs => JsonAppendValueToArrayNode.cs} | 14 ++++---- .../JSON/JsonCountArrayChildrenNode.cs | 1 + .../JSON/JsonCountObjectChildrenNode.cs | 1 + .../ProtoFlux/JSON/JsonEmptyArrayNode.cs | 14 ++++++++ .../{JsonEmpty.cs => JsonEmptyObjectNode.cs} | 7 +--- .../JSON/JsonGetObjectFromArrayNode.cs | 3 +- .../JSON/JsonGetObjectFromObjectNode.cs | 3 +- .../JSON/JsonGetValueFromArrayNode.cs | 3 +- .../JSON/JsonGetValueFromObjectNode.cs | 3 +- .../JSON/JsonInsertObjectToArrayNode.cs | 33 ++++++++++++++++++ .../ProtoFlux/JSON/JsonInsertToArrayNode.cs | 34 ------------------- .../JSON/JsonInsertValueToArrayNode.cs | 32 +++++++++++++++++ .../JSON/JsonParseStringArrayNode.cs | 22 ++++++------ .../JSON/JsonParseStringObjectNode.cs | 22 ++++++------ .../JSON/JsonQuickGetObjectFromObjectNode.cs | 3 +- .../JSON/JsonQuickGetValueFromObjectNode.cs | 3 +- .../ProtoFlux/JSON/JsonRemoveFromArrayNode.cs | 30 ++++++++-------- .../JSON/JsonRemoveFromObjectNode.cs | 28 +++++++-------- .../ProtoFlux/JSON/JsonToStringNode.cs | 1 + 23 files changed, 227 insertions(+), 113 deletions(-) create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonAddObjectToObjectNode.cs rename ProjectObsidian/ProtoFlux/JSON/{JsonAddToObjectNode.cs => JsonAddValueToObjectNode.cs} (68%) create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonAppendObjectToArrayNode.cs rename ProjectObsidian/ProtoFlux/JSON/{JsonAppendToArrayNode.cs => JsonAppendValueToArrayNode.cs} (62%) create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonEmptyArrayNode.cs rename ProjectObsidian/ProtoFlux/JSON/{JsonEmpty.cs => JsonEmptyObjectNode.cs} (66%) create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs delete mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonInsertToArrayNode.cs create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs diff --git a/ProjectObsidian/Elements/JsonTypes.cs b/ProjectObsidian/Elements/JsonTypes.cs index 108b605..158841d 100644 --- a/ProjectObsidian/Elements/JsonTypes.cs +++ b/ProjectObsidian/Elements/JsonTypes.cs @@ -23,15 +23,19 @@ public static class JsonTypeHelper typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), typeof(JsonObject), typeof(JsonArray), }; - public static readonly Type[] ValidValueGetTypes = + public static readonly Type[] ValidValueTypes = { typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double) }; - public static readonly Type[] ValidObjectTypes = + public static readonly Type[] ValidObjectGetTypes = { typeof(string), typeof(Uri), typeof(JsonObject), typeof(JsonArray), }; + public static readonly Type[] ValidObjectSetTypes = + { + typeof(string), typeof(Uri), typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray), + }; } [DataModelType] diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAddObjectToObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAddObjectToObjectNode.cs new file mode 100644 index 0000000..e50f4a0 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonAddObjectToObjectNode.cs @@ -0,0 +1,34 @@ +using System; +using System.Linq; +using Newtonsoft.Json.Linq; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using Obsidian.Elements; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeName("Add To Object")] +[NodeCategory("Obsidian/Json")] +[GenericTypes(typeof(string), typeof(Uri), typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray))] +public class JsonAddObjectToObjectNode : ObjectFunctionNode where T : class +{ + public readonly ObjectInput Input; + public readonly ObjectInput Tag; + public readonly ObjectInput Object; + + public static bool IsValidGenericType => JsonTypeHelper.ValidObjectSetTypes.Contains(typeof(T)); + + protected override JsonObject Compute(FrooxEngineContext context) + { + var input = Input.Evaluate(context); + if (input == null) return null; + + var tag = Tag.Evaluate(context); + var obj = Object.Evaluate(context); + + return string.IsNullOrEmpty(tag) ? input : input.Add(tag, obj); + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAddToObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAddValueToObjectNode.cs similarity index 68% rename from ProjectObsidian/ProtoFlux/JSON/JsonAddToObjectNode.cs rename to ProjectObsidian/ProtoFlux/JSON/JsonAddValueToObjectNode.cs index 867e749..ddea561 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonAddToObjectNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonAddValueToObjectNode.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using Newtonsoft.Json.Linq; using ProtoFlux.Core; @@ -13,15 +13,14 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; [NodeName("Add To Object")] [NodeCategory("Obsidian/Json")] [GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), - typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), - typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray))] -public class JsonAddToObjectNode : ObjectFunctionNode + typeof(long), typeof(ulong), typeof(float), typeof(double))] +public class JsonAddValueToObjectNode : ObjectFunctionNode where T : unmanaged { public readonly ObjectInput Input; public readonly ObjectInput Tag; - public readonly ObjectInput Object; + public readonly ValueInput Object; - public static bool IsValidGenericType => JsonTypeHelper.AllValidTypes.Contains(typeof(T)); + public static bool IsValidGenericType => JsonTypeHelper.ValidValueTypes.Contains(typeof(T)); protected override JsonObject Compute(FrooxEngineContext context) { @@ -33,4 +32,4 @@ protected override JsonObject Compute(FrooxEngineContext context) return string.IsNullOrEmpty(tag) ? input : input.Add(tag, obj); } -} \ No newline at end of file +} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAppendObjectToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAppendObjectToArrayNode.cs new file mode 100644 index 0000000..dbdfdd2 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonAppendObjectToArrayNode.cs @@ -0,0 +1,28 @@ +using System; +using System.Linq; +using Newtonsoft.Json.Linq; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using FrooxEngine; +using Elements.Core; +using FrooxEngine.ProtoFlux; +using Obsidian.Elements; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeName("Append To Array")] +[NodeCategory("Obsidian/Json")] +[GenericTypes(typeof(string), typeof(Uri), typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray))] +public class JsonAppendObjectToArrayNode : ObjectFunctionNode where T : class +{ + public readonly ObjectInput Array; + public readonly ObjectInput Object; + + public static bool IsValidGenericType => JsonTypeHelper.ValidObjectSetTypes.Contains(typeof(T)); + protected override JsonArray Compute(FrooxEngineContext context) + { + var array = Array.Evaluate(context); + var obj = Object.Evaluate(context); + return array?.Append(obj); + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAppendToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToArrayNode.cs similarity index 62% rename from ProjectObsidian/ProtoFlux/JSON/JsonAppendToArrayNode.cs rename to ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToArrayNode.cs index d5d3781..c4b499c 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonAppendToArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToArrayNode.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using Newtonsoft.Json.Linq; using ProtoFlux.Core; @@ -10,16 +10,16 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; +[NodeName("Append To Array")] [NodeCategory("Obsidian/Json")] [GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), - typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), typeof(IJsonToken), typeof(JsonObject), - typeof(JsonArray))] -public class JsonAppendToArrayNode : ObjectFunctionNode + typeof(ulong), typeof(float), typeof(double))] +public class JsonAppendValueToArrayNode : ObjectFunctionNode where T : unmanaged { public readonly ObjectInput Array; - public readonly ObjectInput Object; - - public static bool IsValidGenericType => JsonTypeHelper.AllValidTypes.Contains(typeof(T)); + public readonly ValueInput Object; + + public static bool IsValidGenericType => JsonTypeHelper.ValidValueTypes.Contains(typeof(T)); protected override JsonArray Compute(FrooxEngineContext context) { var array = Array.Evaluate(context); diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonCountArrayChildrenNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonCountArrayChildrenNode.cs index 21d25ec..8ca21a0 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonCountArrayChildrenNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonCountArrayChildrenNode.cs @@ -7,6 +7,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json { + [NodeName("Count")] [NodeCategory("Obsidian/Json")] public class JsonCountArrayChildrenNode : ValueFunctionNode { diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonCountObjectChildrenNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonCountObjectChildrenNode.cs index 0002bdf..33b374e 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonCountObjectChildrenNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonCountObjectChildrenNode.cs @@ -6,6 +6,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json { + [NodeName("Count")] [NodeCategory("Obsidian/Json")] public class JsonCountObjectChildrenNode : ValueFunctionNode { diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonEmptyArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonEmptyArrayNode.cs new file mode 100644 index 0000000..33d3cb3 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonEmptyArrayNode.cs @@ -0,0 +1,14 @@ +using FrooxEngine.ProtoFlux; +using Newtonsoft.Json.Linq; +using Obsidian.Elements; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeName("Empty JsonArray")] +[NodeCategory("Obsidian/Json")] +public class JsonEmptyArrayNode : ObjectFunctionNode +{ + protected override JsonArray Compute(FrooxEngineContext context) => new(new JArray()); +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonEmpty.cs b/ProjectObsidian/ProtoFlux/JSON/JsonEmptyObjectNode.cs similarity index 66% rename from ProjectObsidian/ProtoFlux/JSON/JsonEmpty.cs rename to ProjectObsidian/ProtoFlux/JSON/JsonEmptyObjectNode.cs index 9b1de8b..15182d1 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonEmpty.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonEmptyObjectNode.cs @@ -6,14 +6,9 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; +[NodeName("Empty JsonObject")] [NodeCategory("Obsidian/Json")] public class JsonEmptyObjectNode : ObjectFunctionNode { protected override JsonObject Compute(FrooxEngineContext context) => new(new JObject()); -} - -[NodeCategory("Obsidian/Json")] -public class JsonEmptyArrayNode : ObjectFunctionNode -{ - protected override JsonArray Compute(FrooxEngineContext context) => new(new JArray()); } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs index 180061f..caf3b75 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs @@ -10,13 +10,14 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; +[NodeName("Get From Array")] [NodeCategory("Obsidian/Json")] [GenericTypes(typeof(string), typeof(Uri), typeof(JsonObject), typeof(JsonArray))] public class JsonGetObjectFromArrayNode : ObjectFunctionNode where T : class { public readonly ObjectInput Input; public readonly ObjectInput Index; - public static bool IsValidGenericType => JsonTypeHelper.ValidObjectTypes.Contains(typeof(T)); + public static bool IsValidGenericType => JsonTypeHelper.ValidObjectGetTypes.Contains(typeof(T)); protected override T Compute(FrooxEngineContext context) { var input = Input.Evaluate(context); diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromObjectNode.cs index 48a3cfe..f3b6f79 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromObjectNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromObjectNode.cs @@ -10,13 +10,14 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; +[NodeName("Get From Object")] [NodeCategory("Obsidian/Json")] [GenericTypes(typeof(string), typeof(Uri), typeof(JsonObject), typeof(JsonArray))] public class JsonGetObjectFromObjectNode : ObjectFunctionNode where T : class { public readonly ObjectInput Input; public readonly ObjectInput Tag; - public static bool IsValidGenericType => JsonTypeHelper.ValidObjectTypes.Contains(typeof(T)); + public static bool IsValidGenericType => JsonTypeHelper.ValidObjectGetTypes.Contains(typeof(T)); protected override T Compute(FrooxEngineContext context) { var input = Input.Evaluate(context); diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs index 5fbe8f2..686f570 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs @@ -7,6 +7,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; +[NodeName("Get From Array")] [NodeCategory("Obsidian/Json")] [GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double))] @@ -14,7 +15,7 @@ public class JsonGetValueFromArrayNode : ValueFunctionNode Input; public readonly ObjectInput Index; - public static bool IsValidGenericType => JsonTypeHelper.ValidValueGetTypes.Contains(typeof(T)); + public static bool IsValidGenericType => JsonTypeHelper.ValidValueTypes.Contains(typeof(T)); protected override T Compute(FrooxEngineContext context) { var input = Input.Evaluate(context); diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.cs index 9a5f4a4..4d03085 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.cs @@ -10,6 +10,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; +[NodeName("Get From Object")] [NodeCategory("Obsidian/Json")] [GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double))] @@ -17,7 +18,7 @@ public class JsonGetValueFromObjectNode : ValueFunctionNode Input; public readonly ObjectInput Tag; - public static bool IsValidGenericType => JsonTypeHelper.ValidValueGetTypes.Contains(typeof(T)); + public static bool IsValidGenericType => JsonTypeHelper.ValidValueTypes.Contains(typeof(T)); protected override T Compute(FrooxEngineContext context) { var input = Input.Evaluate(context); diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs new file mode 100644 index 0000000..6401c9a --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs @@ -0,0 +1,33 @@ +using System; +using System.Linq; +using Newtonsoft.Json.Linq; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using Obsidian.Elements; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeName("Insert To Array")] +[NodeCategory("Obsidian/Json")] +[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), + typeof(long), typeof(ulong), typeof(float), typeof(double))] +public class JsonInsertObjectToArrayNode : ObjectFunctionNode +{ + public readonly ObjectInput Array; + public readonly ObjectInput Object; + public readonly ObjectInput Index; + public static bool IsValidGenericType => JsonTypeHelper.ValidObjectSetTypes.Contains(typeof(T)); + protected override JsonArray Compute(FrooxEngineContext context) + { + var array = Array.Evaluate(context); + var obj = Object.Evaluate(context); + var index = Index.Evaluate(context); + if (array == null || index < 0 || index > array.Count) + return null; + + return array.Insert(index, obj); + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonInsertToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInsertToArrayNode.cs deleted file mode 100644 index abf4660..0000000 --- a/ProjectObsidian/ProtoFlux/JSON/JsonInsertToArrayNode.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Linq; -using Newtonsoft.Json.Linq; -using ProtoFlux.Core; -using ProtoFlux.Runtimes.Execution; -using Elements.Core; -using FrooxEngine; -using FrooxEngine.ProtoFlux; -using Obsidian.Elements; - -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json -{ - [NodeCategory("Obsidian/Json")] - [GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), - typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(Uri), - typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray))] - public class JsonInsertToArrayNode : ObjectFunctionNode - { - public readonly ObjectInput Array; - public readonly ObjectInput Object; - public readonly ObjectInput Index; - public static bool IsValidGenericType => JsonTypeHelper.AllValidTypes.Contains(typeof(T)); - protected override JsonArray Compute(FrooxEngineContext context) - { - var array = Array.Evaluate(context); - var obj = Object.Evaluate(context); - var index = Index.Evaluate(context); - if (array == null || index < 0 || index > array.Count) - return null; - - return array.Insert(index, obj); - } - } -} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs new file mode 100644 index 0000000..e25794f --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs @@ -0,0 +1,32 @@ +using System; +using System.Linq; +using Newtonsoft.Json.Linq; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using Obsidian.Elements; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeName("Insert To Array")] +[NodeCategory("Obsidian/Json")] +[GenericTypes(typeof(string), typeof(Uri), typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray))] +public class JsonInsertValueToArrayNode : ObjectFunctionNode +{ + public readonly ObjectInput Array; + public readonly ObjectInput Object; + public readonly ValueInput Index; + public static bool IsValidGenericType => JsonTypeHelper.ValidValueTypes.Contains(typeof(T)); + protected override JsonArray Compute(FrooxEngineContext context) + { + var array = Array.Evaluate(context); + var obj = Object.Evaluate(context); + var index = Index.Evaluate(context); + if (array == null || index < 0 || index > array.Count) + return null; + + return array.Insert(index, obj); + } +} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArrayNode.cs index df553dd..f8c8020 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArrayNode.cs @@ -5,17 +5,17 @@ using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeName("JsonArray From String")] +[NodeCategory("Obsidian/Json")] +public class JsonParseStringArrayNode : ObjectFunctionNode { - [NodeCategory("Obsidian/Json")] - public class JsonParseStringArrayNode : ObjectFunctionNode - { - public readonly ObjectInput Input; + public readonly ObjectInput Input; - protected override JsonArray Compute(FrooxEngineContext context) - { - var input = Input.Evaluate(context); - return string.IsNullOrEmpty(input) ? null : JsonArray.FromString(input); - } + protected override JsonArray Compute(FrooxEngineContext context) + { + var input = Input.Evaluate(context); + return string.IsNullOrEmpty(input) ? null : JsonArray.FromString(input); } -} +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringObjectNode.cs index 360143d..07732e7 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringObjectNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringObjectNode.cs @@ -5,18 +5,18 @@ using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeName("JsonObject From String")] +[NodeCategory("Obsidian/Json")] +public class JsonParseStringObjectNode : ObjectFunctionNode { - [NodeCategory("Obsidian/Json")] - public class JsonParseStringObjectNode : ObjectFunctionNode - { - public readonly ObjectInput Input; + public readonly ObjectInput Input; - protected override JsonObject Compute(FrooxEngineContext context) - { - var input = Input.Evaluate(context); - return string.IsNullOrEmpty(input) ? null : JsonObject.FromString(input); - } + protected override JsonObject Compute(FrooxEngineContext context) + { + var input = Input.Evaluate(context); + return string.IsNullOrEmpty(input) ? null : JsonObject.FromString(input); } -} +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObjectFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObjectFromObjectNode.cs index 14b9b83..09d5009 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObjectFromObjectNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObjectFromObjectNode.cs @@ -10,13 +10,14 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; +[NodeName("Quick Get From Object")] [NodeCategory("Obsidian/Json")] [GenericTypes(typeof(string), typeof(Uri), typeof(JsonObject), typeof(JsonArray))] public class JsonQuickGetObjectFromObjectNode : ObjectFunctionNode where T : class { public readonly ObjectInput Input; public readonly ObjectInput Tag; - public static bool IsValidGenericType => JsonTypeHelper.ValidObjectTypes.Contains(typeof(T)); + public static bool IsValidGenericType => JsonTypeHelper.ValidObjectGetTypes.Contains(typeof(T)); protected override T Compute(FrooxEngineContext context) { var input = Input.Evaluate(context); diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValueFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValueFromObjectNode.cs index 2ead36d..bba5e0d 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValueFromObjectNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValueFromObjectNode.cs @@ -10,6 +10,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; +[NodeName("Quick Get From Object")] [NodeCategory("Obsidian/Json")] [GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double))] @@ -17,7 +18,7 @@ public class JsonQuickGetValueFromObjectNode : ValueFunctionNode Input; public readonly ObjectInput Tag; - public static bool IsValidGenericType => JsonTypeHelper.ValidValueGetTypes.Contains(typeof(T)); + public static bool IsValidGenericType => JsonTypeHelper.ValidValueTypes.Contains(typeof(T)); protected override T Compute(FrooxEngineContext context) { var input = Input.Evaluate(context); diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromArrayNode.cs index 72c42b0..870d0f9 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromArrayNode.cs @@ -5,23 +5,23 @@ using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeName("Remove From Array")] +[NodeCategory("Obsidian/Json")] +public class JsonRemoveFromArrayNode : ObjectFunctionNode { - [NodeCategory("Obsidian/Json")] - public class JsonRemoveFromArrayNode : ObjectFunctionNode - { - public readonly ObjectInput Array; - public readonly ObjectInput Index; + public readonly ObjectInput Array; + public readonly ObjectInput Index; - protected override JsonArray Compute(FrooxEngineContext context) - { - var array = Array.Evaluate(context); - var index = Index.Evaluate(context); - if (array == null || index < 0 || index >= array.Count) - return null; + protected override JsonArray Compute(FrooxEngineContext context) + { + var array = Array.Evaluate(context); + var index = Index.Evaluate(context); + if (array == null || index < 0 || index >= array.Count) + return null; - return array.Remove(index); - } + return array.Remove(index); } -} +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromObjectNode.cs index 0751c39..705015f 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromObjectNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromObjectNode.cs @@ -5,22 +5,22 @@ using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; -namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; + +[NodeName("Remove From Object")] +[NodeCategory("Obsidian/Json")] +public class JsonRemoveFromObjectNode : ObjectFunctionNode { - [NodeCategory("Obsidian/Json")] - public class JsonRemoveFromObjectNode : ObjectFunctionNode - { - public readonly ObjectInput Input; - public readonly ObjectInput Tag; + public readonly ObjectInput Input; + public readonly ObjectInput Tag; - protected override JsonObject Compute(FrooxEngineContext context) - { - var input = Input.Evaluate(context); - if (input == null) return null; + protected override JsonObject Compute(FrooxEngineContext context) + { + var input = Input.Evaluate(context); + if (input == null) return null; - var tag = Tag.Evaluate(context); - return string.IsNullOrEmpty(tag) ? input : input.Remove(tag); - } + var tag = Tag.Evaluate(context); + return string.IsNullOrEmpty(tag) ? input : input.Remove(tag); } -} +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonToStringNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonToStringNode.cs index a1ed246..38524c7 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonToStringNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonToStringNode.cs @@ -9,6 +9,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; +[NodeName("To String")] [NodeCategory("Obsidian/Json")] [GenericTypes(typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray))] public class JsonToStringNode : ObjectFunctionNode From f2febf40fca842713c64d5f020d0eddd55696310 Mon Sep 17 00:00:00 2001 From: frozenreflex Date: Sun, 14 Jul 2024 02:53:27 -0500 Subject: [PATCH 4/5] Fix JsonInsertToArrayNode generic types --- ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs | 3 +-- ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs index 6401c9a..866a7f9 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs @@ -12,8 +12,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; [NodeName("Insert To Array")] [NodeCategory("Obsidian/Json")] -[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), - typeof(long), typeof(ulong), typeof(float), typeof(double))] +[GenericTypes(typeof(string), typeof(Uri), typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray))] public class JsonInsertObjectToArrayNode : ObjectFunctionNode { public readonly ObjectInput Array; diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs index e25794f..1409eef 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs @@ -12,7 +12,8 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; [NodeName("Insert To Array")] [NodeCategory("Obsidian/Json")] -[GenericTypes(typeof(string), typeof(Uri), typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray))] +[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), + typeof(long), typeof(ulong), typeof(float), typeof(double))] public class JsonInsertValueToArrayNode : ObjectFunctionNode { public readonly ObjectInput Array; From c3d7cc387e7c7913d28f85c1ae092759a827b821 Mon Sep 17 00:00:00 2001 From: frozenreflex Date: Sun, 14 Jul 2024 02:58:06 -0500 Subject: [PATCH 5/5] Fix invalid instances of ObjectInput in Json nodes --- ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs | 2 +- ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs | 2 +- ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs | 2 +- ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs index caf3b75..49271a6 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs @@ -16,7 +16,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; public class JsonGetObjectFromArrayNode : ObjectFunctionNode where T : class { public readonly ObjectInput Input; - public readonly ObjectInput Index; + public readonly ValueInput Index; public static bool IsValidGenericType => JsonTypeHelper.ValidObjectGetTypes.Contains(typeof(T)); protected override T Compute(FrooxEngineContext context) { diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs index 686f570..5943a40 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs @@ -14,7 +14,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; public class JsonGetValueFromArrayNode : ValueFunctionNode where T : unmanaged { public readonly ObjectInput Input; - public readonly ObjectInput Index; + public readonly ValueInput Index; public static bool IsValidGenericType => JsonTypeHelper.ValidValueTypes.Contains(typeof(T)); protected override T Compute(FrooxEngineContext context) { diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs index 866a7f9..237b8ef 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs @@ -13,7 +13,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; [NodeName("Insert To Array")] [NodeCategory("Obsidian/Json")] [GenericTypes(typeof(string), typeof(Uri), typeof(IJsonToken), typeof(JsonObject), typeof(JsonArray))] -public class JsonInsertObjectToArrayNode : ObjectFunctionNode +public class JsonInsertObjectToArrayNode : ObjectFunctionNode where T : class { public readonly ObjectInput Array; public readonly ObjectInput Object; diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs index 1409eef..35c89ab 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs @@ -14,10 +14,10 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; [NodeCategory("Obsidian/Json")] [GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double))] -public class JsonInsertValueToArrayNode : ObjectFunctionNode +public class JsonInsertValueToArrayNode : ObjectFunctionNode where T : unmanaged { public readonly ObjectInput Array; - public readonly ObjectInput Object; + public readonly ValueInput Object; public readonly ValueInput Index; public static bool IsValidGenericType => JsonTypeHelper.ValidValueTypes.Contains(typeof(T)); protected override JsonArray Compute(FrooxEngineContext context)