66 lines
2.0 KiB
C#
66 lines
2.0 KiB
C#
using System;
|
|
using System.Reactive.Linq;
|
|
using DynamicData;
|
|
using Intromat.Model.Compiler;
|
|
using Intromat.PersistentModel;
|
|
using Intromat.ViewModels;
|
|
using Intromat.ViewModels.Editors;
|
|
using Intromat.ViewModels.Previews;
|
|
using Intromat.Views;
|
|
using NodeNetwork.Toolkit.ValueNode;
|
|
using ReactiveUI;
|
|
using Splat;
|
|
|
|
namespace Intromat.Nodes.Code
|
|
{
|
|
public class IntLiteralNode : CodeGenNodeViewModel
|
|
{
|
|
static IntLiteralNode()
|
|
{
|
|
Locator.CurrentMutable.Register(() => new CodeGenNodeView(), typeof(IViewFor<IntLiteralNode>));
|
|
}
|
|
|
|
public IntLiteralNode() : base(NodeType.Literal)
|
|
{
|
|
Name = "Integer";
|
|
|
|
Output = new CodeGenOutputViewModel<ITypedExpression<int>>(EPortType.Integer)
|
|
{
|
|
Name = "Value",
|
|
Editor = ValueEditor,
|
|
Value = ValueEditor.ValueChanged.Select(v => new IntLiteralValue { Value = v })
|
|
};
|
|
Outputs.Add(Output);
|
|
|
|
var stringPreview = new StringPreviewViewModel();
|
|
Preview = stringPreview;
|
|
|
|
this.WhenAnyValue(vm => vm.Output.CurrentValue)
|
|
.Where(v => v != null)
|
|
.Subscribe(_ => stringPreview.Value = Output.CurrentValue.PreviewValue ?? "0");
|
|
}
|
|
|
|
public IntegerValueEditorViewModel ValueEditor { get; } = new();
|
|
|
|
public ValueNodeOutputViewModel<ITypedExpression<int>> Output { get; }
|
|
|
|
public override NodeModelBase CreateModel()
|
|
{
|
|
return new IntLiteralModel();
|
|
}
|
|
|
|
public override void LoadModel(NodeModelBase model)
|
|
{
|
|
base.LoadModel(model);
|
|
var intLiteral = (IntLiteralModel)model;
|
|
ValueEditor.Value = intLiteral.Value;
|
|
}
|
|
|
|
public override void SaveModel(NodeModelBase model)
|
|
{
|
|
base.SaveModel(model);
|
|
var intLiteral = (IntLiteralModel)model;
|
|
intLiteral.Value = ValueEditor.Value;
|
|
}
|
|
}
|
|
} |