mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-12-26 23:16:46 +00:00
Added some utility functions
This commit is contained in:
parent
6412cb3aee
commit
121fc13153
|
@ -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.
|
||||
*/
|
||||
|
|
25
source/funkin/util/tools/ArrayTools.hx
Normal file
25
source/funkin/util/tools/ArrayTools.hx
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue