Editor Scripts 🔥: Alpha Release

Since it looks like people are posting their editor scripts here, I figured I’d chip in and post my lifecycle script that auto-implements this fix for slow HTML5 bundles on certain browsers. The only caveat is that you have to output the bundle into the project directory so Lua can access it. I’m also not very experienced with IO and string manipulation, so feel free to suggest improvements! Anyways, here it is:

Code
local M = {}

local function read(file)
    local data = ""
    for l in file:lines() do
        data = data .. l .. "\n"
    end
    return data
end

function M.on_bundle_finished(opts)
    if opts.platform == "js-web" and opts.success then
        local title = sys.get_config("project.title", "Desktop Game")
        local file = io.open(opts.output_directory .. "/" .. title .. "/index.html", "r")
        local fixed = string.gsub(read(file), "engine_arguments: %[%]", "engine_arguments: [\"--verify-graphics-calls=false\"]")
        file:close()

        file = io.open(opts.output_directory .. "/" .. title .."/index.html", "wb")
        file:write(fixed)
        file:flush()
        file:close()
    end
end

return M
5 Likes