public StoryLink GetLink(string linkName, bool throwException = false) { StoryLink link = this.GetCurrentLinks() .Where(lnk => string.Equals(lnk.Name, linkName, System.StringComparison.OrdinalIgnoreCase)) .FirstOrDefault(); if (link == null && throwException) { throw new StoryException(string.Format("There is no available link with the name '{0}' in the passage '{1}'.", linkName, this.CurrentPassage.Name)); } return(link); }
// --------------------------------- // Links public void DoLink(StoryLink link) { if (this.State != StoryState.Idle) { throw new InvalidOperationException( // Paused this.State == StoryState.Paused ? "The story is currently paused. Resume() must be called before a link can be used." : // Playing this.State == StoryState.Playing || this.State == StoryState.Exiting ? "A link can be used only when the story is in the Idle state." : // Complete "The story is complete. Reset() must be called before it can be played again." ); } // Process the link action before continuing if (link.Action != null) { CurrentLinkInAction = link; // Action might invoke a fragment method, in which case we need to process it with cues etc. IStoryThread linkActionThread = link.Action.Invoke(); if (linkActionThread != null) { // Prepare the fragment thread enumerator _currentThread = CollapseThread(linkActionThread).GetEnumerator(); // Resume story, this time with the actoin thread this.State = StoryState.Playing; ExecuteCurrentThread(); } } // Continue to the link passage only if a fragment thread (opened by the action) isn't in progress if (link.PassageName != null && _lastThreadResult == ThreadResult.Done) { NumberOfLinksDone++; GoTo(link.PassageName); } }
public void Advance(StoryLink link) { DoLink(link); }
public void DoLink(string linkName) { StoryLink link = GetLink(linkName, true); DoLink(link); }