Newer
Older
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Xml.Linq;
public class ScrollDetails : MonoBehaviour
{
public GameObject parameterDisplayPrefab;
public int x_Start;
public int y_Start;
public int y_Paece_Between_Items;
public static List<GameObject> ParameterDisplays;
static TextMeshProUGUI _scrollDescriptionField;
static string _scrollDescription;
public static string ScrollDescription
{
get { return _scrollDescription; }
set
{
_scrollDescription = value;
_scrollDescriptionField.text = value;
}
}
public string situationTheory = "http://BenniDoes.Stuff?SituationTheory";
return new Vector3(x_Start, y_Start + i * (-y_Paece_Between_Items), 0f);
// Start is called before the first frame update
void Start()
{
if (cursor == null) cursor = GameObject.FindObjectOfType<WorldCursor>();
_scrollDescriptionField = this.gameObject.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>();
}
// Update is called once per frame
void Update()
{
Transform scrollView = gameObject.transform.GetChild(2);
Transform viewport = scrollView.GetChild(0);
ParameterDisplays = new List<GameObject>();
Scroll.InitDynamicScroll(s.requiredFacts.Count);
for (int i = 0; i < s.requiredFacts.Count; i++)
var obj = Instantiate(parameterDisplayPrefab, Vector3.zero, Quaternion.identity, transform);
var scrollFact = obj.transform.GetChild(0).GetComponent<RenderedScrollFact>();
//obj.GetComponent<RectTransform>().localPosition = GetPosition(i);
scrollFact.Label = Scroll.ParseString(i,s.requiredFacts[i].label,s.requiredFacts);
//this is from benni, I dont know if the hack is the commented line below or the line above....
//TODO: Remvoe this reaaaaly bad hack
//scroll description
ScrollDescription = Scroll.ParseString(-1, s.description, s.requiredFacts);
Debug.Log("DAS HAT NICHT GEKLAPPT");
//TODO: hier ne Art PopUp, wo drin steht, dass das nicht geklappt hat
John Schihada
committed
CommunicationEvents.PushoutFactFailEvent.Invoke(null);
return;
}
string ret = pushout(view);
Debug.Log(ret);
{
List<Scroll.ScrollAssignment> assignments = new List<Scroll.ScrollAssignment>();
Scroll.FilledScroll scroll = new Scroll.FilledScroll(this.scroll, assignments);
string body = Scroll.ToJSON(scroll);
UnityWebRequest www = UnityWebRequest.Put(CommunicationEvents.ServerAdress+"/scroll/apply", body);
www.method = UnityWebRequest.kHttpVerbPOST;
www.SetRequestHeader("Content-Type", "application/json");
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 sendView()
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;
var drophandler = ParameterDisplays[i].GetComponentInChildren<DropHandling>();
if (decl_i.value != null && fact_i.backendValueURI != null)
{
jsonRequest = jsonRequest + @" """ + decl_i.value + @""":""" + fact_i.backendValueURI + @""",";
}
jsonRequest = jsonRequest + @" """ + decl_i.identifier + @""":""" + fact_i.backendURI + @""",";
}
//removing the last ','
jsonRequest = jsonRequest.Substring(0, jsonRequest.Length - 1);
jsonRequest = jsonRequest + "}}";
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;
}
}
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
private string sendView2()
{
Dictionary<Declaration, Fact[]> possibilities = new Dictionary<Declaration, Fact[]>();
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];
if (fact_i is DirectedFact)
{
possibilities.Add(decl_i, new Fact[] { fact_i, ((DirectedFact)fact_i).flippedFact });
}
else
{
possibilities.Add(decl_i, new Fact[] { fact_i });
}
}
Dictionary<Declaration, Fact> selection = new Dictionary<Declaration, Fact>();
for (int i = 0; i < possibilities.Count; i++)
{
Declaration decl_i = new List<Declaration>(possibilities.Keys)[i];
selection[decl_i] = possibilities[decl_i][0];
}
return testPossibilities(selection, possibilities, 0);
return "";
}
private string testPossibilities(Dictionary<Declaration, Fact> selection, Dictionary<Declaration, Fact[]> possibilities, int i)
{
if (i == possibilities.Count)
{
return testVariant(selection);
}
else
{
Declaration decl_i = new List<Declaration>(possibilities.Keys)[i];
for (int j = 0; j < possibilities[decl_i].Length; j++)
{
Fact fact_j = possibilities[decl_i][j];
selection.Remove(decl_i);
selection.Add(decl_i, fact_j);
string ret = testPossibilities(selection, possibilities, i + 1);
if (ret != FAIL) return ret;
}
}
return FAIL;
}
private string testVariant(Dictionary<Declaration, Fact> selection)
{
string jsonRequest = @"{";
jsonRequest = jsonRequest + @" ""from"":""" + this.scroll.problemTheory + @""", ";
jsonRequest = jsonRequest + @" ""to"":""" + this.situationTheory + @""", ";
jsonRequest = jsonRequest + @" ""mappings"": { ";
for (int i = 0; i < selection.Count; i++)
{
Declaration decl_i = new List<Declaration>(selection.Keys)[i];
Fact fact_i = selection[decl_i];
if (decl_i.value != null && fact_i.backendValueURI != null)
{
jsonRequest = jsonRequest + @" """ + decl_i.value + @""":""" + fact_i.backendValueURI + @""",";
}
jsonRequest = jsonRequest + @" """ + decl_i.identifier + @""":""" + fact_i.backendURI + @""",";
}
//removing the last ','
jsonRequest = jsonRequest.Substring(0, jsonRequest.Length - 1);
jsonRequest = jsonRequest + "}}";
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;
}
public string newSituation;
public PushoutFact[] outputs;
}
// generic class to make a common Supertype for all PushoutResponses
public string uri;
public string value;
public string a;
public string b;
public string c;
public string pointA;
public string pointB;
public string left;
public string middle;
public string right;
return a != null &&
b != null &&
c != null &&
pointA == null &&
pointB == null &&
value == null &&
left == null &&
middle == null &&
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
}
public bool isDistance()
{
return a == null &&
b == null &&
c == null &&
pointA != null &&
pointB != null &&
value != null &&
left == null &&
middle == null &&
right == null;
}
public bool isAngle()
{
return a == null &&
b == null &&
c == null &&
pointA == null &&
pointB == null &&
value != null &&
left != null &&
middle != null &&
right != null;
}
}
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
readPushout(answer);
return "true";
//return answer;
//TODO Parse Anwser from JSON TO FACTS...
}
PushoutReturn ret = JsonUtility.FromJson<PushoutReturn>(txt);
this.situationTheory = ret.newSituation;
FactManager factManager = cursor.GetComponent<FactManager>();
float a = float.Parse(f.a);
float b = float.Parse(f.b);
float c = float.Parse(f.c);
int id = factManager.GetFirstEmptyID();
PointFact pf = new PointFact(id, a, b, c, f.uri);
CommunicationEvents.Facts.Insert(id, pf);
CommunicationEvents.AddFactEvent.Invoke(pf);
CommunicationEvents.PushoutFactEvent.Invoke(pf);
int id = factManager.GetFirstEmptyID();
int pid1 = getIdforBackendURI(f.pointA);
int pid2 = getIdforBackendURI(f.pointB);
LineFact lf = new LineFact();//id, pid1, pid2, f.uri, f.value);
CommunicationEvents.Facts.Insert(id, lf);
CommunicationEvents.AddFactEvent.Invoke(lf);
CommunicationEvents.PushoutFactEvent.Invoke(lf);
int id = factManager.GetFirstEmptyID();
int pid1 = getIdforBackendURI(f.left);
int pid2 = getIdforBackendURI(f.middle);
int pid3 = getIdforBackendURI(f.right);
AngleFact af = new AngleFact();//id, pid1, pid2, pid3, f.uri, f.value);
CommunicationEvents.Facts.Insert(id, af);
CommunicationEvents.AddFactEvent.Invoke(af);
CommunicationEvents.PushoutFactEvent.Invoke(af);
return CommunicationEvents.Facts.Find(x => x.backendURI.Equals(uri)).Id;
}