-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Xlinka/Testing
Add Write to log Node
- Loading branch information
Showing
3 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |