Skip to content

Commit

Permalink
Merge pull request #32 from paradoxical-autumn/main
Browse files Browse the repository at this point in the history
While nodes with iteration & UserFromUserRef
  • Loading branch information
Xlinka authored Jul 1, 2024
2 parents 51fb4ee + 2432189 commit fb8fe73
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
40 changes: 40 additions & 0 deletions ProjectObsidian/ProtoFlux/Flow/AsyncWhileWithIteration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using ProtoFlux.Core;
using System.Threading.Tasks;
using ProtoFlux.Runtimes.Execution;

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Flow
{
[NodeCategory("Obsidian/Flow")]
[NodeName("AsyncWhile With I", false)]
public class AsyncWhileWithIteration : AsyncActionNode<ExecutionContext>
{
public ValueInput<bool> Condition;
public AsyncCall LoopStart;
public AsyncCall LoopIteration;
public Continuation LoopEnd;
public readonly ValueOutput<int> i;
private int iter;

protected override async Task<IOperation> RunAsync(ExecutionContext context)
{
iter = 0;
await LoopStart.ExecuteAsync(context);
while (Condition.Evaluate(context, defaultValue: false))
{
i.Write(iter, context);
if (context.AbortExecution)
{
throw new ExecutionAbortedException(base.Runtime as IExecutionRuntime, this, LoopIteration.Target, isAsync: true);
}
await LoopIteration.ExecuteAsync(context);
iter++;
}
return LoopEnd.Target;
}

public AsyncWhileWithIteration()
{
i = new ValueOutput<int>(this);
}
}
}
39 changes: 39 additions & 0 deletions ProjectObsidian/ProtoFlux/Flow/WhileWithIteration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Flow
{
[NodeCategory("Obsidian/Flow")]
[NodeName("While With I", false)]
public class WhileWithIteration : ActionNode<ExecutionContext>
{
public ValueInput<bool> Condition;
public Call LoopStart;
public Call LoopIteration;
public Call LoopEnd;
public readonly ValueOutput<int> i;
private int iter;

protected override IOperation Run(ExecutionContext context)
{
iter = 0;
LoopStart.Execute(context);
while (Condition.Evaluate(context, defaultValue: false))
{
i.Write(iter, context);
if (context.AbortExecution)
{
throw new ExecutionAbortedException(base.Runtime as IExecutionRuntime, this, LoopIteration.Target, isAsync: false);
}
LoopIteration.Execute(context);
iter++;
}
return LoopEnd.Target;
}

public WhileWithIteration()
{
i = new ValueOutput<int>(this);
}
}
}
21 changes: 21 additions & 0 deletions ProjectObsidian/ProtoFlux/Users/UserFromUserRef.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using FrooxEngine.ProtoFlux;
using ProtoFlux.Core;
using FrooxEngine;
using ProtoFlux.Runtimes.Execution;

namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Users
{
[ContinuouslyChanging]
[NodeCategory("Obsidian/Users")]
[NodeName("User From UserRef")]
public class UserFromUserRef : ObjectFunctionNode<FrooxEngineContext, User>
{
public readonly ObjectInput<UserRef> UserRef;

protected override User Compute(FrooxEngineContext context)
{
UserRef userRef = UserRef.Evaluate(context);
return userRef.Target;
}
}
}

0 comments on commit fb8fe73

Please sign in to comment.