From 506e4bf6806cf900d2a4e35f2629b6454c4f88f0 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Thu, 15 Jun 2023 00:15:57 -0400 Subject: [PATCH] Propagate Conductor rework to dependent classes. --- source/funkin/LatencyState.hx | 28 ++--- source/funkin/MusicBeatSubState.hx | 108 ++++++++++++------ source/funkin/Note.hx | 2 +- source/funkin/play/Countdown.hx | 6 +- source/funkin/play/character/BaseCharacter.hx | 2 +- .../funkin/play/event/ZoomCameraSongEvent.hx | 11 +- source/funkin/play/song/SongData.hx | 4 +- source/funkin/play/stage/Stage.hx | 2 +- source/funkin/ui/PopUpStuff.hx | 6 +- .../ui/debug/charting/ChartEditorState.hx | 24 ++-- 10 files changed, 118 insertions(+), 75 deletions(-) diff --git a/source/funkin/LatencyState.hx b/source/funkin/LatencyState.hx index 694e9c3e5..347454253 100644 --- a/source/funkin/LatencyState.hx +++ b/source/funkin/LatencyState.hx @@ -88,14 +88,14 @@ class LatencyState extends MusicBeatSubState // // musSpec.visType = FREQUENCIES; // add(musSpec); - for (beat in 0...Math.floor(FlxG.sound.music.length / Conductor.crochet)) + for (beat in 0...Math.floor(FlxG.sound.music.length / Conductor.beatLengthMs)) { - var beatTick:FlxSprite = new FlxSprite(songPosToX(beat * Conductor.crochet), FlxG.height - 15); + var beatTick:FlxSprite = new FlxSprite(songPosToX(beat * Conductor.beatLengthMs), FlxG.height - 15); beatTick.makeGraphic(2, 15); beatTick.alpha = 0.3; add(beatTick); - var offsetTxt:FlxText = new FlxText(songPosToX(beat * Conductor.crochet), FlxG.height - 26, 0, "swag"); + var offsetTxt:FlxText = new FlxText(songPosToX(beat * Conductor.beatLengthMs), FlxG.height - 26, 0, "swag"); offsetTxt.alpha = 0.5; diffGrp.add(offsetTxt); @@ -127,7 +127,7 @@ class LatencyState extends MusicBeatSubState for (i in 0...32) { - var note:Note = new Note(Conductor.crochet * i, 1); + var note:Note = new Note(Conductor.beatLengthMs * i, 1); noteGrp.add(note); } @@ -143,9 +143,9 @@ class LatencyState extends MusicBeatSubState override function stepHit():Bool { - if (curStep % 4 == 2) + if (Conductor.currentStep % 4 == 2) { - blocks.members[((curBeat % 8) + 1) % 8].alpha = 0.5; + blocks.members[((Conductor.currentBeat % 8) + 1) % 8].alpha = 0.5; } return super.stepHit(); @@ -153,11 +153,11 @@ class LatencyState extends MusicBeatSubState override function beatHit():Bool { - if (curBeat % 8 == 0) blocks.forEach(blok -> { + if (Conductor.currentBeat % 8 == 0) blocks.forEach(blok -> { blok.alpha = 0; }); - blocks.members[curBeat % 8].alpha = 1; + blocks.members[Conductor.currentBeat % 8].alpha = 1; // block.visible = !block.visible; return super.beatHit(); @@ -198,8 +198,8 @@ class LatencyState extends MusicBeatSubState offsetText.text = "AUDIO Offset: " + Conductor.audioOffset + "ms"; offsetText.text += "\nVIDOE Offset: " + Conductor.visualOffset + "ms"; - offsetText.text += "\ncurStep: " + curStep; - offsetText.text += "\ncurBeat: " + curBeat; + offsetText.text += "\ncurrentStep: " + Conductor.currentStep; + offsetText.text += "\ncurrentBeat: " + Conductor.currentBeat; var avgOffsetInput:Float = 0; @@ -255,7 +255,7 @@ class LatencyState extends MusicBeatSubState if (daNote.y < 0 - daNote.height) { daNote.alpha = 1; - // daNote.data.strumTime += Conductor.crochet * 8; + // daNote.data.strumTime += Conductor.beatLengthMs * 8; } }); @@ -266,12 +266,12 @@ class LatencyState extends MusicBeatSubState { Conductor.songPosition = swagSong.getTimeWithDiff(); - var closestBeat:Int = Math.round(Conductor.songPosition / Conductor.crochet) % diffGrp.members.length; - var getDiff:Float = Conductor.songPosition - (closestBeat * Conductor.crochet); + var closestBeat:Int = Math.round(Conductor.songPosition / Conductor.beatLengthMs) % diffGrp.members.length; + var getDiff:Float = Conductor.songPosition - (closestBeat * Conductor.beatLengthMs); getDiff -= Conductor.visualOffset; // lil fix for end of song - if (closestBeat == 0 && getDiff >= Conductor.crochet * 2) getDiff -= FlxG.sound.music.length; + if (closestBeat == 0 && getDiff >= Conductor.beatLengthMs * 2) getDiff -= FlxG.sound.music.length; trace("\tDISTANCE TO CLOSEST BEAT: " + getDiff + "ms"); trace("\tCLOSEST BEAT: " + closestBeat); diff --git a/source/funkin/MusicBeatSubState.hx b/source/funkin/MusicBeatSubState.hx index 440e25c96..5c6635a02 100644 --- a/source/funkin/MusicBeatSubState.hx +++ b/source/funkin/MusicBeatSubState.hx @@ -5,62 +5,96 @@ import flixel.util.FlxColor; import funkin.Conductor.BPMChangeEvent; import funkin.modding.events.ScriptEvent; import funkin.modding.module.ModuleHandler; +import flixel.text.FlxText; +import funkin.modding.PolymodHandler; /** * MusicBeatSubState reincorporates the functionality of MusicBeatState into an FlxSubState. */ class MusicBeatSubState extends FlxSubState { + public var leftWatermarkText:FlxText = null; + public var rightWatermarkText:FlxText = null; + public function new(bgColor:FlxColor = FlxColor.TRANSPARENT) { super(bgColor); } - var curStep:Int = 0; - var curBeat:Int = 0; var controls(get, never):Controls; inline function get_controls():Controls return PlayerSettings.player1.controls; - override function update(elapsed:Float) + override function create():Void { - // everyStep(); - var oldStep:Int = curStep; + super.create(); - updateCurStep(); - curBeat = Math.floor(curStep / 4); + createWatermarkText(); - if (oldStep != curStep && curStep >= 0) stepHit(); + Conductor.beatHit.add(this.beatHit); + Conductor.stepHit.add(this.stepHit); + } + public override function destroy():Void + { + super.destroy(); + Conductor.beatHit.remove(this.beatHit); + Conductor.stepHit.remove(this.stepHit); + } + + override function update(elapsed:Float):Void + { super.update(elapsed); + + // Rebindable volume keys. + if (controls.VOLUME_MUTE) FlxG.sound.toggleMuted(); + else if (controls.VOLUME_UP) FlxG.sound.changeVolume(0.1); + else if (controls.VOLUME_DOWN) FlxG.sound.changeVolume(-0.1); + + // Emergency exit button. + if (FlxG.keys.justPressed.F4) FlxG.switchState(new MainMenuState()); + + // This can now be used in EVERY STATE YAY! + if (FlxG.keys.justPressed.F5) debug_refreshModules(); } - function updateCurStep():Void + function debug_refreshModules() { - var lastChange:BPMChangeEvent = - { - stepTime: 0, - songTime: 0, - bpm: 0 - } - for (i in 0...Conductor.bpmChangeMap.length) - { - if (Conductor.songPosition > Conductor.bpmChangeMap[i].songTime) lastChange = Conductor.bpmChangeMap[i]; - } + PolymodHandler.forceReloadAssets(); - curStep = lastChange.stepTime + Math.floor(((Conductor.songPosition - Conductor.audioOffset) - lastChange.songTime) / Conductor.stepCrochet); + // Restart the current state, so old data is cleared. + FlxG.resetState(); } + /** + * Called when a step is hit in the current song. + * Continues outside of PlayState, for things like animations in menus. + * @return Whether the event should continue (not canceled). + */ public function stepHit():Bool { - var event = new SongTimeScriptEvent(ScriptEvent.SONG_STEP_HIT, curBeat, curStep); + var event:ScriptEvent = new SongTimeScriptEvent(ScriptEvent.SONG_STEP_HIT, Conductor.currentBeat, Conductor.currentStep); dispatchEvent(event); if (event.eventCanceled) return false; - if (curStep % 4 == 0) beatHit(); + return true; + } + + /** + * Called when a beat is hit in the current song. + * Continues outside of PlayState, for things like animations in menus. + * @return Whether the event should continue (not canceled). + */ + public function beatHit():Bool + { + var event:ScriptEvent = new SongTimeScriptEvent(ScriptEvent.SONG_BEAT_HIT, Conductor.currentBeat, Conductor.currentStep); + + dispatchEvent(event); + + if (event.eventCanceled) return false; return true; } @@ -70,6 +104,25 @@ class MusicBeatSubState extends FlxSubState ModuleHandler.callEvent(event); } + function createWatermarkText():Void + { + // Both have an xPos of 0, but a width equal to the full screen. + // The rightWatermarkText is right aligned, which puts the text in the correct spot. + leftWatermarkText = new FlxText(0, FlxG.height - 18, FlxG.width, '', 12); + rightWatermarkText = new FlxText(0, FlxG.height - 18, FlxG.width, '', 12); + + // 100,000 should be good enough. + leftWatermarkText.zIndex = 100000; + rightWatermarkText.zIndex = 100000; + leftWatermarkText.scrollFactor.set(0, 0); + rightWatermarkText.scrollFactor.set(0, 0); + leftWatermarkText.setFormat('VCR OSD Mono', 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); + rightWatermarkText.setFormat('VCR OSD Mono', 16, FlxColor.WHITE, RIGHT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); + + add(leftWatermarkText); + add(rightWatermarkText); + } + /** * Close this substate and replace it with a different one. */ @@ -78,15 +131,4 @@ class MusicBeatSubState extends FlxSubState this.close(); this._parentState.openSubState(substate); } - - public function beatHit():Bool - { - var event = new SongTimeScriptEvent(ScriptEvent.SONG_BEAT_HIT, curBeat, curStep); - - dispatchEvent(event); - - if (event.eventCanceled) return false; - - return true; - } } diff --git a/source/funkin/Note.hx b/source/funkin/Note.hx index 71c63a94e..ea99449b1 100644 --- a/source/funkin/Note.hx +++ b/source/funkin/Note.hx @@ -207,7 +207,7 @@ class Note extends FlxSprite prevNote.animation.play(prevNote.colorName + 'hold'); prevNote.updateHitbox(); - var scaleThing:Float = Math.round((Conductor.stepCrochet) * (0.45 * FlxMath.roundDecimal(SongLoad.getSpeed(), 2))); + var scaleThing:Float = Math.round((Conductor.stepLengthMs) * (0.45 * FlxMath.roundDecimal(PlayState.instance.currentChart.scrollSpeed, 2))); // get them a LIL closer together cuz the antialiasing blurs the edges if (antialiasing) scaleThing *= 1.0 + (1.0 / prevNote.frameHeight); prevNote.scale.y = scaleThing / prevNote.frameHeight; diff --git a/source/funkin/play/Countdown.hx b/source/funkin/play/Countdown.hx index 016b21c6c..169bda24b 100644 --- a/source/funkin/play/Countdown.hx +++ b/source/funkin/play/Countdown.hx @@ -38,7 +38,7 @@ class Countdown stopCountdown(); PlayState.instance.isInCountdown = true; - Conductor.songPosition = Conductor.crochet * -5; + Conductor.songPosition = Conductor.beatLengthMs * -5; // Handle onBeatHit events manually @:privateAccess PlayState.instance.dispatchEvent(new SongTimeScriptEvent(ScriptEvent.SONG_BEAT_HIT, 0, 0)); @@ -46,7 +46,7 @@ class Countdown // The timer function gets called based on the beat of the song. countdownTimer = new FlxTimer(); - countdownTimer.start(Conductor.crochet / 1000, function(tmr:FlxTimer) { + countdownTimer.start(Conductor.beatLengthMs / 1000, function(tmr:FlxTimer) { countdownStep = decrement(countdownStep); // Handle onBeatHit events manually @@ -212,7 +212,7 @@ class Countdown countdownSprite.screenCenter(); // Fade sprite in, then out, then destroy it. - FlxTween.tween(countdownSprite, {y: countdownSprite.y += 100, alpha: 0}, Conductor.crochet / 1000, + FlxTween.tween(countdownSprite, {y: countdownSprite.y += 100, alpha: 0}, Conductor.beatLengthMs / 1000, { ease: FlxEase.cubeInOut, onComplete: function(twn:FlxTween) { diff --git a/source/funkin/play/character/BaseCharacter.hx b/source/funkin/play/character/BaseCharacter.hx index f4db7f66f..bdf7ef591 100644 --- a/source/funkin/play/character/BaseCharacter.hx +++ b/source/funkin/play/character/BaseCharacter.hx @@ -367,7 +367,7 @@ class BaseCharacter extends Bopper // This lets you add frames to the end of the sing animation to ease back into the idle! holdTimer += event.elapsed; - var singTimeSec:Float = singTimeSec * (Conductor.crochet * 0.001); // x beats, to ms. + var singTimeSec:Float = singTimeSec * (Conductor.beatLengthMs * 0.001); // x beats, to ms. if (getCurrentAnimation().endsWith('miss')) singTimeSec *= 2; // makes it feel more awkward when you miss diff --git a/source/funkin/play/event/ZoomCameraSongEvent.hx b/source/funkin/play/event/ZoomCameraSongEvent.hx index e6e9c843d..79425d564 100644 --- a/source/funkin/play/event/ZoomCameraSongEvent.hx +++ b/source/funkin/play/event/ZoomCameraSongEvent.hx @@ -10,7 +10,7 @@ import funkin.play.event.SongEventData.SongEventFieldType; /** * This class represents a handler for camera zoom events. - * + * * Example: Zoom to 1.3x: * ``` * { @@ -18,8 +18,8 @@ import funkin.play.event.SongEventData.SongEventFieldType; * 'v': 1.3 * } * ``` - * - * Example: Zoom to 1.3x + * + * Example: Zoom to 1.3x * ``` * { * 'e': 'FocusCamera', @@ -29,7 +29,7 @@ import funkin.play.event.SongEventData.SongEventFieldType; * } * } * ``` - * + * * Example: Focus on (100, 100): * ``` * { @@ -76,7 +76,8 @@ class ZoomCameraSongEvent extends SongEvent return; } - FlxTween.tween(PlayState.instance, {defaultCameraZoom: zoom * FlxCamera.defaultZoom}, (Conductor.stepCrochet * duration / 1000), {ease: easeFunction}); + FlxTween.tween(PlayState.instance, {defaultCameraZoom: zoom * FlxCamera.defaultZoom}, (Conductor.stepLengthMs * duration / 1000), + {ease: easeFunction}); } } diff --git a/source/funkin/play/song/SongData.hx b/source/funkin/play/song/SongData.hx index 78593c6c0..282734d10 100644 --- a/source/funkin/play/song/SongData.hx +++ b/source/funkin/play/song/SongData.hx @@ -365,7 +365,7 @@ abstract SongNoteData(RawSongNoteData) public function get_stepTime():Float { // TODO: Account for changes in BPM. - return this.t / Conductor.stepCrochet; + return this.t / Conductor.stepLengthMs; } /** @@ -551,7 +551,7 @@ abstract SongEventData(RawSongEventData) public function get_stepTime():Float { // TODO: Account for changes in BPM. - return this.t / Conductor.stepCrochet; + return this.t / Conductor.stepLengthMs; } public var event(get, set):String; diff --git a/source/funkin/play/stage/Stage.hx b/source/funkin/play/stage/Stage.hx index 36d1600a6..ef2d28430 100644 --- a/source/funkin/play/stage/Stage.hx +++ b/source/funkin/play/stage/Stage.hx @@ -658,7 +658,7 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass public function onBeatHit(event:SongTimeScriptEvent):Void { // Override me in your scripted stage to perform custom behavior! - // Make sure to call super.onBeatHit(curBeat) if you want to keep the boppers dancing. + // Make sure to call super.onBeatHit(event) if you want to keep the boppers dancing. for (bopper in boppers) { diff --git a/source/funkin/ui/PopUpStuff.hx b/source/funkin/ui/PopUpStuff.hx index c5828dd0a..20380f50a 100644 --- a/source/funkin/ui/PopUpStuff.hx +++ b/source/funkin/ui/PopUpStuff.hx @@ -59,7 +59,7 @@ class PopUpStuff extends FlxTypedGroup remove(rating, true); rating.destroy(); }, - startDelay: Conductor.crochet * 0.001 + startDelay: Conductor.beatLengthMs * 0.001 }); } @@ -109,7 +109,7 @@ class PopUpStuff extends FlxTypedGroup remove(comboSpr, true); comboSpr.destroy(); }, - startDelay: Conductor.crochet * 0.001 + startDelay: Conductor.beatLengthMs * 0.001 }); var seperatedScore:Array = []; @@ -155,7 +155,7 @@ class PopUpStuff extends FlxTypedGroup remove(numScore, true); numScore.destroy(); }, - startDelay: Conductor.crochet * 0.002 + startDelay: Conductor.beatLengthMs * 0.002 }); daLoop++; diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index c61637536..18e34c72b 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -189,12 +189,12 @@ class ChartEditorState extends HaxeUIState function get_scrollPositionInMs():Float { - return scrollPositionInSteps * Conductor.stepCrochet; + return scrollPositionInSteps * Conductor.stepLengthMs; } function set_scrollPositionInMs(value:Float):Float { - scrollPositionInPixels = value / Conductor.stepCrochet; + scrollPositionInPixels = value / Conductor.stepLengthMs; return value; } @@ -223,7 +223,7 @@ class ChartEditorState extends HaxeUIState function get_playheadPositionInMs():Float { - return playheadPositionInSteps * Conductor.stepCrochet; + return playheadPositionInSteps * Conductor.stepLengthMs; } /** @@ -263,7 +263,7 @@ class ChartEditorState extends HaxeUIState function get_songLengthInMs():Float { - return songLengthInSteps * Conductor.stepCrochet; + return songLengthInSteps * Conductor.stepLengthMs; } function set_songLengthInMs(value:Float):Float @@ -1667,7 +1667,7 @@ class ChartEditorState extends HaxeUIState // The song position of the cursor, in steps. var cursorFractionalStep:Float = cursorY / GRID_SIZE / (16 / noteSnapQuant); var cursorStep:Int = Std.int(Math.floor(cursorFractionalStep)); - var cursorMs:Float = cursorStep * Conductor.stepCrochet * (16 / noteSnapQuant); + var cursorMs:Float = cursorStep * Conductor.stepLengthMs * (16 / noteSnapQuant); // The direction value for the column at the cursor. var cursorColumn:Int = Math.floor(cursorX / GRID_SIZE); if (cursorColumn < 0) cursorColumn = 0; @@ -1705,7 +1705,7 @@ class ChartEditorState extends HaxeUIState // We released the mouse. Select the notes in the box. var cursorFractionalStepStart:Float = cursorYStart / GRID_SIZE; var cursorStepStart:Int = Math.floor(cursorFractionalStepStart); - var cursorMsStart:Float = cursorStepStart * Conductor.stepCrochet; + var cursorMsStart:Float = cursorStepStart * Conductor.stepLengthMs; var cursorColumnBase:Int = Math.floor(cursorX / GRID_SIZE); var cursorColumnBaseStart:Int = Math.floor(cursorXStart / GRID_SIZE); @@ -1878,11 +1878,11 @@ class ChartEditorState extends HaxeUIState // Handle extending the note as you drag. // Since use Math.floor and stepCrochet here, the hold notes will be beat snapped. - var dragLengthSteps:Float = Math.floor((cursorMs - currentPlaceNoteData.time) / Conductor.stepCrochet); + var dragLengthSteps:Float = Math.floor((cursorMs - currentPlaceNoteData.time) / Conductor.stepLengthMs); // Without this, the newly placed note feels too short compared to the user's input. var INCREMENT:Float = 1.0; - var dragLengthMs:Float = (dragLengthSteps + INCREMENT) * Conductor.stepCrochet; + var dragLengthMs:Float = (dragLengthSteps + INCREMENT) * Conductor.stepLengthMs; // TODO: Add and update some sort of preview? @@ -2187,7 +2187,7 @@ class ChartEditorState extends HaxeUIState } // Get the position the note should be at. - var noteTimePixels:Float = noteData.time / Conductor.stepCrochet * GRID_SIZE; + var noteTimePixels:Float = noteData.time / Conductor.stepLengthMs * GRID_SIZE; // Make sure the note appears when scrolling up. var modifiedViewAreaTop = viewAreaTop - GRID_SIZE; @@ -2213,7 +2213,7 @@ class ChartEditorState extends HaxeUIState { // If the note is a hold, we need to make sure it's long enough. var noteLengthMs:Float = noteSprite.noteData.length; - var noteLengthSteps:Float = (noteLengthMs / Conductor.stepCrochet); + var noteLengthSteps:Float = (noteLengthMs / Conductor.stepLengthMs); var lastNoteSprite:ChartEditorNoteSprite = noteSprite; while (noteLengthSteps > 0) @@ -2237,7 +2237,7 @@ class ChartEditorState extends HaxeUIState // Make sure the last note sprite shows the end cap properly. lastNoteSprite.childNoteSprite = null; - // var noteLengthPixels:Float = (noteLengthMs / Conductor.stepCrochet + 1) * GRID_SIZE; + // var noteLengthPixels:Float = (noteLengthMs / Conductor.stepLengthMs + 1) * GRID_SIZE; // add(new FlxSprite(noteSprite.x, noteSprite.y - renderedNotes.y + noteLengthPixels).makeGraphic(40, 2, 0xFFFF0000)); } } @@ -2252,7 +2252,7 @@ class ChartEditorState extends HaxeUIState } // Get the position the event should be at. - var eventTimePixels:Float = eventData.time / Conductor.stepCrochet * GRID_SIZE; + var eventTimePixels:Float = eventData.time / Conductor.stepLengthMs * GRID_SIZE; // Make sure the event appears when scrolling up. var modifiedViewAreaTop = viewAreaTop - GRID_SIZE;