Skip to content

Commit

Permalink
primitive song timer
Browse files Browse the repository at this point in the history
  • Loading branch information
x8c8r committed Jul 5, 2024
1 parent af27b54 commit 6b8f9e4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
Empty file removed source/BeatBattle.hx
Empty file.
12 changes: 12 additions & 0 deletions source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ class PlayState extends MusicBeatState
"exe" => 1
];

var songTimer:SongTimer;

#if desktop
// Discord RPC variables
var iconRPC:String = "";
Expand Down Expand Up @@ -954,6 +956,10 @@ class PlayState extends MusicBeatState
iconP2.y = healthBar.y - (iconP2.height / 2);
add(iconP2);

songTimer = new SongTimer(0);
songTimer.cameras = [camHUD];
add(songTimer);

strumLineNotes.cameras = [camHUD];
notes.cameras = [camHUD];
healthBar.cameras = [camHUD];
Expand Down Expand Up @@ -1265,6 +1271,9 @@ class PlayState extends MusicBeatState
// Song duration in a float, useful for the time left feature
songLength = FlxG.sound.music.length;

songTimer.endTime = Math.round(songLength/1000);
songTimer.updateDisplay();

// Updating Discord Rich Presence (with Time Left)
DiscordClient.changePresence(detailsText + " " + SONG.song, "\nAcc: " + truncateFloat(accuracy, 2) + "% | Score: " + songScore + " | Misses: " + misses , iconRPC);
#end
Expand Down Expand Up @@ -1750,6 +1759,9 @@ class PlayState extends MusicBeatState
// Conductor.lastSongPos = FlxG.sound.music.time;
}

songTimer.curTime = Math.round(Conductor.songPosition/1000);
songTimer.updateDisplay();

if (generatedMusic && PlayState.SONG.notes[Std.int(curStep / 16)] != null)
{
if (curBeat % 4 == 0)
Expand Down
50 changes: 50 additions & 0 deletions source/SongTimer.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.FlxG;
import flixel.text.FlxText;
import flixel.FlxSprite;

class SongTimer extends FlxTypedGroup<FlxText>{
public var curTime:Int;
public var endTime:Int;

private var _display:FlxText;

public function new(endTime:Int) {
super();

this.endTime = endTime;

_display = new FlxText(FlxG.width/2-100, 50);
_display.size = 32;
if (SaveManagement.getOption("Scroll Direction") == "Down")
_display.y = FlxG.height - 50;

add(_display);
}

public function getEndTimeFormatted():String {
var min = Math.floor(endTime/60);
var sec = endTime - (min*60);

var secDis = Std.string(sec);
if (sec < 10)
secDis = Std.string("0"+secDis);

return min+":"+secDis;
}

public function getCurTimeFormatted():String {
var min = Math.floor(curTime/60);
var sec = curTime - (min*60);

var secDis = Std.string(sec);
if (sec < 10)
secDis = Std.string("0"+secDis);

return min+":"+sec;
}

public function updateDisplay():Void {
_display.text = getCurTimeFormatted()+"/"+getEndTimeFormatted();
}
}

0 comments on commit 6b8f9e4

Please sign in to comment.