Created
December 17, 2018 22:15
-
-
Save jesterswilde/8f33a75266b7334bab0512c9066997a7 to your computer and use it in GitHub Desktop.
This file contains 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
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