From d30780b847f5b714f9326c942d13ba9a64f8ed3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=B6sl?= <benjamin.boesl@fau.de> Date: Thu, 30 Jan 2020 17:49:40 +0100 Subject: [PATCH] pushout works, todo Read them --- Assets/InventoryStuff/DragHandling.cs | 1 + Assets/InventoryStuff/DropHandling.cs | 6 +-- Assets/InventoryStuff/ScrollDetails.cs | 58 +++++++++++++++++++++----- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/Assets/InventoryStuff/DragHandling.cs b/Assets/InventoryStuff/DragHandling.cs index 09791e49..6c54e95a 100644 --- a/Assets/InventoryStuff/DragHandling.cs +++ b/Assets/InventoryStuff/DragHandling.cs @@ -14,6 +14,7 @@ public void OnDrag(PointerEventData eventData){ dragged = true; } transform.position = Input.mousePosition; + Debug.Log(gameObject.GetComponent<FactWrapper>().fact.backendURI); } public void OnEndDrag(PointerEventData eventData){ diff --git a/Assets/InventoryStuff/DropHandling.cs b/Assets/InventoryStuff/DropHandling.cs index 690aa25f..56ed5cc8 100644 --- a/Assets/InventoryStuff/DropHandling.cs +++ b/Assets/InventoryStuff/DropHandling.cs @@ -12,11 +12,11 @@ public void OnDrop(PointerEventData eventData){ Destroy(current); current = Instantiate(eventData.pointerDrag,Vector3.zero, Quaternion.identity); current.transform.SetParent(gameObject.transform, false); - GameObject scrollShow = gameObject.transform.parent.gameObject; //PythagorasScript pythagorasScript = scrollShow.GetComponent<PythagorasScript>(); - var fact = ((FactWrapper)current.GetComponent<FactWrapper>()).fact; - currentFact = fact; + currentFact = eventData.pointerDrag.GetComponent<FactWrapper>().fact; + Debug.Log("recieved Fact: " + currentFact.backendURI); //pythagorasScript.putFact(gameObject.name, fact); } } + \ No newline at end of file diff --git a/Assets/InventoryStuff/ScrollDetails.cs b/Assets/InventoryStuff/ScrollDetails.cs index a74b4c0b..87153168 100644 --- a/Assets/InventoryStuff/ScrollDetails.cs +++ b/Assets/InventoryStuff/ScrollDetails.cs @@ -54,11 +54,23 @@ public void setScroll(Scroll s) { } public void magicButton() { - sendView(); + string view = sendView(); + if (view.Equals(FAIL)) { + Debug.Log("DAS HAT NICHT GEKLAPPT"); + //TODO: hier ne Art PopUp, wo drin steht, dass das nicht geklappt hat + return; + } + string ret = pushout(view); + Debug.Log(ret); + } + string FAIL = "FAIL"; + class ViewResponse { + public string view; + } - private void sendView() { + private string sendView() { string jsonRequest = @"{"; jsonRequest = jsonRequest + @" ""from"":""" + this.scroll.problemTheory + @""", "; jsonRequest = jsonRequest + @" ""to"":""" + this.situationTheory + @""", "; @@ -68,9 +80,10 @@ private void sendView() { for (int i = 0; i < ParameterDisplays.Length; i++) { Fact fact_i = ParameterDisplays[i].GetComponentInChildren<DropHandling>().currentFact; + var drophandler = ParameterDisplays[i].GetComponentInChildren<DropHandling>(); Declaration decl_i = scroll.declarations[i]; jsonRequest = jsonRequest + @" """+decl_i.identifier +@""":""" + fact_i.backendURI + @""","; - if (decl_i.value != null && fact_i.backendValueURI != null) ; + if (decl_i.value != null && fact_i.backendValueURI != null) { jsonRequest = jsonRequest + @" """ + decl_i.value + @""":""" + fact_i.backendValueURI + @""","; } @@ -78,20 +91,45 @@ private void sendView() { //removing the last ',' jsonRequest = jsonRequest.Substring(0, jsonRequest.Length - 1); jsonRequest = jsonRequest + "}}"; - Debug.Log(jsonRequest); - /* - UnityWebRequest www = UnityWebRequest.Post("localhost:8081/view/add", jsonRequest); - yield return www.SendWebRequest(); + + UnityWebRequest www = UnityWebRequest.Put("localhost:8081/view/add", jsonRequest); + www.method = UnityWebRequest.kHttpVerbPOST; + var async = www.Send(); + while (!async.isDone) { } + + if (www.isNetworkError || www.isHttpError) + { + Debug.Log(www.error); + return FAIL; + } + else + { + string answer = www.downloadHandler.text; + return JsonUtility.FromJson<ViewResponse>(answer).view; + } + } + + + private string pushout(string view) { + string path = "localhost:8081/pushout?"; + path = path + "problem=" + this.scroll.problemTheory + "&"; + path = path + "solution=" + this.scroll.solutionTheory + "&"; + path = path + "view=" + view; + UnityWebRequest www = UnityWebRequest.Get(path); + var async = www.Send(); + while (!async.isDone) { } if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); //TODO: hier ne Art PopUp, wo drin steht, dass das nicht geklappt hat + return FAIL; } else { - Debug.Log("Form upload complete!"); - string viewUri = www.downloadHandler.text - } */ + string answer = www.downloadHandler.text; + return answer; + //TODO Parse Anwser from JSON TO FACTS... + } } } -- GitLab