From 992faafcd2215e8eb6a9af1a0994de71132c44f0 Mon Sep 17 00:00:00 2001
From: AevaMorigi <21962217+AevaMorigi@users.noreply.github.com>
Date: Wed, 12 Feb 2025 17:27:10 +0100
Subject: [PATCH] removed debug messages, fixed noiseValue processing

---
 .../EventLogger/Scripts/EventLogger.cs        |  1 -
 .../Runtime/Scripts/MenuDataHolder.cs         |  4 ---
 .../Runtime/Scripts/AmbientSound.cs           | 21 +++++++++-----
 .../Scripts/StructureTreeController.cs        |  7 +----
 .../Runtime/WholeClass/Scripts/ClassInfo.cs   |  4 ---
 .../Runtime/Scripts/CoachRtc.cs               | 28 +++++++++----------
 .../Runtime/Scripts/ControllerManager.cs      |  3 --
 7 files changed, 28 insertions(+), 40 deletions(-)

diff --git a/Packages/vr.teachr.applicationmanager/Runtime/EventLogger/Scripts/EventLogger.cs b/Packages/vr.teachr.applicationmanager/Runtime/EventLogger/Scripts/EventLogger.cs
index 2841f188e..115b795d2 100644
--- a/Packages/vr.teachr.applicationmanager/Runtime/EventLogger/Scripts/EventLogger.cs
+++ b/Packages/vr.teachr.applicationmanager/Runtime/EventLogger/Scripts/EventLogger.cs
@@ -279,7 +279,6 @@ namespace TeachR.ApplicationManager
         public string GetScriptInfoListAsJson()
         {
             string json = JsonConvert.SerializeObject(scriptInfoList, Formatting.Indented);
-            Debug.Log($"[Data] Sending scriptInfoList JSON: {json}");
             return json;
         }
 
diff --git a/Packages/vr.teachr.applicationmanager/Runtime/Scripts/MenuDataHolder.cs b/Packages/vr.teachr.applicationmanager/Runtime/Scripts/MenuDataHolder.cs
index f584802ce..92012f7f7 100644
--- a/Packages/vr.teachr.applicationmanager/Runtime/Scripts/MenuDataHolder.cs
+++ b/Packages/vr.teachr.applicationmanager/Runtime/Scripts/MenuDataHolder.cs
@@ -135,13 +135,11 @@ namespace TeachR.ApplicationManager
         [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
         private static void BeforeSceneLoad()
         {
-            Debug.Log($"[MenuDataHolder] BeforeSceneLoad");
             SceneController.OnDoneLoadScene += NewSceneLoaded;
         }
 
         private static void NewSceneLoaded(object sender, SceneControllerEventArgs sceneControllerEventArgs)
         {
-            Debug.Log($"[MenuDataHolder] NewSceneLoaded sender: {sender}");
             BuildScenes newScene = sceneControllerEventArgs.Scene;
             if (newScene == BuildScenes.PreviewRooms) return;
 
@@ -168,8 +166,6 @@ namespace TeachR.ApplicationManager
                 students = StudentCount
             };
             SetMeasures(classChange, newScene);
-
-            Debug.Log($"[MenuDataHolder] classChange students: {StudentCount}");
         }
 
         public static void SetMeasures(ClassChange room, BuildScenes chosenScene)
diff --git a/Packages/vr.teachr.atmosphere/Runtime/Scripts/AmbientSound.cs b/Packages/vr.teachr.atmosphere/Runtime/Scripts/AmbientSound.cs
index 35c2ff50c..ba4780a87 100644
--- a/Packages/vr.teachr.atmosphere/Runtime/Scripts/AmbientSound.cs
+++ b/Packages/vr.teachr.atmosphere/Runtime/Scripts/AmbientSound.cs
@@ -4,8 +4,6 @@ using UnityEngine;
 using UnityEngine.Assertions;
 using System.Threading.Tasks;
 using System;
-using System.Collections;
-using System.Linq;
 
 #if UNITY_EDITOR
 using UnityEditor;
@@ -87,7 +85,17 @@ namespace TeachR.Atmosphere
 
         public Task WebsocketInit()
         {
-            CoachRtc.Transient.On("changeNoiseLevel", json => SoundLevel(json.GetValue<int>()));
+            CoachRtc.Transient.On("changeNoiseLevel", json =>
+            {
+                var data = json.ToDict<int>();
+                if (data.ContainsKey("noiseLevel"))
+                {
+                    int noiseIndex = (int)data["noiseLevel"];
+                    SoundLevel(noiseIndex, true);
+                }
+                else
+                    Debug.LogError("Received changeNoiseLevel message without noiseLevel key!");
+            });
             return Task.CompletedTask;
         }
 
@@ -108,7 +116,7 @@ namespace TeachR.Atmosphere
             SoundLevel(ac.level);
         }
 
-        public void SoundLevel(int soundLevel)
+        public void SoundLevel(int soundLevel, bool setByWebsite = false)
         {
             Assert.IsTrue(soundLevel >= 0 && soundLevel <= NoiseLevels.Length);
 
@@ -117,7 +125,8 @@ namespace TeachR.Atmosphere
             source.volume = NoiseLevels[CurrentNoiseLevel];
             source.clip = ClassAmbient(CurrentNoiseLevel);
 
-            CoachRtc.Send("setVolumeByUnity", CurrentNoiseLevel); // ToDo: rename to setNoiseByUnity
+            if(!setByWebsite)
+                CoachRtc.Send("setNoiseByUnity", CurrentNoiseLevel);
             LogData($"{DateTime.Now.ToString(DateTimeFormat)};{source.clip?.name};{CurrentNoiseLevel}");
 
             // Only play a clip from the start if it was actually changed (avoid obvious cutoff/looping)
@@ -153,8 +162,6 @@ namespace TeachR.Atmosphere
             EditorGUILayout.LabelField("Change Noiselevel:");
 
             AmbientSound ambientSound = (AmbientSound)target;
-            //EditorGUILayout.LabelField($"CurrentNoiseLevel: {AmbientSound.CurrentNoiseLevel}");
-            //EditorGUILayout.LabelField($"current noiseLevel: {noiseLevel}");
 
             if (GUILayout.Button("louder"))
             {
diff --git a/Packages/vr.teachr.structuretree/Runtime/Scripts/StructureTreeController.cs b/Packages/vr.teachr.structuretree/Runtime/Scripts/StructureTreeController.cs
index 888e7daac..8e8842cf0 100644
--- a/Packages/vr.teachr.structuretree/Runtime/Scripts/StructureTreeController.cs
+++ b/Packages/vr.teachr.structuretree/Runtime/Scripts/StructureTreeController.cs
@@ -9,8 +9,6 @@ using TeachR.WebCommunication;
 using System.Threading.Tasks;
 using System.IO;
 
-
-
 #if UNITY_EDITOR
 using UnityEditor;
 #endif
@@ -49,7 +47,6 @@ namespace TeachR.StructureTree
             EventLoggingInit();
         }
 
-
         /// <summary>
         /// Clear all hooks.
         /// </summary>
@@ -59,7 +56,6 @@ namespace TeachR.StructureTree
             InitGlobals.WebsocketInitHook -= WebInit;
         }
 
-
         /// <summary>
         /// Prepare data collection.
         /// </summary>
@@ -69,7 +65,6 @@ namespace TeachR.StructureTree
                 $"{DateTime.Now.ToString(DateTimeFormat)};-;-;-;-");
         }
 
-
         /// <summary>
         /// Sets Poster and Lessondraft active.
         /// </summary>
@@ -221,4 +216,4 @@ namespace TeachR.StructureTree
         }
     }
 #endif
-}
+}
\ No newline at end of file
diff --git a/Packages/vr.teachr.students/Runtime/WholeClass/Scripts/ClassInfo.cs b/Packages/vr.teachr.students/Runtime/WholeClass/Scripts/ClassInfo.cs
index 86853f31a..cac56b348 100644
--- a/Packages/vr.teachr.students/Runtime/WholeClass/Scripts/ClassInfo.cs
+++ b/Packages/vr.teachr.students/Runtime/WholeClass/Scripts/ClassInfo.cs
@@ -22,7 +22,6 @@ namespace TeachR.Student {
         // ReSharper disable Unity.PerformanceAnalysis (rarely called)
         private static BootstrapData FromClass()
         {
-            Debug.Log("BootstrapData FromClass()");
             System.Collections.Generic.List<StudentDataClass> res = Object.FindObjectsByType<StudentController>(
                     FindObjectsInactive.Exclude, FindObjectsSortMode.None)
                 .Select(s => new StudentDataClass(s)).ToList();
@@ -35,11 +34,8 @@ namespace TeachR.Student {
                 femaleQuestions = SoundLoader.FemaleQuestionClips,
                 scene = SceneController.LastLoadedScene.ToString(),
                 weather = "sunny",
-                //behaviors = disturbanceManager?.Disturbances
             };
 
-            Debug.Log($"bootstrap: noise: {request.noiseLevel}, studentData: {request.students.Count}");
-
             return request;
         }
     }
diff --git a/Packages/vr.teachr.webcommunication/Runtime/Scripts/CoachRtc.cs b/Packages/vr.teachr.webcommunication/Runtime/Scripts/CoachRtc.cs
index 0400803c8..4d0c71901 100644
--- a/Packages/vr.teachr.webcommunication/Runtime/Scripts/CoachRtc.cs
+++ b/Packages/vr.teachr.webcommunication/Runtime/Scripts/CoachRtc.cs
@@ -1,3 +1,4 @@
+using Newtonsoft.Json.Linq;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -5,7 +6,6 @@ using System.Net;
 using System.Threading.Tasks;
 using TeachR.ApplicationManager;
 using UnityEngine;
-using UnityEngine.Events;
 
 namespace TeachR.WebCommunication
 {
@@ -25,10 +25,6 @@ namespace TeachR.WebCommunication
         private static readonly List<Msg> InboundStack = new();
 
         public static bool Active { get; private set; }
-        //private static UnityEvent configurationEvent;
-        //private static UnityEvent speechtoolEvent;
-        public static Action<List<ScriptInfo>> OnScriptInfoListChanged;
-
 
         /// <summary>
         /// Listener for transient events, i.e. events that are specific to a current scene and that are reset after
@@ -62,13 +58,13 @@ namespace TeachR.WebCommunication
         }
 
         /// <summary>
-        /// This function is used to query from Unity whether the web app provides certain functions.
+        /// This function is used to request from Unity whether the web app provides certain functions.
         /// </summary>
         private static void CheckFunctionAvailability()
         {
             List<string> functionsToCheck = new List<string> {
                 "behave",
-                "behavesfdsfdsfsfdsfd",
+                "behavesfdsfdsfsfdsfd", // test-value, expected to be false
                 "bootstrap",
                 "disturbanceScores",
                 "highlight",
@@ -104,7 +100,7 @@ namespace TeachR.WebCommunication
 
         private static void HandleFunctionCheckResult(JsonMsg msg)
         {
-            Debug.Log($"[Debug] Function check result received: {msg.content} DoTo: Do something with this information");
+            Debug.Log($"[Debug] Function check result received. DoTo: Do something with this information. Data: {msg.content}");
         }
 
         private static void HandleScriptInfoListRequest(JsonMsg msg)
@@ -203,18 +199,20 @@ namespace TeachR.WebCommunication
         private static void HandleMessage(string arg1, string arg2)
         {
             InboundStack.Add(new Msg { type = arg1, payload = arg2 });
-            Debug.Log($"[DEBUG] handle incomming message: {arg1} payload: {arg2}");
+            //Debug.Log($"[DEBUG] handle incomming message: {arg1} payload: {arg2}");
             if (arg1.Equals("configurationParameters"))
             {
-                Debug.Log($"[CONFIG] received configuration parameters: {arg2} type: {arg2.GetType()}");
-                MenuDataHolder.StudentCount = 4;
-                MenuDataHolder.IsPresentation = false;
-                MenuDataHolder.LevelOfMisbehavior = 2;
-                MenuDataHolder.IsAutomaticIntervention = false;
+                Debug.Log($"[ToDo] handle incomming message: {arg1} payload: {arg2}. These parameters currently have no effect.");
+                var json = JObject.Parse(arg2);
+                MenuDataHolder.StudentCount = (int)json["numStudents"];
+                MenuDataHolder.LevelOfMisbehavior = (int)json["disorderLevel"];
+                MenuDataHolder.IsPresentation = ((string)json["startingSituation"]).Equals("seatwork");
+                MenuDataHolder.IsAutomaticIntervention = !((string)json["interventionControl"]).Equals("manually");
             }
             else if (arg1.Equals("speechtoolParameters"))
             {
-                Debug.Log($"[DEBUG] received speechtool parameters: {arg2}");
+                Debug.Log($"[ToDo] received speechtool parameters: {arg2}. This parameter currently has no effect.");
+                // ToDo: Use parameter (enableSpeechtools [bool])
             }
         }
 
diff --git a/Packages/vr.teachr.webcommunication/Runtime/Scripts/ControllerManager.cs b/Packages/vr.teachr.webcommunication/Runtime/Scripts/ControllerManager.cs
index fc09e99e1..9434e792d 100644
--- a/Packages/vr.teachr.webcommunication/Runtime/Scripts/ControllerManager.cs
+++ b/Packages/vr.teachr.webcommunication/Runtime/Scripts/ControllerManager.cs
@@ -52,8 +52,6 @@ namespace TeachR.WebCommunication
 
         private void RegisterAvailableControllersHandler(Action<JsonMsg> handler)
         {
-            //website can send "askForControllerAvailability"
-            Debug.Log($"Website asks for controllers");
             CoachRtc.Persistent.On("askForControllerAvailability", handler);
         }
 
@@ -69,7 +67,6 @@ namespace TeachR.WebCommunication
                     available = controller.available
                 })
             };
-            Debug.Log($"SendControllerStatus() {controllerGameObjects.ToArray()}");
             CoachRtc.Send("receiveControllerAvailability", payload);
         }
 
-- 
GitLab