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; + } +}