// Called by the RunCodeButton script public void SetWalkerUserPaused(bool paused) { if (!isWalkerRunning) { return; } enabled = !paused; isUserPaused = paused; if (paused) { foreach (IPMCompilerUserPaused ev in UISingleton.FindInterfaces <IPMCompilerUserPaused>()) { ev.OnPMCompilerUserPaused(); } } else { foreach (IPMCompilerUserUnpaused ev in UISingleton.FindInterfaces <IPMCompilerUserUnpaused>()) { ev.OnPMCompilerUserUnpaused(); } } }
private IEnumerator ShowAnswerBubble(int lineNumber, string answer, bool correct) { compilerHasBeenStopped = false; UISingleton.instance.answerBubble.ShowMessage(lineNumber); UISingleton.instance.answerBubble.SetAnswerMessage("Svar: " + answer); yield return(new WaitForSeconds(3 * (1 - PMWrapper.speedMultiplier))); if (compilerHasBeenStopped) { AbortCase(); yield break; } if (correct) { // Call every implemented event foreach (var ev in UISingleton.FindInterfaces <IPMCorrectAnswer>()) { ev.OnPMCorrectAnswer(answer); } } else { Main.Instance.CaseHandler.CaseFailed(); // Call every implemented event foreach (var ev in UISingleton.FindInterfaces <IPMWrongAnswer>()) { ev.OnPMWrongAnswer(answer); } } }
public void CompileFullCode() { enabled = true; lastLineNumber = 0; theVarWindow.ResetList(); foreach (IPMCompilerStarted ev in UISingleton.FindInterfaces <IPMCompilerStarted>()) { ev.OnPMCompilerStarted(); } try { compiledCode = CreateProcessor(); compiledCode.AddBuiltin(BUILTIN_FUNCTIONS.ToArray()); compiledCode.AddBuiltin(addedFunctions.ToArray()); } catch (SyntaxException e) when(!e.SourceReference.IsFromClr) { StopCompiler(StopStatus.RuntimeError); PMWrapper.RaiseError(e.SourceReference.FromRow, e.Message); } catch (Exception e) { StopCompiler(StopStatus.RuntimeError); PMWrapper.RaiseError(e.Message); } }
public void SetCurrentCase(int caseNumber) { if (caseNumber != CurrentCase) { // currentCaseButtonUnpressed LevelModeButtons.Instance.SetCaseButtonsToDefault(); CurrentCase = Mathf.Clamp(caseNumber, 0, numberOfCases); CaseFlash.Instance.HideFlash(); if (numberOfCases > 1) { CaseFlash.Instance.ShowNewCaseFlash(CurrentCase); } } // currentCaseButtonPressed LevelModeButtons.Instance.SetCurrentCaseButtonState(LevelModeButtonState.Active); LevelModeController.Instance.SwitchToCaseMode(); // Call every implemented event foreach (var ev in UISingleton.FindInterfaces <IPMCaseSwitched>()) { ev.OnPMCaseSwitched(CurrentCase); } }
protected IEnumerator ShowAnswerBubble(string answer, bool correct) { compilerHasBeenStopped = false; UISingleton.instance.answerBubble.ShowMessage(); UISingleton.instance.answerBubble.SetAnswerMessage("Svar: " + answer); yield return(new WaitForSeconds(3 * (1 - PMWrapper.speedMultiplier))); if (compilerHasBeenStopped) { Debug.LogError("Compiler stopped prematurely."); AbortCase(); yield break; } if (correct) { // Call every implemented event foreach (IPMCorrectAnswer ev in UISingleton.FindInterfaces <IPMCorrectAnswer>()) { ev.OnPMCorrectAnswer(answer); } } else { Main.instance.caseHandler.CaseFailed(); // Call every implemented event foreach (IPMWrongAnswer ev in UISingleton.FindInterfaces <IPMWrongAnswer>()) { ev.OnPMWrongAnswer(answer); } } }
public void compileCode() { if (isRunning) { return; } isRunning = true; foreach (var ev in UISingleton.FindInterfaces <IPMCompilerStarted>()) { ev.OnPMCompilerStarted(); } try { Runtime.VariableWindow.setVariableWindowFunctions(theVarWindow.addVariable, theVarWindow.resetList); ErrorHandler.ErrorMessage.setLanguage(); ErrorHandler.ErrorMessage.setErrorMethod(PMWrapper.RaiseError); GameFunctions.setGameFunctions(allAddedFunctions); theCodeWalker.ActivateWalker(stopCompiler); } catch { stopCompiler(StopStatus.RuntimeError); throw; } }
// Listener public void valueChanged() { foreach (var ev in UISingleton.FindInterfaces <IPMSpeedChanged>()) { ev.OnPMSpeedChanged(currentSpeed); } }
public void stopCompiler(StopStatus status = StopStatus.CodeForced) { isRunning = false; theCodeWalker.StopWalker(); // Call stop events foreach (var ev in UISingleton.FindInterfaces <IPMCompilerStopped>()) { ev.OnPMCompilerStopped(status); } }
public void StopCompiler(StopStatus status = StopStatus.CodeForced) { SetWalkerUserPaused(false); compiledCode = null; EvaluateEnabled(); // Call stop events foreach (IPMCompilerStopped ev in UISingleton.FindInterfaces <IPMCompilerStopped>()) { ev.OnPMCompilerStopped(status); } }
public void InitSandboxMode() { LevelMode = LevelMode.Sandbox; LevelModeButtons.Instance.SetSandboxButtonState(LevelModeButtonState.Active); LevelModeButtons.Instance.SetCaseButtonsToDefault(); Main.Instance.SetSettings(); foreach (var ev in UISingleton.FindInterfaces <IPMSwitchedToSandbox>()) { ev.OnPMSwitchedToSandbox(); } }
public void StartLevel(int levelIndex) { string sceneName = gameDefinition.activeLevels[levelIndex].sceneName; LoadScene(sceneName); string levelId = gameDefinition.activeLevels[levelIndex].levelId; LoadLevel(levelId); foreach (IPMLevelChanged ev in UISingleton.FindInterfaces <IPMLevelChanged>()) { ev.OnPMLevelChanged(); } }
public void SetLevelCompleted() { PMWrapper.StopCompiler(); foreach (var ev in UISingleton.FindInterfaces <IPMLevelCompleted>()) { ev.OnPMLevelCompleted(); } // If theres more levels && next level is locked if (PMWrapper.currentLevel < PMWrapper.numOfLevels - 1 && PMWrapper.currentLevel == PMWrapper.unlockedLevel) { // Unlock next level UISingleton.instance.levelbar.UpdateButtons(PMWrapper.currentLevel, PMWrapper.currentLevel + 1); } _ShowWinScreen(); }
public void ChangeLevel(int levelIndex) { if (levelIndex == Current) { return; } foreach (var ev in UISingleton.FindInterfaces <IPMUnloadLevel>()) { ev.OnPMUnloadLevel(); } Unlocked = Mathf.Max(levelIndex, Unlocked); // Update which one is current one UpdateButtons(levelIndex, Unlocked); Main.Instance.StartLevel(levelIndex); }
private void Awake() { instance = this; /* Old. Should be replaced with something new * // Load error api config * TextAsset file = Resources.Load<TextAsset>("game_token"); * if (file == null) * gameToken = "1234"; * * try { * gameToken = file.text.Trim(); * } catch { } * * if (gameToken == null || gameToken.Length != 32 || !System.Text.RegularExpressions.Regex.IsMatch(gameToken, @"[a-fA-F0-9]+")) { * Debug.LogError("Invalid game token!"); * gameToken = null; * }*/ }
public void OnPMCompilerStopped(StopStatus status) { if (status == StopStatus.Finished) { if (levelMode == LevelMode.Sandbox && Main.instance.levelDefinition.cases != null && Main.instance.levelDefinition.cases.Count > 0) { correctProgramPanel.SetActive(true); } else if (levelMode == LevelMode.Case) { foreach (IPMTimeToCorrectCase ev in UISingleton.FindInterfaces <IPMTimeToCorrectCase>()) { ev.OnPMTimeToCorrectCase(); } } else { PMWrapper.SetLevelCompleted(); } } if (status == StopStatus.RuntimeError) { if (levelMode == LevelMode.Case) { Main.instance.caseHandler.CaseFailed(); } } if (status == StopStatus.UserForced) { if (levelMode == LevelMode.Case) { Main.instance.caseHandler.isCasesRunning = false; } } }
// Called by the RunCodeButton script public void SetWalkerUserPaused(bool paused) { if (paused == IsUserPaused) { return; } IsUserPaused = paused; if (IsUserPaused) { foreach (var ev in UISingleton.FindInterfaces <IPMCompilerUserPaused>()) { ev.OnPMCompilerUserPaused(); } } else { foreach (var ev in UISingleton.FindInterfaces <IPMCompilerUserUnpaused>()) { ev.OnPMCompilerUserUnpaused(); } } }
private void Awake() { instance = this; }