public DivisionNodeViewModel() { Name = "Divide"; Input1 = new ValueNodeInputViewModel <int?> { Name = "A", Editor = new IntegerValueEditorViewModel() }; Inputs.Add(Input1); Input2 = new ValueNodeInputViewModel <int?> { Name = "B", Editor = new IntegerValueEditorViewModel() }; Inputs.Add(Input2); var divide = this.WhenAnyValue(vm => vm.Input1.Value, vm => vm.Input2.Value) .Select(_ => Input1.Value != null && Input2.Value != null && Input2.Value != 0 ? Input1.Value / Input2.Value : null); Output = new ValueNodeOutputViewModel <int?> { Name = "A / B", Value = divide }; Outputs.Add(Output); }
public void TestListInputDisconnect() { var input1 = new ValueListNodeInputViewModel <string>(); NodeViewModel node1 = new NodeViewModel(); node1.Inputs.Add(input1); var output2 = new ValueNodeOutputViewModel <string> { Value = Observable.Return("Test") }; NodeViewModel node2 = new NodeViewModel(); node2.Outputs.Add(output2); NetworkViewModel network = new NetworkViewModel(); network.Nodes.Add(node1); network.Nodes.Add(node2); var conn1 = network.ConnectionFactory(input1, output2); network.Connections.Add(conn1); CollectionAssert.AreEqual(new[] { "Test" }, input1.Values.Items.AsArray()); network.Connections.Remove(conn1); CollectionAssert.AreEqual(new string[0], input1.Values.Items.AsArray()); }
public ProductNodeViewModel() { Name = "Product"; Input1 = new ValueNodeInputViewModel <int?> { Name = "A", Editor = new IntegerValueEditorViewModel() }; Inputs.Add(Input1); Input2 = new ValueNodeInputViewModel <int?> { Name = "B", Editor = new IntegerValueEditorViewModel() }; Inputs.Add(Input2); var product = this.WhenAnyValue(vm => vm.Input1.Value, vm => vm.Input2.Value) .Select(_ => Input1.Value != null && Input2.Value != null ? Input1.Value * Input2.Value : null); Output = new ValueNodeOutputViewModel <int?> { Name = "A * B", Value = product }; Outputs.Add(Output); }
public SumNodeViewModel() { Name = "Sum"; Input1 = new ValueNodeInputViewModel <int?> { Name = "A", Editor = new IntegerValueEditorViewModel() }; Inputs.Add(Input1); Input2 = new ValueNodeInputViewModel <int?> { Name = "B", Editor = new IntegerValueEditorViewModel() }; Inputs.Add(Input2); var sum = this.WhenAnyValue(vm => vm.Input1.Value, vm => vm.Input2.Value) .Select(_ => Input1.Value != null && Input2.Value != null ? Input1.Value + Input2.Value : null); Output = new ValueNodeOutputViewModel <int?> { Name = "A + B", Value = sum }; Outputs.Add(Output); }
public PrintNode() : base(NodeType.Function) { this.Name = "Print"; Text = new CodeGenInputViewModel <ITypedExpression <string> >(PortType.String) { Name = "Text" }; this.Inputs.Add(Text); Flow = new CodeGenOutputViewModel <IStatement>(PortType.Execution) { Name = "", Value = this.Text.ValueChanged.Select(stringExpr => new FunctionCall { FunctionName = "print", Parameters = { stringExpr ?? new StringLiteral { Value = "" } } }) }; this.Outputs.Add(Flow); }
public void TestListInputDisconnect() { using (TestUtils.WithScheduler(ImmediateScheduler.Instance)) { var input1 = new ValueListNodeInputViewModel <string>(); NodeViewModel node1 = new NodeViewModel { Inputs = { input1 } }; var output2 = new ValueNodeOutputViewModel <string> { Value = Observable.Return("Test") }; NodeViewModel node2 = new NodeViewModel { Outputs = { output2 } }; NetworkViewModel network = new NetworkViewModel(); network.Nodes.Add(node1); network.Nodes.Add(node2); var conn1 = network.ConnectionFactory(input1, output2); network.Connections.Add(conn1); CollectionAssert.AreEqual(new[] { "Test" }, input1.Values.ToArray()); network.Connections.Remove(conn1); CollectionAssert.AreEqual(new string[0], input1.Values.ToArray()); } }
public InteractionNode(InteractionLiteral value) : base("Interaction", value) { Description = new ValueNodeInputViewModel <string>() { Name = "Description" }; ActionBuilderLua = new ValueNodeInputViewModel <string>() { Name = "Action Builder (Lua Source)" }; CreationCondition = new ValueNodeInputViewModel <string>() { Name = "Creation Condition (Lua Source)" }; ActivationDistance = new ValueNodeInputViewModel <float>() { Name = "Activation Distance" }; ClientInt = new ValueNodeInputViewModel <string>() { Name = "Client Interaction Code (Lua Source)" }; Location = new ValueNodeInputViewModel <string>() { Name = "Search Location (Lua Source)" }; Output = new ValueNodeOutputViewModel <InteractionLiteral>() { Name = "Resulting Interaction" }; this.Inputs.Add(Description); this.Inputs.Add(ActionBuilderLua); this.Inputs.Add(CreationCondition); this.Inputs.Add(ActivationDistance); this.Inputs.Add(ClientInt); this.Inputs.Add(Location); this.Outputs.Add(Output); this.WhenAnyObservable(vm => vm.Description.Changed, vm => vm.ActionBuilderLua.Changed, vm => vm.CreationCondition.Changed, vm => vm.ActivationDistance.Changed, vm => vm.ClientInt.Changed, vm => vm.Location.Changed).Subscribe(ip => { InteractionLiteral interaction = InputDocument as InteractionLiteral; interaction.Description = Description.Value; interaction.ActionBuilderLua = ActionBuilderLua.Value; interaction.CreationConditionLua = CreationCondition.Value; interaction.ActivationDistance = ActivationDistance.Value; interaction.ClientIntLua = ClientInt.Value; interaction.LocationLua = Location.Value; InputDocument = interaction; Output.Value = Observable.Return(interaction); }); CanBeRemovedByUser = false; }
public virtual ValueListNodeInputViewModel <T> CreateCompatibleInput <T>(ValueNodeOutputViewModel <IObservableList <T> > output) { return(new ValueListNodeInputViewModel <T>() { Name = output.Name, Icon = output.Icon }); }
public DialogueResponseNode() : base("Response", null) { SpeechInput = new ValueNodeInputViewModel <string>() { Name = "Line of Speech" }; PromptsInput = new ValueListNodeInputViewModel <DialoguePrompt>() { Name = "Prompts" }; Order = new ValueNodeInputViewModel <long>() { Name = "Response Order" }; ConditionLua = new ValueNodeInputViewModel <string>() { Name = "Lua Condition" }; ActionLua = new ValueNodeInputViewModel <string>() { Name = "Lua Action" }; Title = new ValueNodeInputViewModel <string>() { Name = "Prompt Name" }; FinalPrompt = new ValueNodeOutputViewModel <DialogueResponse>(); this.Inputs.Add(SpeechInput); this.Inputs.Add(PromptsInput); this.Inputs.Add(Order); this.Inputs.Add(ConditionLua); this.Inputs.Add(ActionLua); this.Inputs.Add(Title); this.Outputs.Add(FinalPrompt); this.WhenAnyObservable(vm => vm.SpeechInput.Changed, vm => vm.Title.Changed, vm => vm.PromptsInput.Changed, vm => vm.Order.Changed, vm => vm.ActionLua.Changed, vm => vm.ConditionLua.Changed).Subscribe(ip => { FinalPrompt.Value = Observable.Return(new DialogueResponse() { Speech = SpeechInput.Value, Title = Title.Value, Prompts = new ObservableCollection <DialoguePrompt>(PromptsInput.Values.Items.ToList()), Order = (int)Order.Value, ActionLua = ActionLua.Value, ConditionLua = ConditionLua.Value, }); RodskaApp app = (RodskaApp)System.Windows.Application.Current; MainWindow window = (MainWindow)app.MainWindow; window.SignalDocumentChanged(InputDocument); }); }
public ForLoopNode() : base(NodeType.FlowControl) { this.Name = "For Loop"; LoopBodyFlow = new CodeGenListInputViewModel <IStatement>(PortType.Execution) { Name = "Loop Body" }; this.Inputs.Add(LoopBodyFlow); LoopEndFlow = new CodeGenListInputViewModel <IStatement>(PortType.Execution) { Name = "Loop End" }; this.Inputs.Add(LoopEndFlow); FirstIndex = new CodeGenInputViewModel <ITypedExpression <int> >(PortType.Integer) { Name = "First Index" }; this.Inputs.Add(FirstIndex); LastIndex = new CodeGenInputViewModel <ITypedExpression <int> >(PortType.Integer) { Name = "Last Index" }; this.Inputs.Add(LastIndex); CurrentIndex = new CodeGenOutputViewModel <VariableReference <int> >(PortType.Integer) { Name = "Current Index" }; this.Outputs.Add(CurrentIndex); var loopBodyChanged = LoopBodyFlow.Values.Changed.Select(_ => Unit.Default).StartWith(Unit.Default); var loopEndChanged = LoopEndFlow.Values.Changed.Select(_ => Unit.Default).StartWith(Unit.Default); FlowIn = new CodeGenOutputViewModel <IStatement>(PortType.Execution) { Name = "", Value = Observable.CombineLatest(loopBodyChanged, loopEndChanged, FirstIndex.ValueChanged, LastIndex.ValueChanged, (bodyChange, endChange, firstI, lastI) => (BodyChange: bodyChange, EndChange: endChange, FirstI: firstI, LastI: lastI)) .Select(v => new ForLoop { LoopBody = new StatementSequence(LoopBodyFlow.Values), LoopEnd = new StatementSequence(LoopEndFlow.Values), LowerBound = v.FirstI ?? new IntLiteral { Value = 0 }, UpperBound = v.LastI ?? new IntLiteral { Value = 1 } }) }; this.Outputs.Add(FlowIn); } }
public override ValueListNodeInputViewModel <T> CreateCompatibleInput <T>(ValueNodeOutputViewModel <IObservableList <T> > output) { return(new CodeGenListInputViewModel <T>(((CodeGenPortViewModel)output.Port).PortType) { Name = output.Name, Editor = new GroupEndpointEditorViewModel <T>(this), HideEditorIfConnected = false }); }
public IN_Node_Class() { TextOutput = new ValueNodeOutputViewModel <string>() { Name = "Input", Value = this.WhenAnyObservable(vm => vm.NameInput.ValueChanged) .Select(name => $"Hello {name}!") }; Outputs.Add(TextOutput); }
public NodeWithPreview() : base() { NodeOutput = new ValueNodeOutputViewModel <IModule>() { Name = "Output", Editor = OutputPreview }; Outputs.Add(NodeOutput); }
public QuestNode() : base(NodeType.Literal) { this.Name = NPCChooseEditor.NpcValue.Name; // HeaderIconButton action this.HeaderIconButton = ReactiveCommand.Create(() => { // Call models function NPCChooseEditor.NpcSelectNew(); }); // Watch models selected value for change. Once changed, update the nodes icon this.WhenAnyValue(x => x.NPCChooseEditor.NpcValue).Subscribe(name => { SelectNPC(); }); OutputB = new CodeGenOutputViewModel <ITypedExpression <bool> >(PortType.Boolean) { Name = "Add / Remove (w/ Ctrl) Output", Editor = BoolEditor, Value = BoolEditor.ValueChanged.Select(v => new BoolLiteral { Value = v }), }; this.Outputs.Add(OutputB); this.WhenAnyValue(x => x.BoolEditor.Value).Subscribe(x => ManageOutputs(x)); // Subcribe to every change of the state of the button Text = new CodeGenInputViewModel <ITypedExpression <string> >(PortType.String) { Editor = EditableLabelEditor }; this.Inputs.Add(Text); Output = new CodeGenOutputViewModel <ITypedExpression <string> >(PortType.String) { Name = "Value1", Editor = ValueEditor, Value = ValueEditor.ValueChanged.Select(v => new StringLiteral { Value = v }) }; this.Outputs.Add(Output); Output = new CodeGenOutputViewModel <ITypedExpression <string> >(PortType.String) { Name = "Value2", Editor = ValueEditor1, Value = ValueEditor.ValueChanged.Select(v => new StringLiteral { Value = v }) }; this.Outputs.Add(Output); }
public ConstantNodeViewModel() { Name = "ConstantColor"; Output = new ValueNodeOutputViewModel <Color?> { Name = "Color", Editor = ValueEditor, Value = this.WhenAnyValue(vm => vm.ValueEditor.Value) }; Outputs.Add(Output); }
public SubstanceNodeViewModel(Substance sub) { Substance = sub; Name = Substance.Name; switch (Substance) { case Substance <ObservableCollection <PrimitiveBinding <float> > > float_sub: ValueNodeOutputViewModel <ObservableCollection <PrimitiveBinding <float> > > float_output = new ValueNodeOutputViewModel <ObservableCollection <PrimitiveBinding <float> > >(); float_output.Editor = new FloatValueEditorViewModel() { Value = float_sub.Data }; Outputs.Edit(x => x.Add(float_output)); break; case Substance <ObservableCollection <PrimitiveBinding <int> > > int_sub: ValueNodeOutputViewModel <ObservableCollection <PrimitiveBinding <int> > > int_output = new ValueNodeOutputViewModel <ObservableCollection <PrimitiveBinding <int> > >(); int_output.Editor = new IntegerValueEditorViewModel() { Value = int_sub.Data }; Outputs.Edit(x => x.Add(int_output)); break; case Substance <ObservableCollection <BindingVector3> > vec_sub: ValueNodeOutputViewModel <ObservableCollection <BindingVector3> > vec_output = new ValueNodeOutputViewModel <ObservableCollection <BindingVector3> >(); vec_output.Editor = new VectorValueEditorViewModel() { Value = vec_sub.Data }; Outputs.Edit(x => x.Add(vec_output)); break; case Substance <PrimitiveBinding <string> > string_sub: ValueNodeOutputViewModel <PrimitiveBinding <string> > string_output = new ValueNodeOutputViewModel <PrimitiveBinding <string> >(); string_output.Editor = new StringValueEditorViewModel() { Value = string_sub.Data }; Outputs.Edit(x => x.Add(string_output)); break; default: Outputs.Edit(x => x.Add(new NodeOutputViewModel())); break; } }
public ConstantNodeViewModel() { this.Name = "Constant"; Output = new ValueNodeOutputViewModel <int?> { Name = "Value", Editor = ValueEditor, Value = this.WhenAnyValue(vm => vm.ValueEditor.Value) }; this.Outputs.Add(Output); }
public FloatNode() { Name = "Float"; Output = new ValueNodeOutputViewModel <float>() { Name = "Value", Editor = ValueEditor, Value = ValueEditor.ValueChanged.Select(v => v ?? 10.0f) }; this.Outputs.Add(Output); }
public StringNode() { Name = "String (Text)"; StringOutput = new ValueNodeOutputViewModel <string>() { Name = "Value", Editor = ValueEditor, Value = ValueEditor.ValueChanged.Select(v => v) }; this.Outputs.Add(StringOutput); }
public IntLiteralNode() : base(NodeType.Literal) { this.Name = "Integer"; Output = new CodeGenOutputViewModel<ITypedExpression<int>>(PortType.Integer) { Name = "Value", Editor = ValueEditor, Value = ValueEditor.ValueChanged.Select(v => new IntLiteral{Value = v ?? 0}) }; this.Outputs.Add(Output); }
public IntegerNode() { Name = "Integer"; Output = new ValueNodeOutputViewModel <int>() { Name = "Value", Editor = ValueEditor, Value = ValueEditor.ValueChanged.Select(v => v ?? 0) }; this.Outputs.Add(Output); }
private void AddOutput(string name) { var vm = new ValueNodeOutputViewModel <bool?> { Name = name, Port = new ButtonPortViewModel() }; var ov = new Subject <bool?>(); _outputs.Add(ov); vm.Value = ov; Outputs.Add(vm); }
public TextLiteralNode() : base(NodeType.Literal) { this.Name = "Text"; Output = new CodeGenOutputViewModel <ITypedExpression <string> >(PortType.String) { Name = "Value", Editor = ValueEditor, Value = ValueEditor.ValueChanged.Select(v => new StringLiteral { Value = v }) }; this.Outputs.Add(Output); }
public MainWindow() { InitializeComponent(); //Create a new viewmodel for the NetworkView var network = new NetworkViewModel(); //Create the node for the first node, set its name and add it to the network. var node1 = new NodeViewModel(); node1.Name = "Node 1"; network.Nodes.Add(node1); //Create the viewmodel for the input on the first node, set its name and add it to the node. var node1Input = new ValueNodeInputViewModel <string>(); node1Input.Name = "Node 1 input"; node1.Inputs.Add(node1Input); //Print value on change node1Input.ValueChanged.Subscribe(newValue => { Console.WriteLine(newValue); }); //Create the second node viewmodel, set its name, add it to the network and add an output in a similar fashion. var node2 = new NodeViewModel(); node2.Name = "Node 2"; network.Nodes.Add(node2); var node2Output = new ValueNodeOutputViewModel <string>(); node2Output.Name = "Node 2 output"; node2.Outputs.Add(node2Output); node2Output.Value = Observable.Return("Example string"); //Create the third test node viewmodel //Its I/O is already set in the HelloWorldNode class, so no need to declare new ones var node3 = new HelloWorldNode(); node2.Name = "Node 3"; network.Nodes.Add(node3); //Assign the viewmodel to the view. networkView.ViewModel = network; }
public void TestValuePropagation() { //Setup var scheduler = new TestScheduler(); var nodeA = new NodeViewModel(); Subject <int> sourceA = new Subject <int>(); var outputA = new ValueNodeOutputViewModel <int> { Value = sourceA }; nodeA.Outputs.Add(outputA); var nodeB = new NodeViewModel(); var inputB = new ValueListNodeInputViewModel <int>(); nodeB.Inputs.Add(inputB); NetworkViewModel network = new NetworkViewModel(); network.Nodes.AddRange(new [] { nodeA, nodeB }); network.Connections.Add(network.ConnectionFactory(inputB, outputA)); //Define actions scheduler.Schedule(TimeSpan.FromTicks(10), () => sourceA.OnNext(1)); scheduler.Schedule(TimeSpan.FromTicks(20), () => sourceA.OnNext(0)); scheduler.Schedule(TimeSpan.FromTicks(30), () => sourceA.OnNext(1)); scheduler.Schedule(TimeSpan.FromTicks(40), () => sourceA.OnNext(0)); scheduler.Schedule(TimeSpan.FromTicks(50), () => sourceA.OnNext(2)); var actual = scheduler.Start(() => inputB.Values.Connect().QueryWhenChanged(), created: 0, subscribed: 0, disposed: 100); //Assert Assert.AreEqual(actual.Messages.Count, 6); Assert.AreEqual(actual.Messages[0].Time, 1); Assert.IsTrue(actual.Messages[0].Value.Value.SequenceEqual(new[] { 0 })); Assert.AreEqual(actual.Messages[1].Time, 10); Assert.IsTrue(actual.Messages[1].Value.Value.SequenceEqual(new[] { 1 })); Assert.AreEqual(actual.Messages[2].Time, 20); Assert.IsTrue(actual.Messages[2].Value.Value.SequenceEqual(new[] { 0 })); Assert.AreEqual(actual.Messages[3].Time, 30); Assert.IsTrue(actual.Messages[3].Value.Value.SequenceEqual(new[] { 1 })); Assert.AreEqual(actual.Messages[4].Time, 40); Assert.IsTrue(actual.Messages[4].Value.Value.SequenceEqual(new[] { 0 })); Assert.AreEqual(actual.Messages[5].Time, 50); Assert.IsTrue(actual.Messages[5].Value.Value.SequenceEqual(new[] { 2 })); }
public HelloWorldNode() { this.Name = "Hello World Node"; NameInput = new ValueNodeInputViewModel <string>() { Name = "Name" }; this.Inputs.Add(NameInput); TextOutput = new ValueNodeOutputViewModel <string>() { Name = "Text", Value = this.WhenAnyObservable(vm => vm.NameInput.ValueChanged) .Select(name => $"Hello {name}!") }; this.Outputs.Add(TextOutput); }
public DialogueNode(Dialogue value) : base("Conversation", value) { InitialPrompts = new ValueListNodeInputViewModel <DialoguePrompt>() { Name = "Initial Prompts" }; Prompts = new ValueListNodeInputViewModel <DialoguePrompt>() { Name = "Prompts" }; Responses = new ValueListNodeInputViewModel <DialogueResponse>() { Name = "Responses" }; Inputs.Add(InitialPrompts); Inputs.Add(Prompts); Inputs.Add(Responses); Output = new ValueNodeOutputViewModel <Dialogue>() { Name = "Final Result", Visibility = NodeNetwork.ViewModels.EndpointVisibility.AlwaysHidden, }; this.WhenAnyObservable(vm => vm.InitialPrompts.Changed, vm => vm.Prompts.Changed, vm => vm.Responses.Changed).Subscribe(ip => { Dialogue dialogue = InputDocument as Dialogue; dialogue.Prompts = new ObservableCollection <DialoguePrompt>(Prompts.Values.Items.ToList()); dialogue.Responses = new ObservableCollection <DialogueResponse>(Responses.Values.Items.ToList()); dialogue.InitialPrompts = new ObservableCollection <DialoguePrompt>(InitialPrompts.Values.Items.ToList()); InputDocument = dialogue; Output.Value = Observable.Return(dialogue); }); RodskaApp app = (RodskaApp)RodskaApp.Current; MainWindow window = (MainWindow)app.MainWindow; window.DocumentChanged += Window_DocumentChanged; CanBeRemovedByUser = false; }
public HelloWorldNode() { this.Name = "Hello World Node!"; nameInput = new ValueNodeInputViewModel <string>(); { Name = "Input"; } this.Inputs.Add(nameInput); textOutput = new ValueNodeOutputViewModel <string>() { Name = "Output", Value = this.WhenAnyObservable(vm => vm.nameInput.ValueChanged) .Select(name => $"Hello {name}!") }; this.Outputs.Add(textOutput); }
public NodeViewModel CreateNode() { var input = new ValueNodeInputViewModel <int?> { Name = "A" }; var output = new ValueNodeOutputViewModel <int?> { Name = "B", Value = Observable.CombineLatest(input.ValueChanged, Observable.Return(-1), (i1, i2) => (int?)(i1 ?? i2) + 1) }; NodeViewModel node = new NodeViewModel(); node.Inputs.Add(input); node.Outputs.Add(output); output.Value.Subscribe(v => node.Name = v.ToString()); return(node); }
public ButtonInputNode() { Name = "Button Input"; var buttonInput = new ButtonInputViewModel(OnButtonEvent) { ButtonLabel = "Click" }; Inputs.Add(buttonInput); var output = new ValueNodeOutputViewModel <bool?> { Name = "Output", Value = _output, Port = new ButtonPortViewModel() }; Outputs.Add(output); }