Codename LogoCodename Logo

funkin.backend.utils.CoolUtil

APIWikiTools

Various utilities, that have no specific Util class.

Static methods

View on GitHub

staticinlineaddEndZeros(str:String, num:Int):String

Add several zeros at the end of a string, so that 2 becomes 20, useful for ms.

Parameters:

str

String to add zeros

num

The length required

View on GitHub

@:noUsingstaticaddMissingFolders(path:String):String

Creates eventual missing folders to the specified path

WARNING: eventual files in path will be considered as folders! Just to make possible folders be named as songs.json for example

Parameters:

path

Path to check.

Returns:

The initial Path.

View on GitHub

staticinlineaddZeros(str:String, num:Int):String

Add several zeros at the beginning of a string, so that 2 becomes 02.

Parameters:

str

String to add zeros

num

The length required

View on GitHub

staticautoSetFormat(text:FlxText, formats:Array<TextFormat>):FlxText

Sets automatically all the compatible formats to a text.

WARNING: These are dependant from the font, so if the font doesn't support for example the bold format it won't work!

Parameters:

text

Text to set the format for

formats

Array of the formats (to get the formats from a node, you can use XMLUtil.getTextFormats(node))

View on GitHub

@:has_untypedstaticinlineboolToInt(b:Bool):Int

View on GitHub

@:has_untypedstaticinlinebound(Value:Float, Min:Float, Max:Float):Float

View on GitHub

@:has_untypedstaticinlineboundInt(Value:Int, Min:Int, Max:Int):Int

View on GitHub

staticinlinebrowsePath(path:String):Void

Browse a path in the operating system's explorer

Parameters:

null

path

View on GitHub

staticinlinecameraCenter(obj:FlxObject, cam:FlxCamera, axes:FlxAxes = XY):Void

Centers an object in a camera's field, basically screenCenter() but camera.width and camera.height are used instead of FlxG.width and FlxG.height.

Parameters:

obj

Sprite to center

cam

Camera

axes

Axes (XY)

View on GitHub

staticinlineclear<T>(array:Array<T>):Array<T>

Clears the content of an array

View on GitHub

staticcloneProperty(toTarget:Dynamic, fields:OneOfTwo<String, Array<OneOfTwo<String, Int>>>, fromTarget:Dynamic):Dynamic

View on GitHub

@:noUsingstaticcoolTextFile(path:String):Array<String>

Allows you to split a text file from a path, into a "cool text file", AKA a list. Allows for comments. For example, # comment test1 test2 will return ["test1", "test2"]

Parameters:

path

Returns:

Array

View on GitHub

staticinlinecopyColorTransform(color1:ColorTransform, color2:ColorTransform):Void

Copies a color transform from color1 to color2

Parameters:

color1

Color transform to copy to

color2

Color transform to copy from

View on GitHub

staticdeepEqual<T>(a:T, b:T):Bool

View on GitHub

staticdeepFlatten(arr:Array<Dynamic>, ?result:Array<Dynamic>):Array<Dynamic>

Deep flattens an array. Example: deepFlatten([1, [2, 3], 4]) will return [1, 2, 3, 4]

Parameters:

arr

Array to flatten

result

Result array

View on GitHub

@:noUsingstaticdeleteFolder(delete:String):Void

Deletes a folder recursively

Parameters:

delete

Path to the folder.

View on GitHub

staticinlinefirst<T>(array:Array<T>):T

Returns the first element of an Array

Parameters:

array

Array

Returns:

T Last element

View on GitHub

staticinlinefloorInt(e:Float):Int

Equivalent of Math.floor, except doesn't require a Int -> Float -> Int conversion.

Parameters:

e

Value to get the floor of.

View on GitHub

@:noUsingstaticinlineflxeaseFromString(mainEase:String, ?suffix:String):Null<EaseFunction>

Gets the FlxEase from a string.

Parameters:

mainEase

Main ease

suffix

Suffix (Ignored if mainEase is linear)

View on GitHub

staticformatNumberRange(numbers:Array<Int>, separator:String = ","):String

Converts an array of numbers into a string of ranges. Example: [1,2,3,5,7,8,9,8,7,6,5] -> "1..3,5,7..9,8..5"

Parameters:

numbers

Array of numbers

separator

Separator between ranges

Returns:

String representing the ranges

View on GitHub

@:noUsingstaticinlinefpsLerp(v1:Float, v2:Float, ratio:Float):Float

Alternative linear interpolation function for each frame use, without worrying about framerate changes.

Parameters:

v1

Begin value

v2

End value

ratio

Ratio

Returns:

Float Final value

View on GitHub

staticgetAnimsListFromAtlas(atlas:AnimAtlas):Array<String>

View on GitHub

staticgetAnimsListFromFrames(frames:FlxFramesCollection, ?ext:String):Array<String>

View on GitHub

staticinlinegetAtt(xml:Access, name:String):Null<Null<String>>

Gets an XML attribute from an Access abstract, without throwing an exception if invalid. Example: xml.getAtt("test").getDefault("Hello, World!");

Parameters:

xml

XML to get the attribute from

name

Name of the attribute

View on GitHub

@:noUsingstaticgetClosestAngle(angle:Float, targetAngle:Float):Float

View on GitHub

staticgetColorFromDynamic(c:Dynamic):Null<FlxColor>

Tries to get a color from a Dynamic variable.

Parameters:

c

Dynamic color.

Returns:

The result color, or null if invalid.

View on GitHub

staticinlinegetDefault<T>(v:Null<T>, defaultValue:T):T

View on GitHub

staticinlinegetDefaultFloat(v:Float, defaultValue:Float):Float

For use when using Std.parseFloat, if not using that then use getDefault.

Parameters:

v

The value

defaultValue

The default value

Returns:

The return value

View on GitHub

@:noUsingstaticinlinegetFPSRatio(ratio:Float, ?delta:Float):Float

Modifies a lerp ratio based on current FPS to keep a stable speed on higher framerate.

Parameters:

ratio

Ratio

delta

Delta/Elapsed for the fps-modified ratio (Optional)

Returns:

FPS-Modified Ratio

View on GitHub

@:noUsingstaticinlinegetFilename(file:String):String

View on GitHub

staticgetLastExceptionStack():String

Gets the last exception stack. Useful for debugging.

View on GitHub

staticgetLuminance(color:FlxColor):Float

Gets the luminance of the given color

Parameters:

color

Color to use

Returns:

Number between 0 and 1

View on GitHub

@:noUsingstaticinlinegetMacroAbstractClass(className:String):Class<Dynamic>

Gets the macro class created by hscript-improved for an abstract / enum

View on GitHub

staticgetSizeString(size:Float):String

Returns a string representation of a size, following this format: 1.02 GB, 134.00 MB

Parameters:

size

Size to convert to string

Returns:

String Result string representation

View on GitHub

staticgetSizeString64(size:Float64):String

Returns a string representation of a size, following this format: 1.02 GB, 134.00 MB, using Float64 on cpp targets

Parameters:

size

Size to convert to string

Returns:

String Result string representation

View on GitHub

staticimageHasFrameData(path:String):String

! REQUIRES FULL PATH!!!

Parameters:

path

Returns:

Bool

View on GitHub

staticinlineindexOfFromLast<T>(array:Array<T>, element:T):Int

Basically indexOf, but starts from the end.

Parameters:

array

Array to scan

element

Element

Returns:

Index, or -1 if unsuccessful.

View on GitHub

staticinlineisMapEmpty<K, V>(map:Map<K, V>):Bool

View on GitHub

staticinlineisNaN(v:Dynamic):Bool

Whenever a value is NaN or not.

Parameters:

v

Value

View on GitHub

staticinlineisNotNull(v:Null<Dynamic>):Bool

View on GitHub

staticinlinekeyToString(key:Null<FlxKey>):String

Returns a simple string representation of a FlxKey. Used in Controls options.

Parameters:

key

Key

Returns:

Simple representation

View on GitHub

staticinlinelast<T>(array:Array<T>):T

Returns the last element of an Array

Parameters:

array

Array

Returns:

T Last element

View on GitHub

@:noUsingstaticinlinelerpColor(color1:FlxColor, color2:FlxColor, ratio:Float, fpsSensitive:Bool = false):FlxColor

Lerps from color1 into color2 (Shortcut to FlxColor.interpolate)

Parameters:

color1

Color 1

color2

Color 2

ratio

Ratio

fpsSensitive

Whenever the ratio should be fps sensitive (adapted when game is running at 120 instead of 60)

View on GitHub

staticloadAnimatedGraphic(spr:FlxSprite, path:String, fps:Float = 24.0):FlxSprite

Loads an animated graphic, and automatically animates it.

Parameters:

spr

Sprite to load the graphic for

path

Path to the graphic

View on GitHub

staticloadFramesFromData(data:String, ?ext:String):FlxFramesCollection

View on GitHub

@:noUsingstaticinlinemaxInt(p1:Int, p2:Int):Int

Equivalent of Math.max, except doesn't require a Int -> Float -> Int conversion.

Parameters:

p1
p2

Returns:

return p1 < p2 ? p2 : p1

View on GitHub

@:noUsingstaticinlineminInt(p1:Int, p2:Int):Int

Equivalent of Math.min, except doesn't require a Int -> Float -> Int conversion.

Parameters:

p1
p2

Returns:

return p1 > p2 ? p2 : p1

View on GitHub

@:has_untyped@:noUsingstaticinlinenumberArray(max:Int, min:Int = 0):Array<Int>

Returns an array of number from min to max. Equivalent of [for (i in min...max) i].

Parameters:

max

Max value

min

Minimal value (0)

Returns:

Array Final array

View on GitHub

@:noUsingstaticinlinenumberArrayOld(max:Int, min:Int = 0):Array<Int>

View on GitHub

@:noUsingstaticinlineopenURL(url:String):Void

Opens an URL in the browser.

Parameters:

null

url

View on GitHub

staticparseJson(assetPath:String):Dynamic

Shortcut to parse JSON from an Asset path

Parameters:

assetPath

Path to the JSON asset.

View on GitHub

staticinlineparseJsonString(str:String):Dynamic

Shortcut to parse a JSON string

Parameters:

str

Path to the JSON string

Returns:

Parsed JSON

View on GitHub

staticparseNumberRange(input:String):Array<Int>

Converts a string of "1..3,5,7..9,8..5" into an array of numbers like [1,2,3,5,7,8,9,8,7,6,5]

Parameters:

input

String to parse

Returns:

Array of numbers

View on GitHub

staticparseProperty(target:Dynamic, fields:OneOfTwo<String, Array<OneOfTwo<String, Int>>>):Dynamic

View on GitHub

staticinlineparsePropertyString(fieldPath:String):Array<OneOfTwo<String, Int>>

View on GitHub

@:noUsingstaticinlineplayMenuSFX(menuSFX:CoolSfx = SCROLL, volume:Float = 1):FlxSound

Plays a specified Menu SFX.

Parameters:

menuSFX

Menu SFX to play

volume

At which volume it should play

View on GitHub

@:noUsingstaticplayMenuSong(fadeIn:Bool = false):Void

Plays the main menu theme.

Parameters:

null

fadeIn

View on GitHub

@:noUsingstaticplayMusic(path:String, Persist:Bool = false, Volume:Float = 1, Looped:Bool = true, DefaultBPM:Float = 102, ?Group:FlxSoundGroup):Void

Plays music, while resetting the Conductor, and taking info from INI in count.

Parameters:

path

Path to the music

Persist

Whenever the music should persist while switching states

DefaultBPM

Default BPM of the music (102)

Volume

Volume of the music (1)

Looped

Whenever the music loops (true)

Group

A group that this music belongs to (default)

View on GitHub

staticpointToScreenPosition(object:FlxPoint, ?camera:FlxCamera, ?result:FlxPoint):Null<FlxPoint>

Returns the screen position of an point, while taking the camera zoom into account.

Parameters:

object

Any FlxObject

camera

The desired "screen" coordinate space. If null, FlxG.camera is used.

result

Optional arg for the returning point

Returns:

The screen position of the object.

View on GitHub

staticinlinepositiveModulo(dividend:Float, divisor:Float):Float

Applies the % operator, but without any negatives.

Parameters:

dividend

The intial value. The left side of the equation.

divisor

What to modulo by. The right side of the equation.

Returns:

A positive reminder of dividend / divisor.

View on GitHub

staticinlinepositiveModuloInt(dividend:Int, divisor:Int):Int

Applies the % operator, but without any negatives. But it's an int.

Parameters:

dividend

The intial value. The left side of the equation.

divisor

What to modulo by. The right side of the equation.

Returns:

A positive reminder of dividend / divisor.

View on GitHub

@:noUsingstaticpreloadCharacter(name:String, ?spriteName:String):Void

Preloads a character.

Parameters:

name

Character name

spriteName

(Optional) sprite name.

View on GitHub

staticinlinepushGroup<T>(array:Array<T>, args:Rest<T>):Array<T>

Push an entire group into an array.

Parameters:

array

Array to push the group into

...args

Group entries

Returns:

Array

View on GitHub

staticinlinepushOnce<T>(array:Array<T>, element:T):Void

Pushes an element to an array, but only if it doesn't already exist.

Parameters:

array

Array to push to

element

Element to push

View on GitHub

@:noUsingstaticinlinequantize(Value:Float, Quant:Float):Float

Quantizes a value to a certain amount. Example: quantize(2.5543, 1) will return 2.0 Example: quantize(2.5543, 10) will return 2.5 Example: quantize(2.5543, 100) will return 2.55

Parameters:

Value

Value to quantize

Quant

Quantization amount

View on GitHub

staticremoveBOM(str:String):String

View on GitHub

staticinlineremoveIP(msg:String):String

Replaces in a string any kind of IP with [Your IP] making the string safer to trace.

Parameters:

msg

String to check and edit

Returns:

String Result without any kind of IP

View on GitHub

staticinlinerepeat(str:String, times:Int):String

View on GitHub

staticinlinereplay(sound:FlxSound):Void

Stops a sound, set its time to 0 then play it again.

Parameters:

sound

Sound to replay.

View on GitHub

staticresetSprite(spr:FlxSprite, x:Float, y:Float):Void

Resets an FlxSprite

Parameters:

spr

Sprite to reset

x

New X position

y

New Y position

View on GitHub

@:noUsingstaticinlinesafeAddAttributes(path:String, attrib:OneOfTwo<FileAttribute, Int>, useAbsolute:Bool = true):Int

Adds one (or more) file attributes to a file or a folder adding eventual missing folders in the path (WARNING: Only works on windows for now. On other platforms the return code it's always going to be 0 but still creates eventual missing folders if the platforms allows it to).

Parameters:

path

Path to the file or folder

attrib

The attribute(s) to add (WARNING: There are some non settable attributes, such as the COMPRESSED one)

useAbsolute

If it should use the absolute path (By default it's true but if it's false you can use files outside from this program's directory for example)

Returns:

The result code: 0 means that it failed setting

View on GitHub

@:noUsingstaticinlinesafeGetAttributes(path:String, useAbsolute:Bool = true):FileAttributeWrapper

Gets file attributes from a file or a folder adding eventual missing folders in the path (WARNING: Only works on windows for now. On other platforms the attributes' value it's always going to be 0 -thanks to the wrapper you can also use isNothing for checking- but still creates eventual missing folders if the platforms allows it to).

Parameters:

path

Path to the file or folder

useAbsolute

If it should use the absolute path (By default it's true but if it's false you can use files outside from this program's directory for example)

Returns:

The attributes through the FileAttributeWrapper

View on GitHub

@:noUsingstaticinlinesafeRemoveAttributes(path:String, attrib:OneOfTwo<FileAttribute, Int>, useAbsolute:Bool = true):Int

Removes one (or more) file attributes to a file or a folder adding eventual missing folders in the path (WARNING: Only works on windows for now. On other platforms the return code it's always going to be 0 but still creates eventual missing folders if the platforms allows it to).

Parameters:

path

Path to the file or folder

attrib

The attribute(s) to remove (WARNING: There are some non settable attributes, such as the COMPRESSED one)

useAbsolute

If it should use the absolute path (By default it's true but if it's false you can use files outside from this program's directory for example)

Returns:

The result code: 0 means that it failed setting

View on GitHub

@:noUsingstaticsafeSaveFile(path:String, content:OneOfTwo<String, Bytes>, showErrorBox:Bool = true):Void

Safe saves a file (even adding eventual missing folders) and shows a warning box instead of making the program crash

Parameters:

path

Path to save the file at.

content

Content of the file to save (as String or Bytes).

View on GitHub

@:noUsingstaticinlinesafeSetAttributes(path:String, attrib:OneOfThree<FileAttribute, FileAttributeWrapper, Int>, useAbsolute:Bool = true):Int

Sets file attributes to a file or a folder adding eventual missing folders in the path (WARNING: Only works on windows for now. On other platforms the return code it's always going to be 0 but still creates eventual missing folders if the platforms allows it to).

Parameters:

path

Path to the file or folder

attrib

The attribute(s) to set (WARNING: There are some non settable attributes, such as the COMPRESSED one)

useAbsolute

If it should use the absolute path (By default it's true but if it's false you can use files outside from this program's directory for example)

Returns:

The result code: 0 means that it failed setting

View on GitHub

staticsetFieldDefault<T>(v:Dynamic, name:String, defaultValue:T):T

Sets a field's default value, and returns it. In case it already exists, returns the existing one.

Parameters:

v

Dynamic to set the default value to

name

Name of the value

defaultValue

Default value

Returns:

T New/old value.

View on GitHub

staticsetGraphicSizeFloat(sprite:FlxSprite, Width:Float = 0, Height:Float = 0):Void

View on GitHub

staticinlinesetMusic(frontEnd:SoundFrontEnd, music:FlxSound):Void

Sets a SoundFrontEnd's music to a FlxSound. Example: FlxG.sound.setMusic(music);

Parameters:

frontEnd

SoundFrontEnd to set the music of

music

Music

View on GitHub

staticinlinesetSpriteSize(sprite:FlxSprite, width:Float, height:Float):Void

Equivalent of setGraphicSize, except that it can accept floats and automatically updates the hitbox.

Parameters:

sprite

Sprite to set the size of

width

Width

height

Height

View on GitHub

staticinlinesetUnstretchedGraphicSize(sprite:FlxSprite, width:Int, height:Int, fill:Bool = true, maxScale:Float = 0):Void

Allows you to set a graphic size (ex: 150x150), with proper hitbox without a stretched sprite.

Parameters:

sprite

Sprite to apply the new graphic size to

width

Width

height

Height

fill

Whenever the sprite should fill instead of shrinking (true)

maxScale

Maximum scale (0 / none)

View on GitHub

staticsortAlphabetically(array:Array<String>, lowercase:Bool = false):Array<String>

Sorts an array alphabetically.

Parameters:

array

Array to sort

lowercase

Whenever the array should be sorted in lowercase

View on GitHub

staticstringifyFieldsPath(fields:Array<OneOfTwo<String, Int>>):String

View on GitHub

@:noUsingstaticswitchAnimFrames(anim1:FlxAnimation, anim2:FlxAnimation):Void

Switches frames from 2 FlxAnimations.

Parameters:

anim1

First animation

anim2

Second animation

View on GitHub

staticinlinetimeToStr(time:Float):String

Converts a timestamp to a readable format such as 01:22 (mm:ss)

View on GitHub

staticworldToScreenPosition(object:FlxObject, ?camera:FlxCamera, ?result:FlxPoint):Null<FlxPoint>

Returns the screen position of an object, while taking the camera zoom into account.

Parameters:

object

Any FlxObject

camera

The desired "screen" coordinate space. If null, FlxG.camera is used.

result

Optional arg for the returning point

Returns:

The screen position of the object.