From 0fff99bd3c83f50accaadeffcaa673511685e11f Mon Sep 17 00:00:00 2001 From: Richard Marcus <richard.marcus@fau.de> Date: Wed, 22 Jul 2020 17:54:35 +0200 Subject: [PATCH] fact creation now works without server --- Assets/InteractionEngine/CommunicationEvents.cs | 2 ++ Assets/InteractionEngine/Fact.cs | 12 +++++++++--- Assets/InventoryStuff/DisplayScrolls.cs | 3 ++- Assets/StartServer.cs | 6 +++--- Assets/TreeWorld_02.unity | 8 +++++++- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Assets/InteractionEngine/CommunicationEvents.cs b/Assets/InteractionEngine/CommunicationEvents.cs index ddd7481e..57aed277 100644 --- a/Assets/InteractionEngine/CommunicationEvents.cs +++ b/Assets/InteractionEngine/CommunicationEvents.cs @@ -74,4 +74,6 @@ public class SignalEvent : UnityEvent { //Global List of Facts public static List<Fact> Facts = new List<Fact>(); + + public static bool ServerRunning = false; } diff --git a/Assets/InteractionEngine/Fact.cs b/Assets/InteractionEngine/Fact.cs index 596ae179..0129cf82 100644 --- a/Assets/InteractionEngine/Fact.cs +++ b/Assets/InteractionEngine/Fact.cs @@ -27,18 +27,24 @@ public class AddFactResponse public static AddFactResponse sendAdd(string path, string body) { + if (!CommunicationEvents.ServerRunning) + { + Debug.LogWarning("Server not running"); + return new AddFactResponse(); + } Debug.Log(body); //Put constructor parses stringbody to byteArray internally (goofy workaround) UnityWebRequest www = UnityWebRequest.Put(path, body); www.method = UnityWebRequest.kHttpVerbPOST; www.SetRequestHeader("Content-Type", "application/json"); - + www.timeout = 1; + //TODO: implement real asynchronous communication ... AsyncOperation op = www.Send(); while (!op.isDone) { } if (www.isNetworkError || www.isHttpError) { - Debug.Log(www.error); - return null; + Debug.LogWarning(www.error); + return new AddFactResponse(); } else { diff --git a/Assets/InventoryStuff/DisplayScrolls.cs b/Assets/InventoryStuff/DisplayScrolls.cs index 29475db2..366a6210 100644 --- a/Assets/InventoryStuff/DisplayScrolls.cs +++ b/Assets/InventoryStuff/DisplayScrolls.cs @@ -60,10 +60,11 @@ IEnumerator getScrollsfromServer() { yield return request.Send(); if (request.isNetworkError || request.isHttpError) { - Debug.LogError(request.error); + Debug.LogWarning(request.error); } else { + CommunicationEvents.ServerRunning = true; string jsonString = request.downloadHandler.text; buildScrollSelection(jsonString); } diff --git a/Assets/StartServer.cs b/Assets/StartServer.cs index 2075ea48..2e7081d9 100644 --- a/Assets/StartServer.cs +++ b/Assets/StartServer.cs @@ -11,7 +11,7 @@ public class StartServer : MonoBehaviour [SerializeField] TMPro.TextMeshProUGUI WaitingText; - bool ServerRunning = false; + // Start is called before the first frame update void Start() { @@ -20,7 +20,7 @@ void Start() void PrepareGame() { WaitingText.text = "Press any key to start the game"; - ServerRunning= true; + CommunicationEvents.ServerRunning= true; UnityEngine.Debug.Log("server fin"); } @@ -181,7 +181,7 @@ IEnumerator ServerRoutine() // Update is called once per frame void Update() { - if(ServerRunning && Input.anyKey) + if(CommunicationEvents.ServerRunning && Input.anyKey) { SceneManager.LoadScene(1); } diff --git a/Assets/TreeWorld_02.unity b/Assets/TreeWorld_02.unity index beb5782a..52bd65ae 100644 --- a/Assets/TreeWorld_02.unity +++ b/Assets/TreeWorld_02.unity @@ -28366,7 +28366,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 38cd422d38f88564e81d012b615cc77a, type: 3} m_Name: m_EditorClassIdentifier: - ToolMode: 4 + id: 0 + UiName: Sprite: {fileID: 21300000, guid: d456617ba2282854d9570dcebcc2b279, type: 3} FactManager: {fileID: 0} ignoreLayerMask: @@ -40563,6 +40564,11 @@ PrefabInstance: propertyPath: ignoreLayerMask.m_Bits value: 31232 objectReference: {fileID: 0} + - target: {fileID: 729203331, guid: 2ba8d552442ba664e8e567adee683a11, type: 3} + propertyPath: Sprite + value: + objectReference: {fileID: 21300000, guid: 644edf8b3fa05da418500a0e9dd10820, + type: 3} - target: {fileID: 1085307962, guid: 2ba8d552442ba664e8e567adee683a11, type: 3} propertyPath: GadgetUI value: -- GitLab