diff --git a/Assets/InventoryStuff/DragHandling.cs b/Assets/InventoryStuff/DragHandling.cs index 09791e49bb9331751ce8cd50d407d52c2700a931..6c54e95a8bbb05db0e8f146bc463181031c4c8ea 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 690aa25f9600d9c5d005dc4086ef350c8e50082c..56ed5cc87df499fc3598b1218e771295e6f6f3f6 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 a74b4c0bd529f127ad74bc765fff4b449c926c68..8715316846c55549af90e78955a8ba589a5defd8 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... + } } }