Skip to content

Commit

Permalink
Update MusicBeatState.hx
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackx2 committed Mar 25, 2024
1 parent d2ff30e commit d17b9ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 111 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ art/test_x64-debug-officialrelease.bat

### VS Code
export/*
exportUpdater/*
.vscode/*
.haxelib/
*.code-workspace
Expand Down
117 changes: 6 additions & 111 deletions source/backend/system/MusicBeatState.hx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package backend.system;
import backend.Conductor.BPMChangeEvent;
import flixel.FlxG;
import flixel.addons.ui.FlxUIState;
import game.states.PlayState;
import flixel.math.FlxRect;
import backend.Conductor;
import flixel.util.FlxTimer;
import flixel.addons.transition.FlxTransitionableState;
import flixel.tweens.FlxEase;
Expand All @@ -13,29 +10,12 @@ import flixel.FlxSprite;
import flixel.util.FlxColor;
import flixel.util.FlxGradient;
import flixel.FlxState;
import backend.utils.Controls;
import flixel.FlxCamera;
import flixel.FlxBasic;

class MusicBeatState extends FlxUIState
{
private var curSection:Int = 0;
private var stepsToDo:Int = 0;

private var curStep:Int = 0;
private var curBeat:Int = 0;

private var curDecStep:Float = 0;
private var curDecBeat:Float = 0;
private var controls(get, never):Controls;

public static var camBeat:FlxCamera;

inline function get_controls():Controls
return PlayerSettings.player1.controls;

override function create() {
camBeat = FlxG.camera;
var skip:Bool = FlxTransitionableState.skipNextTransOut;
super.create();

Expand All @@ -47,79 +27,9 @@ class MusicBeatState extends FlxUIState

override function update(elapsed:Float)
{
//everyStep();
var oldStep:Int = curStep;

updateCurStep();
updateBeat();

if (oldStep != curStep)
{
if(curStep > 0)
stepHit();

if(PlayState.SONG != null)
{
if (oldStep < curStep)
updateSection();
else
rollbackSection();
}
}

if(FlxG.save.data != null) FlxG.save.data.fullscreen = FlxG.fullscreen;

super.update(elapsed);
}

private function updateSection():Void
{
if(stepsToDo < 1) stepsToDo = Math.round(getBeatsOnSection() * 4);
while(curStep >= stepsToDo)
{
curSection++;
var beats:Float = getBeatsOnSection();
stepsToDo += Math.round(beats * 4);
sectionHit();
}
}

private function rollbackSection():Void
{
if(curStep < 0) return;

var lastSection:Int = curSection;
curSection = 0;
stepsToDo = 0;
for (i in 0...PlayState.SONG.notes.length)
{
if (PlayState.SONG.notes[i] != null)
{
stepsToDo += Math.round(getBeatsOnSection() * 4);
if(stepsToDo > curStep) break;

curSection++;
}
}

if(curSection > lastSection) sectionHit();
}

private function updateBeat():Void
{
curBeat = Math.floor(curStep / 4);
curDecBeat = curDecStep/4;
}

private function updateCurStep():Void
{
var lastChange = Conductor.getBPMFromSeconds(Conductor.songPosition);

var shit = ((Conductor.songPosition - backend.utils.ClientPrefs.data.noteOffset) - lastChange.songTime) / lastChange.stepCrochet;
curDecStep = lastChange.stepTime + shit;
curStep = lastChange.stepTime + Math.floor(shit);
}

public static function switchState(nextState:FlxState) {
// Custom made Trans in
var curState:Dynamic = FlxG.state;
Expand Down Expand Up @@ -153,26 +63,11 @@ class MusicBeatState extends FlxUIState
return leState;
}

public function stepHit():Void
{
if (curStep % 4 == 0)
beatHit();
}

public function beatHit():Void
{
//trace('Beat: ' + curBeat);
}

//Used in twist engine
public function addBehindObject(obj:FlxBasic, obj2:FlxBasic)
return insert(members.indexOf(obj2), obj);
public function addAheadObject(obj:FlxBasic, obj2:FlxBasic)
return insert(members.indexOf(obj2) + 1, obj);

public function sectionHit():Void
{
//trace('Section: ' + curSection + ', Beat: ' + curBeat + ', Step: ' + curStep);
}

function getBeatsOnSection()
{
var val:Null<Float> = 4;
if(PlayState.SONG != null && PlayState.SONG.notes[curSection] != null) val = PlayState.SONG.notes[curSection].sectionBeats;
return val == null ? 4 : val;
}
}

0 comments on commit d17b9ce

Please sign in to comment.