Skip to content

Commit

Permalink
fix assets file list getting incorrect files
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed Apr 9, 2024
1 parent b7e615a commit d610b69
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
14 changes: 11 additions & 3 deletions source/funkin/graphics/FlxSpriteExt.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions source/funkin/sound/FlxFunkSoundGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ class FlxFunkSoundGroup<T:FlxFunkSound> 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();
}
});
});

@: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;
}
Expand Down Expand Up @@ -68,7 +68,7 @@ class FlxFunkSoundGroup<T:FlxFunkSound> 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);
}
}

Expand All @@ -84,7 +84,7 @@ class FlxFunkSoundGroup<T:FlxFunkSound> 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;
}

Expand All @@ -99,7 +99,7 @@ class FlxFunkSoundGroup<T:FlxFunkSound> extends FlxBasic
sounds.fastForEach((sound, i) -> {
if (sound != null) if (!sound.persist) {
sound.destroy();
sounds[i] = null;
sounds.unsafeSet(i, null);
}
});
}
Expand Down
21 changes: 14 additions & 7 deletions source/funkin/util/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,30 @@ class Paths
return frames;
}

static public function getFileList(type:AssetType = IMAGE, fullPath:Bool = true, ?extension:String, ?folder:String):Array<String>
static public function getFileList(type:AssetType = IMAGE, fullPath:Bool = true, extension:String = "", folder:String = ""):Array<String>
{
var fileList:Array<String> = [];
if (folder.length > 0) if (!folder.endsWith("/"))
folder = '$folder/';

var list:Array<String> = [];
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<String> {
Expand Down

0 comments on commit d610b69

Please sign in to comment.