Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class Timeline
{
int currentFrame = 0;
public int CurrentFrame
{
get { return currentFrame; }
set { currentFrame = value; }
}
Dictionary<int, List<Action>> frames = new Dictionary<int, List<Action>>();
Dictionary<int, List<TimedState>> states = new Dictionary<int, List<TimedState>>();
internal void AddAction(Action action)
{
if (!frames.ContainsKey(currentFrame))
{
frames[currentFrame] = new List<Action>();
}
frames[currentFrame].Add(action);
}
public void ProcessFrame()
{
List<Action> frame;
if (frames.TryGetValue(currentFrame, out frame))
{
frame.ForEach((action) =>
{
action.Timed.ProcessAction(action);
});
}
}
public void RecordCurrentState(List<TimedState> currentState){
states[currentFrame] = currentState;
}
internal void AddSerielizedState(TimedState state)
{
if(!states.ContainsKey(currentFrame)){
states[currentFrame] = new List<TimedState>();
}
states[currentFrame].Add(state);
}
public int SetStateToClosestFrame(int frame){
while(frame > 0 && !states.ContainsKey(frame)){
frame--;
}
currentFrame = frame;
states[currentFrame].ForEach((state)=>{
state.Target.Hydrate(state.Data);
});
return frame;
}
public bool HasStateAtFrame(int frame){
return states.ContainsKey(frame);
}
public void RemoveStateAtFrame(int frame){
states.Remove(frame);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.