From 5661040a0d4e14efa34b5f9e7be23265f7261326 Mon Sep 17 00:00:00 2001
From: unknown <john.schihada@hotmail.com>
Date: Tue, 24 Nov 2020 19:14:51 +0100
Subject: [PATCH] Making Pushout- and newAssignment-Routines non-blocking

---
 Assets/Scenes/TreeWorld_02.unity              |  5 ++
 Assets/Scripts/HideUI.cs                      |  1 +
 Assets/Scripts/InteractionEngine/Fact.cs      |  1 -
 .../Scripts/InventoryStuff/ScrollDetails.cs   | 70 ++++++++++++++-----
 4 files changed, 57 insertions(+), 20 deletions(-)

diff --git a/Assets/Scenes/TreeWorld_02.unity b/Assets/Scenes/TreeWorld_02.unity
index 0cd667b6..5d4942e7 100644
--- a/Assets/Scenes/TreeWorld_02.unity
+++ b/Assets/Scenes/TreeWorld_02.unity
@@ -41258,6 +41258,11 @@ PrefabInstance:
   m_Modification:
     m_TransformParent: {fileID: 0}
     m_Modifications:
+    - target: {fileID: 4004370943283418989, guid: c1d50ceff6c06de40b71063574eba754,
+        type: 3}
+      propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
+      value: magicButtonTrigger
+      objectReference: {fileID: 0}
     - target: {fileID: 8372521933580734050, guid: c1d50ceff6c06de40b71063574eba754,
         type: 3}
       propertyPath: m_AnchorMax.x
diff --git a/Assets/Scripts/HideUI.cs b/Assets/Scripts/HideUI.cs
index a44a66f6..1719e1e5 100644
--- a/Assets/Scripts/HideUI.cs
+++ b/Assets/Scripts/HideUI.cs
@@ -50,6 +50,7 @@ void Update()
 
         }
         /*
+        //Todo before capturing: Make directories "UFrameIT-Screenshots/Unity_ScreenCapture" in project folder
         else if (Input.GetKeyDown(ScreenshotKey)) {
             ScreenCapture.CaptureScreenshot("UFrameIT-Screenshots\\Unity_ScreenCapture\\Capture.png");
         }
diff --git a/Assets/Scripts/InteractionEngine/Fact.cs b/Assets/Scripts/InteractionEngine/Fact.cs
index c7244961..d99dc3bc 100644
--- a/Assets/Scripts/InteractionEngine/Fact.cs
+++ b/Assets/Scripts/InteractionEngine/Fact.cs
@@ -3,7 +3,6 @@
 using UnityEngine;
 using UnityEngine.Networking;
 using static JSONManager;
-using static FactManager;
 
 public class ParsingDictionary {
 
diff --git a/Assets/Scripts/InventoryStuff/ScrollDetails.cs b/Assets/Scripts/InventoryStuff/ScrollDetails.cs
index 9cdf4d53..27ed12e8 100644
--- a/Assets/Scripts/InventoryStuff/ScrollDetails.cs
+++ b/Assets/Scripts/InventoryStuff/ScrollDetails.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System.Collections;
+using System.Collections.Generic;
 using UnityEngine;
 using TMPro;
 using UnityEngine.Networking;
@@ -30,7 +31,7 @@ void Start()
 
         parameterDisplayHint.AddListener(animateScrollParameter);
         CompletionsHintEvent.AddListener(animateCompletionsHint);
-        NewAssignmentEvent.AddListener(newAssignment);
+        NewAssignmentEvent.AddListener(newAssignmentTrigger);
     }
 
     public void setScroll(Scroll s)
@@ -61,33 +62,64 @@ public void setScroll(Scroll s)
         }
     }
 
-    public void magicButton()
+    public void magicButtonTrigger() {
+        StartCoroutine(magicButton());
+    }
+
+    IEnumerator magicButton()
     {
-        string answer = sendView("/scroll/apply");
-        
-        if (answer == null)
+        bool workDone = false;
+
+        while (!workDone)
         {
-            Debug.Log("DAS HAT NICHT GEKLAPPT");
-            //TODO: hier ne Art PopUp, wo drin steht, dass das nicht geklappt hat
-            PushoutFactFailEvent.Invoke(null);
-            return;
+            // 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;
         }
+    }
 
-        Scroll.ScrollApplicationInfo pushout = JsonConvert.DeserializeObject<Scroll.ScrollApplicationInfo>(answer);
-        readPushout(pushout.acquiredFacts);
+    public void newAssignmentTrigger() {
+        StartCoroutine(newAssignment());
     }
 
-    public void newAssignment()
+    IEnumerator newAssignment()
     {
-        string answer = sendView("/scroll/dynamic");
+        bool workDone = false;
 
-        if (answer == null)
+        while (!workDone)
         {
-            Debug.Log("DAS HAT NICHT GEKLAPPT");
-            return;
+            // 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;
         }
-        Scroll.ScrollDynamicInfo scrollDynamicInfo = JsonConvert.DeserializeObject<Scroll.ScrollDynamicInfo>(answer);
-        processScrollDynamicInfo(scrollDynamicInfo);
     }
 
     private string sendView(string endpoint)
-- 
GitLab