-
Notifications
You must be signed in to change notification settings - Fork 34
/
animation.lua
373 lines (360 loc) · 14.5 KB
/
animation.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
dgsLogLuaMemory()
---------------Speed Up
local type = type
local tonumber = tonumber
local dgsTriggerEvent = dgsTriggerEvent
local isElement = isElement
local getEasingValue = getEasingValue
local animationID = 0
function dgsAnimTo(...)
local dgsEle,property,targetValue,easing,duration,delay,reversedProgress,splitTable
if select("#",...) == 1 and type(select(1,...)) == "table" then
local argTable = ...
dgsEle = argTable.ele or argTable.dgsEle or argTable.element or argTable.dgsElement or argTable.source or argTable[1]
property = argTable.property or argTable[2]
targetValue = argTable.target or argTable.targetValue or argTable[3]
easing = argTable.easing or argTable.easingFunction or argTable[4]
duration = argTable.duration or argTable.time or argTable[5]
delay = argTable.delay or argTable[6]
reversedProgress = argTable.reversed or argTable[7]
splitTable = argTable[8]
else
dgsEle,property,targetValue,easing,duration,delay,reversedProgress,splitTable = ...
end
delay = tonumber(delay) or 0
if not(type(dgsEle) == "table" or dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsAnimTo",1,"dgs-dxelement/table")) end
if not(type(property) == "string") then error(dgsGenAsrt(property,"dgsAnimTo",2,"string")) end
easing = easing or "Linear"
if not(dgsEasingFunctionExists(easing)) then error(dgsGenAsrt(easing,"dgsAnimTo",4,_,"easing function doesn't exist ("..tostring(easing)..")")) end
if not(type(duration) == "number") then error(dgsGenAsrt(duration,"dgsAnimTo",5,"number")) end
if type(dgsEle) == "table" then
local animIDs = {}
for index,dgsEleItem in pairs(dgsEle) do
animIDs[index] = dgsAnimTo(dgsEleItem,property,targetValue,easing,duration,delay,reversedProgress,splitTable)
end
return animIDs
else
animationID = animationID+1
local animTable = {
[-3]=nil,
[-2]=animationID,
[-1]=sourceResourceRoot,
[0]=nil, --Result
[1]=dgsEle,
[2]=property,
[3]=nil, --Start Value
[4]=targetValue,
[5]=easing,
[6]=duration,
[7]=getTickCount()+delay,
[8]=reversedProgress,
[9]=splitTable,
}
--Debugging
local isTraceDebug = getElementData(localPlayer,"DGS-DebugTracer") or (getElementData(localPlayer,"DGS-DEBUG") == 3)
if isTraceDebug then
dgsDebugGetContext(sourceResourceRoot,function(context)
animTable[-3] = context
end)
end
--
table.insert(animQueue,animTable)
return animationID
end
end
function dgsStopAniming(...)
local dgsEle,property
local stopTick = getTickCount()
if select("#",...) == 1 and type(select(1,...)) == "table" then
local argTable = ...
dgsEle = argTable.ele or argTable.dgsEle or argTable.element or argTable.dgsElement or argTable.source or argTable.index or argTable[1]
property = argTable.property or argTable[2]
else
dgsEle,property = ...
end
if not(dgsIsType(dgsEle) or type(dgsEle) == "number") then error(dgsGenAsrt(dgsEle,"dgsStopAniming",1,"dgs-dxelement/number")) end
if type(dgsEle) == "number" then
--Kill the specific animation
local index = 1
while index <= #animQueue do
local anim = animQueue[index]
if anim[-2] == dgsEle then --Confirm by unique animation ID
local theEle = anim[1]
table.remove(animQueue,index) --Remove
property = anim[2]
dgsTriggerEvent("onDgsStopAniming",theEle,anim[-2],property,anim[3],anim[4],anim[5],anim[7],anim[6],stopTick)
if property == "rltPos" or property == "absPos" then
dgsTriggerEvent("onDgsStopMoving",theEle,anim[-2])
elseif property == "rltSize" or property == "absSize" then
dgsTriggerEvent("onDgsStopSizing",theEle,anim[-2])
elseif property == "alpha" then
dgsTriggerEvent("onDgsStopAlphaing",theEle,anim[-2])
end
return true
else
index = index+1
end
end
elseif type(property) == "string" then
--Kill all animations of the specific property
local index = 1
while index <= #animQueue do
local anim = animQueue[index]
if anim[1] == dgsEle and anim[2] == property then --Confirm
table.remove(animQueue,index) --Remove
dgsTriggerEvent("onDgsStopAniming",dgsEle,anim[-2],property,anim[3],anim[4],anim[5],anim[7],anim[6],stopTick)
if property == "rltPos" or property == "absPos" then
dgsTriggerEvent("onDgsStopMoving",dgsEle,anim[-2])
elseif property == "rltSize" or property == "absSize" then
dgsTriggerEvent("onDgsStopSizing",dgsEle,anim[-2])
elseif property == "alpha" then
dgsTriggerEvent("onDgsStopAlphaing",dgsEle,anim[-2])
end
else
index = index+1
end
end
return true
elseif type(property) == "table" then
local index = 1
while index <= #animQueue do
local anim = animQueue[index]
if anim[1] == dgsEle then --Confirm
for i=1,#property do
if anim[2] == property[i] then
table.remove(animQueue,index) --Remove
dgsTriggerEvent("onDgsStopAniming",dgsEle,anim[-2],property[i],anim[3],anim[4],anim[5],anim[7],anim[6],stopTick)
if property[i] == "rltPos" or property[i] == "absPos" then
dgsTriggerEvent("onDgsStopMoving",dgsEle,anim[-2])
elseif property[i] == "rltSize" or property[i] == "absSize" then
dgsTriggerEvent("onDgsStopSizing",dgsEle,anim[-2])
elseif property[i] == "alpha" then
dgsTriggerEvent("onDgsStopAlphaing",dgsEle,anim[-2])
end
break
end
end
end
index = index+1
end
else
local index = 1
while index <= #animQueue do
local anim = animQueue[index]
if anim[1] == dgsEle then --Confirm
table.remove(animQueue,index) --Remove
dgsTriggerEvent("onDgsStopAniming",dgsEle,anim[-2],anim[2],anim[3],anim[4],anim[5],anim[7],anim[6],stopTick)
if anim[2] == "rltPos" or anim[2] == "absPos" then
dgsTriggerEvent("onDgsStopMoving",dgsEle,anim[-2])
elseif anim[2] == "rltSize" or anim[2] == "absSize" then
dgsTriggerEvent("onDgsStopSizing",dgsEle,anim[-2])
elseif anim[2] == "alpha" then
dgsTriggerEvent("onDgsStopAlphaing",dgsEle,anim[-2])
end
else
index = index+1
end
end
end
end
function dgsIsAniming(dgsEle,property)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsIsAniming",1,"dgs-dxelement")) end
if type(property) == "string" then
for i=1,#animQueue do
if animQueue[i][1] == dgsEle and animQueue[i][2] == property then
return true
end
end
elseif type(property) == "table" then
for i=1,#animQueue do
if animQueue[i][1] == dgsEle then
for p=1,#property do
if animQueue[i][2] == property[p] then
return true
end
end
end
end
else
for i=1,#animQueue do
if animQueue[i][1] == dgsEle then
return true
end
end
end
end
local easingSettings = {}
function onAnimQueueProcess()
local animIndex,animItem = 1
local dgsEle,property,startValue,targetValue,easing,duration,startTick
local rTick = getTickCount()
local dbgResult,rProgress
while animIndex <= #animQueue do
animItem = animQueue[animIndex]
dgsEle = animItem[1]
if isElement(dgsEle) then
startTick = animItem[7]
if rTick >= startTick then
if animItem[3] == nil then animItem[3] = dgsElementData[dgsEle][ animItem[2] ] end
property,startValue,targetValue,easing,duration,reversedProgress,splitTable = animItem[2],animItem[3],animItem[4],animItem[5],animItem[6],animItem[8],animItem[9]
rProgress = (rTick-startTick)/duration
if rProgress >= 1 then rProgress = 1 end
if reversedProgress then rProgress = 1-rProgress end
if dgsEasingFunction[easing] then
if splitTable and type(startValue) == "table" then
animItem[0] = {}
for i=1,#startValue do
easingSettings[1],easingSettings[2],easingSettings[3],easingSettings[4] = property,targetValue,startValue,i
animItem[0][i] = startValue[i]+(targetValue[i]-startValue[i])*dgsEasingFunction[easing](rProgress,easingSettings,dgsEle)
end
easingSettings[4] = nil
else
easingSettings[1],easingSettings[2],easingSettings[3] = property,targetValue,startValue
animItem[0] = dgsEasingFunction[easing](rProgress,easingSettings,dgsEle)
end
else
local easingValue = getEasingValue(rProgress,easing)
if type(startValue) == "table" then
animItem[0] = {}
for i=1,#startValue do
animItem[0][i] = startValue[i]+(targetValue[i]-startValue[i])*easingValue
end
else
animItem[0] = startValue+(targetValue-startValue)*easingValue
end
end
dbgResult = pcall(dgsSetProperty,dgsEle,property,animItem[0])
if not dbgResult then
outputDebugString("DGS runtime error: Animation",4,255,180,100)
if animItem[-1] and animItem[-3] then
local debugContext = animItem[-3]
if type(debugContext) == "table" then
dgsTriggerEvent("DGSI_onDebug",animItem[-1],"AnimationError",property,debugContext.file,debugContext.line,debugContext.fncName)
end
end
end
if rProgress == 1 then
dgsStopAniming(animItem[-2])
else
animIndex = animIndex+1
end
else
animIndex = animIndex+1
end
else
table.remove(animQueue,animIndex)
end
end
end
function dgsMoveTo(...)
local dgsEle,x,y,relative,easing,duration,delay,reversedProgress
if select("#",...) == 1 and type(select(1,...)) == "table" then
local argTable = ...
dgsEle = argTable.ele or argTable.dgsEle or argTable.element or argTable.dgsElement or argTable.source or argTable[1]
x = argTable.x or argTable[2]
y = argTable.y or argTable[3]
relative = argTable.rlt or argTable.relative or argTable[4]
easing = argTable.easing or argTable.easingFunction or argTable[5]
duration = argTable.duration or argTable.time or argTable[6]
delay = argTable.delay or argTable[7]
reversedProgress = argTable.reversed or argTable[8]
else
dgsEle,x,y,relative,easing,duration,delay,reversedProgress = ...
end
delay = tonumber(delay) or 0
if not(type(dgsEle) == "table" or dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsMoveTo",1,"dgs-dxelement/table")) end
if not(type(x) == "number") then error(dgsGenAsrt(x,"dgsMoveTo",2,"number")) end
if not(type(y) == "number") then error(dgsGenAsrt(y,"dgsMoveTo",3,"number")) end
easing = easing or "Linear"
if not(dgsEasingFunctionExists(easing)) then error(dgsGenAsrt(easing,"dgsMoveTo",5,"easing function doesn't exist ("..tostring(easing)..")")) end
if not(type(duration) == "number") then error(dgsGenAsrt(duration,"dgsMoveTo",6,"number")) end
return dgsAnimTo(dgsEle,relative and "rltPos" or "absPos",{x,y},easing,duration,delay,reversedProgress,true)
end
function dgsStopMoving(dgsEle)
if not(type(dgsEle) == "table" or dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsStopMoving",1,"dgs-dxelement/table")) end
if type(dgsEle) == "table" then
for i=1,#dgsEle do dgsStopMoving(dgsEle[i]) end
else
dgsStopAniming(dgsEle,{"absPos","rltPos"})
end
return true
end
function dgsIsMoving(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsIsMoving",1,"dgs-dxelement")) end
return dgsIsAniming(dgsEle,{"absPos","rltPos"})
end
function dgsSizeTo(...)
local dgsEle,w,h,relative,easing,duration,delay,reversedProgress
if select("#",...) == 1 and type(select(1,...)) == "table" then
local argTable = ...
dgsEle = argTable.ele or argTable.dgsEle or argTable.element or argTable.dgsElement or argTable.source or argTable[1]
w = argTable.w or argTable.width or argTable[2]
h = argTable.h or argTable.height or argTable[3]
relative = argTable.rlt or argTable.relative or argTable[4]
easing = argTable.easing or argTable.easingFunction or argTable[5]
duration = argTable.duration or argTable.time or argTable[6]
delay = argTable.delay or argTable[7]
reversedProgress = argTable.reversed or argTable[8]
else
dgsEle,w,h,relative,easing,duration,delay,reversedProgress = ...
end
delay = tonumber(delay) or 0
if not(type(dgsEle) == "table" or dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsSizeTo",1,"dgs-dxelement/table")) end
if not(type(w) == "number") then error(dgsGenAsrt(w,"dgsSizeTo",2,"number")) end
if not(type(h) == "number") then error(dgsGenAsrt(h,"dgsSizeTo",3,"number")) end
if relative then
if w > 10 or w < -10 then error(dgsGenAsrt(w,"dgsSizeTo",2,"float between [0, 1]")) end
if h > 10 or h < -10 then error(dgsGenAsrt(h,"dgsSizeTo",3,"float between [0, 1]")) end
end
easing = easing or "Linear"
if not(dgsEasingFunctionExists(easing)) then error(dgsGenAsrt(easing,"dgsSizeTo",5,"easing function doesn't exist ("..tostring(easing)..")")) end
if not(type(duration) == "number") then error(dgsGenAsrt(duration,"dgsSizeTo",6,"number")) end
return dgsAnimTo(dgsEle,relative and "rltSize" or "absSize",{w,h},easing,duration,delay,reversedProgress,true)
end
function dgsStopSizing(dgsEle)
if not(type(dgsEle) == "table" or dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsStopSizing",1,"dgs-dxelement/table")) end
if type(dgsEle) == "table" then
for i=1,#dgsEle do dgsStopMoving(dgsEle[i]) end
else
dgsStopAniming(dgsEle,{"absSize","rltSize"})
end
return true
end
function dgsIsSizing(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsIsSizing",1,"dgs-dxelement")) end
return dgsIsAniming(dgsEle,{"absSize","rltSize"})
end
function dgsAlphaTo(...)
local dgsEle,alpha,relative,easing,duration,delay,reversedProgress
if select("#",...) == 1 and type(select(1,...)) == "table" then
local argTable = ...
dgsEle = argTable.ele or argTable.dgsEle or argTable.element or argTable.dgsElement or argTable.source or argTable[1]
alpha = argTable.a or argTable.alpha or argTable[2]
easing = argTable.easing or argTable.easingFunction or argTable[3]
duration = argTable.duration or argTable.time or argTable[4]
delay = argTable.delay or argTable[5]
reversedProgress = argTable.reversed or argTable[6]
else
dgsEle,alpha,easing,duration,delay,reversedProgress = ...
end
delay = tonumber(delay) or 0
if not(type(dgsEle) == "table" or dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsAlphaTo",1,"dgs-dxelement/table")) end
if not(type(alpha) == "number") then error(dgsGenAsrt(alpha,"dgsAlphaTo",2,"number")) end
easing = easing or "Linear"
if not(dgsEasingFunctionExists(easing)) then error(dgsGenAsrt(easing,"dgsAlphaTo",3,_,"easing function doesn't exist ("..tostring(easing)..")")) end
if not(type(duration) == "number") then error(dgsGenAsrt(duration,"dgsAlphaTo",4,"number")) end
return dgsAnimTo(dgsEle,"alpha",alpha,easing,duration,delay,reversedProgress,true)
end
function dgsStopAlphaing(dgsEle)
if not(type(dgsEle) == "table" or dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsStopAlphaing",1,"dgs-dxelement/table")) end
if type(dgsEle) == "table" then
for i=1,#dgsEle do dgsStopMoving(dgsEle[i]) end
else
dgsStopAniming(dgsEle,"alpha")
end
return true
end
function dgsIsAlphaing(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsIsAlphaing",1,"dgs-dxelement")) end
return dgsIsAniming(dgsEle,"alpha")
end