From d13292b8f27ed4813f544d16b89b71b1bcef9fdd Mon Sep 17 00:00:00 2001 From: unknown <john.schihada@hotmail.com> Date: Wed, 21 Oct 2020 17:29:35 +0200 Subject: [PATCH] Adjustments for fetching scrolls --- .../Scripts/InventoryStuff/DisplayScrolls.cs | 2 ++ Assets/Scripts/InventoryStuff/Scroll.cs | 35 +++++++++++++++---- Assets/Scripts/JSONManager.cs | 10 ++++-- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/InventoryStuff/DisplayScrolls.cs b/Assets/Scripts/InventoryStuff/DisplayScrolls.cs index 4a79a1b2..59deba49 100644 --- a/Assets/Scripts/InventoryStuff/DisplayScrolls.cs +++ b/Assets/Scripts/InventoryStuff/DisplayScrolls.cs @@ -57,6 +57,8 @@ void Start() IEnumerator getScrollsfromServer() { UnityWebRequest request = UnityWebRequest.Get(CommunicationEvents.ServerAdress + "/scroll/list"); + //Postman-Echo-Mock + //UnityWebRequest request = UnityWebRequest.Get("https://019a8ea5-843a-498b-8d0c-778669aef987.mock.pstmn.io/get"); request.method = UnityWebRequest.kHttpVerbGET; yield return request.Send(); if (request.isNetworkError || request.isHttpError) diff --git a/Assets/Scripts/InventoryStuff/Scroll.cs b/Assets/Scripts/InventoryStuff/Scroll.cs index cbbad972..c1e183d4 100644 --- a/Assets/Scripts/InventoryStuff/Scroll.cs +++ b/Assets/Scripts/InventoryStuff/Scroll.cs @@ -3,6 +3,8 @@ using System.Linq; using System; using UnityEngine; +using static JSONManager; +using Newtonsoft.Json; /* @@ -44,12 +46,18 @@ public class Scroll : LightScroll public static List<Scroll> FromJSON(string json) { - List<Scroll> scrolls = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scroll>>(json); + List<Scroll> scrolls = JsonConvert.DeserializeObject<List<Scroll>>(json, new JsonSerializerSettings + { + TypeNameHandling = TypeNameHandling.Auto + }); return scrolls; } public static string ToJSON(FilledScroll scroll) { - string json = Newtonsoft.Json.JsonConvert.SerializeObject(scroll); + string json = Newtonsoft.Json.JsonConvert.SerializeObject(scroll, new JsonSerializerSettings + { + TypeNameHandling = TypeNameHandling.Auto + }); return json; } @@ -129,15 +137,28 @@ public FilledScroll(LightScroll scroll, List<ScrollAssignment> assignments) public class ScrollFact { public string uri; + public string kind; public string label; - public FactBody tp; - public JSONManager.MMTTerm df; } - public class FactBody + /** + * Class used for deserializing incoming symbol-declarations from mmt + */ + public class ScrollSymbolFact : ScrollFact + { + public MMTTerm tp; + public MMTTerm df; + } + + /** + * Class used for deserializing incoming value-declarations from mmt + */ + public class ScrollValueFact : ScrollFact { - public JSONManager.MMTTerm original; - public JSONManager.MMTTerm simplified; + MMTTerm lhs; + MMTTerm valueTp; + MMTTerm value; + MMTTerm proof; } } diff --git a/Assets/Scripts/JSONManager.cs b/Assets/Scripts/JSONManager.cs index eda92fa6..1cae7a2b 100644 --- a/Assets/Scripts/JSONManager.cs +++ b/Assets/Scripts/JSONManager.cs @@ -94,7 +94,7 @@ public static string ToJson(MMTDeclaration mmtDecl) /** * MMTSymbolDeclaration: Class for facts without values, e.g. Points - **/ + */ public class MMTSymbolDeclaration : MMTDeclaration { public string kind = "general"; @@ -102,6 +102,9 @@ public class MMTSymbolDeclaration : MMTDeclaration public MMTTerm tp; public MMTTerm df; + /** + * Constructor used for sending new declarations to mmt + */ public MMTSymbolDeclaration(string label, MMTTerm tp, MMTTerm df) { this.label = label; @@ -112,7 +115,7 @@ public MMTSymbolDeclaration(string label, MMTTerm tp, MMTTerm df) /** * MMTValueDeclaration: Class for facts with values, e.g. Distances or Angles - **/ + */ public class MMTValueDeclaration : MMTDeclaration { public string kind = "veq"; @@ -121,6 +124,9 @@ public class MMTValueDeclaration : MMTDeclaration public MMTTerm valueTp; public MMTTerm value; + /** + * Constructor used for sending new declarations to mmt + */ public MMTValueDeclaration(string label, MMTTerm lhs, MMTTerm valueTp, MMTTerm value) { this.label = label; -- GitLab