protected override void PreProcessTopLevelObjects(List<Parsed.Object> topLevelContent)
{
var flowsFromOtherFiles = new List<FlowBase> ();
// Inject included files
int i = 0;
while (i < topLevelContent.Count) {
var obj = topLevelContent [i];
if (obj is IncludedFile) {
var file = (IncludedFile)obj;
// Remove the IncludedFile itself
topLevelContent.RemoveAt (i);
// When an included story fails to load, the include
// line itself is still valid, so we have to handle it here
if (file.includedStory) {
var nonFlowContent = new List<Parsed.Object> ();
var subStory = file.includedStory;
// Allow empty file
if (subStory.content != null) {
foreach (var subStoryObj in subStory.content) {
if (subStoryObj is FlowBase) {
flowsFromOtherFiles.Add ((FlowBase)subStoryObj);
} else {
nonFlowContent.Add (subStoryObj);
}
}
// Add newline on the end of the include
nonFlowContent.Add (new Parsed.Text ("\n"));
// Add contents of the file in its place
topLevelContent.InsertRange (i, nonFlowContent);
// Skip past the content of this sub story
// (since it will already have recursively included
// any lines from other files)
i += nonFlowContent.Count;
}
}
// Include object has been removed, with possible content inserted,
// and position of 'i' will have been determined already.
continue;
}
// Non-include: skip over it
else {
i++;
}
}
// Add the flows we collected from the included files to the
// end of our list of our content
topLevelContent.AddRange (flowsFromOtherFiles.ToArray());
}