module("EseBWRecorder", package.seeall) -- Functions -- Behavior function OnTimelineTag(selfID, strm) local animName = strm:GetString(); if animName == "STOP" then local result, keys = BehaviorAPI.FindPropertyKeys(selfID, "Recorders"); for i, key in pairs(keys) do recorderID = BehaviorAPI.GetProperty(selfID, "Recorders", key); epgmLiveMove.StopRecording(recorderID); end else local result, keys = BehaviorAPI.FindPropertyKeys(selfID, "Recorders"); for i, key in pairs(keys) do recorderID = BehaviorAPI.GetProperty(selfID, "Recorders", key); epgmLiveMove.StartRecording(recorderID, animName); end end end -- Behavior function OnEntitySetFinished(selfID, strm) BehaviorAPI.SendEvent(selfID, "OnLoadLevel", nil); end -- Behavior function OnLoadLevel(selfID, strm) BehaviorAPI.SetProperty(selfID, "Enabled", true); epgmGFx.InvokeActionscript(selfID, "DisplayIntro", ""); end -- Behavior function OnBeginMoves(selfID, strm) local activeMove = BehaviorAPI.GetProperty(selfID, "ActiveMove"); if activeMove ~= nil then local nextKey = BehaviorAPI.GetNextPropertyKey(selfID, "TimelineGroups", activeMove); BehaviorAPI.SetProperty(selfID, "ActiveMove", nextKey); BehaviorAPI.SetProperty(selfID, "IterationCount", 0); if nextKey ~= "" then epgmGFx.InvokeActionscript(selfID, "DisplayNewMove", nextKey); end end end -- Behavior function OnStartNewMove(selfID, strm) local iterCount = BehaviorAPI.GetProperty(selfID, "IterationCount"); local maxIterCount = BehaviorAPI.GetProperty(selfID, "MaxIterCount"); local activeMove = BehaviorAPI.GetProperty(selfID, "ActiveMove"); if iterCount >= maxIterCount then -- Serialize the moves local result, keys = BehaviorAPI.FindPropertyKeys(selfID, "Recorders"); for i, key in pairs(keys) do recorderID = BehaviorAPI.GetProperty(selfID, "Recorders", key); epgmLiveMove.Serialize(recorderID); end BehaviorAPI.SendEvent(selfID, "OnBeginMoves", nil); else local params = { activeMove, iterCount }; epgmGFx.InvokeActionscript(selfID, "DisplayHUD", params); iterCount = iterCount + 1; BehaviorAPI.SetProperty(selfID, "IterationCount", iterCount); end end -- Behavior function OnStartTimeline(selfID, strm) local activeMove = BehaviorAPI.GetProperty(selfID, "ActiveMove"); local groupID = BehaviorAPI.GetProperty(selfID, "TimelineGroups", activeMove); local initialTime = BehaviorAPI.GetProperty(groupID, "InitialTime"); egmAnimation.SetPaused(selfID, false); BehaviorAPI.SetProperty(groupID, "TimeCursor", initialTime); BehaviorAPI.SetProperty(groupID, "IsRunning", true); end -- Behavior function OnEndTimeline(selfID, strm) local activeMove = BehaviorAPI.GetProperty(selfID, "ActiveMove"); local groupID = BehaviorAPI.GetProperty(selfID, "TimelineGroups", activeMove); local initialTime = BehaviorAPI.GetProperty(groupID, "InitialTime"); BehaviorAPI.SetProperty(groupID, "TimeCursor", initialTime); BehaviorAPI.SetProperty(groupID, "IsRunning", false); -- -2 in animation speak is no sequence: i.e. kInvalid egmAnimation.SetTargetAnimationById(selfID, -2); egmAnimation.SetPaused(selfID, true); BehaviorAPI.SendEvent(selfID, "OnStartNewMove", nil); end