Created
April 29, 2020 09:54
-
-
Save EngineerSmith/161ff8d4574bcbe9b75220397b95cb2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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