diff --git a/Assets/Scripts/InventoryStuff/ScrollDetails.cs b/Assets/Scripts/InventoryStuff/ScrollDetails.cs index 27ed12e8e7fdcc8c9c26666b3da45308bf0aac16..a07eb8faff920a5ccf6d2def4caec8c95bc50bcc 100644 --- a/Assets/Scripts/InventoryStuff/ScrollDetails.cs +++ b/Assets/Scripts/InventoryStuff/ScrollDetails.cs @@ -19,6 +19,8 @@ public class ScrollDetails : MonoBehaviour public static List<GameObject> ParameterDisplays; private static List<Scroll.ScrollAssignment> LatestCompletions; + public string currentMmtAnswer; + public Vector3 GetPosition(int i) { return new Vector3(x_Start, y_Start + i * (-y_Paece_Between_Items), 0f); @@ -68,28 +70,19 @@ public void magicButtonTrigger() { IEnumerator magicButton() { - bool workDone = false; + //Non blocking wait till sendView() is finished + yield return sendView("/scroll/apply"); - while (!workDone) + if (currentMmtAnswer == null) { - // Let the engine run for a frame for not letting the game freeze - yield return null; - - string answer = sendView("/scroll/apply"); - - if (answer == null) - { - Debug.Log("DAS HAT NICHT GEKLAPPT"); - //TODO: hier ne Art PopUp, wo drin steht, dass das nicht geklappt hat - PushoutFactFailEvent.Invoke(null); - } - else - { - Scroll.ScrollApplicationInfo pushout = JsonConvert.DeserializeObject<Scroll.ScrollApplicationInfo>(answer); - readPushout(pushout.acquiredFacts); - } - - workDone = true; + Debug.Log("DAS HAT NICHT GEKLAPPT"); + //TODO: hier ne Art PopUp, wo drin steht, dass das nicht geklappt hat + PushoutFactFailEvent.Invoke(null); + } + else + { + Scroll.ScrollApplicationInfo pushout = JsonConvert.DeserializeObject<Scroll.ScrollApplicationInfo>(currentMmtAnswer); + readPushout(pushout.acquiredFacts); } } @@ -99,30 +92,21 @@ public void newAssignmentTrigger() { IEnumerator newAssignment() { - bool workDone = false; + //Non blocking wait till sendView() is finished + yield return sendView("/scroll/dynamic"); - while (!workDone) + if (currentMmtAnswer == null) { - // Let the engine run for a frame for not letting the game freeze - yield return null; - - string answer = sendView("/scroll/dynamic"); - - if (answer == null) - { - Debug.Log("DAS HAT NICHT GEKLAPPT"); - } - else - { - Scroll.ScrollDynamicInfo scrollDynamicInfo = JsonConvert.DeserializeObject<Scroll.ScrollDynamicInfo>(answer); - processScrollDynamicInfo(scrollDynamicInfo); - } - - workDone = true; + Debug.Log("DAS HAT NICHT GEKLAPPT"); + } + else + { + Scroll.ScrollDynamicInfo scrollDynamicInfo = JsonConvert.DeserializeObject<Scroll.ScrollDynamicInfo>(currentMmtAnswer); + processScrollDynamicInfo(scrollDynamicInfo); } } - private string sendView(string endpoint) + IEnumerator sendView(string endpoint) { string body = prepareScrollAssignments(); @@ -130,18 +114,21 @@ private string sendView(string endpoint) www.method = UnityWebRequest.kHttpVerbPOST; www.SetRequestHeader("Content-Type", "application/json"); var async = www.Send(); - while (!async.isDone) { } + while (!async.isDone) { + //Non blocking wait for one frame, for letting the game do other things + yield return null; + } if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); - return null; + currentMmtAnswer = null; } else { string answer = www.downloadHandler.text; Debug.Log(answer); - return answer; + currentMmtAnswer = answer; } }