Skip to content

Commit

Permalink
Fix Json value inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Frozenreflex committed Jul 14, 2024
1 parent a39f384 commit a33a54f
Show file tree
Hide file tree
Showing 23 changed files with 227 additions and 113 deletions.
8 changes: 6 additions & 2 deletions ProjectObsidian/Elements/JsonTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
34 changes: 34 additions & 0 deletions ProjectObsidian/ProtoFlux/JSON/JsonAddObjectToObjectNode.cs
Original file line number Diff line number Diff line change
@@ -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<T> : ObjectFunctionNode<FrooxEngineContext, JsonObject> where T : class
{
public readonly ObjectInput<JsonObject> Input;
public readonly ObjectInput<string> Tag;
public readonly ObjectInput<T> 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);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using Newtonsoft.Json.Linq;
using ProtoFlux.Core;
Expand All @@ -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<T> : ObjectFunctionNode<FrooxEngineContext, JsonObject>
typeof(long), typeof(ulong), typeof(float), typeof(double))]
public class JsonAddValueToObjectNode<T> : ObjectFunctionNode<FrooxEngineContext, JsonObject> where T : unmanaged
{
public readonly ObjectInput<JsonObject> Input;
public readonly ObjectInput<string> Tag;
public readonly ObjectInput<T> Object;
public readonly ValueInput<T> 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)
{
Expand All @@ -33,4 +32,4 @@ protected override JsonObject Compute(FrooxEngineContext context)

return string.IsNullOrEmpty(tag) ? input : input.Add(tag, obj);
}
}
}
28 changes: 28 additions & 0 deletions ProjectObsidian/ProtoFlux/JSON/JsonAppendObjectToArrayNode.cs
Original file line number Diff line number Diff line change
@@ -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<T> : ObjectFunctionNode<FrooxEngineContext, JsonArray> where T : class
{
public readonly ObjectInput<JsonArray> Array;
public readonly ObjectInput<T> 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);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using Newtonsoft.Json.Linq;
using ProtoFlux.Core;
Expand All @@ -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<T> : ObjectFunctionNode<FrooxEngineContext, JsonArray>
typeof(ulong), typeof(float), typeof(double))]
public class JsonAppendValueToArrayNode<T> : ObjectFunctionNode<FrooxEngineContext, JsonArray> where T : unmanaged
{
public readonly ObjectInput<JsonArray> Array;
public readonly ObjectInput<T> Object;
public static bool IsValidGenericType => JsonTypeHelper.AllValidTypes.Contains(typeof(T));
public readonly ValueInput<T> Object;

public static bool IsValidGenericType => JsonTypeHelper.ValidValueTypes.Contains(typeof(T));
protected override JsonArray Compute(FrooxEngineContext context)
{
var array = Array.Evaluate(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json
{
[NodeName("Count")]
[NodeCategory("Obsidian/Json")]
public class JsonCountArrayChildrenNode : ValueFunctionNode<FrooxEngineContext, int>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json
{
[NodeName("Count")]
[NodeCategory("Obsidian/Json")]
public class JsonCountObjectChildrenNode : ValueFunctionNode<FrooxEngineContext, int>
{
Expand Down
14 changes: 14 additions & 0 deletions ProjectObsidian/ProtoFlux/JSON/JsonEmptyArrayNode.cs
Original file line number Diff line number Diff line change
@@ -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<FrooxEngineContext, JsonArray>
{
protected override JsonArray Compute(FrooxEngineContext context) => new(new JArray());
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json;

[NodeName("Empty JsonObject")]
[NodeCategory("Obsidian/Json")]
public class JsonEmptyObjectNode : ObjectFunctionNode<FrooxEngineContext, JsonObject>
{
protected override JsonObject Compute(FrooxEngineContext context) => new(new JObject());
}

[NodeCategory("Obsidian/Json")]
public class JsonEmptyArrayNode : ObjectFunctionNode<FrooxEngineContext, JsonArray>
{
protected override JsonArray Compute(FrooxEngineContext context) => new(new JArray());
}
3 changes: 2 additions & 1 deletion ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromArrayNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> : ObjectFunctionNode<FrooxEngineContext, T> where T : class
{
public readonly ObjectInput<JsonArray> Input;
public readonly ObjectInput<int> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> : ObjectFunctionNode<FrooxEngineContext, T> where T : class
{
public readonly ObjectInput<JsonObject> Input;
public readonly ObjectInput<string> 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);
Expand Down
3 changes: 2 additions & 1 deletion ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

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<T> : ValueFunctionNode<FrooxEngineContext, T> where T : unmanaged
{
public readonly ObjectInput<JsonArray> Input;
public readonly ObjectInput<int> 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);
Expand Down
3 changes: 2 additions & 1 deletion ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

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<T> : ValueFunctionNode<FrooxEngineContext, T> where T : unmanaged
{
public readonly ObjectInput<JsonObject> Input;
public readonly ObjectInput<string> 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);
Expand Down
33 changes: 33 additions & 0 deletions ProjectObsidian/ProtoFlux/JSON/JsonInsertObjectToArrayNode.cs
Original file line number Diff line number Diff line change
@@ -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),

This comment has been minimized.

Copy link
@Nytra

Nytra Jul 14, 2024

Contributor

Wrong generic types?

This comment has been minimized.

Copy link
@Frozenreflex

Frozenreflex Jul 14, 2024

Author Collaborator

im very tired

typeof(long), typeof(ulong), typeof(float), typeof(double))]
public class JsonInsertObjectToArrayNode<T> : ObjectFunctionNode<FrooxEngineContext, JsonArray>
{
public readonly ObjectInput<JsonArray> Array;
public readonly ObjectInput<T> Object;
public readonly ObjectInput<int> 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);
}
}
34 changes: 0 additions & 34 deletions ProjectObsidian/ProtoFlux/JSON/JsonInsertToArrayNode.cs

This file was deleted.

32 changes: 32 additions & 0 deletions ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs
Original file line number Diff line number Diff line change
@@ -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<T> : ObjectFunctionNode<FrooxEngineContext, JsonArray>

This comment has been minimized.

Copy link
@Nytra

Nytra Jul 14, 2024

Contributor

Name doesn't match the types

{
public readonly ObjectInput<JsonArray> Array;
public readonly ObjectInput<T> Object;
public readonly ValueInput<int> 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);
}
}
22 changes: 11 additions & 11 deletions ProjectObsidian/ProtoFlux/JSON/JsonParseStringArrayNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FrooxEngineContext, JsonArray>
{
[NodeCategory("Obsidian/Json")]
public class JsonParseStringArrayNode : ObjectFunctionNode<FrooxEngineContext, JsonArray>
{
public readonly ObjectInput<string> Input;
public readonly ObjectInput<string> 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);
}
}
}
Loading

0 comments on commit a33a54f

Please sign in to comment.