diff --git a/ProjectObsidian.SourceGenerators/BindingGenerator.cs b/ProjectObsidian.SourceGenerators/BindingGenerator.cs index 6c591f4..4bfc162 100644 --- a/ProjectObsidian.SourceGenerators/BindingGenerator.cs +++ b/ProjectObsidian.SourceGenerators/BindingGenerator.cs @@ -147,10 +147,12 @@ 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 +183,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 +242,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 +289,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..158841d --- /dev/null +++ b/ProjectObsidian/Elements/JsonTypes.cs @@ -0,0 +1,259 @@ +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[] 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[] 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] +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/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/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/JsonAddValueToObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAddValueToObjectNode.cs new file mode 100644 index 0000000..ddea561 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonAddValueToObjectNode.cs @@ -0,0 +1,35 @@ +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))] +public class JsonAddValueToObjectNode : ObjectFunctionNode where T : unmanaged +{ + public readonly ObjectInput Input; + public readonly ObjectInput Tag; + public readonly ValueInput Object; + + public static bool IsValidGenericType => JsonTypeHelper.ValidValueTypes.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); + } +} 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/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/JsonAppendValueToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToArrayNode.cs new file mode 100644 index 0000000..c4b499c --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToArrayNode.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; + +[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))] +public class JsonAppendValueToArrayNode : ObjectFunctionNode where T : unmanaged +{ + public readonly ObjectInput Array; + public readonly ValueInput Object; + + 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); + 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..8ca21a0 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonCountArrayChildrenNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonCountArrayChildrenNode.cs @@ -1,15 +1,18 @@ -using FrooxEngine.ProtoFlux; +using System.Linq; +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("Count")] [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..33b374e 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonCountObjectChildrenNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonCountObjectChildrenNode.cs @@ -1,14 +1,16 @@ 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("Count")] [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 deleted file mode 100644 index fc712e5..0000000 --- a/ProjectObsidian/ProtoFlux/JSON/JsonEmpty.cs +++ /dev/null @@ -1,33 +0,0 @@ -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 JsonEmptyObjectNode : ObjectFunctionNode - { - protected override JObject Compute(FrooxEngineContext context) - { - return 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(); - } - } -} \ No newline at end of file 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/JsonEmptyObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonEmptyObjectNode.cs new file mode 100644 index 0000000..15182d1 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonEmptyObjectNode.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 JsonObject")] +[NodeCategory("Obsidian/Json")] +public class JsonEmptyObjectNode : ObjectFunctionNode +{ + protected override JsonObject Compute(FrooxEngineContext context) => new(new JObject()); +} \ 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..49271a6 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.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; + +[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 ValueInput Index; + public static bool IsValidGenericType => JsonTypeHelper.ValidObjectGetTypes.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..f3b6f79 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromObjectNode.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; + +[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.ValidObjectGetTypes.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..5943a40 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs @@ -0,0 +1,28 @@ +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; + +[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))] +public class JsonGetValueFromArrayNode : ValueFunctionNode where T : unmanaged +{ + public readonly ObjectInput Input; + public readonly ValueInput Index; + public static bool IsValidGenericType => JsonTypeHelper.ValidValueTypes.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..4d03085 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.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; + +[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))] +public class JsonGetValueFromObjectNode : ValueFunctionNode where T : unmanaged +{ + public readonly ObjectInput Input; + public readonly ObjectInput Tag; + public static bool IsValidGenericType => JsonTypeHelper.ValidValueTypes.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/JsonInsertObjectToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs new file mode 100644 index 0000000..237b8ef --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.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 JsonInsertObjectToArrayNode : ObjectFunctionNode where T : class +{ + 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 044c924..0000000 --- a/ProjectObsidian/ProtoFlux/JSON/JsonInsertToArrayNode.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 -{ - [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 - { - public readonly ObjectInput Array; - public readonly ObjectInput Object; - public readonly ObjectInput Index; - - protected override JArray 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) - 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; - } - } - } -} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs new file mode 100644 index 0000000..35c89ab --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.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 JsonInsertValueToArrayNode : ObjectFunctionNode where T : unmanaged +{ + public readonly ObjectInput Array; + public readonly ValueInput 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/JsonParseStringArray.cs b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArray.cs deleted file mode 100644 index 7d18d4d..0000000 --- a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArray.cs +++ /dev/null @@ -1,32 +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 JsonParseStringArrayNode : ObjectFunctionNode - { - public readonly ObjectInput Input; - - protected override JArray 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; - } - } - } -} diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArrayNode.cs new file mode 100644 index 0000000..f8c8020 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArrayNode.cs @@ -0,0 +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; + +[NodeName("JsonArray From String")] +[NodeCategory("Obsidian/Json")] +public class JsonParseStringArrayNode : ObjectFunctionNode +{ + public readonly ObjectInput 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/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..07732e7 --- /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; + +[NodeName("JsonObject From String")] +[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); + } +} \ No newline at end of file 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..09d5009 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObjectFromObjectNode.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; + +[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.ValidObjectGetTypes.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..bba5e0d --- /dev/null +++ b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValueFromObjectNode.cs @@ -0,0 +1,31 @@ +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("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))] +public class JsonQuickGetValueFromObjectNode : ValueFunctionNode where T : unmanaged +{ + public readonly ObjectInput Input; + public readonly ObjectInput Tag; + public static bool IsValidGenericType => JsonTypeHelper.ValidValueTypes.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..870d0f9 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 +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 JArray 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; - 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); } -} +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromObjectNode.cs index 7fa503b..705015f 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 +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 JObject Compute(FrooxEngineContext context) - { - var input = Input.Evaluate(context); - if (input == null) return null; - - var tag = Tag.Evaluate(context); - if (string.IsNullOrEmpty(tag)) return input; + protected override JsonObject Compute(FrooxEngineContext context) + { + var input = Input.Evaluate(context); + if (input == null) return null; - var output = (JObject)input.DeepClone(); - output.Remove(tag); - return output; - } + 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 6d2ddd5..38524c7 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonToStringNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonToStringNode.cs @@ -1,18 +1,21 @@ 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; +[NodeName("To String")] [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); } }