2022-03-08 08:13:53 +00:00
|
|
|
package funkin.util;
|
2022-01-26 19:19:57 +00:00
|
|
|
|
2022-02-23 21:49:54 +00:00
|
|
|
#if !macro
|
2022-03-11 06:30:01 +00:00
|
|
|
import flixel.FlxBasic;
|
2022-01-26 19:19:57 +00:00
|
|
|
import flixel.util.FlxSort;
|
2022-02-23 21:49:54 +00:00
|
|
|
#end
|
2023-06-22 05:41:01 +00:00
|
|
|
import funkin.play.notes.NoteSprite;
|
2022-01-26 19:19:57 +00:00
|
|
|
|
|
|
|
class SortUtil
|
|
|
|
{
|
2023-01-23 03:25:45 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2022-03-11 06:30:01 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
/**
|
|
|
|
* Given two Notes, returns 1 or -1 based on whether `a` or `b` has an earlier strumtime.
|
2023-06-08 20:30:45 +00:00
|
|
|
*
|
2023-01-23 03:25:45 +00:00
|
|
|
* @param order Either `FlxSort.ASCENDING` or `FlxSort.DESCENDING`
|
|
|
|
*/
|
2023-06-22 05:41:01 +00:00
|
|
|
public static inline function byStrumtime(order:Int, a:NoteSprite, b:NoteSprite)
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2023-06-22 05:41:01 +00:00
|
|
|
return FlxSort.byValues(order, a.noteData.time, b.noteData.time);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
2023-07-19 05:29:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort predicate for sorting strings alphabetically.
|
|
|
|
*/
|
|
|
|
public static function alphabetical(a:String, b:String):Int
|
|
|
|
{
|
|
|
|
// Sort alphabetically. Yes that's how this works.
|
|
|
|
return a > b ? 1 : -1;
|
|
|
|
}
|
2022-01-26 19:19:57 +00:00
|
|
|
}
|