heroes-of-nerevelon/lib/asset_bundle.lua
Neckrat a5ad1b9870 add camera
Co-authored-by: Ivan Yuriev <ivanyr44@gmail.com>
2025-08-01 02:00:35 +03:00

54 lines
1.3 KiB
Lua

local AssetBundle = {
root = "/assets",
files = {}
}
function AssetBundle:load(onFileLoading)
local callback = onFileLoading or function(path)
print("[AssetBundle]: loading " .. path)
end
local function enumerate(path)
local tree = {}
local contents = love.filesystem.getDirectoryItems(path)
for _, v in pairs(contents) do
local newPath = path .. "/" .. v
local type = love.filesystem.getInfo(newPath).type
if type == "file" then
callback(newPath)
local data = self.loadFile(newPath)
tree[self.cutExtension(v)] = data
end
if type == "directory" then
tree[v] = enumerate(newPath)
end
end
return tree
end
self.files = enumerate(self.root)
end
function AssetBundle.loadFile(path)
local filedata = love.filesystem.newFileData(path)
local ext = filedata:getExtension()
if (ext == "png") then
local img = love.graphics.newImage(path)
img:setFilter("nearest", "nearest")
return
img
elseif (ext == "glsl") then
return love.graphics.newShader(path);
end
return nil
end
function AssetBundle.cutExtension(filename)
return string.match(filename, '(.+)%.(.+)')
end
return AssetBundle