Created
September 28, 2014 02:51
-
-
Save seebs/99c1c4c64e6cbb4eada3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local passnouns = { 'Loc', 'Rot', 'Scl', 'Color' } | |
local anim_safe_data = {} | |
setmetatable(anim_safe_data, { __mode = 'k' }) | |
local animverbs = { 'seek', 'move' } | |
function Util.animsafe(obj) | |
if anim_safe_data[obj] then | |
return | |
end | |
local d = {} | |
local f = {} | |
anim_safe_data[obj] = true | |
for i = 1, #passnouns do | |
local noun = passnouns[i] | |
for j = 1, #animverbs do | |
local name = animverbs[j] .. noun | |
f[name] = obj[name] | |
obj[name] = function(...) | |
if d[noun] then | |
d[noun]:stop() | |
end | |
d[noun] = f[name](...) | |
return d[noun] | |
end | |
end | |
local name = 'set' .. noun | |
f[name] = obj[name] | |
obj[name] = function(...) | |
if d[noun] then | |
d[noun]:stop() | |
d[noun] = nil | |
end | |
-- set doesn't return a value, so no need to stash it | |
return f[name](...) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment