public static void AddStageAtIndex(FStage stageToAdd, int newIndex)
{
int stageIndex = _stages.IndexOf(stageToAdd);
if(newIndex > _stages.Count) //if it's past the end, make it at the end
{
newIndex = _stages.Count;
}
if(stageIndex == newIndex) return; //if it's already at the right index, just leave it there
if(stageIndex == -1) //add it if it's not in the stages already
{
stageToAdd.HandleAddedToFutile();
_stages.Insert(newIndex, stageToAdd);
}
else //if stage is already in the stages, move it to the desired index
{
_stages.RemoveAt(stageIndex);
if(stageIndex < newIndex)
{
_stages.Insert(newIndex-1, stageToAdd); //gotta subtract 1 to account for it moving in the order
}
else
{
_stages.Insert(newIndex, stageToAdd);
}
}
UpdateStageIndices();
}