Skip to content

Instantly share code, notes, and snippets.

@EngineerSmith
Created April 29, 2020 09:54
Show Gist options
  • Save EngineerSmith/161ff8d4574bcbe9b75220397b95cb2e to your computer and use it in GitHub Desktop.
Save EngineerSmith/161ff8d4574bcbe9b75220397b95cb2e to your computer and use it in GitHub Desktop.
local lily = require("Lib.Lily")
local global = require("Scripts.global")
local file = require("Scripts.Utilities.file")
local insert = table.insert
local lilyLoaders = {
png = "newImage",
jpg = "newImage",
jpeg = "newImage",
bmp = "newImage",
dds = "newImage",
mp3 = "newSource",
ogg = "newSource",
wav = "newSource",
txt = "read",
ttf = "newFont", -- TODO check if it works as wanted
otf = "newFont",
fnt = "newFont",
}
local function loadAssetTable(tbl)
local lilyLoadTable = {}
for _, asset in ipairs(tbl) do
local loader = lilyLoaders[file.getFileExtension(asset.path)]
if not loader then
error("LilyLoader not found for "..asset.path)
end
insert(lilyLoadTable, {loader, asset.path})
end
local multilily = lily.loadMulti(lilyLoadTable)
local assets = global.assets
multilily:onComplete(function(_, loadedAssets)
for index, asset in ipairs(tbl) do
assets[asset.name] = loadedAssets[index][1]
if asset.process then
asset.process(assets[asset.name], asset.name)
end
end
end)
return multilily
end
return loadAssetTable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment