!(function dirLookup(dir, extension, newFunc, type, handle) local indent = "" local sep = "\n\n" handle = handle ~= nil and handle or function(varName, nf, file) return varName .. ' = ' .. nf .. '("' .. file .. '")' end local p = io.popen('find ./' .. dir .. ' -maxdepth 1 -type f | sort -h') local assetCode = "" --Loop through all files for file in p:lines() do if file:find(extension) then local varName = file:gsub(".*/(.*)%." .. extension, "%1") file = file:gsub("%./", "") assetCode = assetCode .. indent .. '-- luacheck: ignore\n' assetCode = assetCode .. indent .. '---@type ' .. type ..'\n' assetCode = assetCode .. indent .. handle(varName, newFunc, file) .. sep end end return assetCode end function generatedFileWarning() -- Only in a function to make clear that THIS .lua2p is not the generated file! return "-- GENERATED FILE - DO NOT EDIT\n-- Instead, edit the source file directly: assets.lua2p." end)!!(generatedFileWarning()) !!(dirLookup('assets/images', 'png', 'love.graphics.newImage', 'Image')) !!(dirLookup('assets/sounds', 'wav', 'love.sound.newSoundData', 'SoundData')) !!(dirLookup('assets/music', 'wav', 'love.sound.newSoundData', 'SoundData')) !!(dirLookup('assets/fonts', 'ttf', 'love.graphics.newFont', 'FontData', function(varName, newFunc, file) return varName .. ' = function(fontSize)\n return ' .. newFunc .. '("' .. file .. '", fontSize)\nend' end))