diff --git a/ProjectObsidian/ProtoFlux/Audio/IsPaused.cs b/ProjectObsidian/ProtoFlux/Audio/IsPaused.cs new file mode 100644 index 0000000..d7bf72c --- /dev/null +++ b/ProjectObsidian/ProtoFlux/Audio/IsPaused.cs @@ -0,0 +1,22 @@ +using Elements.Core; +using FrooxEngine; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Playback +{ + [NodeCategory("Obsidian/Playback")] + [NodeName("IsPaused", false)] + public class IsPaused : ValueFunctionNode + { + public ObjectInput Playable; + + protected override bool Compute(ExecutionContext context) + { + var target = Playable.Evaluate(context); + var isPlaying = target != null && target.IsPlaying; + var isAtStart = MathX.Approximately(target?.NormalizedPosition ?? 0f, 0f); + return !isPlaying && !isAtStart; + } + } +} diff --git a/ProjectObsidian/ProtoFlux/Audio/IsStopped.cs b/ProjectObsidian/ProtoFlux/Audio/IsStopped.cs new file mode 100644 index 0000000..27a38f2 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/Audio/IsStopped.cs @@ -0,0 +1,22 @@ +using Elements.Core; +using FrooxEngine; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Playback +{ + [NodeCategory("Obsidian/Playback")] + [NodeName("IsStopped", false)] + public class IsStopped : ValueFunctionNode + { + public ObjectInput Playable; + + protected override bool Compute(ExecutionContext context) + { + var target = Playable.Evaluate(context); + var isPlaying = target != null && target.IsPlaying; + var isAtStart = MathX.Approximately(target?.NormalizedPosition ?? 0f, 0f); + return !isPlaying && isAtStart; + } + } +} diff --git a/ProjectObsidian/ProtoFlux/Flow/AsyncWait.cs b/ProjectObsidian/ProtoFlux/Flow/AsyncWait.cs index cc0eeed..acc225a 100644 --- a/ProjectObsidian/ProtoFlux/Flow/AsyncWait.cs +++ b/ProjectObsidian/ProtoFlux/Flow/AsyncWait.cs @@ -2,45 +2,48 @@ using System.Threading.Tasks; using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; - -[NodeCategory("Flow/Async")] -[NodeName("Async Wait", false)] -public class AsyncWait : AsyncActionNode +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Flow { - public ValueInput Condition; - public ValueInput Timeout; - - public AsyncCall OnStarted; - - public Continuation OnDone; - public Continuation TimedOut; - - protected override async Task RunAsync(ExecutionContext context) + [NodeCategory("Obsidian/Flow")] + [NodeName("Async Wait", false)] + public class AsyncWait : AsyncActionNode { - await OnStarted.ExecuteAsync(context); + public ValueInput Condition; + public ValueInput Timeout; - var timeoutInSeconds = Timeout.Evaluate(context); - var startTime = DateTime.UtcNow; + public AsyncCall OnStarted; - // Initial evaluation of the condition - if (Condition.Evaluate(context, defaultValue: false)) - { - return OnDone.Target; - } + public Continuation OnDone; + public Continuation TimedOut; - while (!Condition.Evaluate(context, defaultValue: false)) + protected override async Task RunAsync(ExecutionContext context) { - if ((DateTime.UtcNow - startTime).TotalSeconds > timeoutInSeconds) + await OnStarted.ExecuteAsync(context); + + var timeoutInSeconds = Timeout.Evaluate(context); + var startTime = DateTime.UtcNow; + + // Initial evaluation of the condition + if (Condition.Evaluate(context, defaultValue: false)) { - return TimedOut.Target; + return OnDone.Target; } - if (context.AbortExecution) + while (!Condition.Evaluate(context, defaultValue: false)) { - throw new ExecutionAbortedException(base.Runtime as IExecutionRuntime, this, TimedOut.Target, isAsync: true); + if ((DateTime.UtcNow - startTime).TotalSeconds > timeoutInSeconds) + { + return TimedOut.Target; + } + + if (context.AbortExecution) + { + throw new ExecutionAbortedException(base.Runtime as IExecutionRuntime, this, TimedOut.Target, isAsync: true); + } } - } - return OnDone.Target; + return OnDone.Target; + } } } +