public void SwitchToCase(int caseNumber) { if (PMWrapper.IsCompilerRunning || PMWrapper.IsCompilerUserPaused) { return; } SetButtonActive(); PMWrapper.SwitchCase(caseNumber); }
public void SwitchToCase(int caseNumber) { if (PMWrapper.IsCompilerRunning || PMWrapper.IsCompilerUserPaused || PMWrapper.IsCasesRunning) { return; } LevelModeButtons.Instance.SetSandboxButtonToDefault(); SetButtonActive(); PMWrapper.SwitchCase(caseNumber); }
/// <summary> /// Loads the scene, opens the level, sets case, runs the case, then unloads the scene. /// Guarantees a fresh game instance between each case. /// Useful to try catch unwanted state between cases. /// <para>Argument <paramref name="data"/> can be fed using the <see cref="ValueSourceAttribute"/> in combination /// with using <see cref="PlaygroundTestHelper.GetActiveCases"/> from <see cref="PlaygroundTestHelper"/>.</para> /// <para>Note: Needs attribute <see cref="UnityTestAttribute"/> to be applied on the overridden method /// in your derived class for Unity Test Runner to find the method.</para> /// </summary> /// <param name="data">The level data. Use <see cref="PlaygroundTestHelper.GetActiveCases"/> /// from <see cref="PlaygroundTestHelper"/> to feed automatically using <see cref="ValueSourceAttribute"/>.</param> public virtual IEnumerator TestPlayCase(CaseTestData data) { if (data.caseData == null) { Assert.Inconclusive($"Level '{data.levelData.id}' ({data.scene.name}) has not a single case."); } // Arrange Main.instance.ignorePlayingGuides = true; Main.instance.ignoreNextCase = true; Main.instance.StartGame(data.levelIndex); yield return(null); PMWrapper.SwitchCase(data.caseIndex); yield return(null); var postSceneLoad = PostSceneLoad(); while (postSceneLoad != null && postSceneLoad.MoveNext()) { yield return(postSceneLoad.Current); } yield return(null); PMWrapper.speedMultiplier = 1; // Act if (!string.IsNullOrWhiteSpace(data.levelData.levelSettings.exampleSolutionCode)) { PMWrapper.mainCode = data.levelData.levelSettings.exampleSolutionCode; } else { Assert.Inconclusive($"Level '{data.levelData.id}' ({data.scene.name}) has no example solution."); } IEnumerator coroutine = PlaygroundTestHelper.RunCaseAndAssert(data); while (coroutine.MoveNext()) { yield return(coroutine.Current); } // Asserting is done by assuming no exceptions & no error logs }