diff --git a/Assets/FactManager.cs b/Assets/FactManager.cs index 719db5d0b95ad38fd3b297709d582cc11cc342fb..937432b761122034b2fce273d3a9d88440dba13c 100644 --- a/Assets/FactManager.cs +++ b/Assets/FactManager.cs @@ -41,39 +41,20 @@ void Update() PointFact AddPointFact(RaycastHit hit, int id) { - - Facts.Insert(id, new PointFact - { - - Id = id, - Point = hit.point, - Normal = hit.normal - }); - + Facts.Insert(id, new PointFact(id, hit.point, hit.normal)); return Facts.Find(x => x.Id == id) as PointFact; } LineFact AddLineFact(int pid1, int pid2, int id) { - Facts.Insert(id, new LineFact - { - Id = id, - Pid1 = pid1, - Pid2 = pid2 - }); + Facts.Insert(id, new LineFact(id,pid1,pid2)); return Facts.Find(x => x.Id == id) as LineFact; } AngleFact AddAngleFact(int pid1, int pid2, int pid3, int id) { - Facts.Insert(id, new AngleFact - { - Id = id, - Pid1 = pid1, - Pid2 = pid2, - Pid3 = pid3 - }); + Facts.Insert(id, new AngleFact(id,pid1,pid2,pid3)); return Facts.Find(x => x.Id == id) as AngleFact; } diff --git a/Assets/InteractionEngine/Fact.cs b/Assets/InteractionEngine/Fact.cs index b363c89c8c6ee7a79906c1ea45a1abf802ce51ef..640fbd094c49d47d74ade6f2964205e93f1e8068 100644 --- a/Assets/InteractionEngine/Fact.cs +++ b/Assets/InteractionEngine/Fact.cs @@ -1,31 +1,119 @@ using UnityEngine; +using UnityEngine.Networking; public abstract class Fact { public int Id; public GameObject Representation; + public string backendURI; + public string backendValueURI; // supposed to be null, for Facts without values eg. Points, OpenLines, OnLineFacts... +} + +public class AddFactResponse +{ + public string factUri; + public string factValUri; + public static AddFactResponse sendAdd(string path, string body) { + Debug.Log(body); + //Put constructor parses stringbody to byteArray internally (goofy workaround) + UnityWebRequest www = UnityWebRequest.Put(path, body); + www.method = UnityWebRequest.kHttpVerbPOST; + www.SetRequestHeader("Content-Type", "application/json"); + + AsyncOperation op = www.Send(); + while (!op.isDone) { } + if (www.isNetworkError || www.isHttpError) + { + Debug.Log(www.error); + return null; + } + else + { + string answer = www.downloadHandler.text; + return JsonUtility.FromJson<AddFactResponse>(answer); + } + } } //I am not sure if we ever need to attach these to an object, so one script for all for now... public class PointFact : Fact { public Vector3 Point; public Vector3 Normal; + + public PointFact(int i,Vector3 P, Vector3 N) { + this.Id = i; + this.Point = P; + this.Normal = N; + + string body = @"{ ""a"":" +P.x + @"," + @"""b"":" +P.y + @","+@"""c"":" + P.z + "}"; + AddFactResponse res = AddFactResponse.sendAdd("localhost:8081/fact/add/vector", body); + this.backendURI = res.factUri; + + } +} + +public class OpenLineFact : Fact +{ + //an infinite Line through the Points Pid1 and Pid2 + public int Pid1, Pid2; } public class LineFact : Fact { //Id's of the 2 Point-Facts that are connected public int Pid1, Pid2; + + //only for temporary Use of LineFacts. + public LineFact() { } + + public LineFact(int i, int pid1, int pid2) { + this.Id = i; + this.Pid1 = pid1; + this.Pid2 = pid2; + PointFact pf1 = CommunicationEvents.Facts.Find((x => x.Id == pid1)) as PointFact; + PointFact pf2 = CommunicationEvents.Facts.Find((x => x.Id == pid2)) as PointFact; + string p1URI = pf1.backendURI; + string p2URI = pf2.backendURI; + double v = (pf1.Point - pf2.Point).magnitude; + string body = @"{ ""pointA"":""" + p1URI + @"""," + @"""pointB"":""" + p2URI + @"""," + @"""value"":" + v + "}"; + AddFactResponse res = AddFactResponse.sendAdd("localhost:8081/fact/add/distance", body); + this.backendURI = res.factUri; + this.backendValueURI = res.factValUri; + } + } public class AngleFact : Fact { //Id's of the 3 Point-Facts, where Pid2 is the point, where the angle is public int Pid1, Pid2, Pid3; + + //only for temporary Use of AngleFacts + public AngleFact() { } + + public AngleFact(int i, int pid1, int pid2, int pid3) { + this.Id = i; + this.Pid1 = pid1; + this.Pid2 = pid2; + this.Pid3 = pid3; + PointFact pf1 = CommunicationEvents.Facts.Find((x => x.Id == pid1)) as PointFact; + PointFact pf2 = CommunicationEvents.Facts.Find((x => x.Id == pid2)) as PointFact; + PointFact pf3 = CommunicationEvents.Facts.Find((x => x.Id == pid3)) as PointFact; + double v = Vector3.Angle((pf1.Point - pf2.Point), (pf1.Point - pf2.Point)); + string body = @"{" + + @"""left"":""" + pf1.backendURI + @"""," + + @"""middle"":""" + pf2.backendURI + @""","+ + @"""right"":""" + pf3.backendURI + @""","+ + @"""value"":" + v + + "}"; + AddFactResponse res = AddFactResponse.sendAdd("localhost:8081/fact/add/angle", body); + this.backendURI = res.factUri; + this.backendValueURI = res.factValUri; + } } public class OnLineFact : Fact { - //Id's of the 3 Point-Facs that are on one line - public int Pid1, Pid2, Pid3; + //Id's of the Point , and the Id of the Line it sits on + public int Pid1, Lid2; } diff --git a/Assets/InteractionEngine/ShinyThings.cs b/Assets/InteractionEngine/ShinyThings.cs index 909c0fb41c2f8fcc60ba756d414e8d9ad7ec66da..c5afaf29cb601083f502e04c43fe190b0b149830 100644 --- a/Assets/InteractionEngine/ShinyThings.cs +++ b/Assets/InteractionEngine/ShinyThings.cs @@ -53,7 +53,7 @@ public void Update() //@John before: hit.point - Debug.Log(this.transform.position); + //Debug.Log(this.transform.position); if (this.lineDrawingActivated) UpdateLineDrawing(this.transform.position); diff --git a/Assets/InteractionEngine/WorldCursor.cs b/Assets/InteractionEngine/WorldCursor.cs index 022cf569843afb6311e37cc685375164fcce8c4c..7fe202fc989e5e8d36d49eb03bded0079a0900b7 100644 --- a/Assets/InteractionEngine/WorldCursor.cs +++ b/Assets/InteractionEngine/WorldCursor.cs @@ -34,7 +34,7 @@ void Update() if(Physics.Raycast(ray, out Hit, 30f, layerMask)){ - Debug.Log(Hit.transform.tag); + // Debug.Log(Hit.transform.tag); if (Hit.collider.transform.CompareTag("SnapZone")) { Hit.point = Hit.collider.transform.position; diff --git a/Assets/InventoryStuff/DisplayScrolls.cs b/Assets/InventoryStuff/DisplayScrolls.cs index 7a13742d6d1289d2daf3a661650194fb05ddb6fe..c2a58a7a418f9325731599edf087ebe5b89f55c9 100644 --- a/Assets/InventoryStuff/DisplayScrolls.cs +++ b/Assets/InventoryStuff/DisplayScrolls.cs @@ -9,6 +9,7 @@ public class DisplayScrolls : MonoBehaviour { public Scroll[] scrolls; + public GameObject[] ScrollButtons; public GameObject ScrollPrefab; public GameObject DetailScreen; @@ -24,23 +25,10 @@ public class DisplayScrolls : MonoBehaviour // Update is called once per frame void Update() { - // UpdateDisplay(); - } - public void UpdateDisplay() - { - /* for( int i = 0; i< inventory.Scrolls.Count; i++){ - if(! inventory.Scrolls[i].isDisplayed){ - var item = inventory.Scrolls[i].item; - var obj = Instantiate(item.IconPrefab, Vector3.zero, Quaternion.identity, transform); - obj.GetComponent<RectTransform>().localPosition = GetPosition(i); - inventory.Scrolls[i].isDisplayed = true; - } - - } - */ } + public Vector3 GetPosition(int i) { return new Vector3(x_Start+ (X_Pacece_Between_Items * (i % number_of_Column)), y_Start + (-y_Pacece_Between_Items * (i / number_of_Column)), 0f); @@ -84,16 +72,20 @@ void buildScrollSelection(string jsonString) { ScrollArrayWrapper scrollsRead = new ScrollArrayWrapper(); scrollsRead = (ScrollArrayWrapper)JsonUtility.FromJson(jsonString, scrollsRead.GetType()); this.scrolls = scrollsRead.Scrolls; - + ScrollButtons = new GameObject[this.scrolls.Length]; //Build Selection-GUI of Scrolls for (int i = 0; i < this.scrolls.Length; i++) { + var obj = Instantiate(ScrollPrefab, Vector3.zero, Quaternion.identity, transform); obj.GetComponent<RectTransform>().localPosition = GetPosition(i); obj.GetComponent<ScrollClickedScript>().scroll = this.scrolls[i]; obj.GetComponent<ScrollClickedScript>().DetailScreen = this.DetailScreen; obj.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>().text = this.scrolls[i].label; + ScrollButtons[i] = obj; } + this.DetailScreen.GetComponent<ScrollDetails>().setScroll(this.scrolls[0]); + } } diff --git a/Assets/InventoryStuff/ScrollDetails.cs b/Assets/InventoryStuff/ScrollDetails.cs index 3e8d369a95d6cc1cb0a6c3a352461be7a8424f07..a74b4c0bd529f127ad74bc765fff4b449c926c68 100644 --- a/Assets/InventoryStuff/ScrollDetails.cs +++ b/Assets/InventoryStuff/ScrollDetails.cs @@ -2,11 +2,12 @@ using System.Collections.Generic; using UnityEngine; using TMPro; +using UnityEngine.Networking; public class ScrollDetails : MonoBehaviour { - public GameObject ParameterDisplayPrefab; + public GameObject parameterDisplayPrefab; public Scroll scroll; public int x_Start; @@ -15,6 +16,8 @@ public class ScrollDetails : MonoBehaviour public GameObject[] ParameterDisplays; + public string situationTheory = "http://BenniDoes.Stuff?SituationTheory"; + public Vector3 GetPosition(int i) { return new Vector3(x_Start, y_Start + i * (-y_Paece_Between_Items ), 0f); @@ -41,7 +44,7 @@ public void setScroll(Scroll s) { } this.ParameterDisplays = new GameObject[s.declarations.Length]; for (int i = 0; i < s.declarations.Length; i++) { - var obj = Instantiate(ParameterDisplayPrefab, Vector3.zero, Quaternion.identity, transform); + var obj = Instantiate(parameterDisplayPrefab, Vector3.zero, Quaternion.identity, transform); obj.GetComponent<RectTransform>().localPosition = GetPosition(i); obj.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>().text = s.declarations[i].description; obj.transform.SetParent(viewport); @@ -51,9 +54,44 @@ public void setScroll(Scroll s) { } public void magicButton() { - for (int i = 0; i < ParameterDisplays.Length; i++) { - Fact facti = ParameterDisplays[i].GetComponent<DropHandling>().currentFact; + sendView(); + } + + + private void sendView() { + string jsonRequest = @"{"; + jsonRequest = jsonRequest + @" ""from"":""" + this.scroll.problemTheory + @""", "; + jsonRequest = jsonRequest + @" ""to"":""" + this.situationTheory + @""", "; + jsonRequest = jsonRequest + @" ""mappings"": { "; + + + for (int i = 0; i < ParameterDisplays.Length; i++) + { + Fact fact_i = ParameterDisplays[i].GetComponentInChildren<DropHandling>().currentFact; Declaration decl_i = scroll.declarations[i]; + jsonRequest = jsonRequest + @" """+decl_i.identifier +@""":""" + fact_i.backendURI + @""","; + if (decl_i.value != null && fact_i.backendValueURI != null) ; + { + jsonRequest = jsonRequest + @" """ + decl_i.value + @""":""" + fact_i.backendValueURI + @""","; + } + } + //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(); + + if (www.isNetworkError || www.isHttpError) + { + Debug.Log(www.error); + //TODO: hier ne Art PopUp, wo drin steht, dass das nicht geklappt hat } + else + { + Debug.Log("Form upload complete!"); + string viewUri = www.downloadHandler.text + } */ } } diff --git a/Assets/TreeWorld.unity b/Assets/TreeWorld.unity index 721d54aae1196ec8a2d14719167c6ba0f6a31077..0eb277496490ca12d3afe07ece2dc374c9c976b2 100644 --- a/Assets/TreeWorld.unity +++ b/Assets/TreeWorld.unity @@ -1900,7 +1900,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: -125, y: -30} + m_AnchoredPosition: {x: -437.34998, y: -30} m_SizeDelta: {x: 250, y: 60} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1143784615 @@ -1990,8 +1990,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 0} - m_AnchoredPosition: {x: 0, y: 44} - m_SizeDelta: {x: 0, y: 1000} + m_AnchoredPosition: {x: 100.4, y: 78.5} + m_SizeDelta: {x: -825.5, y: 1046.5} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1351049952 MonoBehaviour: diff --git a/Assets/inventoryStuff.unity b/Assets/inventoryStuff.unity index 87c686aef3cee16645e69a0172065da8f07c676c..bda56a9e67238ffc9704db6ef3b669580ecfdaa7 100644 --- a/Assets/inventoryStuff.unity +++ b/Assets/inventoryStuff.unity @@ -264,6 +264,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: scrolls: [] + ScrollButtons: [] ScrollPrefab: {fileID: 3173330253721512196, guid: a6a9a3ebdb022e546a21d9f9ff148261, type: 3} DetailScreen: {fileID: 6421936590152144003} @@ -736,7 +737,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 92f58ba8e8c7bf243bfde7e6656c9064, type: 3} m_Name: m_EditorClassIdentifier: - ParameterDisplayPrefab: {fileID: 8358525157842135574, guid: 0651df442e07acf439dd439c86c20e93, + parameterDisplayPrefab: {fileID: 8358525157842135574, guid: 0651df442e07acf439dd439c86c20e93, type: 3} scroll: problemTheory: @@ -746,8 +747,9 @@ MonoBehaviour: declarations: [] x_Start: 0 y_Start: 65 - y_Paece_Between_Items: 115 + y_Paece_Between_Items: 120 ParameterDisplays: [] + situationTheory: http://BenniDoes.Stuff?SituationTheory --- !u!1 &2070523361 GameObject: m_ObjectHideFlags: 0 @@ -910,7 +912,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: 0.000030517578} + m_AnchoredPosition: {x: 0, y: 0.0001373291} m_SizeDelta: {x: -17, y: 0} m_Pivot: {x: 0, y: 1} --- !u!114 &2421006697587610782 @@ -1204,8 +1206,8 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: - - m_Target: {fileID: 0} - m_MethodName: doMagic + - m_Target: {fileID: 1891786657} + m_MethodName: magicButton m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0}