public void OnBlockRecieved(GameObject block) //if loop placed : add new indented blocks { block.transform.SetParent(transform); for (int i = 0; i < slots.Count; i++) { slotValue s**t = slots[i]; if (block.transform.localPosition == s**t.slot.transform.localPosition) { if (block.CompareTag("Loop") || block.CompareTag("IfStatement")) { slots[i + 4].slot.SetActive(true); slots[i + 3].slot.SetActive(true); } else { slots[i + 3].slot.SetActive(true); } if (i % 3 > 0) { slots[i - (i % 3)].slot.SetActive(false); } s**t.method = block; block.transform.position = new Vector3(block.transform.position.x, block.transform.position.y, block.transform.position.z - 90); block.SetActive(false); block.SetActive(true); updateGas(); Logger.writeString("New block input to console in slot " + i + " of type " + block.name); break; } } }
IEnumerator WhatIfRunConsole(int number) //TODO - this { int startIndent = number % 3; for (int i = number; i < slots.Count - (2 - startIndent); i += 3) { if (loopFixer > 0 && loopFixer > i && startIndent != loopFixer % 3) { i = (loopFixer - loopFixer % 3) + startIndent; loopFixer = 0; } slotValue slot = slots[i]; if (slot.method != null) { DragNDrop blockScript = slot.method.GetComponent <DragNDrop>(); if (slot.method.CompareTag("IfStatement")) { if (startIndent > 1) { break; } //don't allow nesting within nesting! yield return(StartCoroutine("WhatIfRunConsole", (i + 3 + 1))); } else if (slot.method.CompareTag("Loop")) { if (startIndent > 1) { break; } //don't allow nesting within nesting! string loopTimes = ""; loopTimes = blockScript.loopVar.text == "" ? "1" : blockScript.loopVar.text; for (int j = 0; j < int.Parse(loopTimes); j++) { yield return(StartCoroutine("WhatIfRunConsole", (i + 3 + 1))); } } else { print("Doing nothing, as I am supposed to, sir! " + Time.time.ToString()); } } else if (startIndent > 0) /*print("Method is null! " + "Looking at: " + (i / 3) + "," + (i % 3) + " : " + Time.time.ToString());*/ { loopFixer = i; break; } } yield break; }
void updateGas() { gasMeter.gasReset(); List <int> lastEntered = new List <int>(); //since we have only two states (loop or if) bool is most efficient, albeit slightly less readable for (int i = 0; i < slots.Count - (i % 3); i += 3) { slotValue s**t = slots[i]; //s**t.slot.GetComponent<Image>().color = Color.black; if (s**t.method != null) { if (s**t.method.CompareTag("Loop")) { if (s**t.method.GetComponent <DragNDrop>().loopVar.text != "") { int howManyTimesShouldITakeYourGas = int.Parse(s**t.method.GetComponent <DragNDrop>().loopVar.text); if (howManyTimesShouldITakeYourGas > 1) { lastEntered.Add(howManyTimesShouldITakeYourGas); //loops are whatever the iterations they require i += 1; continue; } } } if ((s**t.method.CompareTag("IfStatement"))) { lastEntered.Add(0); //conditionals are 0 i += 1; continue; } } if (i % 3 != 0) { if (s**t.method == null) { i -= 4; lastEntered.RemoveAt(lastEntered.Count - 1); continue; } if (lastEntered.Count > 1) { if (lastEntered[lastEntered.Count - 1] == 0 && lastEntered[lastEntered.Count - 2] > 0) { //inside an if inside a loop for (int j = 0; j < lastEntered[lastEntered.Count - 2]; j++) { gasMeter.gasChecker(3); } } else if (lastEntered[lastEntered.Count - 2] == 0 && lastEntered[lastEntered.Count - 1] > 0) //if inside a loop inside an if { for (int j = 0; j < lastEntered[lastEntered.Count - 1]; j++) { gasMeter.gasChecker(3); } } else if (lastEntered[lastEntered.Count - 1] > 0 && lastEntered[lastEntered.Count - 2] > 0) //Loop inside loop (nested loops!) { for (int j = 0; j < lastEntered[lastEntered.Count - 1] * lastEntered[lastEntered.Count - 2]; j++) { gasMeter.gasChecker(1); } } continue; } if (lastEntered[lastEntered.Count - 1] > 0) { //inside a loop for (int j = 0; j < lastEntered[lastEntered.Count - 1]; j++) { gasMeter.gasChecker(1); } } else if (lastEntered[lastEntered.Count - 1] == 0) { //inside an if gasMeter.gasChecker(2); } else { gasMeter.gasChecker(0); } } else if (s**t.method != null) { gasMeter.gasChecker(0); } } }
IEnumerator RunConsole(int number) //TODO - this { int emptyCheck = 0; int startIndent = number % 3; for (int i = number; i < slots.Count - (2 - startIndent); i += 3) { if (loopFixer > 0 && loopFixer > i && startIndent < loopFixer % 3) { i = (loopFixer - loopFixer % 3) + startIndent; loopFixer = 0; } slotValue slot = slots[i]; if (slot.method != null) { DragNDrop blockScript = slot.method.GetComponent <DragNDrop>(); if (slot.method.CompareTag("IfStatement")) { if (startIndent > 1) { break; } //don't allow nesting within nesting! if (ifif(blockScript)) { print("if-Block entered. Starting new console at row: " + ((i + 3) / 3) + " and " + (startIndent + 1) + " : " + Time.time.ToString()); yield return(StartCoroutine("RunConsole", (i + 3 + 1))); } else { yield return(StartCoroutine("WhatIfRunConsole", (i + 3 + 1))); } } else if (slot.method.CompareTag("Loop")) { if (startIndent > 1) { break; } //don't allow nesting within nesting! string loopTimes = ""; loopTimes = blockScript.loopVar.text == ""? "1" : blockScript.loopVar.text; for (int j = 0; j < int.Parse(loopTimes); j++) { print("loop entered. Starting new console at row: " + ((i + 3) / 3) + " and " + (startIndent + 1) + " : " + Time.time.ToString()); yield return(StartCoroutine("RunConsole", (i + 3 + 1))); } } else { print("Executing function: " + blockScript.methodName.text + " " + Time.time.ToString()); yield return(playerMovement.StartCoroutine(blockScript.methodName.text)); //yield return new WaitWhile(() => playerMovement.driving); //<-- this is still nice code. Just not used } } else if (startIndent > 0) { print("Method is null! " + "Looking at: " + (i / 3) + "," + (i % 3) + " : " + Time.time.ToString()); loopFixer = i; break; } else { emptyCheck++; if (emptyCheck == 50) { Cursor.lockState = CursorLockMode.None; print("You are a fat c**t."); } } } yield break; }