[Script] Add Inverted Frame

I needed to create a flashing animation for my game and wanted to invert the colors of the sprite I was working on. This was my first ever attempt at lua scripting for Aseprite so thought I’d share it!

do
    app.transaction(
        function()
            app.command.NewFrame()
            local newFrame = app.activeFrame
            assert(newFrame ~= nil and newFrame.frameNumber ~= nil)
            local sprite = newFrame.sprite
            for i, layer in ipairs(sprite.layers) do
                local cel = layer:cel(newFrame.frameNumber)
                if (cel ~= nil) then
                    app.activeCel = cel
                    app.command.InvertColor(false)
                end
            end
        end
    )
end