public void SetIsManusPlaying(bool state) { if (state == isPlaying) { return; } isPlaying = state; UISingleton.instance.uiCanvasGroup.blocksRaycasts = !state; skipManusBubble.gameObject.SetActive(state); PMWrapper.speedMultiplier = 0.5f; if (state) { UISingleton.instance.textField.deActivateField(); IDELineMarker.instance.SetState(IDELineMarker.State.Hidden); currentManus = Loader.allManuses[PMWrapper.currentLevel].Copy(); currentManus.NextStep(); } else { if (currentManus != null) { currentManus.FastForwardAllSteps(); currentManus = null; } UISingleton.instance.textField.reActivateField(); UISingleton.instance.manusBubble.HideMessage(); PMWrapper.SetLevelCompleted(); IDELineMarker.SetIDEPosition(PMWrapper.preCode == string.Empty ? 1 : (PMWrapper.preCode.Split('\n').Length + 1)); } }
public override IScriptType Invoke(params IScriptType[] arguments) { if (arguments.Length == 0) { PMWrapper.RaiseError("Kräver minst 1 värde till max()."); } IScriptType max = null; foreach (IScriptType v in arguments) { if (max == null) { max = v; continue; } IScriptType result = v.CompareGreaterThan(max); if (result == null) { PMWrapper.RaiseError($"Kan inte jämföra datatypen '{v.GetTypeName()}'."); } else if (result.IsTruthy()) { max = v; } } return(max); }
private bool CorrectNumberOfCarsInQueue(string correctType, List <GameObject> queue, string direction) { if (correctType != "none" && correctType != "whatever") { var correctNumberOfCars = 0; foreach (var car in LevelController.CaseData.cars) { var currentType = FindTypeFromDefinition(car.sections.First().type); if (currentType == correctType) { correctNumberOfCars++; } } if (queue.Count < correctNumberOfCars) { PMWrapper.RaiseTaskError("För få varor sorterades " + direction); return(false); } if (queue.Count > correctNumberOfCars) { PMWrapper.RaiseTaskError("För många varor sorterade " + direction); return(false); } } return(true); }
public override Variable runFunction(Scope currentScope, Variable[] inputParas, int lineNumber) { GameObject car = CarQueue.GetFirstCar(); if (car == null) { PMWrapper.RaiseError(lineNumber, "Kan inte hitta något att scanna."); } Scanner scanner = Scanner.Instance; scanner.Scan(car); int lampCount = 0; foreach (Transform child in car.transform) { if (child.CompareTag("Lamp")) { lampCount++; } } scanner.SetDisplayText(lampCount); return(new Variable("lampCount", lampCount)); }
private void MoveWalls(Direction direction) { var move = Vector3.zero; float gameSpeedExp = MyLibrary.LinearToExponential(0, 1f, 10, PMWrapper.speedMultiplier); if (direction == Direction.Up) { move = Vector3.up * Time.deltaTime * gameSpeedExp * WallSpeed; } else if (direction == Direction.Down) { move = Vector3.down * Time.deltaTime * gameSpeedExp * WallSpeed; } Walls.transform.Translate(move); if (direction == Direction.Up && Walls.transform.localPosition.z > 0.2f) { isRasingWalls = false; isCharging = true; } else if (direction == Direction.Down && Walls.transform.localPosition.z < -0.3f) { isLoweringWalls = false; PMWrapper.UnpauseWalker(); } }
public override Variable runFunction(Scope currentScope, Variable[] inputParas, int lineNumber) { Variable v = inputParas[0]; switch (v.variableType) { case VariableTypes.number: if (Math.Abs(v.getNumber() - Math.Round(v.getNumber())) <= double.Epsilon) { // Close enough to whole number return(new Variable(v.name, Convert.ToString((long)Math.Round(v.getNumber()), 8))); } PMWrapper.RaiseError(lineNumber, "Kan endast konvertera heltal till oktaler!"); return(null); case VariableTypes.boolean: return(new Variable(v.name, v.getBool() ? "1" : "0")); case VariableTypes.textString: PMWrapper.RaiseError(lineNumber, "Kan inte konvertera text sträng till octaler!"); return(null); default: PMWrapper.RaiseError(lineNumber, "Kan inte konvertera 'None' till octaler!"); return(null); } }
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 OnPMCompilerStopped(HelloCompiler.StopStatus status) { if (status == HelloCompiler.StopStatus.Finished) { int itemsToUnload = 0; foreach (Section section in caseData.cars[0].sections) { itemsToUnload += section.itemCount; } if (itemsUnloaded < itemsToUnload) { int itemsNotUnloaded = itemsToUnload - itemsUnloaded; string itemsSingularOrPlural = itemsNotUnloaded == 1 ? "1 vara" : itemsNotUnloaded + " varor"; PMWrapper.RaiseTaskError("Alla varor blev inte avlastade. Nu är det " + itemsSingularOrPlural + " som inte lastas av."); } if (itemsToUnload == itemsUnloaded) { PMWrapper.SetCaseCompleted(); } } itemsUnloaded = 0; }
private bool CorrectNumberOfCarsInQueue(CorrectSortedQueue bounds, List <GameObject> queue, string direction) { var correctNumberOfCars = 0; foreach (var car in LevelController.CaseData.cars) { var itemsInCar = 0; foreach (var carSection in car.sections) { itemsInCar += carSection.itemCount; } if (itemsInCar <= bounds.upperBound && itemsInCar >= bounds.lowerBound) { correctNumberOfCars++; } } if (queue.Count < correctNumberOfCars) { PMWrapper.RaiseTaskError("För få tåg sorterades " + direction); return(false); } if (queue.Count > correctNumberOfCars) { PMWrapper.RaiseTaskError("För många tåg sorterades " + direction); return(false); } return(true); }
private IEnumerator ShowFeedbackAndRunNextCase() { string positiveMassage; if (numberOfCases == 1) { positiveMassage = "Bra jobbat!"; } else { positiveMassage = "Test " + (CurrentCase + 1) + " avklarat!"; } UISingleton.instance.taskDescription.ShowPositiveMessage(positiveMassage); yield return(new WaitForSeconds(3 * (1 - PMWrapper.speedMultiplier))); UISingleton.instance.answerBubble.HideMessage(); UISingleton.instance.taskDescription.HideTaskFeedback(); LevelModeButtons.Instance.SetCurrentCaseButtonState(LevelModeButtonState.Completed); CurrentCase++; if (CurrentCase >= numberOfCases) { IsCasesRunning = false; AllCasesCompleted = true; PMWrapper.SetLevelCompleted(); yield break; } SetCurrentCase(CurrentCase); RunCase(CurrentCase); }
private void CorrectCase() { int chargeBound = LevelController.CaseData.chargeBound; if (CorrectlyCharged == carsToCharge) { if (FalselyCharged > 0) { PMWrapper.RaiseTaskError("För många tåg laddades. Bara tåg med batterinivå < " + chargeBound + " ska laddas."); } else if (CheckChargeCounter < carsToCheck) { PMWrapper.RaiseTaskError("Alla tåg kollades inte. Se till att köra kolla_batterinivå() för varje tåg."); } else { PMWrapper.SetCaseCompleted(); } } else { if (CorrectlyCharged + FalselyCharged == carsToCharge) { PMWrapper.RaiseTaskError("Fel tåg laddades."); } else if (CorrectlyCharged + FalselyCharged < carsToCharge) { PMWrapper.RaiseTaskError("För få tåg laddades. Alla tåg med batterinivå < " + chargeBound + " ska laddas."); } else { PMWrapper.RaiseTaskError("För många tåg laddades. Bara tåg med batterinivå < " + chargeBound + " ska laddas."); } } }
public override Compiler.Variable runFunction(Compiler.Scope currentScope, Compiler.Variable[] inputParas, int lineNumber) { GameObject currentCar = CarQueue.GetFirstCar(); if (currentCar == null) { PMWrapper.RaiseError(lineNumber, "Hittade inget tåg att tömma. "); } UnloadableItem[] itemsToUnload = currentCar.GetComponentsInChildren <UnloadableItem>(); if (itemsToUnload.Length == 0) { PMWrapper.RaiseError(lineNumber, "Kan inte tömma ett tomt tåg. Kom ihåg att köra fram nästa tåg innan du tömmer igen."); } foreach (UnloadableItem item in itemsToUnload) { if (item != null) { item.IsUnloading = true; } } GameObject.FindGameObjectWithTag("SceneController").GetComponent <SceneController1_3>().carsUnloaded += 1; return(new Compiler.Variable()); }
public void CaseCompleted() { PMWrapper.StopCompiler(); Main.instance.StartCoroutine(ShowFeedbackAndRunNextCase()); LevelModeButtons.instance.SetCurrentCaseButtonState(LevelCaseState.Completed); }
public void OnPMCompilerStopped(HelloCompiler.StopStatus status) { PlayerMovement playerMovement = null; if (playerObject != null) { playerMovement = playerObject.GetComponent <PlayerMovement>(); } if (status == HelloCompiler.StopStatus.Finished) { if (playerMovement != null && playerMovement.AtChargeStation) { if (!playerMovement.isCharging) { PMWrapper.RaiseTaskError("Podden laddades inte. Kom ihåg att ladda()."); } } else { PMWrapper.RaiseTaskError("Podden kom inte hela vägen fram."); } } if (playerMovement != null && !playerMovement.isCharging) { playerMovement.Reset(); } }
private void SetLevelSettings() { if (currentLevelSettings == null) { return; } if (!string.IsNullOrEmpty(currentLevelSettings.precode)) { PMWrapper.preCode = currentLevelSettings.precode; } if (currentLevelSettings.taskDescription != null && !ignorePlayingGuides) { PMWrapper.SetTaskDescription(currentLevelSettings.taskDescription.header, currentLevelSettings.taskDescription.body); } else { PMWrapper.SetTaskDescription("", ""); } if (currentLevelSettings.rowLimit > 0) { PMWrapper.codeRowsLimit = currentLevelSettings.rowLimit; } if (currentLevelSettings.availableFunctions != null) { List <IEmbeddedType> availableFunctions = CreateFunctionsFromStrings(currentLevelSettings.availableFunctions); PMWrapper.AddCompilerFunctions(availableFunctions); } }
public override Variable runFunction(Scope currentScope, Variable[] inputParas, int lineNumber) { if (inputParas.Length == 0) { return(new Variable("Float", 0)); } Variable v = inputParas[0]; switch (v.variableType) { case VariableTypes.boolean: return(new Variable(v.name, v.getBool() ? 1 : 0)); case VariableTypes.textString: double num; if (double.TryParse(v.getString(), out num)) { return(new Variable(v.name, num)); } else { PMWrapper.RaiseError(lineNumber, onFail); } break; case VariableTypes.number: return(v); } PMWrapper.RaiseError(lineNumber, onFail); return(null); }
void OnEnable() { PMWrapper.mainCode = codeAtStart; PMWrapper.SetCompilerFunctions( new CustomFunction() ); }
public void StartStep() { if (!PMWrapper.IsCompilerRunning) { PMWrapper.StartCompiler(); } }
void Update() { if (Input.GetKeyDown(KeyCode.U)) { PMWrapper.RaiseTaskError("Nu glömde du att göra något..."); } }
public void StartStep() { stepsLeft = p_steps; if (!PMWrapper.IsCompilerRunning) { PMWrapper.StartCompiler(); } }
public bool IsStepDone() { if (PMWrapper.IsCompilerRunning) { PMWrapper.StopCompiler(); } return(!PMWrapper.IsCompilerRunning); }
public void TestLevel() { if (Main.Instance.LevelDefinition.levelSettings != null && Main.Instance.LevelDefinition.levelSettings.exampleSolutionCode != null) { PMWrapper.mainCode = Main.Instance.LevelDefinition.levelSettings.exampleSolutionCode; } PMWrapper.speedMultiplier = 1; PMWrapper.RunCode(); }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { // TODO play crash animation PMWrapper.RaiseTaskError("Podden kraschade. Undvik vägarbeten."); PMWrapper.StopCompiler(); } }
public void SwitchToCase(int caseNumber) { if (PMWrapper.IsCompilerRunning || PMWrapper.IsCompilerUserPaused) { return; } SetButtonActive(); PMWrapper.SwitchCase(caseNumber); }
public static GameObject GetFirstCar() { if (Cars.Count == 0) { PMWrapper.RaiseError("Hittade inget tåg."); return(null); } return(Cars.First.Value); }
private IEnumerator PlayChargeAnimation() { var animator = GameObject.FindGameObjectWithTag("ChargeStation").GetComponent <Animator>(); animator.SetTrigger("Charge"); yield return(new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length)); PMWrapper.SetCaseCompleted(); isCharging = false; }
// UITooltip Tooltip; public void OnRunCodeButtownClick() { if (PMWrapper.IsCompilerRunning) { UISingleton.instance.walker.SetWalkerUserPaused(!PMWrapper.IsCompilerUserPaused); } else { PMWrapper.RunCode(); } }
public void SwitchToCase(int caseNumber) { if (PMWrapper.IsCompilerRunning || PMWrapper.IsCompilerUserPaused || PMWrapper.IsCasesRunning) { return; } LevelModeButtons.Instance.SetSandboxButtonToDefault(); SetButtonActive(); PMWrapper.SwitchCase(caseNumber); }
public void UseSettings() { PMWrapper.codeRowsLimit = rowLimit; PMWrapper.SetTaskDescription(taskDescription); PMWrapper.preCode = preCode; PMWrapper.AddCodeAtStart(startCode); UISingleton.instance.levelHandler.currentLevel.caseHandler = new CaseHandler(caseCount); PMWrapper.codewalkerBaseSpeed = gameSpeed; PMWrapper.SetSmartButtons(smartButtons); PMWrapper.SetCompilerFunctions(functions); }
void Awake() { PMWrapper.SetCompilerFunctions( new MoveFunction("gå_norr", Direction.North), new MoveFunction("gå_väst", Direction.West), new MoveFunction("gå_syd", Direction.South), new MoveFunction("gå_öst", Direction.East) ); PMWrapper.AutoSetSmartButtons(); }