Closed MadByteDE closed 2 years ago
I just added a license because I believe this can be useful separately for other smaller scale projects in the future & I'd like to make sure ppl can use it freely.
Nice. I'll check it tomorrow.
Can we pass an optional text parameter to force stream or static? Determining by file size is neat and will work 98% of the time but it world be nice to have the option to force a specific setting.
Perhaps something for the future?
Can we pass an optional text parameter to force stream or static? Determining by file size is neat and will work 98% of the time but it world be nice to have the option to force a specific setting.
Perhaps something for the future?
Sure, I'll look into it.
Can we pass an optional text parameter to force stream or static? Determining by file size is neat and will work 98% of the time but it world be nice to have the option to force a specific setting.
Okay, right now it's possible to load audio files in the desired mode by loading the files manually with
Assets.newSound("assets/streamAudio/rapMusic.mp3", "stream")
-- And using it with e.g
local music = Assets.getSound("rapMusic")
music:setVolume(.2)
music:play()
I also added an argument for Assets.loadDirectory(path, audioMode)
to load all files from a specific directory with the desired mode (by default it will choose based on the file size). Usage:
-- Load images
Assets.loadDirectory("assets/images")
-- Load sounds (static mode)
Assets.loadDirectory("assets/sounds", "static")
-- Load music (stream mode)
Assets.loadDirectory("assets/music", "stream")
-- Load sounds based on file size
Assets.loadDirectory("assets/sounds")
When loading directories recursively, it's not possible to choose between audio loading modes because that would need me to pass something like an additional file list to the function for it to determine what files should be streamed or not.
In that case I think it's better to just set the file size limit (Assets.audioStreamSizeLimit
) to make sure that big audio files are not shoved directly into memory, which is the reason why modes exist after all.
Tested. All good. Merging. Thanks.
Overview
I put some more work into the asset loader to add the ability to load directories recursively and to fix the game crashing when trying to load a file with the wrong love function (e.g
love.audio.newSource
for an image file).For audio files I also added a file size limit to determine if a file should be loaded in streaming or static mode.
This PR should reduce the amount of work we have to put into loading assets even more & also allows us to easily create sub-folders if we want e.g for assets that belong to a single object like the fuelBase (landingLights.png, fulebaseOn.png, fuelbaseOff.png).
Other changes