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

Add Write to log Node #9

Merged
merged 3 commits into from
Jan 21, 2024
Merged
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
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;
}
}
}