Utility functions related to sorting.

NOTE: Array.sort() takes a function (x, y) -> Int. If the objects are in the correct order (x before y), return a negative value. If the objects need to be swapped (y before x), return a negative value. If the objects are equal, return 0.

NOTE: Array.sort() does NOT guarantee that the order of equal elements. haxe.ds.ArraySort.sort() does guarantee this. NOTE: Array.sort() may not be the most efficient sorting algorithm for all use cases (especially if the array is known to be mostly sorted). You may consider using one of the functions in funkin.util.tools.ArraySortTools instead. NOTE: Both sort functions modify the array in-place. You may consider using Reflect.copy() to make a copy of the array before sorting.

Static methods

staticalphabetically(a:String, b:String):Int

Sort predicate for sorting strings alphabetically.

Parameters:

a

The first string to compare.

b

The second string to compare.

Returns:

1 if a comes before b, -1 if b comes before a, 0 if they are equal

staticinlinebyFrameName(a:FlxFrame, b:FlxFrame):Int

Given two FlxFrames, sort their names alphabetically.

Parameters:

order

Either FlxSort.ASCENDING or FlxSort.DESCENDING

a

The first Frame to compare.

b

The second Frame to compare.

Returns:

1 if a has an earlier time, -1 if b has an earlier time.

staticinlinebyStrumtime(order:Int, a:NoteSprite, b:NoteSprite):Int

Given two Notes, returns 1 or -1 based on whether a or b has an earlier strumtime.

Parameters:

order

Either FlxSort.ASCENDING or FlxSort.DESCENDING

a

The first Note to compare.

b

The second Note to compare.

Returns:

1 if a has an earlier strumtime, -1 if b has an earlier strumtime.

staticinlinebyZIndex(order:Int, a:FlxBasic, b:FlxBasic):Int

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.

Parameters:

order

Either FlxSort.ASCENDING or FlxSort.DESCENDING

a

The first FlxObject to compare.

b

The second FlxObject to compare.

Returns:

1 if a has a higher z-index, -1 if b has a higher z-index.

staticdefaultThenAlphabetically(defaultValue:String, a:String, b:String):Int

Sort predicate which sorts two strings alphabetically, but prioritizes a specific string first. Example usage: array.sort(defaultThenAlphabetical.bind('test')) will sort the array so that the string 'test' is first.

Parameters:

defaultValue

The value to prioritize.

a

The first string to compare.

b

The second string to compare.

Returns:

1 if a comes before b, -1 if b comes before a, 0 if they are equal

staticdefaultsThenAlphabetically(defaultValues:Array<String>, a:String, b:String):Int

Sort predicate which sorts two strings alphabetically, but prioritizes a specific string first. Example usage: array.sort(defaultsThenAlphabetical.bind(['test'])) will sort the array so that the string 'test' is first.

Parameters:

defaultValues

The values to prioritize.

a

The first string to compare.

b

The second string to compare.

Returns:

1 if a comes before b, -1 if b comes before a, 0 if they are equal

staticinlineeventDataByTime(order:Int, a:SongEventData, b:SongEventData):Int

Given two Event Data objects, returns 1 or -1 based on whether a or b has an earlier time.

Parameters:

order

Either FlxSort.ASCENDING or FlxSort.DESCENDING

a

The first Event to compare.

b

The second Event to compare.

Returns:

1 if a has an earlier time, -1 if b has an earlier time.

staticinlinenoteDataByTime(order:Int, a:SongNoteData, b:SongNoteData):Int

Given two Note Data objects, returns 1 or -1 based on whether a or b has an earlier time.

Parameters:

order

Either FlxSort.ASCENDING or FlxSort.DESCENDING

a

The first Event to compare.

b

The second Event to compare.

Returns:

1 if a has an earlier time, -1 if b has an earlier time.