Skip to content
Snippets Groups Projects
Commit d41dbe99 authored by scherlit's avatar scherlit
Browse files

receive/send script names and log values

parent 4e08fe51
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,8 @@ using System.IO;
using System.Linq;
using UnityEngine;
using System.Threading.Tasks;
using Newtonsoft.Json;
#if UNITY_EDITOR
using UnityEditor;
......@@ -278,7 +280,9 @@ namespace TeachR.ApplicationManager
/// <returns>The script info list as Json.</returns>
public string GetScriptInfoListAsJson()
{
return JsonUtility.ToJson(new { scripts = scriptInfoList }, true);
string json = JsonConvert.SerializeObject(scriptInfoList, Formatting.Indented);
Debug.Log($"[Data] Sending scriptInfoList JSON: {json}");
return json;
}
/// <summary>
......
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using UnityEngine;
......@@ -17,36 +18,42 @@ namespace TeachR.ApplicationManager
public string scriptName;
public string scriptAlias;
[SerializeField] private bool _logScript;
private bool _scriptAvailable;
public bool scriptAvailable
public bool logScript
{
get => _scriptAvailable;
get => _logScript;
set
{
if (_scriptAvailable != value)
if (_logScript != value)
{
_scriptAvailable = value;
_logScript = value;
OnLogScriptChanged?.Invoke(value, this);
OnParameterChanged?.Invoke(this);
}
}
}
public bool logScript
[SerializeField] private bool _scriptAvailable;
public bool scriptAvailable
{
get => _logScript;
get => _scriptAvailable;
set
{
if (_logScript != value)
if (_scriptAvailable != value)
{
_logScript = value;
OnLogScriptChanged?.Invoke(value, this);
_scriptAvailable = value;
OnParameterChanged?.Invoke(this);
}
}
}
public Action<bool, ScriptInfo> OnLogScriptChanged;
public Action<ScriptInfo> OnParameterChanged;
[JsonIgnore] public Action<bool, ScriptInfo> OnLogScriptChanged;
[JsonIgnore] public Action<ScriptInfo> OnParameterChanged;
public void SetLogValueByWebsite(bool value)
{
_logScript = value;
}
/// <summary>
/// Used to send the scriptInfo to website
......@@ -54,7 +61,7 @@ namespace TeachR.ApplicationManager
/// <returns>The script info as Json.</returns>
public string GetScriptInfoAsJson()
{
return JsonUtility.ToJson(new { scriptName = scriptName, scriptAlias = scriptAlias, logScript = logScript, scriptAvailable = scriptAvailable }, true);
return JsonConvert.SerializeObject(new { scriptAlias = this.scriptAlias, logScript = this.logScript });
}
}
}
......@@ -54,7 +54,8 @@ namespace TeachR.WebCommunication
WebsocketDelegateHooks.OnFixedUpdate += RunEventLoop;
RegisterFunctionCheckResultHandler(HandleFunctionCheckResult);
RegisterScriptInfoListRequestHandler(HandleScriptInfoListRequest);
RegisterScriptInfoListHandler(HandleScriptInfoListRequest);
RegisterDataCollectionHandler(HandleManageScriptInfo);
EventLogger.Instance.OnScriptInfoListChanged += HandleScriptInfoListEntryChanged;
return Task.CompletedTask;
......@@ -86,10 +87,14 @@ namespace TeachR.WebCommunication
Persistent.On("functionCheckResult", handler);
}
private static void RegisterScriptInfoListRequestHandler(Action<JsonMsg> handler)
private static void RegisterScriptInfoListHandler(Action<JsonMsg> handler)
{
Persistent.On("requestScriptInfoList", handler);
Debug.Log("requestScriptInfoList bereit zum Empfang");
}
private static void RegisterDataCollectionHandler(Action<JsonMsg> handler)
{
Persistent.On("manageScriptInfo", handler);
}
private static void HandleFunctionCheckResult(JsonMsg msg)
......@@ -99,9 +104,32 @@ namespace TeachR.WebCommunication
private static void HandleScriptInfoListRequest(JsonMsg msg)
{
Send("sendScriptInfoList", EventLogger.Instance.GetScriptInfoListAsJson());
var infoList = EventLogger.Instance.GetScriptInfoListAsJson();
Send("sendScriptInfoList", infoList);
EventLogger.Instance.AddEventListenerAfterConnection();
Debug.Log("HandleScriptInfoListRequest lst send aus");
}
private static void HandleManageScriptInfo(JsonMsg msg)
{
var data = msg.GetValue<Dictionary<string, object>>();
string scriptAlias = data["scriptAlias"].ToString();
bool logValue = Convert.ToBoolean(data["logValue"]);
foreach (var scriptInfo in EventLogger.Instance.scriptInfoList)
{
if (scriptInfo.scriptAlias == scriptAlias)
{
scriptInfo.SetLogValueByWebsite(logValue);
}
}
}
private static void HandleScriptInfoListEntryChanged(ScriptInfo scriptInfo)
{
var info = scriptInfo.GetScriptInfoAsJson();
Send("updateScriptInfoEntry", info);
Debug.Log($"[DATA] update script Info entry: {info}");
}
/// <summary>
......@@ -132,12 +160,6 @@ namespace TeachR.WebCommunication
}
}
private static void HandleScriptInfoListEntryChanged(ScriptInfo scriptInfo)
{
Send("sendScriptInfoList", scriptInfo.GetScriptInfoAsJson());
Debug.Log($"[DATA] send script Info entry: {scriptInfo.GetScriptInfoAsJson()}");
}
/// <summary>
/// Converts parameters into a valid message to send to the frontend. The messages are probably
/// sent from website-control\src\features\behaviourControls\behaviourGroups\BehaviourManagement\SendBehaviour.jsx .
......@@ -182,10 +204,10 @@ namespace TeachR.WebCommunication
{
Debug.Log($"[DEBUG] received speechtool parameters: {arg2}");
}
else if (arg1.Equals("requestScriptInfoList"))
{
Debug.Log($"[DEBUG] received requestScriptInfoList : {arg2}");
}
//else if (arg1.Equals("requestScriptInfoList"))
//{
// Debug.Log($"[DEBUG] received requestScriptInfoList : {arg2}");
//}
}
private static void RunEventLoop()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment