public void Resume() { if (this.State != TwineStoryState.Paused) { throw new InvalidOperationException( // Paused this.State == TwineStoryState.Idle ? "The story is currently idle. Call Begin, Advance or GoTo to play." : // Playing this.State == TwineStoryState.Playing || this.State == TwineStoryState.Exiting? "Resume() should be called only when the story is paused." : // Complete "The story is complete. Reset() must be called before it can be played again." ); } // Either enter the next passage, or Execute if it was already entered if (_passageWaitingToEnter != null) { Enter(_passageWaitingToEnter); } else { this.State = TwineStoryState.Playing; Execute(); } }
public void GoTo(string passageName) { if (this.State != TwineStoryState.Idle) { throw new InvalidOperationException( // Paused this.State == TwineStoryState.Paused ? "The story is currently paused. Resume() must be called before advancing to a different passage." : // Playing this.State == TwineStoryState.Playing || this.State == TwineStoryState.Exiting ? "The story can only be advanced when it is in the Idle state." : // Complete "The story is complete. Reset() must be called before it can be played again." ); } // Indicate specified passage as next _passageWaitingToEnter = passageName; if (CurrentPassageName != null) { this.State = TwineStoryState.Exiting; // invoke exit hooks HooksInvoke(HooksFind("Exit", reverse: true)); } if (this.State != TwineStoryState.Paused) { Enter(passageName); } }
void Enter(string passageName) { _passageWaitingToEnter = null; this.Output.Clear(); this.Text.Clear(); this.Links.Clear(); this.PassageParameters = null; _passageUpdateHooks = null; TwinePassage passage = GetPassage(passageName); this.Tags = (string[])passage.Tags.Clone(); this.PreviousPassageName = this.CurrentPassageName; this.CurrentPassageName = passage.Name; // Update visited counters for passages and tags int visitedPassage; if (!_visitedCountPassages.TryGetValue(passageName, out visitedPassage)) { visitedPassage = 0; } _visitedCountPassages[passageName] = visitedPassage + 1; for (int i = 0; i < passage.Tags.Length; i++) { string tag = passage.Tags[i]; int visitedTag; if (!_visitedCountTags.TryGetValue(tag, out visitedTag)) { visitedTag = 0; } _visitedCountTags[tag] = visitedTag + 1; } // Add output (and trigger hooks) this.Output.Add(passage); // Prepare the enumerator _passageExecutor = ExecutePassage(passage).GetEnumerator(); // Get update hooks for calling during update _passageUpdateHooks = HooksFind("Update", reverse: false, allowCoroutines: false).ToArray(); this.State = TwineStoryState.Playing; SendOutput(passage); HooksInvoke(HooksFind("Enter", maxLevels: 1)); // Story was paused, wait for it to resume if (this.State == TwineStoryState.Paused) { return; } else { Execute(); } }
void Story_OnStateChanged(TwineStoryState state) { if (state == TwineStoryState.Playing && this.Story.Output.Count == 1) { // Clear previous output Clear(); } }
/// <summary> /// While the story is playing, pauses the execution of the current passage. /// </summary> public void Pause() { if (this.State != TwineStoryState.Playing && this.State != TwineStoryState.Exiting) { throw new InvalidOperationException("Pause can only be called while a passage is playing or exiting."); } this.State = TwineStoryState.Paused; }
/// <summary> /// Resumes a story that was paused. /// </summary> void Execute() { while (_passageExecutor.MoveNext()) { TwineOutput output = _passageExecutor.Current; this.Output.Add(output); if (output is TwineLink) { // Add links to dedicated list var link = (TwineLink)output; this.Links.Add(link); } else if (output is TwineText) { // Add all text to the Text property for easy access var text = (TwineText)output; this.Text.Add(text); } // Let the handlers and hooks kick in if (output is TwinePassage) { HooksInvoke(HooksFind("Enter", reverse: true, maxLevels: 1)); // Refresh the update hooks _passageUpdateHooks = HooksFind("Update", reverse: false, allowCoroutines: false).ToArray(); } else { SendOutput(output); HooksInvoke(HooksFind("Output"), output); } // Story was paused, wait for it to resume if (this.State == TwineStoryState.Paused) { return; } } _passageExecutor.Dispose(); _passageExecutor = null; this.State = this.Links.Count > 0 ? TwineStoryState.Idle : TwineStoryState.Complete; HooksInvoke(HooksFind("Done")); }
protected void Init() { _state = TwineStoryState.Idle; this.Output = new List <TwineOutput>(); this.Text = new List <TwineText>(); this.Links = new List <TwineLink>(); this.Tags = new string[0]; this.PassageParameters = null; _turns = 0; _visitedCountPassages.Clear(); _visitedCountTags.Clear(); PreviousPassageName = null; CurrentPassageName = null; }
void Story_OnStateChanged(TwineStoryState state) { if (state == TwineStoryState.Idle || state == TwineStoryState.Complete) { //dialogUI.displayDialog ("", this.currentText); advanceStory(); //CleanupFunction = Close } else if (state == TwineStoryState.Playing) { //Make sure we don't display options prematurely HideOptions(); } //Debug.Log ("Now in state " + state); }
protected void Init() { _state = TwineStoryState.Idle; this.Output = new List<TwineOutput>(); this.Text = new List<TwineText>(); this.Links = new List<TwineLink>(); this.Tags = new string[0]; this.PassageParameters = null; _turns = 0; _visitedCountPassages.Clear(); _visitedCountTags.Clear(); PreviousPassageName = null; CurrentPassageName = null; }
/// <summary> /// Resumes a story that was paused. /// </summary> void Execute() { while (_passageExecutor.MoveNext()) { TwineOutput output = _passageExecutor.Current; this.Output.Add(output); if (output is TwineLink) { // Add links to dedicated list var link = (TwineLink)output; this.Links.Add(link); } else if (output is TwineText) { // Add all text to the Text property for easy access var text = (TwineText)output; this.Text.Add(text); } // Let the handlers and hooks kick in else if (output is TwinePassage) { HooksInvoke(HooksFind("Enter", reverse: true, maxLevels: 1)); // Refresh the update hooks _passageUpdateHooks = HooksFind("Update", reverse: false, allowCoroutines: false).ToArray(); } // Send output SendOutput(output); HooksInvoke(HooksFind("Output"), output); // Story was paused, wait for it to resume if (this.State == TwineStoryState.Paused) return; } _passageExecutor.Dispose(); _passageExecutor = null; this.State = this.Links.Count > 0 ? TwineStoryState.Idle : TwineStoryState.Complete; HooksInvoke(HooksFind("Done")); }
/// <summary> /// While the story is playing, pauses the execution of the current passage. /// </summary> public void Pause() { if (this.State != TwineStoryState.Playing && this.State != TwineStoryState.Exiting) throw new InvalidOperationException("Pause can only be called while a passage is playing or exiting."); this.State = TwineStoryState.Paused; }
void Enter(string passageName) { _passageWaitingToEnter = null; this.Output.Clear(); this.Text.Clear(); this.Links.Clear(); this.PassageParameters = null; _passageUpdateHooks = null; TwinePassage passage = GetPassage(passageName); this.Tags = (string[]) passage.Tags.Clone(); this.PreviousPassageName = this.CurrentPassageName; this.CurrentPassageName = passage.Name; // Update visited counters for passages and tags int visitedPassage; if (!_visitedCountPassages.TryGetValue(passageName, out visitedPassage)) visitedPassage = 0; _visitedCountPassages[passageName] = visitedPassage+1; for (int i = 0; i < passage.Tags.Length; i++) { string tag = passage.Tags[i]; int visitedTag; if (!_visitedCountTags.TryGetValue(tag, out visitedTag)) visitedTag = 0; _visitedCountTags[tag] = visitedTag+1; } // Add output (and trigger hooks) this.Output.Add(passage); // Prepare the enumerator _passageExecutor = ExecutePassage(passage).GetEnumerator(); // Get update hooks for calling during update _passageUpdateHooks = HooksFind("Update", reverse: false, allowCoroutines: false).ToArray(); this.State = TwineStoryState.Playing; SendOutput(passage); HooksInvoke(HooksFind("Enter", maxLevels: 1)); // Story was paused, wait for it to resume if (this.State == TwineStoryState.Paused) return; else Execute(); }
public void GoTo(string passageName) { if (this.State != TwineStoryState.Idle) { throw new InvalidOperationException( // Paused this.State == TwineStoryState.Paused ? "The story is currently paused. Resume() must be called before advancing to a different passage." : // Playing this.State == TwineStoryState.Playing || this.State == TwineStoryState.Exiting ? "The story can only be advanced when it is in the Idle state." : // Complete "The story is complete. Reset() must be called before it can be played again." ); } // Indicate specified passage as next _passageWaitingToEnter = passageName; if (CurrentPassageName != null) { this.State = TwineStoryState.Exiting; // invoke exit hooks HooksInvoke(HooksFind("Exit", reverse: true)); } if (this.State != TwineStoryState.Paused) Enter(passageName); }