From cd414f0ee7e714283e16d9ae538d5d8af8fff050 Mon Sep 17 00:00:00 2001
From: Nytra <14206961+Nytra@users.noreply.github.com>
Date: Sun, 14 Jul 2024 02:07:02 +0100
Subject: [PATCH 1/5] Add external types to AssemblyInfo.cs
---
ProjectObsidian/ProjectObsidian.csproj | 2 +-
ProjectObsidian/Properties/AssemblyInfo.cs | 10 +++++++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/ProjectObsidian/ProjectObsidian.csproj b/ProjectObsidian/ProjectObsidian.csproj
index 339892e..f7b1f11 100644
--- a/ProjectObsidian/ProjectObsidian.csproj
+++ b/ProjectObsidian/ProjectObsidian.csproj
@@ -4,7 +4,7 @@
Project-Obsidian
net48
11
- Copyright © 2023
+ Copyright © 2024
Project-Obsidian
diff --git a/ProjectObsidian/Properties/AssemblyInfo.cs b/ProjectObsidian/Properties/AssemblyInfo.cs
index 251da04..3734633 100644
--- a/ProjectObsidian/Properties/AssemblyInfo.cs
+++ b/ProjectObsidian/Properties/AssemblyInfo.cs
@@ -9,7 +9,9 @@
//------------------------------------------------------------------------------
using System;
+using System.Net;
using System.Reflection;
+using Newtonsoft.Json.Linq;
using Elements.Core;
@@ -25,4 +27,10 @@
// Generated by the MSBuild WriteCodeFragment class.
//Mark as DataModelAssembly for the Plugin loading system to load this assembly
-[assembly: DataModelAssembly(DataModelAssemblyType.Core)]
\ No newline at end of file
+[assembly: DataModelAssembly(DataModelAssemblyType.Core)]
+
+[assembly: ExternalDataModelType(typeof(Valve.VR.Imu_OffScaleFlags))]
+[assembly: ExternalDataModelType(typeof(HttpStatusCode))]
+[assembly: ExternalDataModelType(typeof(JObject))]
+[assembly: ExternalDataModelType(typeof(JToken))]
+[assembly: ExternalDataModelType(typeof(JArray))]
\ No newline at end of file
From 974cf847f00f7273a9cd17b77041a0705071adf5 Mon Sep 17 00:00:00 2001
From: Nytra <14206961+Nytra@users.noreply.github.com>
Date: Sun, 14 Jul 2024 02:14:09 +0100
Subject: [PATCH 2/5] Mark RequestType as Data Model Type
---
ProjectObsidian/ProtoFlux/Networking/AsyncHttpRequestNode.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/ProjectObsidian/ProtoFlux/Networking/AsyncHttpRequestNode.cs b/ProjectObsidian/ProtoFlux/Networking/AsyncHttpRequestNode.cs
index 6f1555a..b0ec752 100644
--- a/ProjectObsidian/ProtoFlux/Networking/AsyncHttpRequestNode.cs
+++ b/ProjectObsidian/ProtoFlux/Networking/AsyncHttpRequestNode.cs
@@ -13,6 +13,7 @@
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Network
{
+ [DataModelType]
public enum RequestType
{
GET,
From a04daad307e5797fab2867af42c0ed521a5438de Mon Sep 17 00:00:00 2001
From: Nytra <14206961+Nytra@users.noreply.github.com>
Date: Sun, 14 Jul 2024 02:21:34 +0100
Subject: [PATCH 3/5] Mark some enums as data model types
---
.../Components/Transform/Drivers/MultiValueArithmeticDriver.cs | 1 +
ProjectObsidian/ProtoFlux/Strings/HMAC.cs | 1 +
2 files changed, 2 insertions(+)
diff --git a/ProjectObsidian/Components/Transform/Drivers/MultiValueArithmeticDriver.cs b/ProjectObsidian/Components/Transform/Drivers/MultiValueArithmeticDriver.cs
index ab74f9f..09d4fc0 100644
--- a/ProjectObsidian/Components/Transform/Drivers/MultiValueArithmeticDriver.cs
+++ b/ProjectObsidian/Components/Transform/Drivers/MultiValueArithmeticDriver.cs
@@ -4,6 +4,7 @@
namespace Obsidian;
+[DataModelType]
public enum ArithmeticMode
{
Addition,
diff --git a/ProjectObsidian/ProtoFlux/Strings/HMAC.cs b/ProjectObsidian/ProtoFlux/Strings/HMAC.cs
index 55f1200..49e6b79 100644
--- a/ProjectObsidian/ProtoFlux/Strings/HMAC.cs
+++ b/ProjectObsidian/ProtoFlux/Strings/HMAC.cs
@@ -9,6 +9,7 @@
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Strings
{
+ [DataModelType]
public enum HashFunction
{
MD5,
From cb6380651e90576a8c72c1401b760960e599b58d Mon Sep 17 00:00:00 2001
From: Nytra <14206961+Nytra@users.noreply.github.com>
Date: Sun, 14 Jul 2024 05:32:09 +0100
Subject: [PATCH 4/5] Improve binding generator to handle constraint clauses
and generic types attribute, fix JSON nodes
---
.../BindingGenerator.cs | 10 ++++-
...dToObject.cs => JsonAddObjectToJObject.cs} | 5 +--
.../ProtoFlux/JSON/JsonAddValueToJObject.cs | 35 ++++++++++++++++
...ToArray.cs => JsonAppendObjectToJArray.cs} | 5 +--
.../ProtoFlux/JSON/JsonAppendValueToJArray.cs | 36 ++++++++++++++++
...drenNode.cs => JsonCountJArrayChildren.cs} | 2 +-
...renNode.cs => JsonCountJObjectChildren.cs} | 2 +-
ProjectObsidian/ProtoFlux/JSON/JsonEmpty.cs | 33 ---------------
.../ProtoFlux/JSON/JsonEmptyJArray.cs | 16 ++++++++
.../ProtoFlux/JSON/JsonEmptyJObject.cs | 16 ++++++++
.../ProtoFlux/JSON/JsonGetObjectFromJArray.cs | 36 ++++++++++++++++
.../JSON/JsonGetObjectFromJObject.cs | 36 ++++++++++++++++
...ArrayNode.cs => JsonGetValueFromJArray.cs} | 8 ++--
...omObject.cs => JsonGetValueFromJObject.cs} | 5 +--
...rayNode.cs => JsonInsertObjectToJArray.cs} | 7 ++--
.../ProtoFlux/JSON/JsonInsertValueToJArray.cs | 41 +++++++++++++++++++
.../ProtoFlux/JSON/JsonNullValue.cs | 16 ++++++++
...tringArray.cs => JsonParseStringJArray.cs} | 2 +-
...tringNode.cs => JsonParseStringJObject.cs} | 3 +-
.../ProtoFlux/JSON/JsonQuickGetObject.cs | 5 +--
.../ProtoFlux/JSON/JsonQuickGetValue.cs | 37 +++++++++++++++++
...omArrayNode.cs => JsonRemoveFromJArray.cs} | 5 +--
...ObjectNode.cs => JsonRemoveFromJObject.cs} | 3 +-
.../{JsonToStringNode.cs => JsonToString.cs} | 2 +-
24 files changed, 300 insertions(+), 66 deletions(-)
rename ProjectObsidian/ProtoFlux/JSON/{JsonAddToObject.cs => JsonAddObjectToJObject.cs} (79%)
create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonAddValueToJObject.cs
rename ProjectObsidian/ProtoFlux/JSON/{JsonAppendToArray.cs => JsonAppendObjectToJArray.cs} (75%)
create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToJArray.cs
rename ProjectObsidian/ProtoFlux/JSON/{JsonCountArrayChildrenNode.cs => JsonCountJArrayChildren.cs} (83%)
rename ProjectObsidian/ProtoFlux/JSON/{JsonCountObjectChildrenNode.cs => JsonCountJObjectChildren.cs} (83%)
delete mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonEmpty.cs
create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonEmptyJArray.cs
create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonEmptyJObject.cs
create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromJArray.cs
create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromJObject.cs
rename ProjectObsidian/ProtoFlux/JSON/{JsonGetFromArrayNode.cs => JsonGetValueFromJArray.cs} (75%)
rename ProjectObsidian/ProtoFlux/JSON/{JsonGetFromObject.cs => JsonGetValueFromJObject.cs} (79%)
rename ProjectObsidian/ProtoFlux/JSON/{JsonInsertToArrayNode.cs => JsonInsertObjectToJArray.cs} (74%)
create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToJArray.cs
create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonNullValue.cs
rename ProjectObsidian/ProtoFlux/JSON/{JsonParseStringArray.cs => JsonParseStringJArray.cs} (89%)
rename ProjectObsidian/ProtoFlux/JSON/{JsonParseStringNode.cs => JsonParseStringJObject.cs} (89%)
create mode 100644 ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValue.cs
rename ProjectObsidian/ProtoFlux/JSON/{JsonRemoveFromArrayNode.cs => JsonRemoveFromJArray.cs} (86%)
rename ProjectObsidian/ProtoFlux/JSON/{JsonRemoveFromObjectNode.cs => JsonRemoveFromJObject.cs} (88%)
rename ProjectObsidian/ProtoFlux/JSON/{JsonToStringNode.cs => JsonToString.cs} (86%)
diff --git a/ProjectObsidian.SourceGenerators/BindingGenerator.cs b/ProjectObsidian.SourceGenerators/BindingGenerator.cs
index 6c591f4..9f43ced 100644
--- a/ProjectObsidian.SourceGenerators/BindingGenerator.cs
+++ b/ProjectObsidian.SourceGenerators/BindingGenerator.cs
@@ -146,8 +146,9 @@ public string Result
namespace {BindingPrefix}{_currentNameSpace};
+{_genericTypesAttribute}
[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} {_constraintClauses}
{{
{Declarations}
{_nodeNameOverride}
@@ -181,6 +182,8 @@ public override N Instantiate()
private string _match;
private string _category;
private string _nodeNameOverride = "";
+ private string _constraintClauses;
+ private string _genericTypesAttribute;
private bool TypedFieldDetection(string type, string name, string targetTypeName, string declarationFormat, OrderedCount counter)
{
@@ -285,6 +288,9 @@ public override void VisitClassDeclaration(ClassDeclarationSyntax node)
_baseType = baseTypeName;
+ // Add the generic parameter constraints
+ _constraintClauses = string.Join(",", node.ConstraintClauses);
+
if (!node.AttributeLists.Any())
{
base.VisitClassDeclaration(node);
@@ -294,6 +300,8 @@ public override void VisitClassDeclaration(ClassDeclarationSyntax node)
var find = node.AttributeLists.SelectMany(i => i.Attributes)
.FirstOrDefault(i => i.Name.ToString() == "NodeCategory");
+ _genericTypesAttribute = node.AttributeLists.FirstOrDefault(attr => attr.Attributes.Any(attr2 => attr2.Name.ToString() == "GenericTypes"))?.ToString();
+
if (find?.ArgumentList is null)
{
base.VisitClassDeclaration(node);
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAddToObject.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAddObjectToJObject.cs
similarity index 79%
rename from ProjectObsidian/ProtoFlux/JSON/JsonAddToObject.cs
rename to ProjectObsidian/ProtoFlux/JSON/JsonAddObjectToJObject.cs
index 1088fd6..31f9f10 100644
--- a/ProjectObsidian/ProtoFlux/JSON/JsonAddToObject.cs
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonAddObjectToJObject.cs
@@ -10,10 +10,9 @@ 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),
+ [GenericTypes(typeof(string), typeof(Uri),
typeof(JToken), typeof(JObject), typeof(JArray))]
- public class JsonAddToObjectNode : ObjectFunctionNode
+ public class JsonAddObjectToJObject : ObjectFunctionNode
{
public readonly ObjectInput Input;
public readonly ObjectInput Tag;
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAddValueToJObject.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAddValueToJObject.cs
new file mode 100644
index 0000000..cbc7f2f
--- /dev/null
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonAddValueToJObject.cs
@@ -0,0 +1,35 @@
+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))]
+ public class JsonAddValueToJObject : ObjectFunctionNode where T : unmanaged
+ {
+ public readonly ObjectInput Input;
+ public readonly ObjectInput Tag;
+ public readonly ValueInput Value;
+
+ protected override JObject Compute(FrooxEngineContext context)
+ {
+ var input = Input.Evaluate(context);
+ if (input == null) return null;
+
+ var tag = Tag.Evaluate(context);
+ var value = Value.Evaluate(context);
+ if (string.IsNullOrEmpty(tag)) return input;
+
+ var in2 = (JObject)input.DeepClone();
+ in2[tag] = new JValue(value);
+ return in2;
+ }
+ }
+}
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAppendToArray.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAppendObjectToJArray.cs
similarity index 75%
rename from ProjectObsidian/ProtoFlux/JSON/JsonAppendToArray.cs
rename to ProjectObsidian/ProtoFlux/JSON/JsonAppendObjectToJArray.cs
index 37c5037..ce8f4d7 100644
--- a/ProjectObsidian/ProtoFlux/JSON/JsonAppendToArray.cs
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonAppendObjectToJArray.cs
@@ -9,10 +9,9 @@
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),
+ [GenericTypes(typeof(string), typeof(Uri), typeof(JToken), typeof(JObject),
typeof(JArray))]
- public class JsonAppendToArrayNode : ObjectFunctionNode
+ public class JsonAppendObjectToJArray : ObjectFunctionNode
{
public readonly ObjectInput Array;
public readonly ObjectInput Object;
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToJArray.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToJArray.cs
new file mode 100644
index 0000000..5197552
--- /dev/null
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToJArray.cs
@@ -0,0 +1,36 @@
+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))]
+ public class JsonAppendValueToJArray : ObjectFunctionNode where T : unmanaged
+ {
+ public readonly ObjectInput Array;
+ public readonly ValueInput Value;
+ protected override JArray Compute(FrooxEngineContext context)
+ {
+ var array = Array.Evaluate(context);
+ var value = Value.Evaluate(context);
+ if (array == null) return null;
+
+ try
+ {
+ var output = (JArray)array.DeepClone();
+ output.Add(new JValue(value));
+ return output;
+ }
+ catch
+ {
+ return null;
+ }
+ }
+ }
+}
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonCountArrayChildrenNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonCountJArrayChildren.cs
similarity index 83%
rename from ProjectObsidian/ProtoFlux/JSON/JsonCountArrayChildrenNode.cs
rename to ProjectObsidian/ProtoFlux/JSON/JsonCountJArrayChildren.cs
index 3517dd2..ac351a2 100644
--- a/ProjectObsidian/ProtoFlux/JSON/JsonCountArrayChildrenNode.cs
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonCountJArrayChildren.cs
@@ -6,7 +6,7 @@
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json
{
[NodeCategory("Obsidian/Json")]
- public class JsonCountArrayChildrenNode : ValueFunctionNode
+ public class JsonCountJArrayChildren : ValueFunctionNode
{
public readonly ObjectInput Input;
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonCountObjectChildrenNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonCountJObjectChildren.cs
similarity index 83%
rename from ProjectObsidian/ProtoFlux/JSON/JsonCountObjectChildrenNode.cs
rename to ProjectObsidian/ProtoFlux/JSON/JsonCountJObjectChildren.cs
index a4086da..f0c16d3 100644
--- a/ProjectObsidian/ProtoFlux/JSON/JsonCountObjectChildrenNode.cs
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonCountJObjectChildren.cs
@@ -6,7 +6,7 @@
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json
{
[NodeCategory("Obsidian/Json")]
- public class JsonCountObjectChildrenNode : ValueFunctionNode
+ public class JsonCountJObjectChildren : ValueFunctionNode
{
public readonly ObjectInput Input;
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/JsonEmptyJArray.cs b/ProjectObsidian/ProtoFlux/JSON/JsonEmptyJArray.cs
new file mode 100644
index 0000000..7b406fe
--- /dev/null
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonEmptyJArray.cs
@@ -0,0 +1,16 @@
+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 JsonEmptyJArray : ObjectFunctionNode
+ {
+ protected override JArray Compute(FrooxEngineContext context)
+ {
+ return new JArray();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonEmptyJObject.cs b/ProjectObsidian/ProtoFlux/JSON/JsonEmptyJObject.cs
new file mode 100644
index 0000000..affdafe
--- /dev/null
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonEmptyJObject.cs
@@ -0,0 +1,16 @@
+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 JsonEmptyJObject : ObjectFunctionNode
+ {
+ protected override JObject Compute(FrooxEngineContext context)
+ {
+ return new JObject();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromJArray.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromJArray.cs
new file mode 100644
index 0000000..cbfbb9f
--- /dev/null
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromJArray.cs
@@ -0,0 +1,36 @@
+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(string), typeof(Uri), typeof(JToken), typeof(JObject),
+ typeof(JArray))]
+ public class JsonGetObjectFromJArray : ObjectFunctionNode
+ {
+ public readonly ObjectInput Input;
+ public readonly ValueInput 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/JsonGetObjectFromJObject.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromJObject.cs
new file mode 100644
index 0000000..1ca9c4e
--- /dev/null
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromJObject.cs
@@ -0,0 +1,36 @@
+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(string), typeof(Uri), typeof(JToken), typeof(JObject),
+ typeof(JArray))]
+ public class JsonGetObjectFromJObject : 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/JsonGetFromArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromJArray.cs
similarity index 75%
rename from ProjectObsidian/ProtoFlux/JSON/JsonGetFromArrayNode.cs
rename to ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromJArray.cs
index 2524b5a..679b005 100644
--- a/ProjectObsidian/ProtoFlux/JSON/JsonGetFromArrayNode.cs
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromJArray.cs
@@ -10,13 +10,11 @@ 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
+ typeof(ulong), typeof(float), typeof(double))]
+ public class JsonGetValueFromJArray : ValueFunctionNode where T : unmanaged
{
public readonly ObjectInput Input;
- public readonly ObjectInput Index;
-
+ public readonly ValueInput Index;
protected override T Compute(FrooxEngineContext context)
{
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetFromObject.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromJObject.cs
similarity index 79%
rename from ProjectObsidian/ProtoFlux/JSON/JsonGetFromObject.cs
rename to ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromJObject.cs
index 64f8da4..4a5769e 100644
--- a/ProjectObsidian/ProtoFlux/JSON/JsonGetFromObject.cs
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromJObject.cs
@@ -10,9 +10,8 @@ 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
+ typeof(ulong), typeof(float), typeof(double))]
+ public class JsonGetValueFromJObject : ValueFunctionNode where T : unmanaged
{
public readonly ObjectInput Input;
public readonly ObjectInput Tag;
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonInsertToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToJArray.cs
similarity index 74%
rename from ProjectObsidian/ProtoFlux/JSON/JsonInsertToArrayNode.cs
rename to ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToJArray.cs
index 044c924..920cc75 100644
--- a/ProjectObsidian/ProtoFlux/JSON/JsonInsertToArrayNode.cs
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToJArray.cs
@@ -9,14 +9,13 @@
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),
+ [GenericTypes(typeof(string), typeof(Uri), typeof(JToken), typeof(JObject),
typeof(JArray))]
- public class JsonInsertToArrayNode : ObjectFunctionNode
+ public class JsonInsertObjectToJArray : ObjectFunctionNode
{
public readonly ObjectInput Array;
public readonly ObjectInput Object;
- public readonly ObjectInput Index;
+ public readonly ValueInput Index;
protected override JArray Compute(FrooxEngineContext context)
{
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToJArray.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToJArray.cs
new file mode 100644
index 0000000..ae2674d
--- /dev/null
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToJArray.cs
@@ -0,0 +1,41 @@
+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))]
+ public class JsonInsertValueToJArray : ObjectFunctionNode where T : unmanaged
+ {
+ public readonly ObjectInput Array;
+ public readonly ValueInput Value;
+ public readonly ValueInput Index;
+
+ protected override JArray Compute(FrooxEngineContext context)
+ {
+ var array = Array.Evaluate(context);
+ var value = Value.Evaluate(context);
+ var index = Index.Evaluate(context);
+ if (array == null || index < 0 || index > array.Count)
+ return null;
+
+ try
+ {
+ var output = (JArray)array.DeepClone();
+ var token = new JValue(value);
+ output.Insert(index, token);
+ return output;
+ }
+ catch
+ {
+ return null;
+ }
+ }
+ }
+}
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonNullValue.cs b/ProjectObsidian/ProtoFlux/JSON/JsonNullValue.cs
new file mode 100644
index 0000000..c595cae
--- /dev/null
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonNullValue.cs
@@ -0,0 +1,16 @@
+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 JsonNullValue : ObjectFunctionNode
+ {
+ protected override JToken Compute(FrooxEngineContext context)
+ {
+ return JValue.CreateNull();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArray.cs b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringJArray.cs
similarity index 89%
rename from ProjectObsidian/ProtoFlux/JSON/JsonParseStringArray.cs
rename to ProjectObsidian/ProtoFlux/JSON/JsonParseStringJArray.cs
index 7d18d4d..dd44310 100644
--- a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringArray.cs
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringJArray.cs
@@ -7,7 +7,7 @@
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json
{
[NodeCategory("Obsidian/Json")]
- public class JsonParseStringArrayNode : ObjectFunctionNode
+ public class JsonParseStringJArray : ObjectFunctionNode
{
public readonly ObjectInput Input;
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringJObject.cs
similarity index 89%
rename from ProjectObsidian/ProtoFlux/JSON/JsonParseStringNode.cs
rename to ProjectObsidian/ProtoFlux/JSON/JsonParseStringJObject.cs
index 1624cd1..b884bb2 100644
--- a/ProjectObsidian/ProtoFlux/JSON/JsonParseStringNode.cs
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonParseStringJObject.cs
@@ -7,10 +7,9 @@
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json
{
[NodeCategory("Obsidian/Json")]
- public class JsonParseStringNode : ObjectFunctionNode
+ public class JsonParseStringJObject : ObjectFunctionNode
{
public readonly ObjectInput Input;
-
protected override JObject Compute(FrooxEngineContext context)
{
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObject.cs b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObject.cs
index b5e491d..cda93af 100644
--- a/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObject.cs
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetObject.cs
@@ -9,10 +9,9 @@
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),
+ [GenericTypes(typeof(string), typeof(Uri), typeof(JToken), typeof(JObject),
typeof(JArray))]
- public class JsonQuickGetFromObjectNode : ObjectFunctionNode
+ public class JsonQuickGetObject : ObjectFunctionNode
{
public readonly ObjectInput Input;
public readonly ObjectInput Tag;
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValue.cs b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValue.cs
new file mode 100644
index 0000000..9f31931
--- /dev/null
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValue.cs
@@ -0,0 +1,37 @@
+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))]
+ public class JsonQuickGetValue : ValueFunctionNode where T : unmanaged
+ {
+ public readonly ObjectInput Input;
+ public readonly ObjectInput Tag;
+ protected override T Compute(FrooxEngineContext context)
+ {
+ string input = Input.Evaluate(context);
+ string tag = Tag.Evaluate(context);
+ if (string.IsNullOrEmpty(input) || string.IsNullOrEmpty(tag))
+ return default;
+
+ try
+ {
+ var inputObject = JObject.Parse(input);
+ return inputObject[tag].Value();
+ }
+ catch
+ {
+ // In case of parsing error or if the tag is not found
+ return default;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromJArray.cs
similarity index 86%
rename from ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromArrayNode.cs
rename to ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromJArray.cs
index 25ea200..a22adf9 100644
--- a/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromArrayNode.cs
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromJArray.cs
@@ -7,11 +7,10 @@
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json
{
[NodeCategory("Obsidian/Json")]
- public class JsonRemoveFromArrayNode : ObjectFunctionNode
+ public class JsonRemoveFromJArray : ObjectFunctionNode
{
public readonly ObjectInput Array;
- public readonly ObjectInput Index;
-
+ public readonly ValueInput Index;
protected override JArray Compute(FrooxEngineContext context)
{
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromJObject.cs
similarity index 88%
rename from ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromObjectNode.cs
rename to ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromJObject.cs
index 7fa503b..f9d081f 100644
--- a/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromObjectNode.cs
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonRemoveFromJObject.cs
@@ -7,11 +7,10 @@
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json
{
[NodeCategory("Obsidian/Json")]
- public class JsonRemoveFromObjectNode : ObjectFunctionNode
+ public class JsonRemoveFromJObject : ObjectFunctionNode
{
public readonly ObjectInput Input;
public readonly ObjectInput Tag;
-
protected override JObject Compute(FrooxEngineContext context)
{
diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonToStringNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonToString.cs
similarity index 86%
rename from ProjectObsidian/ProtoFlux/JSON/JsonToStringNode.cs
rename to ProjectObsidian/ProtoFlux/JSON/JsonToString.cs
index 6d2ddd5..0f33177 100644
--- a/ProjectObsidian/ProtoFlux/JSON/JsonToStringNode.cs
+++ b/ProjectObsidian/ProtoFlux/JSON/JsonToString.cs
@@ -9,7 +9,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json;
[NodeCategory("Obsidian/Json")]
[GenericTypes(typeof(JToken), typeof(JObject), typeof(JArray))]
-public class JsonToStringNode : ObjectFunctionNode
+public class JsonToString : ObjectFunctionNode
{
public readonly ObjectInput Input;
From aaf64d2556e638305002ad1d21f8a27592114479 Mon Sep 17 00:00:00 2001
From: Nytra <14206961+Nytra@users.noreply.github.com>
Date: Sun, 14 Jul 2024 05:42:41 +0100
Subject: [PATCH 5/5] Improve var names
---
ProjectObsidian.SourceGenerators/BindingGenerator.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ProjectObsidian.SourceGenerators/BindingGenerator.cs b/ProjectObsidian.SourceGenerators/BindingGenerator.cs
index 9f43ced..f1a9516 100644
--- a/ProjectObsidian.SourceGenerators/BindingGenerator.cs
+++ b/ProjectObsidian.SourceGenerators/BindingGenerator.cs
@@ -300,7 +300,7 @@ public override void VisitClassDeclaration(ClassDeclarationSyntax node)
var find = node.AttributeLists.SelectMany(i => i.Attributes)
.FirstOrDefault(i => i.Name.ToString() == "NodeCategory");
- _genericTypesAttribute = node.AttributeLists.FirstOrDefault(attr => attr.Attributes.Any(attr2 => attr2.Name.ToString() == "GenericTypes"))?.ToString();
+ _genericTypesAttribute = node.AttributeLists.FirstOrDefault(attrList => attrList.Attributes.Any(attr => attr.Name.ToString() == "GenericTypes"))?.ToString();
if (find?.ArgumentList is null)
{