From 910105b8524f21026129ae5b5409c87e4f99fa25 Mon Sep 17 00:00:00 2001 From: CuckyDev Date: Sun, 11 Jul 2021 17:22:06 -0400 Subject: [PATCH 1/3] Rewrite MusicBeatState stuff --- source/MusicBeatState.hx | 23 +++++++++++++---------- source/MusicBeatSubstate.hx | 27 ++++++++++++++++++--------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/source/MusicBeatState.hx b/source/MusicBeatState.hx index d98bd64..6eb151c 100644 --- a/source/MusicBeatState.hx +++ b/source/MusicBeatState.hx @@ -51,13 +51,17 @@ class MusicBeatState extends FlxUIState override function update(elapsed:Float) { //everyStep(); - var oldStep:Int = curStep; + var nextStep:Int = updateCurStep(); - updateCurStep(); - updateBeat(); - - if (oldStep != curStep && curStep > 0) - stepHit(); + if (nextStep > curStep && curStep >= 0) + { + for (i in curStep...nextStep) + { + curStep++; + updateBeat(); + stepHit(); + } + } if (FlxG.save.data.fpsRain && skippedFrames >= 6) { @@ -78,13 +82,13 @@ class MusicBeatState extends FlxUIState private function updateBeat():Void { - lastBeat = curStep; + lastBeat = curBeat; curBeat = Math.floor(curStep / 4); } public static var currentColor = 0; - private function updateCurStep():Void + private function updateCurStep():Int { var lastChange:BPMChangeEvent = { stepTime: 0, @@ -97,12 +101,11 @@ class MusicBeatState extends FlxUIState lastChange = Conductor.bpmChangeMap[i]; } - curStep = lastChange.stepTime + Math.floor((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet); + return lastChange.stepTime + Math.floor((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet); } public function stepHit():Void { - if (curStep % 4 == 0) beatHit(); } diff --git a/source/MusicBeatSubstate.hx b/source/MusicBeatSubstate.hx index c6da0fb..1be9789 100644 --- a/source/MusicBeatSubstate.hx +++ b/source/MusicBeatSubstate.hx @@ -24,19 +24,28 @@ class MusicBeatSubstate extends FlxSubState override function update(elapsed:Float) { //everyStep(); - var oldStep:Int = curStep; - - updateCurStep(); - curBeat = Math.floor(curStep / 4); - - if (oldStep != curStep && curStep > 0) - stepHit(); + var nextStep = updateCurStep(); + if (nextStep > curStep && curStep >= 0) + { + for (i in curStep...nextStep) + { + curStep++; + updateBeat(); + stepHit(); + } + } super.update(elapsed); } - private function updateCurStep():Void + private function updateBeat():Void + { + lastBeat = curBeat; + curBeat = Math.floor(curStep / 4); + } + + private function updateCurStep():Int { var lastChange:BPMChangeEvent = { stepTime: 0, @@ -49,7 +58,7 @@ class MusicBeatSubstate extends FlxSubState lastChange = Conductor.bpmChangeMap[i]; } - curStep = lastChange.stepTime + Math.floor((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet); + return lastChange.stepTime + Math.floor((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet); } public function stepHit():Void From ad89799f58434eb7ae0482c2a7fe4521292afc95 Mon Sep 17 00:00:00 2001 From: CuckyDev Date: Sun, 11 Jul 2021 18:04:30 -0400 Subject: [PATCH 2/3] Fix note positioning --- source/Note.hx | 23 +++++++++++++---------- source/PlayState.hx | 27 +++++++++++++++++++++------ 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/source/Note.hx b/source/Note.hx index e5e7f5f..7baedf4 100644 --- a/source/Note.hx +++ b/source/Note.hx @@ -67,7 +67,12 @@ class Note extends FlxSprite this.prevNote = prevNote; isSustainNote = sustainNote; - x += 50; + this.noteData = noteData; + + if (!inCharter) + x = PlayState.strumLineNotes.members[Math.floor(Math.abs(noteData))].x; + else + x += 50; // MAKE SURE ITS DEFINITELY OFF SCREEN? y -= 2000; @@ -86,8 +91,6 @@ class Note extends FlxSprite if (this.strumTime < 0 ) this.strumTime = 0; - this.noteData = noteData; - var daStage:String = PlayState.curStage; //defaults if no noteStyle was found in chart @@ -177,20 +180,20 @@ class Note extends FlxSprite noteScore * 0.2; alpha = 0.6; - x += width / 2; + x += width / 2 + 17; + if (noteTypeCheck == 'pixel') + x -= 8; + //x += width / 2; originColor = prevNote.originColor; animation.play(dataColor[originColor] + 'holdend'); // This works both for normal colors and quantization colors updateHitbox(); - x -= width / 2; + //x -= width / 2; - if (noteTypeCheck == 'pixel') - x += 30; - - if (inCharter) - x += 30; + //if (PlayState.curStage.startsWith('school')) + // x += 30; if (prevNote.isSustainNote) { diff --git a/source/PlayState.hx b/source/PlayState.hx index e82619d..d4c5ad6 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -997,6 +997,9 @@ class PlayState extends MusicBeatState playerStrums = new FlxTypedGroup(); cpuStrums = new FlxTypedGroup(); + generateStaticArrows(0); + generateStaticArrows(1); + // startCountdown(); if (SONG.song == null) @@ -1308,8 +1311,9 @@ class PlayState extends MusicBeatState { inCutscene = false; - generateStaticArrows(0); - generateStaticArrows(1); + appearStaticArrows(); + //generateStaticArrows(0); + //generateStaticArrows(1); #if windows // pre lowercasing the song name (startCountdown) @@ -1796,9 +1800,6 @@ class PlayState extends MusicBeatState { swagNote.x += FlxG.width / 2; // general offset } - else - { - } } daBeats += 1; } @@ -1901,10 +1902,11 @@ class PlayState extends MusicBeatState babyArrow.updateHitbox(); babyArrow.scrollFactor.set(); + babyArrow.alpha = 0; if (!isStoryMode) { babyArrow.y -= 10; - babyArrow.alpha = 0; + //babyArrow.alpha = 0; FlxTween.tween(babyArrow, {y: babyArrow.y + 10, alpha: 1}, 1, {ease: FlxEase.circOut, startDelay: 0.5 + (0.2 * i)}); } @@ -1934,6 +1936,15 @@ class PlayState extends MusicBeatState } } + private function appearStaticArrows():Void + { + strumLineNotes.forEach(function(babyArrow:FlxSprite) + { + if (isStoryMode) + babyArrow.alpha = 1; + }); + } + function tweenCamIn():Void { FlxTween.tween(FlxG.camera, {zoom: 1.3}, (Conductor.stepCrochet * 4 / 1000), {ease: FlxEase.elasticInOut}); @@ -2796,7 +2807,11 @@ class PlayState extends MusicBeatState } if (daNote.isSustainNote) + { daNote.x += daNote.width / 2 + 17; + if (PlayState.curStage.startsWith('school')) + daNote.x -= 8; + } // trace(daNote.y); // WIP interpolation shit? Need to fix the pause issue From 321badd0b299ec29463ab1fca488387769c98add Mon Sep 17 00:00:00 2001 From: CuckyDev Date: Sun, 11 Jul 2021 18:36:12 -0400 Subject: [PATCH 3/3] Fix issues with HTML5 and note drawing --- source/Caching.hx | 239 ++++++++++++++++++++++------------------------ source/Main.hx | 18 ++++ source/Note.hx | 27 +++--- 3 files changed, 143 insertions(+), 141 deletions(-) diff --git a/source/Caching.hx b/source/Caching.hx index 298d5dc..fdf458a 100644 --- a/source/Caching.hx +++ b/source/Caching.hx @@ -10,8 +10,10 @@ import flixel.ui.FlxBar; import haxe.Exception; import flixel.tweens.FlxEase; import flixel.tweens.FlxTween; +#if cpp import sys.FileSystem; import sys.io.File; +#end import flixel.FlxG; import flixel.FlxSprite; import flixel.addons.transition.FlxTransitionSprite.GraphicTransTileDiamond; @@ -29,161 +31,144 @@ using StringTools; class Caching extends MusicBeatState { - var toBeDone = 0; - var done = 0; + var toBeDone = 0; + var done = 0; - var loaded = false; + var loaded = false; - var text:FlxText; - var kadeLogo:FlxSprite; + var text:FlxText; + var kadeLogo:FlxSprite; - public static var bitmapData:Map; + public static var bitmapData:Map; - var images = []; - var music = []; - var charts = []; + var images = []; + var music = []; + var charts = []; override function create() { - FlxG.mouse.visible = false; + FlxG.mouse.visible = false; - FlxG.worldBounds.set(0,0); + FlxG.worldBounds.set(0,0); - bitmapData = new Map(); + bitmapData = new Map(); - text = new FlxText(FlxG.width / 2, FlxG.height / 2 + 300,0,"Loading..."); - text.size = 34; - text.alignment = FlxTextAlign.CENTER; - text.alpha = 0; + text = new FlxText(FlxG.width / 2, FlxG.height / 2 + 300,0,"Loading..."); + text.size = 34; + text.alignment = FlxTextAlign.CENTER; + text.alpha = 0; - kadeLogo = new FlxSprite(FlxG.width / 2, FlxG.height / 2).loadGraphic(Paths.image('KadeEngineLogo')); - kadeLogo.x -= kadeLogo.width / 2; - kadeLogo.y -= kadeLogo.height / 2 + 100; - text.y -= kadeLogo.height / 2 - 125; - text.x -= 170; - kadeLogo.setGraphicSize(Std.int(kadeLogo.width * 0.6)); - kadeLogo.antialiasing = true; + kadeLogo = new FlxSprite(FlxG.width / 2, FlxG.height / 2).loadGraphic(Paths.image('KadeEngineLogo')); + kadeLogo.x -= kadeLogo.width / 2; + kadeLogo.y -= kadeLogo.height / 2 + 100; + text.y -= kadeLogo.height / 2 - 125; + text.x -= 170; + kadeLogo.setGraphicSize(Std.int(kadeLogo.width * 0.6)); + kadeLogo.antialiasing = true; - kadeLogo.alpha = 0; + kadeLogo.alpha = 0; - PlayerSettings.init(); + #if cpp + if (FlxG.save.data.cacheImages) + { + trace("caching images..."); - #if windows - DiscordClient.initialize(); + for (i in FileSystem.readDirectory(FileSystem.absolutePath("assets/shared/images/characters"))) + { + if (!i.endsWith(".png")) + continue; + images.push(i); + } + } - Application.current.onExit.add (function (exitCode) { - DiscordClient.shutdown(); - }); - + trace("caching music..."); + + for (i in FileSystem.readDirectory(FileSystem.absolutePath("assets/songs"))) + { + music.push(i); + } #end + toBeDone = Lambda.count(images) + Lambda.count(music); + + var bar = new FlxBar(10,FlxG.height - 50,FlxBarFillDirection.LEFT_TO_RIGHT,FlxG.width,40,null,"done",0,toBeDone); + bar.color = FlxColor.PURPLE; + + add(bar); + + add(kadeLogo); + add(text); + + trace('starting caching..'); - Highscore.load(); + #if cpp + // update thread - FlxG.save.bind('funkin', 'ninjamuffin99'); + sys.thread.Thread.create(() -> { + while(!loaded) + { + if (toBeDone != 0 && done != toBeDone) + { + var alpha = HelperFunctions.truncateFloat(done / toBeDone * 100,2) / 100; + kadeLogo.alpha = alpha; + text.alpha = alpha; + text.text = "Loading... (" + done + "/" + toBeDone + ")"; + } + } + + }); - KadeEngineData.initSave(); + // cache thread + + sys.thread.Thread.create(() -> { + cache(); + }); + #end + + super.create(); + } + + var calledDone = false; + + override function update(elapsed) + { + super.update(elapsed); + } - if (FlxG.save.data.cacheImages) - { - trace("caching images..."); + function cache() + { + trace("LOADING: " + toBeDone + " OBJECTS."); - for (i in FileSystem.readDirectory(FileSystem.absolutePath("assets/shared/images/characters"))) - { - if (!i.endsWith(".png")) - continue; - images.push(i); - } - } + for (i in images) + { + var replaced = i.replace(".png",""); + var data:BitmapData = BitmapData.fromFile("assets/shared/images/characters/" + i); + trace('id ' + replaced + ' file - assets/shared/images/characters/' + i + ' ${data.width}'); + var graph = FlxGraphic.fromBitmapData(data); + graph.persist = true; + graph.destroyOnNoUse = false; + bitmapData.set(replaced,graph); + done++; + } - trace("caching music..."); - - for (i in FileSystem.readDirectory(FileSystem.absolutePath("assets/songs"))) - { - music.push(i); - } - - - toBeDone = Lambda.count(images) + Lambda.count(music); - - var bar = new FlxBar(10,FlxG.height - 50,FlxBarFillDirection.LEFT_TO_RIGHT,FlxG.width,40,null,"done",0,toBeDone); - bar.color = FlxColor.PURPLE; - - add(bar); - - add(kadeLogo); - add(text); - - trace('starting caching..'); - - // update thread - - sys.thread.Thread.create(() -> { - while(!loaded) - { - if (toBeDone != 0 && done != toBeDone) - { - var alpha = HelperFunctions.truncateFloat(done / toBeDone * 100,2) / 100; - kadeLogo.alpha = alpha; - text.alpha = alpha; - text.text = "Loading... (" + done + "/" + toBeDone + ")"; - } - } - - }); - - // cache thread - - sys.thread.Thread.create(() -> { - cache(); - }); - - super.create(); - } - - var calledDone = false; - - override function update(elapsed) - { - super.update(elapsed); - } + for (i in music) + { + FlxG.sound.cache(Paths.inst(i)); + FlxG.sound.cache(Paths.voices(i)); + trace("cached " + i); + done++; + } - function cache() - { + trace("Finished caching..."); - trace("LOADING: " + toBeDone + " OBJECTS."); + loaded = true; - for (i in images) - { - var replaced = i.replace(".png",""); - var data:BitmapData = BitmapData.fromFile("assets/shared/images/characters/" + i); - trace('id ' + replaced + ' file - assets/shared/images/characters/' + i + ' ${data.width}'); - var graph = FlxGraphic.fromBitmapData(data); - graph.persist = true; - graph.destroyOnNoUse = false; - bitmapData.set(replaced,graph); - done++; - } + trace(Assets.cache.hasBitmapData('GF_assets')); - for (i in music) - { - FlxG.sound.cache(Paths.inst(i)); - FlxG.sound.cache(Paths.voices(i)); - trace("cached " + i); - done++; - } + FlxG.switchState(new TitleState()); + } - - trace("Finished caching..."); - - loaded = true; - - trace(Assets.cache.hasBitmapData('GF_assets')); - - FlxG.switchState(new TitleState()); - } - -} +} \ No newline at end of file diff --git a/source/Main.hx b/source/Main.hx index 6c06d39..5c6b862 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -89,6 +89,24 @@ class Main extends Sprite toggleFPS(FlxG.save.data.fps); #end + + PlayerSettings.init(); + + #if windows + DiscordClient.initialize(); + + Application.current.onExit.add (function (exitCode) { + DiscordClient.shutdown(); + }); + + #end + + + Highscore.load(); + + FlxG.save.bind('funkin', 'ninjamuffin99'); + + KadeEngineData.initSave(); } var game:FlxGame; diff --git a/source/Note.hx b/source/Note.hx index 7baedf4..4116d1a 100644 --- a/source/Note.hx +++ b/source/Note.hx @@ -67,12 +67,7 @@ class Note extends FlxSprite this.prevNote = prevNote; isSustainNote = sustainNote; - this.noteData = noteData; - - if (!inCharter) - x = PlayState.strumLineNotes.members[Math.floor(Math.abs(noteData))].x; - else - x += 50; + x += 50; // MAKE SURE ITS DEFINITELY OFF SCREEN? y -= 2000; @@ -91,12 +86,16 @@ class Note extends FlxSprite if (this.strumTime < 0 ) this.strumTime = 0; + this.noteData = noteData; + var daStage:String = PlayState.curStage; //defaults if no noteStyle was found in chart var noteTypeCheck:String = 'normal'; + if (PlayState.curStage.startsWith('school')) + noteTypeCheck = 'pixel'; - if (!inCharter) + if (inCharter) { frames = Paths.getSparrowAtlas('NOTE_assets'); @@ -180,20 +179,20 @@ class Note extends FlxSprite noteScore * 0.2; alpha = 0.6; - x += width / 2 + 17; - if (noteTypeCheck == 'pixel') - x -= 8; - //x += width / 2; + x += width / 2; originColor = prevNote.originColor; animation.play(dataColor[originColor] + 'holdend'); // This works both for normal colors and quantization colors updateHitbox(); - //x -= width / 2; + x -= width / 2; - //if (PlayState.curStage.startsWith('school')) - // x += 30; + if (noteTypeCheck == 'pixel') + x += 30; + + if (inCharter) + x += 30; if (prevNote.isSustainNote) {