public IEnumerator FastForwardBranchingChapter() { // Given a chapter with a step branching to three transitions, Step branchingStep = new Step("Branching Step"); Chapter chapter = new Chapter("Chapter", branchingStep); Transition firstTransition = new Transition(); Transition secondTransition = new Transition(); Transition thirdTransition = new Transition(); EndlessCondition firstCondition = new EndlessCondition(); EndlessCondition secondCondition = new EndlessCondition(); EndlessCondition thirdCondition = new EndlessCondition(); firstTransition.Data.Conditions.Add(firstCondition); secondTransition.Data.Conditions.Add(secondCondition); thirdTransition.Data.Conditions.Add(thirdCondition); branchingStep.Data.Transitions.Data.Transitions.Add(firstTransition); branchingStep.Data.Transitions.Data.Transitions.Add(secondTransition); branchingStep.Data.Transitions.Data.Transitions.Add(thirdTransition); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); chapter.LifeCycle.Activate(); yield return(null); chapter.Update(); // When it's marked to be fast-forwarded, chapter.LifeCycle.MarkToFastForward(); // Then only the first transition completes. Assert.IsTrue(firstTransition.IsCompleted); Assert.IsFalse(secondTransition.IsCompleted); Assert.IsFalse(thirdTransition.IsCompleted); }
public IEnumerator NonBlockingBehaviorDoesNotBlock() { // Given a chapter with a step with no conditions but a transition to the end, and a non-blocking endless behavior, EndlessBehaviorMock nonBlockingBehaviorMock = new EndlessBehaviorMock(false); ITransition transition = new Transition(); transition.Data.TargetStep = null; IStep step = new Step("NonBlockingStep"); step.Data.Transitions.Data.Transitions.Add(transition); step.Data.Behaviors.Data.Behaviors.Add(nonBlockingBehaviorMock); IChapter chapter = new Chapter("NonBlockingChapter", step); chapter.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); // When we activate the chapter, chapter.LifeCycle.Activate(); // Then it will finish activation immediately after a few update cycles. while (chapter.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Assert.AreEqual(Stage.Active, chapter.LifeCycle.Stage); }
public IEnumerator NonBlockingBehaviorLoop() { // Given a chapter with a step with a loop transition, and a non-blocking endless behavior, EndlessBehaviorMock nonBlockingBehaviorMock = new EndlessBehaviorMock(false); ITransition transition = new Transition(); IStep step = new Step("NonBlockingStep"); transition.Data.TargetStep = step; step.Data.Transitions.Data.Transitions.Add(transition); step.Data.Behaviors.Data.Behaviors.Add(nonBlockingBehaviorMock); IChapter chapter = new Chapter("NonBlockingChapter", step); chapter.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); // When we activate the chapter, chapter.LifeCycle.Activate(); // Then it will loop without any problems. int loops = 3; while (loops > 0) { while (step.LifeCycle.Stage != Stage.Activating) { yield return(null); chapter.Update(); } while (step.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } while (step.LifeCycle.Stage != Stage.Deactivating) { yield return(null); chapter.Update(); } while (step.LifeCycle.Stage != Stage.Inactive) { yield return(null); chapter.Update(); } Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage); loops--; } Assert.AreEqual(Stage.Inactive, step.LifeCycle.Stage); }
public IEnumerator StepWithHighlightBehavior() { // Given a HighlightObjectBehavior with a HighlightProperty in a linear chapter. Color highlightColor = Color.yellow; GameObject interactable = GameObject.CreatePrimitive(PrimitiveType.Cube); interactable.name = targetName; DummyHighlightProperty highlightProperty = interactable.AddComponent <DummyHighlightProperty>(); HighlightObjectBehavior highlightBehavior = new HighlightObjectBehavior(highlightProperty, highlightColor); TestLinearChapterBuilder chapterBuilder = TestLinearChapterBuilder.SetupChapterBuilder(1); chapterBuilder.Steps[0].Data.Behaviors.Data.Behaviors.Add(highlightBehavior); Chapter chapter = chapterBuilder.Build(); chapter.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); // When we activate the chapter. chapter.LifeCycle.Activate(); while (highlightBehavior.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage highlightStageInStep = highlightBehavior.LifeCycle.Stage; bool objectHighlightedActiveInStep = highlightProperty.IsHighlighted; Color?colorInStep = highlightProperty.CurrentHighlightColor; chapter.Data.FirstStep.LifeCycle.Deactivate(); while (chapter.Data.FirstStep.LifeCycle.Stage != Stage.Inactive) { yield return(null); chapter.Update(); } Stage highlightStageAfterStep = highlightBehavior.LifeCycle.Stage; bool objectHighlightedActiveAfterStep = highlightProperty.IsHighlighted; Color?colorAfterStep = highlightProperty.CurrentHighlightColor; // Then the highlight behavior is active during the step and inactive after it. Assert.AreEqual(Stage.Active, highlightStageInStep, "The HighlightObjectBehavior should be active during step"); Assert.IsTrue(objectHighlightedActiveInStep, "The HighlightProperty should be active during step"); Assert.AreEqual(highlightColor, colorInStep, $"The highlight color should be {highlightColor}"); Assert.AreEqual(Stage.Inactive, highlightStageAfterStep, "The HighlightObjectBehavior should be deactivated after step"); Assert.IsFalse(objectHighlightedActiveAfterStep, "The HighlightProperty should be inactive after step"); Assert.IsNull(colorAfterStep, "The highlight color should be null after deactivation of step."); }
public IEnumerator BlockingBehaviorDoesBlock() { // Given a chapter with a step with no conditions but a transition to the end, and a blocking endless behavior, EndlessBehaviorMock blockingBehaviorMock = new EndlessBehaviorMock(true); ITransition transition = new Transition(); transition.Data.TargetStep = null; IStep step = new Step("BlockingStep"); step.Data.Transitions.Data.Transitions.Add(transition); step.Data.Behaviors.Data.Behaviors.Add(blockingBehaviorMock); IChapter chapter = new Chapter("BlockingChapter", step); chapter.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); // When we activate the chapter, chapter.LifeCycle.Activate(); while (blockingBehaviorMock.LifeCycle.Stage != Stage.Activating) { yield return(null); chapter.Update(); } // When endless behavior stays activating even after a few frames, int waitingFrames = 10; while (waitingFrames > 0) { yield return(null); chapter.Update(); Assert.AreEqual(Stage.Activating, blockingBehaviorMock.LifeCycle.Stage); Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage); waitingFrames--; } // Then the chapter will not be activated until the behavior finishes. blockingBehaviorMock.LifeCycle.MarkToFastForward(); Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage); while (chapter.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Assert.AreEqual(Stage.Active, chapter.LifeCycle.Stage); }
public IEnumerator FastForwardLoopingChapter() { // Given a chapter with a looping step, Step loopingStep = new Step("Looping Step"); Chapter chapter = new Chapter("Chapter", loopingStep); Transition loopingTransition = new Transition(); loopingTransition.Data.TargetStep = loopingStep; Transition endTransition = new Transition(); EndlessCondition condition = new EndlessCondition(); endTransition.Data.Conditions.Add(condition); loopingStep.Data.Transitions.Data.Transitions.Add(loopingTransition); loopingStep.Data.Transitions.Data.Transitions.Add(endTransition); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); chapter.LifeCycle.Activate(); int loops = 0; while (loops < 2) { while (loopingStep.LifeCycle.Stage != Stage.Active) { Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage); yield return(null); chapter.Update(); } while (loopingStep.LifeCycle.Stage != Stage.Inactive) { Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage); yield return(null); chapter.Update(); } loops++; } // When it's marked to be fast-forwarded, chapter.LifeCycle.MarkToFastForward(); // Then it completes. Assert.AreEqual(Stage.Active, chapter.LifeCycle.Stage); Assert.AreEqual(Stage.Inactive, loopingStep.LifeCycle.Stage); }
public IEnumerator FirstStepGetActivated() { // Setup Chapter Chapter chapter = TestLinearChapterBuilder.SetupChapterBuilder(3, true).Build(); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // Activate should work on simple steps. chapter.LifeCycle.Activate(); while (chapter.Data.FirstStep.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } // First Step should be active now. Assert.IsNotNull(chapter.Data.Current, "First step not set"); Assert.AreEqual(chapter.Data.Current.LifeCycle.Stage, Stage.Active, "First Step of Chapter was not activated"); }
public IEnumerator FastForwardTwoStepsLoopingChapter() { // Given a chapter with two steps looping between each other, Step firstStep = new Step("First Step"); Step secondStep = new Step("Second Step"); Chapter chapter = new Chapter("Chapter", firstStep); chapter.Data.Steps.Add(secondStep); Transition firstToSecond = new Transition(); firstToSecond.Data.TargetStep = secondStep; Transition secondToFirst = new Transition(); secondToFirst.Data.TargetStep = firstStep; Transition secondToEnd = new Transition(); EndlessCondition condition = new EndlessCondition(); secondToEnd.Data.Conditions.Add(condition); firstStep.Data.Transitions.Data.Transitions.Add(firstToSecond); secondStep.Data.Transitions.Data.Transitions.Add(secondToFirst); secondStep.Data.Transitions.Data.Transitions.Add(secondToEnd); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); chapter.LifeCycle.Activate(); int loops = 0; while (loops < 2) { while (firstStep.LifeCycle.Stage != Stage.Active) { Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage); Assert.AreEqual(Stage.Inactive, secondStep.LifeCycle.Stage); yield return(null); chapter.Update(); } while (firstStep.LifeCycle.Stage != Stage.Inactive) { Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage); Assert.AreEqual(Stage.Inactive, secondStep.LifeCycle.Stage); yield return(null); chapter.Update(); } while (secondStep.LifeCycle.Stage != Stage.Active) { Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage); Assert.AreEqual(Stage.Inactive, firstStep.LifeCycle.Stage); yield return(null); chapter.Update(); } while (secondStep.LifeCycle.Stage != Stage.Inactive) { Assert.AreEqual(Stage.Activating, chapter.LifeCycle.Stage); Assert.AreEqual(Stage.Inactive, firstStep.LifeCycle.Stage); yield return(null); chapter.Update(); } loops++; } // When it's marked to be fast-forwarded, chapter.LifeCycle.MarkToFastForward(); // Then it completes. Assert.AreEqual(Stage.Active, chapter.LifeCycle.Stage); Assert.AreEqual(Stage.Inactive, firstStep.LifeCycle.Stage); Assert.AreEqual(Stage.Inactive, secondStep.LifeCycle.Stage); }
public IEnumerator LoopingStepsWithOneEndStep() { // Given a chapter with three steps // where the first two steps are connected to each other with two transitions with each one condition ("loop") // and the second step is connected to the third step with a third transition with one condition, Step step1 = new Step("First"); Step step2 = new Step("Second"); Step step3 = new Step("Third"); Chapter chapter = new Chapter("Chapter 1", step1); chapter.Data.Steps.Add(step2); chapter.Data.Steps.Add(step3); Transition transition1 = new Transition(); Transition transition2 = new Transition(); Transition transition3 = new Transition(); Transition transitionToEnd = new Transition(); transition1.Data.TargetStep = step2; transition2.Data.TargetStep = step1; transition3.Data.TargetStep = step3; EndlessCondition condition1 = new EndlessCondition(); EndlessCondition condition2 = new EndlessCondition(); EndlessCondition condition3 = new EndlessCondition(); transition1.Data.Conditions.Add(condition1); transition2.Data.Conditions.Add(condition2); transition3.Data.Conditions.Add(condition3); step1.Data.Transitions.Data.Transitions.Add(transition1); step2.Data.Transitions.Data.Transitions.Add(transition2); step2.Data.Transitions.Data.Transitions.Add(transition3); step3.Data.Transitions.Data.Transitions.Add(transitionToEnd); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When we activate the chapter and complete the third condition after looping the first two steps once, chapter.LifeCycle.Activate(); while (chapter.Data.FirstStep.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } condition1.Autocomplete(); while (step2.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } condition2.Autocomplete(); while (step1.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } condition1.Autocomplete(); while (step2.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } condition3.Autocomplete(); while (chapter.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } // Then the chapter and each step are deactivated. Assert.AreEqual(Stage.Active, chapter.LifeCycle.Stage, "Chapter should be active in the end"); Assert.AreEqual(Stage.Inactive, step1.LifeCycle.Stage, "Step1 should not be active in the end"); Assert.AreEqual(Stage.Inactive, step2.LifeCycle.Stage, "Step2 should not be active in the end"); Assert.AreEqual(Stage.Inactive, step3.LifeCycle.Stage, "Step3 should not be active in the end"); yield break; }
public IEnumerator LoopingStepsActivationStates() { // Given a chapter with two steps that have transitions with one condition to each other (a "loop"), Step step1 = new Step("First"); Step step2 = new Step("Second"); Chapter chapter = new Chapter("Looping Chapter", step1); chapter.Data.Steps.Add(step2); Transition transition1 = new Transition(); Transition transition2 = new Transition(); transition1.Data.TargetStep = step2; transition2.Data.TargetStep = step1; EndlessCondition condition1 = new EndlessCondition(); EndlessCondition condition2 = new EndlessCondition(); transition1.Data.Conditions.Add(condition1); transition2.Data.Conditions.Add(condition2); step1.Data.Transitions.Data.Transitions.Add(transition1); step2.Data.Transitions.Data.Transitions.Add(transition2); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // When we activate the chapter and complete every condition, chapter.LifeCycle.Activate(); while (chapter.Data.FirstStep.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage chapterInitalStage = chapter.LifeCycle.Stage; Stage step1InitialStage = step1.LifeCycle.Stage; Stage step2InitialStage = step2.LifeCycle.Stage; condition1.Autocomplete(); while (step2.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage chapterStageAfterFirstComplete = chapter.LifeCycle.Stage; Stage step1StageAfterFirstComplete = step1.LifeCycle.Stage; Stage step2StageAfterFirstComplete = step2.LifeCycle.Stage; condition2.Autocomplete(); while (step1.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage chapterStageAfterSecondComplete = chapter.LifeCycle.Stage; Stage step1StageAfterSecondComplete = step1.LifeCycle.Stage; Stage step2StageAfterSecondComplete = step2.LifeCycle.Stage; // Then the first step is active again and every ActivationState after each condition completion has been correct. Assert.AreEqual(Stage.Activating, chapterInitalStage, "Chapter should be activating in the beginning"); Assert.AreEqual(Stage.Active, step1InitialStage, "First Step should be active in the beginning"); Assert.AreEqual(Stage.Inactive, step2InitialStage, "Second Step should be inactive in the beginning"); Assert.AreEqual(Stage.Activating, chapterStageAfterFirstComplete, "Chapter should be activating after first complete"); Assert.AreEqual(Stage.Inactive, step1StageAfterFirstComplete, "First Step should be deactivated after first complete"); Assert.AreEqual(Stage.Active, step2StageAfterFirstComplete, "Second Step should be active after first complete"); Assert.AreEqual(Stage.Activating, chapterStageAfterSecondComplete, "Chapter should not be activating after second complete because of the loop"); Assert.AreEqual(Stage.Active, step1StageAfterSecondComplete, "First Step should be active after second complete because of the loop"); Assert.AreEqual(Stage.Inactive, step2StageAfterSecondComplete, "Second Step should be deactivated after second complete because of the loop"); yield break; }
public IEnumerator MultiStepChapterCompletesSteps() { // Setup Chapter TestLinearChapterBuilder builder = TestLinearChapterBuilder.SetupChapterBuilder(2, true); Chapter chapter = builder.Build(); chapter.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); // Activate should work on simple steps. chapter.LifeCycle.Activate(); while (chapter.Data.FirstStep.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage chapterInitalStage = chapter.LifeCycle.Stage; Stage step1InitialStage = builder.Steps[0].LifeCycle.Stage; Stage step2InitialStage = builder.Steps[1].LifeCycle.Stage; builder.StepTriggerConditions[0].Autocomplete(); while (chapter.Data.Steps[1].LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage chapterStageAfterFirstComplete = chapter.LifeCycle.Stage; Stage step1StageAfterFirstComplete = builder.Steps[0].LifeCycle.Stage; Stage step2StageAfterFirstComplete = builder.Steps[1].LifeCycle.Stage; builder.StepTriggerConditions[1].Autocomplete(); while (chapter.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage chapterStageInEnd = chapter.LifeCycle.Stage; Stage step1StageInEnd = builder.Steps[0].LifeCycle.Stage; Stage step2StageInEnd = builder.Steps[1].LifeCycle.Stage; // check steps are activated and completed in correct order Assert.AreEqual(Stage.Activating, chapterInitalStage, "Chapter should be active in the beginning"); Assert.AreEqual(Stage.Active, step1InitialStage, "First Step should be active in the beginning"); Assert.AreEqual(Stage.Inactive, step2InitialStage, "Second Step should not be active in the beginning"); Assert.AreEqual(Stage.Activating, chapterStageAfterFirstComplete, "Chapter should be active after first complete"); Assert.AreEqual(Stage.Inactive, step1StageAfterFirstComplete, "First Step should not be active after first complete"); Assert.AreEqual(Stage.Active, step2StageAfterFirstComplete, "Second Step should be active after first complete"); Assert.AreEqual(Stage.Active, chapterStageInEnd, "Chapter should still be active, as nothing deactivated it."); Assert.AreEqual(Stage.Inactive, step1StageInEnd, "First Step should not be active in the end"); Assert.AreEqual(Stage.Inactive, step2StageInEnd, "Second Step should not be active in the end"); }