Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        // ---------------------------------
        // 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);
            }
        }
Esempio n. 3
0
 public void Advance(StoryLink link)
 {
     DoLink(link);
 }
Esempio n. 4
0
        public void DoLink(string linkName)
        {
            StoryLink link = GetLink(linkName, true);

            DoLink(link);
        }