/* Get enumerator */ IEnumerator GetAnyEnumerator( IterableContainer container, Func <DialogueLine, IEnumerator> OnLine, Func <Menu, IEnumerator> OnMenu, Func <IEnumerator> OnReturn = null, Func <Reference, IEnumerator> OnReference = null) { if (!IsPrimed) { throw new Exception("Can't iterate if the script is not primed!"); } return(container.GetEnumerator(OnLine, OnMenu, OnReturn, OnReference)); }
void RunIterable(Func <Menu, int> OnMenu, Action <DialogueLine> OnLine, IterableContainer c, Action <Reference> OnReference = null, int?Take = null) { var i = Take.GetValueOrDefault(); foreach (var x in this) { if (Take != null && --i < 0) { break; } if (x is Menu) { var menu = x as Menu; var ichoice = OnMenu(menu); if (ichoice < 0 || ichoice >= menu.Count) { throw new Exception("Invalid choice index!"); } CurrentChoiceIndex = (uint)ichoice; } else if (x is DialogueLine) { OnLine(x as DialogueLine); } else if (x is Reference) { var reference = x as Reference; if (OnReference == null) { reference.Action(); } else { OnReference(reference); } } else { Logger.Log("Unhandled item type: " + x.ToString()); } } }
/* Wrapper enumerators */ IEnumerator GetAnyWrapperEnumerator(IterableContainer container) { return(container.GetWrapperEnumerator()); }