Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JSON nodes, improve binding generator, add external types to AssemblyInfo.cs and mark enums as data model types #44

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ProjectObsidian.SourceGenerators/BindingGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -181,6 +182,8 @@ public override N Instantiate<N>()
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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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(attrList => attrList.Attributes.Any(attr => attr.Name.ToString() == "GenericTypes"))?.ToString();

if (find?.ArgumentList is null)
{
base.VisitClassDeclaration(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Obsidian;

[DataModelType]
public enum ArithmeticMode
{
Addition,
Expand Down
2 changes: 1 addition & 1 deletion ProjectObsidian/ProjectObsidian.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyName>Project-Obsidian</AssemblyName>
<TargetFramework>net48</TargetFramework>
<LangVersion>11</LangVersion>
<Copyright>Copyright © 2023</Copyright>
<Copyright>Copyright © 2024</Copyright>
<Product>Project-Obsidian</Product>
</PropertyGroup>
<PropertyGroup>
Expand Down
10 changes: 9 additions & 1 deletion ProjectObsidian/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
//------------------------------------------------------------------------------

using System;
using System.Net;
using System.Reflection;
using Newtonsoft.Json.Linq;

using Elements.Core;

Expand All @@ -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)]
[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))]
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> : ObjectFunctionNode<FrooxEngineContext, JObject>
public class JsonAddObjectToJObject<T> : ObjectFunctionNode<FrooxEngineContext, JObject>
{
public readonly ObjectInput<JObject> Input;
public readonly ObjectInput<string> Tag;
Expand Down
35 changes: 35 additions & 0 deletions ProjectObsidian/ProtoFlux/JSON/JsonAddValueToJObject.cs
Original file line number Diff line number Diff line change
@@ -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<T> : ObjectFunctionNode<FrooxEngineContext, JObject> where T : unmanaged
{
public readonly ObjectInput<JObject> Input;
public readonly ObjectInput<string> Tag;
public readonly ValueInput<T> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> : ObjectFunctionNode<FrooxEngineContext, JArray>
public class JsonAppendObjectToJArray<T> : ObjectFunctionNode<FrooxEngineContext, JArray>
{
public readonly ObjectInput<JArray> Array;
public readonly ObjectInput<T> Object;
Expand Down
36 changes: 36 additions & 0 deletions ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToJArray.cs
Original file line number Diff line number Diff line change
@@ -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<T> : ObjectFunctionNode<FrooxEngineContext, JArray> where T : unmanaged
{
public readonly ObjectInput<JArray> Array;
public readonly ValueInput<T> 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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json
{
[NodeCategory("Obsidian/Json")]
public class JsonCountArrayChildrenNode : ValueFunctionNode<FrooxEngineContext, int>
public class JsonCountJArrayChildren : ValueFunctionNode<FrooxEngineContext, int>
{
public readonly ObjectInput<JArray> Input;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json
{
[NodeCategory("Obsidian/Json")]
public class JsonCountObjectChildrenNode : ValueFunctionNode<FrooxEngineContext, int>
public class JsonCountJObjectChildren : ValueFunctionNode<FrooxEngineContext, int>
{
public readonly ObjectInput<JObject> Input;

Expand Down
33 changes: 0 additions & 33 deletions ProjectObsidian/ProtoFlux/JSON/JsonEmpty.cs

This file was deleted.

16 changes: 16 additions & 0 deletions ProjectObsidian/ProtoFlux/JSON/JsonEmptyJArray.cs
Original file line number Diff line number Diff line change
@@ -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<FrooxEngineContext, JArray>
{
protected override JArray Compute(FrooxEngineContext context)
{
return new JArray();
}
}
}
16 changes: 16 additions & 0 deletions ProjectObsidian/ProtoFlux/JSON/JsonEmptyJObject.cs
Original file line number Diff line number Diff line change
@@ -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<FrooxEngineContext, JObject>
{
protected override JObject Compute(FrooxEngineContext context)
{
return new JObject();
}
}
}
36 changes: 36 additions & 0 deletions ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromJArray.cs
Original file line number Diff line number Diff line change
@@ -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<T> : ObjectFunctionNode<FrooxEngineContext, T>
{
public readonly ObjectInput<JArray> Input;
public readonly ValueInput<int> 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<T>();
}
catch
{
return default;
}
}
}
}
36 changes: 36 additions & 0 deletions ProjectObsidian/ProtoFlux/JSON/JsonGetObjectFromJObject.cs
Original file line number Diff line number Diff line change
@@ -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<T> : ObjectFunctionNode<FrooxEngineContext, T>
{
public readonly ObjectInput<JObject> Input;
public readonly ObjectInput<string> 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<T>();
}
catch
{
return default;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> : ObjectFunctionNode<FrooxEngineContext, T>
typeof(ulong), typeof(float), typeof(double))]
public class JsonGetValueFromJArray<T> : ValueFunctionNode<FrooxEngineContext, T> where T : unmanaged
{
public readonly ObjectInput<JArray> Input;
public readonly ObjectInput<int> Index;

public readonly ValueInput<int> Index;

protected override T Compute(FrooxEngineContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> : ObjectFunctionNode<FrooxEngineContext, T>
typeof(ulong), typeof(float), typeof(double))]
public class JsonGetValueFromJObject<T> : ValueFunctionNode<FrooxEngineContext, T> where T : unmanaged
{
public readonly ObjectInput<JObject> Input;
public readonly ObjectInput<string> Tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> : ObjectFunctionNode<FrooxEngineContext, JArray>
public class JsonInsertObjectToJArray<T> : ObjectFunctionNode<FrooxEngineContext, JArray>
{
public readonly ObjectInput<JArray> Array;
public readonly ObjectInput<T> Object;
public readonly ObjectInput<int> Index;
public readonly ValueInput<int> Index;

protected override JArray Compute(FrooxEngineContext context)
{
Expand Down
Loading