mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-11-05 22:34:36 +00:00
50 lines
1.1 KiB
Haxe
50 lines
1.1 KiB
Haxe
package funkin.util;
|
|
|
|
#if !macro
|
|
import flixel.FlxBasic;
|
|
import flixel.util.FlxSort;
|
|
#end
|
|
import funkin.play.notes.NoteSprite;
|
|
|
|
class SortUtil
|
|
{
|
|
/**
|
|
* You can use this function in FlxTypedGroup.sort() to sort FlxObjects by their z-index values.
|
|
* The value defaults to 0, but by assigning it you can easily rearrange objects as desired.
|
|
*/
|
|
public static inline function byZIndex(Order:Int, Obj1:FlxBasic, Obj2:FlxBasic):Int
|
|
{
|
|
if (Obj1 == null || Obj2 == null) return 0;
|
|
return FlxSort.byValues(Order, Obj1.zIndex, Obj2.zIndex);
|
|
}
|
|
|
|
/**
|
|
* Given two Notes, returns 1 or -1 based on whether `a` or `b` has an earlier strumtime.
|
|
*
|
|
* @param order Either `FlxSort.ASCENDING` or `FlxSort.DESCENDING`
|
|
*/
|
|
public static inline function byStrumtime(order:Int, a:NoteSprite, b:NoteSprite)
|
|
{
|
|
return FlxSort.byValues(order, a.noteData.time, b.noteData.time);
|
|
}
|
|
|
|
public static inline function alphabetically(a:String, b:String)
|
|
{
|
|
a = a.toUpperCase();
|
|
b = b.toUpperCase();
|
|
|
|
if (a < b)
|
|
{
|
|
return -1;
|
|
}
|
|
else if (a > b)
|
|
{
|
|
return 1;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|