This repository has been archived by the owner on Nov 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fastpour.lua
84 lines (77 loc) · 2.24 KB
/
fastpour.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
assert(fastpour == nil)
local fastpour = {}
_ENV.fastpour = fastpour
local js = require("js")
local window = js.global
local document = window.document
local console = window.console
local location = window.location
local function ypcall(func, ...)
local args, j = {...}, select("#", ...)
return xpcall(function()
return func(table.unpack(args, 1, j)) -- this is so awful
end, function(err)
err = debug.traceback(err, 2)
console:error(err)
end)
end
local function ypcall_wrap(func)
return function(...)
return ypcall(func, ...)
end
end
ypcall(function(...)
local cachebuster = ""
if location.hostname == "localhost" then
cachebuster = string.format("?cb=%x", math.random(0, math.maxinteger))
end
fastpour.cachebuster = cachebuster
local client = dofile("./client.lua"..cachebuster)
local viewport = document:getElementById("fp-viewport")
local ctx = assert(viewport:getContext("2d"))
local textarea = document:getElementById("fp-textarea")
local button_start = document:getElementById("fp-start")
local button_stop = document:getElementById("fp-stop")
local checkbox_lua51 = document:getElementById("fp-lua51")
local checkbox_strict = document:getElementById("fp-strict")
local animation_id, saved, my_client
local function draw(self, now)
if saved then
ctx:restore()
saved = false
end
ctx:save()
saved = true
--ctx:reset()
my_client:tick(now/1000)
if animation_id ~= nil then
animation_id = window:requestAnimationFrame(draw)
end
end
draw = ypcall_wrap(draw)
button_start:addEventListener("click", ypcall_wrap(function(self, event)
if animation_id ~= nil then
window:cancelAnimationFrame(animation_id)
animation_id = nil
end
my_client = client.new()
my_client.strict = checkbox_strict.checked
my_client.env_spoof_lua51 = checkbox_lua51.checked
client.ctx = ctx
client.width = viewport.width
client.height = viewport.height
client.viewport = viewport
my_client:init()
local path = my_client.mod_path.."/options.lua"
my_client.filesystem:write(path, textarea.value)
my_client:start_ui(path)
animation_id = window:requestAnimationFrame(draw)
end))
button_stop:addEventListener("click", ypcall_wrap(function(self, event)
if animation_id == nil then
return
end
window:cancelAnimationFrame(animation_id)
animation_id = nil
end))
end, ...)