Skip to content

Commit

Permalink
Merge pull request #9 from Xlinka/Testing
Browse files Browse the repository at this point in the history
Add Write to log Node
  • Loading branch information
Xlinka authored Jan 21, 2024
2 parents b309b54 + 861a7b8 commit db35af0
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 3 deletions.
3 changes: 0 additions & 3 deletions ProjectObsidian.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
<Reference Include="Elements.Assets">
<HintPath>$(ResonitePath)Resonite_Data/Managed/Elements.Assets.dll</HintPath>
</Reference>
<Reference Include="SteamVR">
<HintPath>$(ResonitePath)/Managed/SteamVR.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
96 changes: 96 additions & 0 deletions ProtoFlux/Bindings/Utility/writetolog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System;
using FrooxEngine;
using FrooxEngine.ProtoFlux;
using FrooxEngine.ProtoFlux.Runtimes.Execution;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Utility;


[Category(new string[] { "ProtoFlux/Runtimes/Execution/Nodes/Obsidian/Utility" })]
public class WriteToLogBinding : AsyncActionNode<FrooxEngineContext>
{
public readonly SyncRef<INodeObjectOutput<string>> Value;
public readonly SyncRef<INodeValueOutput<LogSeverity>> Severity;
public readonly SyncRef<INodeObjectOutput<string>> Tag;
public readonly SyncRef<INodeObjectOutput<User>> HandlingUser;

public readonly SyncRef<INodeOperation> OnWriteStart;
public readonly SyncRef<INodeOperation> OnWriteComplete;

public override Type NodeType => typeof(WriteToLogNode);

public WriteToLogNode TypedNodeInstance { get; private set; }

public override INode NodeInstance => TypedNodeInstance;

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

public override int NodeImpulseCount => base.NodeImpulseCount + 2;

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

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

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

protected override ISyncRef GetInputInternal(ref int index)
{
ISyncRef inputInternal = base.GetInputInternal(ref index);
if (inputInternal != null)
{
return inputInternal;
}
switch (index)
{
case 0:
return Value;
case 1:
return Severity;
case 2:
return Tag;
case 3:
return HandlingUser;
default:
index -= 4;
return null;
}
}

protected override ISyncRef GetImpulseInternal(ref int index)
{
ISyncRef impulseInternal = base.GetImpulseInternal(ref index);
if (impulseInternal != null)
{
return impulseInternal;
}
switch (index)
{
case 0:
return OnWriteStart;
case 1:
return OnWriteComplete;
default:
index -= 2;
return null;
}
}
}
51 changes: 51 additions & 0 deletions ProtoFlux/Utility/WriteToLogNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Elements.Core;
using FrooxEngine;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;
using System.Threading.Tasks;
using FrooxEngine.ProtoFlux;

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Utility
{
public enum LogSeverity
{
Log,
Warning,
Error
}

[NodeCategory("Obsidian/Utility/WriteToLog")]
public class WriteToLogNode : AsyncActionNode<FrooxEngineContext>
{
public ObjectInput<string> Value;
public ValueInput<LogSeverity> Severity;
public ObjectInput<string> Tag;
public ObjectInput<User> HandlingUser;

public AsyncCall OnWriteStart;
public Continuation OnWriteComplete;

protected override async Task<IOperation> RunAsync(FrooxEngineContext context)
{
User user = HandlingUser.Evaluate(context, context.LocalUser);
if (user != null)
{
await OnWriteStart.ExecuteAsync(context);
switch (Severity.Evaluate(context))
{
case LogSeverity.Log:
UniLog.Log(Tag.Evaluate(context) + Value.Evaluate(context)?.ToString());
break;
case LogSeverity.Warning:
UniLog.Warning(Tag.Evaluate(context) + Value.Evaluate(context)?.ToString());
break;
case LogSeverity.Error:
UniLog.Error(Tag.Evaluate(context) + Value.Evaluate(context)?.ToString());
break;
}
return OnWriteComplete.Target;
}
return null;
}
}
}

0 comments on commit db35af0

Please sign in to comment.