forked from DarkEnergyProcessor/livesim2_async
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenshot.lua
59 lines (50 loc) · 1.36 KB
/
screenshot.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- LOVE 11.0 screenshot implementation
-- Part of Live Simulator: 2
-- See copyright notice in main.lua
local love = require("love")
local Util = require("util")
local screenshot = {
list = {}
}
local function screenshotUpdateImpl() end
local function cleanListStartFrom(i, len)
for j = i, len do
screenshot.list[j] = nil
end
end
function screenshot.update()
return screenshotUpdateImpl()
end
if love._version <= "11.0" then
function screenshotUpdateImpl()
local len = #screenshot.list
if len > 0 then
local ss = love.graphics.newScreenshot()
for i = 1, len do
local obj = screenshot.list[i]
local tobj = type(obj)
if tobj == "string" then
local ext = Util.getExtension(obj):lower()
ext = #ext > 0 and ext or "png"
ss:encode(ext, obj)
elseif tobj == "function" then
local s, m = pcall(obj, ss)
if not(s) then
cleanListStartFrom(i, len)
error(m)
end
elseif tobj == "userdata" and tobj.typeOf and tobj:typeOf("Channel") then
obj:push(ss)
end
screenshot.list[i] = nil
end
end
end
function love.graphics.captureScreenshot(obj)
local tobj = type(obj)
if tobj == "string" or tobj == "function" or (tobj == "userdata" and tobj:typeOf("Channel")) then
screenshot.list[#screenshot.list + 1] = obj
end
end
end
return screenshot