diff --git a/res/modules/animation.lua b/res/modules/animation.lua index fb0a915f2..3f6acf351 100644 --- a/res/modules/animation.lua +++ b/res/modules/animation.lua @@ -68,26 +68,40 @@ end local running_actions = {} local playing_tracks = {} -local next_track_id = 1 function this.action(func) table.insert(running_actions, coroutine.create(func)) end -function this.play(name, target) - local id = next_track_id - table.insert(playing_tracks, {id=id, name=name, target=target, timer=0.0}) - next_track_id = id + 1 - return id -end - -function this.stop(id) - for i, entry in pairs(playing_tracks) do - if entry.id == id then - table.remove(playing_tracks, i) - return +local PlayingTrack = { + __index = { + stop = function(self) + table.remove_value(playing_tracks, self) + self.__timer = 0.0 + self.__playing = false + end, + pause = function(self) + table.remove_value(playing_tracks, self) + self.__playing = false + end, + resume = function(self) + if not self.__playing then + table.insert(playing_tracks, self) + self.__playing = true + 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 function internals.on_animation_frame() @@ -109,11 +123,11 @@ function internals.on_animation_frame() debug.error("animation track not found: "..track_info.name) table.remove(playing_tracks, i) else - track_info.timer = track_info.timer + delta - if track_info.timer > track.duration then + track_info.__timer = track_info.__timer + delta + if track_info.__timer > track.duration then table.remove(playing_tracks, i) else - track.func(track_info.target, track_info.timer) + track.func(track_info.target, track_info.__timer) end end end diff --git a/res/modules/internal/animation_codegen.lua b/res/modules/internal/animation_codegen.lua index 3301f401f..0b2cd7ce3 100644 --- a/res/modules/internal/animation_codegen.lua +++ b/res/modules/internal/animation_codegen.lua @@ -182,7 +182,7 @@ local function codegen_track(raw_track, lineset, memoised, keysets, use_tsf) local axis_names = {"X", "Y", "Z"} 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 local axis = axis_indices[rotation_order[i]] local var = rotation[axis] diff --git a/res/modules/internal/formats/vca.lua b/res/modules/internal/formats/vca.lua index 051066ecd..fc910a8d7 100644 --- a/res/modules/internal/formats/vca.lua +++ b/res/modules/internal/formats/vca.lua @@ -24,7 +24,7 @@ local function parse_configure(raw_track, node) elseif node.duration then raw_track.duration = node.duration end - raw_track.rotation_order = string.upper(node["rotation-order"]) or "XYZ" + raw_track.rotation_order = string.upper(node["rotation-order"]) end local function parse_curve(line, node)