diff --git a/.gitignore b/.gitignore index e7c639a6..559100ca 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ art/test_x64-debug-officialrelease.bat ### VS Code export/* -exportUpdater/* .vscode/* .haxelib/ *.code-workspace diff --git a/source/backend/system/MusicBeatState.hx b/source/backend/system/MusicBeatState.hx index e248daac..e0945c05 100644 --- a/source/backend/system/MusicBeatState.hx +++ b/source/backend/system/MusicBeatState.hx @@ -1,7 +1,10 @@ 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; @@ -10,12 +13,29 @@ 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(); @@ -27,9 +47,79 @@ 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; @@ -63,11 +153,26 @@ class MusicBeatState extends FlxUIState return leState; } - - //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 stepHit():Void + { + if (curStep % 4 == 0) + beatHit(); + } + + public function beatHit():Void + { + //trace('Beat: ' + curBeat); + } + public function sectionHit():Void + { + //trace('Section: ' + curSection + ', Beat: ' + curBeat + ', Step: ' + curStep); + } + + function getBeatsOnSection() + { + var val:Null = 4; + if(PlayState.SONG != null && PlayState.SONG.notes[curSection] != null) val = PlayState.SONG.notes[curSection].sectionBeats; + return val == null ? 4 : val; + } }