mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
update animation api
This commit is contained in:
parent
aa6ac5f5bd
commit
21bd5ba1b2
3 changed files with 33 additions and 19 deletions
|
|
@ -68,26 +68,40 @@ end
|
||||||
|
|
||||||
local running_actions = {}
|
local running_actions = {}
|
||||||
local playing_tracks = {}
|
local playing_tracks = {}
|
||||||
local next_track_id = 1
|
|
||||||
|
|
||||||
function this.action(func)
|
function this.action(func)
|
||||||
table.insert(running_actions, coroutine.create(func))
|
table.insert(running_actions, coroutine.create(func))
|
||||||
end
|
end
|
||||||
|
|
||||||
function this.play(name, target)
|
local PlayingTrack = {
|
||||||
local id = next_track_id
|
__index = {
|
||||||
table.insert(playing_tracks, {id=id, name=name, target=target, timer=0.0})
|
stop = function(self)
|
||||||
next_track_id = id + 1
|
table.remove_value(playing_tracks, self)
|
||||||
return id
|
self.__timer = 0.0
|
||||||
end
|
self.__playing = false
|
||||||
|
end,
|
||||||
function this.stop(id)
|
pause = function(self)
|
||||||
for i, entry in pairs(playing_tracks) do
|
table.remove_value(playing_tracks, self)
|
||||||
if entry.id == id then
|
self.__playing = false
|
||||||
table.remove(playing_tracks, i)
|
end,
|
||||||
return
|
resume = function(self)
|
||||||
|
if not self.__playing then
|
||||||
|
table.insert(playing_tracks, self)
|
||||||
|
self.__playing = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function this.play(name, target)
|
||||||
|
local track = setmetatable({
|
||||||
|
name = name,
|
||||||
|
target = target,
|
||||||
|
__timer = 0.0,
|
||||||
|
__playing = true,
|
||||||
|
}, PlayingTrack)
|
||||||
|
table.insert(playing_tracks, track)
|
||||||
|
return track
|
||||||
end
|
end
|
||||||
|
|
||||||
function internals.on_animation_frame()
|
function internals.on_animation_frame()
|
||||||
|
|
@ -109,11 +123,11 @@ function internals.on_animation_frame()
|
||||||
debug.error("animation track not found: "..track_info.name)
|
debug.error("animation track not found: "..track_info.name)
|
||||||
table.remove(playing_tracks, i)
|
table.remove(playing_tracks, i)
|
||||||
else
|
else
|
||||||
track_info.timer = track_info.timer + delta
|
track_info.__timer = track_info.__timer + delta
|
||||||
if track_info.timer > track.duration then
|
if track_info.__timer > track.duration then
|
||||||
table.remove(playing_tracks, i)
|
table.remove(playing_tracks, i)
|
||||||
else
|
else
|
||||||
track.func(track_info.target, track_info.timer)
|
track.func(track_info.target, track_info.__timer)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@ local function codegen_track(raw_track, lineset, memoised, keysets, use_tsf)
|
||||||
|
|
||||||
local axis_names = {"X", "Y", "Z"}
|
local axis_names = {"X", "Y", "Z"}
|
||||||
local axis_indices = {X=1, Y=2, Z=3}
|
local axis_indices = {X=1, Y=2, Z=3}
|
||||||
local rotation_order = raw_track.rotation_order
|
local rotation_order = raw_track.rotation_order or "XYZ"
|
||||||
for i=1,3 do
|
for i=1,3 do
|
||||||
local axis = axis_indices[rotation_order[i]]
|
local axis = axis_indices[rotation_order[i]]
|
||||||
local var = rotation[axis]
|
local var = rotation[axis]
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ local function parse_configure(raw_track, node)
|
||||||
elseif node.duration then
|
elseif node.duration then
|
||||||
raw_track.duration = node.duration
|
raw_track.duration = node.duration
|
||||||
end
|
end
|
||||||
raw_track.rotation_order = string.upper(node["rotation-order"]) or "XYZ"
|
raw_track.rotation_order = string.upper(node["rotation-order"])
|
||||||
end
|
end
|
||||||
|
|
||||||
local function parse_curve(line, node)
|
local function parse_curve(line, node)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue