diff --git a/OpenBullet/Pages/StackerBlocks/PageBlockUtility.xaml b/OpenBullet/Pages/StackerBlocks/PageBlockUtility.xaml
index d1b03c4..dc13af1 100644
--- a/OpenBullet/Pages/StackerBlocks/PageBlockUtility.xaml
+++ b/OpenBullet/Pages/StackerBlocks/PageBlockUtility.xaml
@@ -70,6 +70,12 @@
+
+
+
+
+
+
diff --git a/OpenBullet/Pages/StackerBlocks/PageBlockUtility.xaml.cs b/OpenBullet/Pages/StackerBlocks/PageBlockUtility.xaml.cs
index 43e8ba1..7673a53 100644
--- a/OpenBullet/Pages/StackerBlocks/PageBlockUtility.xaml.cs
+++ b/OpenBullet/Pages/StackerBlocks/PageBlockUtility.xaml.cs
@@ -90,21 +90,25 @@ namespace OpenBullet.Pages.StackerBlocks
listActionTabControl.SelectedIndex = 1;
break;
+ case ListAction.Sort:
+ listActionTabControl.SelectedIndex = 2;
+ break;
+
case ListAction.Zip:
- listActionTabControl.SelectedIndex = 2;
- break;
-
- case ListAction.Map:
- listActionTabControl.SelectedIndex = 2;
- break;
-
- case ListAction.Add:
listActionTabControl.SelectedIndex = 3;
break;
- case ListAction.Remove:
+ case ListAction.Map:
+ listActionTabControl.SelectedIndex = 3;
+ break;
+
+ case ListAction.Add:
listActionTabControl.SelectedIndex = 4;
break;
+
+ case ListAction.Remove:
+ listActionTabControl.SelectedIndex = 5;
+ break;
}
}
diff --git a/RuriLib/Blocks/BlockUtility.cs b/RuriLib/Blocks/BlockUtility.cs
index 4d09630..a7156fe 100644
--- a/RuriLib/Blocks/BlockUtility.cs
+++ b/RuriLib/Blocks/BlockUtility.cs
@@ -3,6 +3,7 @@ using RuriLib.Models;
using RuriLib.ViewModels;
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
@@ -52,6 +53,9 @@ namespace RuriLib
/// Joins a list into a single string, separating the elements with a separator.
Join,
+ /// Sorts a list alphabetically, in ascending or descending order.
+ Sort,
+
/// Concatenates two lists into a longer list variable.
Concat,
@@ -146,6 +150,14 @@ namespace RuriLib
/// The separator for joining a list.
public string Separator { get { return separator; } set { separator = value; OnPropertyChanged(); } }
+ private bool ascending = true;
+ /// Whether the sort should happen in ascending order.
+ public bool Ascending { get { return ascending; } set { ascending = value; OnPropertyChanged(); } }
+
+ private bool numeric = false;
+ /// Whether a list is made of numeric values.
+ public bool Numeric { get { return numeric; } set { numeric = value; OnPropertyChanged(); } }
+
private string secondListName = ""; // Zip
/// The name of the second list variable.
public string SecondListName { get { return secondListName; } set { secondListName = value; OnPropertyChanged(); } }
@@ -227,6 +239,11 @@ namespace RuriLib
Separator = LineParser.ParseLiteral(ref input, "Separator");
break;
+ case ListAction.Sort:
+ while (LineParser.Lookahead(ref input) == TokenType.Boolean)
+ LineParser.SetBool(ref input, this);
+ break;
+
case ListAction.Concat:
case ListAction.Zip:
case ListAction.Map:
@@ -321,6 +338,12 @@ namespace RuriLib
.Literal(Separator);
break;
+ case ListAction.Sort:
+ writer
+ .Boolean(Ascending, "Ascending")
+ .Boolean(Numeric, "Numeric");
+ break;
+
case ListAction.Concat:
case ListAction.Zip:
case ListAction.Map:
@@ -420,6 +443,22 @@ namespace RuriLib
data.Variables.Set(new CVar(variableName, string.Join(separator, list), isCapture));
break;
+ case ListAction.Sort:
+ var sorted = list.Select(e => e).ToList(); // Clone the list so we don't edit the original one
+ if (Numeric)
+ {
+ var nums = sorted.Select(e => double.Parse(e, CultureInfo.InvariantCulture)).ToList();
+ nums.Sort();
+ sorted = nums.Select(e => e.ToString()).ToList();
+ }
+ else
+ {
+ sorted.Sort();
+ }
+ if (!Ascending) sorted.Reverse();
+ data.Variables.Set(new CVar(variableName, sorted, isCapture));
+ break;
+
case ListAction.Concat:
data.Variables.Set(new CVar(variableName, list.Concat(list2).ToList(), isCapture));
break;