From f50302c59c98715c546d3e977258aa1ba34cffb1 Mon Sep 17 00:00:00 2001
From: "Marco Zimmer (MaZiFAU)" <marco.alexander.zimmer@fau.de>
Date: Thu, 5 Aug 2021 15:12:39 +0200
Subject: [PATCH] BugFixes, Refactoring, +CommunicationEvents: added Verbose
 Setting for Debug.Log()

---
 .../NaturePackLite/Prefabs/Tree_01.prefab     |  2 +-
 Assets/Scenes/RiverWorld.unity                |  6 ++
 .../TaskCharakterAnimation.cs                 |  2 +-
 .../InteractionEngine/CommunicationEvents.cs  |  7 ++-
 Assets/Scripts/InteractionEngine/Fact.cs      | 63 +++++++++----------
 .../Scripts/InteractionEngine/FactComparer.cs |  2 +-
 .../InteractionEngine/FactOrganizer.cs        | 10 +--
 .../Scripts/InteractionEngine/FactSpawner.cs  |  3 +-
 .../Gadgets/GadgetManager.cs                  |  1 -
 .../Scripts/InteractionEngine/ShinyThings.cs  |  2 +-
 Assets/Scripts/Level.cs                       |  1 +
 Assets/Scripts/Restart.cs                     |  9 ++-
 Packages/manifest.json                        |  2 +-
 Packages/packages-lock.json                   |  2 +-
 14 files changed, 62 insertions(+), 50 deletions(-)

diff --git a/Assets/Plugins/NaturePackLite/Prefabs/Tree_01.prefab b/Assets/Plugins/NaturePackLite/Prefabs/Tree_01.prefab
index d63ec606..3b451c09 100644
--- a/Assets/Plugins/NaturePackLite/Prefabs/Tree_01.prefab
+++ b/Assets/Plugins/NaturePackLite/Prefabs/Tree_01.prefab
@@ -109,7 +109,7 @@ GameObject:
   - component: {fileID: 7455726115425455088}
   - component: {fileID: 933372636075482527}
   - component: {fileID: 539717056228735193}
-  m_Layer: 0
+  m_Layer: 16
   m_Name: TopSnapZone
   m_TagString: SnapZone
   m_Icon: {fileID: 0}
diff --git a/Assets/Scenes/RiverWorld.unity b/Assets/Scenes/RiverWorld.unity
index a44f2372..fb99d299 100644
--- a/Assets/Scenes/RiverWorld.unity
+++ b/Assets/Scenes/RiverWorld.unity
@@ -3544,6 +3544,7 @@ MonoBehaviour:
   ignoreLayerMask:
     serializedVersion: 2
     m_Bits: 96768
+  maxHeight: 2.5
   Cursor: {fileID: 1324548121420804703}
   lineRenderer: {fileID: 492903072}
   linePreviewMaterial: {fileID: 2100000, guid: a8a7bf60a30970f469a9c9d3ae2de6ef, type: 2}
@@ -59786,6 +59787,11 @@ PrefabInstance:
       propertyPath: m_AnchoredPosition.y
       value: 75
       objectReference: {fileID: 0}
+    - target: {fileID: 798194300259120277, guid: b996060e27da25c498842defc1996d84,
+        type: 3}
+      propertyPath: m_IsActive
+      value: 0
+      objectReference: {fileID: 0}
     - target: {fileID: 798194300310305303, guid: b996060e27da25c498842defc1996d84,
         type: 3}
       propertyPath: m_AnchoredPosition.x
diff --git a/Assets/Scripts/InteractionEngine/Character_Animations/TaskCharakterAnimation.cs b/Assets/Scripts/InteractionEngine/Character_Animations/TaskCharakterAnimation.cs
index 95100e22..f26c7097 100644
--- a/Assets/Scripts/InteractionEngine/Character_Animations/TaskCharakterAnimation.cs
+++ b/Assets/Scripts/InteractionEngine/Character_Animations/TaskCharakterAnimation.cs
@@ -75,7 +75,7 @@ void Update()
             if(taskCharacterAddressed && !LelvelVerifiedSolved && checkGameSolved())
             {
                 startHappy();
-                //LelvelVerifiedSolved = true;
+                LelvelVerifiedSolved = true;
             }
 
             return;
diff --git a/Assets/Scripts/InteractionEngine/CommunicationEvents.cs b/Assets/Scripts/InteractionEngine/CommunicationEvents.cs
index b114c501..2904c10b 100644
--- a/Assets/Scripts/InteractionEngine/CommunicationEvents.cs
+++ b/Assets/Scripts/InteractionEngine/CommunicationEvents.cs
@@ -48,12 +48,15 @@ public class AnimationEventWithUris : UnityEvent<List<string>> { }
     //------------------------------------------------------------------------------------
     //-------------------------------Global Variables-------------------------------------
 
-    //Global Level-List of Facts
+    // Global Level-List of Facts
     public static FactOrganizer LevelFacts = new FactOrganizer(true);
     public static FactOrganizer SolutionManager = new FactOrganizer(false);
-    //TODO? List<[HashSet<string>, FactComparer]>
+    //TODO? [SolutionManager, List<[HashSet<string>, FactComparer]>]
     public static List<Fact> Solution = new List<Fact>();
 
     public static bool ServerRunning = true;
     public static string ServerAdress = "localhost:8085";
+
+    // Configs
+    public static bool VerboseURI = false;
 }
diff --git a/Assets/Scripts/InteractionEngine/Fact.cs b/Assets/Scripts/InteractionEngine/Fact.cs
index f9481f17..8d691daf 100644
--- a/Assets/Scripts/InteractionEngine/Fact.cs
+++ b/Assets/Scripts/InteractionEngine/Fact.cs
@@ -6,6 +6,7 @@
 using static JSONManager;
 using static CommunicationEvents;
 
+
 public class ParsingDictionary {
 
     public static Dictionary<string, Func<Scroll.ScrollFact, Fact>> parseFactDictionary = new Dictionary<string, Func<Scroll.ScrollFact, Fact>>() {
@@ -27,14 +28,24 @@ public class AddFactResponse
     // public string factValUri;
     public string uri;
 
-    public static AddFactResponse sendAdd(string path, string body)
+    public static bool sendAdd(MMTDeclaration mmtDecl, out string uri)
+    {
+        string body = MMTSymbolDeclaration.ToJson(mmtDecl);
+        return sendAdd(CommunicationEvents.ServerAdress + "/fact/add", body, out uri);
+    }
+
+    public static bool sendAdd(string path, string body, out string uri)
     {
         if (!CommunicationEvents.ServerRunning)
         {
             Debug.LogWarning("Server not running");
-            return new AddFactResponse();
+            uri = null;
+            return false;
         }
-        Debug.Log(body);
+
+        if(VerboseURI)
+            Debug.Log("Sending to Server:\n" + body);
+
         //Put constructor parses stringbody to byteArray internally  (goofy workaround)
         UnityWebRequest www = UnityWebRequest.Put(path, body);
         www.method = UnityWebRequest.kHttpVerbPOST;
@@ -49,12 +60,19 @@ public static AddFactResponse sendAdd(string path, string body)
          || www.result == UnityWebRequest.Result.ProtocolError)
         {
             Debug.LogWarning(www.error);
-            return new AddFactResponse();
+            uri = null;
+            return false;
         }
         else
         {
             string answer = www.downloadHandler.text;
-            return JsonUtility.FromJson<AddFactResponse>(answer);
+            AddFactResponse res = JsonUtility.FromJson<AddFactResponse>(answer);
+
+            if (VerboseURI)
+                Debug.Log("Server added Fact:\n" + res.uri);
+
+            uri = res.uri;
+            return true;
         }
     }
 }
@@ -92,6 +110,8 @@ public void rename(string newLabel)
     public virtual void delete()
     {
         //TODO: MMT: delete over there
+        if (VerboseURI)
+            Debug.Log("Server removed Fact:\n" + this.URI);
     }
 
     public abstract bool Equivalent(Fact f2);
@@ -102,6 +122,7 @@ public virtual void delete()
 
     protected abstract string generateLabel(); 
 
+    // TODO: "ID"/ Letter Management
     protected string generateLetter()
     {
         return ((char)(64 + LabelId++ + 1)).ToString();
@@ -231,11 +252,7 @@ public PointFact(Vector3 P, Vector3 N, FactOrganizer organizer) : base(organizer
 
         //TODO: rework fact list + labeling
         MMTSymbolDeclaration mmtDecl = new MMTSymbolDeclaration(this.Label, tp, df);
-        string body = MMTSymbolDeclaration.ToJson(mmtDecl);
-
-        AddFactResponse res = AddFactResponse.sendAdd(CommunicationEvents.ServerAdress+"/fact/add", body);
-        this._URI = res.uri;
-        Debug.Log(this.URI);
+        AddFactResponse.sendAdd(mmtDecl, out this._URI);
     }
 
     public PointFact(float a, float b, float c, string uri, FactOrganizer organizer) : base(organizer)
@@ -327,10 +344,7 @@ public LineFact(string pid1, string pid2, FactOrganizer organizer) : base(pid1,
 
         //see point label
         MMTValueDeclaration mmtDecl = new MMTValueDeclaration(this.Label, lhs, valueTp, value);
-        string body = MMTDeclaration.ToJson(mmtDecl);
-        AddFactResponse res = AddFactResponse.sendAdd(CommunicationEvents.ServerAdress + "/fact/add", body);
-        this._URI = res.uri;
-        Debug.Log(this.URI);
+        AddFactResponse.sendAdd(mmtDecl, out this._URI);
     }
 
     public static LineFact parseFact(Scroll.ScrollFact fact)
@@ -407,11 +421,7 @@ public RayFact(string pid1, string pid2, FactOrganizer organizer) : base(pid1, p
 
         //TODO: rework fact list + labeling
         MMTSymbolDeclaration mmtDecl = new MMTSymbolDeclaration(this.Label, tp, df);
-        string body = MMTSymbolDeclaration.ToJson(mmtDecl);
-
-        AddFactResponse res = AddFactResponse.sendAdd(CommunicationEvents.ServerAdress + "/fact/add", body);
-        this._URI = res.uri;
-        Debug.Log(this.URI);
+        AddFactResponse.sendAdd(mmtDecl, out this._URI);
     }
 
     public static RayFact parseFact(Scroll.ScrollFact fact)
@@ -491,11 +501,7 @@ public OnLineFact(string pid, string rid, FactOrganizer organizer) : base(organi
 
         //TODO: rework fact list + labeling
         MMTSymbolDeclaration mmtDecl = new MMTSymbolDeclaration(this.Label, tp, df);
-        string body = MMTSymbolDeclaration.ToJson(mmtDecl);
-
-        AddFactResponse res = AddFactResponse.sendAdd(CommunicationEvents.ServerAdress + "/fact/add", body);
-        this._URI = res.uri;
-        Debug.Log(this.URI);
+        AddFactResponse.sendAdd(mmtDecl, out this._URI);
     }
 
     public OnLineFact(string pid, string rid, string uri, FactOrganizer organizer) : base(organizer)
@@ -591,14 +597,7 @@ public AngleFact(string pid1, string pid2, string pid3, FactOrganizer organizer)
         else
             mmtDecl = generateNot90DegreeAngleDeclaration(v, p1URI, p2URI, p3URI);
 
-        Debug.Log("angle: " + v);
-
-        string body = MMTDeclaration.ToJson(mmtDecl);
-
-        Debug.Log(body);
-        AddFactResponse res = AddFactResponse.sendAdd(CommunicationEvents.ServerAdress+"/fact/add", body);
-        this._URI = res.uri;
-        Debug.Log(this.URI);
+        AddFactResponse.sendAdd(mmtDecl, out this._URI);
     }
 
     public AngleFact(string Pid1, string Pid2, string Pid3, string backendURI, FactOrganizer organizer) : base(organizer)
diff --git a/Assets/Scripts/InteractionEngine/FactComparer.cs b/Assets/Scripts/InteractionEngine/FactComparer.cs
index 7259946f..414ba098 100644
--- a/Assets/Scripts/InteractionEngine/FactComparer.cs
+++ b/Assets/Scripts/InteractionEngine/FactComparer.cs
@@ -44,7 +44,7 @@ protected override bool Compare (Fact search, Fact fact)
     {
         return fact is LineFact && search is LineFact
             && Math3d.IsApproximatelyParallel(((LineFact) fact).Dir, ((LineFact) search).Dir)
-            && ((LineFact) fact).Distance > ((LineFact) search).Distance + Math3d.vectorPrecission;
+            && ((LineFact) fact).Distance + Math3d.vectorPrecission >= ((LineFact) search).Distance;
         // && Mathf.Approximately(((LineFact) x).Distance, ((LineFact) y).Distance);
     }
 }
diff --git a/Assets/Scripts/InteractionEngine/FactOrganizer.cs b/Assets/Scripts/InteractionEngine/FactOrganizer.cs
index dbe47e92..6e17f382 100644
--- a/Assets/Scripts/InteractionEngine/FactOrganizer.cs
+++ b/Assets/Scripts/InteractionEngine/FactOrganizer.cs
@@ -133,10 +133,10 @@ private void WorkflowAdd(stepnote note)
     private void PruneWorkflow()
     // set current (displayed) state in stone; resets un-redo parameters
     {
-        if (soft_resetted)
-            this.hardreset(false);
+        /*if (soft_resetted)
+            this.hardreset(false); // musn't clear
 
-        else if (backlog > 0)
+        else*/ if (backlog > 0)
         {
             worksteps -= backlog;
             backlog = 0;
@@ -424,10 +424,10 @@ private void InvokeFactEvent(bool creation, string Id)
                 CommunicationEvents.RemoveFactEvent.Invoke(this[Id]);
     }
 
-    public bool StaticlySovled(List<Fact> StaticSolution, out List<Fact> MissingElements)
+    public bool StaticlySovled(List<Fact> StaticSolution, out List<Fact> MissingElements, out List<Fact> Solutions)
     // QoL for simple Levels
     {
-        return DynamiclySolved(StaticSolution, out MissingElements, out _, new FactEquivalentsComparer());
+        return DynamiclySolved(StaticSolution, out MissingElements, out Solutions, new FactEquivalentsComparer());
     }
 
     //TODO: PERF: see CommunicationEvents.Solution
diff --git a/Assets/Scripts/InteractionEngine/FactSpawner.cs b/Assets/Scripts/InteractionEngine/FactSpawner.cs
index 0500cac8..7242dc98 100644
--- a/Assets/Scripts/InteractionEngine/FactSpawner.cs
+++ b/Assets/Scripts/InteractionEngine/FactSpawner.cs
@@ -122,7 +122,7 @@ public Fact SpawnRay(Fact fact)
         //Get the Line-GameObject as the first Child of the Line-Prefab -> That's the Collider
         var v3T = line.transform.GetChild(0).localScale;
         v3T.x = (point2 - point1).magnitude;
-        Debug.Log(v3T.x);
+
         //For every Coordinate x,y,z we have to devide it by the LocalScale of the Child,
         //because actually the Child should be of this length and not the parent, which is only the Collider
         v3T.x = v3T.x / line.transform.GetChild(0).GetChild(0).localScale.x;
@@ -197,7 +197,6 @@ public Fact SpawnAngle(Fact fact)
 
     public void DeleteObject(Fact fact)
     {
-        Debug.Log("delete obj of "+ fact.URI);
         GameObject factRepresentation = fact.Representation;
         GameObject.Destroy(factRepresentation);
     }
diff --git a/Assets/Scripts/InteractionEngine/Gadgets/GadgetManager.cs b/Assets/Scripts/InteractionEngine/Gadgets/GadgetManager.cs
index 9e8b43b9..3b85d12f 100644
--- a/Assets/Scripts/InteractionEngine/Gadgets/GadgetManager.cs
+++ b/Assets/Scripts/InteractionEngine/Gadgets/GadgetManager.cs
@@ -13,7 +13,6 @@ void Start()
         CommunicationEvents.ToolModeChangedEvent.AddListener(OnToolModeChanged);
         gadgets = GetComponentsInChildren<Gadget>();
 
-        Debug.Log(gadgets.Length);
         for (int i = 0; i < gadgets.Length; i++)
         {
             gadgets[i].id = i;
diff --git a/Assets/Scripts/InteractionEngine/ShinyThings.cs b/Assets/Scripts/InteractionEngine/ShinyThings.cs
index 0ff9960a..29efa1d7 100644
--- a/Assets/Scripts/InteractionEngine/ShinyThings.cs
+++ b/Assets/Scripts/InteractionEngine/ShinyThings.cs
@@ -276,7 +276,7 @@ public void CheckPushoutHighlighting() {
                     StopHighlighting();
                 }
                 //After this.timerDuration: Slow Down Fireworks
-                else
+                else if (this.extraHighlight != null)
                 {
                     ParticleSystem main1 = this.extraHighlight.transform.GetChild(0).GetComponent<ParticleSystem>();
                     ParticleSystem main2 = this.extraHighlight.transform.GetChild(1).GetComponent<ParticleSystem>();
diff --git a/Assets/Scripts/Level.cs b/Assets/Scripts/Level.cs
index 8832fabc..b68c87a6 100644
--- a/Assets/Scripts/Level.cs
+++ b/Assets/Scripts/Level.cs
@@ -15,6 +15,7 @@ public class Level : MonoBehaviour
     void Start()
     // Start is called before the first frame update
     {
+        // TODO: do not generate! -> load from somewhere
         PointFact
             buttom = new PointFact(Vector3.zero, Vector3.up, SolutionManager),
             top = new PointFact(Vector3.zero + Vector3.up * minimalSolutionHight, Vector3.up, SolutionManager);
diff --git a/Assets/Scripts/Restart.cs b/Assets/Scripts/Restart.cs
index 47e919b4..36df6d4c 100644
--- a/Assets/Scripts/Restart.cs
+++ b/Assets/Scripts/Restart.cs
@@ -6,8 +6,13 @@ public class Restart : MonoBehaviour
     public void LevelReset()
     {
         CommunicationEvents.LevelReset.Invoke(); // currently unused
-        Level.solved = false; // needed?
-        CommunicationEvents.LevelFacts.hardreset(false); // delete Facts at Server
+        Level.solved = false; // needed since static
+
+        // delete Facts at Server
+        CommunicationEvents.LevelFacts.hardreset(false);
+        // only when generated! (in Level.cs)
+        CommunicationEvents.SolutionManager.hardreset(false);
+
         SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex);
     }
 
diff --git a/Packages/manifest.json b/Packages/manifest.json
index 5aa00290..186d3a79 100644
--- a/Packages/manifest.json
+++ b/Packages/manifest.json
@@ -6,7 +6,7 @@
     "com.unity.analytics": "3.5.3",
     "com.unity.collab-proxy": "1.7.1",
     "com.unity.ide.rider": "2.0.7",
-    "com.unity.ide.visualstudio": "2.0.9",
+    "com.unity.ide.visualstudio": "2.0.11",
     "com.unity.ide.vscode": "1.2.3",
     "com.unity.multiplayer-hlapi": "1.0.8",
     "com.unity.nuget.newtonsoft-json": "2.0.0",
diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json
index e79090dd..99eb41fa 100644
--- a/Packages/packages-lock.json
+++ b/Packages/packages-lock.json
@@ -56,7 +56,7 @@
       "url": "https://packages.unity.com"
     },
     "com.unity.ide.visualstudio": {
-      "version": "2.0.9",
+      "version": "2.0.11",
       "depth": 0,
       "source": "registry",
       "dependencies": {
-- 
GitLab