-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwn.lua
98 lines (69 loc) · 2.37 KB
/
twn.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
--flux = require 'path.to.flux'
local function skip(t, n)
for i = 1,n do
table.remove(t, 1)
end
return t
end
--foo = tween(...) or tween(...):set("foo")
function set(self, name, object)
local scope = object or _G
scope[name] = self
return self
end
flux._twnr = function(self, ...)
local args = {...}
local tween = nil
local mode = nil
if type(args[1]) == "table" and self.obj == nil then mode = "root" end
if type(args[1]) == "table" and self.obj ~= nil then mode = "branch" end
if type(args[1]) ~= "table" then mode = "leaf" end
local index, first = nil, 2
if mode == "leaf" then first = 1 end
local obj, time, vars, ease = nil, nil, nil, nil
if mode ~= "leaf" then obj = args[1] end
for i = first,#args do
index = i
if type(args[i]) == "number" and time then error("unexpected second time argument", 2) end
if type(args[i]) == "string" and ease then error("unexpected second easing argument", 2) end
if type(args[i]) == "table" and not time then error("expected time argument before table argument", 2) end
if type(args[i]) == "number" then time = args[i] end
if type(args[i]) == "string" then ease = args[i] end
if type(args[i]) == "table" then vars = args[i] end
if mode == "root" and time and vars then
tween = flux.to(obj, time, vars):ease(ease or "linear")
break
end
if mode == "branch" and time and vars then
tween = self:after(obj, time, vars):ease(ease or "linear")
break
end
if mode == "leaf" and time and vars then
tween = self:after(time, vars):ease(ease or "linear")
break
end
if mode == "root" and time and ease == "wait" then
tween = flux.to(obj, time, {})
break
end
if mode == "branch" and time and ease == "wait" then
tween = self:after(obj, time, {})
break
end
if mode == "leaf" and time and ease == "wait" then
tween = self:after(time, {})
break
end
end
if tween == nil then error("wrong number of arguments", 2) end
if type(args[index+1]) == "table" then error("unexpected second object argument", 2) end
if index < #args then
return flux._twnr( tween, unpack( skip(args, index) ) )
else
getmetatable(tween).__call = flux._twnr
tween.set = set
return tween
end
end
getmetatable(flux).__call = flux._twnr
--return flux