Skip to content

Commit

Permalink
use FlxStringUtil.formatBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vortex2Oblivion committed Sep 11, 2024
1 parent e719cd7 commit e03b46c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 96 deletions.
46 changes: 22 additions & 24 deletions build/install_libraries.bat
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
@echo off
echo Installing all required libraries.

@echo on
haxelib install lime
haxelib install openfl
haxelib git flixel https://github.com/HaxeFlixel/flixel
haxelib install flixel-tools
haxelib git flixel-ui https://github.com/HaxeFlixel/flixel-ui
haxelib git flixel-addons https://github.com/HaxeFlixel/flixel-addons
haxelib git linc_luajit https://github.com/Leather128/linc_luajit.git
haxelib git hscript-improved https://github.com/FNF-CNE-Devs/hscript-improved codename-dev
haxelib git scriptless-polymod https://github.com/Vortex2Oblivion/scriptless-polymod
haxelib git hxNoise https://github.com/whuop/hxNoise
haxelib install hxvlc
haxelib git discord_rpc https://github.com/Aidan63/linc_discord-rpc
haxelib git fnf-modcharting-tools https://github.com/Vortex2Oblivion/FNF-Modcharting-Tools
haxelib git flxanimate https://github.com/Vortex2Oblivion/flxanimate
haxelib git thx.core https://github.com/fponticelli/thx.core
haxelib git thx.semver https://github.com/fponticelli/thx.semver.git
haxelib git jsonpath https://github.com/EliteMasterEric/jsonpath
haxelib git jsonpatch https://github.com/EliteMasterEric/jsonpatch
haxelib git funkin.vis https://github.com/FunkinCrew/funkVis
haxelib git grig.audio https://gitlab.com/haxe-grig/grig.audio
haxelib git hxcpp https://github.com/HaxeFoundation/hxcpp
haxelib install hxcpp-debug-server
haxelib --never install lime
haxelib --never install openfl
haxelib --never git flixel https://github.com/HaxeFlixel/flixel
haxelib --never install flixel-tools
haxelib --never git flixel-ui https://github.com/HaxeFlixel/flixel-ui
haxelib --never git flixel-addons https://github.com/HaxeFlixel/flixel-addons
haxelib --never git linc_luajit https://github.com/Leather128/linc_luajit.git
haxelib --never git hscript-improved https://github.com/FNF-CNE-Devs/hscript-improved codename-dev
haxelib --never git scriptless-polymod https://github.com/Vortex2Oblivion/scriptless-polymod
haxelib --never git hxNoise https://github.com/whuop/hxNoise
haxelib --never install hxvlc
haxelib --never git discord_rpc https://github.com/Aidan63/linc_discord-rpc
haxelib --never git fnf-modcharting-tools https://github.com/Vortex2Oblivion/FNF-Modcharting-Tools
haxelib --never git flxanimate https://github.com/Vortex2Oblivion/flxanimate
haxelib --never git thx.core https://github.com/fponticelli/thx.core
haxelib --never git thx.semver https://github.com/fponticelli/thx.semver.git
haxelib --never git jsonpath https://github.com/EliteMasterEric/jsonpath
haxelib --never git jsonpatch https://github.com/EliteMasterEric/jsonpatch
haxelib --never git funkin.vis https://github.com/FunkinCrew/funkVis
haxelib --never git grig.audio https://gitlab.com/haxe-grig/grig.audio
haxelib --never git hxcpp https://github.com/HaxeFoundation/hxcpp
haxelib --never install hxcpp-debug-server

@echo off
echo Finished
4 changes: 2 additions & 2 deletions source/substates/ResultsSubstate.hx
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,11 @@ class ResultsSubstate extends MusicBeatSubstate {
}
});

new FlxTimer().start(rank.getBFDelay(), _ -> {
new FlxTimer().start(rank.getBFDelay() ?? 1, _ -> {
afterRankTallySequence();
});

new FlxTimer().start(rank.getFlashDelay(), _ -> {
new FlxTimer().start(rank.getFlashDelay() ?? 1, _ -> {
displayRankText();
});

Expand Down
33 changes: 17 additions & 16 deletions source/ui/SimpleInfoDisplay.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ui;

import flixel.util.FlxStringUtil;
import flixel.FlxG;
import openfl.utils.Assets;
import openfl.text.TextField;
Expand All @@ -14,9 +15,10 @@ class SimpleInfoDisplay extends TextField {
public var infoDisplayed:Array<Bool> = [false, false, false, false];

public var framerate:Int = 0;

private var framerateTimer:Float = 0.0;
private var framesCounted:Int = 0;
private var framesCounted:Int = 0;

public var version:String = CoolUtil.getCurrentVersion();

public function new(x:Float = 10.0, y:Float = 10.0, color:Int = 0x000000, ?font:String) {
Expand All @@ -25,42 +27,41 @@ class SimpleInfoDisplay extends TextField {
this.x = x;
this.y = y;
selectable = false;
defaultTextFormat = new TextFormat(font != null ? font : Assets.getFont(Paths.font("vcr.ttf")).fontName, (font == "_sans" ? 12 : 14),
color);
defaultTextFormat = new TextFormat(font ?? Assets.getFont(Paths.font("vcr.ttf")).fontName, (font == "_sans" ? 12 : 14), color);

FlxG.signals.postDraw.add(update);
FlxG.signals.postDraw.add(update);

width = FlxG.width;
height = FlxG.height;
}

private function update():Void {
framerateTimer += FlxG.elapsed;
if (framerateTimer >= 1) {

if (framerateTimer >= 1) {
framerateTimer = 0;
framerate = framesCounted;
framesCounted = 0;
}

framerate = framesCounted;
framesCounted = 0;
}

framesCounted++;

if (!visible) {
return;
}

text = '';
for (i in 0...infoDisplayed.length) {
if (!infoDisplayed[i]) {
continue;
}

switch (i) {
case 0: // FPS
text += '${framerate}fps';
case 1: // Memory
text += '${CoolUtil.formatBytes(Memory.getCurrentUsage())} / ${CoolUtil.formatBytes(Memory.getPeakUsage())}';
text += '${FlxStringUtil.formatBytes(Memory.getCurrentUsage())} / ${FlxStringUtil.formatBytes(Memory.getPeakUsage())}';
case 2: // Version
text += version;
case 3: // Console
Expand Down
56 changes: 2 additions & 54 deletions source/utilities/CoolUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import lime.utils.Assets;
import openfl.utils.Function;
import states.PlayState;
import ui.logs.Logs;

using StringTools;
import haxe.Json;

/**
* Helper class with lots of utilitiy functions.
Expand Down Expand Up @@ -368,57 +367,6 @@ class CoolUtil {
**/
public static var haxe_trace:Function;

/**
* List of formatting for different byte amounts
* in an array formatted like this:
*
* [`Format`, `Divisor`]
*/
public static var byte_formats:Array<Array<Dynamic>> = [
["$bytes b", 1.0],
["$bytes kib", 1024.0],
["$bytes mib", 1048576.0],
["$bytes gib", 1073741824.0],
["$bytes tib", 1099511627776.0]
];

/**
* Formats `bytes` into a `String`.
*
* Examples (Input = Output)
*
* ```
* 1024 = '1 kib'
* 1536 = '1.5 kib'
* 1048576 = '2 mib'
* ```
*
* @param bytes Amount of bytes to format and return.
* @param onlyValue (Optional, Default = `false`) Whether or not to only format the value of bytes (ex: `'1.5 mib' -> '1.5'`).
* @param precision (Optional, Default = `2`) The precision of the decimal value of bytes. (ex: `1 -> 1.5, 2 -> 1.53, etc`).
* @return Formatted byte string.
*/
public static function formatBytes(bytes:Float, onlyValue:Bool = false, precision:Int = 2):String {
var formatted_bytes:String = "?";

for (i in 0...byte_formats.length) {
// If the next byte format has a divisor smaller than the current amount of bytes,
// and thus not the right format skip it.
if (byte_formats.length > i + 1 && byte_formats[i + 1][1] < bytes)
continue;

var format:Array<Dynamic> = byte_formats[i];

if (!onlyValue)
formatted_bytes = StringTools.replace(format[0], "$bytes", Std.string(FlxMath.roundDecimal(bytes / format[1], precision)));
else
formatted_bytes = Std.string(FlxMath.roundDecimal(bytes / format[1], precision));

break;
}

return formatted_bytes;
}

public static inline function getCurrentVersion():String {
return 'v' + Application.current.meta.get('version');
Expand All @@ -441,7 +389,7 @@ class CoolUtil {
return exists;
}

var meta:FNFCMetadata = cast haxe.Json.parse(Assets.getText(Paths.json('$songPath/$song-metadata$difficultyExtensionMeta')));
var meta:FNFCMetadata = cast Json.parse(Assets.getText(Paths.json('$songPath/$song-metadata$difficultyExtensionMeta')));
if (meta.playData.difficulties.contains(difficulty)) {
exists = true;
}
Expand Down

0 comments on commit e03b46c

Please sign in to comment.