From 51bb34fc57e744a18729c33f29c614f69d3d6404 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Wed, 11 Dec 2024 16:18:28 -0600 Subject: [PATCH 1/7] auto add sound extensions --- flixel/sound/FlxSound.hx | 2 ++ flixel/system/frontEnds/AssetFrontEnd.hx | 34 ++++++++++++++++++++---- flixel/system/frontEnds/SoundFrontEnd.hx | 6 +++++ flixel/system/macros/FlxDefines.hx | 6 +++++ tests/coverage/Project.xml | 2 ++ 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/flixel/sound/FlxSound.hx b/flixel/sound/FlxSound.hx index e087968790..ff7f3e8213 100644 --- a/flixel/sound/FlxSound.hx +++ b/flixel/sound/FlxSound.hx @@ -337,6 +337,8 @@ class FlxSound extends FlxBasic /** * One of the main setup functions for sounds, this function loads a sound from an embedded MP3. * + * **Note:** If the `FLX_SOUND_ADD_EXT` flag is enabled, you may omit the file extension + * * @param EmbeddedSound An embedded Class object representing an MP3 file. * @param Looped Whether or not this sound should loop endlessly. * @param AutoDestroy Whether or not this FlxSound instance should be destroyed when the sound finishes playing. diff --git a/flixel/system/frontEnds/AssetFrontEnd.hx b/flixel/system/frontEnds/AssetFrontEnd.hx index 6c2d7cf3a9..e13be9069a 100644 --- a/flixel/system/frontEnds/AssetFrontEnd.hx +++ b/flixel/system/frontEnds/AssetFrontEnd.hx @@ -231,6 +231,10 @@ class AssetFrontEnd */ public dynamic function exists(id:String, ?type:FlxAssetType) { + // add file extension + if (type == SOUND) + id = addSoundExtIf(id); + #if FLX_STANDARD_ASSETS_DIRECTORY return Assets.exists(id, type.toOpenFlType()); #else @@ -253,6 +257,10 @@ class AssetFrontEnd */ public dynamic function isLocal(id:String, ?type:FlxAssetType, useCache = true) { + // add file extension + if (type == SOUND) + id = addSoundExtIf(id); + #if FLX_STANDARD_ASSETS_DIRECTORY return Assets.isLocal(id, type.toOpenFlType(), useCache); #else @@ -327,11 +335,13 @@ class AssetFrontEnd */ public inline function getSoundUnsafe(id:String, useCache = true):Sound { - return cast getAssetUnsafe(id, SOUND, useCache); + return cast getAssetUnsafe(addSoundExtIf(id), SOUND, useCache); } /** - * Gets an instance of a sound, logs when the asset is not found + * Gets an instance of a sound, logs when the asset is not found. + * + * **Note:** If the `FLX_SOUND_ADD_EXT` flag is enabled, you may omit the file extension * * @param id The ID or asset path for the sound * @param useCache Whether to allow use of the asset cache (if one exists) @@ -340,7 +350,7 @@ class AssetFrontEnd */ public inline function getSound(id:String, useCache = true, ?logStyle:LogStyle):Sound { - return cast getAsset(id, SOUND, useCache, logStyle); + return cast getAsset(addSoundExtIf(id), SOUND, useCache, logStyle); } /** @@ -352,11 +362,25 @@ class AssetFrontEnd * @return A new `Sound` object Note: Dos not return a `FlxSound` */ public inline function getSoundAddExt(id:String, useCache = true, ?logStyle:LogStyle):Sound + { + return getSound(addSoundExt(id), useCache, logStyle); + } + + inline function addSoundExtIf(id:String) + { + #if FLX_SOUND_ADD_EXT + return addSoundExt(id); + #else + return id; + #end + } + + inline function addSoundExt(id:String) { if (!id.endsWith(".mp3") && !id.endsWith(".ogg") && !id.endsWith(".wav")) - id += "." + #if flash "mp3" #else "ogg" #end; + return id + "." + #if flash "mp3" #else "ogg" #end; - return getSound(id, useCache, logStyle); + return id; } /** diff --git a/flixel/system/frontEnds/SoundFrontEnd.hx b/flixel/system/frontEnds/SoundFrontEnd.hx index 3a40e9ddc5..4ecae68745 100644 --- a/flixel/system/frontEnds/SoundFrontEnd.hx +++ b/flixel/system/frontEnds/SoundFrontEnd.hx @@ -103,6 +103,8 @@ class SoundFrontEnd /** * Set up and play a looping background soundtrack. * + * **Note:** If the `FLX_SOUND_ADD_EXT` flag is enabled, you may omit the file extension + * * @param embeddedMusic The sound file you want to loop in the background. * @param volume How loud the sound should be, from 0 to 1. * @param looped Whether to loop this music. @@ -132,6 +134,8 @@ class SoundFrontEnd /** * Creates a new FlxSound object. * + * **Note:** If the `FLX_SOUND_ADD_EXT` flag is enabled, you may omit the file extension + * * @param embeddedSound The embedded sound resource you want to play. To stream, use the optional URL parameter instead. * @param volume How loud to play it (0 to 1). * @param looped Whether to loop this sound. @@ -230,6 +234,8 @@ class SoundFrontEnd /** * Plays a sound from an embedded sound. Tries to recycle a cached sound first. * + * **Note:** If the `FLX_SOUND_ADD_EXT` flag is enabled, you may omit the file extension + * * @param embeddedSound The embedded sound resource you want to play. * @param volume How loud to play it (0 to 1). * @param looped Whether to loop this sound. diff --git a/flixel/system/macros/FlxDefines.hx b/flixel/system/macros/FlxDefines.hx index c019da71ca..d8d2462c12 100644 --- a/flixel/system/macros/FlxDefines.hx +++ b/flixel/system/macros/FlxDefines.hx @@ -52,6 +52,10 @@ private enum UserDefines * any `` tags in your project.xml, to reduce your total memory */ FLX_CUSTOM_ASSETS_DIRECTORY; + /** + * allows you to use sound paths with no extension, and the default sound type for that target will be used + */ + FLX_SOUND_ADD_EXT; } /** @@ -100,6 +104,7 @@ private enum HelperDefines FLX_STANDARD_ASSETS_DIRECTORY; /** The normalized, absolute path of `FLX_CUSTOM_ASSETS_DIRECTORY`, used internally */ FLX_CUSTOM_ASSETS_DIRECTORY_ABS; + FLX_SOUND_NO_ADD_EXT } class FlxDefines @@ -200,6 +205,7 @@ class FlxDefines defineInversion(FLX_SWF_VERSION_TEST, FLX_NO_SWF_VERSION_TEST); defineInversion(FLX_NO_HEALTH, FLX_HEALTH); defineInversion(FLX_TRACK_POOLS, FLX_NO_TRACK_POOLS); + defineInversion(FLX_SOUND_ADD_EXT, FLX_SOUND_NO_ADD_EXT); // defineInversion(FLX_TRACK_GRAPHICS, FLX_NO_TRACK_GRAPHICS); // special case } diff --git a/tests/coverage/Project.xml b/tests/coverage/Project.xml index e53cc93d2e..46a00af3da 100644 --- a/tests/coverage/Project.xml +++ b/tests/coverage/Project.xml @@ -54,6 +54,7 @@ +
@@ -77,5 +78,6 @@ +
From 51c16fb9286f4b9e490ee1c8be614b0e04a1fe67 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Wed, 11 Dec 2024 16:35:08 -0600 Subject: [PATCH 2/7] allow FLX_SOUND_ADD_EXT to specify the extension --- flixel/system/frontEnds/AssetFrontEnd.hx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/flixel/system/frontEnds/AssetFrontEnd.hx b/flixel/system/frontEnds/AssetFrontEnd.hx index e13be9069a..65e64dd8f4 100644 --- a/flixel/system/frontEnds/AssetFrontEnd.hx +++ b/flixel/system/frontEnds/AssetFrontEnd.hx @@ -85,6 +85,16 @@ class AssetFrontEnd public function new () {} #end + #if (FLX_SOUND_ADD_EXT == "wav") + public static final defaultSoundExtension:String = '.wav'; + #elseif (FLX_SOUND_ADD_EXT == "mp3") + public static final defaultSoundExtension:String = '.mp3'; + #elseif (FLX_SOUND_ADD_EXT == "ogg") + public static final defaultSoundExtension:String = '.ogg'; + #else + public static final defaultSoundExtension:String = #if flash ".mp3" #else ".ogg" #end; + #end + /** * Used by methods like `getAsset`, `getBitmapData`, `getText`, their "unsafe" counterparts and * the like to get assets synchronously. Can be set to a custom function to avoid the existing @@ -378,7 +388,7 @@ class AssetFrontEnd inline function addSoundExt(id:String) { if (!id.endsWith(".mp3") && !id.endsWith(".ogg") && !id.endsWith(".wav")) - return id + "." + #if flash "mp3" #else "ogg" #end; + return id + defaultSoundExtension; return id; } From 04a47405ea168adb9057b0dcf70157bc741facf0 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Wed, 11 Dec 2024 16:39:16 -0600 Subject: [PATCH 3/7] doc --- flixel/system/macros/FlxDefines.hx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flixel/system/macros/FlxDefines.hx b/flixel/system/macros/FlxDefines.hx index d8d2462c12..7efeffcb3f 100644 --- a/flixel/system/macros/FlxDefines.hx +++ b/flixel/system/macros/FlxDefines.hx @@ -53,7 +53,9 @@ private enum UserDefines */ FLX_CUSTOM_ASSETS_DIRECTORY; /** - * allows you to use sound paths with no extension, and the default sound type for that target will be used + * Allows you to use sound paths with no extension, and the default sound type for that + * target will be used. If enabled it will use ogg on all targets except flash, which uses mp3. + * If this flag is set to "wav", "mp3" or "ogg" if will use that type */ FLX_SOUND_ADD_EXT; } From 64b2ca7eceb6f525562f2f38fc558251857aa66a Mon Sep 17 00:00:00 2001 From: George FunBook Date: Wed, 11 Dec 2024 16:45:13 -0600 Subject: [PATCH 4/7] d'oh --- flixel/system/macros/FlxDefines.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/system/macros/FlxDefines.hx b/flixel/system/macros/FlxDefines.hx index 7efeffcb3f..696d49677c 100644 --- a/flixel/system/macros/FlxDefines.hx +++ b/flixel/system/macros/FlxDefines.hx @@ -106,7 +106,7 @@ private enum HelperDefines FLX_STANDARD_ASSETS_DIRECTORY; /** The normalized, absolute path of `FLX_CUSTOM_ASSETS_DIRECTORY`, used internally */ FLX_CUSTOM_ASSETS_DIRECTORY_ABS; - FLX_SOUND_NO_ADD_EXT + FLX_SOUND_NO_ADD_EXT; } class FlxDefines From 21addbe9bdc967763a6034ceb6503022fcb42a9a Mon Sep 17 00:00:00 2001 From: George FunBook Date: Wed, 11 Dec 2024 16:49:58 -0600 Subject: [PATCH 5/7] D'oh! --- flixel/system/frontEnds/AssetFrontEnd.hx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/flixel/system/frontEnds/AssetFrontEnd.hx b/flixel/system/frontEnds/AssetFrontEnd.hx index 65e64dd8f4..c179d82c9f 100644 --- a/flixel/system/frontEnds/AssetFrontEnd.hx +++ b/flixel/system/frontEnds/AssetFrontEnd.hx @@ -241,9 +241,11 @@ class AssetFrontEnd */ public dynamic function exists(id:String, ?type:FlxAssetType) { + #if FLX_SOUND_ADD_EXT // add file extension if (type == SOUND) - id = addSoundExtIf(id); + id = addSoundExt(id); + #end #if FLX_STANDARD_ASSETS_DIRECTORY return Assets.exists(id, type.toOpenFlType()); @@ -267,9 +269,11 @@ class AssetFrontEnd */ public dynamic function isLocal(id:String, ?type:FlxAssetType, useCache = true) { + #if FLX_SOUND_ADD_EXT // add file extension if (type == SOUND) - id = addSoundExtIf(id); + id = addSoundExt(id); + #end #if FLX_STANDARD_ASSETS_DIRECTORY return Assets.isLocal(id, type.toOpenFlType(), useCache); From 542408ef6ff97fd252567bee39849bbcb024874d Mon Sep 17 00:00:00 2001 From: George FunBook Date: Wed, 11 Dec 2024 17:30:16 -0600 Subject: [PATCH 6/7] allow any file extension --- flixel/system/frontEnds/AssetFrontEnd.hx | 10 +++------- flixel/system/macros/FlxDefines.hx | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/flixel/system/frontEnds/AssetFrontEnd.hx b/flixel/system/frontEnds/AssetFrontEnd.hx index c179d82c9f..e466a667b4 100644 --- a/flixel/system/frontEnds/AssetFrontEnd.hx +++ b/flixel/system/frontEnds/AssetFrontEnd.hx @@ -85,14 +85,10 @@ class AssetFrontEnd public function new () {} #end - #if (FLX_SOUND_ADD_EXT == "wav") - public static final defaultSoundExtension:String = '.wav'; - #elseif (FLX_SOUND_ADD_EXT == "mp3") - public static final defaultSoundExtension:String = '.mp3'; - #elseif (FLX_SOUND_ADD_EXT == "ogg") - public static final defaultSoundExtension:String = '.ogg'; + #if (FLX_SOUND_ADD_EXT == "1" || FLX_SOUND_NO_ADD_EXT) + public final defaultSoundExtension:String = #if flash ".mp3" #else ".ogg" #end; #else - public static final defaultSoundExtension:String = #if flash ".mp3" #else ".ogg" #end; + public final defaultSoundExtension:String = '.${haxe.macro.Compiler.getDefine("FLX_SOUND_ADD_EXT")}'; #end /** diff --git a/flixel/system/macros/FlxDefines.hx b/flixel/system/macros/FlxDefines.hx index 696d49677c..b22bcfdf18 100644 --- a/flixel/system/macros/FlxDefines.hx +++ b/flixel/system/macros/FlxDefines.hx @@ -55,7 +55,7 @@ private enum UserDefines /** * Allows you to use sound paths with no extension, and the default sound type for that * target will be used. If enabled it will use ogg on all targets except flash, which uses mp3. - * If this flag is set to "wav", "mp3" or "ogg" if will use that type + * If this flag is set to any string, that is used for the file extension */ FLX_SOUND_ADD_EXT; } From 457c83eb3801d6f438a14f55c098d14f0ecfe735 Mon Sep 17 00:00:00 2001 From: George FunBook Date: Wed, 11 Dec 2024 18:33:46 -0600 Subject: [PATCH 7/7] rename to FLX_DEFAULT_SOUND_EXT --- flixel/system/frontEnds/AssetFrontEnd.hx | 12 ++++++------ flixel/system/macros/FlxDefines.hx | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/flixel/system/frontEnds/AssetFrontEnd.hx b/flixel/system/frontEnds/AssetFrontEnd.hx index e466a667b4..a6eea14cc2 100644 --- a/flixel/system/frontEnds/AssetFrontEnd.hx +++ b/flixel/system/frontEnds/AssetFrontEnd.hx @@ -85,10 +85,10 @@ class AssetFrontEnd public function new () {} #end - #if (FLX_SOUND_ADD_EXT == "1" || FLX_SOUND_NO_ADD_EXT) + #if (FLX_DEFAULT_SOUND_EXT == "1" || FLX_NO_DEFAULT_SOUND_EXT) public final defaultSoundExtension:String = #if flash ".mp3" #else ".ogg" #end; #else - public final defaultSoundExtension:String = '.${haxe.macro.Compiler.getDefine("FLX_SOUND_ADD_EXT")}'; + public final defaultSoundExtension:String = '.${haxe.macro.Compiler.getDefine("FLX_DEFAULT_SOUND_EXT")}'; #end /** @@ -237,7 +237,7 @@ class AssetFrontEnd */ public dynamic function exists(id:String, ?type:FlxAssetType) { - #if FLX_SOUND_ADD_EXT + #if FLX_DEFAULT_SOUND_EXT // add file extension if (type == SOUND) id = addSoundExt(id); @@ -265,7 +265,7 @@ class AssetFrontEnd */ public dynamic function isLocal(id:String, ?type:FlxAssetType, useCache = true) { - #if FLX_SOUND_ADD_EXT + #if FLX_DEFAULT_SOUND_EXT // add file extension if (type == SOUND) id = addSoundExt(id); @@ -351,7 +351,7 @@ class AssetFrontEnd /** * Gets an instance of a sound, logs when the asset is not found. * - * **Note:** If the `FLX_SOUND_ADD_EXT` flag is enabled, you may omit the file extension + * **Note:** If the `FLX_DEFAULT_SOUND_EXT` flag is enabled, you may omit the file extension * * @param id The ID or asset path for the sound * @param useCache Whether to allow use of the asset cache (if one exists) @@ -378,7 +378,7 @@ class AssetFrontEnd inline function addSoundExtIf(id:String) { - #if FLX_SOUND_ADD_EXT + #if FLX_DEFAULT_SOUND_EXT return addSoundExt(id); #else return id; diff --git a/flixel/system/macros/FlxDefines.hx b/flixel/system/macros/FlxDefines.hx index b22bcfdf18..4bf4815839 100644 --- a/flixel/system/macros/FlxDefines.hx +++ b/flixel/system/macros/FlxDefines.hx @@ -57,7 +57,7 @@ private enum UserDefines * target will be used. If enabled it will use ogg on all targets except flash, which uses mp3. * If this flag is set to any string, that is used for the file extension */ - FLX_SOUND_ADD_EXT; + FLX_DEFAULT_SOUND_EXT; } /** @@ -106,7 +106,7 @@ private enum HelperDefines FLX_STANDARD_ASSETS_DIRECTORY; /** The normalized, absolute path of `FLX_CUSTOM_ASSETS_DIRECTORY`, used internally */ FLX_CUSTOM_ASSETS_DIRECTORY_ABS; - FLX_SOUND_NO_ADD_EXT; + FLX_NO_DEFAULT_SOUND_EXT; } class FlxDefines @@ -207,7 +207,7 @@ class FlxDefines defineInversion(FLX_SWF_VERSION_TEST, FLX_NO_SWF_VERSION_TEST); defineInversion(FLX_NO_HEALTH, FLX_HEALTH); defineInversion(FLX_TRACK_POOLS, FLX_NO_TRACK_POOLS); - defineInversion(FLX_SOUND_ADD_EXT, FLX_SOUND_NO_ADD_EXT); + defineInversion(FLX_DEFAULT_SOUND_EXT, FLX_NO_DEFAULT_SOUND_EXT); // defineInversion(FLX_TRACK_GRAPHICS, FLX_NO_TRACK_GRAPHICS); // special case }