Codename LogoCodename Logo

funkin.backend.utils.CoolUtil

APIWiki

Static methods

View in 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 in 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 in 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 in 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 in GitHub

@:value({ axes : XY })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 in GitHub

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

Clears the content of an array

View in 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 in 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 in GitHub

@:noUsingstaticdeleteFolder(delete:String):Void

Deletes a folder recursively

Parameters:

delete

Path to the folder.

View in 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 in GitHub

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

View in GitHub

@:value({ seperator : "," })staticformatNumberRange(numbers:Array<Int>, seperator: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

Returns:

String representing the ranges

View in 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 in GitHub

staticinlinegetAtt(xml:Access, name:String):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 in 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 in GitHub

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

View in GitHub

@:noUsingstaticinlinegetFPSRatio(ratio:Float):Float

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

Parameters:

ratio

Ratio

Returns:

FPS-Modified Ratio

View in GitHub

@:noUsingstaticinlinegetFilename(file:String):String

View in GitHub

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

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

View in 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 in 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 in GitHub

staticinlineisNaN(v:Dynamic):Bool

Whenever a value is NaN or not.

Parameters:

v

Value

View in GitHub

staticinlineisNotNull(v:Null<Dynamic>):Bool

View in 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 in GitHub

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

Returns the last of an Array

Parameters:

array

Array

Returns:

T Last element

View in GitHub

@:value({ fpsSensitive : false })@: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 in GitHub

staticloadAnimatedGraphic(spr:FlxSprite, path:String):FlxSprite

Loads an animated graphic, and automatically animates it.

Parameters:

spr

Sprite to load the graphic for

path

Path to the graphic

View in 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 in GitHub

@:value({ min : 0 })@: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 in GitHub

@:noUsingstaticinlineopenURL(url:String):Void

Opens an URL in the browser.

Parameters:

null

url

View in GitHub

staticparseJson(assetPath:String):Unknown

Shortcut to parse JSON from an Asset path

Parameters:

assetPath

Path to the JSON asset.

View in GitHub

staticinlineparseJsonString(str:String):Unknown

Shortcut to parse a JSON string

Parameters:

str

Path to the JSON string

Returns:

Parsed JSON

View in 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 in GitHub

@:value({ volume : 1, menuSFX : SCROLL })@:noUsingstaticinlineplayMenuSFX(menuSFX:CoolSfx = SCROLL, volume:Float = 1):Void

Plays a specified Menu SFX.

Parameters:

menuSFX

Menu SFX to play

volume

At which volume it should play

View in GitHub

@:value({ fadeIn : false })@:noUsingstaticplayMenuSong(fadeIn:Bool = false):Void

Plays the main menu theme.

Parameters:

null

fadeIn

View in GitHub

@:value({ DefaultBPM : 102, Looped : true, Volume : 1, Persist : false })@:noUsingstaticplayMusic(path:String, Persist:Bool = false, Volume:Int = 1, Looped:Bool = true, DefaultBPM:Int = 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 in GitHub

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

Preloads a character.

Parameters:

name

Character name

spriteName

(Optional) sprite name.

View in 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 in GitHub

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

View in 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 in GitHub

staticinlinereplay(sound:FlxSound):Void

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

Parameters:

sound

Sound to replay.

View in 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 in GitHub

@:value({ useAbsol : true })@:noUsingstaticinlinesafeAddAttributes(path:String, attrib:OneOfTwo<FileAttribute, Int>, useAbsol: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)

useAbsol

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 in GitHub

@:value({ useAbsol : true })@:noUsingstaticinlinesafeGetAttributes(path:String, useAbsol: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

useAbsol

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 in GitHub

@:value({ useAbsol : true })@:noUsingstaticinlinesafeRemoveAttributes(path:String, attrib:OneOfTwo<FileAttribute, Int>, useAbsol: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)

useAbsol

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 in GitHub

@:value({ showErrorBox : true })@: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 in GitHub

@:value({ useAbsol : true })@:noUsingstaticinlinesafeSetAttributes(path:String, attrib:OneOfThree<FileAttribute, FileAttributeWrapper, Int>, useAbsol: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)

useAbsol

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 in 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 in 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 in 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 in GitHub

@:value({ maxScale : 0, fill : true })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 in GitHub

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

Switches frames from 2 FlxAnimations.

Parameters:

anim1

First animation

anim2

Second animation

View in GitHub

staticinlinetimeToStr(time:Float):String

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