From d610b69a778baadce7de44461e1cbc2b73f357eb Mon Sep 17 00:00:00 2001 From: MaybeMaru <97055307+MaybeMaru@users.noreply.github.com> Date: Wed, 10 Apr 2024 00:23:13 +0200 Subject: [PATCH] fix assets file list getting incorrect files --- source/funkin/graphics/FlxSpriteExt.hx | 14 +++++++++++--- source/funkin/sound/FlxFunkSoundGroup.hx | 14 +++++++------- source/funkin/util/Paths.hx | 21 ++++++++++++++------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/source/funkin/graphics/FlxSpriteExt.hx b/source/funkin/graphics/FlxSpriteExt.hx index 7c1b4c5b..7020d04e 100644 --- a/source/funkin/graphics/FlxSpriteExt.hx +++ b/source/funkin/graphics/FlxSpriteExt.hx @@ -401,7 +401,8 @@ class FlxSpriteExt extends FlxSkewedSprite @:noCompletion static final __scaleDiff:FlxPoint = FlxPoint.get(); inline public function getScaleDiff():FlxPoint { - return __scaleDiff.set(scale.x / spriteJson.scale, scale.y / spriteJson.scale); + var jsonScale:Float = spriteJson.scale; + return __scaleDiff.set(scale.x / jsonScale, scale.y / jsonScale); } public var scaleOffset:Bool = false; @@ -420,9 +421,16 @@ class FlxSpriteExt extends FlxSkewedSprite if (!point.isZero() || forced) { if (flippedOffsets) point.x = -point.x; // Flip X - if (scaleOffset) point.scalePoint(getScaleDiff()); // Scale offset - if (angle != 0) { // Angled offset + if (scaleOffset) // Scale offset + { + var diff = getScaleDiff(); + point.x = point.x * diff.x; + point.y = point.y * diff.y; + } + + if (angle != 0) // Angled offset + { offset.set( (point.x * _cosAngle) + (point.y * -_sinAngle), (point.x * _sinAngle) + (point.y * _cosAngle) diff --git a/source/funkin/sound/FlxFunkSoundGroup.hx b/source/funkin/sound/FlxFunkSoundGroup.hx index 589193c3..d556d7a1 100644 --- a/source/funkin/sound/FlxFunkSoundGroup.hx +++ b/source/funkin/sound/FlxFunkSoundGroup.hx @@ -12,9 +12,9 @@ class FlxFunkSoundGroup extends FlxBasic super(); @:privateAccess // Window lose focus, pause sounds - FlxG.stage.addEventListener(Event.DEACTIVATE, function (e) { + FlxG.stage.addEventListener(Event.DEACTIVATE, (e) -> { sounds.fastForEach((sound, i) -> { - if (sound.playing) { + if (sound != null) if (sound.playing) { sound.__gainFocus = true; sound.pause(); } @@ -22,9 +22,9 @@ class FlxFunkSoundGroup extends FlxBasic }); @:privateAccess // Window gain focus, resume sounds - FlxG.stage.addEventListener(Event.ACTIVATE, function (e) { + FlxG.stage.addEventListener(Event.ACTIVATE, (e) -> { sounds.fastForEach((sound, i) -> { - if (sound.__gainFocus) { + if (sound != null) if (sound.__gainFocus) { sound.resume(); sound.__gainFocus = false; } @@ -68,7 +68,7 @@ class FlxFunkSoundGroup extends FlxBasic var index = sounds.indexOf(sound); if (index != -1) { - splice ? sounds.splice(index, 1) : sounds[index] = null; + splice ? sounds.splice(index, 1) : sounds.unsafeSet(index, null); } } @@ -84,7 +84,7 @@ class FlxFunkSoundGroup extends FlxBasic // Get the first null index of the group var nullIndex = sounds.indexOf(null); if (nullIndex != -1) { - sounds[nullIndex] = sound; + sounds.unsafeSet(nullIndex, sound); return sound; } @@ -99,7 +99,7 @@ class FlxFunkSoundGroup extends FlxBasic sounds.fastForEach((sound, i) -> { if (sound != null) if (!sound.persist) { sound.destroy(); - sounds[i] = null; + sounds.unsafeSet(i, null); } }); } diff --git a/source/funkin/util/Paths.hx b/source/funkin/util/Paths.hx index 5dd3f767..72fa6334 100644 --- a/source/funkin/util/Paths.hx +++ b/source/funkin/util/Paths.hx @@ -289,23 +289,30 @@ class Paths return frames; } - static public function getFileList(type:AssetType = IMAGE, fullPath:Bool = true, ?extension:String, ?folder:String):Array + static public function getFileList(type:AssetType = IMAGE, fullPath:Bool = true, extension:String = "", folder:String = ""):Array { - var fileList:Array = []; + if (folder.length > 0) if (!folder.endsWith("/")) + folder = '$folder/'; + + var list:Array = []; OpenFlAssets.list(type).fastForEach((file, i) -> { if (file.startsWith('assets/')) { - if (extension == null || file.endsWith(extension)) + if (extension.length == 0 || file.endsWith(extension)) { - if (folder == null || file.contains(folder)) - fileList.push(fullPath ? file : file.split('/')[file.split('/').length-1].split('.')[0]); + if (folder.length == 0 || file.contains(folder)) + { + list.push(fullPath ? file + : file.split('/')[file.split('/').length-1].split('.')[0] + ); + } } } }); - fileList.sort(CoolUtil.sortAlphabetically); - return fileList; + list.sort(CoolUtil.sortAlphabetically); + return list; } static public function getModFileList(folder:String, ?extension:String, fullPath:Bool = true, global:Bool = true, curFolder:Bool = true, allFolders:Bool = false):Array {