-
-
Save TigerHix/8747793a68f0aa15a469f9823812e221 to your computer and use it in GitHub Desktop.
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
using Warudo.Core.Attributes; | |
using Warudo.Core.Data; | |
using Warudo.Core.Graphs; | |
using Warudo.Core.Localization; | |
namespace Warudo.Plugins.Core.Nodes { | |
[NodeType(Id = "5e1411a4-627a-4b50-a371-6fbe099e55bc", Title = "MULTI_GATE", Category = "CATEGORY_CONTROL_FLOW")] | |
public class MultiGateNode : Node { | |
[DataInput] | |
[IntegerSlider(2, 10)] | |
[Label("EXIT_COUNT")] | |
public int ExitCount = 2; | |
[DataInput] | |
[Label("LOOP")] | |
public bool Loop = true; | |
[DataInput] | |
[Label("CURRENT_EXIT")] | |
public int CurrentExit = 1; | |
[DataOutput] | |
[Label("CURRENT_EXIT")] | |
public int CurrentExitOutput() => CurrentExit; | |
protected override void OnCreate() { | |
base.OnCreate(); | |
Watch(nameof(ExitCount), SetupExitPorts); | |
Watch(nameof(CurrentExit), () => { | |
if (CurrentExit > ExitCount + 1) { | |
CurrentExit = ExitCount + 1; | |
BroadcastDataInput(nameof(CurrentExit)); | |
} else if (CurrentExit < 1) { | |
CurrentExit = 1; | |
BroadcastDataInput(nameof(CurrentExit)); | |
} | |
}); | |
SetupExitPorts(); | |
} | |
[FlowInput] | |
public Continuation Enter() { | |
if (CurrentExit <= ExitCount) { | |
InvokeFlow("Exit" + CurrentExit); | |
} | |
CurrentExit = Loop ? CurrentExit % ExitCount + 1 : CurrentExit; | |
BroadcastDataInput(nameof(CurrentExit)); | |
return null; | |
} | |
[FlowInput] | |
[Label("RESET")] | |
public Continuation Reset() { | |
CurrentExit = 1; | |
BroadcastDataInput(nameof(CurrentExit)); | |
return null; | |
} | |
public void SetupExitPorts() { | |
if (ExitCount < 2) { | |
ExitCount = 2; | |
} else if (ExitCount > 99) { | |
ExitCount = 99; | |
} | |
FlowOutputPortCollection.GetPorts().Clear(); | |
for (var i = 1; i <= ExitCount; i++) { | |
AddFlowOutputPort("Exit" + i, new FlowOutputProperties { | |
label = "EXIT".Localized() + " " + i | |
}); | |
} | |
CurrentExit = 1; | |
var indexTypeProperties = (IntegerDataInputTypeProperties) GetDataInputPort(nameof(CurrentExit)).Properties.typeProperties; | |
indexTypeProperties.min = 1; | |
indexTypeProperties.max = ExitCount; | |
Broadcast(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment