From 121fc131538c27fdf6bc582de12cbede349154b1 Mon Sep 17 00:00:00 2001
From: EliteMasterEric <ericmyllyoja@gmail.com>
Date: Tue, 30 May 2023 16:21:24 -0400
Subject: [PATCH] Added some utility functions

---
 source/funkin/util/SerializerUtil.hx   |  9 +++++++++
 source/funkin/util/tools/ArrayTools.hx | 25 +++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 source/funkin/util/tools/ArrayTools.hx

diff --git a/source/funkin/util/SerializerUtil.hx b/source/funkin/util/SerializerUtil.hx
index dae3327c6..3b77a04e5 100644
--- a/source/funkin/util/SerializerUtil.hx
+++ b/source/funkin/util/SerializerUtil.hx
@@ -1,6 +1,7 @@
 package funkin.util;
 
 import haxe.Json;
+import haxe.io.Bytes;
 import thx.semver.Version;
 
 typedef ScoreInput =
@@ -38,6 +39,14 @@ class SerializerUtil
     return Json.parse(input);
   }
 
+  /**
+   * Convert a JSON byte array to a Haxe object.
+   */
+  public static function fromJSONBytes(input:Bytes):Dynamic
+  {
+    return Json.parse(input.toString());
+  }
+
   /**
    * Customize how certain types are serialized when converting to JSON.
    */
diff --git a/source/funkin/util/tools/ArrayTools.hx b/source/funkin/util/tools/ArrayTools.hx
new file mode 100644
index 000000000..02671a8e8
--- /dev/null
+++ b/source/funkin/util/tools/ArrayTools.hx
@@ -0,0 +1,25 @@
+package funkin.util.tools;
+
+/**
+ * A static extension which provides utility functions for Arrays.
+ */
+class ArrayTools
+{
+  /**
+   * Returns a copy of the array with all duplicate elements removed.
+   * @param array The array to remove duplicates from.
+   * @return A copy of the array with all duplicate elements removed.
+   */
+  public static function unique<T>(array:Array<T>):Array<T>
+  {
+    var result:Array<T> = [];
+    for (element in array)
+    {
+      if (!result.contains(element))
+      {
+        result.push(element);
+      }
+    }
+    return result;
+  }
+}