Skip to content

Commit

Permalink
Create JsonToStringBinding.cs
Browse files Browse the repository at this point in the history
Forgot
  • Loading branch information
Xlinka committed Jan 21, 2024
1 parent ef5fd21 commit 52b552e
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Bindings/JSON/JsonToStringBinding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using Elements.Core;
using FrooxEngine;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;
using ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json;
using Newtonsoft.Json.Linq;
using FrooxEngine.ProtoFlux;


[Category(new string[] { "ProtoFlux/Runtimes/Execution/Nodes/Obsidian/Json" })]
public class JsonToStringBinding<T> : FrooxEngine.ProtoFlux.Runtimes.Execution.ObjectFunctionNode<ExecutionContext, string> where T : JToken
{
public readonly SyncRef<INodeObjectOutput<T>> Input;

public override Type NodeType => typeof(JsonToStringNode<T>);

public JsonToStringNode<T> TypedNodeInstance { get; private set; }

public override INode NodeInstance => TypedNodeInstance;

public override int NodeInputCount => base.NodeInputCount + 1;

public override N Instantiate<N>()
{
if (TypedNodeInstance != null)
{
throw new InvalidOperationException("Node has already been instantiated");
}
JsonToStringNode<T> jsonToStringInstance = (TypedNodeInstance = new JsonToStringNode<T>());
return jsonToStringInstance as N;
}

protected override void AssociateInstanceInternal(INode node)
{
if (node is JsonToStringNode<T> typedNodeInstance)
{
TypedNodeInstance = typedNodeInstance;
return;
}
throw new ArgumentException("Node instance is not of type " + typeof(JsonToStringNode<T>));
}

public override void ClearInstance()
{
TypedNodeInstance = null;
}

protected override ISyncRef GetInputInternal(ref int index)
{
ISyncRef inputInternal = base.GetInputInternal(ref index);
if (inputInternal != null)
{
return inputInternal;
}
if (index == 0)
{
return Input;
}
index -= 1;
return null;
}
}

0 comments on commit 52b552e

Please sign in to comment.