Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Operators/Lib/numbers/floats/logic/PickFloatFromList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Lib.numbers.floats.logic;
[Guid("0841cdd4-0106-4f4e-826b-8de23bb5b5f0")]
internal sealed class PickFloatFromList : Instance<PickFloatFromList>
{
[Output(Guid = "{EC2286AF-3EE0-4AF0-AA23-272D4B3710E0}")]
[Output(Guid = "EC2286AF-3EE0-4AF0-AA23-272D4B3710E0")]
public readonly Slot<float> Selected = new();

public PickFloatFromList()
Expand All @@ -14,16 +14,22 @@ public PickFloatFromList()
private void Update(EvaluationContext context)
{
var list = Input.GetValue(context);
var index = Index.GetValue(context);
if (list != null && index >= 0 && index < list.Count)
if (list == null || list.Count == 0)
{
Selected.Value = list[index];
Selected.Value = default;
return;
}

var index = Index.GetValue(context) % list.Count;
if (index < 0)
index += list.Count;

Selected.Value = list[index];
}

[Input(Guid = "{329BA6A4-5B84-43FC-8899-0C04465844DA}")]
[Input(Guid = "329BA6A4-5B84-43FC-8899-0C04465844DA")]
public readonly InputSlot<List<float>> Input = new(new List<float>(20));

[Input(Guid = "{2F87E21A-A1BD-4E2A-948C-2FA35245998D}")]
[Input(Guid = "2F87E21A-A1BD-4E2A-948C-2FA35245998D")]
public readonly InputSlot<int> Index = new(0);
}
15 changes: 7 additions & 8 deletions Operators/Lib/numbers/ints/PickIntFromList.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using T3.Core.Utils;

namespace Lib.numbers.ints;

[Guid("df218352-52ae-4d11-a0f1-24fce0964af5")]
Expand All @@ -17,14 +15,15 @@ private void Update(EvaluationContext context)
{
var list = Input.GetValue(context);
if (list == null || list.Count == 0)
return;

if (list.Count == 0)
{
Selected.Value = list[0];
Selected.Value = default;
return;
}

var index = Index.GetValue(context).Mod(list.Count-1);

var index = Index.GetValue(context) % list.Count;
if (index < 0)
index += list.Count;

Selected.Value = list[index];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace [email protected];

[Guid("ef357e66-24e9-4f54-8d86-869db74602f4")]
internal sealed class PickFromStringList : Instance<PickFromStringList>
internal sealed class PickStringFromList : Instance<PickStringFromList>
{
[Output(Guid = "467bb46e-3391-48a7-b0eb-f7fd9d77b60f")]
public readonly Slot<string> Selected = new();
Expand All @@ -10,37 +10,28 @@ internal sealed class PickFromStringList : Instance<PickFromStringList>
public readonly Slot<int> Count = new();


public PickFromStringList()
public PickStringFromList()
{
Selected.UpdateAction += Update;
}

private void Update(EvaluationContext context)
{
var list = Input.GetValue(context);
if (list == null)
{
Selected.Value= string.Empty;
Count.Value = 0;
return;
}

var count = list.Count;
Count.Value = count;
if (count == 0)
if (list == null || list.Count == 0)
{
Selected.Value = string.Empty;
Count.Value = 0;
return;
}

if (count < 0)
count = -count;

var index = Index.GetValue(context) % count;
if (index >= 0 && index < list.Count)
{
Selected.Value = list[index];
}
Count.Value = list.Count;

var index = Index.GetValue(context) % list.Count;
if (index < 0)
index += list.Count;

Selected.Value = list[index];
}

[Input(Guid = "8d5e77a6-1ec4-4979-ad26-f7862049bce1")]
Expand Down
Loading