!(function dirLookup(dir, extension, newFunc, type, sep, indent, handle)
    indent = indent or ""
    sep = sep or "\n\n"
    handle = handle ~= nil and handle or function(varName, value)
        return varName .. ' = ' .. value
    end

    local p = io.popen('find src/' .. 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("src/", "")
            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/game', 'png', 'playdate.graphics.image.new', 'pd_image'))
!!(dirLookup('assets/sounds', 'wav', 'playdate.sound.sampleplayer.new', 'pd_sampleplayer'))
!!(dirLookup('assets/music', 'wav', 'playdate.sound.sampleplayer.new', 'pd_sampleplayer'))
!!(dirLookup('assets/fonts', 'fnt', 'playdate.graphics.font.new', 'pd_font', nil, nil, function(varName, value)
    return varName:gsub("[- ]", "") .. " = " .. value:gsub("fnt", "pft")
end))
Logos = {
    { name = "Base", image = playdate.graphics.image.new("assets/images/game/logos/Base.png") },

!!(dirLookup('assets/images/game/logos -not -name "Base.png"', 'png', 'playdate.graphics.image.new', 'pd_image', ",\n\n", "    ", function(varName, value)
    return '{ name = "' .. varName .. '", image = ' .. value .. ' }'
end))
}
