-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraySet.cs
More file actions
32 lines (26 loc) · 950 Bytes
/
ArraySet.cs
File metadata and controls
32 lines (26 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using NodeDev.Core.Connections;
using NodeDev.Core.Types;
using System.Linq.Expressions;
namespace NodeDev.Core.Nodes;
public class ArraySet : NormalFlowNode
{
public override string Name
{
get => $"{Inputs[0].Type.Name} Set";
set { }
}
public ArraySet(Graph graph, string? id = null) : base(graph, id)
{
var undefinedT = new UndefinedGenericType("T");
Inputs.Add(new("Array", this, undefinedT.ArrayType));
Inputs.Add(new("Index", this, TypeFactory.Get<int>()));
Inputs.Add(new("Obj", this, undefinedT));
}
internal override Expression BuildExpression(Dictionary<Connection, Graph.NodePathChunks>? subChunks, BuildExpressionInfo info)
{
if (!Inputs[1].Type.IsArray)
throw new Exception("ArrayGet.Inputs[1] should be an array type");
var arrayIndex = Expression.ArrayIndex(info.LocalVariables[Inputs[1]], info.LocalVariables[Inputs[2]]);
return Expression.Assign(arrayIndex, info.LocalVariables[Inputs[3]]);
}
}