From 7ce3eabd17eb918ce326cf401e1e43cd80f62084 Mon Sep 17 00:00:00 2001 From: Sword352 Date: Wed, 8 May 2024 07:35:46 +0200 Subject: [PATCH 01/28] Better character animation offsets handling. --- source/funkin/play/character/BaseCharacter.hx | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/source/funkin/play/character/BaseCharacter.hx b/source/funkin/play/character/BaseCharacter.hx index 2796f8123..cb9d5ae3f 100644 --- a/source/funkin/play/character/BaseCharacter.hx +++ b/source/funkin/play/character/BaseCharacter.hx @@ -1,6 +1,7 @@ package funkin.play.character; import flixel.math.FlxPoint; +import flixel.FlxCamera; import funkin.modding.events.ScriptEvent; import funkin.play.character.CharacterData.CharacterDataParser; import funkin.play.character.CharacterData.CharacterRenderType; @@ -118,19 +119,17 @@ class BaseCharacter extends Bopper */ public var cameraFocusPoint(default, null):FlxPoint = new FlxPoint(0, 0); + /** + * Defines the animation offset. + */ + public var animOffset:FlxPoint = FlxPoint.get(); + override function set_animOffsets(value:Array):Array { if (animOffsets == null) value = [0, 0]; if ((animOffsets[0] == value[0]) && (animOffsets[1] == value[1])) return value; - // Make sure animOffets are halved when scale is 0.5. - var xDiff = (animOffsets[0] * this.scale.x / (this.isPixel ? 6 : 1)) - value[0]; - var yDiff = (animOffsets[1] * this.scale.y / (this.isPixel ? 6 : 1)) - value[1]; - - // Call the super function so that camera focus point is not affected. - super.set_x(this.x + xDiff); - super.set_y(this.y + yDiff); - + animOffset.set(value[0], value[1]); return animOffsets = value; } @@ -570,11 +569,25 @@ class BaseCharacter extends Bopper } } + // override getScreenPosition (used by FlxSprite's draw method) to account for animation offsets. + override function getScreenPosition(?result:FlxPoint, ?camera:FlxCamera):FlxPoint + { + var output:FlxPoint = super.getScreenPosition(result, camera); + output -= animOffset; + return output; + } + public override function onDestroy(event:ScriptEvent):Void { this.characterType = OTHER; } + override function destroy():Void + { + animOffset = flixel.util.FlxDestroyUtil.put(animOffset); + super.destroy(); + } + /** * Play the appropriate singing animation, for the given note direction. * @param dir The direction of the note. From dd86934712276f136193033237cb15095cc0e787 Mon Sep 17 00:00:00 2001 From: Sword352 Date: Wed, 8 May 2024 09:22:49 +0200 Subject: [PATCH 02/28] did the requested changes --- source/funkin/play/character/BaseCharacter.hx | 29 ------------------- source/funkin/play/stage/Bopper.hx | 27 +++++++++++++---- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/source/funkin/play/character/BaseCharacter.hx b/source/funkin/play/character/BaseCharacter.hx index cb9d5ae3f..eee7d15a2 100644 --- a/source/funkin/play/character/BaseCharacter.hx +++ b/source/funkin/play/character/BaseCharacter.hx @@ -1,7 +1,6 @@ package funkin.play.character; import flixel.math.FlxPoint; -import flixel.FlxCamera; import funkin.modding.events.ScriptEvent; import funkin.play.character.CharacterData.CharacterDataParser; import funkin.play.character.CharacterData.CharacterRenderType; @@ -119,20 +118,6 @@ class BaseCharacter extends Bopper */ public var cameraFocusPoint(default, null):FlxPoint = new FlxPoint(0, 0); - /** - * Defines the animation offset. - */ - public var animOffset:FlxPoint = FlxPoint.get(); - - override function set_animOffsets(value:Array):Array - { - if (animOffsets == null) value = [0, 0]; - if ((animOffsets[0] == value[0]) && (animOffsets[1] == value[1])) return value; - - animOffset.set(value[0], value[1]); - return animOffsets = value; - } - /** * If the x position changes, other than via changing the animation offset, * then we need to update the camera focus point. @@ -569,25 +554,11 @@ class BaseCharacter extends Bopper } } - // override getScreenPosition (used by FlxSprite's draw method) to account for animation offsets. - override function getScreenPosition(?result:FlxPoint, ?camera:FlxCamera):FlxPoint - { - var output:FlxPoint = super.getScreenPosition(result, camera); - output -= animOffset; - return output; - } - public override function onDestroy(event:ScriptEvent):Void { this.characterType = OTHER; } - override function destroy():Void - { - animOffset = flixel.util.FlxDestroyUtil.put(animOffset); - super.destroy(); - } - /** * Play the appropriate singing animation, for the given note direction. * @param dir The direction of the note. diff --git a/source/funkin/play/stage/Bopper.hx b/source/funkin/play/stage/Bopper.hx index 262aff7bc..141a85c8f 100644 --- a/source/funkin/play/stage/Bopper.hx +++ b/source/funkin/play/stage/Bopper.hx @@ -1,6 +1,7 @@ package funkin.play.stage; import flixel.FlxSprite; +import flixel.FlxCamera; import flixel.math.FlxPoint; import flixel.util.FlxTimer; import funkin.modding.IScriptedClass.IPlayStateScriptedClass; @@ -67,6 +68,11 @@ class Bopper extends StageProp implements IPlayStateScriptedClass return value; } + /** + * Internally used to define the animation offsets to apply. + */ + var _currentAnimOffset:FlxPoint = FlxPoint.get(); + /** * The offset of the character relative to the position specified by the stage. */ @@ -95,12 +101,7 @@ class Bopper extends StageProp implements IPlayStateScriptedClass if (animOffsets == null) animOffsets = [0, 0]; if ((animOffsets[0] == value[0]) && (animOffsets[1] == value[1])) return value; - var xDiff = animOffsets[0] - value[0]; - var yDiff = animOffsets[1] - value[1]; - - this.x += xDiff; - this.y += yDiff; - + _currentAnimOffset.set(value[0], value[1]); return animOffsets = value; } @@ -349,6 +350,20 @@ class Bopper extends StageProp implements IPlayStateScriptedClass return this.animation.curAnim.name; } + // override getScreenPosition (used by FlxSprite's draw method) to account for animation offsets. + override function getScreenPosition(?result:FlxPoint, ?camera:FlxCamera):FlxPoint + { + var output:FlxPoint = super.getScreenPosition(result, camera); + output -= _currentAnimOffset; + return output; + } + + override function destroy():Void + { + _currentAnimOffset = flixel.util.FlxDestroyUtil.put(_currentAnimOffset); + super.destroy(); + } + public function onPause(event:PauseScriptEvent) {} public function onResume(event:ScriptEvent) {} From f6334fb30b12b44635a9574587f7689d2f3beb28 Mon Sep 17 00:00:00 2001 From: Sword352 Date: Wed, 8 May 2024 22:18:41 +0200 Subject: [PATCH 03/28] Use `animOffsets` directly. --- source/funkin/play/stage/Bopper.hx | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/source/funkin/play/stage/Bopper.hx b/source/funkin/play/stage/Bopper.hx index 141a85c8f..5485edb3e 100644 --- a/source/funkin/play/stage/Bopper.hx +++ b/source/funkin/play/stage/Bopper.hx @@ -68,11 +68,6 @@ class Bopper extends StageProp implements IPlayStateScriptedClass return value; } - /** - * Internally used to define the animation offsets to apply. - */ - var _currentAnimOffset:FlxPoint = FlxPoint.get(); - /** * The offset of the character relative to the position specified by the stage. */ @@ -101,7 +96,6 @@ class Bopper extends StageProp implements IPlayStateScriptedClass if (animOffsets == null) animOffsets = [0, 0]; if ((animOffsets[0] == value[0]) && (animOffsets[1] == value[1])) return value; - _currentAnimOffset.set(value[0], value[1]); return animOffsets = value; } @@ -354,16 +348,11 @@ class Bopper extends StageProp implements IPlayStateScriptedClass override function getScreenPosition(?result:FlxPoint, ?camera:FlxCamera):FlxPoint { var output:FlxPoint = super.getScreenPosition(result, camera); - output -= _currentAnimOffset; + output.x -= animOffsets[0]; + output.y -= animOffsets[1]; return output; } - override function destroy():Void - { - _currentAnimOffset = flixel.util.FlxDestroyUtil.put(_currentAnimOffset); - super.destroy(); - } - public function onPause(event:PauseScriptEvent) {} public function onResume(event:ScriptEvent) {} From 6116ec3639b3720c3b2453be6a76adaa6998e447 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Fri, 12 Jul 2024 22:31:04 -0400 Subject: [PATCH 04/28] Some more fixes for offsets handling and stuffs --- source/funkin/play/PauseSubState.hx | 2 +- source/funkin/play/song/Song.hx | 3 ++- source/funkin/play/stage/Bopper.hx | 18 +++--------------- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/source/funkin/play/PauseSubState.hx b/source/funkin/play/PauseSubState.hx index d0c759b16..6f8908eea 100644 --- a/source/funkin/play/PauseSubState.hx +++ b/source/funkin/play/PauseSubState.hx @@ -306,7 +306,7 @@ class PauseSubState extends MusicBeatSubState metadataDifficulty.setFormat(Paths.font('vcr.ttf'), 32, FlxColor.WHITE, FlxTextAlign.RIGHT); if (PlayState.instance?.currentDifficulty != null) { - metadataDifficulty.text += PlayState.instance.currentDifficulty.toTitleCase(); + metadataDifficulty.text += PlayState.instance.currentDifficulty.replace('-', ' ').toTitleCase(); } metadataDifficulty.scrollFactor.set(0, 0); metadata.add(metadataDifficulty); diff --git a/source/funkin/play/song/Song.hx b/source/funkin/play/song/Song.hx index 91d35d8fa..4e9f70920 100644 --- a/source/funkin/play/song/Song.hx +++ b/source/funkin/play/song/Song.hx @@ -277,7 +277,8 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry Date: Thu, 18 Jul 2024 05:23:31 +0100 Subject: [PATCH 05/28] new stage names --- source/funkin/data/stage/StageRegistry.hx | 4 ++-- source/funkin/ui/debug/charting/ChartEditorState.hx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/funkin/data/stage/StageRegistry.hx b/source/funkin/data/stage/StageRegistry.hx index a03371296..fbb6f188e 100644 --- a/source/funkin/data/stage/StageRegistry.hx +++ b/source/funkin/data/stage/StageRegistry.hx @@ -93,8 +93,8 @@ class StageRegistry extends BaseRegistry public function listBaseGameStageIds():Array { return [ - "mainStage", "spookyMansion", "phillyTrain", "limoRide", "mallXmas", "mallEvil", "school", "schoolEvil", "tankmanBattlefield", "phillyStreets", - "phillyBlazin", + "mainStage", "spookyMansion", "phillyTrain", "phillyTrainErect", "limoRide", "mallXmas", "mallEvil", "school", "schoolEvil", "tankmanBattlefield", + "phillyStreets", "phillyBlazin", ]; } diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index f72cca77f..a4e0de61e 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -5703,9 +5703,9 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState { case 'mainStage': PlayStatePlaylist.campaignId = 'week1'; - case 'spookyMansion': + case 'spookyMansion' | 'spookyMansionErect': PlayStatePlaylist.campaignId = 'week2'; - case 'phillyTrain': + case 'phillyTrain' | 'phillyTrainErect': PlayStatePlaylist.campaignId = 'week3'; case 'limoRide': PlayStatePlaylist.campaignId = 'week4'; From ad93706b1df16f8191e839b6920da4e5e316c071 Mon Sep 17 00:00:00 2001 From: FabsTheFabs Date: Thu, 18 Jul 2024 05:23:37 +0100 Subject: [PATCH 06/28] adjust color shader --- .../graphics/shaders/AdjustColorShader.hx | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 source/funkin/graphics/shaders/AdjustColorShader.hx diff --git a/source/funkin/graphics/shaders/AdjustColorShader.hx b/source/funkin/graphics/shaders/AdjustColorShader.hx new file mode 100644 index 000000000..2b0970eeb --- /dev/null +++ b/source/funkin/graphics/shaders/AdjustColorShader.hx @@ -0,0 +1,55 @@ +package funkin.graphics.shaders; + +import flixel.addons.display.FlxRuntimeShader; +import funkin.Paths; +import openfl.utils.Assets; + +class AdjustColorShader extends FlxRuntimeShader +{ + public var hue(default, set):Float; + public var saturation(default, set):Float; + public var brightness(default, set):Float; + public var contrast(default, set):Float; + + public function new() + { + super(Assets.getText(Paths.frag('adjustColor'))); + // FlxG.debugger.addTrackerProfile(new TrackerProfile(HSVShader, ['hue', 'saturation', 'brightness', 'contrast'])); + hue = 0; + saturation = 0; + brightness = 0; + contrast = 0; + } + + function set_hue(value:Float):Float + { + this.setFloat('hue', value); + this.hue = value; + + return this.hue; + } + + function set_saturation(value:Float):Float + { + this.setFloat('saturation', value); + this.saturation = value; + + return this.saturation; + } + + function set_brightness(value:Float):Float + { + this.setFloat('brightness', value); + this.brightness = value; + + return this.brightness; + } + + function set_contrast(value:Float):Float + { + this.setFloat('contrast', value); + this.contrast = value; + + return this.contrast; + } +} From 4bcfbc957f82726973b4aa1428b285d1132a19e7 Mon Sep 17 00:00:00 2001 From: FabsTheFabs Date: Thu, 18 Jul 2024 05:24:15 +0100 Subject: [PATCH 07/28] assets submod --- assets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets b/assets index 005c96f85..68bf145d5 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 005c96f85f4304865acb196e7cc4d6d83f9d76d8 +Subproject commit 68bf145d5786b2c3e4539a46727da67bef1fd039 From a0ab216617b16d87ed363a590979b4cdc8879012 Mon Sep 17 00:00:00 2001 From: FabsTheFabs Date: Thu, 18 Jul 2024 06:04:19 +0100 Subject: [PATCH 08/28] merged rain shader stuff from 'feature/week2-erect-bg-rain' --- .../shaders/RuntimePostEffectShader.hx | 31 +++++++++++++++++++ .../graphics/shaders/RuntimeRainShader.hx | 8 +++++ 2 files changed, 39 insertions(+) diff --git a/source/funkin/graphics/shaders/RuntimePostEffectShader.hx b/source/funkin/graphics/shaders/RuntimePostEffectShader.hx index 9f49da075..d39f57efe 100644 --- a/source/funkin/graphics/shaders/RuntimePostEffectShader.hx +++ b/source/funkin/graphics/shaders/RuntimePostEffectShader.hx @@ -2,6 +2,7 @@ package funkin.graphics.shaders; import flixel.FlxCamera; import flixel.FlxG; +import flixel.graphics.frames.FlxFrame; import flixel.addons.display.FlxRuntimeShader; import lime.graphics.opengl.GLProgram; import lime.utils.Log; @@ -32,6 +33,9 @@ class RuntimePostEffectShader extends FlxRuntimeShader // equals (camera.viewLeft, camera.viewTop, camera.viewRight, camera.viewBottom) uniform vec4 uCameraBounds; + // equals (frame.left, frame.top, frame.right, frame.bottom) + uniform vec4 uFrameBounds; + // screen coord -> world coord conversion // returns world coord in px vec2 screenToWorld(vec2 screenCoord) { @@ -56,6 +60,25 @@ class RuntimePostEffectShader extends FlxRuntimeShader return (worldCoord - offset) / scale; } + // screen coord -> frame coord conversion + // returns normalized frame coord + vec2 screenToFrame(vec2 screenCoord) { + float left = uFrameBounds.x; + float top = uFrameBounds.y; + float right = uFrameBounds.z; + float bottom = uFrameBounds.w; + float width = right - left; + float height = bottom - top; + + float clampedX = clamp(screenCoord.x, left, right); + float clampedY = clamp(screenCoord.y, top, bottom); + + return vec2( + (clampedX - left) / (width), + (clampedY - top) / (height) + ); + } + // internally used to get the maximum `openfl_TextureCoordv` vec2 bitmapCoordScale() { return openfl_TextureCoordv / screenCoord; @@ -80,6 +103,8 @@ class RuntimePostEffectShader extends FlxRuntimeShader { super(fragmentSource, null, glVersion); uScreenResolution.value = [FlxG.width, FlxG.height]; + uCameraBounds.value = [0, 0, FlxG.width, FlxG.height]; + uFrameBounds.value = [0, 0, FlxG.width, FlxG.height]; } // basically `updateViewInfo(FlxG.width, FlxG.height, FlxG.camera)` is good @@ -89,6 +114,12 @@ class RuntimePostEffectShader extends FlxRuntimeShader uCameraBounds.value = [camera.viewLeft, camera.viewTop, camera.viewRight, camera.viewBottom]; } + public function updateFrameInfo(frame:FlxFrame) + { + // NOTE: uv.width is actually the right pos and uv.height is the bottom pos + uFrameBounds.value = [frame.uv.x, frame.uv.y, frame.uv.width, frame.uv.height]; + } + override function __createGLProgram(vertexSource:String, fragmentSource:String):GLProgram { try diff --git a/source/funkin/graphics/shaders/RuntimeRainShader.hx b/source/funkin/graphics/shaders/RuntimeRainShader.hx index 239276bbe..68a203179 100644 --- a/source/funkin/graphics/shaders/RuntimeRainShader.hx +++ b/source/funkin/graphics/shaders/RuntimeRainShader.hx @@ -32,6 +32,14 @@ class RuntimeRainShader extends RuntimePostEffectShader return time = value; } + public var spriteMode(default, set):Bool = false; + + function set_spriteMode(value:Bool):Bool + { + this.setBool('uSpriteMode', value); + return spriteMode = value; + } + // The scale of the rain depends on the world coordinate system, so higher resolution makes // the raindrops smaller. This parameter can be used to adjust the total scale of the scene. // The size of the raindrops is proportional to the value of this parameter. From 563905ebd42810550904a3c4c894bc24afbc4f30 Mon Sep 17 00:00:00 2001 From: FabsTheFabs Date: Thu, 18 Jul 2024 06:04:32 +0100 Subject: [PATCH 09/28] assets submod --- assets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets b/assets index 68bf145d5..cfd67caa6 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 68bf145d5786b2c3e4539a46727da67bef1fd039 +Subproject commit cfd67caa688465b4a282837434832c107b661b04 From 0e7fad090baae898cb7d95aca6a43d0604fc74db Mon Sep 17 00:00:00 2001 From: anysad Date: Sat, 13 Jul 2024 22:45:58 +0300 Subject: [PATCH 10/28] custom popups and countdowns yay!!! --- assets | 2 +- source/funkin/play/Countdown.hx | 158 ++++++++++---------- source/funkin/play/PlayState.hx | 6 +- source/funkin/play/components/PopUpStuff.hx | 59 ++++++-- 4 files changed, 125 insertions(+), 100 deletions(-) diff --git a/assets b/assets index aa1231e8c..3a9e05108 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit aa1231e8cf2990bb902eac3b37815c010fa9919a +Subproject commit 3a9e0510841533f96228609dcd50f2515443bb90 diff --git a/source/funkin/play/Countdown.hx b/source/funkin/play/Countdown.hx index 55c2a8992..542cb067c 100644 --- a/source/funkin/play/Countdown.hx +++ b/source/funkin/play/Countdown.hx @@ -11,6 +11,7 @@ import funkin.modding.events.ScriptEvent.CountdownScriptEvent; import flixel.util.FlxTimer; import funkin.util.EaseUtil; import funkin.audio.FunkinSound; +import openfl.utils.Assets; class Countdown { @@ -19,6 +20,20 @@ class Countdown */ public static var countdownStep(default, null):CountdownStep = BEFORE; + /** + * Which alternate countdown sound effect to use. + * You can set this via script. + * For example, in Week 6 it is `-pixel`. + */ + public static var soundSuffix:String = ''; + + /** + * Which alternate graphic on countdown to use. + * You can set this via script. + * For example, in Week 6 it is `-pixel`. + */ + public static var graphicSuffix:String = ''; + /** * The currently running countdown. This will be null if there is no countdown running. */ @@ -30,7 +45,7 @@ class Countdown * This will automatically stop and restart the countdown if it is already running. * @returns `false` if the countdown was cancelled by a script. */ - public static function performCountdown(isPixelStyle:Bool):Bool + public static function performCountdown():Bool { countdownStep = BEFORE; var cancelled:Bool = propagateCountdownEvent(countdownStep); @@ -65,10 +80,10 @@ class Countdown // PlayState.instance.dispatchEvent(new SongTimeScriptEvent(SONG_BEAT_HIT, 0, 0)); // Countdown graphic. - showCountdownGraphic(countdownStep, isPixelStyle); + showCountdownGraphic(countdownStep, graphicSuffix.toLowerCase().contains('pixel')); // Countdown sound. - playCountdownSound(countdownStep, isPixelStyle); + playCountdownSound(countdownStep); // Event handling bullshit. var cancelled:Bool = propagateCountdownEvent(countdownStep); @@ -177,55 +192,33 @@ class Countdown } /** - * Retrieves the graphic to use for this step of the countdown. - * TODO: Make this less dumb. Unhardcode it? Use modules? Use notestyles? - * - * This is public so modules can do lol funny shit. + * Reset the countdown configuration to the default. */ - public static function showCountdownGraphic(index:CountdownStep, isPixelStyle:Bool):Void + public static function reset() + { + soundSuffix = ''; + graphicSuffix = ''; + } + + /** + * Retrieves the graphic to use for this step of the countdown. + */ + public static function showCountdownGraphic(index:CountdownStep, isGraphicPixel:Bool):Void { var spritePath:String = null; - - var fadeEase = FlxEase.cubeInOut; - - if (isPixelStyle) - { - fadeEase = EaseUtil.stepped(8); - switch (index) - { - case TWO: - spritePath = 'weeb/pixelUI/ready-pixel'; - case ONE: - spritePath = 'weeb/pixelUI/set-pixel'; - case GO: - spritePath = 'weeb/pixelUI/date-pixel'; - default: - // null - } - } - else - { - switch (index) - { - case TWO: - spritePath = 'ready'; - case ONE: - spritePath = 'set'; - case GO: - spritePath = 'go'; - default: - // null - } - } + spritePath = resolveGraphicPath(graphicSuffix, index); if (spritePath == null) return; var countdownSprite:FunkinSprite = FunkinSprite.create(spritePath); countdownSprite.scrollFactor.set(0, 0); - if (isPixelStyle) countdownSprite.setGraphicSize(Std.int(countdownSprite.width * Constants.PIXEL_ART_SCALE)); + if (isGraphicPixel) countdownSprite.setGraphicSize(Std.int(countdownSprite.width * Constants.PIXEL_ART_SCALE)); - countdownSprite.antialiasing = !isPixelStyle; + var fadeEase = FlxEase.cubeInOut; + if (isGraphicPixel) fadeEase = EaseUtil.stepped(8); + + countdownSprite.antialiasing = !isGraphicPixel; countdownSprite.updateHitbox(); countdownSprite.screenCenter(); @@ -247,52 +240,55 @@ class Countdown PlayState.instance.add(countdownSprite); } + static function resolveGraphicPath(suffix:String, index:CountdownStep):Null + { + var basePath:String = 'ui/countdown/'; + var indexString:String = null; + switch (index) + { + case TWO: + indexString = 'ready'; + case ONE: + indexString = 'set'; + case GO: + indexString = 'go'; + default: + // null + } + basePath += indexString; + var spritePath:String = basePath + suffix; + while (!Assets.exists(Paths.image(spritePath)) && suffix.length > 0) + { + suffix = suffix.split('-').slice(0, -1).join('-'); + spritePath = basePath + suffix; + } + if (!Assets.exists(Paths.image(spritePath))) return null; + trace('Resolved sprite path: ' + Paths.image(spritePath)); + return spritePath; + } + /** * Retrieves the sound file to use for this step of the countdown. - * TODO: Make this less dumb. Unhardcode it? Use modules? Use notestyles? - * - * This is public so modules can do lol funny shit. */ - public static function playCountdownSound(index:CountdownStep, isPixelStyle:Bool):Void + public static function playCountdownSound(index:CountdownStep):Void { - var soundPath:String = null; + FunkinSound.playOnce(resolveSoundPath(soundSuffix, index), Constants.COUNTDOWN_VOLUME); + } - if (isPixelStyle) + static function resolveSoundPath(suffix:String, step:CountdownStep):Null + { + var basePath:String = 'gameplay/countdown/intro'; + if (step != CountdownStep.BEFORE || step != CountdownStep.AFTER) basePath += step; + + var soundPath:String = Paths.sound(basePath + suffix); + while (!Assets.exists(soundPath) && suffix.length > 0) { - switch (index) - { - case THREE: - soundPath = 'intro3-pixel'; - case TWO: - soundPath = 'intro2-pixel'; - case ONE: - soundPath = 'intro1-pixel'; - case GO: - soundPath = 'introGo-pixel'; - default: - // null - } + suffix = suffix.split('-').slice(0, -1).join('-'); + soundPath = Paths.sound(basePath + suffix); } - else - { - switch (index) - { - case THREE: - soundPath = 'intro3'; - case TWO: - soundPath = 'intro2'; - case ONE: - soundPath = 'intro1'; - case GO: - soundPath = 'introGo'; - default: - // null - } - } - - if (soundPath == null) return; - - FunkinSound.playOnce(Paths.sound(soundPath), Constants.COUNTDOWN_VOLUME); + if (!Assets.exists(soundPath)) return null; + trace('Resolved sound path: ' + soundPath); + return soundPath; } public static function decrement(step:CountdownStep):CountdownStep diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 32b6e7b62..384c28056 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -900,7 +900,7 @@ class PlayState extends MusicBeatSubState health = Constants.HEALTH_STARTING; songScore = 0; Highscore.tallies.combo = 0; - Countdown.performCountdown(currentStageId.startsWith('school')); + Countdown.performCountdown(); needsReset = false; } @@ -1857,7 +1857,7 @@ class PlayState extends MusicBeatSubState public function startCountdown():Void { // If Countdown.performCountdown returns false, then the countdown was canceled by a script. - var result:Bool = Countdown.performCountdown(currentStageId.startsWith('school')); + var result:Bool = Countdown.performCountdown(); if (!result) return; isInCutscene = false; @@ -3004,6 +3004,8 @@ class PlayState extends MusicBeatSubState GameOverSubState.reset(); PauseSubState.reset(); + Countdown.reset(); + PopUpStuff.reset(); // Clear the static reference to this state. instance = null; diff --git a/source/funkin/play/components/PopUpStuff.hx b/source/funkin/play/components/PopUpStuff.hx index 1bdfd98a8..4ae425cb6 100644 --- a/source/funkin/play/components/PopUpStuff.hx +++ b/source/funkin/play/components/PopUpStuff.hx @@ -8,25 +8,51 @@ import funkin.graphics.FunkinSprite; import funkin.play.PlayState; import funkin.util.TimerUtil; import funkin.util.EaseUtil; +import openfl.utils.Assets; class PopUpStuff extends FlxTypedGroup { public var offsets:Array = [0, 0]; + /** + * Which alternate graphic on popup to use. + * You can set this via script. + * For example, in Week 6 it is `-pixel`. + */ + public static var graphicSuffix:String = ''; + override public function new() { super(); } - public function displayRating(daRating:String):Void + static function resolveGraphicPath(suffix:String, index:String):Null + { + var folder:String; + if (suffix != '') folder = suffix.substring(0, suffix.indexOf("-")) + suffix.substring(suffix.indexOf("-") + 1); + else + folder = 'normal'; + var basePath:String = 'gameplay/popup/$folder/$index'; + var spritePath:String = basePath + suffix; + trace(spritePath); + while (!Assets.exists(Paths.image(spritePath)) && suffix.length > 0) + { + suffix = suffix.split('-').slice(0, -1).join('-'); + spritePath = basePath + suffix; + } + if (!Assets.exists(Paths.image(spritePath))) return null; + return spritePath; + } + + public function displayRating(daRating:String) { var perfStart:Float = TimerUtil.start(); if (daRating == null) daRating = "good"; - var ratingPath:String = daRating; + var ratingPath:String = resolveGraphicPath(graphicSuffix, daRating); - if (PlayState.instance.currentStageId.startsWith('school')) ratingPath = "weeb/pixelUI/" + ratingPath + "-pixel"; + // if (PlayState.instance.currentStageId.startsWith('school')) ratingPath = "weeb/pixelUI/" + ratingPath + "-pixel"; var rating:FunkinSprite = FunkinSprite.create(0, 0, ratingPath); rating.scrollFactor.set(0.2, 0.2); @@ -43,7 +69,7 @@ class PopUpStuff extends FlxTypedGroup var fadeEase = null; - if (PlayState.instance.currentStageId.startsWith('school')) + if (graphicSuffix.toLowerCase().contains('pixel')) { rating.setGraphicSize(Std.int(rating.width * Constants.PIXEL_ART_SCALE * 0.7)); rating.antialiasing = false; @@ -80,15 +106,8 @@ class PopUpStuff extends FlxTypedGroup if (combo == null) combo = 0; - var pixelShitPart1:String = ""; - var pixelShitPart2:String = ''; - - if (PlayState.instance.currentStageId.startsWith('school')) - { - pixelShitPart1 = 'weeb/pixelUI/'; - pixelShitPart2 = '-pixel'; - } - var comboSpr:FunkinSprite = FunkinSprite.create(pixelShitPart1 + 'combo' + pixelShitPart2); + var comboPath:String = resolveGraphicPath(graphicSuffix, Std.string(combo)); + var comboSpr:FunkinSprite = FunkinSprite.create(comboPath); comboSpr.y = (FlxG.camera.height * 0.44) + offsets[1]; comboSpr.x = (FlxG.width * 0.507) + offsets[0]; // comboSpr.x -= FlxG.camera.scroll.x * 0.2; @@ -101,7 +120,7 @@ class PopUpStuff extends FlxTypedGroup var fadeEase = null; - if (PlayState.instance.currentStageId.startsWith('school')) + if (graphicSuffix.toLowerCase().contains('pixel')) { comboSpr.setGraphicSize(Std.int(comboSpr.width * Constants.PIXEL_ART_SCALE * 1)); comboSpr.antialiasing = false; @@ -142,9 +161,9 @@ class PopUpStuff extends FlxTypedGroup var daLoop:Int = 1; for (i in seperatedScore) { - var numScore:FunkinSprite = FunkinSprite.create(0, comboSpr.y, pixelShitPart1 + 'num' + Std.int(i) + pixelShitPart2); + var numScore:FunkinSprite = FunkinSprite.create(0, comboSpr.y, resolveGraphicPath(graphicSuffix, 'num' + Std.int(i))); - if (PlayState.instance.currentStageId.startsWith('school')) + if (graphicSuffix.toLowerCase().contains('pixel')) { numScore.setGraphicSize(Std.int(numScore.width * Constants.PIXEL_ART_SCALE * 1)); numScore.antialiasing = false; @@ -182,4 +201,12 @@ class PopUpStuff extends FlxTypedGroup return combo; } + + /** + * Reset the popup configuration to the default. + */ + public static function reset() + { + graphicSuffix = ''; + } } From bf1d4031af0c60287cbfd700a4597a2dc8fb9829 Mon Sep 17 00:00:00 2001 From: anysad Date: Sat, 13 Jul 2024 23:08:16 +0300 Subject: [PATCH 11/28] remove trace --- source/funkin/play/components/PopUpStuff.hx | 1 - 1 file changed, 1 deletion(-) diff --git a/source/funkin/play/components/PopUpStuff.hx b/source/funkin/play/components/PopUpStuff.hx index 4ae425cb6..971ed1064 100644 --- a/source/funkin/play/components/PopUpStuff.hx +++ b/source/funkin/play/components/PopUpStuff.hx @@ -34,7 +34,6 @@ class PopUpStuff extends FlxTypedGroup folder = 'normal'; var basePath:String = 'gameplay/popup/$folder/$index'; var spritePath:String = basePath + suffix; - trace(spritePath); while (!Assets.exists(Paths.image(spritePath)) && suffix.length > 0) { suffix = suffix.split('-').slice(0, -1).join('-'); From dc9dbe84fa68fd988eeca6666f3d199c92a3f945 Mon Sep 17 00:00:00 2001 From: anysad Date: Sat, 13 Jul 2024 23:29:26 +0300 Subject: [PATCH 12/28] cache textures at their new locations! --- source/funkin/ui/transition/LoadingState.hx | 33 ++++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/source/funkin/ui/transition/LoadingState.hx b/source/funkin/ui/transition/LoadingState.hx index 0f2ce1076..b4987ff27 100644 --- a/source/funkin/ui/transition/LoadingState.hx +++ b/source/funkin/ui/transition/LoadingState.hx @@ -291,17 +291,28 @@ class LoadingState extends MusicBeatSubState FunkinSprite.preparePurgeCache(); FunkinSprite.cacheTexture(Paths.image('healthBar')); FunkinSprite.cacheTexture(Paths.image('menuDesat')); - FunkinSprite.cacheTexture(Paths.image('combo')); - FunkinSprite.cacheTexture(Paths.image('num0')); - FunkinSprite.cacheTexture(Paths.image('num1')); - FunkinSprite.cacheTexture(Paths.image('num2')); - FunkinSprite.cacheTexture(Paths.image('num3')); - FunkinSprite.cacheTexture(Paths.image('num4')); - FunkinSprite.cacheTexture(Paths.image('num5')); - FunkinSprite.cacheTexture(Paths.image('num6')); - FunkinSprite.cacheTexture(Paths.image('num7')); - FunkinSprite.cacheTexture(Paths.image('num8')); - FunkinSprite.cacheTexture(Paths.image('num9')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/combo')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num0')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num1')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num2')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num3')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num4')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num5')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num6')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num7')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num8')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num9')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/combo-pixel')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num0-pixel')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num1-pixel')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num2-pixel')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num3-pixel')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num4-pixel')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num5-pixel')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num6-pixel')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num7-pixel')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num8-pixel')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num9-pixel')); FunkinSprite.cacheTexture(Paths.image('notes', 'shared')); FunkinSprite.cacheTexture(Paths.image('noteSplashes', 'shared')); FunkinSprite.cacheTexture(Paths.image('noteStrumline', 'shared')); From d5a53855d35458fbf4ceb1ab7ad09436d650f9c6 Mon Sep 17 00:00:00 2001 From: anysad Date: Sat, 13 Jul 2024 23:39:56 +0300 Subject: [PATCH 13/28] how the hell did I miss these? --- source/funkin/ui/transition/LoadingState.hx | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/source/funkin/ui/transition/LoadingState.hx b/source/funkin/ui/transition/LoadingState.hx index b4987ff27..3e9dec96b 100644 --- a/source/funkin/ui/transition/LoadingState.hx +++ b/source/funkin/ui/transition/LoadingState.hx @@ -317,13 +317,20 @@ class LoadingState extends MusicBeatSubState FunkinSprite.cacheTexture(Paths.image('noteSplashes', 'shared')); FunkinSprite.cacheTexture(Paths.image('noteStrumline', 'shared')); FunkinSprite.cacheTexture(Paths.image('NOTE_hold_assets')); - FunkinSprite.cacheTexture(Paths.image('ready', 'shared')); - FunkinSprite.cacheTexture(Paths.image('set', 'shared')); - FunkinSprite.cacheTexture(Paths.image('go', 'shared')); - FunkinSprite.cacheTexture(Paths.image('sick', 'shared')); - FunkinSprite.cacheTexture(Paths.image('good', 'shared')); - FunkinSprite.cacheTexture(Paths.image('bad', 'shared')); - FunkinSprite.cacheTexture(Paths.image('shit', 'shared')); + FunkinSprite.cacheTexture(Paths.image('ui/countdown/ready', 'shared')); + FunkinSprite.cacheTexture(Paths.image('ui/countdown/set', 'shared')); + FunkinSprite.cacheTexture(Paths.image('ui/countdown/go', 'shared')); + FunkinSprite.cacheTexture(Paths.image('ui/countdown/ready-pixel', 'shared')); + FunkinSprite.cacheTexture(Paths.image('ui/countdown/set-pixel', 'shared')); + FunkinSprite.cacheTexture(Paths.image('ui/countdown/go-pixel', 'shared')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/sick')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/good')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/bad')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/shit')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/sick-pixel')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/good-pixel')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/bad-pixel')); + FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/shit-pixel')); FunkinSprite.cacheTexture(Paths.image('miss', 'shared')); // TODO: remove this // List all image assets in the level's library. From d3209e57b7f177df969a5610b16f4bd57163ffda Mon Sep 17 00:00:00 2001 From: anysad Date: Tue, 16 Jul 2024 20:53:12 +0300 Subject: [PATCH 14/28] goodbye scripts, hello notestyles! --- source/funkin/play/Countdown.hx | 98 +++++++++++++-------- source/funkin/play/components/PopUpStuff.hx | 48 ++++++---- source/funkin/ui/transition/LoadingState.hx | 73 +++++++-------- source/funkin/util/Constants.hx | 5 ++ 4 files changed, 131 insertions(+), 93 deletions(-) diff --git a/source/funkin/play/Countdown.hx b/source/funkin/play/Countdown.hx index 542cb067c..139b6cacd 100644 --- a/source/funkin/play/Countdown.hx +++ b/source/funkin/play/Countdown.hx @@ -12,6 +12,8 @@ import flixel.util.FlxTimer; import funkin.util.EaseUtil; import funkin.audio.FunkinSound; import openfl.utils.Assets; +import funkin.data.notestyle.NoteStyleRegistry; +import funkin.play.notes.notestyle.NoteStyle; class Countdown { @@ -21,9 +23,9 @@ class Countdown public static var countdownStep(default, null):CountdownStep = BEFORE; /** - * Which alternate countdown sound effect to use. - * You can set this via script. - * For example, in Week 6 it is `-pixel`. + * Which alternate graphic/sound on countdown to use. + * This is set via the current notestyle. + * For example, in Week 6 it is `pixel`. */ public static var soundSuffix:String = ''; @@ -34,6 +36,10 @@ class Countdown */ public static var graphicSuffix:String = ''; + static var noteStyle:NoteStyle; + + static var isPixel:Bool = false; + /** * The currently running countdown. This will be null if there is no countdown running. */ @@ -63,6 +69,12 @@ class Countdown // @:privateAccess // PlayState.instance.dispatchEvent(new SongTimeScriptEvent(SONG_BEAT_HIT, 0, 0)); + var fetchedNoteStyle:NoteStyle = NoteStyleRegistry.instance.fetchEntry(PlayState.instance.currentChart.noteStyle); + if (fetchedNoteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault(); + else + noteStyle = fetchedNoteStyle; + if (noteStyle._data.assets.note.isPixel) isPixel = true; + // The timer function gets called based on the beat of the song. countdownTimer = new FlxTimer(); @@ -80,10 +92,10 @@ class Countdown // PlayState.instance.dispatchEvent(new SongTimeScriptEvent(SONG_BEAT_HIT, 0, 0)); // Countdown graphic. - showCountdownGraphic(countdownStep, graphicSuffix.toLowerCase().contains('pixel')); + showCountdownGraphic(countdownStep, noteStyle, isPixel); // Countdown sound. - playCountdownSound(countdownStep); + playCountdownSound(countdownStep, noteStyle); // Event handling bullshit. var cancelled:Bool = propagateCountdownEvent(countdownStep); @@ -196,17 +208,31 @@ class Countdown */ public static function reset() { - soundSuffix = ''; - graphicSuffix = ''; + noteStyle = NoteStyleRegistry.instance.fetchDefault(); + isPixel = false; } /** * Retrieves the graphic to use for this step of the countdown. */ - public static function showCountdownGraphic(index:CountdownStep, isGraphicPixel:Bool):Void + public static function showCountdownGraphic(index:CountdownStep, noteStyle:NoteStyle, isGraphicPixel:Bool):Void { + var indexString:String = null; + switch (index) + { + case TWO: + indexString = 'ready'; + case ONE: + indexString = 'set'; + case GO: + indexString = 'go'; + default: + // null + } + if (indexString == null) return; + var spritePath:String = null; - spritePath = resolveGraphicPath(graphicSuffix, index); + spritePath = resolveGraphicPath(noteStyle, indexString); if (spritePath == null) return; @@ -214,6 +240,8 @@ class Countdown countdownSprite.scrollFactor.set(0, 0); if (isGraphicPixel) countdownSprite.setGraphicSize(Std.int(countdownSprite.width * Constants.PIXEL_ART_SCALE)); + else + countdownSprite.setGraphicSize(Std.int(countdownSprite.width * 0.7)); var fadeEase = FlxEase.cubeInOut; if (isGraphicPixel) fadeEase = EaseUtil.stepped(8); @@ -223,6 +251,8 @@ class Countdown countdownSprite.updateHitbox(); countdownSprite.screenCenter(); + countdownSprite.cameras = [PlayState.instance.camHUD]; + // Fade sprite in, then out, then destroy it. FlxTween.tween(countdownSprite, {y: countdownSprite.y += 100}, Conductor.instance.beatLengthMs / 1000, { @@ -240,29 +270,19 @@ class Countdown PlayState.instance.add(countdownSprite); } - static function resolveGraphicPath(suffix:String, index:CountdownStep):Null + static function resolveGraphicPath(noteStyle:NoteStyle, index:String):Null { var basePath:String = 'ui/countdown/'; - var indexString:String = null; - switch (index) + + var spritePath:String = basePath + noteStyle.id + '/$index'; + // If nothing is found, revert it to default notestyle skin + if (!Assets.exists(Paths.image(spritePath))) { - case TWO: - indexString = 'ready'; - case ONE: - indexString = 'set'; - case GO: - indexString = 'go'; - default: - // null + if (!isPixel) spritePath = basePath + Constants.DEFAULT_NOTE_STYLE + '/$index'; + else + spritePath = basePath + Constants.DEFAULT_PIXEL_NOTE_STYLE + '/$index'; } - basePath += indexString; - var spritePath:String = basePath + suffix; - while (!Assets.exists(Paths.image(spritePath)) && suffix.length > 0) - { - suffix = suffix.split('-').slice(0, -1).join('-'); - spritePath = basePath + suffix; - } - if (!Assets.exists(Paths.image(spritePath))) return null; + trace('Resolved sprite path: ' + Paths.image(spritePath)); return spritePath; } @@ -270,23 +290,25 @@ class Countdown /** * Retrieves the sound file to use for this step of the countdown. */ - public static function playCountdownSound(index:CountdownStep):Void + public static function playCountdownSound(step:CountdownStep, noteStyle:NoteStyle):Void { - FunkinSound.playOnce(resolveSoundPath(soundSuffix, index), Constants.COUNTDOWN_VOLUME); + return FunkinSound.playOnce(Paths.sound(resolveSoundPath(noteStyle, step)), Constants.COUNTDOWN_VOLUME); } - static function resolveSoundPath(suffix:String, step:CountdownStep):Null + static function resolveSoundPath(noteStyle:NoteStyle, step:CountdownStep):Null { - var basePath:String = 'gameplay/countdown/intro'; - if (step != CountdownStep.BEFORE || step != CountdownStep.AFTER) basePath += step; + if (step == CountdownStep.BEFORE || step == CountdownStep.AFTER) return null; + var basePath:String = 'gameplay/countdown/'; - var soundPath:String = Paths.sound(basePath + suffix); - while (!Assets.exists(soundPath) && suffix.length > 0) + var soundPath:String = basePath + noteStyle.id + '/intro$step'; + // If nothing is found, revert it to default notestyle sound + if (!Assets.exists(Paths.sound(soundPath))) { - suffix = suffix.split('-').slice(0, -1).join('-'); - soundPath = Paths.sound(basePath + suffix); + if (!isPixel) soundPath = basePath + Constants.DEFAULT_NOTE_STYLE + '/intro$step'; + else + soundPath = basePath + Constants.DEFAULT_PIXEL_NOTE_STYLE + '/intro$step'; } - if (!Assets.exists(soundPath)) return null; + trace('Resolved sound path: ' + soundPath); return soundPath; } diff --git a/source/funkin/play/components/PopUpStuff.hx b/source/funkin/play/components/PopUpStuff.hx index 971ed1064..2bd2bf4db 100644 --- a/source/funkin/play/components/PopUpStuff.hx +++ b/source/funkin/play/components/PopUpStuff.hx @@ -9,6 +9,8 @@ import funkin.play.PlayState; import funkin.util.TimerUtil; import funkin.util.EaseUtil; import openfl.utils.Assets; +import funkin.data.notestyle.NoteStyleRegistry; +import funkin.play.notes.notestyle.NoteStyle; class PopUpStuff extends FlxTypedGroup { @@ -16,30 +18,37 @@ class PopUpStuff extends FlxTypedGroup /** * Which alternate graphic on popup to use. - * You can set this via script. - * For example, in Week 6 it is `-pixel`. + * This is set via the current notestyle. + * For example, in Week 6 it is `pixel`. */ - public static var graphicSuffix:String = ''; + static var noteStyle:NoteStyle; + + static var isPixel:Bool = false; override public function new() { super(); + + var fetchedNoteStyle:NoteStyle = NoteStyleRegistry.instance.fetchEntry(PlayState.instance.currentChart.noteStyle); + if (fetchedNoteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault(); + else + noteStyle = fetchedNoteStyle; + if (noteStyle._data.assets.note.isPixel) isPixel = true; } - static function resolveGraphicPath(suffix:String, index:String):Null + static function resolveGraphicPath(noteStyle:NoteStyle, index:String):Null { - var folder:String; - if (suffix != '') folder = suffix.substring(0, suffix.indexOf("-")) + suffix.substring(suffix.indexOf("-") + 1); - else - folder = 'normal'; - var basePath:String = 'gameplay/popup/$folder/$index'; - var spritePath:String = basePath + suffix; - while (!Assets.exists(Paths.image(spritePath)) && suffix.length > 0) + var basePath:String = 'ui/popup/'; + + var spritePath:String = basePath + noteStyle.id + '/$index'; + // If nothing is found, revert it to default notestyle skin + if (!Assets.exists(Paths.image(spritePath))) { - suffix = suffix.split('-').slice(0, -1).join('-'); - spritePath = basePath + suffix; + if (!isPixel) spritePath = basePath + Constants.DEFAULT_NOTE_STYLE + '/$index'; + else + spritePath = basePath + Constants.DEFAULT_PIXEL_NOTE_STYLE + '/$index'; } - if (!Assets.exists(Paths.image(spritePath))) return null; + return spritePath; } @@ -49,7 +58,7 @@ class PopUpStuff extends FlxTypedGroup if (daRating == null) daRating = "good"; - var ratingPath:String = resolveGraphicPath(graphicSuffix, daRating); + var ratingPath:String = resolveGraphicPath(noteStyle, daRating); // if (PlayState.instance.currentStageId.startsWith('school')) ratingPath = "weeb/pixelUI/" + ratingPath + "-pixel"; @@ -68,7 +77,7 @@ class PopUpStuff extends FlxTypedGroup var fadeEase = null; - if (graphicSuffix.toLowerCase().contains('pixel')) + if (isPixel) { rating.setGraphicSize(Std.int(rating.width * Constants.PIXEL_ART_SCALE * 0.7)); rating.antialiasing = false; @@ -105,7 +114,7 @@ class PopUpStuff extends FlxTypedGroup if (combo == null) combo = 0; - var comboPath:String = resolveGraphicPath(graphicSuffix, Std.string(combo)); + var comboPath:String = resolveGraphicPath(noteStyle, 'combo'); var comboSpr:FunkinSprite = FunkinSprite.create(comboPath); comboSpr.y = (FlxG.camera.height * 0.44) + offsets[1]; comboSpr.x = (FlxG.width * 0.507) + offsets[0]; @@ -160,7 +169,7 @@ class PopUpStuff extends FlxTypedGroup var daLoop:Int = 1; for (i in seperatedScore) { - var numScore:FunkinSprite = FunkinSprite.create(0, comboSpr.y, resolveGraphicPath(graphicSuffix, 'num' + Std.int(i))); + var numScore:FunkinSprite = FunkinSprite.create(0, comboSpr.y, resolveGraphicPath(noteStyle, 'num' + Std.int(i))); if (graphicSuffix.toLowerCase().contains('pixel')) { @@ -206,6 +215,7 @@ class PopUpStuff extends FlxTypedGroup */ public static function reset() { - graphicSuffix = ''; + noteStyle = NoteStyleRegistry.instance.fetchDefault(); + isPixel = false; } } diff --git a/source/funkin/ui/transition/LoadingState.hx b/source/funkin/ui/transition/LoadingState.hx index 3e9dec96b..d48ca1c0b 100644 --- a/source/funkin/ui/transition/LoadingState.hx +++ b/source/funkin/ui/transition/LoadingState.hx @@ -291,46 +291,47 @@ class LoadingState extends MusicBeatSubState FunkinSprite.preparePurgeCache(); FunkinSprite.cacheTexture(Paths.image('healthBar')); FunkinSprite.cacheTexture(Paths.image('menuDesat')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/combo')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num0')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num1')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num2')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num3')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num4')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num5')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num6')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num7')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num8')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/num9')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/combo-pixel')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num0-pixel')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num1-pixel')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num2-pixel')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num3-pixel')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num4-pixel')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num5-pixel')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num6-pixel')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num7-pixel')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num8-pixel')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/num9-pixel')); + // Lord have mercy on me and this caching -anysad + FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/combo')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num0')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num1')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num2')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num3')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num4')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num5')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num6')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num7')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num8')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/funkin/num9')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/combo')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num0')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num1')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num2')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num3')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num4')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num5')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num6')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num7')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num8')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/num9')); FunkinSprite.cacheTexture(Paths.image('notes', 'shared')); FunkinSprite.cacheTexture(Paths.image('noteSplashes', 'shared')); FunkinSprite.cacheTexture(Paths.image('noteStrumline', 'shared')); FunkinSprite.cacheTexture(Paths.image('NOTE_hold_assets')); - FunkinSprite.cacheTexture(Paths.image('ui/countdown/ready', 'shared')); - FunkinSprite.cacheTexture(Paths.image('ui/countdown/set', 'shared')); - FunkinSprite.cacheTexture(Paths.image('ui/countdown/go', 'shared')); - FunkinSprite.cacheTexture(Paths.image('ui/countdown/ready-pixel', 'shared')); - FunkinSprite.cacheTexture(Paths.image('ui/countdown/set-pixel', 'shared')); - FunkinSprite.cacheTexture(Paths.image('ui/countdown/go-pixel', 'shared')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/sick')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/good')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/bad')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/normal/shit')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/sick-pixel')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/good-pixel')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/bad-pixel')); - FunkinSprite.cacheTexture(Paths.image('gameplay/popup/pixel/shit-pixel')); + FunkinSprite.cacheTexture(Paths.image('ui/countdown/funkin/ready', 'shared')); + FunkinSprite.cacheTexture(Paths.image('ui/countdown/funkin/set', 'shared')); + FunkinSprite.cacheTexture(Paths.image('ui/countdown/funkin/go', 'shared')); + FunkinSprite.cacheTexture(Paths.image('ui/countdown/pixel/ready', 'shared')); + FunkinSprite.cacheTexture(Paths.image('ui/countdown/pixel/set', 'shared')); + FunkinSprite.cacheTexture(Paths.image('ui/countdown/pixel/go', 'shared')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/normal/sick')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/normal/good')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/normal/bad')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/normal/shit')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/sick')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/good')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/bad')); + FunkinSprite.cacheTexture(Paths.image('ui/popup/pixel/shit')); FunkinSprite.cacheTexture(Paths.image('miss', 'shared')); // TODO: remove this // List all image assets in the level's library. diff --git a/source/funkin/util/Constants.hx b/source/funkin/util/Constants.hx index 2d4fef1f4..85cd1a27b 100644 --- a/source/funkin/util/Constants.hx +++ b/source/funkin/util/Constants.hx @@ -258,6 +258,11 @@ class Constants */ public static final DEFAULT_NOTE_STYLE:String = 'funkin'; + /** + * The default pixel note style for songs. + */ + public static final DEFAULT_PIXEL_NOTE_STYLE:String = 'pixel'; + /** * The default album for songs in Freeplay. */ From 82a6ca591687c01ff82a6605c74195da3237ac6d Mon Sep 17 00:00:00 2001 From: anysad Date: Wed, 17 Jul 2024 23:19:18 +0300 Subject: [PATCH 15/28] welcome fallback note styles! --- source/funkin/play/Countdown.hx | 54 ++++++++++++++----- source/funkin/play/components/PopUpStuff.hx | 21 +++++++- .../funkin/play/notes/notestyle/NoteStyle.hx | 2 +- 3 files changed, 60 insertions(+), 17 deletions(-) diff --git a/source/funkin/play/Countdown.hx b/source/funkin/play/Countdown.hx index 139b6cacd..a8bf1b500 100644 --- a/source/funkin/play/Countdown.hx +++ b/source/funkin/play/Countdown.hx @@ -38,6 +38,8 @@ class Countdown static var noteStyle:NoteStyle; + static var fallbackNoteStyle:Null; + static var isPixel:Bool = false; /** @@ -69,11 +71,7 @@ class Countdown // @:privateAccess // PlayState.instance.dispatchEvent(new SongTimeScriptEvent(SONG_BEAT_HIT, 0, 0)); - var fetchedNoteStyle:NoteStyle = NoteStyleRegistry.instance.fetchEntry(PlayState.instance.currentChart.noteStyle); - if (fetchedNoteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault(); - else - noteStyle = fetchedNoteStyle; - if (noteStyle._data.assets.note.isPixel) isPixel = true; + fetchNoteStyle(); // The timer function gets called based on the beat of the song. countdownTimer = new FlxTimer(); @@ -92,7 +90,7 @@ class Countdown // PlayState.instance.dispatchEvent(new SongTimeScriptEvent(SONG_BEAT_HIT, 0, 0)); // Countdown graphic. - showCountdownGraphic(countdownStep, noteStyle, isPixel); + showCountdownGraphic(countdownStep, noteStyle); // Countdown sound. playCountdownSound(countdownStep, noteStyle); @@ -212,10 +210,20 @@ class Countdown isPixel = false; } + static function fetchNoteStyle():Void + { + var fetchedNoteStyle:NoteStyle = NoteStyleRegistry.instance.fetchEntry(PlayState.instance.currentChart.noteStyle); + if (fetchedNoteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault(); + else + noteStyle = fetchedNoteStyle; + fallbackNoteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyle.getFallbackID()); + isPixel = false; + } + /** * Retrieves the graphic to use for this step of the countdown. */ - public static function showCountdownGraphic(index:CountdownStep, noteStyle:NoteStyle, isGraphicPixel:Bool):Void + public static function showCountdownGraphic(index:CountdownStep, noteStyle:NoteStyle):Void { var indexString:String = null; switch (index) @@ -246,13 +254,13 @@ class Countdown var fadeEase = FlxEase.cubeInOut; if (isGraphicPixel) fadeEase = EaseUtil.stepped(8); - countdownSprite.antialiasing = !isGraphicPixel; + countdownSprite.antialiasing = !isPixel; + + countdownSprite.cameras = [PlayState.instance.camHUD]; countdownSprite.updateHitbox(); countdownSprite.screenCenter(); - countdownSprite.cameras = [PlayState.instance.camHUD]; - // Fade sprite in, then out, then destroy it. FlxTween.tween(countdownSprite, {y: countdownSprite.y += 100}, Conductor.instance.beatLengthMs / 1000, { @@ -272,10 +280,19 @@ class Countdown static function resolveGraphicPath(noteStyle:NoteStyle, index:String):Null { + fetchNoteStyle(); var basePath:String = 'ui/countdown/'; - var spritePath:String = basePath + noteStyle.id + '/$index'; - // If nothing is found, revert it to default notestyle skin + + while (!Assets.exists(Paths.image(spritePath)) && fallbackNoteStyle != null) + { + noteStyle = fallbackNoteStyle; + fallbackNoteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyle.getFallbackID()); + spritePath = basePath + noteStyle.id + '/$index'; + } + if (noteStyle.isHoldNotePixel()) isPixel = true; + + // If ABSOLUTELY nothing is found, revert it to default notestyle skin if (!Assets.exists(Paths.image(spritePath))) { if (!isPixel) spritePath = basePath + Constants.DEFAULT_NOTE_STYLE + '/$index'; @@ -298,10 +315,19 @@ class Countdown static function resolveSoundPath(noteStyle:NoteStyle, step:CountdownStep):Null { if (step == CountdownStep.BEFORE || step == CountdownStep.AFTER) return null; + fetchNoteStyle(); var basePath:String = 'gameplay/countdown/'; - var soundPath:String = basePath + noteStyle.id + '/intro$step'; - // If nothing is found, revert it to default notestyle sound + + while (!Assets.exists(Paths.sound(soundPath)) && fallbackNoteStyle != null) + { + noteStyle = fallbackNoteStyle; + fallbackNoteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyle.getFallbackID()); + soundPath = basePath + noteStyle.id + '/intro$step'; + } + if (noteStyle.isHoldNotePixel()) isPixel = true; + + // If ABSOLUTELY nothing is found, revert it to default notestyle sound if (!Assets.exists(Paths.sound(soundPath))) { if (!isPixel) soundPath = basePath + Constants.DEFAULT_NOTE_STYLE + '/intro$step'; diff --git a/source/funkin/play/components/PopUpStuff.hx b/source/funkin/play/components/PopUpStuff.hx index 2bd2bf4db..97e1d291d 100644 --- a/source/funkin/play/components/PopUpStuff.hx +++ b/source/funkin/play/components/PopUpStuff.hx @@ -23,24 +23,41 @@ class PopUpStuff extends FlxTypedGroup */ static var noteStyle:NoteStyle; + static var fallbackNoteStyle:Null; + static var isPixel:Bool = false; override public function new() { super(); + fetchNoteStyle(); + } + + static function fetchNoteStyle():Void + { var fetchedNoteStyle:NoteStyle = NoteStyleRegistry.instance.fetchEntry(PlayState.instance.currentChart.noteStyle); if (fetchedNoteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault(); else noteStyle = fetchedNoteStyle; - if (noteStyle._data.assets.note.isPixel) isPixel = true; + fallbackNoteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyle.getFallbackID()); + isPixel = false; } static function resolveGraphicPath(noteStyle:NoteStyle, index:String):Null { + fetchNoteStyle(); var basePath:String = 'ui/popup/'; - var spritePath:String = basePath + noteStyle.id + '/$index'; + + while (!Assets.exists(Paths.image(spritePath)) && fallbackNoteStyle != null) + { + noteStyle = fallbackNoteStyle; + fallbackNoteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyle.getFallbackID()); + spritePath = basePath + noteStyle.id + '/$index'; + } + if (noteStyle.isHoldNotePixel()) isPixel = true; + // If nothing is found, revert it to default notestyle skin if (!Assets.exists(Paths.image(spritePath))) { diff --git a/source/funkin/play/notes/notestyle/NoteStyle.hx b/source/funkin/play/notes/notestyle/NoteStyle.hx index 3993cce52..5a877aa5b 100644 --- a/source/funkin/play/notes/notestyle/NoteStyle.hx +++ b/source/funkin/play/notes/notestyle/NoteStyle.hx @@ -72,7 +72,7 @@ class NoteStyle implements IRegistryEntry * Get the note style ID of the parent note style. * @return The string ID, or `null` if there is no parent. */ - function getFallbackID():Null + public function getFallbackID():Null { return _data.fallback; } From d07564cdc234a39daaa4aebc8ec9b69d4bf2eaf0 Mon Sep 17 00:00:00 2001 From: anysad Date: Thu, 18 Jul 2024 17:56:54 +0300 Subject: [PATCH 16/28] hopefully final polish? --- source/funkin/play/Countdown.hx | 29 ++++++++------------- source/funkin/play/components/PopUpStuff.hx | 10 +++---- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/source/funkin/play/Countdown.hx b/source/funkin/play/Countdown.hx index a8bf1b500..47d6faa9c 100644 --- a/source/funkin/play/Countdown.hx +++ b/source/funkin/play/Countdown.hx @@ -71,8 +71,6 @@ class Countdown // @:privateAccess // PlayState.instance.dispatchEvent(new SongTimeScriptEvent(SONG_BEAT_HIT, 0, 0)); - fetchNoteStyle(); - // The timer function gets called based on the beat of the song. countdownTimer = new FlxTimer(); @@ -90,10 +88,10 @@ class Countdown // PlayState.instance.dispatchEvent(new SongTimeScriptEvent(SONG_BEAT_HIT, 0, 0)); // Countdown graphic. - showCountdownGraphic(countdownStep, noteStyle); + showCountdownGraphic(countdownStep); // Countdown sound. - playCountdownSound(countdownStep, noteStyle); + playCountdownSound(countdownStep); // Event handling bullshit. var cancelled:Bool = propagateCountdownEvent(countdownStep); @@ -223,7 +221,7 @@ class Countdown /** * Retrieves the graphic to use for this step of the countdown. */ - public static function showCountdownGraphic(index:CountdownStep, noteStyle:NoteStyle):Void + public static function showCountdownGraphic(index:CountdownStep):Void { var indexString:String = null; switch (index) @@ -240,7 +238,7 @@ class Countdown if (indexString == null) return; var spritePath:String = null; - spritePath = resolveGraphicPath(noteStyle, indexString); + spritePath = resolveGraphicPath(indexString); if (spritePath == null) return; @@ -259,26 +257,21 @@ class Countdown countdownSprite.cameras = [PlayState.instance.camHUD]; countdownSprite.updateHitbox(); - countdownSprite.screenCenter(); // Fade sprite in, then out, then destroy it. - FlxTween.tween(countdownSprite, {y: countdownSprite.y += 100}, Conductor.instance.beatLengthMs / 1000, + FlxTween.tween(countdownSprite, {alpha: 0}, Conductor.instance.beatLengthMs / 1000, { - ease: FlxEase.cubeInOut, + ease: fadeEase, onComplete: function(twn:FlxTween) { countdownSprite.destroy(); } }); - FlxTween.tween(countdownSprite, {alpha: 0}, Conductor.instance.beatLengthMs / 1000, - { - ease: fadeEase - }); - PlayState.instance.add(countdownSprite); + countdownSprite.screenCenter(); } - static function resolveGraphicPath(noteStyle:NoteStyle, index:String):Null + static function resolveGraphicPath(index:String):Null { fetchNoteStyle(); var basePath:String = 'ui/countdown/'; @@ -307,12 +300,12 @@ class Countdown /** * Retrieves the sound file to use for this step of the countdown. */ - public static function playCountdownSound(step:CountdownStep, noteStyle:NoteStyle):Void + public static function playCountdownSound(step:CountdownStep):Void { - return FunkinSound.playOnce(Paths.sound(resolveSoundPath(noteStyle, step)), Constants.COUNTDOWN_VOLUME); + return FunkinSound.playOnce(Paths.sound(resolveSoundPath(step)), Constants.COUNTDOWN_VOLUME); } - static function resolveSoundPath(noteStyle:NoteStyle, step:CountdownStep):Null + static function resolveSoundPath(step:CountdownStep):Null { if (step == CountdownStep.BEFORE || step == CountdownStep.AFTER) return null; fetchNoteStyle(); diff --git a/source/funkin/play/components/PopUpStuff.hx b/source/funkin/play/components/PopUpStuff.hx index 97e1d291d..b9479ec8b 100644 --- a/source/funkin/play/components/PopUpStuff.hx +++ b/source/funkin/play/components/PopUpStuff.hx @@ -30,8 +30,6 @@ class PopUpStuff extends FlxTypedGroup override public function new() { super(); - - fetchNoteStyle(); } static function fetchNoteStyle():Void @@ -44,7 +42,7 @@ class PopUpStuff extends FlxTypedGroup isPixel = false; } - static function resolveGraphicPath(noteStyle:NoteStyle, index:String):Null + static function resolveGraphicPath(index:String):Null { fetchNoteStyle(); var basePath:String = 'ui/popup/'; @@ -75,7 +73,7 @@ class PopUpStuff extends FlxTypedGroup if (daRating == null) daRating = "good"; - var ratingPath:String = resolveGraphicPath(noteStyle, daRating); + var ratingPath:String = resolveGraphicPath(daRating); // if (PlayState.instance.currentStageId.startsWith('school')) ratingPath = "weeb/pixelUI/" + ratingPath + "-pixel"; @@ -131,7 +129,7 @@ class PopUpStuff extends FlxTypedGroup if (combo == null) combo = 0; - var comboPath:String = resolveGraphicPath(noteStyle, 'combo'); + var comboPath:String = resolveGraphicPath('combo'); var comboSpr:FunkinSprite = FunkinSprite.create(comboPath); comboSpr.y = (FlxG.camera.height * 0.44) + offsets[1]; comboSpr.x = (FlxG.width * 0.507) + offsets[0]; @@ -186,7 +184,7 @@ class PopUpStuff extends FlxTypedGroup var daLoop:Int = 1; for (i in seperatedScore) { - var numScore:FunkinSprite = FunkinSprite.create(0, comboSpr.y, resolveGraphicPath(noteStyle, 'num' + Std.int(i))); + var numScore:FunkinSprite = FunkinSprite.create(0, comboSpr.y, resolveGraphicPath('num' + Std.int(i))); if (graphicSuffix.toLowerCase().contains('pixel')) { From 41bd0246ac31bf9b1195b4c317e1f3ea36ae94bb Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Sun, 28 Jul 2024 17:10:32 -0400 Subject: [PATCH 17/28] Custom coutndown, judgements, and combo count now use the note style file instead of hardcoded paths. --- assets | 2 +- source/funkin/data/BaseRegistry.hx | 2 +- source/funkin/data/notestyle/CHANGELOG.md | 31 + source/funkin/data/notestyle/NoteStyleData.hx | 88 ++- .../data/notestyle/NoteStyleRegistry.hx | 4 +- source/funkin/play/Countdown.hx | 119 +-- source/funkin/play/PlayState.hx | 23 +- source/funkin/play/components/PopUpStuff.hx | 186 +---- source/funkin/play/notes/StrumlineNote.hx | 7 + .../funkin/play/notes/notestyle/NoteStyle.hx | 712 ++++++++++++++++-- .../components/ChartEditorHoldNoteSprite.hx | 4 +- 11 files changed, 840 insertions(+), 338 deletions(-) create mode 100644 source/funkin/data/notestyle/CHANGELOG.md diff --git a/assets b/assets index 3a9e05108..c4bd52818 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 3a9e0510841533f96228609dcd50f2515443bb90 +Subproject commit c4bd5281880ac2a1e26016c1219824d2f4247536 diff --git a/source/funkin/data/BaseRegistry.hx b/source/funkin/data/BaseRegistry.hx index 118516bec..83413ad00 100644 --- a/source/funkin/data/BaseRegistry.hx +++ b/source/funkin/data/BaseRegistry.hx @@ -263,7 +263,7 @@ abstract class BaseRegistry & Constructible + public function parseEntryDataWithMigration(id:String, version:Null):Null { if (version == null) { diff --git a/source/funkin/data/notestyle/CHANGELOG.md b/source/funkin/data/notestyle/CHANGELOG.md new file mode 100644 index 000000000..d85c11cad --- /dev/null +++ b/source/funkin/data/notestyle/CHANGELOG.md @@ -0,0 +1,31 @@ +# Note Style Data Schema Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.1.0] +### Added +- Added several new `assets`: + - `countdownThree` + - `countdownTwo` + - `countdownOne` + - `countdownGo` + - `judgementSick` + - `judgementGood` + - `judgementBad` + - `judgementShit` + - `comboNumber0` + - `comboNumber1` + - `comboNumber2` + - `comboNumber3` + - `comboNumber4` + - `comboNumber5` + - `comboNumber6` + - `comboNumber7` + - `comboNumber8` + - `comboNumber9` + +## [1.0.0] +Initial version. diff --git a/source/funkin/data/notestyle/NoteStyleData.hx b/source/funkin/data/notestyle/NoteStyleData.hx index fcdb3b4f9..39162b896 100644 --- a/source/funkin/data/notestyle/NoteStyleData.hx +++ b/source/funkin/data/notestyle/NoteStyleData.hx @@ -74,6 +74,84 @@ typedef NoteStyleAssetsData = */ @:optional var holdNoteCover:NoteStyleAssetData; + + /** + * The THREE sound (and an optional pre-READY graphic). + */ + @:optional + var countdownThree:NoteStyleAssetData; + + /** + * The TWO sound and READY graphic. + */ + @:optional + var countdownTwo:NoteStyleAssetData; + + /** + * The ONE sound and SET graphic. + */ + @:optional + var countdownOne:NoteStyleAssetData; + + /** + * The GO sound and GO! graphic. + */ + @:optional + var countdownGo:NoteStyleAssetData; + + /** + * The SICK! judgement. + */ + @:optional + var judgementSick:NoteStyleAssetData; + + /** + * The GOOD! judgement. + */ + @:optional + var judgementGood:NoteStyleAssetData; + + /** + * The BAD! judgement. + */ + @:optional + var judgementBad:NoteStyleAssetData; + + /** + * The SHIT! judgement. + */ + @:optional + var judgementShit:NoteStyleAssetData; + + @:optional + var comboNumber0:NoteStyleAssetData; + + @:optional + var comboNumber1:NoteStyleAssetData; + + @:optional + var comboNumber2:NoteStyleAssetData; + + @:optional + var comboNumber3:NoteStyleAssetData; + + @:optional + var comboNumber4:NoteStyleAssetData; + + @:optional + var comboNumber5:NoteStyleAssetData; + + @:optional + var comboNumber6:NoteStyleAssetData; + + @:optional + var comboNumber7:NoteStyleAssetData; + + @:optional + var comboNumber8:NoteStyleAssetData; + + @:optional + var comboNumber9:NoteStyleAssetData; } /** @@ -120,7 +198,8 @@ typedef NoteStyleAssetData = /** * The structure of this data depends on the asset. */ - var data:T; + @:optional + var data:Null; } typedef NoteStyleData_Note = @@ -131,7 +210,14 @@ typedef NoteStyleData_Note = var right:UnnamedAnimationData; } +typedef NoteStyleData_Countdown = +{ + var audioPath:String; +} + typedef NoteStyleData_HoldNote = {} +typedef NoteStyleData_Judgement = {} +typedef NoteStyleData_ComboNum = {} /** * Data on animations for each direction of the strumline. diff --git a/source/funkin/data/notestyle/NoteStyleRegistry.hx b/source/funkin/data/notestyle/NoteStyleRegistry.hx index 5e9fa9a3d..36d1b9200 100644 --- a/source/funkin/data/notestyle/NoteStyleRegistry.hx +++ b/source/funkin/data/notestyle/NoteStyleRegistry.hx @@ -11,9 +11,9 @@ class NoteStyleRegistry extends BaseRegistry * Handle breaking changes by incrementing this value * and adding migration to the `migrateNoteStyleData()` function. */ - public static final NOTE_STYLE_DATA_VERSION:thx.semver.Version = "1.0.0"; + public static final NOTE_STYLE_DATA_VERSION:thx.semver.Version = "1.1.0"; - public static final NOTE_STYLE_DATA_VERSION_RULE:thx.semver.VersionRule = "1.0.x"; + public static final NOTE_STYLE_DATA_VERSION_RULE:thx.semver.VersionRule = "1.1.x"; public static var instance(get, never):NoteStyleRegistry; static var _instance:Null = null; diff --git a/source/funkin/play/Countdown.hx b/source/funkin/play/Countdown.hx index 47d6faa9c..643883a43 100644 --- a/source/funkin/play/Countdown.hx +++ b/source/funkin/play/Countdown.hx @@ -40,8 +40,6 @@ class Countdown static var fallbackNoteStyle:Null; - static var isPixel:Bool = false; - /** * The currently running countdown. This will be null if there is no countdown running. */ @@ -204,18 +202,22 @@ class Countdown */ public static function reset() { - noteStyle = NoteStyleRegistry.instance.fetchDefault(); - isPixel = false; + noteStyle = null; } - static function fetchNoteStyle():Void + /** + * Retrieve the note style data (if we haven't already) + * @param noteStyleId The id of the note style to fetch. Defaults to the one used by the current PlayState. + * @param force Fetch the note style from the registry even if we've already fetched it. + */ + static function fetchNoteStyle(?noteStyleId:String, force:Bool = false):Void { - var fetchedNoteStyle:NoteStyle = NoteStyleRegistry.instance.fetchEntry(PlayState.instance.currentChart.noteStyle); - if (fetchedNoteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault(); - else - noteStyle = fetchedNoteStyle; - fallbackNoteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyle.getFallbackID()); - isPixel = false; + if (noteStyle != null && !force) return; + + if (noteStyleId == null) noteStyleId = PlayState.instance?.currentChart?.noteStyle; + + noteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyleId); + if (noteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault(); } /** @@ -223,40 +225,13 @@ class Countdown */ public static function showCountdownGraphic(index:CountdownStep):Void { - var indexString:String = null; - switch (index) - { - case TWO: - indexString = 'ready'; - case ONE: - indexString = 'set'; - case GO: - indexString = 'go'; - default: - // null - } - if (indexString == null) return; + fetchNoteStyle(); - var spritePath:String = null; - spritePath = resolveGraphicPath(indexString); - - if (spritePath == null) return; - - var countdownSprite:FunkinSprite = FunkinSprite.create(spritePath); - countdownSprite.scrollFactor.set(0, 0); - - if (isGraphicPixel) countdownSprite.setGraphicSize(Std.int(countdownSprite.width * Constants.PIXEL_ART_SCALE)); - else - countdownSprite.setGraphicSize(Std.int(countdownSprite.width * 0.7)); + var countdownSprite = noteStyle.buildCountdownSprite(index); + if (countdownSprite == null) return; var fadeEase = FlxEase.cubeInOut; - if (isGraphicPixel) fadeEase = EaseUtil.stepped(8); - - countdownSprite.antialiasing = !isPixel; - - countdownSprite.cameras = [PlayState.instance.camHUD]; - - countdownSprite.updateHitbox(); + if (noteStyle.isCountdownSpritePixel(index)) fadeEase = EaseUtil.stepped(8); // Fade sprite in, then out, then destroy it. FlxTween.tween(countdownSprite, {alpha: 0}, Conductor.instance.beatLengthMs / 1000, @@ -267,69 +242,25 @@ class Countdown } }); + countdownSprite.cameras = [PlayState.instance.camHUD]; PlayState.instance.add(countdownSprite); countdownSprite.screenCenter(); - } - static function resolveGraphicPath(index:String):Null - { - fetchNoteStyle(); - var basePath:String = 'ui/countdown/'; - var spritePath:String = basePath + noteStyle.id + '/$index'; - - while (!Assets.exists(Paths.image(spritePath)) && fallbackNoteStyle != null) - { - noteStyle = fallbackNoteStyle; - fallbackNoteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyle.getFallbackID()); - spritePath = basePath + noteStyle.id + '/$index'; - } - if (noteStyle.isHoldNotePixel()) isPixel = true; - - // If ABSOLUTELY nothing is found, revert it to default notestyle skin - if (!Assets.exists(Paths.image(spritePath))) - { - if (!isPixel) spritePath = basePath + Constants.DEFAULT_NOTE_STYLE + '/$index'; - else - spritePath = basePath + Constants.DEFAULT_PIXEL_NOTE_STYLE + '/$index'; - } - - trace('Resolved sprite path: ' + Paths.image(spritePath)); - return spritePath; + var offsets = noteStyle.getCountdownSpriteOffsets(index); + countdownSprite.x += offsets[0]; + countdownSprite.y += offsets[1]; } /** * Retrieves the sound file to use for this step of the countdown. */ - public static function playCountdownSound(step:CountdownStep):Void + public static function playCountdownSound(step:CountdownStep):FunkinSound { - return FunkinSound.playOnce(Paths.sound(resolveSoundPath(step)), Constants.COUNTDOWN_VOLUME); - } - - static function resolveSoundPath(step:CountdownStep):Null - { - if (step == CountdownStep.BEFORE || step == CountdownStep.AFTER) return null; fetchNoteStyle(); - var basePath:String = 'gameplay/countdown/'; - var soundPath:String = basePath + noteStyle.id + '/intro$step'; + var path = noteStyle.getCountdownSoundPath(step); + if (path == null) return null; - while (!Assets.exists(Paths.sound(soundPath)) && fallbackNoteStyle != null) - { - noteStyle = fallbackNoteStyle; - fallbackNoteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyle.getFallbackID()); - soundPath = basePath + noteStyle.id + '/intro$step'; - } - if (noteStyle.isHoldNotePixel()) isPixel = true; - - // If ABSOLUTELY nothing is found, revert it to default notestyle sound - if (!Assets.exists(Paths.sound(soundPath))) - { - if (!isPixel) soundPath = basePath + Constants.DEFAULT_NOTE_STYLE + '/intro$step'; - else - soundPath = basePath + Constants.DEFAULT_PIXEL_NOTE_STYLE + '/intro$step'; - } - - trace('Resolved sound path: ' + soundPath); - return soundPath; + return FunkinSound.playOnce(path, Constants.COUNTDOWN_VOLUME); } public static function decrement(step:CountdownStep):CountdownStep diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 384c28056..3fd68efe9 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -694,12 +694,7 @@ class PlayState extends MusicBeatSubState initMinimalMode(); } initStrumlines(); - - // Initialize the judgements and combo meter. - comboPopUps = new PopUpStuff(); - comboPopUps.zIndex = 900; - add(comboPopUps); - comboPopUps.cameras = [camHUD]; + initPopups(); #if discord_rpc // Initialize Discord Rich Presence. @@ -1727,6 +1722,21 @@ class PlayState extends MusicBeatSubState opponentStrumline.fadeInArrows(); } + /** + * Configures the judgement and combo popups. + */ + function initPopups():Void + { + var noteStyleId:String = currentChart.noteStyle; + var noteStyle:NoteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyleId); + if (noteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault(); + // Initialize the judgements and combo meter. + comboPopUps = new PopUpStuff(noteStyle); + comboPopUps.zIndex = 900; + add(comboPopUps); + comboPopUps.cameras = [camHUD]; + } + /** * Initializes the Discord Rich Presence. */ @@ -3005,7 +3015,6 @@ class PlayState extends MusicBeatSubState GameOverSubState.reset(); PauseSubState.reset(); Countdown.reset(); - PopUpStuff.reset(); // Clear the static reference to this state. instance = null; diff --git a/source/funkin/play/components/PopUpStuff.hx b/source/funkin/play/components/PopUpStuff.hx index b9479ec8b..911c3578c 100644 --- a/source/funkin/play/components/PopUpStuff.hx +++ b/source/funkin/play/components/PopUpStuff.hx @@ -12,103 +12,47 @@ import openfl.utils.Assets; import funkin.data.notestyle.NoteStyleRegistry; import funkin.play.notes.notestyle.NoteStyle; +@:nullSafety class PopUpStuff extends FlxTypedGroup { - public var offsets:Array = [0, 0]; - /** - * Which alternate graphic on popup to use. - * This is set via the current notestyle. - * For example, in Week 6 it is `pixel`. + * The current note style to use. This determines which graphics to display. + * For example, Week 6 uses the `pixel` note style, and mods can create their own. */ - static var noteStyle:NoteStyle; + var noteStyle:NoteStyle; - static var fallbackNoteStyle:Null; - - static var isPixel:Bool = false; - - override public function new() + override public function new(noteStyle:NoteStyle) { super(); + + this.noteStyle = noteStyle; } - static function fetchNoteStyle():Void + public function displayRating(daRating:Null) { - var fetchedNoteStyle:NoteStyle = NoteStyleRegistry.instance.fetchEntry(PlayState.instance.currentChart.noteStyle); - if (fetchedNoteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault(); - else - noteStyle = fetchedNoteStyle; - fallbackNoteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyle.getFallbackID()); - isPixel = false; - } - - static function resolveGraphicPath(index:String):Null - { - fetchNoteStyle(); - var basePath:String = 'ui/popup/'; - var spritePath:String = basePath + noteStyle.id + '/$index'; - - while (!Assets.exists(Paths.image(spritePath)) && fallbackNoteStyle != null) - { - noteStyle = fallbackNoteStyle; - fallbackNoteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyle.getFallbackID()); - spritePath = basePath + noteStyle.id + '/$index'; - } - if (noteStyle.isHoldNotePixel()) isPixel = true; - - // If nothing is found, revert it to default notestyle skin - if (!Assets.exists(Paths.image(spritePath))) - { - if (!isPixel) spritePath = basePath + Constants.DEFAULT_NOTE_STYLE + '/$index'; - else - spritePath = basePath + Constants.DEFAULT_PIXEL_NOTE_STYLE + '/$index'; - } - - return spritePath; - } - - public function displayRating(daRating:String) - { - var perfStart:Float = TimerUtil.start(); - if (daRating == null) daRating = "good"; - var ratingPath:String = resolveGraphicPath(daRating); - - // if (PlayState.instance.currentStageId.startsWith('school')) ratingPath = "weeb/pixelUI/" + ratingPath + "-pixel"; - - var rating:FunkinSprite = FunkinSprite.create(0, 0, ratingPath); - rating.scrollFactor.set(0.2, 0.2); + var rating:Null = noteStyle.buildJudgementSprite(daRating); + if (rating == null) return; rating.zIndex = 1000; - rating.x = (FlxG.width * 0.474) + offsets[0]; - // rating.x -= FlxG.camera.scroll.x * 0.2; - rating.y = (FlxG.camera.height * 0.45 - 60) + offsets[1]; + + rating.x = (FlxG.width * 0.474); + rating.x -= rating.width / 2; + rating.y = (FlxG.camera.height * 0.45 - 60); + rating.y -= rating.height / 2; + + var offsets = noteStyle.getJudgementSpriteOffsets(daRating); + rating.x += offsets[0]; + rating.y += offsets[1]; + rating.acceleration.y = 550; rating.velocity.y -= FlxG.random.int(140, 175); rating.velocity.x -= FlxG.random.int(0, 10); add(rating); - var fadeEase = null; - - if (isPixel) - { - rating.setGraphicSize(Std.int(rating.width * Constants.PIXEL_ART_SCALE * 0.7)); - rating.antialiasing = false; - rating.pixelPerfectRender = true; - rating.pixelPerfectPosition = true; - fadeEase = EaseUtil.stepped(2); - } - else - { - rating.setGraphicSize(Std.int(rating.width * 0.65)); - rating.antialiasing = true; - } - rating.updateHitbox(); - - rating.x -= rating.width / 2; - rating.y -= rating.height / 2; + var fadeEase = noteStyle.isJudgementSpritePixel(daRating) ? EaseUtil.stepped(2) : null; FlxTween.tween(rating, {alpha: 0}, 0.2, { @@ -119,55 +63,10 @@ class PopUpStuff extends FlxTypedGroup startDelay: Conductor.instance.beatLengthMs * 0.001, ease: fadeEase }); - - trace('displayRating took: ${TimerUtil.seconds(perfStart)}'); } - public function displayCombo(?combo:Int = 0):Int + public function displayCombo(combo:Int = 0):Void { - var perfStart:Float = TimerUtil.start(); - - if (combo == null) combo = 0; - - var comboPath:String = resolveGraphicPath('combo'); - var comboSpr:FunkinSprite = FunkinSprite.create(comboPath); - comboSpr.y = (FlxG.camera.height * 0.44) + offsets[1]; - comboSpr.x = (FlxG.width * 0.507) + offsets[0]; - // comboSpr.x -= FlxG.camera.scroll.x * 0.2; - - comboSpr.acceleration.y = 600; - comboSpr.velocity.y -= 150; - comboSpr.velocity.x += FlxG.random.int(1, 10); - - // add(comboSpr); - - var fadeEase = null; - - if (graphicSuffix.toLowerCase().contains('pixel')) - { - comboSpr.setGraphicSize(Std.int(comboSpr.width * Constants.PIXEL_ART_SCALE * 1)); - comboSpr.antialiasing = false; - comboSpr.pixelPerfectRender = true; - comboSpr.pixelPerfectPosition = true; - fadeEase = EaseUtil.stepped(2); - } - else - { - comboSpr.setGraphicSize(Std.int(comboSpr.width * 0.7)); - comboSpr.antialiasing = true; - } - comboSpr.updateHitbox(); - - FlxTween.tween(comboSpr, {alpha: 0}, 0.2, - { - onComplete: function(tween:FlxTween) { - remove(comboSpr, true); - comboSpr.destroy(); - }, - startDelay: Conductor.instance.beatLengthMs * 0.001, - ease: fadeEase - }); - var seperatedScore:Array = []; var tempCombo:Int = combo; @@ -182,31 +81,27 @@ class PopUpStuff extends FlxTypedGroup // seperatedScore.reverse(); var daLoop:Int = 1; - for (i in seperatedScore) + for (digit in seperatedScore) { - var numScore:FunkinSprite = FunkinSprite.create(0, comboSpr.y, resolveGraphicPath('num' + Std.int(i))); + var numScore:Null = noteStyle.buildComboNumSprite(digit); + if (numScore == null) continue; - if (graphicSuffix.toLowerCase().contains('pixel')) - { - numScore.setGraphicSize(Std.int(numScore.width * Constants.PIXEL_ART_SCALE * 1)); - numScore.antialiasing = false; - numScore.pixelPerfectRender = true; - numScore.pixelPerfectPosition = true; - } - else - { - numScore.setGraphicSize(Std.int(numScore.width * 0.45)); - numScore.antialiasing = true; - } - numScore.updateHitbox(); + numScore.x = (FlxG.width * 0.507) - (36 * daLoop) - 65; + trace('numScore($daLoop) = ${numScore.x}'); + numScore.y = (FlxG.camera.height * 0.44); + + var offsets = noteStyle.getComboNumSpriteOffsets(digit); + numScore.x += offsets[0]; + numScore.y += offsets[1]; - numScore.x = comboSpr.x - (36 * daLoop) - 65; //- 90; numScore.acceleration.y = FlxG.random.int(250, 300); numScore.velocity.y -= FlxG.random.int(130, 150); numScore.velocity.x = FlxG.random.float(-5, 5); add(numScore); + var fadeEase = noteStyle.isComboNumSpritePixel(digit) ? EaseUtil.stepped(2) : null; + FlxTween.tween(numScore, {alpha: 0}, 0.2, { onComplete: function(tween:FlxTween) { @@ -219,18 +114,5 @@ class PopUpStuff extends FlxTypedGroup daLoop++; } - - trace('displayCombo took: ${TimerUtil.seconds(perfStart)}'); - - return combo; - } - - /** - * Reset the popup configuration to the default. - */ - public static function reset() - { - noteStyle = NoteStyleRegistry.instance.fetchDefault(); - isPixel = false; } } diff --git a/source/funkin/play/notes/StrumlineNote.hx b/source/funkin/play/notes/StrumlineNote.hx index 40d893255..d8230aa28 100644 --- a/source/funkin/play/notes/StrumlineNote.hx +++ b/source/funkin/play/notes/StrumlineNote.hx @@ -75,6 +75,13 @@ class StrumlineNote extends FlxSprite function setup(noteStyle:NoteStyle):Void { + if (noteStyle == null) + { + // If you get an exception on this line, check the debug console. + // You probably have a parsing error in your note style's JSON file. + throw "FATAL ERROR: Attempted to initialize PlayState with an invalid NoteStyle."; + } + noteStyle.applyStrumlineFrames(this); noteStyle.applyStrumlineAnimations(this, this.direction); diff --git a/source/funkin/play/notes/notestyle/NoteStyle.hx b/source/funkin/play/notes/notestyle/NoteStyle.hx index 5a877aa5b..ee07703f1 100644 --- a/source/funkin/play/notes/notestyle/NoteStyle.hx +++ b/source/funkin/play/notes/notestyle/NoteStyle.hx @@ -1,5 +1,6 @@ package funkin.play.notes.notestyle; +import funkin.play.Countdown; import flixel.graphics.frames.FlxAtlasFrames; import flixel.graphics.frames.FlxFramesCollection; import funkin.data.animation.AnimationData; @@ -16,6 +17,7 @@ using funkin.data.animation.AnimationData.AnimationDataUtil; * Holds the data for what assets to use for a note style, * and provides convenience methods for building sprites based on them. */ +@:nullSafety class NoteStyle implements IRegistryEntry { /** @@ -42,12 +44,8 @@ class NoteStyle implements IRegistryEntry this.id = id; _data = _fetchData(id); - if (_data == null) - { - throw 'Could not parse note style data for id: $id'; - } - - this.fallback = NoteStyleRegistry.instance.fetchEntry(getFallbackID()); + var fallbackID = _data.fallback; + if (fallbackID != null) this.fallback = NoteStyleRegistry.instance.fetchEntry(fallbackID); } /** @@ -80,7 +78,7 @@ class NoteStyle implements IRegistryEntry public function buildNoteSprite(target:NoteSprite):Void { // Apply the note sprite frames. - var atlas:FlxAtlasFrames = buildNoteFrames(false); + var atlas:Null = buildNoteFrames(false); if (atlas == null) { @@ -89,7 +87,7 @@ class NoteStyle implements IRegistryEntry target.frames = atlas; - target.antialiasing = !_data.assets.note.isPixel; + target.antialiasing = !(_data.assets?.note?.isPixel ?? false); // Apply the animations. buildNoteAnimations(target); @@ -99,21 +97,30 @@ class NoteStyle implements IRegistryEntry target.updateHitbox(); } - var noteFrames:FlxAtlasFrames = null; + var noteFrames:Null = null; - function buildNoteFrames(force:Bool = false):FlxAtlasFrames + function buildNoteFrames(force:Bool = false):Null { - if (!FunkinSprite.isTextureCached(Paths.image(getNoteAssetPath()))) + var noteAssetPath = getNoteAssetPath(); + if (noteAssetPath == null) return null; + + if (!FunkinSprite.isTextureCached(Paths.image(noteAssetPath))) { - FlxG.log.warn('Note texture is not cached: ${getNoteAssetPath()}'); + FlxG.log.warn('Note texture is not cached: ${noteAssetPath}'); } // Purge the note frames if the cached atlas is invalid. - if (noteFrames?.parent?.isDestroyed ?? false) noteFrames = null; + @:nullSafety(Off) + { + if (noteFrames?.parent?.isDestroyed ?? false) noteFrames = null; + } if (noteFrames != null && !force) return noteFrames; - noteFrames = Paths.getSparrowAtlas(getNoteAssetPath(), getNoteAssetLibrary()); + var noteAssetPath = getNoteAssetPath(); + if (noteAssetPath == null) return null; + + noteFrames = Paths.getSparrowAtlas(noteAssetPath, getNoteAssetLibrary()); if (noteFrames == null) { @@ -123,17 +130,18 @@ class NoteStyle implements IRegistryEntry return noteFrames; } - function getNoteAssetPath(raw:Bool = false):String + function getNoteAssetPath(raw:Bool = false):Null { if (raw) { var rawPath:Null = _data?.assets?.note?.assetPath; - if (rawPath == null) return fallback.getNoteAssetPath(true); + if (rawPath == null && fallback != null) return fallback.getNoteAssetPath(true); return rawPath; } // library:path - var parts = getNoteAssetPath(true).split(Constants.LIBRARY_SEPARATOR); + var parts = getNoteAssetPath(true)?.split(Constants.LIBRARY_SEPARATOR) ?? []; + if (parts.length == 0) return null; if (parts.length == 1) return getNoteAssetPath(true); return parts[1]; } @@ -141,57 +149,63 @@ class NoteStyle implements IRegistryEntry function getNoteAssetLibrary():Null { // library:path - var parts = getNoteAssetPath(true).split(Constants.LIBRARY_SEPARATOR); + var parts = getNoteAssetPath(true)?.split(Constants.LIBRARY_SEPARATOR) ?? []; + if (parts.length == 0) return null; if (parts.length == 1) return null; return parts[0]; } function buildNoteAnimations(target:NoteSprite):Void { - var leftData:AnimationData = fetchNoteAnimationData(LEFT); - target.animation.addByPrefix('purpleScroll', leftData.prefix, leftData.frameRate, leftData.looped, leftData.flipX, leftData.flipY); - var downData:AnimationData = fetchNoteAnimationData(DOWN); - target.animation.addByPrefix('blueScroll', downData.prefix, downData.frameRate, downData.looped, downData.flipX, downData.flipY); - var upData:AnimationData = fetchNoteAnimationData(UP); - target.animation.addByPrefix('greenScroll', upData.prefix, upData.frameRate, upData.looped, upData.flipX, upData.flipY); - var rightData:AnimationData = fetchNoteAnimationData(RIGHT); - target.animation.addByPrefix('redScroll', rightData.prefix, rightData.frameRate, rightData.looped, rightData.flipX, rightData.flipY); + var leftData:Null = fetchNoteAnimationData(LEFT); + if (leftData != null) target.animation.addByPrefix('purpleScroll', leftData.prefix ?? '', leftData.frameRate ?? 24, leftData.looped ?? false, + leftData.flipX, leftData.flipY); + var downData:Null = fetchNoteAnimationData(DOWN); + if (downData != null) target.animation.addByPrefix('blueScroll', downData.prefix ?? '', downData.frameRate ?? 24, downData.looped ?? false, + downData.flipX, downData.flipY); + var upData:Null = fetchNoteAnimationData(UP); + if (upData != null) target.animation.addByPrefix('greenScroll', upData.prefix ?? '', upData.frameRate ?? 24, upData.looped ?? false, upData.flipX, + upData.flipY); + var rightData:Null = fetchNoteAnimationData(RIGHT); + if (rightData != null) target.animation.addByPrefix('redScroll', rightData.prefix ?? '', rightData.frameRate ?? 24, rightData.looped ?? false, + rightData.flipX, rightData.flipY); } public function isNoteAnimated():Bool { - return _data.assets.note.animated; + return _data.assets?.note?.animated ?? false; } public function getNoteScale():Float { - return _data.assets.note.scale; + return _data.assets?.note?.scale ?? 1.0; } - function fetchNoteAnimationData(dir:NoteDirection):AnimationData + function fetchNoteAnimationData(dir:NoteDirection):Null { var result:Null = switch (dir) { - case LEFT: _data.assets.note.data.left.toNamed(); - case DOWN: _data.assets.note.data.down.toNamed(); - case UP: _data.assets.note.data.up.toNamed(); - case RIGHT: _data.assets.note.data.right.toNamed(); + case LEFT: _data.assets?.note?.data?.left?.toNamed(); + case DOWN: _data.assets?.note?.data?.down?.toNamed(); + case UP: _data.assets?.note?.data?.up?.toNamed(); + case RIGHT: _data.assets?.note?.data?.right?.toNamed(); }; - return (result == null) ? fallback.fetchNoteAnimationData(dir) : result; + return (result == null && fallback != null) ? fallback.fetchNoteAnimationData(dir) : result; } - public function getHoldNoteAssetPath(raw:Bool = false):String + public function getHoldNoteAssetPath(raw:Bool = false):Null { if (raw) { // TODO: figure out why ?. didn't work here var rawPath:Null = (_data?.assets?.holdNote == null) ? null : _data?.assets?.holdNote?.assetPath; - return (rawPath == null) ? fallback.getHoldNoteAssetPath(true) : rawPath; + return (rawPath == null && fallback != null) ? fallback.getHoldNoteAssetPath(true) : rawPath; } // library:path - var parts = getHoldNoteAssetPath(true).split(Constants.LIBRARY_SEPARATOR); + var parts = getHoldNoteAssetPath(true)?.split(Constants.LIBRARY_SEPARATOR) ?? []; + if (parts.length == 0) return null; if (parts.length == 1) return Paths.image(parts[0]); return Paths.image(parts[1], parts[0]); } @@ -199,15 +213,15 @@ class NoteStyle implements IRegistryEntry public function isHoldNotePixel():Bool { var data = _data?.assets?.holdNote; - if (data == null) return fallback.isHoldNotePixel(); - return data.isPixel; + if (data == null && fallback != null) return fallback.isHoldNotePixel(); + return data?.isPixel ?? false; } public function fetchHoldNoteScale():Float { var data = _data?.assets?.holdNote; - if (data == null) return fallback.fetchHoldNoteScale(); - return data.scale; + if (data == null && fallback != null) return fallback.fetchHoldNoteScale(); + return data?.scale ?? 1.0; } public function applyStrumlineFrames(target:StrumlineNote):Void @@ -215,7 +229,7 @@ class NoteStyle implements IRegistryEntry // TODO: Add support for multi-Sparrow. // Will be less annoying after this is merged: https://github.com/HaxeFlixel/flixel/pull/2772 - var atlas:FlxAtlasFrames = Paths.getSparrowAtlas(getStrumlineAssetPath(), getStrumlineAssetLibrary()); + var atlas:FlxAtlasFrames = Paths.getSparrowAtlas(getStrumlineAssetPath() ?? '', getStrumlineAssetLibrary()); if (atlas == null) { @@ -224,31 +238,30 @@ class NoteStyle implements IRegistryEntry target.frames = atlas; - target.scale.x = _data.assets.noteStrumline.scale; - target.scale.y = _data.assets.noteStrumline.scale; - target.antialiasing = !_data.assets.noteStrumline.isPixel; + target.scale.set(_data.assets.noteStrumline?.scale ?? 1.0); + target.antialiasing = !(_data.assets.noteStrumline?.isPixel ?? false); } - function getStrumlineAssetPath(raw:Bool = false):String + function getStrumlineAssetPath(raw:Bool = false):Null { if (raw) { var rawPath:Null = _data?.assets?.noteStrumline?.assetPath; - if (rawPath == null) return fallback.getStrumlineAssetPath(true); + if (rawPath == null && fallback != null) return fallback.getStrumlineAssetPath(true); return rawPath; } // library:path - var parts = getStrumlineAssetPath(true).split(Constants.LIBRARY_SEPARATOR); - if (parts.length == 1) return getStrumlineAssetPath(true); + var parts = getStrumlineAssetPath(true)?.split(Constants.LIBRARY_SEPARATOR) ?? []; + if (parts.length <= 1) return getStrumlineAssetPath(true); return parts[1]; } function getStrumlineAssetLibrary():Null { // library:path - var parts = getStrumlineAssetPath(true).split(Constants.LIBRARY_SEPARATOR); - if (parts.length == 1) return null; + var parts = getStrumlineAssetPath(true)?.split(Constants.LIBRARY_SEPARATOR) ?? []; + if (parts.length <= 1) return null; return parts[0]; } @@ -259,60 +272,592 @@ class NoteStyle implements IRegistryEntry function getStrumlineAnimationData(dir:NoteDirection):Array { - var result:Array = switch (dir) + var result:Array> = switch (dir) { case NoteDirection.LEFT: [ - _data.assets.noteStrumline.data.leftStatic.toNamed('static'), - _data.assets.noteStrumline.data.leftPress.toNamed('press'), - _data.assets.noteStrumline.data.leftConfirm.toNamed('confirm'), - _data.assets.noteStrumline.data.leftConfirmHold.toNamed('confirm-hold'), + _data.assets.noteStrumline?.data?.leftStatic?.toNamed('static'), + _data.assets.noteStrumline?.data?.leftPress?.toNamed('press'), + _data.assets.noteStrumline?.data?.leftConfirm?.toNamed('confirm'), + _data.assets.noteStrumline?.data?.leftConfirmHold?.toNamed('confirm-hold'), ]; case NoteDirection.DOWN: [ - _data.assets.noteStrumline.data.downStatic.toNamed('static'), - _data.assets.noteStrumline.data.downPress.toNamed('press'), - _data.assets.noteStrumline.data.downConfirm.toNamed('confirm'), - _data.assets.noteStrumline.data.downConfirmHold.toNamed('confirm-hold'), + _data.assets.noteStrumline?.data?.downStatic?.toNamed('static'), + _data.assets.noteStrumline?.data?.downPress?.toNamed('press'), + _data.assets.noteStrumline?.data?.downConfirm?.toNamed('confirm'), + _data.assets.noteStrumline?.data?.downConfirmHold?.toNamed('confirm-hold'), ]; case NoteDirection.UP: [ - _data.assets.noteStrumline.data.upStatic.toNamed('static'), - _data.assets.noteStrumline.data.upPress.toNamed('press'), - _data.assets.noteStrumline.data.upConfirm.toNamed('confirm'), - _data.assets.noteStrumline.data.upConfirmHold.toNamed('confirm-hold'), + _data.assets.noteStrumline?.data?.upStatic?.toNamed('static'), + _data.assets.noteStrumline?.data?.upPress?.toNamed('press'), + _data.assets.noteStrumline?.data?.upConfirm?.toNamed('confirm'), + _data.assets.noteStrumline?.data?.upConfirmHold?.toNamed('confirm-hold'), ]; case NoteDirection.RIGHT: [ - _data.assets.noteStrumline.data.rightStatic.toNamed('static'), - _data.assets.noteStrumline.data.rightPress.toNamed('press'), - _data.assets.noteStrumline.data.rightConfirm.toNamed('confirm'), - _data.assets.noteStrumline.data.rightConfirmHold.toNamed('confirm-hold'), + _data.assets.noteStrumline?.data?.rightStatic?.toNamed('static'), + _data.assets.noteStrumline?.data?.rightPress?.toNamed('press'), + _data.assets.noteStrumline?.data?.rightConfirm?.toNamed('confirm'), + _data.assets.noteStrumline?.data?.rightConfirmHold?.toNamed('confirm-hold'), ]; + default: []; }; - return result; + return thx.Arrays.filterNull(result); } - public function applyStrumlineOffsets(target:StrumlineNote) + public function applyStrumlineOffsets(target:StrumlineNote):Void { - target.x += _data.assets.noteStrumline.offsets[0]; - target.y += _data.assets.noteStrumline.offsets[1]; + var offsets = _data?.assets?.noteStrumline?.offsets ?? [0.0, 0.0]; + target.x += offsets[0]; + target.y += offsets[1]; } public function getStrumlineScale():Float { - return _data.assets.noteStrumline.scale; + return _data?.assets?.noteStrumline?.scale ?? 1.0; } public function isNoteSplashEnabled():Bool { var data = _data?.assets?.noteSplash?.data; - if (data == null) return fallback.isNoteSplashEnabled(); - return data.enabled; + if (data == null) return fallback?.isNoteSplashEnabled() ?? false; + return data.enabled ?? false; } public function isHoldNoteCoverEnabled():Bool { var data = _data?.assets?.holdNoteCover?.data; - if (data == null) return fallback.isHoldNoteCoverEnabled(); - return data.enabled; + if (data == null) return fallback?.isHoldNoteCoverEnabled() ?? false; + return data.enabled ?? false; + } + + /** + * Build a sprite for the given step of the countdown. + * @param step + * @return A `FunkinSprite`, or `null` if no graphic is available for this step. + */ + public function buildCountdownSprite(step:Countdown.CountdownStep):Null + { + var result = new FunkinSprite(); + + switch (step) + { + case THREE: + if (_data.assets.countdownThree == null) return fallback?.buildCountdownSprite(step); + var assetPath = buildCountdownSpritePath(step); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.countdownThree?.scale ?? 1.0; + result.scale.y = _data.assets.countdownThree?.scale ?? 1.0; + case TWO: + if (_data.assets.countdownTwo == null) return fallback?.buildCountdownSprite(step); + var assetPath = buildCountdownSpritePath(step); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.countdownTwo?.scale ?? 1.0; + result.scale.y = _data.assets.countdownTwo?.scale ?? 1.0; + case ONE: + if (_data.assets.countdownOne == null) return fallback?.buildCountdownSprite(step); + var assetPath = buildCountdownSpritePath(step); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.countdownOne?.scale ?? 1.0; + result.scale.y = _data.assets.countdownOne?.scale ?? 1.0; + case GO: + if (_data.assets.countdownGo == null) return fallback?.buildCountdownSprite(step); + var assetPath = buildCountdownSpritePath(step); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.countdownGo?.scale ?? 1.0; + result.scale.y = _data.assets.countdownGo?.scale ?? 1.0; + default: + // TODO: Do something here? + return null; + } + + result.scrollFactor.set(0, 0); + result.antialiasing = !isCountdownSpritePixel(step); + result.updateHitbox(); + + return result; + } + + function buildCountdownSpritePath(step:Countdown.CountdownStep):Null + { + var basePath:Null = null; + switch (step) + { + case THREE: + basePath = _data.assets.countdownThree?.assetPath; + case TWO: + basePath = _data.assets.countdownTwo?.assetPath; + case ONE: + basePath = _data.assets.countdownOne?.assetPath; + case GO: + basePath = _data.assets.countdownGo?.assetPath; + default: + basePath = null; + } + + if (basePath == null) return fallback?.buildCountdownSpritePath(step); + + var parts = basePath?.split(Constants.LIBRARY_SEPARATOR) ?? []; + if (parts.length < 1) return null; + if (parts.length == 1) return parts[0]; + + return parts[1]; + } + + function buildCountdownSpriteLibrary(step:Countdown.CountdownStep):Null + { + var basePath:Null = null; + switch (step) + { + case THREE: + basePath = _data.assets.countdownThree?.assetPath; + case TWO: + basePath = _data.assets.countdownTwo?.assetPath; + case ONE: + basePath = _data.assets.countdownOne?.assetPath; + case GO: + basePath = _data.assets.countdownGo?.assetPath; + default: + basePath = null; + } + + if (basePath == null) return fallback?.buildCountdownSpriteLibrary(step); + + var parts = basePath?.split(Constants.LIBRARY_SEPARATOR) ?? []; + if (parts.length <= 1) return null; + + return parts[0]; + } + + public function isCountdownSpritePixel(step:Countdown.CountdownStep):Bool + { + switch (step) + { + case THREE: + var result = _data.assets.countdownThree?.isPixel; + if (result == null && fallback != null) result = fallback.isCountdownSpritePixel(step); + return result ?? false; + case TWO: + var result = _data.assets.countdownTwo?.isPixel; + if (result == null && fallback != null) result = fallback.isCountdownSpritePixel(step); + return result ?? false; + case ONE: + var result = _data.assets.countdownOne?.isPixel; + if (result == null && fallback != null) result = fallback.isCountdownSpritePixel(step); + return result ?? false; + case GO: + var result = _data.assets.countdownGo?.isPixel; + if (result == null && fallback != null) result = fallback.isCountdownSpritePixel(step); + return result ?? false; + default: + return false; + } + } + + public function getCountdownSpriteOffsets(step:Countdown.CountdownStep):Array + { + switch (step) + { + case THREE: + var result = _data.assets.countdownThree?.offsets; + if (result == null && fallback != null) result = fallback.getCountdownSpriteOffsets(step); + return result ?? [0, 0]; + case TWO: + var result = _data.assets.countdownTwo?.offsets; + if (result == null && fallback != null) result = fallback.getCountdownSpriteOffsets(step); + return result ?? [0, 0]; + case ONE: + var result = _data.assets.countdownOne?.offsets; + if (result == null && fallback != null) result = fallback.getCountdownSpriteOffsets(step); + return result ?? [0, 0]; + case GO: + var result = _data.assets.countdownGo?.offsets; + if (result == null && fallback != null) result = fallback.getCountdownSpriteOffsets(step); + return result ?? [0, 0]; + default: + return [0, 0]; + } + } + + public function getCountdownSoundPath(step:Countdown.CountdownStep, raw:Bool = false):Null + { + if (raw) + { + // TODO: figure out why ?. didn't work here + var rawPath:Null = switch (step) + { + case Countdown.CountdownStep.THREE: + _data.assets.countdownThree?.data?.audioPath; + case Countdown.CountdownStep.TWO: + _data.assets.countdownTwo?.data?.audioPath; + case Countdown.CountdownStep.ONE: + _data.assets.countdownOne?.data?.audioPath; + case Countdown.CountdownStep.GO: + _data.assets.countdownGo?.data?.audioPath; + default: + null; + } + + return (rawPath == null && fallback != null) ? fallback.getCountdownSoundPath(step, true) : rawPath; + } + + // library:path + var parts = getCountdownSoundPath(step, true)?.split(Constants.LIBRARY_SEPARATOR) ?? []; + if (parts.length == 0) return null; + if (parts.length == 1) return Paths.image(parts[0]); + return Paths.sound(parts[1], parts[0]); + } + + public function buildJudgementSprite(rating:String):Null + { + var result = new FunkinSprite(); + + switch (rating) + { + case "sick": + if (_data.assets.judgementSick == null) return fallback?.buildJudgementSprite(rating); + var assetPath = buildJudgementSpritePath(rating); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.judgementSick?.scale ?? 1.0; + result.scale.y = _data.assets.judgementSick?.scale ?? 1.0; + case "good": + if (_data.assets.judgementGood == null) return fallback?.buildJudgementSprite(rating); + var assetPath = buildJudgementSpritePath(rating); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.judgementGood?.scale ?? 1.0; + result.scale.y = _data.assets.judgementGood?.scale ?? 1.0; + case "bad": + if (_data.assets.judgementBad == null) return fallback?.buildJudgementSprite(rating); + var assetPath = buildJudgementSpritePath(rating); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.judgementBad?.scale ?? 1.0; + result.scale.y = _data.assets.judgementBad?.scale ?? 1.0; + case "shit": + if (_data.assets.judgementShit == null) return fallback?.buildJudgementSprite(rating); + var assetPath = buildJudgementSpritePath(rating); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.judgementShit?.scale ?? 1.0; + result.scale.y = _data.assets.judgementShit?.scale ?? 1.0; + default: + return null; + } + + result.scrollFactor.set(0.2, 0.2); + var isPixel = isJudgementSpritePixel(rating); + result.antialiasing = !isPixel; + result.pixelPerfectRender = isPixel; + result.pixelPerfectPosition = isPixel; + result.updateHitbox(); + + return result; + } + + public function isJudgementSpritePixel(rating:String):Bool + { + switch (rating) + { + case "sick": + var result = _data.assets.judgementSick?.isPixel; + if (result == null && fallback != null) result = fallback.isJudgementSpritePixel(rating); + return result ?? false; + case "good": + var result = _data.assets.judgementGood?.isPixel; + if (result == null && fallback != null) result = fallback.isJudgementSpritePixel(rating); + return result ?? false; + case "bad": + var result = _data.assets.judgementBad?.isPixel; + if (result == null && fallback != null) result = fallback.isJudgementSpritePixel(rating); + return result ?? false; + case "GO": + var result = _data.assets.judgementShit?.isPixel; + if (result == null && fallback != null) result = fallback.isJudgementSpritePixel(rating); + return result ?? false; + default: + return false; + } + } + + function buildJudgementSpritePath(rating:String):Null + { + var basePath:Null = null; + switch (rating) + { + case "sick": + basePath = _data.assets.judgementSick?.assetPath; + case "good": + basePath = _data.assets.judgementGood?.assetPath; + case "bad": + basePath = _data.assets.judgementBad?.assetPath; + case "shit": + basePath = _data.assets.judgementShit?.assetPath; + default: + basePath = null; + } + + if (basePath == null) return fallback?.buildJudgementSpritePath(rating); + + var parts = basePath?.split(Constants.LIBRARY_SEPARATOR) ?? []; + if (parts.length < 1) return null; + if (parts.length == 1) return parts[0]; + + return parts[1]; + } + + public function getJudgementSpriteOffsets(rating:String):Array + { + switch (rating) + { + case "sick": + var result = _data.assets.judgementSick?.offsets; + if (result == null && fallback != null) result = fallback.getJudgementSpriteOffsets(rating); + return result ?? [0, 0]; + case "good": + var result = _data.assets.judgementGood?.offsets; + if (result == null && fallback != null) result = fallback.getJudgementSpriteOffsets(rating); + return result ?? [0, 0]; + case "bad": + var result = _data.assets.judgementBad?.offsets; + if (result == null && fallback != null) result = fallback.getJudgementSpriteOffsets(rating); + return result ?? [0, 0]; + case "shit": + var result = _data.assets.judgementShit?.offsets; + if (result == null && fallback != null) result = fallback.getJudgementSpriteOffsets(rating); + return result ?? [0, 0]; + default: + return [0, 0]; + } + } + + public function buildComboNumSprite(digit:Int):Null + { + var result = new FunkinSprite(); + + switch (digit) + { + case 0: + if (_data.assets.comboNumber0 == null) return fallback?.buildComboNumSprite(digit); + var assetPath = buildComboNumSpritePath(digit); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.comboNumber0?.scale ?? 1.0; + result.scale.y = _data.assets.comboNumber0?.scale ?? 1.0; + case 1: + if (_data.assets.comboNumber1 == null) return fallback?.buildComboNumSprite(digit); + var assetPath = buildComboNumSpritePath(digit); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.comboNumber1?.scale ?? 1.0; + result.scale.y = _data.assets.comboNumber1?.scale ?? 1.0; + case 2: + if (_data.assets.comboNumber2 == null) return fallback?.buildComboNumSprite(digit); + var assetPath = buildComboNumSpritePath(digit); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.comboNumber2?.scale ?? 1.0; + result.scale.y = _data.assets.comboNumber2?.scale ?? 1.0; + case 3: + if (_data.assets.comboNumber3 == null) return fallback?.buildComboNumSprite(digit); + var assetPath = buildComboNumSpritePath(digit); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.comboNumber3?.scale ?? 1.0; + result.scale.y = _data.assets.comboNumber3?.scale ?? 1.0; + case 4: + if (_data.assets.comboNumber4 == null) return fallback?.buildComboNumSprite(digit); + var assetPath = buildComboNumSpritePath(digit); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.comboNumber4?.scale ?? 1.0; + result.scale.y = _data.assets.comboNumber4?.scale ?? 1.0; + case 5: + if (_data.assets.comboNumber5 == null) return fallback?.buildComboNumSprite(digit); + var assetPath = buildComboNumSpritePath(digit); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.comboNumber5?.scale ?? 1.0; + result.scale.y = _data.assets.comboNumber5?.scale ?? 1.0; + case 6: + if (_data.assets.comboNumber6 == null) return fallback?.buildComboNumSprite(digit); + var assetPath = buildComboNumSpritePath(digit); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.comboNumber6?.scale ?? 1.0; + result.scale.y = _data.assets.comboNumber6?.scale ?? 1.0; + case 7: + if (_data.assets.comboNumber7 == null) return fallback?.buildComboNumSprite(digit); + var assetPath = buildComboNumSpritePath(digit); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.comboNumber7?.scale ?? 1.0; + result.scale.y = _data.assets.comboNumber7?.scale ?? 1.0; + case 8: + if (_data.assets.comboNumber8 == null) return fallback?.buildComboNumSprite(digit); + var assetPath = buildComboNumSpritePath(digit); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.comboNumber8?.scale ?? 1.0; + result.scale.y = _data.assets.comboNumber8?.scale ?? 1.0; + case 9: + if (_data.assets.comboNumber9 == null) return fallback?.buildComboNumSprite(digit); + var assetPath = buildComboNumSpritePath(digit); + if (assetPath == null) return null; + result.loadTexture(assetPath); + result.scale.x = _data.assets.comboNumber9?.scale ?? 1.0; + result.scale.y = _data.assets.comboNumber9?.scale ?? 1.0; + default: + return null; + } + + var isPixel = isComboNumSpritePixel(digit); + result.antialiasing = !isPixel; + result.pixelPerfectRender = isPixel; + result.pixelPerfectPosition = isPixel; + result.updateHitbox(); + + return result; + } + + public function isComboNumSpritePixel(digit:Int):Bool + { + switch (digit) + { + case 0: + var result = _data.assets.comboNumber0?.isPixel; + if (result == null && fallback != null) result = fallback.isComboNumSpritePixel(digit); + return result ?? false; + case 1: + var result = _data.assets.comboNumber1?.isPixel; + if (result == null && fallback != null) result = fallback.isComboNumSpritePixel(digit); + return result ?? false; + case 2: + var result = _data.assets.comboNumber2?.isPixel; + if (result == null && fallback != null) result = fallback.isComboNumSpritePixel(digit); + return result ?? false; + case 3: + var result = _data.assets.comboNumber3?.isPixel; + if (result == null && fallback != null) result = fallback.isComboNumSpritePixel(digit); + return result ?? false; + case 4: + var result = _data.assets.comboNumber4?.isPixel; + if (result == null && fallback != null) result = fallback.isComboNumSpritePixel(digit); + return result ?? false; + case 5: + var result = _data.assets.comboNumber5?.isPixel; + if (result == null && fallback != null) result = fallback.isComboNumSpritePixel(digit); + return result ?? false; + case 6: + var result = _data.assets.comboNumber6?.isPixel; + if (result == null && fallback != null) result = fallback.isComboNumSpritePixel(digit); + return result ?? false; + case 7: + var result = _data.assets.comboNumber7?.isPixel; + if (result == null && fallback != null) result = fallback.isComboNumSpritePixel(digit); + return result ?? false; + case 8: + var result = _data.assets.comboNumber8?.isPixel; + if (result == null && fallback != null) result = fallback.isComboNumSpritePixel(digit); + return result ?? false; + case 9: + var result = _data.assets.comboNumber9?.isPixel; + if (result == null && fallback != null) result = fallback.isComboNumSpritePixel(digit); + return result ?? false; + default: + return false; + } + } + + function buildComboNumSpritePath(digit:Int):Null + { + var basePath:Null = null; + switch (digit) + { + case 0: + basePath = _data.assets.comboNumber0?.assetPath; + case 1: + basePath = _data.assets.comboNumber1?.assetPath; + case 2: + basePath = _data.assets.comboNumber2?.assetPath; + case 3: + basePath = _data.assets.comboNumber3?.assetPath; + case 4: + basePath = _data.assets.comboNumber4?.assetPath; + case 5: + basePath = _data.assets.comboNumber5?.assetPath; + case 6: + basePath = _data.assets.comboNumber6?.assetPath; + case 7: + basePath = _data.assets.comboNumber7?.assetPath; + case 8: + basePath = _data.assets.comboNumber8?.assetPath; + case 9: + basePath = _data.assets.comboNumber9?.assetPath; + default: + basePath = null; + } + + if (basePath == null) return fallback?.buildComboNumSpritePath(digit); + + var parts = basePath?.split(Constants.LIBRARY_SEPARATOR) ?? []; + if (parts.length < 1) return null; + if (parts.length == 1) return parts[0]; + + return parts[1]; + } + + public function getComboNumSpriteOffsets(digit:Int):Array + { + switch (digit) + { + case 0: + var result = _data.assets.comboNumber0?.offsets; + if (result == null && fallback != null) result = fallback.getComboNumSpriteOffsets(digit); + return result ?? [0, 0]; + case 1: + var result = _data.assets.comboNumber1?.offsets; + if (result == null && fallback != null) result = fallback.getComboNumSpriteOffsets(digit); + return result ?? [0, 0]; + case 2: + var result = _data.assets.comboNumber2?.offsets; + if (result == null && fallback != null) result = fallback.getComboNumSpriteOffsets(digit); + return result ?? [0, 0]; + case 3: + var result = _data.assets.comboNumber3?.offsets; + if (result == null && fallback != null) result = fallback.getComboNumSpriteOffsets(digit); + return result ?? [0, 0]; + case 4: + var result = _data.assets.comboNumber4?.offsets; + if (result == null && fallback != null) result = fallback.getComboNumSpriteOffsets(digit); + return result ?? [0, 0]; + case 5: + var result = _data.assets.comboNumber5?.offsets; + if (result == null && fallback != null) result = fallback.getComboNumSpriteOffsets(digit); + return result ?? [0, 0]; + case 6: + var result = _data.assets.comboNumber6?.offsets; + if (result == null && fallback != null) result = fallback.getComboNumSpriteOffsets(digit); + return result ?? [0, 0]; + case 7: + var result = _data.assets.comboNumber7?.offsets; + if (result == null && fallback != null) result = fallback.getComboNumSpriteOffsets(digit); + return result ?? [0, 0]; + case 8: + var result = _data.assets.comboNumber8?.offsets; + if (result == null && fallback != null) result = fallback.getComboNumSpriteOffsets(digit); + return result ?? [0, 0]; + case 9: + var result = _data.assets.comboNumber9?.offsets; + if (result == null && fallback != null) result = fallback.getComboNumSpriteOffsets(digit); + return result ?? [0, 0]; + default: + return [0, 0]; + } } public function destroy():Void {} @@ -322,8 +867,17 @@ class NoteStyle implements IRegistryEntry return 'NoteStyle($id)'; } - static function _fetchData(id:String):Null + static function _fetchData(id:String):NoteStyleData { - return NoteStyleRegistry.instance.parseEntryDataWithMigration(id, NoteStyleRegistry.instance.fetchEntryVersion(id)); + var result = NoteStyleRegistry.instance.parseEntryDataWithMigration(id, NoteStyleRegistry.instance.fetchEntryVersion(id)); + + if (result == null) + { + throw 'Could not parse note style data for id: $id'; + } + else + { + return result; + } } } diff --git a/source/funkin/ui/debug/charting/components/ChartEditorHoldNoteSprite.hx b/source/funkin/ui/debug/charting/components/ChartEditorHoldNoteSprite.hx index 1e631f2cf..ff8446c49 100644 --- a/source/funkin/ui/debug/charting/components/ChartEditorHoldNoteSprite.hx +++ b/source/funkin/ui/debug/charting/components/ChartEditorHoldNoteSprite.hx @@ -60,7 +60,9 @@ class ChartEditorHoldNoteSprite extends SustainTrail override function setupHoldNoteGraphic(noteStyle:NoteStyle):Void { - loadGraphic(noteStyle.getHoldNoteAssetPath()); + var graphicPath = noteStyle.getHoldNoteAssetPath(); + if (graphicPath == null) return; + loadGraphic(graphicPath); antialiasing = true; From c9c81fae51e5f2a23ee7fc1ac0cfd499e95b1b9a Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Mon, 29 Jul 2024 21:26:02 -0400 Subject: [PATCH 18/28] assets submod? --- assets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets b/assets index 005c96f85..aa1231e8c 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 005c96f85f4304865acb196e7cc4d6d83f9d76d8 +Subproject commit aa1231e8cf2990bb902eac3b37815c010fa9919a From 3b7e65679357687bd6901f45c120de06970d46f8 Mon Sep 17 00:00:00 2001 From: FabsTheFabs Date: Wed, 31 Jul 2024 14:36:06 +0100 Subject: [PATCH 19/28] add stage names to registry + chart editor --- source/funkin/data/stage/StageRegistry.hx | 4 ++-- source/funkin/ui/debug/charting/ChartEditorState.hx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/funkin/data/stage/StageRegistry.hx b/source/funkin/data/stage/StageRegistry.hx index fbb6f188e..1f0504247 100644 --- a/source/funkin/data/stage/StageRegistry.hx +++ b/source/funkin/data/stage/StageRegistry.hx @@ -93,8 +93,8 @@ class StageRegistry extends BaseRegistry public function listBaseGameStageIds():Array { return [ - "mainStage", "spookyMansion", "phillyTrain", "phillyTrainErect", "limoRide", "mallXmas", "mallEvil", "school", "schoolEvil", "tankmanBattlefield", - "phillyStreets", "phillyBlazin", + "mainStage", "spookyMansion", "phillyTrain", "phillyTrainErect", "limoRide", "limoRideErect", "mallXmas", "mallEvil", "school", "schoolEvil", + "tankmanBattlefield", "phillyStreets", "phillyBlazin", ]; } diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index a4e0de61e..24d290abd 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -5707,7 +5707,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState PlayStatePlaylist.campaignId = 'week2'; case 'phillyTrain' | 'phillyTrainErect': PlayStatePlaylist.campaignId = 'week3'; - case 'limoRide': + case 'limoRide' | 'limoRideErect': PlayStatePlaylist.campaignId = 'week4'; case 'mallXmas' | 'mallEvil': PlayStatePlaylist.campaignId = 'week5'; From 270748d1081a947c0c84ecd718e65ccb34ba6911 Mon Sep 17 00:00:00 2001 From: FabsTheFabs Date: Wed, 31 Jul 2024 14:36:24 +0100 Subject: [PATCH 20/28] fuck these decimals messing up my compiling --- source/funkin/ui/freeplay/FreeplayState.hx | 2 +- source/funkin/ui/story/LevelProp.hx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/funkin/ui/freeplay/FreeplayState.hx b/source/funkin/ui/freeplay/FreeplayState.hx index dc42bd651..fa895042f 100644 --- a/source/funkin/ui/freeplay/FreeplayState.hx +++ b/source/funkin/ui/freeplay/FreeplayState.hx @@ -1527,7 +1527,7 @@ class FreeplayState extends MusicBeatSubState var moveDataX = funnyMoveShit.x ?? spr.x; var moveDataY = funnyMoveShit.y ?? spr.y; var moveDataSpeed = funnyMoveShit.speed ?? 0.2; - var moveDataWait = funnyMoveShit.wait ?? 0; + var moveDataWait = funnyMoveShit.wait ?? 0.0; FlxTween.tween(spr, {x: moveDataX, y: moveDataY}, moveDataSpeed, {ease: FlxEase.expoIn}); diff --git a/source/funkin/ui/story/LevelProp.hx b/source/funkin/ui/story/LevelProp.hx index 0547404a1..4e78415e3 100644 --- a/source/funkin/ui/story/LevelProp.hx +++ b/source/funkin/ui/story/LevelProp.hx @@ -16,7 +16,7 @@ class LevelProp extends Bopper this.propData = value; this.visible = this.propData != null; - danceEvery = this.propData?.danceEvery ?? 0; + danceEvery = this.propData?.danceEvery ?? 0.0; applyData(); } From 8200a08152ceea85cd242b990518007af5d4806f Mon Sep 17 00:00:00 2001 From: FabsTheFabs Date: Wed, 31 Jul 2024 14:36:34 +0100 Subject: [PATCH 21/28] assets submod --- assets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets b/assets index cfd67caa6..06067d187 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit cfd67caa688465b4a282837434832c107b661b04 +Subproject commit 06067d187e7699a8eec42ab07c53d195c589a690 From f4968b0ae5211e70f99d68f8de618553c8eb9a35 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Mon, 5 Aug 2024 10:47:59 -0400 Subject: [PATCH 22/28] openfl hmm commit to dev-funkin --- hmm.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hmm.json b/hmm.json index e9aa678ef..c72b4240a 100644 --- a/hmm.json +++ b/hmm.json @@ -178,7 +178,7 @@ "name": "openfl", "type": "git", "dir": null, - "ref": "228c1b5063911e2ad75cef6e3168ef0a4b9f9134", + "ref": "8306425c497766739510ab29e876059c96f77bd2", "url": "https://github.com/FunkinCrew/openfl" }, { From 62d0b33689f3cae21c32778e3428b93a7a50c60c Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Tue, 6 Aug 2024 13:44:02 -0400 Subject: [PATCH 23/28] Fix for switching to old icon on isPixel levels --- source/funkin/play/components/HealthIcon.hx | 54 ++++++++++++++------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/source/funkin/play/components/HealthIcon.hx b/source/funkin/play/components/HealthIcon.hx index 2442b0dc5..0e24d73fb 100644 --- a/source/funkin/play/components/HealthIcon.hx +++ b/source/funkin/play/components/HealthIcon.hx @@ -150,13 +150,17 @@ class HealthIcon extends FunkinSprite { if (characterId == 'bf-old') { + isPixel = PlayState.instance.currentStage.getBoyfriend().isPixel; PlayState.instance.currentStage.getBoyfriend().initHealthIcon(false); } else { characterId = 'bf-old'; + isPixel = false; loadCharacter(characterId); } + + lerpIconSize(true); } /** @@ -200,31 +204,45 @@ class HealthIcon extends FunkinSprite if (bopEvery != 0) { - // Lerp the health icon back to its normal size, - // while maintaining aspect ratio. - if (this.width > this.height) - { - // Apply linear interpolation while accounting for frame rate. - var targetSize:Int = Std.int(MathUtil.coolLerp(this.width, HEALTH_ICON_SIZE * this.size.x, 0.15)); - - setGraphicSize(targetSize, 0); - } - else - { - var targetSize:Int = Std.int(MathUtil.coolLerp(this.height, HEALTH_ICON_SIZE * this.size.y, 0.15)); - - setGraphicSize(0, targetSize); - } + lerpIconSize(); // Lerp the health icon back to its normal angle. this.angle = MathUtil.coolLerp(this.angle, 0, 0.15); - - this.updateHitbox(); } this.updatePosition(); } + /** + * Does the calculation to lerp the icon size. Usually called every frame, but can be forced to the target size. + * Mainly forced when changing to old icon to not have a weird lerp related to changing from pixel icon to non-pixel old icon + * @param force Force the icon immedialtely to be the target size. Defaults to false. + */ + function lerpIconSize(force:Bool = false):Void + { + // Lerp the health icon back to its normal size, + // while maintaining aspect ratio. + if (this.width > this.height) + { + // Apply linear interpolation while accounting for frame rate. + var targetSize:Int = Std.int(MathUtil.coolLerp(this.width, HEALTH_ICON_SIZE * this.size.x, 0.15)); + + if (force) targetSize = Std.int(HEALTH_ICON_SIZE * this.size.x); + + setGraphicSize(targetSize, 0); + } + else + { + var targetSize:Int = Std.int(MathUtil.coolLerp(this.height, HEALTH_ICON_SIZE * this.size.y, 0.15)); + + if (force) targetSize = Std.int(HEALTH_ICON_SIZE * this.size.y); + + setGraphicSize(0, targetSize); + } + + this.updateHitbox(); + } + /** * Update the position (and status) of the health icon. */ @@ -412,6 +430,8 @@ class HealthIcon extends FunkinSprite isLegacyStyle = !isNewSpritesheet(charId); + trace(' Loading health icon for character: $charId (legacy: $isLegacyStyle)'); + if (!isLegacyStyle) { loadSparrow('icons/icon-$charId'); From ae648418c2e860dc33a9b61d4be611719209fb53 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Tue, 6 Aug 2024 14:03:25 -0400 Subject: [PATCH 24/28] assets submod senpai fix --- assets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets b/assets index aa1231e8c..a659c2a58 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit aa1231e8cf2990bb902eac3b37815c010fa9919a +Subproject commit a659c2a58d2d8b8036102e563a9c620a590da50a From c3d497a9d907b38cd11d1fa15f2d9a85bf82db96 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Wed, 7 Aug 2024 19:01:46 -0400 Subject: [PATCH 25/28] hxcpp bump --- hmm.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hmm.json b/hmm.json index c72b4240a..aad0be8cf 100644 --- a/hmm.json +++ b/hmm.json @@ -104,7 +104,7 @@ "type": "git", "dir": null, "url": "https://github.com/HaxeFoundation/hxcpp", - "ref": "01cfee282a9a783e10c5a7774a3baaf547e6b0a7" + "ref": "8dc8020f8465027de6c2aaaed90718bc693651ed" }, { "name": "hxcpp-debug-server", From 9ff3e0435ad7b51ef88ceabff8909b4f2845f18e Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Fri, 9 Aug 2024 23:02:46 -0400 Subject: [PATCH 26/28] assets submod --- assets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets b/assets index a659c2a58..62c4a8203 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit a659c2a58d2d8b8036102e563a9c620a590da50a +Subproject commit 62c4a8203362c1b434de0d376046ebccb96da254 From b47c695cb7acbe032dc717017332f0395dd92656 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Fri, 9 Aug 2024 23:09:23 -0400 Subject: [PATCH 27/28] perhaps use funkin versions of haxelib and hmm? --- .github/actions/setup-haxe/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup-haxe/action.yml b/.github/actions/setup-haxe/action.yml index 5a9f7b293..701a023f9 100644 --- a/.github/actions/setup-haxe/action.yml +++ b/.github/actions/setup-haxe/action.yml @@ -60,8 +60,8 @@ runs: haxelib --debug --never deleterepo || true haxelib --debug --never newrepo echo "HAXEPATH=$(haxelib config)" >> "$GITHUB_ENV" - haxelib --debug --never git haxelib https://github.com/HaxeFoundation/haxelib.git master - haxelib --debug --global install hmm + haxelib --debug --never git haxelib https://github.com/FunkinCrew/haxelib.git funkin-patches --skip-dependencies + haxelib --debug --global git hmm https://github.com/FunkinCrew/hmm funkin-patches echo "TIMER_DEPS=$(date +%s)" >> "$GITHUB_ENV" - name: Restore cached dependencies From a0047a482fd7263ba1b015c4a015054f97b52d7b Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Fri, 9 Aug 2024 23:31:40 -0400 Subject: [PATCH 28/28] use --always when installing funkin-patches versions of haxelib and hmm --- .github/actions/setup-haxe/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup-haxe/action.yml b/.github/actions/setup-haxe/action.yml index 701a023f9..b22fc6f69 100644 --- a/.github/actions/setup-haxe/action.yml +++ b/.github/actions/setup-haxe/action.yml @@ -60,8 +60,8 @@ runs: haxelib --debug --never deleterepo || true haxelib --debug --never newrepo echo "HAXEPATH=$(haxelib config)" >> "$GITHUB_ENV" - haxelib --debug --never git haxelib https://github.com/FunkinCrew/haxelib.git funkin-patches --skip-dependencies - haxelib --debug --global git hmm https://github.com/FunkinCrew/hmm funkin-patches + haxelib --debug --always --global git haxelib https://github.com/FunkinCrew/haxelib.git funkin-patches --skip-dependencies + haxelib --debug --global --always git hmm https://github.com/FunkinCrew/hmm funkin-patches echo "TIMER_DEPS=$(date +%s)" >> "$GITHUB_ENV" - name: Restore cached dependencies