Repository navigation
Expand file tree
/
Copy pathcompilerC.lua
More file actions
207 lines (177 loc) · 7.4 KB
/
Copy pathcompilerC.lua
File metadata and controls
207 lines (177 loc) · 7.4 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
local compilationBrowser = nil
local compilationGui = nil
local isMinimized = false
function createCompilationPanel()
if (compilationGui) then
destroyElement(compilationGui)
compilationGui = nil
compilationBrowser = nil
end
local screenW, screenH = guiGetScreenSize()
compilationGui = guiCreateBrowser(0, 0, screenW, screenH, true, true, false)
if (compilationGui) then
compilationBrowser = guiGetBrowser(compilationGui)
addEventHandler("onClientBrowserCreated", compilationGui, onBrowserCreated)
addEventHandler("onClientBrowserDocumentReady", compilationGui, function () end)
guiSetVisible(compilationGui, true)
guiBringToFront(compilationGui)
showCursor(true)
return true
end
return false
end
function onBrowserCreated()
if (compilationBrowser) then
loadBrowserURL(compilationBrowser, "http://mta/local/index.html")
focusBrowser(compilationBrowser)
end
end
function openCompilationPanel(scripts)
if (not compilationGui) then
if (createCompilationPanel()) then
loadScriptsFromServer(scripts)
end
else
if (not guiGetVisible(compilationGui)) then
guiSetVisible(compilationGui, true)
guiBringToFront(compilationGui)
showCursor(true)
focusBrowser(compilationBrowser)
isMinimized = false
loadScriptsFromServer(scripts)
end
end
end
function closePanel()
if (compilationGui) then
removeEventHandler("onClientBrowserDocumentReady", compilationGui, function () end)
removeEventHandler("onClientBrowserCreated", compilationGui, onBrowserCreated)
destroyElement(compilationGui)
compilationGui = nil
compilationBrowser = nil
showCursor(false)
isMinimized = false
end
end
addEvent("closePanel", true)
addEventHandler("closePanel", root, closePanel)
function minimizePanel()
if (compilationGui and guiGetVisible(compilationGui)) then
guiSetVisible(compilationGui, false)
showCursor(false)
isMinimized = true
end
end
addEvent("minimizePanel", true)
addEventHandler("minimizePanel", root, minimizePanel)
function restoreCompilationPanel()
if (compilationGui and isMinimized) then
guiSetVisible(compilationGui, true)
guiBringToFront(compilationGui)
showCursor(true)
focusBrowser(compilationBrowser)
isMinimized = false
end
end
function refreshScriptsList()
triggerServerEvent("TScompiler.requestScriptsList", localPlayer)
end
addEvent("refreshScriptsList", true)
addEventHandler("refreshScriptsList", root, refreshScriptsList)
function requestScriptsList()
triggerServerEvent("TScompiler.requestScriptsList", localPlayer)
end
addEvent("requestScriptsList", true)
addEventHandler("requestScriptsList", root, requestScriptsList)
function startCompilation(data)
if (data and type(data) == "string") then
local success, result = pcall(function()
local compilationTasks = {}
local jsonStr = data
if (string.find(jsonStr, "%[") and string.find(jsonStr, "%]")) then
jsonStr = string.sub(jsonStr, 2, -2)
local taskPattern = '{(.-)}'
for taskStr in string.gmatch(jsonStr, taskPattern) do
local task = {}
for key, value in string.gmatch(taskStr, '"([^"]+)":([^,}]+)') do
value = string.gsub(value, '"', '')
if (value == "true") then
task[key] = true
elseif (value == "false") then
task[key] = false
else
task[key] = value
end
end
if (task.resourceName) then
table.insert(compilationTasks, task)
end
end
end
return compilationTasks
end)
if (success and result and #result > 0) then
triggerServerEvent("TScompiler.startCompilation", localPlayer, result)
end
end
end
addEvent("startCompilation", true)
addEventHandler("startCompilation", root, startCompilation)
function loadScriptsFromServer(scripts)
if (not compilationBrowser or not guiGetVisible(compilationGui)) then return end
if (scripts and #scripts > 0) then
setTimer(function()
if (compilationBrowser and guiGetVisible(compilationGui)) then
local jsArray = "["
for i, script in ipairs(scripts) do
if (i > 1) then jsArray = jsArray .. "," end
local clientFiles = "["
if (script.clientFiles) then
for j, file in ipairs(script.clientFiles) do
if (j > 1) then clientFiles = clientFiles .. "," end
clientFiles = clientFiles .. '"' .. file .. '"'
end
end
clientFiles = clientFiles .. "]"
local serverFiles = "["
if (script.serverFiles) then
for j, file in ipairs(script.serverFiles) do
if (j > 1) then serverFiles = serverFiles .. "," end
serverFiles = serverFiles .. '"' .. file .. '"'
end
end
serverFiles = serverFiles .. "]"
jsArray = jsArray .. '{'
jsArray = jsArray .. 'name:"' .. script.name .. '",'
jsArray = jsArray .. 'clientFiles:' .. clientFiles .. ','
jsArray = jsArray .. 'serverFiles:' .. serverFiles .. ','
jsArray = jsArray .. 'hasProtection:' .. (script.hasProtection and "true" or "false") .. ','
jsArray = jsArray .. 'clientCompiled:' .. (script.clientCompiled and "true" or "false")
jsArray = jsArray .. '}'
end
jsArray = jsArray .. "]"
executeBrowserJavascript(compilationBrowser, "loadScriptsData(" .. jsArray .. ");")
end
end, 2000, 1)
end
end
function updateCompilationStatus(statusData)
if (compilationBrowser and guiGetVisible(compilationGui)) then
executeBrowserJavascript(compilationBrowser, "updateCompilationProgress(" .. toJSON(statusData) .. ");")
end
end
function onOpenPanel(scripts)
openCompilationPanel(scripts)
end
addEvent("TScompiler.openPanel", true)
addEventHandler("TScompiler.openPanel", localPlayer, onOpenPanel)
function onScriptsReceived(scripts)
loadScriptsFromServer(scripts)
end
addEvent("TScompiler.loadScripts", true)
addEventHandler("TScompiler.loadScripts", localPlayer, onScriptsReceived)
function onStatusUpdate(statusData)
updateCompilationStatus(statusData)
end
addEvent("TScompiler.updateStatus", true)
addEventHandler("TScompiler.updateStatus", localPlayer, onStatusUpdate)