From 95373e3b647b153b4e7a9ee4ac169d9a58dab43f Mon Sep 17 00:00:00 2001 From: xLinka Date: Tue, 16 Jan 2024 13:57:36 +0000 Subject: [PATCH 1/3] Create WriteToLog Write to log node being ported over. --- ProtoFlux/Utility/WriteToLog | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 ProtoFlux/Utility/WriteToLog diff --git a/ProtoFlux/Utility/WriteToLog b/ProtoFlux/Utility/WriteToLog new file mode 100644 index 0000000..9a5cba7 --- /dev/null +++ b/ProtoFlux/Utility/WriteToLog @@ -0,0 +1,44 @@ +using Elements.Core; +using FrooxEngine; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using System; +// this is not tested not working this is just random code at work will sort it when home - linka +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Utility +{ + public enum LogSeverity + { + Log, + Warning, + Error + } + + [NodeCategory("Obsidian/Utility/WriteToLog")] + public class WriteToLogNode : ValueFunctionNode + { + public readonly ValueInput Value; + public readonly ValueInput Severity; + public readonly ValueInput Tag; + public readonly ValueInput HandlingUser; + + public void Write() + { + User user = HandlingUser.Evaluate(base.LocalUser); + if (user != null) + { + switch (Severity.Evaluate()) + { + case LogSeverity.Log: + UniLog.Log(Tag.EvaluateRaw() + Value.EvaluateRaw()?.ToString()); + break; + case LogSeverity.Warning: + UniLog.Warning(Tag.EvaluateRaw() + Value.EvaluateRaw()?.ToString()); + break; + case LogSeverity.Error: + UniLog.Error(Tag.EvaluateRaw() + Value.EvaluateRaw()?.ToString()); + break; + } + } + } + } +} \ No newline at end of file From 4f86808030c6f5bfe01bd971a11f56caf296a074 Mon Sep 17 00:00:00 2001 From: xLinka Date: Sun, 21 Jan 2024 18:18:36 +0000 Subject: [PATCH 2/3] new stuff --- .../Utility/{WriteToLog => WriteToLogNode.cs} | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) rename ProtoFlux/Utility/{WriteToLog => WriteToLogNode.cs} (50%) diff --git a/ProtoFlux/Utility/WriteToLog b/ProtoFlux/Utility/WriteToLogNode.cs similarity index 50% rename from ProtoFlux/Utility/WriteToLog rename to ProtoFlux/Utility/WriteToLogNode.cs index 9a5cba7..0440349 100644 --- a/ProtoFlux/Utility/WriteToLog +++ b/ProtoFlux/Utility/WriteToLogNode.cs @@ -3,7 +3,9 @@ using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; using System; -// this is not tested not working this is just random code at work will sort it when home - linka +using System.Threading; +using System.Threading.Tasks; + namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Utility { public enum LogSeverity @@ -12,33 +14,39 @@ public enum LogSeverity Warning, Error } - + [NodeCategory("Obsidian/Utility/WriteToLog")] - public class WriteToLogNode : ValueFunctionNode + public class WriteToLogNode : AsyncActionNode { public readonly ValueInput Value; public readonly ValueInput Severity; public readonly ValueInput Tag; public readonly ValueInput HandlingUser; - public void Write() + public AsyncCall OnWriteStart; + public Continuation OnWriteComplete; + + protected override async Task RunAsync(ExecutionContext context) { - User user = HandlingUser.Evaluate(base.LocalUser); + User user = HandlingUser.Evaluate(context, context.LocalUser); if (user != null) { - switch (Severity.Evaluate()) + await OnWriteStart.ExecuteAsync(context); + switch (Severity.Evaluate(context)) { case LogSeverity.Log: - UniLog.Log(Tag.EvaluateRaw() + Value.EvaluateRaw()?.ToString()); + UniLog.Log(Tag.EvaluateRaw(context) + Value.EvaluateRaw(context)?.ToString()); break; case LogSeverity.Warning: - UniLog.Warning(Tag.EvaluateRaw() + Value.EvaluateRaw()?.ToString()); + UniLog.Warning(Tag.EvaluateRaw(context) + Value.EvaluateRaw(context)?.ToString()); break; case LogSeverity.Error: - UniLog.Error(Tag.EvaluateRaw() + Value.EvaluateRaw()?.ToString()); + UniLog.Error(Tag.EvaluateRaw(context) + Value.EvaluateRaw(context)?.ToString()); break; } + return OnWriteComplete.Target; } + return null; } } -} \ No newline at end of file +} From 861a7b8b5c298ca316334412b48296d3475197bf Mon Sep 17 00:00:00 2001 From: xLinka Date: Sun, 21 Jan 2024 18:41:17 +0000 Subject: [PATCH 3/3] fixed --- ProjectObsidian.csproj | 3 - ProtoFlux/Bindings/Utility/writetolog.cs | 96 ++++++++++++++++++++++++ ProtoFlux/Utility/WriteToLogNode.cs | 23 +++--- 3 files changed, 107 insertions(+), 15 deletions(-) create mode 100644 ProtoFlux/Bindings/Utility/writetolog.cs diff --git a/ProjectObsidian.csproj b/ProjectObsidian.csproj index 9738e67..646ffcc 100644 --- a/ProjectObsidian.csproj +++ b/ProjectObsidian.csproj @@ -40,9 +40,6 @@ $(ResonitePath)Resonite_Data/Managed/Elements.Assets.dll - - $(ResonitePath)/Managed/SteamVR.dll - diff --git a/ProtoFlux/Bindings/Utility/writetolog.cs b/ProtoFlux/Bindings/Utility/writetolog.cs new file mode 100644 index 0000000..d40c26b --- /dev/null +++ b/ProtoFlux/Bindings/Utility/writetolog.cs @@ -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 +{ + public readonly SyncRef> Value; + public readonly SyncRef> Severity; + public readonly SyncRef> Tag; + public readonly SyncRef> HandlingUser; + + public readonly SyncRef OnWriteStart; + public readonly SyncRef 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() + { + 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; + } + } +} diff --git a/ProtoFlux/Utility/WriteToLogNode.cs b/ProtoFlux/Utility/WriteToLogNode.cs index 0440349..6d2b38f 100644 --- a/ProtoFlux/Utility/WriteToLogNode.cs +++ b/ProtoFlux/Utility/WriteToLogNode.cs @@ -2,9 +2,8 @@ using FrooxEngine; using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; -using System; -using System.Threading; using System.Threading.Tasks; +using FrooxEngine.ProtoFlux; namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Utility { @@ -16,17 +15,17 @@ public enum LogSeverity } [NodeCategory("Obsidian/Utility/WriteToLog")] - public class WriteToLogNode : AsyncActionNode + public class WriteToLogNode : AsyncActionNode { - public readonly ValueInput Value; - public readonly ValueInput Severity; - public readonly ValueInput Tag; - public readonly ValueInput HandlingUser; + public ObjectInput Value; + public ValueInput Severity; + public ObjectInput Tag; + public ObjectInput HandlingUser; public AsyncCall OnWriteStart; public Continuation OnWriteComplete; - protected override async Task RunAsync(ExecutionContext context) + protected override async Task RunAsync(FrooxEngineContext context) { User user = HandlingUser.Evaluate(context, context.LocalUser); if (user != null) @@ -35,13 +34,13 @@ protected override async Task RunAsync(ExecutionContext context) switch (Severity.Evaluate(context)) { case LogSeverity.Log: - UniLog.Log(Tag.EvaluateRaw(context) + Value.EvaluateRaw(context)?.ToString()); + UniLog.Log(Tag.Evaluate(context) + Value.Evaluate(context)?.ToString()); break; case LogSeverity.Warning: - UniLog.Warning(Tag.EvaluateRaw(context) + Value.EvaluateRaw(context)?.ToString()); + UniLog.Warning(Tag.Evaluate(context) + Value.Evaluate(context)?.ToString()); break; case LogSeverity.Error: - UniLog.Error(Tag.EvaluateRaw(context) + Value.EvaluateRaw(context)?.ToString()); + UniLog.Error(Tag.Evaluate(context) + Value.Evaluate(context)?.ToString()); break; } return OnWriteComplete.Target; @@ -49,4 +48,4 @@ protected override async Task RunAsync(ExecutionContext context) return null; } } -} +} \ No newline at end of file