Skip to content
Snippets Groups Projects
Commit 10f9e5bc authored by John Schihada's avatar John Schihada
Browse files

Correctly adjusted Coroutine-workflow for newAssignments- and magicButton-Events

parent 4c7e5cf4
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,8 @@ public class ScrollDetails : MonoBehaviour ...@@ -19,6 +19,8 @@ public class ScrollDetails : MonoBehaviour
public static List<GameObject> ParameterDisplays; public static List<GameObject> ParameterDisplays;
private static List<Scroll.ScrollAssignment> LatestCompletions; private static List<Scroll.ScrollAssignment> LatestCompletions;
public string currentMmtAnswer;
public Vector3 GetPosition(int i) public Vector3 GetPosition(int i)
{ {
return new Vector3(x_Start, y_Start + i * (-y_Paece_Between_Items), 0f); return new Vector3(x_Start, y_Start + i * (-y_Paece_Between_Items), 0f);
...@@ -68,28 +70,19 @@ public void magicButtonTrigger() { ...@@ -68,28 +70,19 @@ public void magicButtonTrigger() {
IEnumerator magicButton() 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 Debug.Log("DAS HAT NICHT GEKLAPPT");
yield return null; //TODO: hier ne Art PopUp, wo drin steht, dass das nicht geklappt hat
PushoutFactFailEvent.Invoke(null);
string answer = sendView("/scroll/apply"); }
else
if (answer == null) {
{ Scroll.ScrollApplicationInfo pushout = JsonConvert.DeserializeObject<Scroll.ScrollApplicationInfo>(currentMmtAnswer);
Debug.Log("DAS HAT NICHT GEKLAPPT"); readPushout(pushout.acquiredFacts);
//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;
} }
} }
...@@ -99,30 +92,21 @@ public void newAssignmentTrigger() { ...@@ -99,30 +92,21 @@ public void newAssignmentTrigger() {
IEnumerator newAssignment() 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 Debug.Log("DAS HAT NICHT GEKLAPPT");
yield return null; }
else
string answer = sendView("/scroll/dynamic"); {
Scroll.ScrollDynamicInfo scrollDynamicInfo = JsonConvert.DeserializeObject<Scroll.ScrollDynamicInfo>(currentMmtAnswer);
if (answer == null) processScrollDynamicInfo(scrollDynamicInfo);
{
Debug.Log("DAS HAT NICHT GEKLAPPT");
}
else
{
Scroll.ScrollDynamicInfo scrollDynamicInfo = JsonConvert.DeserializeObject<Scroll.ScrollDynamicInfo>(answer);
processScrollDynamicInfo(scrollDynamicInfo);
}
workDone = true;
} }
} }
private string sendView(string endpoint) IEnumerator sendView(string endpoint)
{ {
string body = prepareScrollAssignments(); string body = prepareScrollAssignments();
...@@ -130,18 +114,21 @@ private string sendView(string endpoint) ...@@ -130,18 +114,21 @@ private string sendView(string endpoint)
www.method = UnityWebRequest.kHttpVerbPOST; www.method = UnityWebRequest.kHttpVerbPOST;
www.SetRequestHeader("Content-Type", "application/json"); www.SetRequestHeader("Content-Type", "application/json");
var async = www.Send(); 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) if (www.isNetworkError || www.isHttpError)
{ {
Debug.Log(www.error); Debug.Log(www.error);
return null; currentMmtAnswer = null;
} }
else else
{ {
string answer = www.downloadHandler.text; string answer = www.downloadHandler.text;
Debug.Log(answer); Debug.Log(answer);
return answer; currentMmtAnswer = answer;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment