From 5a06a7bdeb87dd8a49c8582ca53f650170ea5d7b Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sat, 12 Oct 2024 00:32:38 +0200 Subject: [PATCH 01/98] Receive messages --- Runtime.meta | 8 + Runtime/BcpInterface.cs | 37 +++++ Runtime/BcpInterface.cs.meta | 11 ++ Runtime/BcpServer.cs | 150 ++++++++++++++++++ Runtime/BcpServer.cs.meta | 11 ++ .../FutureBoxSystems.MpfUnityBcpServer.asmdef | 3 + ...reBoxSystems.MpfUnityBcpServer.asmdef.meta | 7 + package.json | 7 + package.json.meta | 7 + 9 files changed, 241 insertions(+) create mode 100644 Runtime.meta create mode 100644 Runtime/BcpInterface.cs create mode 100644 Runtime/BcpInterface.cs.meta create mode 100644 Runtime/BcpServer.cs create mode 100644 Runtime/BcpServer.cs.meta create mode 100644 Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef create mode 100644 Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef.meta create mode 100644 package.json create mode 100644 package.json.meta diff --git a/Runtime.meta b/Runtime.meta new file mode 100644 index 00000000..71525e80 --- /dev/null +++ b/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5a704d73c7dd35e4fa4f8c2dabd660b3 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/BcpInterface.cs b/Runtime/BcpInterface.cs new file mode 100644 index 00000000..eff0daba --- /dev/null +++ b/Runtime/BcpInterface.cs @@ -0,0 +1,37 @@ +using UnityEngine; + +namespace MpfBcpServer +{ + public class BcpInterface : MonoBehaviour + { + public ConnectionState state; + [SerializeField] + private int port = 5050; + + private BcpServer server; + + private void OnEnable() + { + server ??= new BcpServer(); + server.StateChanged += Server_StateChanged; + server.OpenConnection(port); + } + + private void Server_StateChanged(object sender, ConnectionStateChangedEventArgs e) + { + state = e.CurrentState; + } + + private void Update() + { + if (server.TryDequeueMessage(out var message)) + Debug.Log(message); + } + + private async void OnDisable() + { + await server.CloseConnectionAsync(); + server.StateChanged -= Server_StateChanged; + } + } +} \ No newline at end of file diff --git a/Runtime/BcpInterface.cs.meta b/Runtime/BcpInterface.cs.meta new file mode 100644 index 00000000..324988eb --- /dev/null +++ b/Runtime/BcpInterface.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 51b9336ad819de34399a83bd1df10416 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/BcpServer.cs b/Runtime/BcpServer.cs new file mode 100644 index 00000000..8b5d5be5 --- /dev/null +++ b/Runtime/BcpServer.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Unity.Profiling.Editor; + +namespace MpfBcpServer +{ + public class ConnectionStateChangedEventArgs : EventArgs + { + public ConnectionStateChangedEventArgs(ConnectionState current, ConnectionState previous) + { + CurrentState = current; + PreviousState = previous; + } + + public ConnectionState CurrentState { get; private set; } + public ConnectionState PreviousState { get; private set; } + } + + public enum ConnectionState { NotConnected, Connecting, Connected, Disconnecting }; + public class BcpServer + { + public event EventHandler StateChanged; + private readonly object connectionStateLock = new(); + private ConnectionState connectionState = ConnectionState.NotConnected; + public ConnectionState ConnectionState + { + get + { + lock (connectionStateLock) + { + return connectionState; + } + } + private set + { + ConnectionState prevState; + lock (connectionStateLock) + { + prevState = connectionState; + connectionState = value; + } + + if (prevState != value) + { + StateChanged(this, new(value, prevState)); + } + } + } + private CancellationTokenSource cts = null; + private Task receiveMessagesTask = null; + private readonly object messageQueueLock = new(); + private Queue messageQueue = new(); + + public void OpenConnection(int port) + { + if (ConnectionState != ConnectionState.NotConnected) + throw new InvalidOperationException("[BcpServer] Cannot open connection, because it is connected, connecting, or disconnecting"); + cts = new CancellationTokenSource(); + ConnectionState = ConnectionState.Connecting; + receiveMessagesTask = Task.Run(() => ReceiveMessages(port, cts.Token)); + } + + public async Task CloseConnectionAsync() + { + if (ConnectionState == ConnectionState.NotConnected || ConnectionState == ConnectionState.Disconnecting) + throw new InvalidOperationException("[BcpServer] Cannot close connection because it is not connected or already in the process of disconnecting"); + ConnectionState = ConnectionState.Disconnecting; + cts.Cancel(); + cts.Dispose(); + cts = null; + await receiveMessagesTask; + ConnectionState = ConnectionState.NotConnected; + } + + public bool TryDequeueMessage(out string message) + { + lock (messageQueueLock) + return messageQueue.TryDequeue(out message); + } + + private async Task ReceiveMessages(int port, CancellationToken ct) + { + var listener = new TcpListener(IPAddress.Any, port); + try + { + listener.Start(); + while (!ct.IsCancellationRequested) + { + if (listener.Pending()) + { + using TcpClient client = listener.AcceptTcpClient(); + ConnectionState = ConnectionState.Connected; + using NetworkStream stream = client.GetStream(); + const int bufferSize = 1024; + var byteBuffer = new byte[bufferSize]; + var stringBuffer = new StringBuilder(); + while (!ct.IsCancellationRequested) + { + int numBytesRead = 0; + + if (!stream.DataAvailable) + { + await Task.Yield(); + continue; + } + + try + { + numBytesRead = await stream.ReadAsync(byteBuffer, 0, bufferSize, ct); + } + catch (OperationCanceledException) + { + break; + } + + if (numBytesRead == 0) + break; + + var stringRead = Encoding.UTF8.GetString(byteBuffer, 0, numBytesRead); + stringBuffer.Append(stringRead); + const char terminator = '\n'; + int messageLength; + while (!ct.IsCancellationRequested && (messageLength = stringBuffer.ToString().IndexOf(terminator)) > -1) + { + var message = stringBuffer.ToString(0, messageLength); + stringBuffer.Remove(0, messageLength + 1); + lock (messageQueueLock) + messageQueue.Enqueue(message); + } + } + } + else + { + await Task.Yield(); + } + } + } + finally + { + listener.Stop(); + } + } + } +} diff --git a/Runtime/BcpServer.cs.meta b/Runtime/BcpServer.cs.meta new file mode 100644 index 00000000..a735c46e --- /dev/null +++ b/Runtime/BcpServer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 04972bef1baf70147b4137bbf24704b1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef b/Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef new file mode 100644 index 00000000..b56eacec --- /dev/null +++ b/Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef @@ -0,0 +1,3 @@ +{ + "name": "FutureBoxSystems.MpfUnityBcpServer" +} diff --git a/Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef.meta b/Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef.meta new file mode 100644 index 00000000..fe6754d3 --- /dev/null +++ b/Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 12ad807656c18b64a898ea816cf5bf11 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json new file mode 100644 index 00000000..cad71ed4 --- /dev/null +++ b/package.json @@ -0,0 +1,7 @@ +{ + "name": "com.futureboxsystems.mpf-unity-bcp-server", + "version": "0.1.0", + "displayName": "MPF Unity BCP Server", + "description": "Communicate with MPF (Mission Pinball Framework) using the BCP (Backpox Control Protocol) to control media playback and user interfaces for a pinball machine", + "unity": "2022.3" +} \ No newline at end of file diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 00000000..45c616d4 --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 784abc6885d58ca40a4594fd7b9b672d +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From e2d09e24ba35ad6234d9ea56edb68299bcfe4aaa Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:35:25 +0200 Subject: [PATCH 02/98] Improve perfomance and reliability --- Runtime/BcpInterface.cs | 6 ++--- Runtime/BcpServer.cs | 50 ++++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/Runtime/BcpInterface.cs b/Runtime/BcpInterface.cs index eff0daba..d3459f9c 100644 --- a/Runtime/BcpInterface.cs +++ b/Runtime/BcpInterface.cs @@ -10,11 +10,11 @@ public class BcpInterface : MonoBehaviour private BcpServer server; - private void OnEnable() + private async void OnEnable() { - server ??= new BcpServer(); + server ??= new BcpServer(port); server.StateChanged += Server_StateChanged; - server.OpenConnection(port); + await server.OpenConnectionAsync(); } private void Server_StateChanged(object sender, ConnectionStateChangedEventArgs e) diff --git a/Runtime/BcpServer.cs b/Runtime/BcpServer.cs index 8b5d5be5..2d995e3c 100644 --- a/Runtime/BcpServer.cs +++ b/Runtime/BcpServer.cs @@ -1,12 +1,10 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; using System.Threading.Tasks; -using Unity.Profiling.Editor; namespace MpfBcpServer { @@ -39,7 +37,7 @@ public ConnectionState ConnectionState } private set { - ConnectionState prevState; + ConnectionState prevState; lock (connectionStateLock) { prevState = connectionState; @@ -52,30 +50,42 @@ private set } } } + private CancellationTokenSource cts = null; private Task receiveMessagesTask = null; private readonly object messageQueueLock = new(); - private Queue messageQueue = new(); + private readonly Queue messageQueue = new(); + private readonly int port; + + public BcpServer(int port) + { + this.port = port; + } - public void OpenConnection(int port) + public async Task OpenConnectionAsync() { - if (ConnectionState != ConnectionState.NotConnected) - throw new InvalidOperationException("[BcpServer] Cannot open connection, because it is connected, connecting, or disconnecting"); - cts = new CancellationTokenSource(); - ConnectionState = ConnectionState.Connecting; - receiveMessagesTask = Task.Run(() => ReceiveMessages(port, cts.Token)); + while (ConnectionState == ConnectionState.Disconnecting) + await Task.Yield(); + if (ConnectionState == ConnectionState.NotConnected) + { + cts = new CancellationTokenSource(); + ConnectionState = ConnectionState.Connecting; + receiveMessagesTask = Task.Run(() => ReceiveMessages(port, cts.Token)); + } } public async Task CloseConnectionAsync() { - if (ConnectionState == ConnectionState.NotConnected || ConnectionState == ConnectionState.Disconnecting) - throw new InvalidOperationException("[BcpServer] Cannot close connection because it is not connected or already in the process of disconnecting"); - ConnectionState = ConnectionState.Disconnecting; - cts.Cancel(); - cts.Dispose(); - cts = null; - await receiveMessagesTask; - ConnectionState = ConnectionState.NotConnected; + if (ConnectionState == ConnectionState.Connected || + ConnectionState == ConnectionState.Connecting) + { + ConnectionState = ConnectionState.Disconnecting; + cts.Cancel(); + cts.Dispose(); + cts = null; + await receiveMessagesTask; + ConnectionState = ConnectionState.NotConnected; + } } public bool TryDequeueMessage(out string message) @@ -106,7 +116,7 @@ private async Task ReceiveMessages(int port, CancellationToken ct) if (!stream.DataAvailable) { - await Task.Yield(); + await Task.Delay(10); continue; } @@ -137,7 +147,7 @@ private async Task ReceiveMessages(int port, CancellationToken ct) } else { - await Task.Yield(); + await Task.Delay(100); } } } From 59f2d85492ebbae5bba3f0b477c82eedb3da2504 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sat, 12 Oct 2024 20:27:43 +0200 Subject: [PATCH 03/98] Add custom inspector for BcpInterface --- Editor.meta | 8 +++++ Editor/BcpInterfaceInspector.cs | 32 +++++++++++++++++++ Editor/BcpInterfaceInspector.cs.meta | 11 +++++++ ...BoxSystems.MpfUnityBcpServer.Editor.asmdef | 18 +++++++++++ ...stems.MpfUnityBcpServer.Editor.asmdef.meta | 7 ++++ Runtime/BcpInterface.cs | 13 +++----- Runtime/BcpServer.cs | 4 +-- 7 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 Editor.meta create mode 100644 Editor/BcpInterfaceInspector.cs create mode 100644 Editor/BcpInterfaceInspector.cs.meta create mode 100644 Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef create mode 100644 Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef.meta diff --git a/Editor.meta b/Editor.meta new file mode 100644 index 00000000..3d7be30f --- /dev/null +++ b/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fd9aa13d5408a4a4cab71c78d5fe2bf0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/BcpInterfaceInspector.cs b/Editor/BcpInterfaceInspector.cs new file mode 100644 index 00000000..ba645f3f --- /dev/null +++ b/Editor/BcpInterfaceInspector.cs @@ -0,0 +1,32 @@ +using UnityEditor; +using UnityEngine; + +namespace FutureBoxSystems.MpfBcpServer +{ + [CustomEditor(typeof(BcpInterface))] + public class BcpInterfaceInspector : Editor + { + private SerializedProperty portProperty; + private BcpInterface bcpInterface; + + private void OnEnable() + { + portProperty = serializedObject.FindProperty("port"); + bcpInterface = target as BcpInterface; + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + if (bcpInterface != null) + { + var connectionState = bcpInterface.ConnectionState; + EditorGUILayout.LabelField("Connection status:", connectionState.ToString()); + } + EditorGUI.BeginChangeCheck(); + EditorGUILayout.PropertyField(portProperty, new GUIContent("Port")); + if (EditorGUI.EndChangeCheck()) + serializedObject.ApplyModifiedProperties(); + } + } +} diff --git a/Editor/BcpInterfaceInspector.cs.meta b/Editor/BcpInterfaceInspector.cs.meta new file mode 100644 index 00000000..c47749cb --- /dev/null +++ b/Editor/BcpInterfaceInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0bea179b36a1e3c4c95091c53c60a399 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef b/Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef new file mode 100644 index 00000000..52a0155d --- /dev/null +++ b/Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef @@ -0,0 +1,18 @@ +{ + "name": "FutureBoxSystems.MpfUnityBcpServer.Editor", + "rootNamespace": "", + "references": [ + "FutureBoxSystems.MpfUnityBcpServer" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef.meta b/Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef.meta new file mode 100644 index 00000000..548d11bc --- /dev/null +++ b/Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 48cf4bb59f7238345a24c866827e892c +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/BcpInterface.cs b/Runtime/BcpInterface.cs index d3459f9c..c870b8f9 100644 --- a/Runtime/BcpInterface.cs +++ b/Runtime/BcpInterface.cs @@ -1,27 +1,23 @@ using UnityEngine; -namespace MpfBcpServer +namespace FutureBoxSystems.MpfBcpServer { public class BcpInterface : MonoBehaviour { - public ConnectionState state; + public ConnectionState ConnectionState => server != null ? server.ConnectionState : ConnectionState.NotConnected; [SerializeField] private int port = 5050; private BcpServer server; + private int t = 5050; + private async void OnEnable() { server ??= new BcpServer(port); - server.StateChanged += Server_StateChanged; await server.OpenConnectionAsync(); } - private void Server_StateChanged(object sender, ConnectionStateChangedEventArgs e) - { - state = e.CurrentState; - } - private void Update() { if (server.TryDequeueMessage(out var message)) @@ -31,7 +27,6 @@ private void Update() private async void OnDisable() { await server.CloseConnectionAsync(); - server.StateChanged -= Server_StateChanged; } } } \ No newline at end of file diff --git a/Runtime/BcpServer.cs b/Runtime/BcpServer.cs index 2d995e3c..c6e64324 100644 --- a/Runtime/BcpServer.cs +++ b/Runtime/BcpServer.cs @@ -6,7 +6,7 @@ using System.Threading; using System.Threading.Tasks; -namespace MpfBcpServer +namespace FutureBoxSystems.MpfBcpServer { public class ConnectionStateChangedEventArgs : EventArgs { @@ -46,7 +46,7 @@ private set if (prevState != value) { - StateChanged(this, new(value, prevState)); + StateChanged?.Invoke(this, new(value, prevState)); } } } From bc85f3c357172dda42aec3280558dcf6d4015d3c Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:53:59 +0200 Subject: [PATCH 04/98] Parse messages --- Editor/BcpInterfaceInspector.cs | 5 +- Runtime/BcpInterface.cs | 26 ++++++++-- Runtime/BcpMessage.cs | 85 +++++++++++++++++++++++++++++++++ Runtime/BcpMessage.cs.meta | 11 +++++ Runtime/BcpServer.cs | 2 + 5 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 Runtime/BcpMessage.cs create mode 100644 Runtime/BcpMessage.cs.meta diff --git a/Editor/BcpInterfaceInspector.cs b/Editor/BcpInterfaceInspector.cs index ba645f3f..72aa65cd 100644 --- a/Editor/BcpInterfaceInspector.cs +++ b/Editor/BcpInterfaceInspector.cs @@ -23,10 +23,7 @@ public override void OnInspectorGUI() var connectionState = bcpInterface.ConnectionState; EditorGUILayout.LabelField("Connection status:", connectionState.ToString()); } - EditorGUI.BeginChangeCheck(); - EditorGUILayout.PropertyField(portProperty, new GUIContent("Port")); - if (EditorGUI.EndChangeCheck()) - serializedObject.ApplyModifiedProperties(); + base.OnInspectorGUI(); } } } diff --git a/Runtime/BcpInterface.cs b/Runtime/BcpInterface.cs index c870b8f9..c931c65d 100644 --- a/Runtime/BcpInterface.cs +++ b/Runtime/BcpInterface.cs @@ -1,3 +1,4 @@ +using System; using UnityEngine; namespace FutureBoxSystems.MpfBcpServer @@ -7,10 +8,13 @@ public class BcpInterface : MonoBehaviour public ConnectionState ConnectionState => server != null ? server.ConnectionState : ConnectionState.NotConnected; [SerializeField] private int port = 5050; + [SerializeField] + [Range(0.1f, 10f)] + private float frameTimeBudgetMs = 3f; private BcpServer server; - private int t = 5050; + public event EventHandler MessageReceived; private async void OnEnable() { @@ -20,8 +24,14 @@ private async void OnEnable() private void Update() { - if (server.TryDequeueMessage(out var message)) - Debug.Log(message); + float startTime = Time.unscaledTime; + float timeSpentMs = 0f; + while (timeSpentMs < frameTimeBudgetMs && server.TryDequeueMessage(out var messageAsString)) + { + var message = BcpMessage.FromString(messageAsString); + MessageReceived?.Invoke(this, new(message)); + timeSpentMs = (Time.unscaledTime - startTime) * 1000f; + } } private async void OnDisable() @@ -29,4 +39,14 @@ private async void OnDisable() await server.CloseConnectionAsync(); } } + + public class MessageReceivedEventArgs : EventArgs + { + public BcpMessage Message { get; private set; } + + public MessageReceivedEventArgs(BcpMessage message) + { + Message = message; + } + } } \ No newline at end of file diff --git a/Runtime/BcpMessage.cs b/Runtime/BcpMessage.cs new file mode 100644 index 00000000..b192a002 --- /dev/null +++ b/Runtime/BcpMessage.cs @@ -0,0 +1,85 @@ +using System.Collections.Generic; +using System.Text; + +namespace FutureBoxSystems.MpfBcpServer +{ + public struct BcpMessage + { + public string Command { get; private set; } + public readonly IReadOnlyList Parameters => parameters.AsReadOnly(); + private readonly List parameters; + private const char commandParamsSeparator = '?'; + private const char paramsSeparator = '&'; + + public BcpMessage(string command, List parameters) + { + Command = command; + this.parameters = parameters; + } + + public override readonly string ToString() + { + var sb = new StringBuilder(Command); + if (parameters.Count > 0) + sb.Append(commandParamsSeparator); + for (int i = 0; i < parameters.Count; i++) + { + sb.Append(parameters[i].ToString()); + bool isLastParam = i == parameters.Count - 1; + if (!isLastParam) + sb.Append(paramsSeparator); + } + return sb.ToString(); + } + + public static BcpMessage FromString(string str) + { + var parts = str.Split(commandParamsSeparator, paramsSeparator); + var name = parts[0]; + var bcpParams = new List(); + for (int i = 1; i < parts.Length; i++) + { + var param = BcpParameter.FromString(parts[i]); + bcpParams.Add(param); + } + return new BcpMessage(name, bcpParams); + } + } + + public struct BcpParameter + { + public string Name { get; private set; } + public string TypeHint { get; private set; } + public string Value { get; private set; } + + public BcpParameter(string name, string typeHint, string value) + { + Name = name; + TypeHint = typeHint; + Value = value; + } + + public override readonly string ToString() + { + if (string.IsNullOrEmpty(TypeHint)) + return $"{Name}={Value}"; + return $"{Name}={TypeHint}:{Value}"; + } + + public static BcpParameter FromString(string str) + { + string[] parts = str.Split(new char[] { '=', ':' }, 3); + var name = parts[0].ToLower(); // Not case sensitive + string typeHint = null; + string value = null; + if (parts.Length == 2) + value = parts[1]; + else if (parts.Length == 3) + { + typeHint = parts[1]; + value = parts[2]; + } + return new BcpParameter(name, typeHint, value); + } + } +} \ No newline at end of file diff --git a/Runtime/BcpMessage.cs.meta b/Runtime/BcpMessage.cs.meta new file mode 100644 index 00000000..882e2e4c --- /dev/null +++ b/Runtime/BcpMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 35ec81e967297614996436632750722a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/BcpServer.cs b/Runtime/BcpServer.cs index c6e64324..ea4af7bd 100644 --- a/Runtime/BcpServer.cs +++ b/Runtime/BcpServer.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using UnityEngine.Networking; namespace FutureBoxSystems.MpfBcpServer { @@ -140,6 +141,7 @@ private async Task ReceiveMessages(int port, CancellationToken ct) { var message = stringBuffer.ToString(0, messageLength); stringBuffer.Remove(0, messageLength + 1); + message = UnityWebRequest.UnEscapeURL(message); lock (messageQueueLock) messageQueue.Enqueue(message); } From 5ada3663b75453974fb9fd05794d48382cf665c5 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:28:11 +0200 Subject: [PATCH 05/98] Add command dispatcher --- Runtime/BcpInterface.cs | 49 ++++++++++++++++++ Runtime/BcpMessage.cs | 112 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 156 insertions(+), 5 deletions(-) diff --git a/Runtime/BcpInterface.cs b/Runtime/BcpInterface.cs index c931c65d..b97b39f4 100644 --- a/Runtime/BcpInterface.cs +++ b/Runtime/BcpInterface.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using UnityEngine; +using UnityEngine.Android; namespace FutureBoxSystems.MpfBcpServer { @@ -15,6 +17,30 @@ public class BcpInterface : MonoBehaviour private BcpServer server; public event EventHandler MessageReceived; + public readonly BcpCommandDispatcher Hello = new(HelloMessage.Parse); + private readonly Dictionary commandDispatchers = new() + { + { HelloMessage.command, new BcpCommandDispatcher(HelloMessage.Parse) } + }; + + public void AddCommandListener(string command, EventHandler listener) where T : EventArgs + { + var dispatcher = commandDispatchers[command] as BcpCommandDispatcher; + dispatcher.CommandReceived += listener; + } + + public bool TryRemoveCommandListener(string command, EventHandler listener) where T : EventArgs + { + if (commandDispatchers.TryGetValue(command, out var dispatcherInterface)) + { + if (dispatcherInterface is BcpCommandDispatcher dispatcher) + { + dispatcher.CommandReceived -= listener; + return true; + } + } + return false; + } private async void OnEnable() { @@ -29,11 +55,34 @@ private void Update() while (timeSpentMs < frameTimeBudgetMs && server.TryDequeueMessage(out var messageAsString)) { var message = BcpMessage.FromString(messageAsString); + HandleReceivedMessage(message); MessageReceived?.Invoke(this, new(message)); timeSpentMs = (Time.unscaledTime - startTime) * 1000f; } } + + private void HandleReceivedMessage(BcpMessage message) + { + if (commandDispatchers.TryGetValue(message.Command, out var dispatcher)) + { + try + { + dispatcher.Dispatch(message); + } + catch (BcpParseException) + { + // Message is malformed + // TODO: Send error message back + } + } + else + { + // Message command is unknown + // TODO: Send error message back + } + } + private async void OnDisable() { await server.CloseConnectionAsync(); diff --git a/Runtime/BcpMessage.cs b/Runtime/BcpMessage.cs index b192a002..f58699a6 100644 --- a/Runtime/BcpMessage.cs +++ b/Runtime/BcpMessage.cs @@ -1,12 +1,14 @@ +using System; using System.Collections.Generic; +using System.Linq; using System.Text; namespace FutureBoxSystems.MpfBcpServer { - public struct BcpMessage + public class BcpMessage { public string Command { get; private set; } - public readonly IReadOnlyList Parameters => parameters.AsReadOnly(); + public IReadOnlyList Parameters => parameters.AsReadOnly(); private readonly List parameters; private const char commandParamsSeparator = '?'; private const char paramsSeparator = '&'; @@ -17,7 +19,13 @@ public BcpMessage(string command, List parameters) this.parameters = parameters; } - public override readonly string ToString() + public string FindParamValue(string name, string typeHint = null) + { + var param = parameters.First(p => p.MatchesPattern(name, typeHint)); + return param.Value; + } + + public override string ToString() { var sb = new StringBuilder(Command); if (parameters.Count > 0) @@ -46,7 +54,7 @@ public static BcpMessage FromString(string str) } } - public struct BcpParameter + public class BcpParameter { public string Name { get; private set; } public string TypeHint { get; private set; } @@ -59,13 +67,20 @@ public BcpParameter(string name, string typeHint, string value) Value = value; } - public override readonly string ToString() + public override string ToString() { if (string.IsNullOrEmpty(TypeHint)) return $"{Name}={Value}"; return $"{Name}={TypeHint}:{Value}"; } + public bool MatchesPattern(string name, string typeHint) + { + return Name.Equals(name, StringComparison.OrdinalIgnoreCase) && + (TypeHint == typeHint || + TypeHint.Equals(typeHint, StringComparison.OrdinalIgnoreCase)); + } + public static BcpParameter FromString(string str) { string[] parts = str.Split(new char[] { '=', ':' }, 3); @@ -82,4 +97,91 @@ public static BcpParameter FromString(string str) return new BcpParameter(name, typeHint, value); } } + + public interface IBcpCommandDispatcher + { + public void Dispatch(BcpMessage message); + } + + public class BcpCommandDispatcher : IBcpCommandDispatcher where T : EventArgs + { + public delegate T ParseDelegate(BcpMessage genericMessage); + private event EventHandler commandReceived; + public event EventHandler CommandReceived + { + add + { + bool isFirstHandler = commandReceived == null; + commandReceived += value; + if (isFirstHandler) + FirstHandlerAdded(this, EventArgs.Empty); + } + remove + { + commandReceived -= value; + if (commandReceived == null) + LastHandlerRemoved(this, EventArgs.Empty); + } + } + + public event EventHandler FirstHandlerAdded; + public event EventHandler LastHandlerRemoved; + + private readonly ParseDelegate Parse; + + public BcpCommandDispatcher(ParseDelegate parse) + { + Parse = parse; + } + + public void Dispatch(BcpMessage genericMessage) + { + T specificMessage; + + try + { + specificMessage = Parse(genericMessage); + } + catch (InvalidOperationException e) + { + throw new BcpParseException(genericMessage, e); + } + + commandReceived?.Invoke(this, specificMessage); + } + } + + public class BcpParseException : Exception + { + public BcpMessage Culprit { get; private set; } + + public BcpParseException(BcpMessage culprit, Exception innerException) : base($"Failed to parse bcp message: {culprit}", innerException) + { + Culprit = culprit; + } + } + + public class HelloMessage : EventArgs + { + public const string command = "hello"; + public string Version { get; private set; } + public string ControllerName { get; private set; } + public string ControllerVersion { get; private set; } + + public HelloMessage(string version, string controllerName, string controllerVersion) + { + Version = version; + ControllerName = controllerName; + ControllerVersion = controllerVersion; + } + + public static HelloMessage Parse(BcpMessage bcpMessage) + { + return new( + version: bcpMessage.FindParamValue("version"), + controllerName: bcpMessage.FindParamValue("controller_name"), + controllerVersion: bcpMessage.FindParamValue("controller_version") + ); + } + } } \ No newline at end of file From faf1ae5b64ea9ec8fb9a7b7f8fb9884d953ac140 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 15 Oct 2024 19:46:45 +0200 Subject: [PATCH 06/98] Add ability to send messages --- Runtime/BcpInterface.cs | 11 +++- Runtime/BcpServer.cs | 123 +++++++++++++++++++++++++++------------- 2 files changed, 93 insertions(+), 41 deletions(-) diff --git a/Runtime/BcpInterface.cs b/Runtime/BcpInterface.cs index b97b39f4..024ced79 100644 --- a/Runtime/BcpInterface.cs +++ b/Runtime/BcpInterface.cs @@ -42,6 +42,15 @@ public bool TryRemoveCommandListener(string command, EventHandler listener return false; } + public bool TrySendMessage(BcpMessage message) + { + if (ConnectionState == ConnectionState.Connected) + { + server.EnqueueMessage(message.ToString()); + } + return false; + } + private async void OnEnable() { server ??= new BcpServer(port); @@ -52,7 +61,7 @@ private void Update() { float startTime = Time.unscaledTime; float timeSpentMs = 0f; - while (timeSpentMs < frameTimeBudgetMs && server.TryDequeueMessage(out var messageAsString)) + while (timeSpentMs < frameTimeBudgetMs && server.TryDequeueReceivedMessage(out var messageAsString)) { var message = BcpMessage.FromString(messageAsString); HandleReceivedMessage(message); diff --git a/Runtime/BcpServer.cs b/Runtime/BcpServer.cs index ea4af7bd..5d79d468 100644 --- a/Runtime/BcpServer.cs +++ b/Runtime/BcpServer.cs @@ -53,10 +53,13 @@ private set } private CancellationTokenSource cts = null; - private Task receiveMessagesTask = null; - private readonly object messageQueueLock = new(); - private readonly Queue messageQueue = new(); + private Task communicationTask = null; + private readonly object receivedMessagesLock = new(); + private readonly Queue receivedMessages = new(); + private readonly object outboundMessagesLock = new(); + private readonly Queue outboundMessages = new(); private readonly int port; + private enum ReceiveEndReason { Finished, Canceled, ClientDisconnected }; public BcpServer(int port) { @@ -67,11 +70,11 @@ public async Task OpenConnectionAsync() { while (ConnectionState == ConnectionState.Disconnecting) await Task.Yield(); - if (ConnectionState == ConnectionState.NotConnected) + if (ConnectionState == ConnectionState.NotConnected) { cts = new CancellationTokenSource(); ConnectionState = ConnectionState.Connecting; - receiveMessagesTask = Task.Run(() => ReceiveMessages(port, cts.Token)); + communicationTask = Task.Run(() => CommunicateAsync(port, cts.Token)); } } @@ -84,18 +87,32 @@ public async Task CloseConnectionAsync() cts.Cancel(); cts.Dispose(); cts = null; - await receiveMessagesTask; + await communicationTask; ConnectionState = ConnectionState.NotConnected; } } - public bool TryDequeueMessage(out string message) + public bool TryDequeueReceivedMessage(out string message) { - lock (messageQueueLock) - return messageQueue.TryDequeue(out message); + lock (receivedMessagesLock) + return receivedMessages.TryDequeue(out message); } - private async Task ReceiveMessages(int port, CancellationToken ct) + public void EnqueueMessage(string message) + { + if (string.IsNullOrEmpty(message)) + return; + lock (outboundMessagesLock) + outboundMessages.Enqueue(message); + } + + private bool TryDequeueOutboundMessage(out string message) + { + lock (outboundMessagesLock) + return outboundMessages.TryDequeue(out message); + } + + private async Task CommunicateAsync(int port, CancellationToken ct) { var listener = new TcpListener(IPAddress.Any, port); try @@ -113,38 +130,13 @@ private async Task ReceiveMessages(int port, CancellationToken ct) var stringBuffer = new StringBuilder(); while (!ct.IsCancellationRequested) { - int numBytesRead = 0; - - if (!stream.DataAvailable) - { - await Task.Delay(10); - continue; - } - - try - { - numBytesRead = await stream.ReadAsync(byteBuffer, 0, bufferSize, ct); - } - catch (OperationCanceledException) - { - break; - } - - if (numBytesRead == 0) + var sendTask = SendMessagesAsync(stream, ct); + var endReason = await ReceiveMessagesAsync(stream, byteBuffer, stringBuffer, ct); + await sendTask; + if (endReason == ReceiveEndReason.Canceled || endReason == ReceiveEndReason.ClientDisconnected) break; - var stringRead = Encoding.UTF8.GetString(byteBuffer, 0, numBytesRead); - stringBuffer.Append(stringRead); - const char terminator = '\n'; - int messageLength; - while (!ct.IsCancellationRequested && (messageLength = stringBuffer.ToString().IndexOf(terminator)) > -1) - { - var message = stringBuffer.ToString(0, messageLength); - stringBuffer.Remove(0, messageLength + 1); - message = UnityWebRequest.UnEscapeURL(message); - lock (messageQueueLock) - messageQueue.Enqueue(message); - } + await Task.Delay(10); } } else @@ -158,5 +150,56 @@ private async Task ReceiveMessages(int port, CancellationToken ct) listener.Stop(); } } + + private async Task ReceiveMessagesAsync (NetworkStream stream, byte[] byteBuffer, StringBuilder stringBuffer, CancellationToken ct) + { + while (stream.DataAvailable) + { + int numBytesRead; + try + { + numBytesRead = await stream.ReadAsync(byteBuffer, 0, byteBuffer.Length, ct); + } + catch (OperationCanceledException) + { + return ReceiveEndReason.Canceled; + } + + if (numBytesRead == 0) + return ReceiveEndReason.ClientDisconnected; + + var stringRead = Encoding.UTF8.GetString(byteBuffer, 0, numBytesRead); + stringBuffer.Append(stringRead); + const char terminator = '\n'; + int messageLength; + while (!ct.IsCancellationRequested && (messageLength = stringBuffer.ToString().IndexOf(terminator)) > -1) + { + var message = stringBuffer.ToString(0, messageLength); + stringBuffer.Remove(0, messageLength + 1); + message = UnityWebRequest.UnEscapeURL(message); + lock (receivedMessagesLock) + receivedMessages.Enqueue(message); + } + } + + return ReceiveEndReason.Finished; + } + + private async Task SendMessagesAsync(NetworkStream stream, CancellationToken ct) + { + while (!ct.IsCancellationRequested && TryDequeueOutboundMessage(out var message)) + { + var packet = Encoding.UTF8.GetBytes(message); + try + { + await stream.WriteAsync(packet, ct); + await stream.FlushAsync(ct); + } + catch (OperationCanceledException) + { + return; + } + } + } } } From a40c114374777b13e3f43e3987f786824a16ea77 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 15 Oct 2024 19:47:54 +0200 Subject: [PATCH 07/98] Add hello response --- Runtime/BcpMessage.cs | 28 ++++++++++++++++++++++------ Runtime/Constants.cs | 9 +++++++++ Runtime/Constants.cs.meta | 11 +++++++++++ Runtime/HelloResponse.cs | 24 ++++++++++++++++++++++++ Runtime/HelloResponse.cs.meta | 11 +++++++++++ 5 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 Runtime/Constants.cs create mode 100644 Runtime/Constants.cs.meta create mode 100644 Runtime/HelloResponse.cs create mode 100644 Runtime/HelloResponse.cs.meta diff --git a/Runtime/BcpMessage.cs b/Runtime/BcpMessage.cs index f58699a6..12b63049 100644 --- a/Runtime/BcpMessage.cs +++ b/Runtime/BcpMessage.cs @@ -114,20 +114,20 @@ public event EventHandler CommandReceived bool isFirstHandler = commandReceived == null; commandReceived += value; if (isFirstHandler) - FirstHandlerAdded(this, EventArgs.Empty); + FirstHandlerAdded?.Invoke(this, EventArgs.Empty); } remove { commandReceived -= value; if (commandReceived == null) - LastHandlerRemoved(this, EventArgs.Empty); + LastHandlerRemoved?.Invoke(this, EventArgs.Empty); } } public event EventHandler FirstHandlerAdded; public event EventHandler LastHandlerRemoved; - private readonly ParseDelegate Parse; + private readonly ParseDelegate Parse; public BcpCommandDispatcher(ParseDelegate parse) { @@ -164,6 +164,9 @@ public BcpParseException(BcpMessage culprit, Exception innerException) : base($" public class HelloMessage : EventArgs { public const string command = "hello"; + public const string versionName = "version"; + public const string controllerNameName = "controller_name"; + public const string controllerVersionName = "controller_version"; public string Version { get; private set; } public string ControllerName { get; private set; } public string ControllerVersion { get; private set; } @@ -175,12 +178,25 @@ public HelloMessage(string version, string controllerName, string controllerVers ControllerVersion = controllerVersion; } + public BcpMessage Parse() + { + return new BcpMessage( + command: command, + parameters: new List() + { + new(versionName, null, Version), + new(controllerNameName, null, ControllerName), + new(controllerVersionName, null, ControllerVersion) + } + ); + } + public static HelloMessage Parse(BcpMessage bcpMessage) { return new( - version: bcpMessage.FindParamValue("version"), - controllerName: bcpMessage.FindParamValue("controller_name"), - controllerVersion: bcpMessage.FindParamValue("controller_version") + version: bcpMessage.FindParamValue(versionName), + controllerName: bcpMessage.FindParamValue(controllerNameName), + controllerVersion: bcpMessage.FindParamValue(controllerVersionName) ); } } diff --git a/Runtime/Constants.cs b/Runtime/Constants.cs new file mode 100644 index 00000000..1078db96 --- /dev/null +++ b/Runtime/Constants.cs @@ -0,0 +1,9 @@ +namespace FutureBoxSystems.MpfBcpServer +{ + public static class Constants + { + public const string mediaControllerName = "Future Box Unity Media Controller"; + public const string mediaControllerVersion = "0.1.0"; + public const string bcpSpecVersion = "1.1"; + } +} \ No newline at end of file diff --git a/Runtime/Constants.cs.meta b/Runtime/Constants.cs.meta new file mode 100644 index 00000000..42d817a0 --- /dev/null +++ b/Runtime/Constants.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fac98a286d7a2ce44a42acba6c226f18 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/HelloResponse.cs b/Runtime/HelloResponse.cs new file mode 100644 index 00000000..89da4bb3 --- /dev/null +++ b/Runtime/HelloResponse.cs @@ -0,0 +1,24 @@ +using UnityEngine; + +namespace FutureBoxSystems.MpfBcpServer +{ + public class HelloResponse : MonoBehaviour + { + [SerializeField] + private BcpInterface bcpInterface; + + private void Start() + { + bcpInterface.AddCommandListener(HelloMessage.command, HelloMessageReceived); + } + + private void HelloMessageReceived(object sender, HelloMessage message) + { + BcpMessage response = new HelloMessage( + Constants.bcpSpecVersion, + Constants.mediaControllerName, + Constants.mediaControllerVersion).Parse(); + bcpInterface.TrySendMessage(response); + } + } +} \ No newline at end of file diff --git a/Runtime/HelloResponse.cs.meta b/Runtime/HelloResponse.cs.meta new file mode 100644 index 00000000..34cc4de1 --- /dev/null +++ b/Runtime/HelloResponse.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f6b6583adcb8fcd40b734479fe7d38b5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From c341be2de77916a41f556dc2141a7b2f694d4a1e Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 15 Oct 2024 19:49:09 +0200 Subject: [PATCH 08/98] Move hello message to new file --- Runtime/BcpMessage.cs | 40 ------------------------------ Runtime/HelloMessage.cs | 47 ++++++++++++++++++++++++++++++++++++ Runtime/HelloMessage.cs.meta | 11 +++++++++ 3 files changed, 58 insertions(+), 40 deletions(-) create mode 100644 Runtime/HelloMessage.cs create mode 100644 Runtime/HelloMessage.cs.meta diff --git a/Runtime/BcpMessage.cs b/Runtime/BcpMessage.cs index 12b63049..cd721d71 100644 --- a/Runtime/BcpMessage.cs +++ b/Runtime/BcpMessage.cs @@ -160,44 +160,4 @@ public BcpParseException(BcpMessage culprit, Exception innerException) : base($" Culprit = culprit; } } - - public class HelloMessage : EventArgs - { - public const string command = "hello"; - public const string versionName = "version"; - public const string controllerNameName = "controller_name"; - public const string controllerVersionName = "controller_version"; - public string Version { get; private set; } - public string ControllerName { get; private set; } - public string ControllerVersion { get; private set; } - - public HelloMessage(string version, string controllerName, string controllerVersion) - { - Version = version; - ControllerName = controllerName; - ControllerVersion = controllerVersion; - } - - public BcpMessage Parse() - { - return new BcpMessage( - command: command, - parameters: new List() - { - new(versionName, null, Version), - new(controllerNameName, null, ControllerName), - new(controllerVersionName, null, ControllerVersion) - } - ); - } - - public static HelloMessage Parse(BcpMessage bcpMessage) - { - return new( - version: bcpMessage.FindParamValue(versionName), - controllerName: bcpMessage.FindParamValue(controllerNameName), - controllerVersion: bcpMessage.FindParamValue(controllerVersionName) - ); - } - } } \ No newline at end of file diff --git a/Runtime/HelloMessage.cs b/Runtime/HelloMessage.cs new file mode 100644 index 00000000..c9a4b8e9 --- /dev/null +++ b/Runtime/HelloMessage.cs @@ -0,0 +1,47 @@ + +using FutureBoxSystems.MpfBcpServer; +using System.Collections.Generic; +using System; + +namespace FutureBoxSystems.MpfBcpServer +{ + public class HelloMessage : EventArgs + { + public const string command = "hello"; + public const string versionName = "version"; + public const string controllerNameName = "controller_name"; + public const string controllerVersionName = "controller_version"; + public string Version { get; private set; } + public string ControllerName { get; private set; } + public string ControllerVersion { get; private set; } + + public HelloMessage(string version, string controllerName, string controllerVersion) + { + Version = version; + ControllerName = controllerName; + ControllerVersion = controllerVersion; + } + + public BcpMessage Parse() + { + return new BcpMessage( + command: command, + parameters: new List() + { + new(versionName, null, Version), + new(controllerNameName, null, ControllerName), + new(controllerVersionName, null, ControllerVersion) + } + ); + } + + public static HelloMessage Parse(BcpMessage bcpMessage) + { + return new( + version: bcpMessage.FindParamValue(versionName), + controllerName: bcpMessage.FindParamValue(controllerNameName), + controllerVersion: bcpMessage.FindParamValue(controllerVersionName) + ); + } + } +} \ No newline at end of file diff --git a/Runtime/HelloMessage.cs.meta b/Runtime/HelloMessage.cs.meta new file mode 100644 index 00000000..075d0c92 --- /dev/null +++ b/Runtime/HelloMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a3a74a2841867f14092b61bd84a1dcf2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From b90b6f44b768e24de631b6d91ca86e9b19b6b664 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 15 Oct 2024 23:43:01 +0200 Subject: [PATCH 09/98] Disconnect on goodbye --- Runtime/BcpInterface.cs | 17 +++++++++++++---- Runtime/BcpMessage.cs | 9 ++++++++- Runtime/BcpServer.cs | 16 +++++++++++++--- Runtime/DisconnectOnGoodbye.cs | 25 +++++++++++++++++++++++++ Runtime/DisconnectOnGoodbye.cs.meta | 11 +++++++++++ Runtime/GoodbyeMessage.cs | 16 ++++++++++++++++ Runtime/GoodbyeMessage.cs.meta | 11 +++++++++++ Runtime/HelloMessage.cs | 2 +- Runtime/HelloResponse.cs | 11 ++++++++--- 9 files changed, 106 insertions(+), 12 deletions(-) create mode 100644 Runtime/DisconnectOnGoodbye.cs create mode 100644 Runtime/DisconnectOnGoodbye.cs.meta create mode 100644 Runtime/GoodbyeMessage.cs create mode 100644 Runtime/GoodbyeMessage.cs.meta diff --git a/Runtime/BcpInterface.cs b/Runtime/BcpInterface.cs index 024ced79..bb8821d6 100644 --- a/Runtime/BcpInterface.cs +++ b/Runtime/BcpInterface.cs @@ -17,10 +17,10 @@ public class BcpInterface : MonoBehaviour private BcpServer server; public event EventHandler MessageReceived; - public readonly BcpCommandDispatcher Hello = new(HelloMessage.Parse); private readonly Dictionary commandDispatchers = new() { - { HelloMessage.command, new BcpCommandDispatcher(HelloMessage.Parse) } + { HelloMessage.command, new BcpCommandDispatcher(HelloMessage.Parse) }, + { GoodbyeMessage.command, new BcpCommandDispatcher(GoodbyeMessage.Parse) } }; public void AddCommandListener(string command, EventHandler listener) where T : EventArgs @@ -42,15 +42,23 @@ public bool TryRemoveCommandListener(string command, EventHandler listener return false; } - public bool TrySendMessage(BcpMessage message) + public bool TrySendMessage(ISentMessage message) { if (ConnectionState == ConnectionState.Connected) { - server.EnqueueMessage(message.ToString()); + BcpMessage bcpMessage = message.Parse(); + string stringMessage = bcpMessage.ToString(); + server.EnqueueMessage(stringMessage); } return false; } + public void RequestDisconnect() + { + if (ConnectionState == ConnectionState.Connected) + server.RequestDisconnect(); + } + private async void OnEnable() { server ??= new BcpServer(port); @@ -63,6 +71,7 @@ private void Update() float timeSpentMs = 0f; while (timeSpentMs < frameTimeBudgetMs && server.TryDequeueReceivedMessage(out var messageAsString)) { + Debug.Log(messageAsString); var message = BcpMessage.FromString(messageAsString); HandleReceivedMessage(message); MessageReceived?.Invoke(this, new(message)); diff --git a/Runtime/BcpMessage.cs b/Runtime/BcpMessage.cs index cd721d71..9b7e2180 100644 --- a/Runtime/BcpMessage.cs +++ b/Runtime/BcpMessage.cs @@ -19,6 +19,8 @@ public BcpMessage(string command, List parameters) this.parameters = parameters; } + public BcpMessage(string command) : this(command, new()) { } + public string FindParamValue(string name, string typeHint = null) { var param = parameters.First(p => p.MatchesPattern(name, typeHint)); @@ -155,9 +157,14 @@ public class BcpParseException : Exception { public BcpMessage Culprit { get; private set; } - public BcpParseException(BcpMessage culprit, Exception innerException) : base($"Failed to parse bcp message: {culprit}", innerException) + public BcpParseException(BcpMessage culprit, Exception innerException = null) : base($"Failed to parse bcp message: {culprit}", innerException) { Culprit = culprit; } } + + public interface ISentMessage + { + public BcpMessage Parse(); + } } \ No newline at end of file diff --git a/Runtime/BcpServer.cs b/Runtime/BcpServer.cs index 5d79d468..f5c8f11c 100644 --- a/Runtime/BcpServer.cs +++ b/Runtime/BcpServer.cs @@ -58,6 +58,7 @@ private set private readonly Queue receivedMessages = new(); private readonly object outboundMessagesLock = new(); private readonly Queue outboundMessages = new(); + private readonly ManualResetEventSlim disconnectRequested = new(false); private readonly int port; private enum ReceiveEndReason { Finished, Canceled, ClientDisconnected }; @@ -72,6 +73,7 @@ public async Task OpenConnectionAsync() await Task.Yield(); if (ConnectionState == ConnectionState.NotConnected) { + disconnectRequested.Reset(); cts = new CancellationTokenSource(); ConnectionState = ConnectionState.Connecting; communicationTask = Task.Run(() => CommunicateAsync(port, cts.Token)); @@ -106,6 +108,12 @@ public void EnqueueMessage(string message) outboundMessages.Enqueue(message); } + public void RequestDisconnect() + { + if (ConnectionState == ConnectionState.Connected) + disconnectRequested.Set(); + } + private bool TryDequeueOutboundMessage(out string message) { lock (outboundMessagesLock) @@ -120,6 +128,7 @@ private async Task CommunicateAsync(int port, CancellationToken ct) listener.Start(); while (!ct.IsCancellationRequested) { + ConnectionState = ConnectionState.Connecting; if (listener.Pending()) { using TcpClient client = listener.AcceptTcpClient(); @@ -128,16 +137,17 @@ private async Task CommunicateAsync(int port, CancellationToken ct) const int bufferSize = 1024; var byteBuffer = new byte[bufferSize]; var stringBuffer = new StringBuilder(); - while (!ct.IsCancellationRequested) + while (!ct.IsCancellationRequested && !disconnectRequested.IsSet) { var sendTask = SendMessagesAsync(stream, ct); var endReason = await ReceiveMessagesAsync(stream, byteBuffer, stringBuffer, ct); await sendTask; if (endReason == ReceiveEndReason.Canceled || endReason == ReceiveEndReason.ClientDisconnected) break; - await Task.Delay(10); } + await SendMessagesAsync(stream, ct); + disconnectRequested.Reset(); } else { @@ -151,7 +161,7 @@ private async Task CommunicateAsync(int port, CancellationToken ct) } } - private async Task ReceiveMessagesAsync (NetworkStream stream, byte[] byteBuffer, StringBuilder stringBuffer, CancellationToken ct) + private async Task ReceiveMessagesAsync(NetworkStream stream, byte[] byteBuffer, StringBuilder stringBuffer, CancellationToken ct) { while (stream.DataAvailable) { diff --git a/Runtime/DisconnectOnGoodbye.cs b/Runtime/DisconnectOnGoodbye.cs new file mode 100644 index 00000000..0580e142 --- /dev/null +++ b/Runtime/DisconnectOnGoodbye.cs @@ -0,0 +1,25 @@ +using UnityEngine; + +namespace FutureBoxSystems.MpfBcpServer +{ + public class DisconnectOnGoodbye : MonoBehaviour + { + [SerializeField] + BcpInterface bcpInterface; + + private void OnEnable() + { + bcpInterface.AddCommandListener(GoodbyeMessage.command, GoodbyeMessageReceived); + } + + private void OnDisable() + { + bcpInterface.TryRemoveCommandListener(GoodbyeMessage.command, GoodbyeMessageReceived); + } + + private void GoodbyeMessageReceived(object sender, GoodbyeMessage message) + { + bcpInterface.RequestDisconnect(); + } + } +} \ No newline at end of file diff --git a/Runtime/DisconnectOnGoodbye.cs.meta b/Runtime/DisconnectOnGoodbye.cs.meta new file mode 100644 index 00000000..74c88271 --- /dev/null +++ b/Runtime/DisconnectOnGoodbye.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fb15bb559ef2ee64ca4f6ba49b0a8605 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/GoodbyeMessage.cs b/Runtime/GoodbyeMessage.cs new file mode 100644 index 00000000..2288432c --- /dev/null +++ b/Runtime/GoodbyeMessage.cs @@ -0,0 +1,16 @@ +using System; + +namespace FutureBoxSystems.MpfBcpServer +{ + public class GoodbyeMessage : EventArgs, ISentMessage + { + public const string command = "goodbye"; + public BcpMessage Parse() => new(command); + public static GoodbyeMessage Parse(BcpMessage bcpMessage) + { + if (bcpMessage.Command != command) + throw new BcpParseException(bcpMessage); + return new(); + } + } +} \ No newline at end of file diff --git a/Runtime/GoodbyeMessage.cs.meta b/Runtime/GoodbyeMessage.cs.meta new file mode 100644 index 00000000..6931d93d --- /dev/null +++ b/Runtime/GoodbyeMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 547e18b4a16061943893d2ae8325ff46 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/HelloMessage.cs b/Runtime/HelloMessage.cs index c9a4b8e9..459fd8fa 100644 --- a/Runtime/HelloMessage.cs +++ b/Runtime/HelloMessage.cs @@ -5,7 +5,7 @@ namespace FutureBoxSystems.MpfBcpServer { - public class HelloMessage : EventArgs + public class HelloMessage : EventArgs, ISentMessage { public const string command = "hello"; public const string versionName = "version"; diff --git a/Runtime/HelloResponse.cs b/Runtime/HelloResponse.cs index 89da4bb3..5ab79a5b 100644 --- a/Runtime/HelloResponse.cs +++ b/Runtime/HelloResponse.cs @@ -7,17 +7,22 @@ public class HelloResponse : MonoBehaviour [SerializeField] private BcpInterface bcpInterface; - private void Start() + private void OnEnable() { bcpInterface.AddCommandListener(HelloMessage.command, HelloMessageReceived); } + private void OnDisable() + { + bcpInterface.TryRemoveCommandListener(HelloMessage.command, HelloMessageReceived); + } + private void HelloMessageReceived(object sender, HelloMessage message) { - BcpMessage response = new HelloMessage( + var response = new HelloMessage( Constants.bcpSpecVersion, Constants.mediaControllerName, - Constants.mediaControllerVersion).Parse(); + Constants.mediaControllerVersion); bcpInterface.TrySendMessage(response); } } From ba5a62e0539a7ec4156795c0c4a5e511980bc851 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:38:43 +0200 Subject: [PATCH 10/98] Rename from BcpServer to MediaController --- Editor/BcpInterfaceInspector.cs | 2 +- ... => FutureBoxSystems.MpfUnityMediaControllerEditor.asmdef} | 4 ++-- ...utureBoxSystems.MpfUnityMediaControllerEditor.asmdef.meta} | 2 +- Runtime/BcpInterface.cs | 2 +- Runtime/BcpMessage.cs | 2 +- Runtime/BcpServer.cs | 2 +- Runtime/Constants.cs | 2 +- Runtime/DisconnectOnGoodbye.cs | 2 +- Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef | 3 --- Runtime/FutureBoxSystems.MpfUnityMediaController.asmdef | 3 +++ ...a => FutureBoxSystems.MpfUnityMediaController.asmdef.meta} | 2 +- Runtime/GoodbyeMessage.cs | 2 +- Runtime/HelloMessage.cs | 3 +-- Runtime/HelloResponse.cs | 2 +- package.json | 4 ++-- 15 files changed, 18 insertions(+), 19 deletions(-) rename Editor/{FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef => FutureBoxSystems.MpfUnityMediaControllerEditor.asmdef} (75%) rename Editor/{FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef.meta => FutureBoxSystems.MpfUnityMediaControllerEditor.asmdef.meta} (76%) delete mode 100644 Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef create mode 100644 Runtime/FutureBoxSystems.MpfUnityMediaController.asmdef rename Runtime/{FutureBoxSystems.MpfUnityBcpServer.asmdef.meta => FutureBoxSystems.MpfUnityMediaController.asmdef.meta} (76%) diff --git a/Editor/BcpInterfaceInspector.cs b/Editor/BcpInterfaceInspector.cs index 72aa65cd..a83a23ef 100644 --- a/Editor/BcpInterfaceInspector.cs +++ b/Editor/BcpInterfaceInspector.cs @@ -1,7 +1,7 @@ using UnityEditor; using UnityEngine; -namespace FutureBoxSystems.MpfBcpServer +namespace FutureBoxSystems.MpfMediaController { [CustomEditor(typeof(BcpInterface))] public class BcpInterfaceInspector : Editor diff --git a/Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef b/Editor/FutureBoxSystems.MpfUnityMediaControllerEditor.asmdef similarity index 75% rename from Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef rename to Editor/FutureBoxSystems.MpfUnityMediaControllerEditor.asmdef index 52a0155d..9147ba72 100644 --- a/Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef +++ b/Editor/FutureBoxSystems.MpfUnityMediaControllerEditor.asmdef @@ -1,8 +1,8 @@ { - "name": "FutureBoxSystems.MpfUnityBcpServer.Editor", + "name": "FutureBoxSystems.MpfUnityMediaController.Editor", "rootNamespace": "", "references": [ - "FutureBoxSystems.MpfUnityBcpServer" + "FutureBoxSystems.MpfUnityMediaController" ], "includePlatforms": [ "Editor" diff --git a/Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef.meta b/Editor/FutureBoxSystems.MpfUnityMediaControllerEditor.asmdef.meta similarity index 76% rename from Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef.meta rename to Editor/FutureBoxSystems.MpfUnityMediaControllerEditor.asmdef.meta index 548d11bc..94192c40 100644 --- a/Editor/FutureBoxSystems.MpfUnityBcpServer.Editor.asmdef.meta +++ b/Editor/FutureBoxSystems.MpfUnityMediaControllerEditor.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 48cf4bb59f7238345a24c866827e892c +guid: 64457d6ee109ed24ab7dd5570a420ff7 AssemblyDefinitionImporter: externalObjects: {} userData: diff --git a/Runtime/BcpInterface.cs b/Runtime/BcpInterface.cs index bb8821d6..4e00eb43 100644 --- a/Runtime/BcpInterface.cs +++ b/Runtime/BcpInterface.cs @@ -3,7 +3,7 @@ using UnityEngine; using UnityEngine.Android; -namespace FutureBoxSystems.MpfBcpServer +namespace FutureBoxSystems.MpfMediaController { public class BcpInterface : MonoBehaviour { diff --git a/Runtime/BcpMessage.cs b/Runtime/BcpMessage.cs index 9b7e2180..d93fc526 100644 --- a/Runtime/BcpMessage.cs +++ b/Runtime/BcpMessage.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -namespace FutureBoxSystems.MpfBcpServer +namespace FutureBoxSystems.MpfMediaController { public class BcpMessage { diff --git a/Runtime/BcpServer.cs b/Runtime/BcpServer.cs index f5c8f11c..48bf9d08 100644 --- a/Runtime/BcpServer.cs +++ b/Runtime/BcpServer.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; using UnityEngine.Networking; -namespace FutureBoxSystems.MpfBcpServer +namespace FutureBoxSystems.MpfMediaController { public class ConnectionStateChangedEventArgs : EventArgs { diff --git a/Runtime/Constants.cs b/Runtime/Constants.cs index 1078db96..c82750be 100644 --- a/Runtime/Constants.cs +++ b/Runtime/Constants.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfBcpServer +namespace FutureBoxSystems.MpfMediaController { public static class Constants { diff --git a/Runtime/DisconnectOnGoodbye.cs b/Runtime/DisconnectOnGoodbye.cs index 0580e142..9fd6c9a2 100644 --- a/Runtime/DisconnectOnGoodbye.cs +++ b/Runtime/DisconnectOnGoodbye.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace FutureBoxSystems.MpfBcpServer +namespace FutureBoxSystems.MpfMediaController { public class DisconnectOnGoodbye : MonoBehaviour { diff --git a/Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef b/Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef deleted file mode 100644 index b56eacec..00000000 --- a/Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "FutureBoxSystems.MpfUnityBcpServer" -} diff --git a/Runtime/FutureBoxSystems.MpfUnityMediaController.asmdef b/Runtime/FutureBoxSystems.MpfUnityMediaController.asmdef new file mode 100644 index 00000000..a14f6cf6 --- /dev/null +++ b/Runtime/FutureBoxSystems.MpfUnityMediaController.asmdef @@ -0,0 +1,3 @@ +{ + "name": "FutureBoxSystems.MpfUnityMediaController" +} diff --git a/Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef.meta b/Runtime/FutureBoxSystems.MpfUnityMediaController.asmdef.meta similarity index 76% rename from Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef.meta rename to Runtime/FutureBoxSystems.MpfUnityMediaController.asmdef.meta index fe6754d3..49edac01 100644 --- a/Runtime/FutureBoxSystems.MpfUnityBcpServer.asmdef.meta +++ b/Runtime/FutureBoxSystems.MpfUnityMediaController.asmdef.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 12ad807656c18b64a898ea816cf5bf11 +guid: ffee5cd20a1a79f409709475573e2552 AssemblyDefinitionImporter: externalObjects: {} userData: diff --git a/Runtime/GoodbyeMessage.cs b/Runtime/GoodbyeMessage.cs index 2288432c..84ab9a7d 100644 --- a/Runtime/GoodbyeMessage.cs +++ b/Runtime/GoodbyeMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfBcpServer +namespace FutureBoxSystems.MpfMediaController { public class GoodbyeMessage : EventArgs, ISentMessage { diff --git a/Runtime/HelloMessage.cs b/Runtime/HelloMessage.cs index 459fd8fa..c3d0476f 100644 --- a/Runtime/HelloMessage.cs +++ b/Runtime/HelloMessage.cs @@ -1,9 +1,8 @@ -using FutureBoxSystems.MpfBcpServer; using System.Collections.Generic; using System; -namespace FutureBoxSystems.MpfBcpServer +namespace FutureBoxSystems.MpfMediaController { public class HelloMessage : EventArgs, ISentMessage { diff --git a/Runtime/HelloResponse.cs b/Runtime/HelloResponse.cs index 5ab79a5b..e2b9543d 100644 --- a/Runtime/HelloResponse.cs +++ b/Runtime/HelloResponse.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace FutureBoxSystems.MpfBcpServer +namespace FutureBoxSystems.MpfMediaController { public class HelloResponse : MonoBehaviour { diff --git a/package.json b/package.json index cad71ed4..e7fa777b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "com.futureboxsystems.mpf-unity-bcp-server", + "name": "com.futureboxsystems.mpf-unity-media-controller", "version": "0.1.0", - "displayName": "MPF Unity BCP Server", + "displayName": "MPF Unity Media Controller", "description": "Communicate with MPF (Mission Pinball Framework) using the BCP (Backpox Control Protocol) to control media playback and user interfaces for a pinball machine", "unity": "2022.3" } \ No newline at end of file From b0205c721a8c743d6fa62c0a3e8b58170edc89c3 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:15:14 +0200 Subject: [PATCH 11/98] Lowercase and trim commands and param names --- Runtime/BcpMessage.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Runtime/BcpMessage.cs b/Runtime/BcpMessage.cs index d93fc526..1d83efc2 100644 --- a/Runtime/BcpMessage.cs +++ b/Runtime/BcpMessage.cs @@ -45,14 +45,14 @@ public override string ToString() public static BcpMessage FromString(string str) { var parts = str.Split(commandParamsSeparator, paramsSeparator); - var name = parts[0]; + var command = parts[0].Trim().ToLower(); var bcpParams = new List(); for (int i = 1; i < parts.Length; i++) { var param = BcpParameter.FromString(parts[i]); bcpParams.Add(param); } - return new BcpMessage(name, bcpParams); + return new BcpMessage(command, bcpParams); } } @@ -86,7 +86,7 @@ public bool MatchesPattern(string name, string typeHint) public static BcpParameter FromString(string str) { string[] parts = str.Split(new char[] { '=', ':' }, 3); - var name = parts[0].ToLower(); // Not case sensitive + var name = parts[0].Trim().ToLower(); // Not case sensitive string typeHint = null; string value = null; if (parts.Length == 2) From 51b3ea637e3af5cc82be1a17a20ebcf799a1e2b1 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:19:45 +0200 Subject: [PATCH 12/98] Change BcpMessage to string conversion process --- Runtime/BcpInterface.cs | 7 ++----- Runtime/BcpServer.cs | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Runtime/BcpInterface.cs b/Runtime/BcpInterface.cs index 4e00eb43..4e556575 100644 --- a/Runtime/BcpInterface.cs +++ b/Runtime/BcpInterface.cs @@ -47,8 +47,7 @@ public bool TrySendMessage(ISentMessage message) if (ConnectionState == ConnectionState.Connected) { BcpMessage bcpMessage = message.Parse(); - string stringMessage = bcpMessage.ToString(); - server.EnqueueMessage(stringMessage); + server.EnqueueMessage(bcpMessage); } return false; } @@ -69,10 +68,8 @@ private void Update() { float startTime = Time.unscaledTime; float timeSpentMs = 0f; - while (timeSpentMs < frameTimeBudgetMs && server.TryDequeueReceivedMessage(out var messageAsString)) + while (timeSpentMs < frameTimeBudgetMs && server.TryDequeueReceivedMessage(out var message)) { - Debug.Log(messageAsString); - var message = BcpMessage.FromString(messageAsString); HandleReceivedMessage(message); MessageReceived?.Invoke(this, new(message)); timeSpentMs = (Time.unscaledTime - startTime) * 1000f; diff --git a/Runtime/BcpServer.cs b/Runtime/BcpServer.cs index 48bf9d08..764b02db 100644 --- a/Runtime/BcpServer.cs +++ b/Runtime/BcpServer.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Web; using UnityEngine.Networking; namespace FutureBoxSystems.MpfMediaController @@ -55,9 +56,9 @@ private set private CancellationTokenSource cts = null; private Task communicationTask = null; private readonly object receivedMessagesLock = new(); - private readonly Queue receivedMessages = new(); + private readonly Queue receivedMessages = new(); private readonly object outboundMessagesLock = new(); - private readonly Queue outboundMessages = new(); + private readonly Queue outboundMessages = new(); private readonly ManualResetEventSlim disconnectRequested = new(false); private readonly int port; private enum ReceiveEndReason { Finished, Canceled, ClientDisconnected }; @@ -94,16 +95,14 @@ public async Task CloseConnectionAsync() } } - public bool TryDequeueReceivedMessage(out string message) + public bool TryDequeueReceivedMessage(out BcpMessage message) { lock (receivedMessagesLock) return receivedMessages.TryDequeue(out message); } - public void EnqueueMessage(string message) + public void EnqueueMessage(BcpMessage message) { - if (string.IsNullOrEmpty(message)) - return; lock (outboundMessagesLock) outboundMessages.Enqueue(message); } @@ -114,7 +113,7 @@ public void RequestDisconnect() disconnectRequested.Set(); } - private bool TryDequeueOutboundMessage(out string message) + private bool TryDequeueOutboundMessage(out BcpMessage message) { lock (outboundMessagesLock) return outboundMessages.TryDequeue(out message); @@ -186,9 +185,10 @@ private async Task ReceiveMessagesAsync(NetworkStream stream, { var message = stringBuffer.ToString(0, messageLength); stringBuffer.Remove(0, messageLength + 1); - message = UnityWebRequest.UnEscapeURL(message); + message = Uri.UnescapeDataString(message); + var bcpMessage = BcpMessage.FromString(message); lock (receivedMessagesLock) - receivedMessages.Enqueue(message); + receivedMessages.Enqueue(bcpMessage); } } @@ -197,9 +197,11 @@ private async Task ReceiveMessagesAsync(NetworkStream stream, private async Task SendMessagesAsync(NetworkStream stream, CancellationToken ct) { - while (!ct.IsCancellationRequested && TryDequeueOutboundMessage(out var message)) + while (!ct.IsCancellationRequested && TryDequeueOutboundMessage(out BcpMessage bcpMessage)) { - var packet = Encoding.UTF8.GetBytes(message); + var stringMessage = bcpMessage.ToString(); + stringMessage = Uri.EscapeDataString(stringMessage); + var packet = Encoding.UTF8.GetBytes(stringMessage); try { await stream.WriteAsync(packet, ct); From c9921a702ae13012ec9f30dea502de87eea3bcab Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:31:55 +0200 Subject: [PATCH 13/98] Refactor message handling --- Runtime/BcpInterface.cs | 48 +++++++------------------- Runtime/BcpMessage.cs | 54 ++++++++++++++++++------------ Runtime/BcpMessageHandlers.cs | 15 +++++++++ Runtime/BcpMessageHandlers.cs.meta | 11 ++++++ Runtime/DisconnectOnGoodbye.cs | 6 ++-- Runtime/GoodbyeMessage.cs | 8 ++--- Runtime/HelloMessage.cs | 15 +++++---- Runtime/HelloResponse.cs | 7 ++-- 8 files changed, 92 insertions(+), 72 deletions(-) create mode 100644 Runtime/BcpMessageHandlers.cs create mode 100644 Runtime/BcpMessageHandlers.cs.meta diff --git a/Runtime/BcpInterface.cs b/Runtime/BcpInterface.cs index 4e556575..b982ebfe 100644 --- a/Runtime/BcpInterface.cs +++ b/Runtime/BcpInterface.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using UnityEngine; -using UnityEngine.Android; +using UnityEngine.Assertions; namespace FutureBoxSystems.MpfMediaController { @@ -16,38 +16,28 @@ public class BcpInterface : MonoBehaviour private BcpServer server; - public event EventHandler MessageReceived; - private readonly Dictionary commandDispatchers = new() - { - { HelloMessage.command, new BcpCommandDispatcher(HelloMessage.Parse) }, - { GoodbyeMessage.command, new BcpCommandDispatcher(GoodbyeMessage.Parse) } - }; + public delegate void HandleMessage(BcpMessage message); + private readonly Dictionary messageHandlers = new(); - public void AddCommandListener(string command, EventHandler listener) where T : EventArgs + public void RegisterMessageHandler(string command, HandleMessage handle) { - var dispatcher = commandDispatchers[command] as BcpCommandDispatcher; - dispatcher.CommandReceived += listener; + if (!messageHandlers.TryAdd(command, handle)) + Debug.LogWarning($"[BcpInterface] Cannot add message handler, because command '{command}' already has a handler."); } - public bool TryRemoveCommandListener(string command, EventHandler listener) where T : EventArgs + public void UnregisterMessageHandler(string command, HandleMessage handle) { - if (commandDispatchers.TryGetValue(command, out var dispatcherInterface)) - { - if (dispatcherInterface is BcpCommandDispatcher dispatcher) - { - dispatcher.CommandReceived -= listener; - return true; - } - } - return false; + if (!messageHandlers.Remove(command)) + Debug.LogWarning("[BcpInterface] Cannot remove message handler, because it is not registered."); } public bool TrySendMessage(ISentMessage message) { if (ConnectionState == ConnectionState.Connected) { - BcpMessage bcpMessage = message.Parse(); + BcpMessage bcpMessage = message.ToGenericMessage(); server.EnqueueMessage(bcpMessage); + return true; } return false; } @@ -71,19 +61,17 @@ private void Update() while (timeSpentMs < frameTimeBudgetMs && server.TryDequeueReceivedMessage(out var message)) { HandleReceivedMessage(message); - MessageReceived?.Invoke(this, new(message)); timeSpentMs = (Time.unscaledTime - startTime) * 1000f; } } - private void HandleReceivedMessage(BcpMessage message) { - if (commandDispatchers.TryGetValue(message.Command, out var dispatcher)) + if (messageHandlers.TryGetValue(message.Command, out var handler)) { try { - dispatcher.Dispatch(message); + handler(message); } catch (BcpParseException) { @@ -103,14 +91,4 @@ private async void OnDisable() await server.CloseConnectionAsync(); } } - - public class MessageReceivedEventArgs : EventArgs - { - public BcpMessage Message { get; private set; } - - public MessageReceivedEventArgs(BcpMessage message) - { - Message = message; - } - } } \ No newline at end of file diff --git a/Runtime/BcpMessage.cs b/Runtime/BcpMessage.cs index 1d83efc2..0d84d23e 100644 --- a/Runtime/BcpMessage.cs +++ b/Runtime/BcpMessage.cs @@ -23,8 +23,15 @@ public BcpMessage(string command, List parameters) public string FindParamValue(string name, string typeHint = null) { - var param = parameters.First(p => p.MatchesPattern(name, typeHint)); - return param.Value; + try + { + var param = parameters.First(p => p.MatchesPattern(name, typeHint)); + return param.Value; + } + catch (InvalidOperationException ioe) + { + throw new BcpParseException(this, ioe); + } } public override string ToString() @@ -100,16 +107,13 @@ public static BcpParameter FromString(string str) } } - public interface IBcpCommandDispatcher - { - public void Dispatch(BcpMessage message); - } - - public class BcpCommandDispatcher : IBcpCommandDispatcher where T : EventArgs + public class BcpMessageHandler where T : EventArgs { + public string Command { get; private set; } + public delegate void Test(); public delegate T ParseDelegate(BcpMessage genericMessage); private event EventHandler commandReceived; - public event EventHandler CommandReceived + public event EventHandler Received { add { @@ -129,26 +133,28 @@ public event EventHandler CommandReceived public event EventHandler FirstHandlerAdded; public event EventHandler LastHandlerRemoved; + private readonly BcpInterface bcpInterface; private readonly ParseDelegate Parse; - public BcpCommandDispatcher(ParseDelegate parse) + public BcpMessageHandler(string command, ParseDelegate parse, BcpInterface bcpInterface) { + Command = command; Parse = parse; + this.bcpInterface = bcpInterface; + bcpInterface.RegisterMessageHandler(Command, Handle); } - public void Dispatch(BcpMessage genericMessage) + ~BcpMessageHandler() { - T specificMessage; - - try - { - specificMessage = Parse(genericMessage); - } - catch (InvalidOperationException e) - { - throw new BcpParseException(genericMessage, e); - } + if (bcpInterface != null) + bcpInterface.UnregisterMessageHandler(Command, Handle); + } + private void Handle(BcpMessage message) + { + if (message.Command != Command) + throw new BcpParseException(message); + T specificMessage = Parse(message); commandReceived?.Invoke(this, specificMessage); } } @@ -163,8 +169,12 @@ public BcpParseException(BcpMessage culprit, Exception innerException = null) : } } + /// + /// Most message types are only received and never sent. + /// The ones that are sent must implement this interface + /// public interface ISentMessage { - public BcpMessage Parse(); + public BcpMessage ToGenericMessage(); } } \ No newline at end of file diff --git a/Runtime/BcpMessageHandlers.cs b/Runtime/BcpMessageHandlers.cs new file mode 100644 index 00000000..166d5ef5 --- /dev/null +++ b/Runtime/BcpMessageHandlers.cs @@ -0,0 +1,15 @@ +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController +{ + public class BcpMessageHandlers : MonoBehaviour + { + [SerializeField] + private BcpInterface bcpInterface; + + private BcpMessageHandler hello; + public BcpMessageHandler Hello => hello ??= new(HelloMessage.Command, HelloMessage.FromGenericMessage, bcpInterface); + private BcpMessageHandler goodbye; + public BcpMessageHandler Goodbye => goodbye ??= new(GoodbyeMessage.Command, GoodbyeMessage.FromGenericMessage, bcpInterface); + } +} \ No newline at end of file diff --git a/Runtime/BcpMessageHandlers.cs.meta b/Runtime/BcpMessageHandlers.cs.meta new file mode 100644 index 00000000..09e95ef8 --- /dev/null +++ b/Runtime/BcpMessageHandlers.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5af634c2dfa44ce4499cfbf44abee844 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/DisconnectOnGoodbye.cs b/Runtime/DisconnectOnGoodbye.cs index 9fd6c9a2..7cc7298c 100644 --- a/Runtime/DisconnectOnGoodbye.cs +++ b/Runtime/DisconnectOnGoodbye.cs @@ -6,15 +6,17 @@ public class DisconnectOnGoodbye : MonoBehaviour { [SerializeField] BcpInterface bcpInterface; + [SerializeField] + BcpMessageHandlers messageHandlers; private void OnEnable() { - bcpInterface.AddCommandListener(GoodbyeMessage.command, GoodbyeMessageReceived); + messageHandlers.Goodbye.Received += GoodbyeMessageReceived; } private void OnDisable() { - bcpInterface.TryRemoveCommandListener(GoodbyeMessage.command, GoodbyeMessageReceived); + messageHandlers.Goodbye.Received -= GoodbyeMessageReceived; } private void GoodbyeMessageReceived(object sender, GoodbyeMessage message) diff --git a/Runtime/GoodbyeMessage.cs b/Runtime/GoodbyeMessage.cs index 84ab9a7d..552cd02e 100644 --- a/Runtime/GoodbyeMessage.cs +++ b/Runtime/GoodbyeMessage.cs @@ -4,11 +4,11 @@ namespace FutureBoxSystems.MpfMediaController { public class GoodbyeMessage : EventArgs, ISentMessage { - public const string command = "goodbye"; - public BcpMessage Parse() => new(command); - public static GoodbyeMessage Parse(BcpMessage bcpMessage) + public const string Command = "goodbye"; + public BcpMessage ToGenericMessage() => new(Command); + public static GoodbyeMessage FromGenericMessage(BcpMessage bcpMessage) { - if (bcpMessage.Command != command) + if (bcpMessage.Command != Command) throw new BcpParseException(bcpMessage); return new(); } diff --git a/Runtime/HelloMessage.cs b/Runtime/HelloMessage.cs index c3d0476f..21546475 100644 --- a/Runtime/HelloMessage.cs +++ b/Runtime/HelloMessage.cs @@ -1,15 +1,16 @@ using System.Collections.Generic; using System; +using UnityEngine; namespace FutureBoxSystems.MpfMediaController { public class HelloMessage : EventArgs, ISentMessage { - public const string command = "hello"; - public const string versionName = "version"; - public const string controllerNameName = "controller_name"; - public const string controllerVersionName = "controller_version"; + public const string Command = "hello"; + private const string versionName = "version"; + private const string controllerNameName = "controller_name"; + private const string controllerVersionName = "controller_version"; public string Version { get; private set; } public string ControllerName { get; private set; } public string ControllerVersion { get; private set; } @@ -21,10 +22,10 @@ public HelloMessage(string version, string controllerName, string controllerVers ControllerVersion = controllerVersion; } - public BcpMessage Parse() + public BcpMessage ToGenericMessage() { return new BcpMessage( - command: command, + command: Command, parameters: new List() { new(versionName, null, Version), @@ -34,7 +35,7 @@ public BcpMessage Parse() ); } - public static HelloMessage Parse(BcpMessage bcpMessage) + public static HelloMessage FromGenericMessage(BcpMessage bcpMessage) { return new( version: bcpMessage.FindParamValue(versionName), diff --git a/Runtime/HelloResponse.cs b/Runtime/HelloResponse.cs index e2b9543d..46824760 100644 --- a/Runtime/HelloResponse.cs +++ b/Runtime/HelloResponse.cs @@ -6,15 +6,18 @@ public class HelloResponse : MonoBehaviour { [SerializeField] private BcpInterface bcpInterface; + [SerializeField] + private BcpMessageHandlers messageHandlers; private void OnEnable() { - bcpInterface.AddCommandListener(HelloMessage.command, HelloMessageReceived); + messageHandlers.Hello.Received += HelloMessageReceived; } private void OnDisable() { - bcpInterface.TryRemoveCommandListener(HelloMessage.command, HelloMessageReceived); + if (bcpInterface ) + messageHandlers.Hello.Received -= HelloMessageReceived; } private void HelloMessageReceived(object sender, HelloMessage message) From 70ab7aff3c2a698873392be2e54782fac5a4b5fb Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu, 17 Oct 2024 20:19:08 +0200 Subject: [PATCH 14/98] Make sure message handlers are initialized --- Runtime/BcpMessageHandlers.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Runtime/BcpMessageHandlers.cs b/Runtime/BcpMessageHandlers.cs index 166d5ef5..f6797f4b 100644 --- a/Runtime/BcpMessageHandlers.cs +++ b/Runtime/BcpMessageHandlers.cs @@ -11,5 +11,16 @@ public class BcpMessageHandlers : MonoBehaviour public BcpMessageHandler Hello => hello ??= new(HelloMessage.Command, HelloMessage.FromGenericMessage, bcpInterface); private BcpMessageHandler goodbye; public BcpMessageHandler Goodbye => goodbye ??= new(GoodbyeMessage.Command, GoodbyeMessage.FromGenericMessage, bcpInterface); + + private void Awake() + { + // Initialize command handlers + // Lazy initialization using the property getters above is needed because + // event handlers may try to access them before this Awake function is called. + // Even if no event handlers subscribe, the message handlers still need to exist, + // because an error message is sent for each command for which no handler exists. + _ = Hello; + _ = Goodbye; + } } } \ No newline at end of file From e089c6b2f552f672b0e09a29bf1af2a7f9b174e6 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu, 17 Oct 2024 20:20:01 +0200 Subject: [PATCH 15/98] Safely remove message handlers --- Runtime/BcpInterface.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Runtime/BcpInterface.cs b/Runtime/BcpInterface.cs index b982ebfe..3d869174 100644 --- a/Runtime/BcpInterface.cs +++ b/Runtime/BcpInterface.cs @@ -27,8 +27,10 @@ public void RegisterMessageHandler(string command, HandleMessage handle) public void UnregisterMessageHandler(string command, HandleMessage handle) { - if (!messageHandlers.Remove(command)) - Debug.LogWarning("[BcpInterface] Cannot remove message handler, because it is not registered."); + if (messageHandlers.TryGetValue(command, out var registeredHandle) && registeredHandle == handle) + messageHandlers.Remove(command); + else + Debug.LogWarning($"[BcpInterface] Cannot remove message handler for command '{command}', because it is not registered."); } public bool TrySendMessage(ISentMessage message) From 52e26e01f1f0ff7499d947af2b368379cb781489 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu, 17 Oct 2024 20:27:42 +0200 Subject: [PATCH 16/98] Restructure files --- Runtime/Behaviours.meta | 8 ++++++++ Runtime/{ => Behaviours}/DisconnectOnGoodbye.cs | 0 Runtime/{ => Behaviours}/DisconnectOnGoodbye.cs.meta | 2 +- Runtime/{ => Behaviours}/HelloResponse.cs | 0 Runtime/{ => Behaviours}/HelloResponse.cs.meta | 2 +- Runtime/Messages.meta | 8 ++++++++ Runtime/{ => Messages}/GoodbyeMessage.cs | 0 Runtime/{ => Messages}/GoodbyeMessage.cs.meta | 2 +- Runtime/{ => Messages}/HelloMessage.cs | 0 Runtime/{ => Messages}/HelloMessage.cs.meta | 2 +- 10 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 Runtime/Behaviours.meta rename Runtime/{ => Behaviours}/DisconnectOnGoodbye.cs (100%) rename Runtime/{ => Behaviours}/DisconnectOnGoodbye.cs.meta (83%) rename Runtime/{ => Behaviours}/HelloResponse.cs (100%) rename Runtime/{ => Behaviours}/HelloResponse.cs.meta (83%) create mode 100644 Runtime/Messages.meta rename Runtime/{ => Messages}/GoodbyeMessage.cs (100%) rename Runtime/{ => Messages}/GoodbyeMessage.cs.meta (83%) rename Runtime/{ => Messages}/HelloMessage.cs (100%) rename Runtime/{ => Messages}/HelloMessage.cs.meta (83%) diff --git a/Runtime/Behaviours.meta b/Runtime/Behaviours.meta new file mode 100644 index 00000000..05cd391f --- /dev/null +++ b/Runtime/Behaviours.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bc850fa7463d73b4b915322b8f37a887 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/DisconnectOnGoodbye.cs b/Runtime/Behaviours/DisconnectOnGoodbye.cs similarity index 100% rename from Runtime/DisconnectOnGoodbye.cs rename to Runtime/Behaviours/DisconnectOnGoodbye.cs diff --git a/Runtime/DisconnectOnGoodbye.cs.meta b/Runtime/Behaviours/DisconnectOnGoodbye.cs.meta similarity index 83% rename from Runtime/DisconnectOnGoodbye.cs.meta rename to Runtime/Behaviours/DisconnectOnGoodbye.cs.meta index 74c88271..1f8288be 100644 --- a/Runtime/DisconnectOnGoodbye.cs.meta +++ b/Runtime/Behaviours/DisconnectOnGoodbye.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: fb15bb559ef2ee64ca4f6ba49b0a8605 +guid: cf6e722a91a3eed43b7d8f5cf8f929ac MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/HelloResponse.cs b/Runtime/Behaviours/HelloResponse.cs similarity index 100% rename from Runtime/HelloResponse.cs rename to Runtime/Behaviours/HelloResponse.cs diff --git a/Runtime/HelloResponse.cs.meta b/Runtime/Behaviours/HelloResponse.cs.meta similarity index 83% rename from Runtime/HelloResponse.cs.meta rename to Runtime/Behaviours/HelloResponse.cs.meta index 34cc4de1..306994c3 100644 --- a/Runtime/HelloResponse.cs.meta +++ b/Runtime/Behaviours/HelloResponse.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f6b6583adcb8fcd40b734479fe7d38b5 +guid: d38f5f799b1bc354c9f85833a5c6c3ba MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Messages.meta b/Runtime/Messages.meta new file mode 100644 index 00000000..2c1e18c2 --- /dev/null +++ b/Runtime/Messages.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 45776fc1e8ad4ac46ad16aec95fcb94f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/GoodbyeMessage.cs b/Runtime/Messages/GoodbyeMessage.cs similarity index 100% rename from Runtime/GoodbyeMessage.cs rename to Runtime/Messages/GoodbyeMessage.cs diff --git a/Runtime/GoodbyeMessage.cs.meta b/Runtime/Messages/GoodbyeMessage.cs.meta similarity index 83% rename from Runtime/GoodbyeMessage.cs.meta rename to Runtime/Messages/GoodbyeMessage.cs.meta index 6931d93d..308c240b 100644 --- a/Runtime/GoodbyeMessage.cs.meta +++ b/Runtime/Messages/GoodbyeMessage.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 547e18b4a16061943893d2ae8325ff46 +guid: ebc3f3e430459444988aece8b374d564 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/HelloMessage.cs b/Runtime/Messages/HelloMessage.cs similarity index 100% rename from Runtime/HelloMessage.cs rename to Runtime/Messages/HelloMessage.cs diff --git a/Runtime/HelloMessage.cs.meta b/Runtime/Messages/HelloMessage.cs.meta similarity index 83% rename from Runtime/HelloMessage.cs.meta rename to Runtime/Messages/HelloMessage.cs.meta index 075d0c92..73bf4aea 100644 --- a/Runtime/HelloMessage.cs.meta +++ b/Runtime/Messages/HelloMessage.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a3a74a2841867f14092b61bd84a1dcf2 +guid: f734718d659e82140928f1b5916414f6 MonoImporter: externalObjects: {} serializedVersion: 2 From eb8902a2af2ba0e16dcb3054409fdbc7d7ec8946 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:37:54 +0200 Subject: [PATCH 17/98] Send error on bcp spec mismatch --- Runtime/BcpMessage.cs | 4 +-- Runtime/Behaviours/HelloResponse.cs | 19 ++++++++++--- Runtime/Constants.cs | 6 ++-- Runtime/Messages/ErrorMessage.cs | 40 +++++++++++++++++++++++++++ Runtime/Messages/ErrorMessage.cs.meta | 11 ++++++++ Runtime/Messages/HelloMessage.cs | 11 ++++---- 6 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 Runtime/Messages/ErrorMessage.cs create mode 100644 Runtime/Messages/ErrorMessage.cs.meta diff --git a/Runtime/BcpMessage.cs b/Runtime/BcpMessage.cs index 0d84d23e..544d514b 100644 --- a/Runtime/BcpMessage.cs +++ b/Runtime/BcpMessage.cs @@ -69,7 +69,7 @@ public class BcpParameter public string TypeHint { get; private set; } public string Value { get; private set; } - public BcpParameter(string name, string typeHint, string value) + public BcpParameter(string name, string value, string typeHint = null) { Name = name; TypeHint = typeHint; @@ -103,7 +103,7 @@ public static BcpParameter FromString(string str) typeHint = parts[1]; value = parts[2]; } - return new BcpParameter(name, typeHint, value); + return new BcpParameter(name, value, typeHint); } } diff --git a/Runtime/Behaviours/HelloResponse.cs b/Runtime/Behaviours/HelloResponse.cs index 46824760..7e25776d 100644 --- a/Runtime/Behaviours/HelloResponse.cs +++ b/Runtime/Behaviours/HelloResponse.cs @@ -22,10 +22,21 @@ private void OnDisable() private void HelloMessageReceived(object sender, HelloMessage message) { - var response = new HelloMessage( - Constants.bcpSpecVersion, - Constants.mediaControllerName, - Constants.mediaControllerVersion); + ISentMessage response; + if (message.BcpSpecVersion == Constants.BcpSpecVersion) + { + response = new HelloMessage( + Constants.BcpSpecVersion, + Constants.MediaControllerName, + Constants.MediaControllerVersion); + } + else + { + string originalHelloMessage = message.ToGenericMessage().ToString(); + response = new ErrorMessage( + message: "unknown protocol version", + commandThatCausedError: originalHelloMessage); + } bcpInterface.TrySendMessage(response); } } diff --git a/Runtime/Constants.cs b/Runtime/Constants.cs index c82750be..ecaa88a4 100644 --- a/Runtime/Constants.cs +++ b/Runtime/Constants.cs @@ -2,8 +2,8 @@ namespace FutureBoxSystems.MpfMediaController { public static class Constants { - public const string mediaControllerName = "Future Box Unity Media Controller"; - public const string mediaControllerVersion = "0.1.0"; - public const string bcpSpecVersion = "1.1"; + public const string MediaControllerName = "Future Box Unity Media Controller"; + public const string MediaControllerVersion = "0.1.0"; + public const string BcpSpecVersion = "1.1"; } } \ No newline at end of file diff --git a/Runtime/Messages/ErrorMessage.cs b/Runtime/Messages/ErrorMessage.cs new file mode 100644 index 00000000..9b9cfda0 --- /dev/null +++ b/Runtime/Messages/ErrorMessage.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; + +namespace FutureBoxSystems.MpfMediaController +{ + public class ErrorMessage : EventArgs, ISentMessage + { + public const string Command = "error"; + private const string messageName = "message"; + private const string commandThatCausedErrorName = "command"; + public string Message { get; private set; } + public string CommandThatCausedError { get; private set; } + + public ErrorMessage(string message, string commandThatCausedError) + { + Message = message; + CommandThatCausedError = commandThatCausedError; + } + + public BcpMessage ToGenericMessage() + { + return new BcpMessage( + command: Command, + parameters: new List() + { + new(messageName, Message), + new(commandThatCausedErrorName, CommandThatCausedError) + } + ); + } + + public static ErrorMessage FromGenericMessage(BcpMessage bcpMessage) + { + return new( + message: bcpMessage.FindParamValue(messageName), + commandThatCausedError: bcpMessage.FindParamValue(commandThatCausedErrorName) + ); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/ErrorMessage.cs.meta b/Runtime/Messages/ErrorMessage.cs.meta new file mode 100644 index 00000000..c6caa81e --- /dev/null +++ b/Runtime/Messages/ErrorMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 50b13d0c75326db4eb6cbd54c3e754fa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/HelloMessage.cs b/Runtime/Messages/HelloMessage.cs index 21546475..2cef07c7 100644 --- a/Runtime/Messages/HelloMessage.cs +++ b/Runtime/Messages/HelloMessage.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System; -using UnityEngine; namespace FutureBoxSystems.MpfMediaController { @@ -11,13 +10,13 @@ public class HelloMessage : EventArgs, ISentMessage private const string versionName = "version"; private const string controllerNameName = "controller_name"; private const string controllerVersionName = "controller_version"; - public string Version { get; private set; } + public string BcpSpecVersion { get; private set; } public string ControllerName { get; private set; } public string ControllerVersion { get; private set; } public HelloMessage(string version, string controllerName, string controllerVersion) { - Version = version; + BcpSpecVersion = version; ControllerName = controllerName; ControllerVersion = controllerVersion; } @@ -28,9 +27,9 @@ public BcpMessage ToGenericMessage() command: Command, parameters: new List() { - new(versionName, null, Version), - new(controllerNameName, null, ControllerName), - new(controllerVersionName, null, ControllerVersion) + new(versionName, BcpSpecVersion), + new(controllerNameName, ControllerName), + new(controllerVersionName, ControllerVersion) } ); } From 8f96868042e1b5081fb5f53e865d18f0eba570f3 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Fri, 18 Oct 2024 23:22:59 +0200 Subject: [PATCH 18/98] Fix incorrect receive end reason on cancellation --- Runtime/BcpServer.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Runtime/BcpServer.cs b/Runtime/BcpServer.cs index 764b02db..06fb4c81 100644 --- a/Runtime/BcpServer.cs +++ b/Runtime/BcpServer.cs @@ -162,7 +162,7 @@ private async Task CommunicateAsync(int port, CancellationToken ct) private async Task ReceiveMessagesAsync(NetworkStream stream, byte[] byteBuffer, StringBuilder stringBuffer, CancellationToken ct) { - while (stream.DataAvailable) + while (stream.DataAvailable && ct.IsCancellationRequested) { int numBytesRead; try @@ -192,6 +192,9 @@ private async Task ReceiveMessagesAsync(NetworkStream stream, } } + if (ct.IsCancellationRequested) + return ReceiveEndReason.Canceled; + return ReceiveEndReason.Finished; } From abe11f07c313f5557a9f5d477181b0b094331b1b Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Fri, 18 Oct 2024 23:29:32 +0200 Subject: [PATCH 19/98] Ignore messages that start with # or are empty --- Runtime/BcpServer.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Runtime/BcpServer.cs b/Runtime/BcpServer.cs index 06fb4c81..18afd6fe 100644 --- a/Runtime/BcpServer.cs +++ b/Runtime/BcpServer.cs @@ -186,9 +186,12 @@ private async Task ReceiveMessagesAsync(NetworkStream stream, var message = stringBuffer.ToString(0, messageLength); stringBuffer.Remove(0, messageLength + 1); message = Uri.UnescapeDataString(message); - var bcpMessage = BcpMessage.FromString(message); - lock (receivedMessagesLock) - receivedMessages.Enqueue(bcpMessage); + if (message.Length > 0 && !message.StartsWith("#")) + { + var bcpMessage = BcpMessage.FromString(message); + lock (receivedMessagesLock) + receivedMessages.Enqueue(bcpMessage); + } } } From 9e66882ef857e6ca8231643110a7603560073b8e Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sat, 19 Oct 2024 17:30:08 +0200 Subject: [PATCH 20/98] Add wrong parser exception --- Runtime/BcpMessage.cs | 9 ++++++++- Runtime/Messages/ErrorMessage.cs | 4 +++- Runtime/Messages/GoodbyeMessage.cs | 4 ++-- Runtime/Messages/HelloMessage.cs | 4 +++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Runtime/BcpMessage.cs b/Runtime/BcpMessage.cs index 544d514b..cc1ed08c 100644 --- a/Runtime/BcpMessage.cs +++ b/Runtime/BcpMessage.cs @@ -163,12 +163,19 @@ public class BcpParseException : Exception { public BcpMessage Culprit { get; private set; } - public BcpParseException(BcpMessage culprit, Exception innerException = null) : base($"Failed to parse bcp message: {culprit}", innerException) + public BcpParseException(BcpMessage culprit, Exception innerException = null, string failReason = null) + : base($"Failed to parse bcp message: '{culprit}' Reason: {(failReason ?? "None given")}", innerException) { Culprit = culprit; } } + public class WrongParserException : BcpParseException + { + public WrongParserException(BcpMessage culprit, string expectedCommand, string actualCommand, Exception innerException = null) + : base(culprit, innerException, $"Wrong parser chosen for message. Parser expected command type: {expectedCommand} Actual: {actualCommand}") { } + } + /// /// Most message types are only received and never sent. /// The ones that are sent must implement this interface diff --git a/Runtime/Messages/ErrorMessage.cs b/Runtime/Messages/ErrorMessage.cs index 9b9cfda0..4bbd380d 100644 --- a/Runtime/Messages/ErrorMessage.cs +++ b/Runtime/Messages/ErrorMessage.cs @@ -31,7 +31,9 @@ public BcpMessage ToGenericMessage() public static ErrorMessage FromGenericMessage(BcpMessage bcpMessage) { - return new( + if (bcpMessage.Command != Command) + throw new WrongParserException(bcpMessage, Command, bcpMessage.Command); + return new ErrorMessage( message: bcpMessage.FindParamValue(messageName), commandThatCausedError: bcpMessage.FindParamValue(commandThatCausedErrorName) ); diff --git a/Runtime/Messages/GoodbyeMessage.cs b/Runtime/Messages/GoodbyeMessage.cs index 552cd02e..d95321b3 100644 --- a/Runtime/Messages/GoodbyeMessage.cs +++ b/Runtime/Messages/GoodbyeMessage.cs @@ -9,8 +9,8 @@ public class GoodbyeMessage : EventArgs, ISentMessage public static GoodbyeMessage FromGenericMessage(BcpMessage bcpMessage) { if (bcpMessage.Command != Command) - throw new BcpParseException(bcpMessage); - return new(); + throw new WrongParserException(bcpMessage, Command, bcpMessage.Command); + return new GoodbyeMessage(); } } } \ No newline at end of file diff --git a/Runtime/Messages/HelloMessage.cs b/Runtime/Messages/HelloMessage.cs index 2cef07c7..c63218db 100644 --- a/Runtime/Messages/HelloMessage.cs +++ b/Runtime/Messages/HelloMessage.cs @@ -36,7 +36,9 @@ public BcpMessage ToGenericMessage() public static HelloMessage FromGenericMessage(BcpMessage bcpMessage) { - return new( + if (bcpMessage.Command != Command) + throw new WrongParserException(bcpMessage, Command, bcpMessage.Command); + return new HelloMessage( version: bcpMessage.FindParamValue(versionName), controllerName: bcpMessage.FindParamValue(controllerNameName), controllerVersion: bcpMessage.FindParamValue(controllerVersionName) From 273661a616c4294bd9a3fec1672c4fad497448bc Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sat, 19 Oct 2024 17:57:29 +0200 Subject: [PATCH 21/98] Fix receiving messages --- Runtime/BcpServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/BcpServer.cs b/Runtime/BcpServer.cs index 18afd6fe..4456d4a8 100644 --- a/Runtime/BcpServer.cs +++ b/Runtime/BcpServer.cs @@ -162,7 +162,7 @@ private async Task CommunicateAsync(int port, CancellationToken ct) private async Task ReceiveMessagesAsync(NetworkStream stream, byte[] byteBuffer, StringBuilder stringBuffer, CancellationToken ct) { - while (stream.DataAvailable && ct.IsCancellationRequested) + while (stream.DataAvailable && !ct.IsCancellationRequested) { int numBytesRead; try From ebd8fa63093d5975e1e8472dd43043cc955637e8 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sat, 19 Oct 2024 18:08:49 +0200 Subject: [PATCH 22/98] Refactor message handling again --- Runtime/BcpMessage.cs | 52 ------------------- Runtime/BcpMessageHandler.cs | 52 +++++++++++++++++++ ...lers.cs.meta => BcpMessageHandler.cs.meta} | 2 +- Runtime/BcpMessageHandlers.cs | 26 ---------- Runtime/Behaviours/DisconnectOnGoodbye.cs | 6 +-- Runtime/Behaviours/HelloResponse.cs | 6 +-- Runtime/MessageHandlers.meta | 8 +++ .../MessageHandlers/ErrorMessageHandler.cs | 8 +++ .../ErrorMessageHandler.cs.meta | 11 ++++ .../MessageHandlers/GoodbyeMessageHandler.cs | 8 +++ .../GoodbyeMessageHandler.cs.meta | 11 ++++ .../MessageHandlers/HelloMessageHandler.cs | 8 +++ .../HelloMessageHandler.cs.meta | 11 ++++ 13 files changed, 124 insertions(+), 85 deletions(-) create mode 100644 Runtime/BcpMessageHandler.cs rename Runtime/{BcpMessageHandlers.cs.meta => BcpMessageHandler.cs.meta} (83%) delete mode 100644 Runtime/BcpMessageHandlers.cs create mode 100644 Runtime/MessageHandlers.meta create mode 100644 Runtime/MessageHandlers/ErrorMessageHandler.cs create mode 100644 Runtime/MessageHandlers/ErrorMessageHandler.cs.meta create mode 100644 Runtime/MessageHandlers/GoodbyeMessageHandler.cs create mode 100644 Runtime/MessageHandlers/GoodbyeMessageHandler.cs.meta create mode 100644 Runtime/MessageHandlers/HelloMessageHandler.cs create mode 100644 Runtime/MessageHandlers/HelloMessageHandler.cs.meta diff --git a/Runtime/BcpMessage.cs b/Runtime/BcpMessage.cs index cc1ed08c..9791b59c 100644 --- a/Runtime/BcpMessage.cs +++ b/Runtime/BcpMessage.cs @@ -107,58 +107,6 @@ public static BcpParameter FromString(string str) } } - public class BcpMessageHandler where T : EventArgs - { - public string Command { get; private set; } - public delegate void Test(); - public delegate T ParseDelegate(BcpMessage genericMessage); - private event EventHandler commandReceived; - public event EventHandler Received - { - add - { - bool isFirstHandler = commandReceived == null; - commandReceived += value; - if (isFirstHandler) - FirstHandlerAdded?.Invoke(this, EventArgs.Empty); - } - remove - { - commandReceived -= value; - if (commandReceived == null) - LastHandlerRemoved?.Invoke(this, EventArgs.Empty); - } - } - - public event EventHandler FirstHandlerAdded; - public event EventHandler LastHandlerRemoved; - - private readonly BcpInterface bcpInterface; - private readonly ParseDelegate Parse; - - public BcpMessageHandler(string command, ParseDelegate parse, BcpInterface bcpInterface) - { - Command = command; - Parse = parse; - this.bcpInterface = bcpInterface; - bcpInterface.RegisterMessageHandler(Command, Handle); - } - - ~BcpMessageHandler() - { - if (bcpInterface != null) - bcpInterface.UnregisterMessageHandler(Command, Handle); - } - - private void Handle(BcpMessage message) - { - if (message.Command != Command) - throw new BcpParseException(message); - T specificMessage = Parse(message); - commandReceived?.Invoke(this, specificMessage); - } - } - public class BcpParseException : Exception { public BcpMessage Culprit { get; private set; } diff --git a/Runtime/BcpMessageHandler.cs b/Runtime/BcpMessageHandler.cs new file mode 100644 index 00000000..7be27fe9 --- /dev/null +++ b/Runtime/BcpMessageHandler.cs @@ -0,0 +1,52 @@ +using System; +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController +{ + public abstract class BcpMessageHandler : MonoBehaviour where T : EventArgs + { + [SerializeField] + protected BcpInterface bcpInterface; + + public abstract string Command { get; } + public virtual string MonitoringCategory => null; + protected abstract ParseDelegate Parse { get; } + public delegate T ParseDelegate(BcpMessage genericMessage); + private event EventHandler CommandReceived; + public event EventHandler Received + { + add + { + bool isFirstHandler = CommandReceived == null; + CommandReceived += value; + if (isFirstHandler && MonitoringCategory != null) + bcpInterface.AddMonitoringCategoryUser(MonitoringCategory); + } + remove + { + CommandReceived -= value; + if (CommandReceived == null && MonitoringCategory != null) + bcpInterface.RemoveMonitoringCategoryUser(MonitoringCategory); + } + } + + private void OnEnable() + { + bcpInterface.RegisterMessageHandler(Command, Handle); + } + + private void OnDisable() + { + if (bcpInterface != null) + bcpInterface.UnregisterMessageHandler(Command, Handle); + } + + private void Handle(BcpMessage message) + { + if (message.Command != Command) + throw new BcpParseException(message); + T specificMessage = Parse(message); + CommandReceived?.Invoke(this, specificMessage); + } + } +} \ No newline at end of file diff --git a/Runtime/BcpMessageHandlers.cs.meta b/Runtime/BcpMessageHandler.cs.meta similarity index 83% rename from Runtime/BcpMessageHandlers.cs.meta rename to Runtime/BcpMessageHandler.cs.meta index 09e95ef8..64c61d85 100644 --- a/Runtime/BcpMessageHandlers.cs.meta +++ b/Runtime/BcpMessageHandler.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 5af634c2dfa44ce4499cfbf44abee844 +guid: 779db86abf0cf624fa7560e7354bb0e1 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/BcpMessageHandlers.cs b/Runtime/BcpMessageHandlers.cs deleted file mode 100644 index f6797f4b..00000000 --- a/Runtime/BcpMessageHandlers.cs +++ /dev/null @@ -1,26 +0,0 @@ -using UnityEngine; - -namespace FutureBoxSystems.MpfMediaController -{ - public class BcpMessageHandlers : MonoBehaviour - { - [SerializeField] - private BcpInterface bcpInterface; - - private BcpMessageHandler hello; - public BcpMessageHandler Hello => hello ??= new(HelloMessage.Command, HelloMessage.FromGenericMessage, bcpInterface); - private BcpMessageHandler goodbye; - public BcpMessageHandler Goodbye => goodbye ??= new(GoodbyeMessage.Command, GoodbyeMessage.FromGenericMessage, bcpInterface); - - private void Awake() - { - // Initialize command handlers - // Lazy initialization using the property getters above is needed because - // event handlers may try to access them before this Awake function is called. - // Even if no event handlers subscribe, the message handlers still need to exist, - // because an error message is sent for each command for which no handler exists. - _ = Hello; - _ = Goodbye; - } - } -} \ No newline at end of file diff --git a/Runtime/Behaviours/DisconnectOnGoodbye.cs b/Runtime/Behaviours/DisconnectOnGoodbye.cs index 7cc7298c..019b30e5 100644 --- a/Runtime/Behaviours/DisconnectOnGoodbye.cs +++ b/Runtime/Behaviours/DisconnectOnGoodbye.cs @@ -7,16 +7,16 @@ public class DisconnectOnGoodbye : MonoBehaviour [SerializeField] BcpInterface bcpInterface; [SerializeField] - BcpMessageHandlers messageHandlers; + GoodbyeMessageHandler goodbyeHandler; private void OnEnable() { - messageHandlers.Goodbye.Received += GoodbyeMessageReceived; + goodbyeHandler.Received += GoodbyeMessageReceived; } private void OnDisable() { - messageHandlers.Goodbye.Received -= GoodbyeMessageReceived; + goodbyeHandler.Received -= GoodbyeMessageReceived; } private void GoodbyeMessageReceived(object sender, GoodbyeMessage message) diff --git a/Runtime/Behaviours/HelloResponse.cs b/Runtime/Behaviours/HelloResponse.cs index 7e25776d..d7359aed 100644 --- a/Runtime/Behaviours/HelloResponse.cs +++ b/Runtime/Behaviours/HelloResponse.cs @@ -7,17 +7,17 @@ public class HelloResponse : MonoBehaviour [SerializeField] private BcpInterface bcpInterface; [SerializeField] - private BcpMessageHandlers messageHandlers; + private HelloMessageHandler helloHandler; private void OnEnable() { - messageHandlers.Hello.Received += HelloMessageReceived; + helloHandler.Received += HelloMessageReceived; } private void OnDisable() { if (bcpInterface ) - messageHandlers.Hello.Received -= HelloMessageReceived; + helloHandler.Received -= HelloMessageReceived; } private void HelloMessageReceived(object sender, HelloMessage message) diff --git a/Runtime/MessageHandlers.meta b/Runtime/MessageHandlers.meta new file mode 100644 index 00000000..73e3bfd6 --- /dev/null +++ b/Runtime/MessageHandlers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7004fa09e6fdb884fbfe6ed0bf1316a9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/MessageHandlers/ErrorMessageHandler.cs b/Runtime/MessageHandlers/ErrorMessageHandler.cs new file mode 100644 index 00000000..c874b8f1 --- /dev/null +++ b/Runtime/MessageHandlers/ErrorMessageHandler.cs @@ -0,0 +1,8 @@ +namespace FutureBoxSystems.MpfMediaController +{ + public class ErrorMessageHandler : BcpMessageHandler + { + public override string Command => ErrorMessage.Command; + protected override ParseDelegate Parse => ErrorMessage.FromGenericMessage; + } +} \ No newline at end of file diff --git a/Runtime/MessageHandlers/ErrorMessageHandler.cs.meta b/Runtime/MessageHandlers/ErrorMessageHandler.cs.meta new file mode 100644 index 00000000..0c528229 --- /dev/null +++ b/Runtime/MessageHandlers/ErrorMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7fd1ee0333546544b9c3dea71e6c20a7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/MessageHandlers/GoodbyeMessageHandler.cs b/Runtime/MessageHandlers/GoodbyeMessageHandler.cs new file mode 100644 index 00000000..d1127e35 --- /dev/null +++ b/Runtime/MessageHandlers/GoodbyeMessageHandler.cs @@ -0,0 +1,8 @@ +namespace FutureBoxSystems.MpfMediaController +{ + public class GoodbyeMessageHandler : BcpMessageHandler + { + public override string Command => GoodbyeMessage.Command; + protected override ParseDelegate Parse => GoodbyeMessage.FromGenericMessage; + } +} \ No newline at end of file diff --git a/Runtime/MessageHandlers/GoodbyeMessageHandler.cs.meta b/Runtime/MessageHandlers/GoodbyeMessageHandler.cs.meta new file mode 100644 index 00000000..4a86ea50 --- /dev/null +++ b/Runtime/MessageHandlers/GoodbyeMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4ad4af17d27824a418620638a7c60d96 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/MessageHandlers/HelloMessageHandler.cs b/Runtime/MessageHandlers/HelloMessageHandler.cs new file mode 100644 index 00000000..9ba48881 --- /dev/null +++ b/Runtime/MessageHandlers/HelloMessageHandler.cs @@ -0,0 +1,8 @@ +namespace FutureBoxSystems.MpfMediaController +{ + public class HelloMessageHandler : BcpMessageHandler + { + public override string Command => HelloMessage.Command; + protected override ParseDelegate Parse => HelloMessage.FromGenericMessage; + } +} \ No newline at end of file diff --git a/Runtime/MessageHandlers/HelloMessageHandler.cs.meta b/Runtime/MessageHandlers/HelloMessageHandler.cs.meta new file mode 100644 index 00000000..57944f14 --- /dev/null +++ b/Runtime/MessageHandlers/HelloMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bf919a90a2e4ed040b8913ce8901228b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 0eea6bf532b3256704c42ced30e994c8d9163598 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sat, 19 Oct 2024 22:41:54 +0200 Subject: [PATCH 23/98] Improve parsing exceptions --- Runtime/BcpMessage.cs | 10 ++++++++-- Runtime/BcpMessageHandler.cs | 2 +- Runtime/Messages/ErrorMessage.cs | 2 -- Runtime/Messages/GoodbyeMessage.cs | 7 +------ Runtime/Messages/HelloMessage.cs | 4 +--- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Runtime/BcpMessage.cs b/Runtime/BcpMessage.cs index 9791b59c..25eac685 100644 --- a/Runtime/BcpMessage.cs +++ b/Runtime/BcpMessage.cs @@ -30,7 +30,7 @@ public string FindParamValue(string name, string typeHint = null) } catch (InvalidOperationException ioe) { - throw new BcpParseException(this, ioe); + throw new ParameterException(this, name, ioe); } } @@ -121,7 +121,13 @@ public BcpParseException(BcpMessage culprit, Exception innerException = null, st public class WrongParserException : BcpParseException { public WrongParserException(BcpMessage culprit, string expectedCommand, string actualCommand, Exception innerException = null) - : base(culprit, innerException, $"Wrong parser chosen for message. Parser expected command type: {expectedCommand} Actual: {actualCommand}") { } + : base(culprit, innerException, $"Wrong parser chosen for message. Parser expected command type: '{expectedCommand}' Actual: '{actualCommand}'") { } + } + + public class ParameterException : BcpParseException + { + public ParameterException(BcpMessage culprit, string parameterName, Exception innerException = null) + : base(culprit, innerException, $"Missing or invalid parameter '{parameterName}'") { } } /// diff --git a/Runtime/BcpMessageHandler.cs b/Runtime/BcpMessageHandler.cs index 7be27fe9..8886b7b2 100644 --- a/Runtime/BcpMessageHandler.cs +++ b/Runtime/BcpMessageHandler.cs @@ -44,7 +44,7 @@ private void OnDisable() private void Handle(BcpMessage message) { if (message.Command != Command) - throw new BcpParseException(message); + throw new WrongParserException(message, Command, message.Command); T specificMessage = Parse(message); CommandReceived?.Invoke(this, specificMessage); } diff --git a/Runtime/Messages/ErrorMessage.cs b/Runtime/Messages/ErrorMessage.cs index 4bbd380d..26ccbf2e 100644 --- a/Runtime/Messages/ErrorMessage.cs +++ b/Runtime/Messages/ErrorMessage.cs @@ -31,8 +31,6 @@ public BcpMessage ToGenericMessage() public static ErrorMessage FromGenericMessage(BcpMessage bcpMessage) { - if (bcpMessage.Command != Command) - throw new WrongParserException(bcpMessage, Command, bcpMessage.Command); return new ErrorMessage( message: bcpMessage.FindParamValue(messageName), commandThatCausedError: bcpMessage.FindParamValue(commandThatCausedErrorName) diff --git a/Runtime/Messages/GoodbyeMessage.cs b/Runtime/Messages/GoodbyeMessage.cs index d95321b3..779f84d3 100644 --- a/Runtime/Messages/GoodbyeMessage.cs +++ b/Runtime/Messages/GoodbyeMessage.cs @@ -6,11 +6,6 @@ public class GoodbyeMessage : EventArgs, ISentMessage { public const string Command = "goodbye"; public BcpMessage ToGenericMessage() => new(Command); - public static GoodbyeMessage FromGenericMessage(BcpMessage bcpMessage) - { - if (bcpMessage.Command != Command) - throw new WrongParserException(bcpMessage, Command, bcpMessage.Command); - return new GoodbyeMessage(); - } + public static GoodbyeMessage FromGenericMessage(BcpMessage _) => new(); } } \ No newline at end of file diff --git a/Runtime/Messages/HelloMessage.cs b/Runtime/Messages/HelloMessage.cs index c63218db..61b31b7f 100644 --- a/Runtime/Messages/HelloMessage.cs +++ b/Runtime/Messages/HelloMessage.cs @@ -36,13 +36,11 @@ public BcpMessage ToGenericMessage() public static HelloMessage FromGenericMessage(BcpMessage bcpMessage) { - if (bcpMessage.Command != Command) - throw new WrongParserException(bcpMessage, Command, bcpMessage.Command); return new HelloMessage( version: bcpMessage.FindParamValue(versionName), controllerName: bcpMessage.FindParamValue(controllerNameName), controllerVersion: bcpMessage.FindParamValue(controllerVersionName) - ); + ); } } } \ No newline at end of file From c54fba7740838cf1bcf5109188c8692fa419f485 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 20 Oct 2024 10:34:59 +0200 Subject: [PATCH 24/98] Fix message encoding --- Runtime/BcpMessage.cs | 6 ++++-- Runtime/BcpServer.cs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Runtime/BcpMessage.cs b/Runtime/BcpMessage.cs index 25eac685..83deb3ca 100644 --- a/Runtime/BcpMessage.cs +++ b/Runtime/BcpMessage.cs @@ -78,9 +78,11 @@ public BcpParameter(string name, string value, string typeHint = null) public override string ToString() { + var nameEncoded = Uri.EscapeDataString(Name); + var valueEncoded = Uri.EscapeDataString(Value); if (string.IsNullOrEmpty(TypeHint)) - return $"{Name}={Value}"; - return $"{Name}={TypeHint}:{Value}"; + return $"{nameEncoded}={valueEncoded}"; + return $"{nameEncoded}={TypeHint}:{valueEncoded}"; } public bool MatchesPattern(string name, string typeHint) diff --git a/Runtime/BcpServer.cs b/Runtime/BcpServer.cs index 4456d4a8..a23849b1 100644 --- a/Runtime/BcpServer.cs +++ b/Runtime/BcpServer.cs @@ -206,7 +206,7 @@ private async Task SendMessagesAsync(NetworkStream stream, CancellationToken ct) while (!ct.IsCancellationRequested && TryDequeueOutboundMessage(out BcpMessage bcpMessage)) { var stringMessage = bcpMessage.ToString(); - stringMessage = Uri.EscapeDataString(stringMessage); + stringMessage += "\n"; var packet = Encoding.UTF8.GetBytes(stringMessage); try { From c9443fe2aef6a032c542400a01f9802c8cab33d1 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 20 Oct 2024 11:28:05 +0200 Subject: [PATCH 25/98] Handle reset --- Runtime/BcpMessageHandler.cs | 5 +++++ Runtime/MessageHandlers/ResetMessageHandler.cs | 14 ++++++++++++++ .../MessageHandlers/ResetMessageHandler.cs.meta | 11 +++++++++++ Runtime/Messages/ResetCompleteMessage.cs | 11 +++++++++++ Runtime/Messages/ResetCompleteMessage.cs.meta | 11 +++++++++++ Runtime/Messages/ResetMessage.cs | 11 +++++++++++ Runtime/Messages/ResetMessage.cs.meta | 11 +++++++++++ 7 files changed, 74 insertions(+) create mode 100644 Runtime/MessageHandlers/ResetMessageHandler.cs create mode 100644 Runtime/MessageHandlers/ResetMessageHandler.cs.meta create mode 100644 Runtime/Messages/ResetCompleteMessage.cs create mode 100644 Runtime/Messages/ResetCompleteMessage.cs.meta create mode 100644 Runtime/Messages/ResetMessage.cs create mode 100644 Runtime/Messages/ResetMessage.cs.meta diff --git a/Runtime/BcpMessageHandler.cs b/Runtime/BcpMessageHandler.cs index 8886b7b2..715d7cff 100644 --- a/Runtime/BcpMessageHandler.cs +++ b/Runtime/BcpMessageHandler.cs @@ -46,7 +46,12 @@ private void Handle(BcpMessage message) if (message.Command != Command) throw new WrongParserException(message, Command, message.Command); T specificMessage = Parse(message); + BeforeEvent(); CommandReceived?.Invoke(this, specificMessage); + AfterEvent(); } + + protected virtual void BeforeEvent() { } + protected virtual void AfterEvent() { } } } \ No newline at end of file diff --git a/Runtime/MessageHandlers/ResetMessageHandler.cs b/Runtime/MessageHandlers/ResetMessageHandler.cs new file mode 100644 index 00000000..41fee764 --- /dev/null +++ b/Runtime/MessageHandlers/ResetMessageHandler.cs @@ -0,0 +1,14 @@ +namespace FutureBoxSystems.MpfMediaController +{ + public class ResetMessageHandler : BcpMessageHandler + { + public override string Command => ResetMessage.Command; + protected override ParseDelegate Parse => ResetMessage.FromGenericMessage; + + protected override void AfterEvent() + { + base.AfterEvent(); + bcpInterface.TrySendMessage(new ResetCompleteMessage()); + } + } +} \ No newline at end of file diff --git a/Runtime/MessageHandlers/ResetMessageHandler.cs.meta b/Runtime/MessageHandlers/ResetMessageHandler.cs.meta new file mode 100644 index 00000000..d2d75a8b --- /dev/null +++ b/Runtime/MessageHandlers/ResetMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 587867a0f90cc0947a58c70dd2a7eff6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/ResetCompleteMessage.cs b/Runtime/Messages/ResetCompleteMessage.cs new file mode 100644 index 00000000..4f3f40f1 --- /dev/null +++ b/Runtime/Messages/ResetCompleteMessage.cs @@ -0,0 +1,11 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController +{ + public class ResetCompleteMessage : EventArgs, ISentMessage + { + public const string Command = "reset_complete"; + public static ResetCompleteMessage FromGenericMessage(BcpMessage _) => new(); + public BcpMessage ToGenericMessage() => new(Command); + } +} \ No newline at end of file diff --git a/Runtime/Messages/ResetCompleteMessage.cs.meta b/Runtime/Messages/ResetCompleteMessage.cs.meta new file mode 100644 index 00000000..25a01f27 --- /dev/null +++ b/Runtime/Messages/ResetCompleteMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fc75fcf4f306b8c44ab7fbd927bfd13a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/ResetMessage.cs b/Runtime/Messages/ResetMessage.cs new file mode 100644 index 00000000..f6ba660a --- /dev/null +++ b/Runtime/Messages/ResetMessage.cs @@ -0,0 +1,11 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController +{ + public class ResetMessage : EventArgs + { + public const string Command = "reset"; + public static ResetMessage FromGenericMessage(BcpMessage _) => new(); + + } +} \ No newline at end of file diff --git a/Runtime/Messages/ResetMessage.cs.meta b/Runtime/Messages/ResetMessage.cs.meta new file mode 100644 index 00000000..0c96a86a --- /dev/null +++ b/Runtime/Messages/ResetMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 020f4b1b2b99c434d8181f652af0aed4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 49ec73bad9e229eccd28259b3be57fcbf2df8060 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 20 Oct 2024 11:29:45 +0200 Subject: [PATCH 26/98] Minor fixes --- Runtime/BcpServer.cs | 2 -- Runtime/Behaviours/DisconnectOnGoodbye.cs | 3 ++- Runtime/Behaviours/HelloResponse.cs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Runtime/BcpServer.cs b/Runtime/BcpServer.cs index a23849b1..6cd8da2e 100644 --- a/Runtime/BcpServer.cs +++ b/Runtime/BcpServer.cs @@ -5,8 +5,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using System.Web; -using UnityEngine.Networking; namespace FutureBoxSystems.MpfMediaController { diff --git a/Runtime/Behaviours/DisconnectOnGoodbye.cs b/Runtime/Behaviours/DisconnectOnGoodbye.cs index 019b30e5..a2715fec 100644 --- a/Runtime/Behaviours/DisconnectOnGoodbye.cs +++ b/Runtime/Behaviours/DisconnectOnGoodbye.cs @@ -16,7 +16,8 @@ private void OnEnable() private void OnDisable() { - goodbyeHandler.Received -= GoodbyeMessageReceived; + if (goodbyeHandler) + goodbyeHandler.Received -= GoodbyeMessageReceived; } private void GoodbyeMessageReceived(object sender, GoodbyeMessage message) diff --git a/Runtime/Behaviours/HelloResponse.cs b/Runtime/Behaviours/HelloResponse.cs index d7359aed..c85ce2f9 100644 --- a/Runtime/Behaviours/HelloResponse.cs +++ b/Runtime/Behaviours/HelloResponse.cs @@ -16,7 +16,7 @@ private void OnEnable() private void OnDisable() { - if (bcpInterface ) + if (helloHandler) helloHandler.Received -= HelloMessageReceived; } From 67ac703826c5ea170f2a010a4836930d4ed3a095 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 20 Oct 2024 11:30:43 +0200 Subject: [PATCH 27/98] Use enum for monitoring categories --- Runtime/BcpInterface.cs | 39 +++++++++++++++++++ Runtime/BcpMessageHandler.cs | 6 +-- Runtime/Messages/MonitorStartMessage.cs | 29 ++++++++++++++ Runtime/Messages/MonitorStartMessage.cs.meta | 11 ++++++ Runtime/Messages/MonitorStopMessage.cs | 29 ++++++++++++++ Runtime/Messages/MonitorStopMessage.cs.meta | 11 ++++++ Runtime/Messages/ParameterTypes.meta | 8 ++++ .../ParameterTypes/MonitoringCategory.cs | 20 ++++++++++ .../ParameterTypes/MonitoringCategory.cs.meta | 11 ++++++ Runtime/Utils.meta | 8 ++++ Runtime/Utils/StringEnum.cs | 30 ++++++++++++++ Runtime/Utils/StringEnum.cs.meta | 11 ++++++ 12 files changed, 210 insertions(+), 3 deletions(-) create mode 100644 Runtime/Messages/MonitorStartMessage.cs create mode 100644 Runtime/Messages/MonitorStartMessage.cs.meta create mode 100644 Runtime/Messages/MonitorStopMessage.cs create mode 100644 Runtime/Messages/MonitorStopMessage.cs.meta create mode 100644 Runtime/Messages/ParameterTypes.meta create mode 100644 Runtime/Messages/ParameterTypes/MonitoringCategory.cs create mode 100644 Runtime/Messages/ParameterTypes/MonitoringCategory.cs.meta create mode 100644 Runtime/Utils.meta create mode 100644 Runtime/Utils/StringEnum.cs create mode 100644 Runtime/Utils/StringEnum.cs.meta diff --git a/Runtime/BcpInterface.cs b/Runtime/BcpInterface.cs index 3d869174..22fbcadd 100644 --- a/Runtime/BcpInterface.cs +++ b/Runtime/BcpInterface.cs @@ -18,6 +18,7 @@ public class BcpInterface : MonoBehaviour public delegate void HandleMessage(BcpMessage message); private readonly Dictionary messageHandlers = new(); + private readonly Dictionary monitoringCategoryUserCounts = new(); public void RegisterMessageHandler(string command, HandleMessage handle) { @@ -33,6 +34,27 @@ public void UnregisterMessageHandler(string command, HandleMessage handle) Debug.LogWarning($"[BcpInterface] Cannot remove message handler for command '{command}', because it is not registered."); } + public void AddMonitoringCategoryUser(MonitoringCategory category) + { + if (!monitoringCategoryUserCounts.TryAdd(category, 1)) + monitoringCategoryUserCounts[category]++; + + if (monitoringCategoryUserCounts[category] == 1) + TrySendMessage(new MonitorStartMessage(category)); + } + + public void RemoveMonitoringCategoryUser(MonitoringCategory category) + { + if (monitoringCategoryUserCounts.TryGetValue(category, out var userCount)) + { + if (userCount > 0) + monitoringCategoryUserCounts[category]--; + + if (monitoringCategoryUserCounts[category] == 0) + TrySendMessage(new MonitorStopMessage(category)); + } + } + public bool TrySendMessage(ISentMessage message) { if (ConnectionState == ConnectionState.Connected) @@ -53,9 +75,25 @@ public void RequestDisconnect() private async void OnEnable() { server ??= new BcpServer(port); + server.StateChanged += HandleServerStateChanged; await server.OpenConnectionAsync(); } + private void HandleServerStateChanged(object sender, ConnectionStateChangedEventArgs e) + { + bool hasJustConnected = e.CurrentState == ConnectionState.Connected; + if (hasJustConnected) + { + foreach (KeyValuePair kvp in monitoringCategoryUserCounts) + { + MonitoringCategory category = kvp.Key; + int userCount = kvp.Value; + if (userCount > 0) + TrySendMessage(new MonitorStartMessage(category)); + } + } + } + private void Update() { float startTime = Time.unscaledTime; @@ -91,6 +129,7 @@ private void HandleReceivedMessage(BcpMessage message) private async void OnDisable() { await server.CloseConnectionAsync(); + server.StateChanged -= HandleServerStateChanged; } } } \ No newline at end of file diff --git a/Runtime/BcpMessageHandler.cs b/Runtime/BcpMessageHandler.cs index 715d7cff..5a56c439 100644 --- a/Runtime/BcpMessageHandler.cs +++ b/Runtime/BcpMessageHandler.cs @@ -9,7 +9,7 @@ public abstract class BcpMessageHandler : MonoBehaviour where T : EventArgs protected BcpInterface bcpInterface; public abstract string Command { get; } - public virtual string MonitoringCategory => null; + public virtual MonitoringCategory MonitoringCategory => MonitoringCategory.None; protected abstract ParseDelegate Parse { get; } public delegate T ParseDelegate(BcpMessage genericMessage); private event EventHandler CommandReceived; @@ -19,13 +19,13 @@ public event EventHandler Received { bool isFirstHandler = CommandReceived == null; CommandReceived += value; - if (isFirstHandler && MonitoringCategory != null) + if (isFirstHandler && MonitoringCategory != MonitoringCategory.None) bcpInterface.AddMonitoringCategoryUser(MonitoringCategory); } remove { CommandReceived -= value; - if (CommandReceived == null && MonitoringCategory != null) + if (CommandReceived == null && MonitoringCategory != MonitoringCategory.None) bcpInterface.RemoveMonitoringCategoryUser(MonitoringCategory); } } diff --git a/Runtime/Messages/MonitorStartMessage.cs b/Runtime/Messages/MonitorStartMessage.cs new file mode 100644 index 00000000..8894c235 --- /dev/null +++ b/Runtime/Messages/MonitorStartMessage.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController +{ + public class MonitorStartMessage : EventArgs, ISentMessage + { + public const string Command = "monitor_start"; + private const string categoryName = "category"; + public MonitoringCategory Category { get; private set; } + + public MonitorStartMessage(MonitoringCategory category) + { + Category = category; + } + + public BcpMessage ToGenericMessage() + { + var categoryString = Category.GetStringValue(); + if (string.IsNullOrEmpty(categoryString)) + Debug.LogError("[MonitorStartMessage] Cannot create proper BCP message because monitoring category has no associated string value"); + return new( + command: Command, + parameters: new List() { new(categoryName, categoryString) } + ); + } + } +} diff --git a/Runtime/Messages/MonitorStartMessage.cs.meta b/Runtime/Messages/MonitorStartMessage.cs.meta new file mode 100644 index 00000000..98e41906 --- /dev/null +++ b/Runtime/Messages/MonitorStartMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2544466f61e07c444b41ad614349e7c0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/MonitorStopMessage.cs b/Runtime/Messages/MonitorStopMessage.cs new file mode 100644 index 00000000..48c9ff18 --- /dev/null +++ b/Runtime/Messages/MonitorStopMessage.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController +{ + public class MonitorStopMessage : EventArgs, ISentMessage + { + public const string Command = "monitor_stop"; + private const string categoryName = "category"; + public MonitoringCategory Category { get; private set; } + + public MonitorStopMessage(MonitoringCategory category) + { + Category = category; + } + + public BcpMessage ToGenericMessage() + { + var categoryString = Category.GetStringValue(); + if (string.IsNullOrEmpty(categoryString)) + Debug.LogError("[MonitorStopMessage] Cannot create proper BCP message because monitoring category has no associated string value"); + return new BcpMessage( + command: Command, + parameters: new List() { new(categoryName, categoryString) } + ); + } + } +} diff --git a/Runtime/Messages/MonitorStopMessage.cs.meta b/Runtime/Messages/MonitorStopMessage.cs.meta new file mode 100644 index 00000000..cbd6317b --- /dev/null +++ b/Runtime/Messages/MonitorStopMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e965141661ce4e34d866edb3ebcbab7d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/ParameterTypes.meta b/Runtime/Messages/ParameterTypes.meta new file mode 100644 index 00000000..1186d488 --- /dev/null +++ b/Runtime/Messages/ParameterTypes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3b8b640f628374647a20797376f57be4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/ParameterTypes/MonitoringCategory.cs b/Runtime/Messages/ParameterTypes/MonitoringCategory.cs new file mode 100644 index 00000000..62b2b32d --- /dev/null +++ b/Runtime/Messages/ParameterTypes/MonitoringCategory.cs @@ -0,0 +1,20 @@ +namespace FutureBoxSystems.MpfMediaController +{ + public enum MonitoringCategory + { + [StringValue(null)] + None, + [StringValue("events")] + Events, + [StringValue("machine_vars")] + MachineVars, + [StringValue("player_vars")] + PlayerVars, + [StringValue("switches")] + Switches, + [StringValue("modes")] + Modes, + [StringValue("core_events")] + CoreEvents + } +} \ No newline at end of file diff --git a/Runtime/Messages/ParameterTypes/MonitoringCategory.cs.meta b/Runtime/Messages/ParameterTypes/MonitoringCategory.cs.meta new file mode 100644 index 00000000..8bc189ee --- /dev/null +++ b/Runtime/Messages/ParameterTypes/MonitoringCategory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9ba83e4021231d04486550c83c1e7e95 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Utils.meta b/Runtime/Utils.meta new file mode 100644 index 00000000..2b11efca --- /dev/null +++ b/Runtime/Utils.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c262253ca8a8fb94f8bf462db41dbf65 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Utils/StringEnum.cs b/Runtime/Utils/StringEnum.cs new file mode 100644 index 00000000..0aa8e75a --- /dev/null +++ b/Runtime/Utils/StringEnum.cs @@ -0,0 +1,30 @@ +// Enum to string mapping +// Source: https://weblogs.asp.net/stefansedich/enum-with-string-values-in-c + +using System; +using System.Reflection; + +namespace FutureBoxSystems.MpfMediaController +{ + [AttributeUsage(AttributeTargets.Field)] + public class StringValueAttribute : Attribute + { + public string StringValue { get; protected set; } + + public StringValueAttribute(string value) + { + StringValue = value; + } + } + + public static class EnumExtension + { + public static string GetStringValue(this Enum value) + { + Type type = value.GetType(); + FieldInfo fieldInfo = type.GetField(value.ToString()); + StringValueAttribute attribute = fieldInfo.GetCustomAttribute(); + return attribute.StringValue ?? null; + } + } +} \ No newline at end of file diff --git a/Runtime/Utils/StringEnum.cs.meta b/Runtime/Utils/StringEnum.cs.meta new file mode 100644 index 00000000..cae554df --- /dev/null +++ b/Runtime/Utils/StringEnum.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9cd0da66fcc02924da27adaab482262e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 0d85d456db8610113d38324c26f3b9cb277d5bd5 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 20 Oct 2024 11:31:48 +0200 Subject: [PATCH 28/98] Handle ball start and end messages --- Runtime/MessageHandlers/BallEndMessageHandler.cs | 9 +++++++++ Runtime/MessageHandlers/BallEndMessageHandler.cs.meta | 11 +++++++++++ Runtime/MessageHandlers/BallStartMessageHandler.cs | 9 +++++++++ .../MessageHandlers/BallStartMessageHandler.cs.meta | 11 +++++++++++ Runtime/Messages/BallEndMessage.cs | 10 ++++++++++ Runtime/Messages/BallEndMessage.cs.meta | 11 +++++++++++ Runtime/Messages/BallStartMessage.cs | 10 ++++++++++ Runtime/Messages/BallStartMessage.cs.meta | 11 +++++++++++ 8 files changed, 82 insertions(+) create mode 100644 Runtime/MessageHandlers/BallEndMessageHandler.cs create mode 100644 Runtime/MessageHandlers/BallEndMessageHandler.cs.meta create mode 100644 Runtime/MessageHandlers/BallStartMessageHandler.cs create mode 100644 Runtime/MessageHandlers/BallStartMessageHandler.cs.meta create mode 100644 Runtime/Messages/BallEndMessage.cs create mode 100644 Runtime/Messages/BallEndMessage.cs.meta create mode 100644 Runtime/Messages/BallStartMessage.cs create mode 100644 Runtime/Messages/BallStartMessage.cs.meta diff --git a/Runtime/MessageHandlers/BallEndMessageHandler.cs b/Runtime/MessageHandlers/BallEndMessageHandler.cs new file mode 100644 index 00000000..d493c115 --- /dev/null +++ b/Runtime/MessageHandlers/BallEndMessageHandler.cs @@ -0,0 +1,9 @@ +namespace FutureBoxSystems.MpfMediaController +{ + public class BallEndMessageHandler : BcpMessageHandler + { + public override string Command => BallEndMessage.Command; + protected override ParseDelegate Parse => BallEndMessage.FromGenericMessage; + public override MonitoringCategory MonitoringCategory => MonitoringCategory.CoreEvents; + } +} \ No newline at end of file diff --git a/Runtime/MessageHandlers/BallEndMessageHandler.cs.meta b/Runtime/MessageHandlers/BallEndMessageHandler.cs.meta new file mode 100644 index 00000000..7ce11590 --- /dev/null +++ b/Runtime/MessageHandlers/BallEndMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 63f2dd8dbb07c27498726c42cff3d4e7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/MessageHandlers/BallStartMessageHandler.cs b/Runtime/MessageHandlers/BallStartMessageHandler.cs new file mode 100644 index 00000000..8b12761c --- /dev/null +++ b/Runtime/MessageHandlers/BallStartMessageHandler.cs @@ -0,0 +1,9 @@ +namespace FutureBoxSystems.MpfMediaController +{ + public class BallStartMessageHandler : BcpMessageHandler + { + public override string Command => BallStartMessage.Command; + protected override ParseDelegate Parse => BallStartMessage.FromGenericMessage; + public override MonitoringCategory MonitoringCategory => MonitoringCategory.CoreEvents; + } +} \ No newline at end of file diff --git a/Runtime/MessageHandlers/BallStartMessageHandler.cs.meta b/Runtime/MessageHandlers/BallStartMessageHandler.cs.meta new file mode 100644 index 00000000..49fa3964 --- /dev/null +++ b/Runtime/MessageHandlers/BallStartMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 359cce4f412e2f24cad70a4f570fac5e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/BallEndMessage.cs b/Runtime/Messages/BallEndMessage.cs new file mode 100644 index 00000000..644c587b --- /dev/null +++ b/Runtime/Messages/BallEndMessage.cs @@ -0,0 +1,10 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController +{ + public class BallEndMessage : EventArgs + { + public const string Command = "ball_end"; + public static BallEndMessage FromGenericMessage(BcpMessage _) => new(); + } +} \ No newline at end of file diff --git a/Runtime/Messages/BallEndMessage.cs.meta b/Runtime/Messages/BallEndMessage.cs.meta new file mode 100644 index 00000000..da077f56 --- /dev/null +++ b/Runtime/Messages/BallEndMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 107ae65cec2e7fe41ae0a5d3388c8425 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/BallStartMessage.cs b/Runtime/Messages/BallStartMessage.cs new file mode 100644 index 00000000..5f42a813 --- /dev/null +++ b/Runtime/Messages/BallStartMessage.cs @@ -0,0 +1,10 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController +{ + public class BallStartMessage : EventArgs + { + public const string Command = "ball_start"; + public static BallStartMessage FromGenericMessage(BcpMessage _) => new(); + } +} \ No newline at end of file diff --git a/Runtime/Messages/BallStartMessage.cs.meta b/Runtime/Messages/BallStartMessage.cs.meta new file mode 100644 index 00000000..50fb52fc --- /dev/null +++ b/Runtime/Messages/BallStartMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 64f576f357622fc4f9e20873155d7ea1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 1037e91ca001371791a6de0435d93f8add1db275 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 20 Oct 2024 11:32:01 +0200 Subject: [PATCH 29/98] Add interface prefab --- Runtime/BcpInterface.prefab | 226 +++++++++++++++++++++++++++++++ Runtime/BcpInterface.prefab.meta | 7 + 2 files changed, 233 insertions(+) create mode 100644 Runtime/BcpInterface.prefab create mode 100644 Runtime/BcpInterface.prefab.meta diff --git a/Runtime/BcpInterface.prefab b/Runtime/BcpInterface.prefab new file mode 100644 index 00000000..767c09cd --- /dev/null +++ b/Runtime/BcpInterface.prefab @@ -0,0 +1,226 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &4502278156144720521 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 4470853328188805554} + - component: {fileID: 8178360348569921075} + - component: {fileID: 2199375185222848247} + - component: {fileID: 615776641453573451} + - component: {fileID: 1824319182504738973} + - component: {fileID: 3006042140711521680} + - component: {fileID: 4146686170121310886} + m_Layer: 0 + m_Name: MessageHandlers + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4470853328188805554 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1626325481512189649} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &8178360348569921075 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bf919a90a2e4ed040b8913ce8901228b, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &2199375185222848247 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4ad4af17d27824a418620638a7c60d96, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &615776641453573451 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7fd1ee0333546544b9c3dea71e6c20a7, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &1824319182504738973 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 359cce4f412e2f24cad70a4f570fac5e, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &3006042140711521680 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 63f2dd8dbb07c27498726c42cff3d4e7, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &4146686170121310886 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 587867a0f90cc0947a58c70dd2a7eff6, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} +--- !u!1 &7214112112941309933 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1626325481512189649} + - component: {fileID: 3405300645593462295} + m_Layer: 0 + m_Name: BcpInterface + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1626325481512189649 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7214112112941309933} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 4470853328188805554} + - {fileID: 146168304089640666} + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &3405300645593462295 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7214112112941309933} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 51b9336ad819de34399a83bd1df10416, type: 3} + m_Name: + m_EditorClassIdentifier: + port: 5050 + frameTimeBudgetMs: 3 +--- !u!1 &8567879373765849912 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 146168304089640666} + - component: {fileID: 2143735940723918985} + - component: {fileID: 6877878494961934022} + m_Layer: 0 + m_Name: Behaviours + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &146168304089640666 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8567879373765849912} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1626325481512189649} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &2143735940723918985 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8567879373765849912} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d38f5f799b1bc354c9f85833a5c6c3ba, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} + helloHandler: {fileID: 8178360348569921075} +--- !u!114 &6877878494961934022 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8567879373765849912} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: cf6e722a91a3eed43b7d8f5cf8f929ac, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} + goodbyeHandler: {fileID: 2199375185222848247} diff --git a/Runtime/BcpInterface.prefab.meta b/Runtime/BcpInterface.prefab.meta new file mode 100644 index 00000000..b5fc14a7 --- /dev/null +++ b/Runtime/BcpInterface.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c159df8f8248f404092a7c9def99e852 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From f6dc914cfe0de7b72a742807b14694285e2c4d0d Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 20 Oct 2024 22:27:48 +0200 Subject: [PATCH 30/98] Add reverse mapping to string enum --- Runtime/Utils/StringEnum.cs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/Runtime/Utils/StringEnum.cs b/Runtime/Utils/StringEnum.cs index 0aa8e75a..bf37b008 100644 --- a/Runtime/Utils/StringEnum.cs +++ b/Runtime/Utils/StringEnum.cs @@ -1,5 +1,5 @@ -// Enum to string mapping -// Source: https://weblogs.asp.net/stefansedich/enum-with-string-values-in-c +// Maps enum values to arbitrary strings and back using a custom attribute +// Based on: https://weblogs.asp.net/stefansedich/enum-with-string-values-in-c using System; using System.Reflection; @@ -17,14 +17,36 @@ public StringValueAttribute(string value) } } - public static class EnumExtension + public static class StringEnum { public static string GetStringValue(this Enum value) { Type type = value.GetType(); FieldInfo fieldInfo = type.GetField(value.ToString()); StringValueAttribute attribute = fieldInfo.GetCustomAttribute(); - return attribute.StringValue ?? null; + return attribute.StringValue; + } + + public static T GetValueFromString(string value) where T : Enum + { + Type enumType = typeof(T); + if (!enumType.IsEnum) + { + throw new ArgumentException($"{enumType} is not an enum type."); + } + + foreach (var field in enumType.GetFields(BindingFlags.Public | BindingFlags.Static)) + { + if (Attribute.GetCustomAttribute(field, typeof(StringValueAttribute)) is StringValueAttribute attribute) + { + if (attribute.StringValue == value) + { + return (T)field.GetValue(null); + } + } + } + + throw new ArgumentException($"No enum value with the string value '{value}' found."); } } } \ No newline at end of file From 28cbc6bd1a772d9d2d8cf33322db4b2f9f13de0d Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 20 Oct 2024 22:29:13 +0200 Subject: [PATCH 31/98] Replace some properties with read-only fields --- Runtime/Messages/HelloMessage.cs | 6 +++--- Runtime/Messages/MonitorStartMessage.cs | 2 +- Runtime/Messages/MonitorStopMessage.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Runtime/Messages/HelloMessage.cs b/Runtime/Messages/HelloMessage.cs index 61b31b7f..00b9aba6 100644 --- a/Runtime/Messages/HelloMessage.cs +++ b/Runtime/Messages/HelloMessage.cs @@ -10,9 +10,9 @@ public class HelloMessage : EventArgs, ISentMessage private const string versionName = "version"; private const string controllerNameName = "controller_name"; private const string controllerVersionName = "controller_version"; - public string BcpSpecVersion { get; private set; } - public string ControllerName { get; private set; } - public string ControllerVersion { get; private set; } + public readonly string BcpSpecVersion; + public readonly string ControllerName; + public readonly string ControllerVersion; public HelloMessage(string version, string controllerName, string controllerVersion) { diff --git a/Runtime/Messages/MonitorStartMessage.cs b/Runtime/Messages/MonitorStartMessage.cs index 8894c235..1b16f5b6 100644 --- a/Runtime/Messages/MonitorStartMessage.cs +++ b/Runtime/Messages/MonitorStartMessage.cs @@ -8,7 +8,7 @@ public class MonitorStartMessage : EventArgs, ISentMessage { public const string Command = "monitor_start"; private const string categoryName = "category"; - public MonitoringCategory Category { get; private set; } + public readonly MonitoringCategory Category; public MonitorStartMessage(MonitoringCategory category) { diff --git a/Runtime/Messages/MonitorStopMessage.cs b/Runtime/Messages/MonitorStopMessage.cs index 48c9ff18..e1a63ff2 100644 --- a/Runtime/Messages/MonitorStopMessage.cs +++ b/Runtime/Messages/MonitorStopMessage.cs @@ -8,7 +8,7 @@ public class MonitorStopMessage : EventArgs, ISentMessage { public const string Command = "monitor_stop"; private const string categoryName = "category"; - public MonitoringCategory Category { get; private set; } + public readonly MonitoringCategory Category; public MonitorStopMessage(MonitoringCategory category) { From 239ff282881623a8c9e49284b2267a2bd2ae52e7 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:24:04 +0200 Subject: [PATCH 32/98] Add device message parsing commit e6f52b7ca9f4b13f22232fa5f53b6a93f7d373b2 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu Oct 24 20:55:42 2024 +0200 Fix parameter parsing commit b8d28d251802eef2ba65110b0f8dd294eebb5113 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu Oct 24 20:32:11 2024 +0200 Add light device type commit 137f685a477851d0684f95dfd80f5e99cfb5a7b1 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu Oct 24 20:31:58 2024 +0200 Rename state changed event commit 3c653c54afac5162107f8b6018fa1bf38bf92226 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu Oct 24 20:06:34 2024 +0200 Refactor casting for device attribute events commit 5141fb3c7087236a5925647120d69d3cb521ba5a Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu Oct 24 15:32:24 2024 +0200 Rename device state parse function commit 83b553e0cfd271df452e10330c836bac9e5622ef Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu Oct 24 11:35:38 2024 +0200 Add combo switch device type commit 73a9d866f4ff5da32b1e3bc3b0f1cd418f400afe Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu Oct 24 10:47:44 2024 +0200 Add options to log received and sent messages commit a27285efa7664343105a70ad527f7daf34d9ac61 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu Oct 24 09:56:02 2024 +0200 Do not always monitor device category commit 4eddfbbb10411d16c89b78a58699bd99aae578e1 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 22:50:42 2024 +0200 Add switch device type commit 268ca3fa5291a872a11085cb00671e197ff84ab9 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 22:50:28 2024 +0200 Fix BcpInterface prefab commit 2df28c43aa48e62f9a4f293dfd285965e7362fdf Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 22:08:24 2024 +0200 Fix constant duplication commit 1274bde1235a215ac1964755ab7cafa908a55ac6 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 21:29:16 2024 +0200 Add playfield device type commit c9e327f78fc0ba157f43d1c060a41e7514c590ea Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 21:20:33 2024 +0200 Add flipper device type commit fcb61ecabfac3fa285e3e6f84f985b52af4fd34f Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 21:12:05 2024 +0200 Add autofire device type commit 02922c6ac5dcb75f2a896d9a109506a15727af2d Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 21:01:00 2024 +0200 Restructure files and namespaces commit da060169b1b122308e5078e0a26ca5ede6214fca Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 19:42:13 2024 +0200 Restructure files commit dadf8064bd85d316182e85a82a9685f754154ca9 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 19:25:17 2024 +0200 Fix parsing errors commit 4d0c6e5cc8d9ad62468cd82d8a58d1f51b6ba8de Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 16:20:31 2024 +0200 Handle exceptions during parsing commit d51dd619403fe8a22f0c777eb86e9560abce01a5 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 14:03:49 2024 +0200 Refactor device attribute change events commit 9bd93cd7cac425de7e483efae260ce9627aa83b8 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 14:03:21 2024 +0200 Restructure files commit 476e30d5c2f4c26097a9d89052abfe7e45d11c93 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 12:18:58 2024 +0200 Add comments to StringEnum commit f693f38fca0c2dfbbcd72c66bced95976c1b8cf9 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 12:15:37 2024 +0200 Remove useless usings commit d7baffe589b3c8db8ff6541fc7a442cc0eb2b125 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 12:14:52 2024 +0200 Remove useless try catch block commit d0f15fb19b741e05b33f1d44ec92f6e0dbf0ccbc Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 12:00:04 2024 +0200 Refactor device messages commit c5f9b6e23e4f0c31fd3fbfa0279843d8b814cff8 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon Oct 21 11:44:18 2024 +0200 Restructure files commit 94ff5d26e96a4234fc700da5ff74e414d47a2ed1 Author: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun Oct 20 22:31:13 2024 +0200 Add preliminary device message parsing --- Runtime/BcpInterface.prefab | 16 +++- Runtime/Behaviours/DisconnectOnGoodbye.cs | 3 +- Runtime/Behaviours/HelloResponse.cs | 5 +- .../ParameterTypes.meta => Core.meta} | 2 +- Runtime/{ => Core}/BcpInterface.cs | 28 ++++-- Runtime/{ => Core}/BcpInterface.cs.meta | 0 Runtime/{ => Core}/BcpMessage.cs | 62 +++++------- Runtime/{ => Core}/BcpMessage.cs.meta | 0 Runtime/{ => Core}/BcpMessageHandler.cs | 3 +- Runtime/{ => Core}/BcpMessageHandler.cs.meta | 0 Runtime/{ => Core}/BcpServer.cs | 4 +- Runtime/{ => Core}/BcpServer.cs.meta | 0 Runtime/{ => Core}/Constants.cs | 0 Runtime/{ => Core}/Constants.cs.meta | 0 Runtime/Core/Exceptions.cs | 27 ++++++ Runtime/Core/Exceptions.cs.meta | 11 +++ .../Ball.meta} | 2 +- Runtime/Messages/{ => Ball}/BallEndMessage.cs | 2 +- .../{ => Ball}/BallEndMessage.cs.meta | 0 .../Ball}/BallEndMessageHandler.cs | 4 +- .../Ball}/BallEndMessageHandler.cs.meta | 0 .../Messages/{ => Ball}/BallStartMessage.cs | 2 +- .../{ => Ball}/BallStartMessage.cs.meta | 0 .../Ball}/BallStartMessageHandler.cs | 4 +- .../Ball}/BallStartMessageHandler.cs.meta | 0 Runtime/Messages/Device.meta | 8 ++ Runtime/Messages/Device/Autofire.meta | 8 ++ .../Device/Autofire/AutofireDeviceMessage.cs | 22 +++++ .../Autofire/AutofireDeviceMessage.cs.meta | 11 +++ .../Autofire/AutofireDeviceMessageHandler.cs | 19 ++++ .../AutofireDeviceMessageHandler.cs.meta | 11 +++ Runtime/Messages/Device/BallDevice.meta | 8 ++ .../Device/BallDevice/BallDeviceMessage.cs | 51 ++++++++++ .../BallDevice/BallDeviceMessage.cs.meta | 11 +++ .../BallDevice/BallDeviceMessageHandler.cs | 32 +++++++ .../BallDeviceMessageHandler.cs.meta | 11 +++ Runtime/Messages/Device/ComboSwitch.meta | 8 ++ .../ComboSwitch/ComboSwitchDeviceMessage.cs | 33 +++++++ .../ComboSwitchDeviceMessage.cs.meta | 11 +++ .../ComboSwitchDeviceMessageHandler.cs | 19 ++++ .../ComboSwitchDeviceMessageHandler.cs.meta | 11 +++ .../Messages/Device/DeviceAttributeChange.cs | 94 +++++++++++++++++++ .../Device/DeviceAttributeChange.cs.meta | 11 +++ Runtime/Messages/Device/DeviceMessage.cs | 50 ++++++++++ Runtime/Messages/Device/DeviceMessage.cs.meta | 11 +++ .../Device/DeviceMessageExceptions.cs | 22 +++++ .../Device/DeviceMessageExceptions.cs.meta | 11 +++ .../Messages/Device/DeviceMessageHandler.cs | 11 +++ .../Device/DeviceMessageHandler.cs.meta | 11 +++ Runtime/Messages/Device/Flipper.meta | 8 ++ .../Device/Flipper/FlipperDeviceMessage.cs | 22 +++++ .../Flipper/FlipperDeviceMessage.cs.meta | 11 +++ .../Flipper/FlipperDeviceMessageHandler.cs | 19 ++++ .../FlipperDeviceMessageHandler.cs.meta | 11 +++ Runtime/Messages/Device/Light.meta | 8 ++ .../Device/Light/LightDeviceMessage.cs | 38 ++++++++ .../Device/Light/LightDeviceMessage.cs.meta | 11 +++ .../Device/Light/LightDeviceMessageHandler.cs | 20 ++++ .../Light/LightDeviceMessageHandler.cs.meta | 11 +++ Runtime/Messages/Device/Playfield.meta | 8 ++ .../Playfield/PlayfieldDeviceMessage.cs | 28 ++++++ .../Playfield/PlayfieldDeviceMessage.cs.meta | 11 +++ .../PlayfieldDeviceMessageHandler.cs | 32 +++++++ .../PlayfieldDeviceMessageHandler.cs.meta | 11 +++ .../Device/SpecificDeviceMessageBase.cs | 14 +++ .../Device/SpecificDeviceMessageBase.cs.meta | 11 +++ .../Device/SpecificDeviceMessageHandler.cs | 60 ++++++++++++ .../SpecificDeviceMessageHandler.cs.meta | 11 +++ Runtime/Messages/Device/Switch.meta | 8 ++ .../Device/Switch/SwitchDeviceMessage.cs | 25 +++++ .../Device/Switch/SwitchDeviceMessage.cs.meta | 11 +++ .../Switch/SwitchDeviceMessageHandler.cs | 35 +++++++ .../Switch/SwitchDeviceMessageHandler.cs.meta | 11 +++ Runtime/Messages/Error.meta | 8 ++ Runtime/Messages/{ => Error}/ErrorMessage.cs | 2 +- .../Messages/{ => Error}/ErrorMessage.cs.meta | 0 .../Error}/ErrorMessageHandler.cs | 2 +- .../Error}/ErrorMessageHandler.cs.meta | 0 Runtime/Messages/Goodbye.meta | 8 ++ .../Messages/{ => Goodbye}/GoodbyeMessage.cs | 2 +- .../{ => Goodbye}/GoodbyeMessage.cs.meta | 2 +- .../Goodbye}/GoodbyeMessageHandler.cs | 2 +- .../Goodbye}/GoodbyeMessageHandler.cs.meta | 2 +- Runtime/Messages/Hello.meta | 8 ++ Runtime/Messages/{ => Hello}/HelloMessage.cs | 3 +- .../Messages/{ => Hello}/HelloMessage.cs.meta | 0 .../Hello}/HelloMessageHandler.cs | 2 +- .../Hello}/HelloMessageHandler.cs.meta | 0 Runtime/Messages/Monitor.meta | 8 ++ .../{ => Monitor}/MonitorStartMessage.cs | 2 +- .../{ => Monitor}/MonitorStartMessage.cs.meta | 0 .../{ => Monitor}/MonitorStopMessage.cs | 2 +- .../{ => Monitor}/MonitorStopMessage.cs.meta | 0 .../MonitoringCategory.cs | 4 +- .../MonitoringCategory.cs.meta | 0 Runtime/Messages/Reset.meta | 8 ++ .../{ => Reset}/ResetCompleteMessage.cs | 2 +- .../{ => Reset}/ResetCompleteMessage.cs.meta | 0 Runtime/Messages/{ => Reset}/ResetMessage.cs | 2 +- .../Messages/{ => Reset}/ResetMessage.cs.meta | 0 .../Reset}/ResetMessageHandler.cs | 2 +- .../Reset}/ResetMessageHandler.cs.meta | 0 Runtime/Utils/StringEnum.cs | 17 +++- 103 files changed, 1117 insertions(+), 76 deletions(-) rename Runtime/{Messages/ParameterTypes.meta => Core.meta} (77%) rename Runtime/{ => Core}/BcpInterface.cs (80%) rename Runtime/{ => Core}/BcpInterface.cs.meta (100%) rename Runtime/{ => Core}/BcpMessage.cs (66%) rename Runtime/{ => Core}/BcpMessage.cs.meta (100%) rename Runtime/{ => Core}/BcpMessageHandler.cs (93%) rename Runtime/{ => Core}/BcpMessageHandler.cs.meta (100%) rename Runtime/{ => Core}/BcpServer.cs (98%) rename Runtime/{ => Core}/BcpServer.cs.meta (100%) rename Runtime/{ => Core}/Constants.cs (100%) rename Runtime/{ => Core}/Constants.cs.meta (100%) create mode 100644 Runtime/Core/Exceptions.cs create mode 100644 Runtime/Core/Exceptions.cs.meta rename Runtime/{MessageHandlers.meta => Messages/Ball.meta} (77%) rename Runtime/Messages/{ => Ball}/BallEndMessage.cs (77%) rename Runtime/Messages/{ => Ball}/BallEndMessage.cs.meta (100%) rename Runtime/{MessageHandlers => Messages/Ball}/BallEndMessageHandler.cs (73%) rename Runtime/{MessageHandlers => Messages/Ball}/BallEndMessageHandler.cs.meta (100%) rename Runtime/Messages/{ => Ball}/BallStartMessage.cs (78%) rename Runtime/Messages/{ => Ball}/BallStartMessage.cs.meta (100%) rename Runtime/{MessageHandlers => Messages/Ball}/BallStartMessageHandler.cs (73%) rename Runtime/{MessageHandlers => Messages/Ball}/BallStartMessageHandler.cs.meta (100%) create mode 100644 Runtime/Messages/Device.meta create mode 100644 Runtime/Messages/Device/Autofire.meta create mode 100644 Runtime/Messages/Device/Autofire/AutofireDeviceMessage.cs create mode 100644 Runtime/Messages/Device/Autofire/AutofireDeviceMessage.cs.meta create mode 100644 Runtime/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs create mode 100644 Runtime/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs.meta create mode 100644 Runtime/Messages/Device/BallDevice.meta create mode 100644 Runtime/Messages/Device/BallDevice/BallDeviceMessage.cs create mode 100644 Runtime/Messages/Device/BallDevice/BallDeviceMessage.cs.meta create mode 100644 Runtime/Messages/Device/BallDevice/BallDeviceMessageHandler.cs create mode 100644 Runtime/Messages/Device/BallDevice/BallDeviceMessageHandler.cs.meta create mode 100644 Runtime/Messages/Device/ComboSwitch.meta create mode 100644 Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs create mode 100644 Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs.meta create mode 100644 Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs create mode 100644 Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs.meta create mode 100644 Runtime/Messages/Device/DeviceAttributeChange.cs create mode 100644 Runtime/Messages/Device/DeviceAttributeChange.cs.meta create mode 100644 Runtime/Messages/Device/DeviceMessage.cs create mode 100644 Runtime/Messages/Device/DeviceMessage.cs.meta create mode 100644 Runtime/Messages/Device/DeviceMessageExceptions.cs create mode 100644 Runtime/Messages/Device/DeviceMessageExceptions.cs.meta create mode 100644 Runtime/Messages/Device/DeviceMessageHandler.cs create mode 100644 Runtime/Messages/Device/DeviceMessageHandler.cs.meta create mode 100644 Runtime/Messages/Device/Flipper.meta create mode 100644 Runtime/Messages/Device/Flipper/FlipperDeviceMessage.cs create mode 100644 Runtime/Messages/Device/Flipper/FlipperDeviceMessage.cs.meta create mode 100644 Runtime/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs create mode 100644 Runtime/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs.meta create mode 100644 Runtime/Messages/Device/Light.meta create mode 100644 Runtime/Messages/Device/Light/LightDeviceMessage.cs create mode 100644 Runtime/Messages/Device/Light/LightDeviceMessage.cs.meta create mode 100644 Runtime/Messages/Device/Light/LightDeviceMessageHandler.cs create mode 100644 Runtime/Messages/Device/Light/LightDeviceMessageHandler.cs.meta create mode 100644 Runtime/Messages/Device/Playfield.meta create mode 100644 Runtime/Messages/Device/Playfield/PlayfieldDeviceMessage.cs create mode 100644 Runtime/Messages/Device/Playfield/PlayfieldDeviceMessage.cs.meta create mode 100644 Runtime/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs create mode 100644 Runtime/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs.meta create mode 100644 Runtime/Messages/Device/SpecificDeviceMessageBase.cs create mode 100644 Runtime/Messages/Device/SpecificDeviceMessageBase.cs.meta create mode 100644 Runtime/Messages/Device/SpecificDeviceMessageHandler.cs create mode 100644 Runtime/Messages/Device/SpecificDeviceMessageHandler.cs.meta create mode 100644 Runtime/Messages/Device/Switch.meta create mode 100644 Runtime/Messages/Device/Switch/SwitchDeviceMessage.cs create mode 100644 Runtime/Messages/Device/Switch/SwitchDeviceMessage.cs.meta create mode 100644 Runtime/Messages/Device/Switch/SwitchDeviceMessageHandler.cs create mode 100644 Runtime/Messages/Device/Switch/SwitchDeviceMessageHandler.cs.meta create mode 100644 Runtime/Messages/Error.meta rename Runtime/Messages/{ => Error}/ErrorMessage.cs (95%) rename Runtime/Messages/{ => Error}/ErrorMessage.cs.meta (100%) rename Runtime/{MessageHandlers => Messages/Error}/ErrorMessageHandler.cs (78%) rename Runtime/{MessageHandlers => Messages/Error}/ErrorMessageHandler.cs.meta (100%) create mode 100644 Runtime/Messages/Goodbye.meta rename Runtime/Messages/{ => Goodbye}/GoodbyeMessage.cs (81%) rename Runtime/Messages/{ => Goodbye}/GoodbyeMessage.cs.meta (83%) rename Runtime/{MessageHandlers => Messages/Goodbye}/GoodbyeMessageHandler.cs (78%) rename Runtime/{MessageHandlers => Messages/Goodbye}/GoodbyeMessageHandler.cs.meta (83%) create mode 100644 Runtime/Messages/Hello.meta rename Runtime/Messages/{ => Hello}/HelloMessage.cs (96%) rename Runtime/Messages/{ => Hello}/HelloMessage.cs.meta (100%) rename Runtime/{MessageHandlers => Messages/Hello}/HelloMessageHandler.cs (78%) rename Runtime/{MessageHandlers => Messages/Hello}/HelloMessageHandler.cs.meta (100%) create mode 100644 Runtime/Messages/Monitor.meta rename Runtime/Messages/{ => Monitor}/MonitorStartMessage.cs (93%) rename Runtime/Messages/{ => Monitor}/MonitorStartMessage.cs.meta (100%) rename Runtime/Messages/{ => Monitor}/MonitorStopMessage.cs (93%) rename Runtime/Messages/{ => Monitor}/MonitorStopMessage.cs.meta (100%) rename Runtime/Messages/{ParameterTypes => Monitor}/MonitoringCategory.cs (77%) rename Runtime/Messages/{ParameterTypes => Monitor}/MonitoringCategory.cs.meta (100%) create mode 100644 Runtime/Messages/Reset.meta rename Runtime/Messages/{ => Reset}/ResetCompleteMessage.cs (83%) rename Runtime/Messages/{ => Reset}/ResetCompleteMessage.cs.meta (100%) rename Runtime/Messages/{ => Reset}/ResetMessage.cs (76%) rename Runtime/Messages/{ => Reset}/ResetMessage.cs.meta (100%) rename Runtime/{MessageHandlers => Messages/Reset}/ResetMessageHandler.cs (86%) rename Runtime/{MessageHandlers => Messages/Reset}/ResetMessageHandler.cs.meta (100%) diff --git a/Runtime/BcpInterface.prefab b/Runtime/BcpInterface.prefab index 767c09cd..ce3554be 100644 --- a/Runtime/BcpInterface.prefab +++ b/Runtime/BcpInterface.prefab @@ -15,6 +15,7 @@ GameObject: - component: {fileID: 1824319182504738973} - component: {fileID: 3006042140711521680} - component: {fileID: 4146686170121310886} + - component: {fileID: 7019407901035039939} m_Layer: 0 m_Name: MessageHandlers m_TagString: Untagged @@ -59,7 +60,7 @@ MonoBehaviour: m_GameObject: {fileID: 4502278156144720521} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 4ad4af17d27824a418620638a7c60d96, type: 3} + m_Script: {fileID: 11500000, guid: 6f9bc1ba9f51a604db49e1a6e7f59a86, type: 3} m_Name: m_EditorClassIdentifier: bcpInterface: {fileID: 3405300645593462295} @@ -115,6 +116,19 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &7019407901035039939 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 88948b8ed19a20e40a42d16e46c70610, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} --- !u!1 &7214112112941309933 GameObject: m_ObjectHideFlags: 0 diff --git a/Runtime/Behaviours/DisconnectOnGoodbye.cs b/Runtime/Behaviours/DisconnectOnGoodbye.cs index a2715fec..e25e3fbf 100644 --- a/Runtime/Behaviours/DisconnectOnGoodbye.cs +++ b/Runtime/Behaviours/DisconnectOnGoodbye.cs @@ -1,6 +1,7 @@ using UnityEngine; +using FutureBoxSystems.MpfMediaController.Messages.Goodbye; -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Behaviours { public class DisconnectOnGoodbye : MonoBehaviour { diff --git a/Runtime/Behaviours/HelloResponse.cs b/Runtime/Behaviours/HelloResponse.cs index c85ce2f9..c10f7bf4 100644 --- a/Runtime/Behaviours/HelloResponse.cs +++ b/Runtime/Behaviours/HelloResponse.cs @@ -1,6 +1,9 @@ using UnityEngine; +using FutureBoxSystems.MpfMediaController.Messages.Hello; +using FutureBoxSystems.MpfMediaController.Messages.Error; -namespace FutureBoxSystems.MpfMediaController + +namespace FutureBoxSystems.MpfMediaController.Behaviours { public class HelloResponse : MonoBehaviour { diff --git a/Runtime/Messages/ParameterTypes.meta b/Runtime/Core.meta similarity index 77% rename from Runtime/Messages/ParameterTypes.meta rename to Runtime/Core.meta index 1186d488..4c8f3d34 100644 --- a/Runtime/Messages/ParameterTypes.meta +++ b/Runtime/Core.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3b8b640f628374647a20797376f57be4 +guid: b7cb29e6dcf55104c89a5f36c5b51eb9 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/BcpInterface.cs b/Runtime/Core/BcpInterface.cs similarity index 80% rename from Runtime/BcpInterface.cs rename to Runtime/Core/BcpInterface.cs index 22fbcadd..ff40c188 100644 --- a/Runtime/BcpInterface.cs +++ b/Runtime/Core/BcpInterface.cs @@ -1,7 +1,8 @@ using System; using System.Collections.Generic; using UnityEngine; -using UnityEngine.Assertions; +using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using FutureBoxSystems.MpfMediaController.Messages.Error; namespace FutureBoxSystems.MpfMediaController { @@ -13,6 +14,10 @@ public class BcpInterface : MonoBehaviour [SerializeField] [Range(0.1f, 10f)] private float frameTimeBudgetMs = 3f; + [SerializeField] + private bool logReceivedMessages = false; + [SerializeField] + private bool logSentMessages = false; private BcpServer server; @@ -48,10 +53,11 @@ public void RemoveMonitoringCategoryUser(MonitoringCategory category) if (monitoringCategoryUserCounts.TryGetValue(category, out var userCount)) { if (userCount > 0) + { monitoringCategoryUserCounts[category]--; - - if (monitoringCategoryUserCounts[category] == 0) - TrySendMessage(new MonitorStopMessage(category)); + if (monitoringCategoryUserCounts[category] == 0) + TrySendMessage(new MonitorStopMessage(category)); + } } } @@ -60,6 +66,8 @@ public bool TrySendMessage(ISentMessage message) if (ConnectionState == ConnectionState.Connected) { BcpMessage bcpMessage = message.ToGenericMessage(); + if (logSentMessages) + Debug.Log($"[BcpInterface] Sending message: {bcpMessage}"); server.EnqueueMessage(bcpMessage); return true; } @@ -107,22 +115,24 @@ private void Update() private void HandleReceivedMessage(BcpMessage message) { + if (logReceivedMessages) + Debug.Log($"[BcpInterface] Message received: {message}"); + if (messageHandlers.TryGetValue(message.Command, out var handler)) { try { handler(message); } - catch (BcpParseException) + catch (BcpParseException e) { - // Message is malformed - // TODO: Send error message back + Debug.LogError($"[BcpInterface] Failed to parse message. Message: {message} Exception: {e}"); } } else { - // Message command is unknown - // TODO: Send error message back + Debug.LogError($"[BcpInterface] No parser registered for message with command '{message.Command}' Message: {message}"); + TrySendMessage(new ErrorMessage("unknown command", message.ToString())); } } diff --git a/Runtime/BcpInterface.cs.meta b/Runtime/Core/BcpInterface.cs.meta similarity index 100% rename from Runtime/BcpInterface.cs.meta rename to Runtime/Core/BcpInterface.cs.meta diff --git a/Runtime/BcpMessage.cs b/Runtime/Core/BcpMessage.cs similarity index 66% rename from Runtime/BcpMessage.cs rename to Runtime/Core/BcpMessage.cs index 83deb3ca..2fb70a7d 100644 --- a/Runtime/BcpMessage.cs +++ b/Runtime/Core/BcpMessage.cs @@ -30,18 +30,20 @@ public string FindParamValue(string name, string typeHint = null) } catch (InvalidOperationException ioe) { - throw new ParameterException(this, name, ioe); + throw new ParameterException(name, this, ioe); } } - public override string ToString() + public override string ToString() => ToString(encode: false); + + public string ToString(bool encode) { var sb = new StringBuilder(Command); if (parameters.Count > 0) sb.Append(commandParamsSeparator); for (int i = 0; i < parameters.Count; i++) { - sb.Append(parameters[i].ToString()); + sb.Append(parameters[i].ToString(encode)); bool isLastParam = i == parameters.Count - 1; if (!isLastParam) sb.Append(paramsSeparator); @@ -76,13 +78,15 @@ public BcpParameter(string name, string value, string typeHint = null) Value = value; } - public override string ToString() + public override string ToString() => ToString(encode: false); + + public string ToString(bool encode) { - var nameEncoded = Uri.EscapeDataString(Name); - var valueEncoded = Uri.EscapeDataString(Value); + var name = encode ? Uri.EscapeDataString(Name) : Name; + var value = encode ? Uri.EscapeDataString(Value) : Value; if (string.IsNullOrEmpty(TypeHint)) - return $"{nameEncoded}={valueEncoded}"; - return $"{nameEncoded}={TypeHint}:{valueEncoded}"; + return $"{name}={value}"; + return $"{name}={TypeHint}:{value}"; } public bool MatchesPattern(string name, string typeHint) @@ -94,44 +98,30 @@ public bool MatchesPattern(string name, string typeHint) public static BcpParameter FromString(string str) { - string[] parts = str.Split(new char[] { '=', ':' }, 3); + string[] parts = str.Split('=', 2); var name = parts[0].Trim().ToLower(); // Not case sensitive string typeHint = null; string value = null; if (parts.Length == 2) - value = parts[1]; - else if (parts.Length == 3) { - typeHint = parts[1]; - value = parts[2]; + if (name == "json") + value = parts[1]; + else + { + parts = parts[1].Split(':', 2); + if (parts.Length == 2) + { + typeHint = parts[0]; + value = parts[1]; + } + else + value = parts[0]; + } } return new BcpParameter(name, value, typeHint); } } - public class BcpParseException : Exception - { - public BcpMessage Culprit { get; private set; } - - public BcpParseException(BcpMessage culprit, Exception innerException = null, string failReason = null) - : base($"Failed to parse bcp message: '{culprit}' Reason: {(failReason ?? "None given")}", innerException) - { - Culprit = culprit; - } - } - - public class WrongParserException : BcpParseException - { - public WrongParserException(BcpMessage culprit, string expectedCommand, string actualCommand, Exception innerException = null) - : base(culprit, innerException, $"Wrong parser chosen for message. Parser expected command type: '{expectedCommand}' Actual: '{actualCommand}'") { } - } - - public class ParameterException : BcpParseException - { - public ParameterException(BcpMessage culprit, string parameterName, Exception innerException = null) - : base(culprit, innerException, $"Missing or invalid parameter '{parameterName}'") { } - } - /// /// Most message types are only received and never sent. /// The ones that are sent must implement this interface diff --git a/Runtime/BcpMessage.cs.meta b/Runtime/Core/BcpMessage.cs.meta similarity index 100% rename from Runtime/BcpMessage.cs.meta rename to Runtime/Core/BcpMessage.cs.meta diff --git a/Runtime/BcpMessageHandler.cs b/Runtime/Core/BcpMessageHandler.cs similarity index 93% rename from Runtime/BcpMessageHandler.cs rename to Runtime/Core/BcpMessageHandler.cs index 5a56c439..4090ddf2 100644 --- a/Runtime/BcpMessageHandler.cs +++ b/Runtime/Core/BcpMessageHandler.cs @@ -1,5 +1,6 @@ using System; using UnityEngine; +using FutureBoxSystems.MpfMediaController.Messages.Monitor; namespace FutureBoxSystems.MpfMediaController { @@ -44,7 +45,7 @@ private void OnDisable() private void Handle(BcpMessage message) { if (message.Command != Command) - throw new WrongParserException(message, Command, message.Command); + throw new WrongParserException(message, Command); T specificMessage = Parse(message); BeforeEvent(); CommandReceived?.Invoke(this, specificMessage); diff --git a/Runtime/BcpMessageHandler.cs.meta b/Runtime/Core/BcpMessageHandler.cs.meta similarity index 100% rename from Runtime/BcpMessageHandler.cs.meta rename to Runtime/Core/BcpMessageHandler.cs.meta diff --git a/Runtime/BcpServer.cs b/Runtime/Core/BcpServer.cs similarity index 98% rename from Runtime/BcpServer.cs rename to Runtime/Core/BcpServer.cs index 6cd8da2e..5305333a 100644 --- a/Runtime/BcpServer.cs +++ b/Runtime/Core/BcpServer.cs @@ -182,7 +182,7 @@ private async Task ReceiveMessagesAsync(NetworkStream stream, while (!ct.IsCancellationRequested && (messageLength = stringBuffer.ToString().IndexOf(terminator)) > -1) { var message = stringBuffer.ToString(0, messageLength); - stringBuffer.Remove(0, messageLength + 1); + stringBuffer.Remove(0, messageLength + 1); message = Uri.UnescapeDataString(message); if (message.Length > 0 && !message.StartsWith("#")) { @@ -203,7 +203,7 @@ private async Task SendMessagesAsync(NetworkStream stream, CancellationToken ct) { while (!ct.IsCancellationRequested && TryDequeueOutboundMessage(out BcpMessage bcpMessage)) { - var stringMessage = bcpMessage.ToString(); + var stringMessage = bcpMessage.ToString(encode: true); stringMessage += "\n"; var packet = Encoding.UTF8.GetBytes(stringMessage); try diff --git a/Runtime/BcpServer.cs.meta b/Runtime/Core/BcpServer.cs.meta similarity index 100% rename from Runtime/BcpServer.cs.meta rename to Runtime/Core/BcpServer.cs.meta diff --git a/Runtime/Constants.cs b/Runtime/Core/Constants.cs similarity index 100% rename from Runtime/Constants.cs rename to Runtime/Core/Constants.cs diff --git a/Runtime/Constants.cs.meta b/Runtime/Core/Constants.cs.meta similarity index 100% rename from Runtime/Constants.cs.meta rename to Runtime/Core/Constants.cs.meta diff --git a/Runtime/Core/Exceptions.cs b/Runtime/Core/Exceptions.cs new file mode 100644 index 00000000..d3d8abf7 --- /dev/null +++ b/Runtime/Core/Exceptions.cs @@ -0,0 +1,27 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController +{ + public class BcpParseException : Exception + { + public readonly BcpMessage Culprit; + + public BcpParseException(string failReason, BcpMessage culprit = null, Exception innerException = null) + : base($"Failed to parse bcp message: '{(culprit?.ToString() ?? "Unknown")}' Reason: {(failReason ?? "None given")}", innerException) + { + Culprit = culprit; + } + } + + public class WrongParserException : BcpParseException + { + public WrongParserException(BcpMessage culprit, string expectedCommand, Exception innerException = null) + : base($"Wrong parser chosen for message. Parser expected command type: '{expectedCommand}' Actual: '{culprit.Command}'", culprit, innerException) { } + } + + public class ParameterException : BcpParseException + { + public ParameterException(string parameterName, BcpMessage culprit = null, Exception innerException = null) + : base($"Missing or invalid parameter '{parameterName}'", culprit, innerException) { } + } +} \ No newline at end of file diff --git a/Runtime/Core/Exceptions.cs.meta b/Runtime/Core/Exceptions.cs.meta new file mode 100644 index 00000000..d05f8bc4 --- /dev/null +++ b/Runtime/Core/Exceptions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1b24829f74f270b4d89484c8c35d9952 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/MessageHandlers.meta b/Runtime/Messages/Ball.meta similarity index 77% rename from Runtime/MessageHandlers.meta rename to Runtime/Messages/Ball.meta index 73e3bfd6..377a3eae 100644 --- a/Runtime/MessageHandlers.meta +++ b/Runtime/Messages/Ball.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7004fa09e6fdb884fbfe6ed0bf1316a9 +guid: 5a32cff327b47f34a80589d1ce32af94 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Runtime/Messages/BallEndMessage.cs b/Runtime/Messages/Ball/BallEndMessage.cs similarity index 77% rename from Runtime/Messages/BallEndMessage.cs rename to Runtime/Messages/Ball/BallEndMessage.cs index 644c587b..f0b7bf8e 100644 --- a/Runtime/Messages/BallEndMessage.cs +++ b/Runtime/Messages/Ball/BallEndMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Ball { public class BallEndMessage : EventArgs { diff --git a/Runtime/Messages/BallEndMessage.cs.meta b/Runtime/Messages/Ball/BallEndMessage.cs.meta similarity index 100% rename from Runtime/Messages/BallEndMessage.cs.meta rename to Runtime/Messages/Ball/BallEndMessage.cs.meta diff --git a/Runtime/MessageHandlers/BallEndMessageHandler.cs b/Runtime/Messages/Ball/BallEndMessageHandler.cs similarity index 73% rename from Runtime/MessageHandlers/BallEndMessageHandler.cs rename to Runtime/Messages/Ball/BallEndMessageHandler.cs index d493c115..8d5bf101 100644 --- a/Runtime/MessageHandlers/BallEndMessageHandler.cs +++ b/Runtime/Messages/Ball/BallEndMessageHandler.cs @@ -1,4 +1,6 @@ -namespace FutureBoxSystems.MpfMediaController +using FutureBoxSystems.MpfMediaController.Messages.Monitor; + +namespace FutureBoxSystems.MpfMediaController.Messages.Ball { public class BallEndMessageHandler : BcpMessageHandler { diff --git a/Runtime/MessageHandlers/BallEndMessageHandler.cs.meta b/Runtime/Messages/Ball/BallEndMessageHandler.cs.meta similarity index 100% rename from Runtime/MessageHandlers/BallEndMessageHandler.cs.meta rename to Runtime/Messages/Ball/BallEndMessageHandler.cs.meta diff --git a/Runtime/Messages/BallStartMessage.cs b/Runtime/Messages/Ball/BallStartMessage.cs similarity index 78% rename from Runtime/Messages/BallStartMessage.cs rename to Runtime/Messages/Ball/BallStartMessage.cs index 5f42a813..2c7f46c7 100644 --- a/Runtime/Messages/BallStartMessage.cs +++ b/Runtime/Messages/Ball/BallStartMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Ball { public class BallStartMessage : EventArgs { diff --git a/Runtime/Messages/BallStartMessage.cs.meta b/Runtime/Messages/Ball/BallStartMessage.cs.meta similarity index 100% rename from Runtime/Messages/BallStartMessage.cs.meta rename to Runtime/Messages/Ball/BallStartMessage.cs.meta diff --git a/Runtime/MessageHandlers/BallStartMessageHandler.cs b/Runtime/Messages/Ball/BallStartMessageHandler.cs similarity index 73% rename from Runtime/MessageHandlers/BallStartMessageHandler.cs rename to Runtime/Messages/Ball/BallStartMessageHandler.cs index 8b12761c..1f5f17ec 100644 --- a/Runtime/MessageHandlers/BallStartMessageHandler.cs +++ b/Runtime/Messages/Ball/BallStartMessageHandler.cs @@ -1,4 +1,6 @@ -namespace FutureBoxSystems.MpfMediaController +using FutureBoxSystems.MpfMediaController.Messages.Monitor; + +namespace FutureBoxSystems.MpfMediaController.Messages.Ball { public class BallStartMessageHandler : BcpMessageHandler { diff --git a/Runtime/MessageHandlers/BallStartMessageHandler.cs.meta b/Runtime/Messages/Ball/BallStartMessageHandler.cs.meta similarity index 100% rename from Runtime/MessageHandlers/BallStartMessageHandler.cs.meta rename to Runtime/Messages/Ball/BallStartMessageHandler.cs.meta diff --git a/Runtime/Messages/Device.meta b/Runtime/Messages/Device.meta new file mode 100644 index 00000000..ca5a77a4 --- /dev/null +++ b/Runtime/Messages/Device.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 22f632a50109c9a44833a5520ff02a6a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Autofire.meta b/Runtime/Messages/Device/Autofire.meta new file mode 100644 index 00000000..cae79764 --- /dev/null +++ b/Runtime/Messages/Device/Autofire.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c7c30094a1f17c14e83c979d064006bf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Autofire/AutofireDeviceMessage.cs b/Runtime/Messages/Device/Autofire/AutofireDeviceMessage.cs new file mode 100644 index 00000000..9269ad16 --- /dev/null +++ b/Runtime/Messages/Device/Autofire/AutofireDeviceMessage.cs @@ -0,0 +1,22 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.Device.Autofire +{ + public class AutofireDeviceMessage : SpecificDeviceMessageBase + { + public readonly bool Enabled; + + public AutofireDeviceMessage(string deviceName, bool enabled) : base(deviceName) + { + Enabled = enabled; + } + + public static AutofireDeviceMessage FromStateJson(StateJson state, string deviceName) + { + return new(deviceName, state.enabled); + } + + public class StateJson + { + public bool enabled; + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/Autofire/AutofireDeviceMessage.cs.meta b/Runtime/Messages/Device/Autofire/AutofireDeviceMessage.cs.meta new file mode 100644 index 00000000..0d979629 --- /dev/null +++ b/Runtime/Messages/Device/Autofire/AutofireDeviceMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 12da0cb81b51f974dad908bd6f3d684e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs b/Runtime/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs new file mode 100644 index 00000000..773aa634 --- /dev/null +++ b/Runtime/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs @@ -0,0 +1,19 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device.Autofire +{ + public class AutofireDeviceMessageHandler : SpecificDeviceMessageHandler + { + protected override string Type => "autofire"; + protected override ParseStateDelegate ParseState => AutofireDeviceMessage.FromStateJson; + public event EventHandler> EnabledChanged; + + protected override void HandleAttributeChange(DeviceAttributeChange change) + { + if (change.AttributeName == nameof(AutofireDeviceMessage.StateJson.enabled)) + EnabledChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + else + throw new UnknownDeviceAttributeException(Type, change.AttributeName); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs.meta b/Runtime/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs.meta new file mode 100644 index 00000000..4eb09236 --- /dev/null +++ b/Runtime/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3259e5390e1ad314caf0fdf0017fe834 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/BallDevice.meta b/Runtime/Messages/Device/BallDevice.meta new file mode 100644 index 00000000..a12da4b9 --- /dev/null +++ b/Runtime/Messages/Device/BallDevice.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 523459f50fe69a14fa4f1477dc456ad1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/BallDevice/BallDeviceMessage.cs b/Runtime/Messages/Device/BallDevice/BallDeviceMessage.cs new file mode 100644 index 00000000..3d45f81a --- /dev/null +++ b/Runtime/Messages/Device/BallDevice/BallDeviceMessage.cs @@ -0,0 +1,51 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.Device.BallDevice +{ + public class BallDeviceMessage : SpecificDeviceMessageBase + { + public readonly int AvailableBalls; + public readonly BallDeviceStatus Status; + public readonly string StatusAsString; + public readonly int Balls; + + public BallDeviceMessage(string deviceName, int availableBalls, BallDeviceStatus status, string statusAsString, int balls) : base(deviceName) + { + AvailableBalls = availableBalls; + Status = status; + StatusAsString = statusAsString; + Balls = balls; + } + + public static BallDeviceMessage FromStateJson(StateJson state, string deviceName) + { + var status = StringEnum.GetValueFromString(state.state); + return new(deviceName, state.available_balls, status, state.state, state.balls); + } + + public class StateJson + { + public int available_balls; + public string state; + public int balls; + } + } + + public enum BallDeviceStatus + { + [StringValue(null)] + Unknown, + [StringValue("idle")] + Idle, + [StringValue("waiting_for_ball")] + WaitingForBall, + [StringValue("waiting_for_target_ready")] + WaitingForTargetReady, + [StringValue("ejecting")] + Ejecting, + [StringValue("eject_broken")] + EjectBroken, + [StringValue("ball_left")] + BallLeft, + [StringValue("failed_confirm")] + FailedConfirm + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/BallDevice/BallDeviceMessage.cs.meta b/Runtime/Messages/Device/BallDevice/BallDeviceMessage.cs.meta new file mode 100644 index 00000000..139dafaf --- /dev/null +++ b/Runtime/Messages/Device/BallDevice/BallDeviceMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 099f2296da4aeba4b8f437ca0d5a3624 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/BallDevice/BallDeviceMessageHandler.cs b/Runtime/Messages/Device/BallDevice/BallDeviceMessageHandler.cs new file mode 100644 index 00000000..48cb3747 --- /dev/null +++ b/Runtime/Messages/Device/BallDevice/BallDeviceMessageHandler.cs @@ -0,0 +1,32 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device.BallDevice +{ + public class BallDeviceMessageHandler : SpecificDeviceMessageHandler + { + protected override string Type => "ball_device"; + protected override ParseStateDelegate ParseState => BallDeviceMessage.FromStateJson; + + public event EventHandler> AvailableBallsChanged; + public event EventHandler> StatusChanged; + public event EventHandler> BallsChanged; + + protected override void HandleAttributeChange(DeviceAttributeChange change) + { + switch (change.AttributeName) + { + case nameof(BallDeviceMessage.StateJson.available_balls): + AvailableBallsChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + break; + case nameof(BallDeviceMessage.StateJson.state): + StatusChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + break; + case nameof(BallDeviceMessage.StateJson.balls): + BallsChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + break; + default: + throw new UnknownDeviceAttributeException(Type, change.AttributeName); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/BallDevice/BallDeviceMessageHandler.cs.meta b/Runtime/Messages/Device/BallDevice/BallDeviceMessageHandler.cs.meta new file mode 100644 index 00000000..94b1d847 --- /dev/null +++ b/Runtime/Messages/Device/BallDevice/BallDeviceMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 90db0c8685c99fa4da8a8e3206a7a5be +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/ComboSwitch.meta b/Runtime/Messages/Device/ComboSwitch.meta new file mode 100644 index 00000000..f571feee --- /dev/null +++ b/Runtime/Messages/Device/ComboSwitch.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c6b1741bd0085cf43b4af4e5b1875866 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs b/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs new file mode 100644 index 00000000..8481f226 --- /dev/null +++ b/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs @@ -0,0 +1,33 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.Device.ComboSwitch +{ + public class ComboSwitchDeviceMessage : SpecificDeviceMessageBase + { + public readonly ComboSwitchStatus Status; + + public ComboSwitchDeviceMessage(string deviceName, ComboSwitchStatus status) : base(deviceName) + { + Status = status; + } + + public static ComboSwitchDeviceMessage FromStateJson(StateJson state, string deviceName) + { + ComboSwitchStatus status = StringEnum.GetValueFromString(state.state); + return new(deviceName, status); + } + + public class StateJson + { + public string state; + } + } + + public enum ComboSwitchStatus + { + [StringValue("inactive")] + Inactive, + [StringValue("both")] + Both, + [StringValue("one")] + One + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs.meta b/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs.meta new file mode 100644 index 00000000..0d66460b --- /dev/null +++ b/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 517e12c6746048942b3c11b7c63aeacd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs b/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs new file mode 100644 index 00000000..714ecefe --- /dev/null +++ b/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs @@ -0,0 +1,19 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device.ComboSwitch +{ + public class ComboSwitchDeviceMessageHandler : SpecificDeviceMessageHandler + { + protected override string Type => "combo_switch"; + protected override ParseStateDelegate ParseState => ComboSwitchDeviceMessage.FromStateJson; + public event EventHandler> StatusChanged; + + protected override void HandleAttributeChange(DeviceAttributeChange change) + { + if (change.AttributeName == nameof(ComboSwitchDeviceMessage.StateJson.state)) + StatusChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + else + throw new UnknownDeviceAttributeException(Type, change.AttributeName); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs.meta b/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs.meta new file mode 100644 index 00000000..b916900a --- /dev/null +++ b/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cad12bb6ebe134e459bfd09e50749904 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/DeviceAttributeChange.cs b/Runtime/Messages/Device/DeviceAttributeChange.cs new file mode 100644 index 00000000..dd93b8f4 --- /dev/null +++ b/Runtime/Messages/Device/DeviceAttributeChange.cs @@ -0,0 +1,94 @@ +using Newtonsoft.Json; +using System; +using System.Runtime.InteropServices.WindowsRuntime; +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device +{ + public class DeviceAttributeChange + { + public readonly string AttributeName; + public readonly string OldValue; + public readonly string NewValue; + + public DeviceAttributeChange(string attributeName, string oldValue, string newValue) + { + AttributeName = attributeName; + OldValue = oldValue; + NewValue = newValue; + } + + public delegate ConversionType ConvertAttributeDelegate(string attributeValue); + public DeviceAttributeChangeEventArgs GetEventArgs(ConvertAttributeDelegate convertAttribute) + { + try + { + return new(convertAttribute(OldValue), convertAttribute(NewValue)); + } + catch (ConversionException e) + { + throw new WrongDeviceAttributeTypeException(AttributeName, typeof(ConversionType), OldValue, NewValue, e); + } + } + + private class ConversionException : InvalidCastException + { + public ConversionException(Exception innerException) : base("Conversion failed", innerException) { } + } + + public DeviceAttributeChangeEventArgs GetEventArgsForPrimitiveTypes() where T : struct + { + try + { + return new((T)Convert.ChangeType(OldValue, typeof(T)), + (T)Convert.ChangeType(NewValue, typeof(T))); + } + catch (InvalidCastException e) + { + throw new ConversionException(e); + } + } + + public DeviceAttributeChangeEventArgs GetEventArgsForEnums() where T : Enum + { + try + { + return new(StringEnum.GetValueFromString(OldValue), + StringEnum.GetValueFromString(NewValue)); + } + catch (ArgumentException e) + { + throw new ConversionException(e); + } + } + + public DeviceAttributeChangeEventArgs GetEventArgsForColor() + { + try + { + static Color StringToColor(string s) + { + var arr = JsonConvert.DeserializeObject(s); + return new Color(arr[0] / 255f, arr[1] / 255f, arr[2] / 255f); + } + return new(StringToColor(OldValue), StringToColor(NewValue)); + } + catch (Exception e) when (e is JsonException || e is ArgumentOutOfRangeException) + { + throw new ConversionException(e); + } + } + } + + public class DeviceAttributeChangeEventArgs : EventArgs + { + public readonly AttributeType OldValue; + public readonly AttributeType NewValue; + + public DeviceAttributeChangeEventArgs(AttributeType oldValue, AttributeType newValue) + { + OldValue = oldValue; + NewValue = newValue; + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/DeviceAttributeChange.cs.meta b/Runtime/Messages/Device/DeviceAttributeChange.cs.meta new file mode 100644 index 00000000..a2a76e72 --- /dev/null +++ b/Runtime/Messages/Device/DeviceAttributeChange.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4db35a69c4b43ff43ad4d2d865ad4eed +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/DeviceMessage.cs b/Runtime/Messages/Device/DeviceMessage.cs new file mode 100644 index 00000000..9db46a21 --- /dev/null +++ b/Runtime/Messages/Device/DeviceMessage.cs @@ -0,0 +1,50 @@ +using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device +{ + public class DeviceMessage : EventArgs + { + public const string Command = "device"; + private const string jsonParamName = "json"; + public readonly string Type; + public readonly string Name; + public readonly DeviceAttributeChange Change; + public readonly string StateJson; + + public DeviceMessage(string type, string name, DeviceAttributeChange change, string stateJson) + { + Type = type; + Name = name; + Change = change; + StateJson = stateJson; + } + + public static DeviceMessage FromGenericMessage(BcpMessage bcpMessage) + { + var jsonString = bcpMessage.FindParamValue(jsonParamName); + try + { + var jsonObject = JObject.Parse(jsonString); + var type = (string)jsonObject["type"]; + var name = (string)jsonObject["name"]; + var changes = jsonObject["changes"].ToString(); + var stateJson = jsonObject["state"].ToString(); + DeviceAttributeChange change; + if (changes.ToLower() == "false") + change = null; + else + { + var arr = JsonConvert.DeserializeObject(changes); + change = new(arr[0], arr[1], arr[2]); + } + return new(type, name, change, stateJson); + } + catch (Exception e) when (e is JsonException || e is IndexOutOfRangeException || e is ArgumentNullException) + { + throw new ParameterException(jsonParamName, bcpMessage, e); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/DeviceMessage.cs.meta b/Runtime/Messages/Device/DeviceMessage.cs.meta new file mode 100644 index 00000000..44620454 --- /dev/null +++ b/Runtime/Messages/Device/DeviceMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c1f1a83432cf81c4ab7a1a8638eba8c1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/DeviceMessageExceptions.cs b/Runtime/Messages/Device/DeviceMessageExceptions.cs new file mode 100644 index 00000000..c1f4917f --- /dev/null +++ b/Runtime/Messages/Device/DeviceMessageExceptions.cs @@ -0,0 +1,22 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device +{ + public class WrongDeviceAttributeTypeException : BcpParseException + { + public WrongDeviceAttributeTypeException(string name, Type expectedType, string oldValue, string newValue, Exception innerException = null) + : base($"The new and old values of device attribute '{name}' (Old: '{oldValue}', New: {newValue}) could not be cast to the expected type '{expectedType}'", null, innerException) { } + } + + public class UnknownDeviceAttributeException : BcpParseException + { + public UnknownDeviceAttributeException(string attributeName, string deviceType, Exception innerException = null) + : base($"The attribute name '{attributeName}' is not valid for device type '{deviceType}'", null, innerException) { } + } + + public class InvalidDeviceStateException : BcpParseException + { + public InvalidDeviceStateException(string type, Type parseFormat, Exception innerException = null) + : base($"Json key 'state' could not be parsed to the type '{parseFormat}'. The type was chosen based on the value of the 'type' key ('{type}'.)", null, innerException) { } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/DeviceMessageExceptions.cs.meta b/Runtime/Messages/Device/DeviceMessageExceptions.cs.meta new file mode 100644 index 00000000..2503f141 --- /dev/null +++ b/Runtime/Messages/Device/DeviceMessageExceptions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: beefa1604a0a6c84ca50008380870fa8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/DeviceMessageHandler.cs b/Runtime/Messages/Device/DeviceMessageHandler.cs new file mode 100644 index 00000000..20ba2bac --- /dev/null +++ b/Runtime/Messages/Device/DeviceMessageHandler.cs @@ -0,0 +1,11 @@ +using FutureBoxSystems.MpfMediaController.Messages.Monitor; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device +{ + public class DeviceMessageHandler : BcpMessageHandler + { + public override string Command => DeviceMessage.Command; + protected override ParseDelegate Parse => DeviceMessage.FromGenericMessage; + public override MonitoringCategory MonitoringCategory => MonitoringCategory.Devices; + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/DeviceMessageHandler.cs.meta b/Runtime/Messages/Device/DeviceMessageHandler.cs.meta new file mode 100644 index 00000000..22b625f6 --- /dev/null +++ b/Runtime/Messages/Device/DeviceMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 88948b8ed19a20e40a42d16e46c70610 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Flipper.meta b/Runtime/Messages/Device/Flipper.meta new file mode 100644 index 00000000..4b04c9cd --- /dev/null +++ b/Runtime/Messages/Device/Flipper.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ee948a273374cd946a824fe4449aa9e3 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Flipper/FlipperDeviceMessage.cs b/Runtime/Messages/Device/Flipper/FlipperDeviceMessage.cs new file mode 100644 index 00000000..50d5aaaf --- /dev/null +++ b/Runtime/Messages/Device/Flipper/FlipperDeviceMessage.cs @@ -0,0 +1,22 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.Device.Flipper +{ + public class FlipperDeviceMessage : SpecificDeviceMessageBase + { + public readonly bool Enabled; + + public FlipperDeviceMessage(string deviceName, bool enabled) : base(deviceName) + { + Enabled = enabled; + } + + public static FlipperDeviceMessage FromStateJson(StateJson state, string deviceName) + { + return new(deviceName, state.enabled); + } + + public class StateJson + { + public bool enabled; + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/Flipper/FlipperDeviceMessage.cs.meta b/Runtime/Messages/Device/Flipper/FlipperDeviceMessage.cs.meta new file mode 100644 index 00000000..440b0d3a --- /dev/null +++ b/Runtime/Messages/Device/Flipper/FlipperDeviceMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4b653d0c5755cfc4d9e314f057254b66 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs b/Runtime/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs new file mode 100644 index 00000000..82f1a322 --- /dev/null +++ b/Runtime/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs @@ -0,0 +1,19 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device.Flipper +{ + public class FlipperDeviceMessageHandler : SpecificDeviceMessageHandler + { + protected override string Type => "flipper"; + protected override ParseStateDelegate ParseState => FlipperDeviceMessage.FromStateJson; + public event EventHandler> EnabledChanged; + + protected override void HandleAttributeChange(DeviceAttributeChange change) + { + if (change.AttributeName == nameof(FlipperDeviceMessage.StateJson.enabled)) + EnabledChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + else + throw new UnknownDeviceAttributeException(Type, change.AttributeName); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs.meta b/Runtime/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs.meta new file mode 100644 index 00000000..53ad0960 --- /dev/null +++ b/Runtime/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a897d61eb8c4d854aac92abba797f387 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Light.meta b/Runtime/Messages/Device/Light.meta new file mode 100644 index 00000000..1c871b43 --- /dev/null +++ b/Runtime/Messages/Device/Light.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4ac8a500f26281b408df7682a9df8fbd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Light/LightDeviceMessage.cs b/Runtime/Messages/Device/Light/LightDeviceMessage.cs new file mode 100644 index 00000000..9297d108 --- /dev/null +++ b/Runtime/Messages/Device/Light/LightDeviceMessage.cs @@ -0,0 +1,38 @@ +using System; +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device.Light +{ + public class LightDeviceMessage : SpecificDeviceMessageBase + { + public const string Type = "light"; + public readonly Color LightColor; + + public LightDeviceMessage(string deviceName, Color lightColor) : base(deviceName) + { + LightColor = lightColor; + } + + public static LightDeviceMessage FromStateJson(StateJson state, string deviceName) + { + float r, g, b; + try + { + r = state.color[0] / 255f; + g = state.color[1] / 255f; + b = state.color[2] / 255f; + } + catch (IndexOutOfRangeException e) + { + throw new InvalidDeviceStateException(Type, typeof(StateJson), e); + } + + return new LightDeviceMessage(deviceName, new Color(r, g, b)); + } + + public class StateJson + { + public int[] color; + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/Light/LightDeviceMessage.cs.meta b/Runtime/Messages/Device/Light/LightDeviceMessage.cs.meta new file mode 100644 index 00000000..4be47a0f --- /dev/null +++ b/Runtime/Messages/Device/Light/LightDeviceMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1988d570cb5efd74999f61fa369b0d15 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Light/LightDeviceMessageHandler.cs b/Runtime/Messages/Device/Light/LightDeviceMessageHandler.cs new file mode 100644 index 00000000..7dba9297 --- /dev/null +++ b/Runtime/Messages/Device/Light/LightDeviceMessageHandler.cs @@ -0,0 +1,20 @@ +using System; +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device.Light +{ + public class LightDeviceMessageHandler : SpecificDeviceMessageHandler + { + protected override string Type => LightDeviceMessage.Type; + protected override ParseStateDelegate ParseState => LightDeviceMessage.FromStateJson; + public event EventHandler> ColorChanged; + + protected override void HandleAttributeChange(DeviceAttributeChange change) + { + if (change.AttributeName == nameof(LightDeviceMessage.StateJson.color)) + ColorChanged?.Invoke(this, change.GetEventArgsForColor()); + else + throw new UnknownDeviceAttributeException(change.AttributeName, Type); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/Light/LightDeviceMessageHandler.cs.meta b/Runtime/Messages/Device/Light/LightDeviceMessageHandler.cs.meta new file mode 100644 index 00000000..aa78948b --- /dev/null +++ b/Runtime/Messages/Device/Light/LightDeviceMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2f4eaa1c1d84bc349aca53857b404c4e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Playfield.meta b/Runtime/Messages/Device/Playfield.meta new file mode 100644 index 00000000..1cd241d2 --- /dev/null +++ b/Runtime/Messages/Device/Playfield.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6644d1e818f09344fbe2674cd6b1e22d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessage.cs b/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessage.cs new file mode 100644 index 00000000..bee9a899 --- /dev/null +++ b/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessage.cs @@ -0,0 +1,28 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.Device.Playfield +{ + public class PlayfieldDeviceMessage : SpecificDeviceMessageBase + { + public readonly int AvailableBalls; + public readonly int BallsRequested; + public readonly int Balls; + + public PlayfieldDeviceMessage(string deviceName, int availableBalls, int ballsRequested, int balls) : base(deviceName) + { + AvailableBalls = availableBalls; + BallsRequested = ballsRequested; + Balls = balls; + } + + public static PlayfieldDeviceMessage FromStateJson(StateJson state, string deviceName) + { + return new(deviceName, state.available_balls, state.balls_requested, state.balls); + } + + public class StateJson + { + public int available_balls; + public int balls_requested; + public int balls; + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessage.cs.meta b/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessage.cs.meta new file mode 100644 index 00000000..0b0a7c17 --- /dev/null +++ b/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e49fa29c4b589c54b8e7d8ff3c73f81a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs b/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs new file mode 100644 index 00000000..54041e2f --- /dev/null +++ b/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs @@ -0,0 +1,32 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device.Playfield +{ + public class PlayfieldDeviceMessageHandler : SpecificDeviceMessageHandler + { + protected override string Type => "playfield"; + protected override ParseStateDelegate ParseState => PlayfieldDeviceMessage.FromStateJson; + + public event EventHandler> AvailableBallsChanged; + public event EventHandler> BallsRequestedChanged; + public event EventHandler> BallsChanged; + + protected override void HandleAttributeChange(DeviceAttributeChange change) + { + switch (change.AttributeName) + { + case nameof(PlayfieldDeviceMessage.StateJson.available_balls): + AvailableBallsChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + break; + case nameof(PlayfieldDeviceMessage.StateJson.balls_requested): + BallsRequestedChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + break; + case nameof(PlayfieldDeviceMessage.StateJson.balls): + BallsChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + break; + default: + throw new UnknownDeviceAttributeException(Type, change.AttributeName); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs.meta b/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs.meta new file mode 100644 index 00000000..66159570 --- /dev/null +++ b/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: efa4c5ba2b359bf4b98840550adf57d8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/SpecificDeviceMessageBase.cs b/Runtime/Messages/Device/SpecificDeviceMessageBase.cs new file mode 100644 index 00000000..ba024ad7 --- /dev/null +++ b/Runtime/Messages/Device/SpecificDeviceMessageBase.cs @@ -0,0 +1,14 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device +{ + public abstract class SpecificDeviceMessageBase : EventArgs + { + public readonly string Name; + + public SpecificDeviceMessageBase(string name) + { + Name = name; + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/SpecificDeviceMessageBase.cs.meta b/Runtime/Messages/Device/SpecificDeviceMessageBase.cs.meta new file mode 100644 index 00000000..7057d887 --- /dev/null +++ b/Runtime/Messages/Device/SpecificDeviceMessageBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6d28bc48081010a4fa58a2087ed53407 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs b/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs new file mode 100644 index 00000000..95bc2295 --- /dev/null +++ b/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs @@ -0,0 +1,60 @@ +using UnityEngine; +using System; +using Newtonsoft.Json; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device +{ + public abstract class SpecificDeviceMessageHandler : MonoBehaviour where MessageType : SpecificDeviceMessageBase + { + [SerializeField] + private string deviceName; + [SerializeField] + private DeviceMessageHandler generalDeviceMessageHandler; + + protected abstract string Type { get; } + protected delegate MessageType ParseStateDelegate(StateJsonFormat deserializedState, string deviceName); + protected abstract ParseStateDelegate ParseState { get; } + public event EventHandler StateUpdated; + + protected void OnEnable() + { + generalDeviceMessageHandler.Received += HandleDeviceMessageReceived; + } + + protected void OnDisable() + { + if (generalDeviceMessageHandler) + generalDeviceMessageHandler.Received -= HandleDeviceMessageReceived; + } + + private void HandleDeviceMessageReceived(object sender, DeviceMessage deviceMessage) + { + if (deviceMessage.Type != Type) + return; + + if (deviceMessage.Name != deviceName) + return; + + if (deviceMessage.Change != null) + HandleAttributeChange(deviceMessage.Change); + + StateJsonFormat deserializedState; + try + { + deserializedState = JsonConvert.DeserializeObject(deviceMessage.StateJson, new JsonSerializerSettings + { + MissingMemberHandling = MissingMemberHandling.Error + }); + } + catch (JsonSerializationException jse) + { + throw new InvalidDeviceStateException(deviceMessage.Type, typeof(StateJsonFormat), jse); + } + + MessageType specificDeviceMessage = ParseState(deserializedState, deviceMessage.Name); + StateUpdated?.Invoke(this, specificDeviceMessage); + } + + protected abstract void HandleAttributeChange(DeviceAttributeChange change); + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs.meta b/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs.meta new file mode 100644 index 00000000..8f98f827 --- /dev/null +++ b/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9f397b3e96ee46742974f41912be8635 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Switch.meta b/Runtime/Messages/Device/Switch.meta new file mode 100644 index 00000000..89768082 --- /dev/null +++ b/Runtime/Messages/Device/Switch.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a46fd18f9f3596e44a416a42a1d19f51 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Switch/SwitchDeviceMessage.cs b/Runtime/Messages/Device/Switch/SwitchDeviceMessage.cs new file mode 100644 index 00000000..aca24649 --- /dev/null +++ b/Runtime/Messages/Device/Switch/SwitchDeviceMessage.cs @@ -0,0 +1,25 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.Device.Switch +{ + public class SwitchDeviceMessage : SpecificDeviceMessageBase + { + public readonly bool IsActive; + public readonly int RecycleJitterCount; + + public SwitchDeviceMessage(string deviceName, bool isActive, int recycleJitterCount) : base(deviceName) + { + IsActive = isActive; + RecycleJitterCount = recycleJitterCount; + } + + public static SwitchDeviceMessage FromStateJson(StateJson state, string deviceName) + { + return new(deviceName, state.state != 0, state.recycle_jitter_count); + } + + public class StateJson + { + public int state; + public int recycle_jitter_count; + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/Switch/SwitchDeviceMessage.cs.meta b/Runtime/Messages/Device/Switch/SwitchDeviceMessage.cs.meta new file mode 100644 index 00000000..700e6f39 --- /dev/null +++ b/Runtime/Messages/Device/Switch/SwitchDeviceMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2c185714a885d7f4ea377b76d2d0bb07 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Device/Switch/SwitchDeviceMessageHandler.cs b/Runtime/Messages/Device/Switch/SwitchDeviceMessageHandler.cs new file mode 100644 index 00000000..d652e848 --- /dev/null +++ b/Runtime/Messages/Device/Switch/SwitchDeviceMessageHandler.cs @@ -0,0 +1,35 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Device.Switch +{ + public class SwitchDeviceMessageHandler : SpecificDeviceMessageHandler + { + protected override string Type => "switch"; + protected override ParseStateDelegate ParseState => SwitchDeviceMessage.FromStateJson; + public event EventHandler> IsActiveChanged; + public event EventHandler> RecycleJitterCountChanged; + + protected override void HandleAttributeChange(DeviceAttributeChange change) + { + switch (change.AttributeName) + { + case nameof(SwitchDeviceMessage.StateJson.state): + change = new(change.AttributeName, + ConvertIsActiveString(change.OldValue), + ConvertIsActiveString(change.NewValue)); + IsActiveChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + break; + case nameof(SwitchDeviceMessage.StateJson.recycle_jitter_count): + RecycleJitterCountChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + break; + default: + throw new UnknownDeviceAttributeException(change.AttributeName, Type); + } + } + + private string ConvertIsActiveString(string isActive) + { + return isActive == "0" ? "false" : "true"; + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Device/Switch/SwitchDeviceMessageHandler.cs.meta b/Runtime/Messages/Device/Switch/SwitchDeviceMessageHandler.cs.meta new file mode 100644 index 00000000..5c4c0640 --- /dev/null +++ b/Runtime/Messages/Device/Switch/SwitchDeviceMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3efcd852325eff943af6953f6c777912 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Error.meta b/Runtime/Messages/Error.meta new file mode 100644 index 00000000..3bf5b905 --- /dev/null +++ b/Runtime/Messages/Error.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f8c2c2e9bd5a1cb4cbd2e2f2552ef1cc +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/ErrorMessage.cs b/Runtime/Messages/Error/ErrorMessage.cs similarity index 95% rename from Runtime/Messages/ErrorMessage.cs rename to Runtime/Messages/Error/ErrorMessage.cs index 26ccbf2e..3a6a3331 100644 --- a/Runtime/Messages/ErrorMessage.cs +++ b/Runtime/Messages/Error/ErrorMessage.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Error { public class ErrorMessage : EventArgs, ISentMessage { diff --git a/Runtime/Messages/ErrorMessage.cs.meta b/Runtime/Messages/Error/ErrorMessage.cs.meta similarity index 100% rename from Runtime/Messages/ErrorMessage.cs.meta rename to Runtime/Messages/Error/ErrorMessage.cs.meta diff --git a/Runtime/MessageHandlers/ErrorMessageHandler.cs b/Runtime/Messages/Error/ErrorMessageHandler.cs similarity index 78% rename from Runtime/MessageHandlers/ErrorMessageHandler.cs rename to Runtime/Messages/Error/ErrorMessageHandler.cs index c874b8f1..1a437704 100644 --- a/Runtime/MessageHandlers/ErrorMessageHandler.cs +++ b/Runtime/Messages/Error/ErrorMessageHandler.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Error { public class ErrorMessageHandler : BcpMessageHandler { diff --git a/Runtime/MessageHandlers/ErrorMessageHandler.cs.meta b/Runtime/Messages/Error/ErrorMessageHandler.cs.meta similarity index 100% rename from Runtime/MessageHandlers/ErrorMessageHandler.cs.meta rename to Runtime/Messages/Error/ErrorMessageHandler.cs.meta diff --git a/Runtime/Messages/Goodbye.meta b/Runtime/Messages/Goodbye.meta new file mode 100644 index 00000000..f7b23e62 --- /dev/null +++ b/Runtime/Messages/Goodbye.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1949d665da6980940b545286b694ddb2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/GoodbyeMessage.cs b/Runtime/Messages/Goodbye/GoodbyeMessage.cs similarity index 81% rename from Runtime/Messages/GoodbyeMessage.cs rename to Runtime/Messages/Goodbye/GoodbyeMessage.cs index 779f84d3..df77b727 100644 --- a/Runtime/Messages/GoodbyeMessage.cs +++ b/Runtime/Messages/Goodbye/GoodbyeMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Goodbye { public class GoodbyeMessage : EventArgs, ISentMessage { diff --git a/Runtime/Messages/GoodbyeMessage.cs.meta b/Runtime/Messages/Goodbye/GoodbyeMessage.cs.meta similarity index 83% rename from Runtime/Messages/GoodbyeMessage.cs.meta rename to Runtime/Messages/Goodbye/GoodbyeMessage.cs.meta index 308c240b..00a46f41 100644 --- a/Runtime/Messages/GoodbyeMessage.cs.meta +++ b/Runtime/Messages/Goodbye/GoodbyeMessage.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ebc3f3e430459444988aece8b374d564 +guid: 3711e967b78243c4e8829a354b02e88a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/MessageHandlers/GoodbyeMessageHandler.cs b/Runtime/Messages/Goodbye/GoodbyeMessageHandler.cs similarity index 78% rename from Runtime/MessageHandlers/GoodbyeMessageHandler.cs rename to Runtime/Messages/Goodbye/GoodbyeMessageHandler.cs index d1127e35..f3fa8fdf 100644 --- a/Runtime/MessageHandlers/GoodbyeMessageHandler.cs +++ b/Runtime/Messages/Goodbye/GoodbyeMessageHandler.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Goodbye { public class GoodbyeMessageHandler : BcpMessageHandler { diff --git a/Runtime/MessageHandlers/GoodbyeMessageHandler.cs.meta b/Runtime/Messages/Goodbye/GoodbyeMessageHandler.cs.meta similarity index 83% rename from Runtime/MessageHandlers/GoodbyeMessageHandler.cs.meta rename to Runtime/Messages/Goodbye/GoodbyeMessageHandler.cs.meta index 4a86ea50..e9434984 100644 --- a/Runtime/MessageHandlers/GoodbyeMessageHandler.cs.meta +++ b/Runtime/Messages/Goodbye/GoodbyeMessageHandler.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4ad4af17d27824a418620638a7c60d96 +guid: 6f9bc1ba9f51a604db49e1a6e7f59a86 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Messages/Hello.meta b/Runtime/Messages/Hello.meta new file mode 100644 index 00000000..b698794e --- /dev/null +++ b/Runtime/Messages/Hello.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6fa3f7c4c430f2d4ca2b79c8716f86a9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/HelloMessage.cs b/Runtime/Messages/Hello/HelloMessage.cs similarity index 96% rename from Runtime/Messages/HelloMessage.cs rename to Runtime/Messages/Hello/HelloMessage.cs index 00b9aba6..d65f08bf 100644 --- a/Runtime/Messages/HelloMessage.cs +++ b/Runtime/Messages/Hello/HelloMessage.cs @@ -1,8 +1,7 @@ - using System.Collections.Generic; using System; -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Hello { public class HelloMessage : EventArgs, ISentMessage { diff --git a/Runtime/Messages/HelloMessage.cs.meta b/Runtime/Messages/Hello/HelloMessage.cs.meta similarity index 100% rename from Runtime/Messages/HelloMessage.cs.meta rename to Runtime/Messages/Hello/HelloMessage.cs.meta diff --git a/Runtime/MessageHandlers/HelloMessageHandler.cs b/Runtime/Messages/Hello/HelloMessageHandler.cs similarity index 78% rename from Runtime/MessageHandlers/HelloMessageHandler.cs rename to Runtime/Messages/Hello/HelloMessageHandler.cs index 9ba48881..a16000db 100644 --- a/Runtime/MessageHandlers/HelloMessageHandler.cs +++ b/Runtime/Messages/Hello/HelloMessageHandler.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Hello { public class HelloMessageHandler : BcpMessageHandler { diff --git a/Runtime/MessageHandlers/HelloMessageHandler.cs.meta b/Runtime/Messages/Hello/HelloMessageHandler.cs.meta similarity index 100% rename from Runtime/MessageHandlers/HelloMessageHandler.cs.meta rename to Runtime/Messages/Hello/HelloMessageHandler.cs.meta diff --git a/Runtime/Messages/Monitor.meta b/Runtime/Messages/Monitor.meta new file mode 100644 index 00000000..c63b7352 --- /dev/null +++ b/Runtime/Messages/Monitor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7bd56004712b5654f8990c6f8264cce0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/MonitorStartMessage.cs b/Runtime/Messages/Monitor/MonitorStartMessage.cs similarity index 93% rename from Runtime/Messages/MonitorStartMessage.cs rename to Runtime/Messages/Monitor/MonitorStartMessage.cs index 1b16f5b6..4921e46c 100644 --- a/Runtime/Messages/MonitorStartMessage.cs +++ b/Runtime/Messages/Monitor/MonitorStartMessage.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Monitor { public class MonitorStartMessage : EventArgs, ISentMessage { diff --git a/Runtime/Messages/MonitorStartMessage.cs.meta b/Runtime/Messages/Monitor/MonitorStartMessage.cs.meta similarity index 100% rename from Runtime/Messages/MonitorStartMessage.cs.meta rename to Runtime/Messages/Monitor/MonitorStartMessage.cs.meta diff --git a/Runtime/Messages/MonitorStopMessage.cs b/Runtime/Messages/Monitor/MonitorStopMessage.cs similarity index 93% rename from Runtime/Messages/MonitorStopMessage.cs rename to Runtime/Messages/Monitor/MonitorStopMessage.cs index e1a63ff2..f60e35d3 100644 --- a/Runtime/Messages/MonitorStopMessage.cs +++ b/Runtime/Messages/Monitor/MonitorStopMessage.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Monitor { public class MonitorStopMessage : EventArgs, ISentMessage { diff --git a/Runtime/Messages/MonitorStopMessage.cs.meta b/Runtime/Messages/Monitor/MonitorStopMessage.cs.meta similarity index 100% rename from Runtime/Messages/MonitorStopMessage.cs.meta rename to Runtime/Messages/Monitor/MonitorStopMessage.cs.meta diff --git a/Runtime/Messages/ParameterTypes/MonitoringCategory.cs b/Runtime/Messages/Monitor/MonitoringCategory.cs similarity index 77% rename from Runtime/Messages/ParameterTypes/MonitoringCategory.cs rename to Runtime/Messages/Monitor/MonitoringCategory.cs index 62b2b32d..f9609048 100644 --- a/Runtime/Messages/ParameterTypes/MonitoringCategory.cs +++ b/Runtime/Messages/Monitor/MonitoringCategory.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Monitor { public enum MonitoringCategory { @@ -6,6 +6,8 @@ public enum MonitoringCategory None, [StringValue("events")] Events, + [StringValue("devices")] + Devices, [StringValue("machine_vars")] MachineVars, [StringValue("player_vars")] diff --git a/Runtime/Messages/ParameterTypes/MonitoringCategory.cs.meta b/Runtime/Messages/Monitor/MonitoringCategory.cs.meta similarity index 100% rename from Runtime/Messages/ParameterTypes/MonitoringCategory.cs.meta rename to Runtime/Messages/Monitor/MonitoringCategory.cs.meta diff --git a/Runtime/Messages/Reset.meta b/Runtime/Messages/Reset.meta new file mode 100644 index 00000000..7c1902b4 --- /dev/null +++ b/Runtime/Messages/Reset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2d389b7d25533ff409621880ab22ab4c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/ResetCompleteMessage.cs b/Runtime/Messages/Reset/ResetCompleteMessage.cs similarity index 83% rename from Runtime/Messages/ResetCompleteMessage.cs rename to Runtime/Messages/Reset/ResetCompleteMessage.cs index 4f3f40f1..36c6e73d 100644 --- a/Runtime/Messages/ResetCompleteMessage.cs +++ b/Runtime/Messages/Reset/ResetCompleteMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Reset { public class ResetCompleteMessage : EventArgs, ISentMessage { diff --git a/Runtime/Messages/ResetCompleteMessage.cs.meta b/Runtime/Messages/Reset/ResetCompleteMessage.cs.meta similarity index 100% rename from Runtime/Messages/ResetCompleteMessage.cs.meta rename to Runtime/Messages/Reset/ResetCompleteMessage.cs.meta diff --git a/Runtime/Messages/ResetMessage.cs b/Runtime/Messages/Reset/ResetMessage.cs similarity index 76% rename from Runtime/Messages/ResetMessage.cs rename to Runtime/Messages/Reset/ResetMessage.cs index f6ba660a..6754a830 100644 --- a/Runtime/Messages/ResetMessage.cs +++ b/Runtime/Messages/Reset/ResetMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Reset { public class ResetMessage : EventArgs { diff --git a/Runtime/Messages/ResetMessage.cs.meta b/Runtime/Messages/Reset/ResetMessage.cs.meta similarity index 100% rename from Runtime/Messages/ResetMessage.cs.meta rename to Runtime/Messages/Reset/ResetMessage.cs.meta diff --git a/Runtime/MessageHandlers/ResetMessageHandler.cs b/Runtime/Messages/Reset/ResetMessageHandler.cs similarity index 86% rename from Runtime/MessageHandlers/ResetMessageHandler.cs rename to Runtime/Messages/Reset/ResetMessageHandler.cs index 41fee764..ba04efb7 100644 --- a/Runtime/MessageHandlers/ResetMessageHandler.cs +++ b/Runtime/Messages/Reset/ResetMessageHandler.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController +namespace FutureBoxSystems.MpfMediaController.Messages.Reset { public class ResetMessageHandler : BcpMessageHandler { diff --git a/Runtime/MessageHandlers/ResetMessageHandler.cs.meta b/Runtime/Messages/Reset/ResetMessageHandler.cs.meta similarity index 100% rename from Runtime/MessageHandlers/ResetMessageHandler.cs.meta rename to Runtime/Messages/Reset/ResetMessageHandler.cs.meta diff --git a/Runtime/Utils/StringEnum.cs b/Runtime/Utils/StringEnum.cs index bf37b008..93043275 100644 --- a/Runtime/Utils/StringEnum.cs +++ b/Runtime/Utils/StringEnum.cs @@ -1,11 +1,12 @@ -// Maps enum values to arbitrary strings and back using a custom attribute -// Based on: https://weblogs.asp.net/stefansedich/enum-with-string-values-in-c - +// Based on: https://weblogs.asp.net/stefansedich/enum-with-string-values-in-c using System; using System.Reflection; namespace FutureBoxSystems.MpfMediaController { + /// + /// Associates an enum value with a string + /// [AttributeUsage(AttributeTargets.Field)] public class StringValueAttribute : Attribute { @@ -17,6 +18,9 @@ public StringValueAttribute(string value) } } + /// + /// Maps enum values to arbitrary strings and back using a custom attribute + /// public static class StringEnum { public static string GetStringValue(this Enum value) @@ -28,6 +32,11 @@ public static string GetStringValue(this Enum value) } public static T GetValueFromString(string value) where T : Enum + { + return GetValueFromStringUnsafe(value); + } + + public static T GetValueFromStringUnsafe(string value) { Type enumType = typeof(T); if (!enumType.IsEnum) @@ -38,7 +47,7 @@ public static T GetValueFromString(string value) where T : Enum foreach (var field in enumType.GetFields(BindingFlags.Public | BindingFlags.Static)) { if (Attribute.GetCustomAttribute(field, typeof(StringValueAttribute)) is StringValueAttribute attribute) - { + { if (attribute.StringValue == value) { return (T)field.GetValue(null); From 6da11bc32266070d494448a7349b97d02391e85b Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:33:05 +0200 Subject: [PATCH 33/98] Add GetParamValue and TryGetParamValue variants --- Runtime/Core/BcpMessage.cs | 9 ++++++++- Runtime/Messages/Device/DeviceMessage.cs | 2 +- Runtime/Messages/Error/ErrorMessage.cs | 4 ++-- Runtime/Messages/Hello/HelloMessage.cs | 6 +++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Runtime/Core/BcpMessage.cs b/Runtime/Core/BcpMessage.cs index 2fb70a7d..43ab4151 100644 --- a/Runtime/Core/BcpMessage.cs +++ b/Runtime/Core/BcpMessage.cs @@ -21,7 +21,14 @@ public BcpMessage(string command, List parameters) public BcpMessage(string command) : this(command, new()) { } - public string FindParamValue(string name, string typeHint = null) + public bool TryGetParamValue(string name, out string value, string typeHint = null) + { + BcpParameter param = parameters.FirstOrDefault(p => p.MatchesPattern(name, typeHint)); + value = param?.Value; + return param != null; + } + + public string GetParamValue(string name, string typeHint = null) { try { diff --git a/Runtime/Messages/Device/DeviceMessage.cs b/Runtime/Messages/Device/DeviceMessage.cs index 9db46a21..310a4bb5 100644 --- a/Runtime/Messages/Device/DeviceMessage.cs +++ b/Runtime/Messages/Device/DeviceMessage.cs @@ -23,7 +23,7 @@ public DeviceMessage(string type, string name, DeviceAttributeChange change, str public static DeviceMessage FromGenericMessage(BcpMessage bcpMessage) { - var jsonString = bcpMessage.FindParamValue(jsonParamName); + var jsonString = bcpMessage.GetParamValue(jsonParamName); try { var jsonObject = JObject.Parse(jsonString); diff --git a/Runtime/Messages/Error/ErrorMessage.cs b/Runtime/Messages/Error/ErrorMessage.cs index 3a6a3331..eafc738d 100644 --- a/Runtime/Messages/Error/ErrorMessage.cs +++ b/Runtime/Messages/Error/ErrorMessage.cs @@ -32,8 +32,8 @@ public BcpMessage ToGenericMessage() public static ErrorMessage FromGenericMessage(BcpMessage bcpMessage) { return new ErrorMessage( - message: bcpMessage.FindParamValue(messageName), - commandThatCausedError: bcpMessage.FindParamValue(commandThatCausedErrorName) + message: bcpMessage.GetParamValue(messageName), + commandThatCausedError: bcpMessage.GetParamValue(commandThatCausedErrorName) ); } } diff --git a/Runtime/Messages/Hello/HelloMessage.cs b/Runtime/Messages/Hello/HelloMessage.cs index d65f08bf..db3e5609 100644 --- a/Runtime/Messages/Hello/HelloMessage.cs +++ b/Runtime/Messages/Hello/HelloMessage.cs @@ -36,9 +36,9 @@ public BcpMessage ToGenericMessage() public static HelloMessage FromGenericMessage(BcpMessage bcpMessage) { return new HelloMessage( - version: bcpMessage.FindParamValue(versionName), - controllerName: bcpMessage.FindParamValue(controllerNameName), - controllerVersion: bcpMessage.FindParamValue(controllerVersionName) + version: bcpMessage.GetParamValue(versionName), + controllerName: bcpMessage.GetParamValue(controllerNameName), + controllerVersion: bcpMessage.GetParamValue(controllerVersionName) ); } } From c64473dda044465c68f2aacbd16851a03bbc6827 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 11:05:41 +0100 Subject: [PATCH 34/98] Refactor parameter parsing --- Runtime/Core/BcpInterface.cs | 1 + Runtime/Core/BcpMessage.cs | 154 +++++++++++------- Runtime/Core/BcpServer.cs | 3 +- Runtime/Messages/Device/DeviceMessage.cs | 46 +++--- .../Device/SpecificDeviceMessageHandler.cs | 9 +- Runtime/Messages/Error/ErrorMessage.cs | 19 +-- Runtime/Messages/Hello/HelloMessage.cs | 18 +- .../Messages/Monitor/MonitorStartMessage.cs | 5 +- .../Messages/Monitor/MonitorStopMessage.cs | 6 +- 9 files changed, 144 insertions(+), 117 deletions(-) diff --git a/Runtime/Core/BcpInterface.cs b/Runtime/Core/BcpInterface.cs index ff40c188..db0e633e 100644 --- a/Runtime/Core/BcpInterface.cs +++ b/Runtime/Core/BcpInterface.cs @@ -99,6 +99,7 @@ private void HandleServerStateChanged(object sender, ConnectionStateChangedEvent if (userCount > 0) TrySendMessage(new MonitorStartMessage(category)); } + TrySendMessage(new MonitorStartMessage(MonitoringCategory.MachineVars)); } } diff --git a/Runtime/Core/BcpMessage.cs b/Runtime/Core/BcpMessage.cs index 43ab4151..ce661120 100644 --- a/Runtime/Core/BcpMessage.cs +++ b/Runtime/Core/BcpMessage.cs @@ -1,3 +1,5 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; @@ -7,37 +9,36 @@ namespace FutureBoxSystems.MpfMediaController { public class BcpMessage { - public string Command { get; private set; } - public IReadOnlyList Parameters => parameters.AsReadOnly(); - private readonly List parameters; + public readonly string Command; + private readonly JObject parameters; + private readonly bool hasComplexParams; private const char commandParamsSeparator = '?'; private const char paramsSeparator = '&'; - public BcpMessage(string command, List parameters) + public BcpMessage(string command, JObject parameters, bool hasComplexParams = false) { Command = command; this.parameters = parameters; + this.hasComplexParams = hasComplexParams; } public BcpMessage(string command) : this(command, new()) { } - public bool TryGetParamValue(string name, out string value, string typeHint = null) - { - BcpParameter param = parameters.FirstOrDefault(p => p.MatchesPattern(name, typeHint)); - value = param?.Value; - return param != null; - } - - public string GetParamValue(string name, string typeHint = null) + public T GetParamValue(string name) { try { - var param = parameters.First(p => p.MatchesPattern(name, typeHint)); - return param.Value; + var token = parameters[name]; + + // If string is requested, but parsed type is different, just return the unparsed JSON string + if (typeof(T) == typeof(string) && token.Type != JTokenType.String) + return (T)Convert.ChangeType(token.ToString(Formatting.None), typeof(T)); + + return (T)Convert.ChangeType(token, typeof(T)); } - catch (InvalidOperationException ioe) + catch (Exception e) when (e is KeyNotFoundException || e is InvalidCastException) { - throw new ParameterException(name, this, ioe); + throw new ParameterException(name, this, e); } } @@ -48,12 +49,23 @@ public string ToString(bool encode) var sb = new StringBuilder(Command); if (parameters.Count > 0) sb.Append(commandParamsSeparator); - for (int i = 0; i < parameters.Count; i++) + + if (hasComplexParams) + { + sb.Append($"json={parameters.ToString(Formatting.None)}"); + } + else { - sb.Append(parameters[i].ToString(encode)); - bool isLastParam = i == parameters.Count - 1; - if (!isLastParam) - sb.Append(paramsSeparator); + var properties = parameters.Properties(); + for (int i = 0; i < properties.Count(); i++) + { + JProperty prop = properties.ElementAt(i); + string propStr = PropertyToString(prop, encode); + sb.Append(propStr); + bool isLastParam = i == parameters.Count - 1; + if (!isLastParam) + sb.Append(paramsSeparator); + } } return sb.ToString(); } @@ -62,70 +74,94 @@ public static BcpMessage FromString(string str) { var parts = str.Split(commandParamsSeparator, paramsSeparator); var command = parts[0].Trim().ToLower(); - var bcpParams = new List(); + var containsJson = false; + JObject parameters = new(); for (int i = 1; i < parts.Length; i++) { - var param = BcpParameter.FromString(parts[i]); - bcpParams.Add(param); + JProperty property = StringToProperty(parts[i]); + if (property.Name == "json" && property.Value is JObject) + { + containsJson = true; + // Unwrap json params + foreach (var subProperty in (property.Value as JObject).Properties()) + { + parameters.Add(subProperty.Name, subProperty.Value); + } + } + else + parameters.Add(property.Name, property.Value); } - return new BcpMessage(command, bcpParams); + return new BcpMessage(command, parameters, containsJson); } - } - - public class BcpParameter - { - public string Name { get; private set; } - public string TypeHint { get; private set; } - public string Value { get; private set; } - public BcpParameter(string name, string value, string typeHint = null) + private static string PropertyToString(JProperty property, bool encode) { - Name = name; - TypeHint = typeHint; - Value = value; - } + var name = property.Name; + string value; + if (property.Value.HasValues) + value = property.Value.ToString(Formatting.None); + else + value = (string)property.Value; + if (encode) + { + name = Uri.EscapeDataString(name); + value = Uri.EscapeDataString(value); + } - public override string ToString() => ToString(encode: false); + string typeHint = property.Value.Type switch + { + JTokenType.Integer => "int", + JTokenType.Float => "float", + JTokenType.Boolean => "bool", + JTokenType.Null => "NoneType", + _ => null, + }; - public string ToString(bool encode) - { - var name = encode ? Uri.EscapeDataString(Name) : Name; - var value = encode ? Uri.EscapeDataString(Value) : Value; - if (string.IsNullOrEmpty(TypeHint)) + if (string.IsNullOrEmpty(typeHint)) return $"{name}={value}"; - return $"{name}={TypeHint}:{value}"; + return $"{name}={typeHint}:{value}"; } - public bool MatchesPattern(string name, string typeHint) - { - return Name.Equals(name, StringComparison.OrdinalIgnoreCase) && - (TypeHint == typeHint || - TypeHint.Equals(typeHint, StringComparison.OrdinalIgnoreCase)); - } - - public static BcpParameter FromString(string str) + private static JProperty StringToProperty(string str) { string[] parts = str.Split('=', 2); - var name = parts[0].Trim().ToLower(); // Not case sensitive - string typeHint = null; - string value = null; + string name = parts[0].Trim().ToLower(); // Not case sensitive + name = Uri.UnescapeDataString(name); + JToken value = null; if (parts.Length == 2) { if (name == "json") - value = parts[1]; + { + string valueStr = parts[1]; + Uri.UnescapeDataString(valueStr); + value = JObject.Parse(valueStr); + } else { + string typeHint = null; + string valueStr; parts = parts[1].Split(':', 2); if (parts.Length == 2) { typeHint = parts[0]; - value = parts[1]; + valueStr = parts[1]; } else - value = parts[0]; + valueStr = parts[0]; + valueStr = Uri.UnescapeDataString(valueStr); + value = typeHint switch + { + "bool" => new JValue((bool)Convert.ChangeType(valueStr, typeof(bool))), + "int" => new JValue((int)Convert.ChangeType(valueStr, typeof(int))), + "float" => new JValue((float)Convert.ChangeType(valueStr, typeof(float))), + "NoneType" => null, + _ => new JValue(valueStr) + }; } } - return new BcpParameter(name, value, typeHint); + + + return new JProperty(name, value); } } diff --git a/Runtime/Core/BcpServer.cs b/Runtime/Core/BcpServer.cs index 5305333a..87f093a9 100644 --- a/Runtime/Core/BcpServer.cs +++ b/Runtime/Core/BcpServer.cs @@ -182,8 +182,7 @@ private async Task ReceiveMessagesAsync(NetworkStream stream, while (!ct.IsCancellationRequested && (messageLength = stringBuffer.ToString().IndexOf(terminator)) > -1) { var message = stringBuffer.ToString(0, messageLength); - stringBuffer.Remove(0, messageLength + 1); - message = Uri.UnescapeDataString(message); + stringBuffer.Remove(0, messageLength + 1); if (message.Length > 0 && !message.StartsWith("#")) { var bcpMessage = BcpMessage.FromString(message); diff --git a/Runtime/Messages/Device/DeviceMessage.cs b/Runtime/Messages/Device/DeviceMessage.cs index 310a4bb5..5e550fd5 100644 --- a/Runtime/Messages/Device/DeviceMessage.cs +++ b/Runtime/Messages/Device/DeviceMessage.cs @@ -1,5 +1,4 @@ using System; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace FutureBoxSystems.MpfMediaController.Messages.Device @@ -7,44 +6,41 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Device public class DeviceMessage : EventArgs { public const string Command = "device"; - private const string jsonParamName = "json"; public readonly string Type; public readonly string Name; public readonly DeviceAttributeChange Change; - public readonly string StateJson; - - public DeviceMessage(string type, string name, DeviceAttributeChange change, string stateJson) + public readonly JObject State; + + public DeviceMessage(string type, string name, DeviceAttributeChange change, JObject state) { Type = type; Name = name; Change = change; - StateJson = stateJson; + State = state; } public static DeviceMessage FromGenericMessage(BcpMessage bcpMessage) { - var jsonString = bcpMessage.GetParamValue(jsonParamName); - try + var type = bcpMessage.GetParamValue("type"); + var name = bcpMessage.GetParamValue("name"); + var changeStr = bcpMessage.GetParamValue("changes"); + var state = bcpMessage.GetParamValue("state"); + DeviceAttributeChange change; + if (changeStr.ToLower() == "false") + change = null; + else { - var jsonObject = JObject.Parse(jsonString); - var type = (string)jsonObject["type"]; - var name = (string)jsonObject["name"]; - var changes = jsonObject["changes"].ToString(); - var stateJson = jsonObject["state"].ToString(); - DeviceAttributeChange change; - if (changes.ToLower() == "false") - change = null; - else + try { - var arr = JsonConvert.DeserializeObject(changes); - change = new(arr[0], arr[1], arr[2]); + var arr = bcpMessage.GetParamValue("changes"); + change = new DeviceAttributeChange((string)arr[0], (string)arr[1], (string)arr[2]); + } + catch (ArgumentOutOfRangeException e) + { + throw new ParameterException("changes", bcpMessage, e); } - return new(type, name, change, stateJson); - } - catch (Exception e) when (e is JsonException || e is IndexOutOfRangeException || e is ArgumentNullException) - { - throw new ParameterException(jsonParamName, bcpMessage, e); } + return new(type, name, change, state); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs b/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs index 95bc2295..84b8661c 100644 --- a/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs +++ b/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs @@ -41,14 +41,11 @@ private void HandleDeviceMessageReceived(object sender, DeviceMessage deviceMess StateJsonFormat deserializedState; try { - deserializedState = JsonConvert.DeserializeObject(deviceMessage.StateJson, new JsonSerializerSettings - { - MissingMemberHandling = MissingMemberHandling.Error - }); + deserializedState = deviceMessage.State.ToObject(); } - catch (JsonSerializationException jse) + catch (JsonException e) { - throw new InvalidDeviceStateException(deviceMessage.Type, typeof(StateJsonFormat), jse); + throw new InvalidDeviceStateException(deviceMessage.Type, typeof(StateJsonFormat), e); } MessageType specificDeviceMessage = ParseState(deserializedState, deviceMessage.Name); diff --git a/Runtime/Messages/Error/ErrorMessage.cs b/Runtime/Messages/Error/ErrorMessage.cs index eafc738d..f5ee3707 100644 --- a/Runtime/Messages/Error/ErrorMessage.cs +++ b/Runtime/Messages/Error/ErrorMessage.cs @@ -1,5 +1,5 @@ -using System; -using System.Collections.Generic; +using Newtonsoft.Json.Linq; +using System; namespace FutureBoxSystems.MpfMediaController.Messages.Error { @@ -10,21 +10,20 @@ public class ErrorMessage : EventArgs, ISentMessage private const string commandThatCausedErrorName = "command"; public string Message { get; private set; } public string CommandThatCausedError { get; private set; } - + public ErrorMessage(string message, string commandThatCausedError) { Message = message; CommandThatCausedError = commandThatCausedError; } - + public BcpMessage ToGenericMessage() { return new BcpMessage( command: Command, - parameters: new List() - { - new(messageName, Message), - new(commandThatCausedErrorName, CommandThatCausedError) + parameters: new JObject{ + { messageName, Message }, + { commandThatCausedErrorName, CommandThatCausedError } } ); } @@ -32,8 +31,8 @@ public BcpMessage ToGenericMessage() public static ErrorMessage FromGenericMessage(BcpMessage bcpMessage) { return new ErrorMessage( - message: bcpMessage.GetParamValue(messageName), - commandThatCausedError: bcpMessage.GetParamValue(commandThatCausedErrorName) + message: bcpMessage.GetParamValue(messageName), + commandThatCausedError: bcpMessage.GetParamValue(commandThatCausedErrorName) ); } } diff --git a/Runtime/Messages/Hello/HelloMessage.cs b/Runtime/Messages/Hello/HelloMessage.cs index db3e5609..f8f2a263 100644 --- a/Runtime/Messages/Hello/HelloMessage.cs +++ b/Runtime/Messages/Hello/HelloMessage.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using Newtonsoft.Json.Linq; using System; namespace FutureBoxSystems.MpfMediaController.Messages.Hello @@ -24,11 +24,10 @@ public BcpMessage ToGenericMessage() { return new BcpMessage( command: Command, - parameters: new List() - { - new(versionName, BcpSpecVersion), - new(controllerNameName, ControllerName), - new(controllerVersionName, ControllerVersion) + parameters: new JObject{ + { versionName, BcpSpecVersion }, + { controllerNameName, ControllerName }, + { controllerVersionName, ControllerVersion } } ); } @@ -36,10 +35,9 @@ public BcpMessage ToGenericMessage() public static HelloMessage FromGenericMessage(BcpMessage bcpMessage) { return new HelloMessage( - version: bcpMessage.GetParamValue(versionName), - controllerName: bcpMessage.GetParamValue(controllerNameName), - controllerVersion: bcpMessage.GetParamValue(controllerVersionName) - ); + version: bcpMessage.GetParamValue(versionName), + controllerName: bcpMessage.GetParamValue(controllerNameName), + controllerVersion: bcpMessage.GetParamValue(controllerVersionName)); } } } \ No newline at end of file diff --git a/Runtime/Messages/Monitor/MonitorStartMessage.cs b/Runtime/Messages/Monitor/MonitorStartMessage.cs index 4921e46c..027eb41a 100644 --- a/Runtime/Messages/Monitor/MonitorStartMessage.cs +++ b/Runtime/Messages/Monitor/MonitorStartMessage.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; using UnityEngine; @@ -22,7 +23,7 @@ public BcpMessage ToGenericMessage() Debug.LogError("[MonitorStartMessage] Cannot create proper BCP message because monitoring category has no associated string value"); return new( command: Command, - parameters: new List() { new(categoryName, categoryString) } + parameters: new JObject { [categoryName] = categoryString } ); } } diff --git a/Runtime/Messages/Monitor/MonitorStopMessage.cs b/Runtime/Messages/Monitor/MonitorStopMessage.cs index f60e35d3..f5d3b484 100644 --- a/Runtime/Messages/Monitor/MonitorStopMessage.cs +++ b/Runtime/Messages/Monitor/MonitorStopMessage.cs @@ -1,5 +1,5 @@ -using System; -using System.Collections.Generic; +using Newtonsoft.Json.Linq; +using System; using UnityEngine; namespace FutureBoxSystems.MpfMediaController.Messages.Monitor @@ -22,7 +22,7 @@ public BcpMessage ToGenericMessage() Debug.LogError("[MonitorStopMessage] Cannot create proper BCP message because monitoring category has no associated string value"); return new BcpMessage( command: Command, - parameters: new List() { new(categoryName, categoryString) } + parameters: new JObject { [categoryName] = categoryString } ); } } From 8044c90db04166136d71175ac4c26cb0f0044fb1 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 12:09:49 +0100 Subject: [PATCH 35/98] Fix get param value for jtoken types --- Runtime/Core/BcpMessage.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Runtime/Core/BcpMessage.cs b/Runtime/Core/BcpMessage.cs index ce661120..7d2b9791 100644 --- a/Runtime/Core/BcpMessage.cs +++ b/Runtime/Core/BcpMessage.cs @@ -33,7 +33,10 @@ public T GetParamValue(string name) // If string is requested, but parsed type is different, just return the unparsed JSON string if (typeof(T) == typeof(string) && token.Type != JTokenType.String) return (T)Convert.ChangeType(token.ToString(Formatting.None), typeof(T)); - + + if (typeof(JToken).IsAssignableFrom(typeof(T))) + return (T)(object)parameters[name]; + return (T)Convert.ChangeType(token, typeof(T)); } catch (Exception e) when (e is KeyNotFoundException || e is InvalidCastException) From e01b0d72660fd1498a009ec7128347d195023504 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 12:19:57 +0100 Subject: [PATCH 36/98] Add machine message parsing --- Runtime/BcpInterface.prefab | 16 +++++++++++ Runtime/Messages/MachineVar.meta | 8 ++++++ .../Messages/MachineVar/MachineVarMessage.cs | 28 +++++++++++++++++++ .../MachineVar/MachineVarMessage.cs.meta | 11 ++++++++ .../MachineVar/MachineVarMessageHandler.cs | 8 ++++++ .../MachineVarMessageHandler.cs.meta | 11 ++++++++ 6 files changed, 82 insertions(+) create mode 100644 Runtime/Messages/MachineVar.meta create mode 100644 Runtime/Messages/MachineVar/MachineVarMessage.cs create mode 100644 Runtime/Messages/MachineVar/MachineVarMessage.cs.meta create mode 100644 Runtime/Messages/MachineVar/MachineVarMessageHandler.cs create mode 100644 Runtime/Messages/MachineVar/MachineVarMessageHandler.cs.meta diff --git a/Runtime/BcpInterface.prefab b/Runtime/BcpInterface.prefab index ce3554be..d3a72223 100644 --- a/Runtime/BcpInterface.prefab +++ b/Runtime/BcpInterface.prefab @@ -16,6 +16,7 @@ GameObject: - component: {fileID: 3006042140711521680} - component: {fileID: 4146686170121310886} - component: {fileID: 7019407901035039939} + - component: {fileID: 642617651384461981} m_Layer: 0 m_Name: MessageHandlers m_TagString: Untagged @@ -129,6 +130,19 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &642617651384461981 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: cdf1f7f6d8df17345ba92944c4fd5214, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} --- !u!1 &7214112112941309933 GameObject: m_ObjectHideFlags: 0 @@ -177,6 +191,8 @@ MonoBehaviour: m_EditorClassIdentifier: port: 5050 frameTimeBudgetMs: 3 + logReceivedMessages: 0 + logSentMessages: 0 --- !u!1 &8567879373765849912 GameObject: m_ObjectHideFlags: 0 diff --git a/Runtime/Messages/MachineVar.meta b/Runtime/Messages/MachineVar.meta new file mode 100644 index 00000000..fa599bb1 --- /dev/null +++ b/Runtime/Messages/MachineVar.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7b819b2051f7ee942a73db054e342c85 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/MachineVar/MachineVarMessage.cs b/Runtime/Messages/MachineVar/MachineVarMessage.cs new file mode 100644 index 00000000..5bab6d28 --- /dev/null +++ b/Runtime/Messages/MachineVar/MachineVarMessage.cs @@ -0,0 +1,28 @@ +using Newtonsoft.Json.Linq; +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar +{ + public class MachineVarMessage : EventArgs + { + public const string Command = "machine_variable"; + private const string nameName = "name"; + private const string valueName = "value"; + public readonly string Name; + public readonly JToken Value; + + public MachineVarMessage(string name, JToken value) + { + Name = name; + Value = value; + } + + public static MachineVarMessage FromGenericMessage(BcpMessage bcpMessage) + { + return new MachineVarMessage( + name: bcpMessage.GetParamValue(nameName), + value: bcpMessage.GetParamValue(valueName) + ); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/MachineVarMessage.cs.meta b/Runtime/Messages/MachineVar/MachineVarMessage.cs.meta new file mode 100644 index 00000000..4d9716bc --- /dev/null +++ b/Runtime/Messages/MachineVar/MachineVarMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1b2b0a3f407dbbe4e9c329d2efe3c661 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs new file mode 100644 index 00000000..34885c2c --- /dev/null +++ b/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs @@ -0,0 +1,8 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar +{ + public class MachineVarMessageHandler : BcpMessageHandler + { + public override string Command => MachineVarMessage.Command; + protected override ParseDelegate Parse => MachineVarMessage.FromGenericMessage; + } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs.meta b/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs.meta new file mode 100644 index 00000000..dfb631ae --- /dev/null +++ b/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cdf1f7f6d8df17345ba92944c4fd5214 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From c12c0ee8d216e959721fe929be3f9fe8fe545e8d Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 12:32:44 +0100 Subject: [PATCH 37/98] Rename parameter string conversion methods --- Runtime/Core/BcpMessage.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Runtime/Core/BcpMessage.cs b/Runtime/Core/BcpMessage.cs index 7d2b9791..63837661 100644 --- a/Runtime/Core/BcpMessage.cs +++ b/Runtime/Core/BcpMessage.cs @@ -63,7 +63,7 @@ public string ToString(bool encode) for (int i = 0; i < properties.Count(); i++) { JProperty prop = properties.ElementAt(i); - string propStr = PropertyToString(prop, encode); + string propStr = PropertyToParameterString(prop, encode); sb.Append(propStr); bool isLastParam = i == parameters.Count - 1; if (!isLastParam) @@ -81,7 +81,7 @@ public static BcpMessage FromString(string str) JObject parameters = new(); for (int i = 1; i < parts.Length; i++) { - JProperty property = StringToProperty(parts[i]); + JProperty property = ParameterStringToProperty(parts[i]); if (property.Name == "json" && property.Value is JObject) { containsJson = true; @@ -97,7 +97,7 @@ public static BcpMessage FromString(string str) return new BcpMessage(command, parameters, containsJson); } - private static string PropertyToString(JProperty property, bool encode) + private static string PropertyToParameterString(JProperty property, bool encode) { var name = property.Name; string value; @@ -125,7 +125,7 @@ private static string PropertyToString(JProperty property, bool encode) return $"{name}={typeHint}:{value}"; } - private static JProperty StringToProperty(string str) + private static JProperty ParameterStringToProperty(string str) { string[] parts = str.Split('=', 2); string name = parts[0].Trim().ToLower(); // Not case sensitive @@ -163,7 +163,6 @@ private static JProperty StringToProperty(string str) } } - return new JProperty(name, value); } } From 6ac4127d7b8503365ff2e55f2102cc5128ad1b39 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 17:00:41 +0100 Subject: [PATCH 38/98] Only monitor machine vars when necessary --- Runtime/Core/BcpInterface.cs | 1 - Runtime/Messages/MachineVar/MachineVarMessageHandler.cs | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Runtime/Core/BcpInterface.cs b/Runtime/Core/BcpInterface.cs index db0e633e..ff40c188 100644 --- a/Runtime/Core/BcpInterface.cs +++ b/Runtime/Core/BcpInterface.cs @@ -99,7 +99,6 @@ private void HandleServerStateChanged(object sender, ConnectionStateChangedEvent if (userCount > 0) TrySendMessage(new MonitorStartMessage(category)); } - TrySendMessage(new MonitorStartMessage(MonitoringCategory.MachineVars)); } } diff --git a/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs index 34885c2c..c503f5db 100644 --- a/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs +++ b/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs @@ -1,8 +1,11 @@ +using FutureBoxSystems.MpfMediaController.Messages.Monitor; + namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar { public class MachineVarMessageHandler : BcpMessageHandler { public override string Command => MachineVarMessage.Command; protected override ParseDelegate Parse => MachineVarMessage.FromGenericMessage; + public override MonitoringCategory MonitoringCategory => MonitoringCategory.MachineVars; } } \ No newline at end of file From eb5b3a6b76573fb95499e288cada0e18e48a93c1 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 17:00:54 +0100 Subject: [PATCH 39/98] Add primitive machine var handling --- Runtime/Messages/MachineVar/Primitive.meta | 8 ++++ .../Primitive/BoolMachineVarMessageHandler.cs | 4 ++ .../BoolMachineVarMessageHandler.cs.meta | 11 +++++ .../FloatMachineVarMessageHandler.cs | 4 ++ .../FloatMachineVarMessageHandler.cs.meta | 11 +++++ .../Primitive/IntMachineVarMessageHandler.cs | 4 ++ .../IntMachineVarMessageHandler.cs.meta | 11 +++++ .../PrimitiveMachineVarMessageHandler.cs | 48 +++++++++++++++++++ .../PrimitiveMachineVarMessageHandler.cs.meta | 11 +++++ .../StringMachineVarMessageHandler.cs | 4 ++ .../StringMachineVarMessageHandler.cs.meta | 11 +++++ 11 files changed, 127 insertions(+) create mode 100644 Runtime/Messages/MachineVar/Primitive.meta create mode 100644 Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs create mode 100644 Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs.meta create mode 100644 Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs create mode 100644 Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs.meta create mode 100644 Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs create mode 100644 Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs.meta create mode 100644 Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs create mode 100644 Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs.meta create mode 100644 Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs create mode 100644 Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs.meta diff --git a/Runtime/Messages/MachineVar/Primitive.meta b/Runtime/Messages/MachineVar/Primitive.meta new file mode 100644 index 00000000..628550fc --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6b43748197a0c1749a69c1e3843ed3cc +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs new file mode 100644 index 00000000..51c00b4a --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +{ + public class BoolMachineVarMessageHandler : PrimitiveMachineVarMessageHandler { } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs.meta b/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs.meta new file mode 100644 index 00000000..dcfadd65 --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8b7fb70665036d044bc9bdf74b7abe56 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs new file mode 100644 index 00000000..38056ec2 --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +{ + public class FloatMachineVarMessageHandler : PrimitiveMachineVarMessageHandler { } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs.meta b/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs.meta new file mode 100644 index 00000000..0a314889 --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d0299ae6ed98bea4eaf8916e9bdcd79c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs new file mode 100644 index 00000000..0c57f7d0 --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +{ + public class IntMachineVarMessageHandler : PrimitiveMachineVarMessageHandler { } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs.meta b/Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs.meta new file mode 100644 index 00000000..42cdbd97 --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 32b4cc2b8641d204b816b73d5d5435af +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs new file mode 100644 index 00000000..9ddedf0b --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs @@ -0,0 +1,48 @@ +using System; +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +{ + public abstract class PrimitiveMachineVarMessageHandler : MonoBehaviour + { + [SerializeField] + protected string varName; + [SerializeField] + private MachineVarMessageHandler machineVarMessageHandler; + + public event EventHandler ValueUpdated; + + private void OnEnable() + { + machineVarMessageHandler.Received += MachineVarMessageHandler_Received; + } + + private void OnDisable() + { + machineVarMessageHandler.Received -= MachineVarMessageHandler_Received; + } + + private void MachineVarMessageHandler_Received(object sender, MachineVarMessage msg) + { + if (msg.Name != varName) + return; + + T convertedValue; + + try + { + convertedValue = (T)Convert.ChangeType(msg.Value, typeof(T)); + } + catch (Exception e) when ( + e is InvalidCastException || + e is FormatException || + e is OverflowException || + e is ArgumentNullException) + { + throw new ParameterException(MachineVarMessage.valueName, null, e); + } + + ValueUpdated?.Invoke(this, convertedValue); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs.meta b/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs.meta new file mode 100644 index 00000000..11b208a0 --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 38cc034e9b27735429d483c34e97b4cc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs new file mode 100644 index 00000000..1cfd51f9 --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +{ + public class StringMachineVarMessageHandler : PrimitiveMachineVarMessageHandler { } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs.meta b/Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs.meta new file mode 100644 index 00000000..06f888ee --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6c05012daf548b14dbb42e32a8828569 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From ff212f37063e40f0bd2c2dc39070a34984bf0474 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 17:28:58 +0100 Subject: [PATCH 40/98] Fix compile error --- Runtime/Messages/MachineVar/MachineVarMessage.cs | 8 ++++---- .../Primitive/PrimitiveMachineVarMessageHandler.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Runtime/Messages/MachineVar/MachineVarMessage.cs b/Runtime/Messages/MachineVar/MachineVarMessage.cs index 5bab6d28..117c5247 100644 --- a/Runtime/Messages/MachineVar/MachineVarMessage.cs +++ b/Runtime/Messages/MachineVar/MachineVarMessage.cs @@ -6,8 +6,8 @@ namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar public class MachineVarMessage : EventArgs { public const string Command = "machine_variable"; - private const string nameName = "name"; - private const string valueName = "value"; + public const string NameParamName = "name"; + public const string ValueParamName = "value"; public readonly string Name; public readonly JToken Value; @@ -20,8 +20,8 @@ public MachineVarMessage(string name, JToken value) public static MachineVarMessage FromGenericMessage(BcpMessage bcpMessage) { return new MachineVarMessage( - name: bcpMessage.GetParamValue(nameName), - value: bcpMessage.GetParamValue(valueName) + name: bcpMessage.GetParamValue(NameParamName), + value: bcpMessage.GetParamValue(ValueParamName) ); } } diff --git a/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs index 9ddedf0b..76ecb23a 100644 --- a/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs +++ b/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs @@ -39,7 +39,7 @@ e is FormatException || e is OverflowException || e is ArgumentNullException) { - throw new ParameterException(MachineVarMessage.valueName, null, e); + throw new ParameterException(MachineVarMessage.ValueParamName, null, e); } ValueUpdated?.Invoke(this, convertedValue); From d17de87289e3908baa656822c86ae9140b5a6b72 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 17:31:18 +0100 Subject: [PATCH 41/98] Add rudimentary settings message parser --- Runtime/BcpInterface.prefab | 14 ++++++++++++ Runtime/Messages/Settings.meta | 8 +++++++ Runtime/Messages/Settings/SettingsMessage.cs | 22 +++++++++++++++++++ .../Messages/Settings/SettingsMessage.cs.meta | 11 ++++++++++ .../Settings/SettingsMessageHandler.cs | 8 +++++++ .../Settings/SettingsMessageHandler.cs.meta | 11 ++++++++++ 6 files changed, 74 insertions(+) create mode 100644 Runtime/Messages/Settings.meta create mode 100644 Runtime/Messages/Settings/SettingsMessage.cs create mode 100644 Runtime/Messages/Settings/SettingsMessage.cs.meta create mode 100644 Runtime/Messages/Settings/SettingsMessageHandler.cs create mode 100644 Runtime/Messages/Settings/SettingsMessageHandler.cs.meta diff --git a/Runtime/BcpInterface.prefab b/Runtime/BcpInterface.prefab index d3a72223..d7556456 100644 --- a/Runtime/BcpInterface.prefab +++ b/Runtime/BcpInterface.prefab @@ -17,6 +17,7 @@ GameObject: - component: {fileID: 4146686170121310886} - component: {fileID: 7019407901035039939} - component: {fileID: 642617651384461981} + - component: {fileID: 4203975233253439991} m_Layer: 0 m_Name: MessageHandlers m_TagString: Untagged @@ -143,6 +144,19 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &4203975233253439991 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b65129ea85086ae47af878a4f30e9e69, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} --- !u!1 &7214112112941309933 GameObject: m_ObjectHideFlags: 0 diff --git a/Runtime/Messages/Settings.meta b/Runtime/Messages/Settings.meta new file mode 100644 index 00000000..fe98cf9c --- /dev/null +++ b/Runtime/Messages/Settings.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6a7a5b6317e5e364983ccb22cf0ea2dd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Settings/SettingsMessage.cs b/Runtime/Messages/Settings/SettingsMessage.cs new file mode 100644 index 00000000..d79e4e0c --- /dev/null +++ b/Runtime/Messages/Settings/SettingsMessage.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json.Linq; +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Settings +{ + public class SettingsMessage : EventArgs + { + public const string Command = "settings"; + private const string settingsParamName = "settings"; + public readonly JArray Settings; + + public SettingsMessage(JArray settings) + { + Settings = settings; + } + + public static SettingsMessage FromGenericMessage(BcpMessage bcpMessage) + { + return new SettingsMessage(bcpMessage.GetParamValue(settingsParamName)); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Settings/SettingsMessage.cs.meta b/Runtime/Messages/Settings/SettingsMessage.cs.meta new file mode 100644 index 00000000..fabdc060 --- /dev/null +++ b/Runtime/Messages/Settings/SettingsMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4aadb422d74356140830f1459efd0e84 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Settings/SettingsMessageHandler.cs b/Runtime/Messages/Settings/SettingsMessageHandler.cs new file mode 100644 index 00000000..ce3f1c02 --- /dev/null +++ b/Runtime/Messages/Settings/SettingsMessageHandler.cs @@ -0,0 +1,8 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.Settings +{ + public class SettingsMessageHandler : BcpMessageHandler + { + public override string Command => SettingsMessage.Command; + protected override ParseDelegate Parse => SettingsMessage.FromGenericMessage; + } +} \ No newline at end of file diff --git a/Runtime/Messages/Settings/SettingsMessageHandler.cs.meta b/Runtime/Messages/Settings/SettingsMessageHandler.cs.meta new file mode 100644 index 00000000..c00a6932 --- /dev/null +++ b/Runtime/Messages/Settings/SettingsMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b65129ea85086ae47af878a4f30e9e69 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From ef62a01b8fc467bfe73d209d83712b5251b1703c Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 18:56:15 +0100 Subject: [PATCH 42/98] Save machine vars --- .../Primitive/BoolMachineVarMessageHandler.cs | 4 ---- .../Primitive/BoolMachineVarMonitor.cs | 4 ++++ ...r.cs.meta => BoolMachineVarMonitor.cs.meta} | 0 .../Primitive/FloatMachineVarMessageHandler.cs | 4 ---- .../Primitive/FloatMachineVarMonitor.cs | 4 ++++ ....cs.meta => FloatMachineVarMonitor.cs.meta} | 0 .../Primitive/IntMachineVarMessageHandler.cs | 4 ---- .../Primitive/IntMachineVarMonitor.cs | 4 ++++ ...er.cs.meta => IntMachineVarMonitor.cs.meta} | 0 ...andler.cs => PrimitiveMachineVarMonitor.cs} | 18 ++++++++++++++++-- ...meta => PrimitiveMachineVarMonitor.cs.meta} | 0 .../StringMachineVarMessageHandler.cs | 4 ---- .../Primitive/StringMachineVarMonitor.cs | 4 ++++ ...cs.meta => StringMachineVarMonitor.cs.meta} | 0 14 files changed, 32 insertions(+), 18 deletions(-) delete mode 100644 Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs create mode 100644 Runtime/Messages/MachineVar/Primitive/BoolMachineVarMonitor.cs rename Runtime/Messages/MachineVar/Primitive/{BoolMachineVarMessageHandler.cs.meta => BoolMachineVarMonitor.cs.meta} (100%) delete mode 100644 Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs create mode 100644 Runtime/Messages/MachineVar/Primitive/FloatMachineVarMonitor.cs rename Runtime/Messages/MachineVar/Primitive/{FloatMachineVarMessageHandler.cs.meta => FloatMachineVarMonitor.cs.meta} (100%) delete mode 100644 Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs create mode 100644 Runtime/Messages/MachineVar/Primitive/IntMachineVarMonitor.cs rename Runtime/Messages/MachineVar/Primitive/{IntMachineVarMessageHandler.cs.meta => IntMachineVarMonitor.cs.meta} (100%) rename Runtime/Messages/MachineVar/Primitive/{PrimitiveMachineVarMessageHandler.cs => PrimitiveMachineVarMonitor.cs} (69%) rename Runtime/Messages/MachineVar/Primitive/{PrimitiveMachineVarMessageHandler.cs.meta => PrimitiveMachineVarMonitor.cs.meta} (100%) delete mode 100644 Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs create mode 100644 Runtime/Messages/MachineVar/Primitive/StringMachineVarMonitor.cs rename Runtime/Messages/MachineVar/Primitive/{StringMachineVarMessageHandler.cs.meta => StringMachineVarMonitor.cs.meta} (100%) diff --git a/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs deleted file mode 100644 index 51c00b4a..00000000 --- a/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive -{ - public class BoolMachineVarMessageHandler : PrimitiveMachineVarMessageHandler { } -} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMonitor.cs b/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMonitor.cs new file mode 100644 index 00000000..67d2c558 --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMonitor.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +{ + public class BoolMachineVarMonitor : PrimitiveMachineVarMonitor { } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs.meta b/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMonitor.cs.meta similarity index 100% rename from Runtime/Messages/MachineVar/Primitive/BoolMachineVarMessageHandler.cs.meta rename to Runtime/Messages/MachineVar/Primitive/BoolMachineVarMonitor.cs.meta diff --git a/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs deleted file mode 100644 index 38056ec2..00000000 --- a/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive -{ - public class FloatMachineVarMessageHandler : PrimitiveMachineVarMessageHandler { } -} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMonitor.cs b/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMonitor.cs new file mode 100644 index 00000000..c8b02760 --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMonitor.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +{ + public class FloatMachineVarMonitor : PrimitiveMachineVarMonitor { } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs.meta b/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMonitor.cs.meta similarity index 100% rename from Runtime/Messages/MachineVar/Primitive/FloatMachineVarMessageHandler.cs.meta rename to Runtime/Messages/MachineVar/Primitive/FloatMachineVarMonitor.cs.meta diff --git a/Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs deleted file mode 100644 index 0c57f7d0..00000000 --- a/Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive -{ - public class IntMachineVarMessageHandler : PrimitiveMachineVarMessageHandler { } -} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/IntMachineVarMonitor.cs b/Runtime/Messages/MachineVar/Primitive/IntMachineVarMonitor.cs new file mode 100644 index 00000000..a8b148d3 --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/IntMachineVarMonitor.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +{ + public class IntMachineVarMonitor : PrimitiveMachineVarMonitor { } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs.meta b/Runtime/Messages/MachineVar/Primitive/IntMachineVarMonitor.cs.meta similarity index 100% rename from Runtime/Messages/MachineVar/Primitive/IntMachineVarMessageHandler.cs.meta rename to Runtime/Messages/MachineVar/Primitive/IntMachineVarMonitor.cs.meta diff --git a/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs similarity index 69% rename from Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs rename to Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs index 76ecb23a..1a89526b 100644 --- a/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs +++ b/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs @@ -3,7 +3,7 @@ namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive { - public abstract class PrimitiveMachineVarMessageHandler : MonoBehaviour + public abstract class PrimitiveMachineVarMonitor : MonoBehaviour where T : IEquatable { [SerializeField] protected string varName; @@ -11,6 +11,19 @@ public abstract class PrimitiveMachineVarMessageHandler : MonoBehaviour private MachineVarMessageHandler machineVarMessageHandler; public event EventHandler ValueUpdated; + private T varValue = default; + public T VarValue + { + get => varValue; + set + { + if (value.Equals(varValue)) + return; + varValue = value; + ValueUpdated?.Invoke(this, varValue); + } + } + public bool WasEverUpdated { get; private set; } = false; private void OnEnable() { @@ -42,7 +55,8 @@ e is OverflowException || throw new ParameterException(MachineVarMessage.ValueParamName, null, e); } - ValueUpdated?.Invoke(this, convertedValue); + WasEverUpdated = true; + VarValue = convertedValue; } } } \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs.meta b/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs.meta similarity index 100% rename from Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMessageHandler.cs.meta rename to Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs.meta diff --git a/Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs deleted file mode 100644 index 1cfd51f9..00000000 --- a/Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive -{ - public class StringMachineVarMessageHandler : PrimitiveMachineVarMessageHandler { } -} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/StringMachineVarMonitor.cs b/Runtime/Messages/MachineVar/Primitive/StringMachineVarMonitor.cs new file mode 100644 index 00000000..57cef1e3 --- /dev/null +++ b/Runtime/Messages/MachineVar/Primitive/StringMachineVarMonitor.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +{ + public class StringMachineVarMonitor : PrimitiveMachineVarMonitor { } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs.meta b/Runtime/Messages/MachineVar/Primitive/StringMachineVarMonitor.cs.meta similarity index 100% rename from Runtime/Messages/MachineVar/Primitive/StringMachineVarMessageHandler.cs.meta rename to Runtime/Messages/MachineVar/Primitive/StringMachineVarMonitor.cs.meta From 92e1c80be0c0a0a024f0652aa363cf2af01d03df Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 19:27:10 +0100 Subject: [PATCH 43/98] Add mode handling --- Runtime/BcpInterface.prefab | 42 +++++++++++++ Runtime/Messages/Mode.meta | 8 +++ Runtime/Messages/Mode/Mode.cs | 14 +++++ Runtime/Messages/Mode/Mode.cs.meta | 11 ++++ Runtime/Messages/Mode/ModeListMessage.cs | 43 +++++++++++++ Runtime/Messages/Mode/ModeListMessage.cs.meta | 11 ++++ .../Messages/Mode/ModeListMessageHandler.cs | 11 ++++ .../Mode/ModeListMessageHandler.cs.meta | 11 ++++ Runtime/Messages/Mode/ModeMonitor.cs | 60 +++++++++++++++++++ Runtime/Messages/Mode/ModeMonitor.cs.meta | 11 ++++ Runtime/Messages/Mode/ModeStartMessage.cs | 27 +++++++++ .../Messages/Mode/ModeStartMessage.cs.meta | 11 ++++ .../Messages/Mode/ModeStartMessageHandler.cs | 11 ++++ .../Mode/ModeStartMessageHandler.cs.meta | 11 ++++ Runtime/Messages/Mode/ModeStopMessage.cs | 22 +++++++ Runtime/Messages/Mode/ModeStopMessage.cs.meta | 11 ++++ .../Messages/Mode/ModeStopMessageHandler.cs | 11 ++++ .../Mode/ModeStopMessageHandler.cs.meta | 11 ++++ 18 files changed, 337 insertions(+) create mode 100644 Runtime/Messages/Mode.meta create mode 100644 Runtime/Messages/Mode/Mode.cs create mode 100644 Runtime/Messages/Mode/Mode.cs.meta create mode 100644 Runtime/Messages/Mode/ModeListMessage.cs create mode 100644 Runtime/Messages/Mode/ModeListMessage.cs.meta create mode 100644 Runtime/Messages/Mode/ModeListMessageHandler.cs create mode 100644 Runtime/Messages/Mode/ModeListMessageHandler.cs.meta create mode 100644 Runtime/Messages/Mode/ModeMonitor.cs create mode 100644 Runtime/Messages/Mode/ModeMonitor.cs.meta create mode 100644 Runtime/Messages/Mode/ModeStartMessage.cs create mode 100644 Runtime/Messages/Mode/ModeStartMessage.cs.meta create mode 100644 Runtime/Messages/Mode/ModeStartMessageHandler.cs create mode 100644 Runtime/Messages/Mode/ModeStartMessageHandler.cs.meta create mode 100644 Runtime/Messages/Mode/ModeStopMessage.cs create mode 100644 Runtime/Messages/Mode/ModeStopMessage.cs.meta create mode 100644 Runtime/Messages/Mode/ModeStopMessageHandler.cs create mode 100644 Runtime/Messages/Mode/ModeStopMessageHandler.cs.meta diff --git a/Runtime/BcpInterface.prefab b/Runtime/BcpInterface.prefab index d7556456..fe458fa8 100644 --- a/Runtime/BcpInterface.prefab +++ b/Runtime/BcpInterface.prefab @@ -18,6 +18,9 @@ GameObject: - component: {fileID: 7019407901035039939} - component: {fileID: 642617651384461981} - component: {fileID: 4203975233253439991} + - component: {fileID: 3090677156515762911} + - component: {fileID: 7662757724108484360} + - component: {fileID: 7963542148954742278} m_Layer: 0 m_Name: MessageHandlers m_TagString: Untagged @@ -157,6 +160,45 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &3090677156515762911 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 11f6680fde0db0b47a34525af2715218, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &7662757724108484360 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2f12a6315c31b7e4a89904664714c88d, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &7963542148954742278 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 35edded1d3e1dbf43abd87fd5af57e9c, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} --- !u!1 &7214112112941309933 GameObject: m_ObjectHideFlags: 0 diff --git a/Runtime/Messages/Mode.meta b/Runtime/Messages/Mode.meta new file mode 100644 index 00000000..2380db74 --- /dev/null +++ b/Runtime/Messages/Mode.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 179d887059b703c49923494791130528 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Mode/Mode.cs b/Runtime/Messages/Mode/Mode.cs new file mode 100644 index 00000000..26ad64ff --- /dev/null +++ b/Runtime/Messages/Mode/Mode.cs @@ -0,0 +1,14 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.Mode +{ + public readonly struct Mode + { + public readonly string Name; + public readonly int Priority; + + public Mode(string name, int priority) + { + Name = name; + Priority = priority; + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Mode/Mode.cs.meta b/Runtime/Messages/Mode/Mode.cs.meta new file mode 100644 index 00000000..f64dfd44 --- /dev/null +++ b/Runtime/Messages/Mode/Mode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1208ed40b647ce941b864994d1a73fd4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Mode/ModeListMessage.cs b/Runtime/Messages/Mode/ModeListMessage.cs new file mode 100644 index 00000000..e7f9543a --- /dev/null +++ b/Runtime/Messages/Mode/ModeListMessage.cs @@ -0,0 +1,43 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.ObjectModel; + +namespace FutureBoxSystems.MpfMediaController.Messages.Mode +{ + public class ModeListMessage : EventArgs + { + public const string Command = "mode_list"; + public const string RunningModesParamName = "running_modes"; + public ReadOnlyCollection RunningModes => Array.AsReadOnly(runningModes); + private readonly Mode[] runningModes; + + public ModeListMessage(Mode[] runningModes) + { + this.runningModes = runningModes; + } + + public static ModeListMessage FromGenericMessage(BcpMessage bcpMessage) + { + try + { + var jArr = bcpMessage.GetParamValue(RunningModesParamName); + Mode[] runningModes = new Mode[jArr.Count]; + + for (int i = 0; i < jArr.Count; i++) + { + var modeJArr = (JArray)jArr[i]; + var modeName = (string)modeJArr[0]; + var modePrio = (int)modeJArr[1]; + runningModes[i] = new Mode(modeName, modePrio); + } + + return new ModeListMessage(runningModes); + } + catch (Exception e) when (e is JsonException || e is InvalidCastException || e is IndexOutOfRangeException) + { + throw new ParameterException(RunningModesParamName, null, e); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Mode/ModeListMessage.cs.meta b/Runtime/Messages/Mode/ModeListMessage.cs.meta new file mode 100644 index 00000000..f946f03d --- /dev/null +++ b/Runtime/Messages/Mode/ModeListMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b2cab57bc80e5b84ba5a702b6e457edb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Mode/ModeListMessageHandler.cs b/Runtime/Messages/Mode/ModeListMessageHandler.cs new file mode 100644 index 00000000..e1877672 --- /dev/null +++ b/Runtime/Messages/Mode/ModeListMessageHandler.cs @@ -0,0 +1,11 @@ +using FutureBoxSystems.MpfMediaController.Messages.Monitor; + +namespace FutureBoxSystems.MpfMediaController.Messages.Mode +{ + public class ModeListMessageHandler : BcpMessageHandler + { + public override string Command => ModeListMessage.Command; + protected override ParseDelegate Parse => ModeListMessage.FromGenericMessage; + public override MonitoringCategory MonitoringCategory => MonitoringCategory.Modes; + } +} \ No newline at end of file diff --git a/Runtime/Messages/Mode/ModeListMessageHandler.cs.meta b/Runtime/Messages/Mode/ModeListMessageHandler.cs.meta new file mode 100644 index 00000000..2eab10aa --- /dev/null +++ b/Runtime/Messages/Mode/ModeListMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 35edded1d3e1dbf43abd87fd5af57e9c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Mode/ModeMonitor.cs b/Runtime/Messages/Mode/ModeMonitor.cs new file mode 100644 index 00000000..83bff18f --- /dev/null +++ b/Runtime/Messages/Mode/ModeMonitor.cs @@ -0,0 +1,60 @@ +using System; +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController.Messages.Mode +{ + public class ModeMonitor : MonoBehaviour + { + [SerializeField] + private string modeName; + + [SerializeField] + private ModeStartMessageHandler modeStartMessageHandler; + [SerializeField] + private ModeStopMessageHandler modeStopMessageHandler; + + private bool isModeActive = false; + public bool IsModeActive + { + get => isModeActive; + set + { + if (value == isModeActive) + return; + + isModeActive = value; + IsModeActiveChanged?.Invoke(this, isModeActive); + } + } + + public event EventHandler IsModeActiveChanged; + + private void OnEnable() + { + modeStartMessageHandler.Received += OnModeStarted; + modeStopMessageHandler.Received += OnModeStopped; + } + + private void OnDisable() + { + modeStartMessageHandler.Received -= OnModeStarted; + modeStopMessageHandler.Received -= OnModeStopped; + } + + private void OnModeStarted(object sender, ModeStartMessage msg) + { + if (msg.Name != modeName) + return; + + IsModeActive = true; + } + + private void OnModeStopped(object sender, ModeStopMessage msg) + { + if (msg.Name != modeName) + return; + + IsModeActive = false; + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Mode/ModeMonitor.cs.meta b/Runtime/Messages/Mode/ModeMonitor.cs.meta new file mode 100644 index 00000000..9932241b --- /dev/null +++ b/Runtime/Messages/Mode/ModeMonitor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7e3297e4511b9e14d88a9fe881934ca6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Mode/ModeStartMessage.cs b/Runtime/Messages/Mode/ModeStartMessage.cs new file mode 100644 index 00000000..5d6acc67 --- /dev/null +++ b/Runtime/Messages/Mode/ModeStartMessage.cs @@ -0,0 +1,27 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Mode +{ + public class ModeStartMessage : EventArgs + { + public const string Command = "mode_start"; + public const string NameParamName = "name"; + public const string PriorityParamName = "priority"; + + public readonly string Name; + public readonly int Priority; + + public ModeStartMessage(string name, int priority) + { + Name = name; + Priority = priority; + } + + public static ModeStartMessage FromGenericMessage(BcpMessage bcpMessage) + { + return new ModeStartMessage( + name: bcpMessage.GetParamValue(NameParamName), + priority: bcpMessage.GetParamValue(PriorityParamName)); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Mode/ModeStartMessage.cs.meta b/Runtime/Messages/Mode/ModeStartMessage.cs.meta new file mode 100644 index 00000000..696c7a5c --- /dev/null +++ b/Runtime/Messages/Mode/ModeStartMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 72d8c859b0e9220498de9d7a5ed23c3d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Mode/ModeStartMessageHandler.cs b/Runtime/Messages/Mode/ModeStartMessageHandler.cs new file mode 100644 index 00000000..9a826eae --- /dev/null +++ b/Runtime/Messages/Mode/ModeStartMessageHandler.cs @@ -0,0 +1,11 @@ +using FutureBoxSystems.MpfMediaController.Messages.Monitor; + +namespace FutureBoxSystems.MpfMediaController.Messages.Mode +{ + public class ModeStartMessageHandler : BcpMessageHandler + { + public override string Command => ModeStartMessage.Command; + protected override ParseDelegate Parse => ModeStartMessage.FromGenericMessage; + public override MonitoringCategory MonitoringCategory => MonitoringCategory.Modes; + } +} \ No newline at end of file diff --git a/Runtime/Messages/Mode/ModeStartMessageHandler.cs.meta b/Runtime/Messages/Mode/ModeStartMessageHandler.cs.meta new file mode 100644 index 00000000..e74c76ea --- /dev/null +++ b/Runtime/Messages/Mode/ModeStartMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 11f6680fde0db0b47a34525af2715218 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Mode/ModeStopMessage.cs b/Runtime/Messages/Mode/ModeStopMessage.cs new file mode 100644 index 00000000..6647428a --- /dev/null +++ b/Runtime/Messages/Mode/ModeStopMessage.cs @@ -0,0 +1,22 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Mode +{ + public class ModeStopMessage : EventArgs + { + public const string Command = "mode_stop"; + public const string NameParamName = "name"; + + public readonly string Name; + + public ModeStopMessage(string name) + { + Name = name; + } + + public static ModeStopMessage FromGenericMessage(BcpMessage bcpMessage) + { + return new ModeStopMessage(name: bcpMessage.GetParamValue(NameParamName)); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Mode/ModeStopMessage.cs.meta b/Runtime/Messages/Mode/ModeStopMessage.cs.meta new file mode 100644 index 00000000..c24a609b --- /dev/null +++ b/Runtime/Messages/Mode/ModeStopMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5195aea21f535ac4890c7d958d33f1bc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Mode/ModeStopMessageHandler.cs b/Runtime/Messages/Mode/ModeStopMessageHandler.cs new file mode 100644 index 00000000..f8c762df --- /dev/null +++ b/Runtime/Messages/Mode/ModeStopMessageHandler.cs @@ -0,0 +1,11 @@ +using FutureBoxSystems.MpfMediaController.Messages.Monitor; + +namespace FutureBoxSystems.MpfMediaController.Messages.Mode +{ + public class ModeStopMessageHandler : BcpMessageHandler + { + public override string Command => ModeStopMessage.Command; + protected override ParseDelegate Parse => ModeStopMessage.FromGenericMessage; + public override MonitoringCategory MonitoringCategory => MonitoringCategory.Modes; + } +} \ No newline at end of file diff --git a/Runtime/Messages/Mode/ModeStopMessageHandler.cs.meta b/Runtime/Messages/Mode/ModeStopMessageHandler.cs.meta new file mode 100644 index 00000000..4bc536f5 --- /dev/null +++ b/Runtime/Messages/Mode/ModeStopMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2f12a6315c31b7e4a89904664714c88d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 601e1f82bf263620869a16da1954fd527b5807e3 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 20:13:30 +0100 Subject: [PATCH 44/98] Add monitoring category to settings message handler --- Runtime/Messages/Settings/SettingsMessageHandler.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Runtime/Messages/Settings/SettingsMessageHandler.cs b/Runtime/Messages/Settings/SettingsMessageHandler.cs index ce3f1c02..de3ee23f 100644 --- a/Runtime/Messages/Settings/SettingsMessageHandler.cs +++ b/Runtime/Messages/Settings/SettingsMessageHandler.cs @@ -1,8 +1,11 @@ +using FutureBoxSystems.MpfMediaController.Messages.Monitor; + namespace FutureBoxSystems.MpfMediaController.Messages.Settings { public class SettingsMessageHandler : BcpMessageHandler { public override string Command => SettingsMessage.Command; protected override ParseDelegate Parse => SettingsMessage.FromGenericMessage; + public override MonitoringCategory MonitoringCategory => MonitoringCategory.MachineVars; } } \ No newline at end of file From d28379e69ddbd7df09ca309bece9e5f7c891330a Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 20:43:48 +0100 Subject: [PATCH 45/98] Add null check in PrimitiveMachineVarMonitor --- .../MachineVar/Primitive/PrimitiveMachineVarMonitor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs b/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs index 1a89526b..2e02e410 100644 --- a/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs +++ b/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs @@ -32,7 +32,8 @@ private void OnEnable() private void OnDisable() { - machineVarMessageHandler.Received -= MachineVarMessageHandler_Received; + if (machineVarMessageHandler) + machineVarMessageHandler.Received -= MachineVarMessageHandler_Received; } private void MachineVarMessageHandler_Received(object sender, MachineVarMessage msg) From 2d9974574a94f39fc6b81fdc461681308e16c2ae Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 20:44:10 +0100 Subject: [PATCH 46/98] Add player added message handling --- Runtime/BcpInterface.prefab | 14 ++++++++++++ Runtime/Messages/PlayerAdded.meta | 8 +++++++ .../PlayerAdded/PlayerAddedMessage.cs | 22 +++++++++++++++++++ .../PlayerAdded/PlayerAddedMessage.cs.meta | 11 ++++++++++ .../PlayerAdded/PlayerAddedMessageHandler.cs | 11 ++++++++++ .../PlayerAddedMessageHandler.cs.meta | 11 ++++++++++ 6 files changed, 77 insertions(+) create mode 100644 Runtime/Messages/PlayerAdded.meta create mode 100644 Runtime/Messages/PlayerAdded/PlayerAddedMessage.cs create mode 100644 Runtime/Messages/PlayerAdded/PlayerAddedMessage.cs.meta create mode 100644 Runtime/Messages/PlayerAdded/PlayerAddedMessageHandler.cs create mode 100644 Runtime/Messages/PlayerAdded/PlayerAddedMessageHandler.cs.meta diff --git a/Runtime/BcpInterface.prefab b/Runtime/BcpInterface.prefab index fe458fa8..9102c155 100644 --- a/Runtime/BcpInterface.prefab +++ b/Runtime/BcpInterface.prefab @@ -21,6 +21,7 @@ GameObject: - component: {fileID: 3090677156515762911} - component: {fileID: 7662757724108484360} - component: {fileID: 7963542148954742278} + - component: {fileID: 491971619498350422} m_Layer: 0 m_Name: MessageHandlers m_TagString: Untagged @@ -199,6 +200,19 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &491971619498350422 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: dab47b28efdc1874687cf7a107bab2c5, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} --- !u!1 &7214112112941309933 GameObject: m_ObjectHideFlags: 0 diff --git a/Runtime/Messages/PlayerAdded.meta b/Runtime/Messages/PlayerAdded.meta new file mode 100644 index 00000000..5e1dfd79 --- /dev/null +++ b/Runtime/Messages/PlayerAdded.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6ad87fcd85ad2724ea025be623aa5357 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/PlayerAdded/PlayerAddedMessage.cs b/Runtime/Messages/PlayerAdded/PlayerAddedMessage.cs new file mode 100644 index 00000000..071fca59 --- /dev/null +++ b/Runtime/Messages/PlayerAdded/PlayerAddedMessage.cs @@ -0,0 +1,22 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.PlayerAdded +{ + public class PlayerAddedMessage : EventArgs + { + public const string Command = "player_added"; + public const string PlayerNumParamName = "player_num"; + + public readonly int PlayerNum; + + public PlayerAddedMessage(int playerNum) + { + PlayerNum = playerNum; + } + + public static PlayerAddedMessage FromGenericMessage(BcpMessage bcpMessage) + { + return new PlayerAddedMessage(bcpMessage.GetParamValue(PlayerNumParamName)); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/PlayerAdded/PlayerAddedMessage.cs.meta b/Runtime/Messages/PlayerAdded/PlayerAddedMessage.cs.meta new file mode 100644 index 00000000..1d2a7169 --- /dev/null +++ b/Runtime/Messages/PlayerAdded/PlayerAddedMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: aceb42fcfe4d1844d96074d0d69dd65b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/PlayerAdded/PlayerAddedMessageHandler.cs b/Runtime/Messages/PlayerAdded/PlayerAddedMessageHandler.cs new file mode 100644 index 00000000..ac892508 --- /dev/null +++ b/Runtime/Messages/PlayerAdded/PlayerAddedMessageHandler.cs @@ -0,0 +1,11 @@ +using FutureBoxSystems.MpfMediaController.Messages.Monitor; + +namespace FutureBoxSystems.MpfMediaController.Messages.PlayerAdded +{ + public class PlayerAddedMessageHandler : BcpMessageHandler + { + public override string Command => PlayerAddedMessage.Command; + protected override ParseDelegate Parse => PlayerAddedMessage.FromGenericMessage; + public override MonitoringCategory MonitoringCategory => MonitoringCategory.CoreEvents; + } +} \ No newline at end of file diff --git a/Runtime/Messages/PlayerAdded/PlayerAddedMessageHandler.cs.meta b/Runtime/Messages/PlayerAdded/PlayerAddedMessageHandler.cs.meta new file mode 100644 index 00000000..d1fadc58 --- /dev/null +++ b/Runtime/Messages/PlayerAdded/PlayerAddedMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dab47b28efdc1874687cf7a107bab2c5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From fd32bf39fea718c6315a61e138fc8be6a797e4cc Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 20:50:24 +0100 Subject: [PATCH 47/98] Add player turn start message handling --- Runtime/BcpInterface.prefab | 14 ++++++++++++ Runtime/Messages/PlayerTurnStart.meta | 8 +++++++ .../PlayerTurnStart/PlayerTurnStartMessage.cs | 22 +++++++++++++++++++ .../PlayerTurnStartMessage.cs.meta | 11 ++++++++++ .../PlayerTurnStartMessageHandler.cs | 11 ++++++++++ .../PlayerTurnStartMessageHandler.cs.meta | 11 ++++++++++ 6 files changed, 77 insertions(+) create mode 100644 Runtime/Messages/PlayerTurnStart.meta create mode 100644 Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs create mode 100644 Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs.meta create mode 100644 Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs create mode 100644 Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs.meta diff --git a/Runtime/BcpInterface.prefab b/Runtime/BcpInterface.prefab index 9102c155..eca42ce4 100644 --- a/Runtime/BcpInterface.prefab +++ b/Runtime/BcpInterface.prefab @@ -22,6 +22,7 @@ GameObject: - component: {fileID: 7662757724108484360} - component: {fileID: 7963542148954742278} - component: {fileID: 491971619498350422} + - component: {fileID: 3968882011461727216} m_Layer: 0 m_Name: MessageHandlers m_TagString: Untagged @@ -213,6 +214,19 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &3968882011461727216 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ed407e67f76aac446b42c742d66192d9, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} --- !u!1 &7214112112941309933 GameObject: m_ObjectHideFlags: 0 diff --git a/Runtime/Messages/PlayerTurnStart.meta b/Runtime/Messages/PlayerTurnStart.meta new file mode 100644 index 00000000..78832053 --- /dev/null +++ b/Runtime/Messages/PlayerTurnStart.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bcda5c224c41fc8499013a92e72d6984 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs b/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs new file mode 100644 index 00000000..4a455e40 --- /dev/null +++ b/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs @@ -0,0 +1,22 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.PlayerTurnStart +{ + public class PlayerTurnStartMessage : EventArgs + { + public const string Command = "player_turn_start"; + public const string PlayerNumParamName = "player_num"; + + public readonly int PlayerNum; + + public PlayerTurnStartMessage(int playerNum) + { + PlayerNum = playerNum; + } + + public static PlayerTurnStartMessage FromGenericMessage(BcpMessage bcpMessage) + { + return new PlayerTurnStartMessage(bcpMessage.GetParamValue(PlayerNumParamName)); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs.meta b/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs.meta new file mode 100644 index 00000000..8eace71f --- /dev/null +++ b/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a210e64019e0cd54e94efe94f4884b93 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs b/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs new file mode 100644 index 00000000..8fe081f6 --- /dev/null +++ b/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs @@ -0,0 +1,11 @@ +using FutureBoxSystems.MpfMediaController.Messages.Monitor; + +namespace FutureBoxSystems.MpfMediaController.Messages.PlayerTurnStart +{ + public class PlayerTurnStartMessageHandler : BcpMessageHandler + { + public override string Command => PlayerTurnStartMessage.Command; + protected override ParseDelegate Parse => PlayerTurnStartMessage.FromGenericMessage; + public override MonitoringCategory MonitoringCategory => MonitoringCategory.CoreEvents; + } +} \ No newline at end of file diff --git a/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs.meta b/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs.meta new file mode 100644 index 00000000..4af9477b --- /dev/null +++ b/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ed407e67f76aac446b42c742d66192d9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 74f03e910cd90be8296a2f8ffd4fbae31dafcf49 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 27 Oct 2024 23:57:20 +0100 Subject: [PATCH 48/98] Add player variable message handling --- Runtime/BcpInterface.prefab | 14 +++++ .../Messages/MachineVar/MachineVarMessage.cs | 28 --------- .../MachineVar/MachineVarMessageHandler.cs | 11 ---- .../Primitive/BoolMachineVarMonitor.cs | 4 -- .../Primitive/FloatMachineVarMonitor.cs | 4 -- .../Primitive/IntMachineVarMonitor.cs | 4 -- .../Primitive/PrimitiveMachineVarMonitor.cs | 63 ------------------- .../Primitive/StringMachineVarMonitor.cs | 4 -- .../{MachineVar.meta => MachineVariable.meta} | 0 .../MachineVariable/MachineVariableMessage.cs | 21 +++++++ .../MachineVariableMessage.cs.meta | 11 ++++ .../MachineVariableMessageHandler.cs | 11 ++++ .../MachineVariableMessageHandler.cs.meta} | 0 .../Monitor.meta} | 0 .../Monitor/BoolMachineVariableMonitor.cs | 4 ++ .../BoolMachineVariableMonitor.cs.meta} | 0 .../Monitor/FloatMachineVarableMonitor.cs | 4 ++ .../FloatMachineVarableMonitor.cs.meta} | 0 .../Monitor/IntMachineVariableMonitor.cs | 4 ++ .../IntMachineVariableMonitor.cs.meta} | 0 .../Monitor/StringMachineVariableMonitor.cs | 4 ++ .../StringMachineVariableMonitor.cs.meta} | 0 .../PrimitiveMachineVariableBase.cs | 9 +++ .../PrimitiveMachineVariableBase.cs.meta} | 0 Runtime/Messages/MonitorBase.cs | 50 +++++++++++++++ Runtime/Messages/MonitorBase.cs.meta | 11 ++++ Runtime/Messages/MpfVariableMessageBase.cs | 19 ++++++ ...cs.meta => MpfVariableMessageBase.cs.meta} | 0 Runtime/Messages/MpfVariableMonitorBase.cs | 32 ++++++++++ .../Messages/MpfVariableMonitorBase.cs.meta | 11 ++++ .../PlayerTurnStart/CurrentPlayerMonitor.cs | 7 +++ .../CurrentPlayerMonitor.cs.meta | 11 ++++ Runtime/Messages/PlayerVariable.meta | 8 +++ Runtime/Messages/PlayerVariable/Monitor.meta | 8 +++ .../Monitor/BoolPlayerVariableMonitor.cs | 4 ++ .../Monitor/FloatPlayerVariableMonitor.cs | 4 ++ .../Monitor/IntPlayerVariableMonitor.cs | 4 ++ .../Monitor/IntPlayerVariableMonitor.cs.meta | 11 ++++ .../Monitor/StringPlayerVariableMonitor.cs | 4 ++ .../PlayerVariable/PlayerVariableMessage.cs | 26 ++++++++ .../PlayerVariableMessage.cs.meta | 11 ++++ .../PlayerVariableMessageHandler.cs | 11 ++++ .../PlayerVariableMessageHandler.cs.meta | 11 ++++ .../PlayerVariableMonitorBase.cs | 49 +++++++++++++++ .../PlayerVariableMonitorBase.cs.meta | 11 ++++ 45 files changed, 385 insertions(+), 118 deletions(-) delete mode 100644 Runtime/Messages/MachineVar/MachineVarMessage.cs delete mode 100644 Runtime/Messages/MachineVar/MachineVarMessageHandler.cs delete mode 100644 Runtime/Messages/MachineVar/Primitive/BoolMachineVarMonitor.cs delete mode 100644 Runtime/Messages/MachineVar/Primitive/FloatMachineVarMonitor.cs delete mode 100644 Runtime/Messages/MachineVar/Primitive/IntMachineVarMonitor.cs delete mode 100644 Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs delete mode 100644 Runtime/Messages/MachineVar/Primitive/StringMachineVarMonitor.cs rename Runtime/Messages/{MachineVar.meta => MachineVariable.meta} (100%) create mode 100644 Runtime/Messages/MachineVariable/MachineVariableMessage.cs create mode 100644 Runtime/Messages/MachineVariable/MachineVariableMessage.cs.meta create mode 100644 Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs rename Runtime/Messages/{MachineVar/MachineVarMessageHandler.cs.meta => MachineVariable/MachineVariableMessageHandler.cs.meta} (100%) rename Runtime/Messages/{MachineVar/Primitive.meta => MachineVariable/Monitor.meta} (100%) create mode 100644 Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs rename Runtime/Messages/{MachineVar/Primitive/BoolMachineVarMonitor.cs.meta => MachineVariable/Monitor/BoolMachineVariableMonitor.cs.meta} (100%) create mode 100644 Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs rename Runtime/Messages/{MachineVar/Primitive/FloatMachineVarMonitor.cs.meta => MachineVariable/Monitor/FloatMachineVarableMonitor.cs.meta} (100%) create mode 100644 Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs rename Runtime/Messages/{MachineVar/Primitive/IntMachineVarMonitor.cs.meta => MachineVariable/Monitor/IntMachineVariableMonitor.cs.meta} (100%) create mode 100644 Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs rename Runtime/Messages/{MachineVar/Primitive/StringMachineVarMonitor.cs.meta => MachineVariable/Monitor/StringMachineVariableMonitor.cs.meta} (100%) create mode 100644 Runtime/Messages/MachineVariable/PrimitiveMachineVariableBase.cs rename Runtime/Messages/{MachineVar/Primitive/PrimitiveMachineVarMonitor.cs.meta => MachineVariable/PrimitiveMachineVariableBase.cs.meta} (100%) create mode 100644 Runtime/Messages/MonitorBase.cs create mode 100644 Runtime/Messages/MonitorBase.cs.meta create mode 100644 Runtime/Messages/MpfVariableMessageBase.cs rename Runtime/Messages/{MachineVar/MachineVarMessage.cs.meta => MpfVariableMessageBase.cs.meta} (100%) create mode 100644 Runtime/Messages/MpfVariableMonitorBase.cs create mode 100644 Runtime/Messages/MpfVariableMonitorBase.cs.meta create mode 100644 Runtime/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs create mode 100644 Runtime/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs.meta create mode 100644 Runtime/Messages/PlayerVariable.meta create mode 100644 Runtime/Messages/PlayerVariable/Monitor.meta create mode 100644 Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs create mode 100644 Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs create mode 100644 Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs create mode 100644 Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs.meta create mode 100644 Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs create mode 100644 Runtime/Messages/PlayerVariable/PlayerVariableMessage.cs create mode 100644 Runtime/Messages/PlayerVariable/PlayerVariableMessage.cs.meta create mode 100644 Runtime/Messages/PlayerVariable/PlayerVariableMessageHandler.cs create mode 100644 Runtime/Messages/PlayerVariable/PlayerVariableMessageHandler.cs.meta create mode 100644 Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs create mode 100644 Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs.meta diff --git a/Runtime/BcpInterface.prefab b/Runtime/BcpInterface.prefab index eca42ce4..7dc48696 100644 --- a/Runtime/BcpInterface.prefab +++ b/Runtime/BcpInterface.prefab @@ -23,6 +23,7 @@ GameObject: - component: {fileID: 7963542148954742278} - component: {fileID: 491971619498350422} - component: {fileID: 3968882011461727216} + - component: {fileID: 2727910698276087158} m_Layer: 0 m_Name: MessageHandlers m_TagString: Untagged @@ -227,6 +228,19 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &2727910698276087158 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5e17d18c78dff5746ae1c03a10b14cb9, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} --- !u!1 &7214112112941309933 GameObject: m_ObjectHideFlags: 0 diff --git a/Runtime/Messages/MachineVar/MachineVarMessage.cs b/Runtime/Messages/MachineVar/MachineVarMessage.cs deleted file mode 100644 index 117c5247..00000000 --- a/Runtime/Messages/MachineVar/MachineVarMessage.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Newtonsoft.Json.Linq; -using System; - -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar -{ - public class MachineVarMessage : EventArgs - { - public const string Command = "machine_variable"; - public const string NameParamName = "name"; - public const string ValueParamName = "value"; - public readonly string Name; - public readonly JToken Value; - - public MachineVarMessage(string name, JToken value) - { - Name = name; - Value = value; - } - - public static MachineVarMessage FromGenericMessage(BcpMessage bcpMessage) - { - return new MachineVarMessage( - name: bcpMessage.GetParamValue(NameParamName), - value: bcpMessage.GetParamValue(ValueParamName) - ); - } - } -} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs b/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs deleted file mode 100644 index c503f5db..00000000 --- a/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs +++ /dev/null @@ -1,11 +0,0 @@ -using FutureBoxSystems.MpfMediaController.Messages.Monitor; - -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar -{ - public class MachineVarMessageHandler : BcpMessageHandler - { - public override string Command => MachineVarMessage.Command; - protected override ParseDelegate Parse => MachineVarMessage.FromGenericMessage; - public override MonitoringCategory MonitoringCategory => MonitoringCategory.MachineVars; - } -} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMonitor.cs b/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMonitor.cs deleted file mode 100644 index 67d2c558..00000000 --- a/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMonitor.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive -{ - public class BoolMachineVarMonitor : PrimitiveMachineVarMonitor { } -} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMonitor.cs b/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMonitor.cs deleted file mode 100644 index c8b02760..00000000 --- a/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMonitor.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive -{ - public class FloatMachineVarMonitor : PrimitiveMachineVarMonitor { } -} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/IntMachineVarMonitor.cs b/Runtime/Messages/MachineVar/Primitive/IntMachineVarMonitor.cs deleted file mode 100644 index a8b148d3..00000000 --- a/Runtime/Messages/MachineVar/Primitive/IntMachineVarMonitor.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive -{ - public class IntMachineVarMonitor : PrimitiveMachineVarMonitor { } -} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs b/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs deleted file mode 100644 index 2e02e410..00000000 --- a/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using UnityEngine; - -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive -{ - public abstract class PrimitiveMachineVarMonitor : MonoBehaviour where T : IEquatable - { - [SerializeField] - protected string varName; - [SerializeField] - private MachineVarMessageHandler machineVarMessageHandler; - - public event EventHandler ValueUpdated; - private T varValue = default; - public T VarValue - { - get => varValue; - set - { - if (value.Equals(varValue)) - return; - varValue = value; - ValueUpdated?.Invoke(this, varValue); - } - } - public bool WasEverUpdated { get; private set; } = false; - - private void OnEnable() - { - machineVarMessageHandler.Received += MachineVarMessageHandler_Received; - } - - private void OnDisable() - { - if (machineVarMessageHandler) - machineVarMessageHandler.Received -= MachineVarMessageHandler_Received; - } - - private void MachineVarMessageHandler_Received(object sender, MachineVarMessage msg) - { - if (msg.Name != varName) - return; - - T convertedValue; - - try - { - convertedValue = (T)Convert.ChangeType(msg.Value, typeof(T)); - } - catch (Exception e) when ( - e is InvalidCastException || - e is FormatException || - e is OverflowException || - e is ArgumentNullException) - { - throw new ParameterException(MachineVarMessage.ValueParamName, null, e); - } - - WasEverUpdated = true; - VarValue = convertedValue; - } - } -} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/StringMachineVarMonitor.cs b/Runtime/Messages/MachineVar/Primitive/StringMachineVarMonitor.cs deleted file mode 100644 index 57cef1e3..00000000 --- a/Runtime/Messages/MachineVar/Primitive/StringMachineVarMonitor.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive -{ - public class StringMachineVarMonitor : PrimitiveMachineVarMonitor { } -} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar.meta b/Runtime/Messages/MachineVariable.meta similarity index 100% rename from Runtime/Messages/MachineVar.meta rename to Runtime/Messages/MachineVariable.meta diff --git a/Runtime/Messages/MachineVariable/MachineVariableMessage.cs b/Runtime/Messages/MachineVariable/MachineVariableMessage.cs new file mode 100644 index 00000000..bb7231ea --- /dev/null +++ b/Runtime/Messages/MachineVariable/MachineVariableMessage.cs @@ -0,0 +1,21 @@ +using Newtonsoft.Json.Linq; + +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar +{ + public class MachineVariableMessage : MpfVariableMessageBase + { + public const string Command = "machine_variable"; + + public MachineVariableMessage(string name, JToken value) : base(name, value) + { + } + + public static MachineVariableMessage FromGenericMessage(BcpMessage bcpMessage) + { + return new MachineVariableMessage( + name: bcpMessage.GetParamValue(NameParamName), + value: bcpMessage.GetParamValue(ValueParamName) + ); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVariable/MachineVariableMessage.cs.meta b/Runtime/Messages/MachineVariable/MachineVariableMessage.cs.meta new file mode 100644 index 00000000..2b7b15b0 --- /dev/null +++ b/Runtime/Messages/MachineVariable/MachineVariableMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 672a1836b4f73ff4f8053f6a8094b00a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs b/Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs new file mode 100644 index 00000000..62af2782 --- /dev/null +++ b/Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs @@ -0,0 +1,11 @@ +using FutureBoxSystems.MpfMediaController.Messages.Monitor; + +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar +{ + public class MachineVariableMessageHandler : BcpMessageHandler + { + public override string Command => MachineVariableMessage.Command; + protected override ParseDelegate Parse => MachineVariableMessage.FromGenericMessage; + public override MonitoringCategory MonitoringCategory => MonitoringCategory.MachineVars; + } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/MachineVarMessageHandler.cs.meta b/Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs.meta similarity index 100% rename from Runtime/Messages/MachineVar/MachineVarMessageHandler.cs.meta rename to Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs.meta diff --git a/Runtime/Messages/MachineVar/Primitive.meta b/Runtime/Messages/MachineVariable/Monitor.meta similarity index 100% rename from Runtime/Messages/MachineVar/Primitive.meta rename to Runtime/Messages/MachineVariable/Monitor.meta diff --git a/Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs b/Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs new file mode 100644 index 00000000..e03cbefd --- /dev/null +++ b/Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar +{ + public class BoolMachineVariableMonitor : PrimitiveMachineVariableBase { } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/BoolMachineVarMonitor.cs.meta b/Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs.meta similarity index 100% rename from Runtime/Messages/MachineVar/Primitive/BoolMachineVarMonitor.cs.meta rename to Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs.meta diff --git a/Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs b/Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs new file mode 100644 index 00000000..e6810366 --- /dev/null +++ b/Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +{ + public class FloatMachineVarableMonitor : PrimitiveMachineVariableBase { } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/FloatMachineVarMonitor.cs.meta b/Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs.meta similarity index 100% rename from Runtime/Messages/MachineVar/Primitive/FloatMachineVarMonitor.cs.meta rename to Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs.meta diff --git a/Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs b/Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs new file mode 100644 index 00000000..3e6988c4 --- /dev/null +++ b/Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +{ + public class IntMachineVariableMonitor : PrimitiveMachineVariableBase { } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/IntMachineVarMonitor.cs.meta b/Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs.meta similarity index 100% rename from Runtime/Messages/MachineVar/Primitive/IntMachineVarMonitor.cs.meta rename to Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs.meta diff --git a/Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs b/Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs new file mode 100644 index 00000000..c4311f29 --- /dev/null +++ b/Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +{ + public class StringMachineVariableMonitor : PrimitiveMachineVariableBase { } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/StringMachineVarMonitor.cs.meta b/Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs.meta similarity index 100% rename from Runtime/Messages/MachineVar/Primitive/StringMachineVarMonitor.cs.meta rename to Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs.meta diff --git a/Runtime/Messages/MachineVariable/PrimitiveMachineVariableBase.cs b/Runtime/Messages/MachineVariable/PrimitiveMachineVariableBase.cs new file mode 100644 index 00000000..80403d0b --- /dev/null +++ b/Runtime/Messages/MachineVariable/PrimitiveMachineVariableBase.cs @@ -0,0 +1,9 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar +{ + public abstract class PrimitiveMachineVariableBase + : MpfVariableMonitorBase where T : IEquatable + { + } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs.meta b/Runtime/Messages/MachineVariable/PrimitiveMachineVariableBase.cs.meta similarity index 100% rename from Runtime/Messages/MachineVar/Primitive/PrimitiveMachineVarMonitor.cs.meta rename to Runtime/Messages/MachineVariable/PrimitiveMachineVariableBase.cs.meta diff --git a/Runtime/Messages/MonitorBase.cs b/Runtime/Messages/MonitorBase.cs new file mode 100644 index 00000000..a45298fd --- /dev/null +++ b/Runtime/Messages/MonitorBase.cs @@ -0,0 +1,50 @@ +using System; +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController.Messages +{ + public abstract class MonitorBase : MonoBehaviour where VarType : IEquatable where MsgType : EventArgs + { + [SerializeField] + private BcpMessageHandler messageHandler; + + public event EventHandler ValueChanged; + private VarType varValue = default; + public VarType VarValue + { + get => varValue; + protected set + { + WasEverUpdated = true; + if (value.Equals(varValue)) + return; + varValue = value; + ValueChanged?.Invoke(this, varValue); + } + } + public bool WasEverUpdated { get; private set; } = false; + + protected virtual void OnEnable() + { + messageHandler.Received += MessageHandler_Received; + } + + protected virtual void OnDisable() + { + if (messageHandler) + messageHandler.Received -= MessageHandler_Received; + } + + protected virtual void MessageHandler_Received(object sender, MsgType msg) + { + if (!MatchesMonitoringCriteria(msg)) + return; + + VarValue = GetValueFromMessage(msg); + } + + protected virtual bool MatchesMonitoringCriteria(MsgType msg) => true; + + protected abstract VarType GetValueFromMessage(MsgType msg); + } +} \ No newline at end of file diff --git a/Runtime/Messages/MonitorBase.cs.meta b/Runtime/Messages/MonitorBase.cs.meta new file mode 100644 index 00000000..f526fc38 --- /dev/null +++ b/Runtime/Messages/MonitorBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ad4fb569779bb6d45acea2626dc07f1c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/MpfVariableMessageBase.cs b/Runtime/Messages/MpfVariableMessageBase.cs new file mode 100644 index 00000000..88267565 --- /dev/null +++ b/Runtime/Messages/MpfVariableMessageBase.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json.Linq; +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages +{ + public abstract class MpfVariableMessageBase : EventArgs + { + public const string NameParamName = "name"; + public const string ValueParamName = "value"; + public readonly string Name; + public readonly JToken Value; + + public MpfVariableMessageBase(string name, JToken value) + { + Name = name; + Value = value; + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVar/MachineVarMessage.cs.meta b/Runtime/Messages/MpfVariableMessageBase.cs.meta similarity index 100% rename from Runtime/Messages/MachineVar/MachineVarMessage.cs.meta rename to Runtime/Messages/MpfVariableMessageBase.cs.meta diff --git a/Runtime/Messages/MpfVariableMonitorBase.cs b/Runtime/Messages/MpfVariableMonitorBase.cs new file mode 100644 index 00000000..963cca84 --- /dev/null +++ b/Runtime/Messages/MpfVariableMonitorBase.cs @@ -0,0 +1,32 @@ +using System; +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController.Messages +{ + public abstract class MpfVariableMonitorBase : MonitorBase where VarType : IEquatable where MsgType : MpfVariableMessageBase + { + [SerializeField] + protected string varName; + + protected override bool MatchesMonitoringCriteria(MsgType msg) + { + return base.MatchesMonitoringCriteria(msg) && msg.Name == varName; + } + + protected override VarType GetValueFromMessage(MsgType msg) + { + try + { + return (VarType)Convert.ChangeType(msg.Value, typeof(VarType)); + } + catch (Exception e) when ( + e is InvalidCastException || + e is FormatException || + e is OverflowException || + e is ArgumentNullException) + { + throw new ParameterException(MpfVariableMessageBase.ValueParamName, null, e); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/MpfVariableMonitorBase.cs.meta b/Runtime/Messages/MpfVariableMonitorBase.cs.meta new file mode 100644 index 00000000..6245f497 --- /dev/null +++ b/Runtime/Messages/MpfVariableMonitorBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 332d3e78eb5bec541856b5ee03b1404e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs b/Runtime/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs new file mode 100644 index 00000000..f2d039c8 --- /dev/null +++ b/Runtime/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs @@ -0,0 +1,7 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.PlayerTurnStart +{ + public class CurrentPlayerMonitor : MonitorBase + { + protected override int GetValueFromMessage(PlayerTurnStartMessage msg) => msg.PlayerNum; + } +} \ No newline at end of file diff --git a/Runtime/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs.meta b/Runtime/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs.meta new file mode 100644 index 00000000..76651cc1 --- /dev/null +++ b/Runtime/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c5dbd4ec22aad5b48b17ce372e46355b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/PlayerVariable.meta b/Runtime/Messages/PlayerVariable.meta new file mode 100644 index 00000000..a908fb7d --- /dev/null +++ b/Runtime/Messages/PlayerVariable.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5f2ac2ff74ff63e44a94b1f86d67bc89 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/PlayerVariable/Monitor.meta b/Runtime/Messages/PlayerVariable/Monitor.meta new file mode 100644 index 00000000..37f57402 --- /dev/null +++ b/Runtime/Messages/PlayerVariable/Monitor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b1374e4b9d1838942886cee4bdf82fa0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs b/Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs new file mode 100644 index 00000000..5f51e40a --- /dev/null +++ b/Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +{ + public class BoolPlayerVariableMonitor : PlayerVariableMonitorBase { } +} \ No newline at end of file diff --git a/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs b/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs new file mode 100644 index 00000000..3dd42012 --- /dev/null +++ b/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +{ + public class FloatPlayerVariableMonitor : PlayerVariableMonitorBase { } +} \ No newline at end of file diff --git a/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs b/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs new file mode 100644 index 00000000..527335cf --- /dev/null +++ b/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +{ + public class IntPlayerVariableMonitor : PlayerVariableMonitorBase { } +} \ No newline at end of file diff --git a/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs.meta b/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs.meta new file mode 100644 index 00000000..8c97ca31 --- /dev/null +++ b/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 992117fba3aa96a4f83c354e4e69eaf7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs b/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs new file mode 100644 index 00000000..e80da8ff --- /dev/null +++ b/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs @@ -0,0 +1,4 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +{ + public class StringPlayerVariableMonitor : PlayerVariableMonitorBase { } +} \ No newline at end of file diff --git a/Runtime/Messages/PlayerVariable/PlayerVariableMessage.cs b/Runtime/Messages/PlayerVariable/PlayerVariableMessage.cs new file mode 100644 index 00000000..51c57865 --- /dev/null +++ b/Runtime/Messages/PlayerVariable/PlayerVariableMessage.cs @@ -0,0 +1,26 @@ +using FutureBoxSystems.MpfMediaController.Messages.MachineVar; +using Newtonsoft.Json.Linq; + +namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +{ + public class PlayerVariableMessage : MpfVariableMessageBase + { + public const string Command = "player_variable"; + public const string PlayerNumParamName = "player_num"; + public readonly int PlayerNum; + + public PlayerVariableMessage(string name, int playerNum, JToken value) : base(name, value) + { + PlayerNum = playerNum; + } + + public static PlayerVariableMessage FromGenericMessage(BcpMessage bcpMessage) + { + return new PlayerVariableMessage( + name: bcpMessage.GetParamValue(NameParamName), + playerNum: bcpMessage.GetParamValue(PlayerNumParamName), + value: bcpMessage.GetParamValue(ValueParamName) + ); + } + } +} diff --git a/Runtime/Messages/PlayerVariable/PlayerVariableMessage.cs.meta b/Runtime/Messages/PlayerVariable/PlayerVariableMessage.cs.meta new file mode 100644 index 00000000..a0ecfba4 --- /dev/null +++ b/Runtime/Messages/PlayerVariable/PlayerVariableMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6940e88c4788fa847aebeb736655d39a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/PlayerVariable/PlayerVariableMessageHandler.cs b/Runtime/Messages/PlayerVariable/PlayerVariableMessageHandler.cs new file mode 100644 index 00000000..b589c840 --- /dev/null +++ b/Runtime/Messages/PlayerVariable/PlayerVariableMessageHandler.cs @@ -0,0 +1,11 @@ +using FutureBoxSystems.MpfMediaController.Messages.Monitor; + +namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +{ + public class PlayerVariableMessageHandler : BcpMessageHandler + { + public override string Command => PlayerVariableMessage.Command; + protected override ParseDelegate Parse => PlayerVariableMessage.FromGenericMessage; + public override MonitoringCategory MonitoringCategory => MonitoringCategory.PlayerVars; + } +} \ No newline at end of file diff --git a/Runtime/Messages/PlayerVariable/PlayerVariableMessageHandler.cs.meta b/Runtime/Messages/PlayerVariable/PlayerVariableMessageHandler.cs.meta new file mode 100644 index 00000000..0d24736e --- /dev/null +++ b/Runtime/Messages/PlayerVariable/PlayerVariableMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5e17d18c78dff5746ae1c03a10b14cb9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs b/Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs new file mode 100644 index 00000000..7cb92e43 --- /dev/null +++ b/Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs @@ -0,0 +1,49 @@ +using FutureBoxSystems.MpfMediaController.Messages.PlayerTurnStart; +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +{ + public abstract class PlayerVariableMonitorBase : MpfVariableMonitorBase where VarType : IEquatable + { + [SerializeField] + CurrentPlayerMonitor currentPlayerMonitor; + + protected Dictionary varPerPlayer = new(); + + protected override void OnEnable() + { + base.OnEnable(); + currentPlayerMonitor.ValueChanged += CurrentPlayerMonitor_ValueChanged; + } + + protected override void OnDisable() + { + base.OnDisable(); + if (currentPlayerMonitor) + currentPlayerMonitor.ValueChanged -= CurrentPlayerMonitor_ValueChanged; + } + + private void CurrentPlayerMonitor_ValueChanged(object sender, int currentPlayerNum) + { + varPerPlayer.TryAdd(currentPlayerNum, default); + VarValue = varPerPlayer[currentPlayerNum]; + } + + protected override void MessageHandler_Received(object sender, PlayerVariableMessage msg) + { + if (base.MatchesMonitoringCriteria(msg)) + { + VarType var = GetValueFromMessage(msg); + varPerPlayer[msg.PlayerNum] = var; + } + base.MessageHandler_Received(sender, msg); + } + + protected override bool MatchesMonitoringCriteria(PlayerVariableMessage msg) + { + return base.MatchesMonitoringCriteria(msg) && msg.PlayerNum == currentPlayerMonitor.VarValue; + } + } +} diff --git a/Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs.meta b/Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs.meta new file mode 100644 index 00000000..ae89b734 --- /dev/null +++ b/Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 343cb8dd7401c2c4390d3313211356db +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 2c45d338b3644bba4eb3e3f1980ef9db9b244035 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 29 Oct 2024 10:49:37 +0100 Subject: [PATCH 49/98] Reset monitored variables when requested --- Runtime/Messages/MonitorBase.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Runtime/Messages/MonitorBase.cs b/Runtime/Messages/MonitorBase.cs index a45298fd..d0dbaf6b 100644 --- a/Runtime/Messages/MonitorBase.cs +++ b/Runtime/Messages/MonitorBase.cs @@ -1,3 +1,4 @@ +using FutureBoxSystems.MpfMediaController.Messages.Reset; using System; using UnityEngine; @@ -7,6 +8,8 @@ public abstract class MonitorBase : MonoBehaviour where VarTyp { [SerializeField] private BcpMessageHandler messageHandler; + [SerializeField] + private ResetMessageHandler resetMessageHandler; public event EventHandler ValueChanged; private VarType varValue = default; @@ -27,12 +30,21 @@ protected set protected virtual void OnEnable() { messageHandler.Received += MessageHandler_Received; + resetMessageHandler.Received += ResetMessageHandler_Received; } protected virtual void OnDisable() { if (messageHandler) messageHandler.Received -= MessageHandler_Received; + if (resetMessageHandler) + resetMessageHandler.Received -= ResetMessageHandler_Received; + } + + private void ResetMessageHandler_Received(object sender, ResetMessage msg) + { + VarValue = default; + WasEverUpdated = false; } protected virtual void MessageHandler_Received(object sender, MsgType msg) From e495e40c9250a458ab9a1a093282b77de62f2a7a Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 29 Oct 2024 10:50:01 +0100 Subject: [PATCH 50/98] Rename PlayerVariableMonitorBase to PlayerVariableMonitor --- .../Monitor/BoolPlayerVariableMonitor.cs | 2 +- .../BoolPlayerVariableMonitor.cs.meta} | 2 +- .../Monitor/FloatPlayerVariableMonitor.cs | 2 +- .../Monitor/FloatPlayerVariableMonitor.cs.meta | 11 +++++++++++ .../Monitor/IntPlayerVariableMonitor.cs | 2 +- .../Monitor/StringPlayerVariableMonitor.cs | 2 +- .../Monitor/StringPlayerVariableMonitor.cs.meta | 11 +++++++++++ ...ariableMonitorBase.cs => PlayerVariableMonitor.cs} | 2 +- .../PlayerVariable/PlayerVariableMonitor.cs.meta | 11 +++++++++++ 9 files changed, 39 insertions(+), 6 deletions(-) rename Runtime/Messages/PlayerVariable/{PlayerVariableMonitorBase.cs.meta => Monitor/BoolPlayerVariableMonitor.cs.meta} (83%) create mode 100644 Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs.meta create mode 100644 Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs.meta rename Runtime/Messages/PlayerVariable/{PlayerVariableMonitorBase.cs => PlayerVariableMonitor.cs} (91%) create mode 100644 Runtime/Messages/PlayerVariable/PlayerVariableMonitor.cs.meta diff --git a/Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs b/Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs index 5f51e40a..ab8dc5c8 100644 --- a/Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs +++ b/Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable { - public class BoolPlayerVariableMonitor : PlayerVariableMonitorBase { } + public class BoolPlayerVariableMonitor : PlayerVariableMonitor { } } \ No newline at end of file diff --git a/Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs.meta b/Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs.meta similarity index 83% rename from Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs.meta rename to Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs.meta index ae89b734..3c2300f7 100644 --- a/Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs.meta +++ b/Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 343cb8dd7401c2c4390d3313211356db +guid: 46c020f5fa89c894499ccb361267d99b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs b/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs index 3dd42012..3208fb44 100644 --- a/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs +++ b/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable { - public class FloatPlayerVariableMonitor : PlayerVariableMonitorBase { } + public class FloatPlayerVariableMonitor : PlayerVariableMonitor { } } \ No newline at end of file diff --git a/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs.meta b/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs.meta new file mode 100644 index 00000000..98898c16 --- /dev/null +++ b/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6dcd93eeaa7785a4598c5a82cb2a1998 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs b/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs index 527335cf..edcbc6b8 100644 --- a/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs +++ b/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable { - public class IntPlayerVariableMonitor : PlayerVariableMonitorBase { } + public class IntPlayerVariableMonitor : PlayerVariableMonitor { } } \ No newline at end of file diff --git a/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs b/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs index e80da8ff..f5280eb5 100644 --- a/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs +++ b/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable { - public class StringPlayerVariableMonitor : PlayerVariableMonitorBase { } + public class StringPlayerVariableMonitor : PlayerVariableMonitor { } } \ No newline at end of file diff --git a/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs.meta b/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs.meta new file mode 100644 index 00000000..24550444 --- /dev/null +++ b/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4914c539440563a4681521fc5bc2eb3d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs b/Runtime/Messages/PlayerVariable/PlayerVariableMonitor.cs similarity index 91% rename from Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs rename to Runtime/Messages/PlayerVariable/PlayerVariableMonitor.cs index 7cb92e43..ee55b3da 100644 --- a/Runtime/Messages/PlayerVariable/PlayerVariableMonitorBase.cs +++ b/Runtime/Messages/PlayerVariable/PlayerVariableMonitor.cs @@ -5,7 +5,7 @@ namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable { - public abstract class PlayerVariableMonitorBase : MpfVariableMonitorBase where VarType : IEquatable + public abstract class PlayerVariableMonitor : MpfVariableMonitorBase where VarType : IEquatable { [SerializeField] CurrentPlayerMonitor currentPlayerMonitor; diff --git a/Runtime/Messages/PlayerVariable/PlayerVariableMonitor.cs.meta b/Runtime/Messages/PlayerVariable/PlayerVariableMonitor.cs.meta new file mode 100644 index 00000000..972b9b6a --- /dev/null +++ b/Runtime/Messages/PlayerVariable/PlayerVariableMonitor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 74657fa6eaa8e8d408fd9299768240ae +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 5f0d1636653eac7f2601adf6db879dc0d64f5b99 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 29 Oct 2024 19:56:43 +0100 Subject: [PATCH 51/98] Fix null exception --- Runtime/Messages/MonitorBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Messages/MonitorBase.cs b/Runtime/Messages/MonitorBase.cs index d0dbaf6b..8ba47eff 100644 --- a/Runtime/Messages/MonitorBase.cs +++ b/Runtime/Messages/MonitorBase.cs @@ -19,7 +19,7 @@ public VarType VarValue protected set { WasEverUpdated = true; - if (value.Equals(varValue)) + if ((value == null && VarValue == null)|| value.Equals(varValue)) return; varValue = value; ValueChanged?.Invoke(this, varValue); From b77bebff75af5e0586d480f47ce6b18f97fb92c7 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 29 Oct 2024 19:57:33 +0100 Subject: [PATCH 52/98] Fix machine variable type issue --- Runtime/BcpInterface.prefab | 28 +++++++++++++++++++ .../MachineVariableMessageHandler.cs | 2 +- .../MachineVariable/MachineVariableMonitor.cs | 9 ++++++ ...cs.meta => MachineVariableMonitor.cs.meta} | 0 .../Monitor/BoolMachineVariableMonitor.cs | 2 +- .../Monitor/FloatMachineVarableMonitor.cs | 2 +- .../Monitor/IntMachineVariableMonitor.cs | 2 +- .../Monitor/StringMachineVariableMonitor.cs | 2 +- .../PrimitiveMachineVariableBase.cs | 9 ------ 9 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 Runtime/Messages/MachineVariable/MachineVariableMonitor.cs rename Runtime/Messages/MachineVariable/{PrimitiveMachineVariableBase.cs.meta => MachineVariableMonitor.cs.meta} (100%) delete mode 100644 Runtime/Messages/MachineVariable/PrimitiveMachineVariableBase.cs diff --git a/Runtime/BcpInterface.prefab b/Runtime/BcpInterface.prefab index 7dc48696..7ea92411 100644 --- a/Runtime/BcpInterface.prefab +++ b/Runtime/BcpInterface.prefab @@ -24,6 +24,8 @@ GameObject: - component: {fileID: 491971619498350422} - component: {fileID: 3968882011461727216} - component: {fileID: 2727910698276087158} + - component: {fileID: 1282676592095372013} + - component: {fileID: 6493956983709597485} m_Layer: 0 m_Name: MessageHandlers m_TagString: Untagged @@ -241,6 +243,32 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &1282676592095372013 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f766cbe8cf3bc84f9686435c4834e79, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &6493956983709597485 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: cdf1f7f6d8df17345ba92944c4fd5214, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} --- !u!1 &7214112112941309933 GameObject: m_ObjectHideFlags: 0 diff --git a/Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs b/Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs index 62af2782..a785799d 100644 --- a/Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs +++ b/Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs @@ -2,7 +2,7 @@ namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar { - public class MachineVariableMessageHandler : BcpMessageHandler + public class MachineVariableMessageHandler : BcpMessageHandler { public override string Command => MachineVariableMessage.Command; protected override ParseDelegate Parse => MachineVariableMessage.FromGenericMessage; diff --git a/Runtime/Messages/MachineVariable/MachineVariableMonitor.cs b/Runtime/Messages/MachineVariable/MachineVariableMonitor.cs new file mode 100644 index 00000000..6ef6a117 --- /dev/null +++ b/Runtime/Messages/MachineVariable/MachineVariableMonitor.cs @@ -0,0 +1,9 @@ +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar +{ + public abstract class MachineVariableMonitor + : MpfVariableMonitorBase where VarType : IEquatable + { + } +} \ No newline at end of file diff --git a/Runtime/Messages/MachineVariable/PrimitiveMachineVariableBase.cs.meta b/Runtime/Messages/MachineVariable/MachineVariableMonitor.cs.meta similarity index 100% rename from Runtime/Messages/MachineVariable/PrimitiveMachineVariableBase.cs.meta rename to Runtime/Messages/MachineVariable/MachineVariableMonitor.cs.meta diff --git a/Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs b/Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs index e03cbefd..6d682ff8 100644 --- a/Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs +++ b/Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar { - public class BoolMachineVariableMonitor : PrimitiveMachineVariableBase { } + public class BoolMachineVariableMonitor : MachineVariableMonitor { } } \ No newline at end of file diff --git a/Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs b/Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs index e6810366..d007c795 100644 --- a/Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs +++ b/Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive { - public class FloatMachineVarableMonitor : PrimitiveMachineVariableBase { } + public class FloatMachineVarableMonitor : MachineVariableMonitor { } } \ No newline at end of file diff --git a/Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs b/Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs index 3e6988c4..d8185064 100644 --- a/Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs +++ b/Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive { - public class IntMachineVariableMonitor : PrimitiveMachineVariableBase { } + public class IntMachineVariableMonitor : MachineVariableMonitor { } } \ No newline at end of file diff --git a/Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs b/Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs index c4311f29..f184c081 100644 --- a/Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs +++ b/Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive { - public class StringMachineVariableMonitor : PrimitiveMachineVariableBase { } + public class StringMachineVariableMonitor : MachineVariableMonitor { } } \ No newline at end of file diff --git a/Runtime/Messages/MachineVariable/PrimitiveMachineVariableBase.cs b/Runtime/Messages/MachineVariable/PrimitiveMachineVariableBase.cs deleted file mode 100644 index 80403d0b..00000000 --- a/Runtime/Messages/MachineVariable/PrimitiveMachineVariableBase.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar -{ - public abstract class PrimitiveMachineVariableBase - : MpfVariableMonitorBase where T : IEquatable - { - } -} \ No newline at end of file From 825b965e84c3f1b815af889f362de1c6dbffdd40 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 29 Oct 2024 19:58:04 +0100 Subject: [PATCH 53/98] Add mpf event listener --- Runtime/Core/BcpInterface.cs | 50 +++++--------- Runtime/Core/BcpMessageHandler.cs | 10 ++- Runtime/Core/SharedEventListener.cs | 66 +++++++++++++++++++ Runtime/Core/SharedEventListener.cs.meta | 11 ++++ Runtime/Messages/Trigger.meta | 8 +++ Runtime/Messages/Trigger/MpfEventListener.cs | 37 +++++++++++ .../Messages/Trigger/MpfEventListener.cs.meta | 11 ++++ .../Trigger/RegisterTriggerMessage.cs | 26 ++++++++ .../Trigger/RegisterTriggerMessage.cs.meta | 11 ++++ .../Messages/Trigger/RemoveTriggerMessage.cs | 26 ++++++++ .../Trigger/RemoveTriggerMessage.cs.meta | 11 ++++ Runtime/Messages/Trigger/TriggerMessage.cs | 34 ++++++++++ .../Messages/Trigger/TriggerMessage.cs.meta | 11 ++++ .../Messages/Trigger/TriggerMessageHandler.cs | 9 +++ .../Trigger/TriggerMessageHandler.cs.meta | 11 ++++ 15 files changed, 295 insertions(+), 37 deletions(-) create mode 100644 Runtime/Core/SharedEventListener.cs create mode 100644 Runtime/Core/SharedEventListener.cs.meta create mode 100644 Runtime/Messages/Trigger.meta create mode 100644 Runtime/Messages/Trigger/MpfEventListener.cs create mode 100644 Runtime/Messages/Trigger/MpfEventListener.cs.meta create mode 100644 Runtime/Messages/Trigger/RegisterTriggerMessage.cs create mode 100644 Runtime/Messages/Trigger/RegisterTriggerMessage.cs.meta create mode 100644 Runtime/Messages/Trigger/RemoveTriggerMessage.cs create mode 100644 Runtime/Messages/Trigger/RemoveTriggerMessage.cs.meta create mode 100644 Runtime/Messages/Trigger/TriggerMessage.cs create mode 100644 Runtime/Messages/Trigger/TriggerMessage.cs.meta create mode 100644 Runtime/Messages/Trigger/TriggerMessageHandler.cs create mode 100644 Runtime/Messages/Trigger/TriggerMessageHandler.cs.meta diff --git a/Runtime/Core/BcpInterface.cs b/Runtime/Core/BcpInterface.cs index ff40c188..d45759ed 100644 --- a/Runtime/Core/BcpInterface.cs +++ b/Runtime/Core/BcpInterface.cs @@ -3,6 +3,7 @@ using UnityEngine; using FutureBoxSystems.MpfMediaController.Messages.Monitor; using FutureBoxSystems.MpfMediaController.Messages.Error; +using FutureBoxSystems.MpfMediaController.Messages.Trigger; namespace FutureBoxSystems.MpfMediaController { @@ -23,7 +24,20 @@ public class BcpInterface : MonoBehaviour public delegate void HandleMessage(BcpMessage message); private readonly Dictionary messageHandlers = new(); - private readonly Dictionary monitoringCategoryUserCounts = new(); + private SharedEventListener monitoringCategories; + public SharedEventListener MonitoringCategories => monitoringCategories ??= new( + bcpInterface: this, + createStartListeningMessage: category => new MonitorStartMessage(category), + createStopListeningMessage: category => new MonitorStopMessage(category)); + + private SharedEventListener mpfEvents; + public SharedEventListener MpfEvents => mpfEvents ??= new( + bcpInterface: this, + createStartListeningMessage: category => new RegisterTriggerMessage(category), + createStopListeningMessage: category => new RemoveTriggerMessage(category)); + + + public event EventHandler ConnectionStateChanged; public void RegisterMessageHandler(string command, HandleMessage handle) { @@ -39,28 +53,6 @@ public void UnregisterMessageHandler(string command, HandleMessage handle) Debug.LogWarning($"[BcpInterface] Cannot remove message handler for command '{command}', because it is not registered."); } - public void AddMonitoringCategoryUser(MonitoringCategory category) - { - if (!monitoringCategoryUserCounts.TryAdd(category, 1)) - monitoringCategoryUserCounts[category]++; - - if (monitoringCategoryUserCounts[category] == 1) - TrySendMessage(new MonitorStartMessage(category)); - } - - public void RemoveMonitoringCategoryUser(MonitoringCategory category) - { - if (monitoringCategoryUserCounts.TryGetValue(category, out var userCount)) - { - if (userCount > 0) - { - monitoringCategoryUserCounts[category]--; - if (monitoringCategoryUserCounts[category] == 0) - TrySendMessage(new MonitorStopMessage(category)); - } - } - } - public bool TrySendMessage(ISentMessage message) { if (ConnectionState == ConnectionState.Connected) @@ -89,17 +81,7 @@ private async void OnEnable() private void HandleServerStateChanged(object sender, ConnectionStateChangedEventArgs e) { - bool hasJustConnected = e.CurrentState == ConnectionState.Connected; - if (hasJustConnected) - { - foreach (KeyValuePair kvp in monitoringCategoryUserCounts) - { - MonitoringCategory category = kvp.Key; - int userCount = kvp.Value; - if (userCount > 0) - TrySendMessage(new MonitorStartMessage(category)); - } - } + ConnectionStateChanged?.Invoke(this, e.CurrentState); } private void Update() diff --git a/Runtime/Core/BcpMessageHandler.cs b/Runtime/Core/BcpMessageHandler.cs index 4090ddf2..21459ef3 100644 --- a/Runtime/Core/BcpMessageHandler.cs +++ b/Runtime/Core/BcpMessageHandler.cs @@ -21,13 +21,17 @@ public event EventHandler Received bool isFirstHandler = CommandReceived == null; CommandReceived += value; if (isFirstHandler && MonitoringCategory != MonitoringCategory.None) - bcpInterface.AddMonitoringCategoryUser(MonitoringCategory); + bcpInterface.MonitoringCategories.AddListener(this, MonitoringCategory); } remove { CommandReceived -= value; - if (CommandReceived == null && MonitoringCategory != MonitoringCategory.None) - bcpInterface.RemoveMonitoringCategoryUser(MonitoringCategory); + if (bcpInterface != null && + CommandReceived == null && + MonitoringCategory != MonitoringCategory.None) + { + bcpInterface.MonitoringCategories.RemoveListener(this, MonitoringCategory); + } } } diff --git a/Runtime/Core/SharedEventListener.cs b/Runtime/Core/SharedEventListener.cs new file mode 100644 index 00000000..dc0e82bf --- /dev/null +++ b/Runtime/Core/SharedEventListener.cs @@ -0,0 +1,66 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController +{ + public class SharedEventListener + { + public delegate ISentMessage CreateMessage(EventType _event); + + private readonly BcpInterface bcpInterface; + private readonly CreateMessage createStartListeningMessage; + private readonly CreateMessage createStopListeningMessage; + private readonly Dictionary> listeners = new(); + + public SharedEventListener( + BcpInterface bcpInterface, + CreateMessage createStartListeningMessage, + CreateMessage createStopListeningMessage) + { + this.bcpInterface = bcpInterface; + this.createStartListeningMessage = createStartListeningMessage; + this.createStopListeningMessage = createStopListeningMessage; + bcpInterface.ConnectionStateChanged += BcpInterface_ConnectionStateChanged; + } + + public void AddListener(object listener, EventType _event) + { + if (listeners.TryAdd(_event, new HashSet { listener })) + { + var startListeningMsg = createStartListeningMessage(_event); + bcpInterface.TrySendMessage(startListeningMsg); + } + else if (!listeners[_event].Add(listener)) + Debug.LogError($"[EventPool] Cannot add listener '{listener}' to event '{_event}' because it was already added."); + } + + private void BcpInterface_ConnectionStateChanged(object sender, ConnectionState e) + { + if (e == ConnectionState.Connected) + { + foreach (var kvp in listeners) + { + EventType _event = kvp.Key; + HashSet listeners = kvp.Value; + if (listeners.Count > 0) + { + var startListeningMsg = createStartListeningMessage(_event); + bcpInterface.TrySendMessage(startListeningMsg); + } + } + } + } + + public void RemoveListener(object listener, EventType _event) + { + if (listeners.TryGetValue(_event, out var listenersForThisEvent) && + listenersForThisEvent.Remove(listener)) + { + var stopListeningMsg = createStopListeningMessage(_event); + bcpInterface.TrySendMessage(stopListeningMsg); + } + else + Debug.LogError($"[EventPool] Cannot remove listener '{listener}' from event '{_event}' because it is not a listener."); + } + } +} \ No newline at end of file diff --git a/Runtime/Core/SharedEventListener.cs.meta b/Runtime/Core/SharedEventListener.cs.meta new file mode 100644 index 00000000..2428d100 --- /dev/null +++ b/Runtime/Core/SharedEventListener.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f22a6ea92d92204479b6fcf7c4e38035 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Trigger.meta b/Runtime/Messages/Trigger.meta new file mode 100644 index 00000000..b455a41c --- /dev/null +++ b/Runtime/Messages/Trigger.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f6dabf473f770a6469302bc9572dccf8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Trigger/MpfEventListener.cs b/Runtime/Messages/Trigger/MpfEventListener.cs new file mode 100644 index 00000000..58174ce1 --- /dev/null +++ b/Runtime/Messages/Trigger/MpfEventListener.cs @@ -0,0 +1,37 @@ +using System; +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController.Messages.Trigger +{ + public class MpfEventListener : MonoBehaviour + { + [SerializeField] + private string eventName; + [SerializeField] + private BcpInterface bcpInterface; + [SerializeField] + private TriggerMessageHandler triggerMessageHandler; + + public event EventHandler Triggered; + + private void OnEnable() + { + bcpInterface.MpfEvents.AddListener(this, eventName); + triggerMessageHandler.Received += TriggerMessageHandler_Received; + } + + private void OnDisable() + { + if (bcpInterface) + bcpInterface.MpfEvents.RemoveListener(this, eventName); + if (triggerMessageHandler) + triggerMessageHandler.Received -= TriggerMessageHandler_Received; + } + + private void TriggerMessageHandler_Received(object sender, TriggerMessage msg) + { + if (msg.TriggerName == eventName) + Triggered?.Invoke(this, EventArgs.Empty); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Trigger/MpfEventListener.cs.meta b/Runtime/Messages/Trigger/MpfEventListener.cs.meta new file mode 100644 index 00000000..09075176 --- /dev/null +++ b/Runtime/Messages/Trigger/MpfEventListener.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a8c5e8010681b514aa48b35b4ef8e6df +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Trigger/RegisterTriggerMessage.cs b/Runtime/Messages/Trigger/RegisterTriggerMessage.cs new file mode 100644 index 00000000..b51af6d9 --- /dev/null +++ b/Runtime/Messages/Trigger/RegisterTriggerMessage.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json.Linq; +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Trigger +{ + public class RegisterTriggerMessage : EventArgs, ISentMessage + { + public const string Command = "register_trigger"; + private const string eventParamName = "event"; + + public readonly string EventName; + + public RegisterTriggerMessage(string eventName) + { + EventName = eventName; + } + + public BcpMessage ToGenericMessage() + { + return new BcpMessage( + command: Command, + parameters: new JObject { { eventParamName, EventName } } + ); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Trigger/RegisterTriggerMessage.cs.meta b/Runtime/Messages/Trigger/RegisterTriggerMessage.cs.meta new file mode 100644 index 00000000..8d71dafe --- /dev/null +++ b/Runtime/Messages/Trigger/RegisterTriggerMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2d7305f2ca5caf54caef72b55fdaa509 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Trigger/RemoveTriggerMessage.cs b/Runtime/Messages/Trigger/RemoveTriggerMessage.cs new file mode 100644 index 00000000..0850eb6a --- /dev/null +++ b/Runtime/Messages/Trigger/RemoveTriggerMessage.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json.Linq; +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Trigger +{ + public class RemoveTriggerMessage : EventArgs, ISentMessage + { + public const string Command = "remove_trigger"; + private const string eventParamName = "event"; + + public readonly string EventName; + + public RemoveTriggerMessage(string eventName) + { + EventName = eventName; + } + + public BcpMessage ToGenericMessage() + { + return new BcpMessage( + command: Command, + parameters: new JObject { { eventParamName, EventName } } + ); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Trigger/RemoveTriggerMessage.cs.meta b/Runtime/Messages/Trigger/RemoveTriggerMessage.cs.meta new file mode 100644 index 00000000..c0403838 --- /dev/null +++ b/Runtime/Messages/Trigger/RemoveTriggerMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eccbcde16d7dccd40a11e58aa1e7159b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Trigger/TriggerMessage.cs b/Runtime/Messages/Trigger/TriggerMessage.cs new file mode 100644 index 00000000..78f577e3 --- /dev/null +++ b/Runtime/Messages/Trigger/TriggerMessage.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json.Linq; +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Trigger +{ + public class TriggerMessage : EventArgs, ISentMessage + { + public const string Command = "trigger"; + public const string NameParamName = "name"; + + public readonly string TriggerName; + + public TriggerMessage(string name) + { + TriggerName = name; + } + + public static TriggerMessage FromGenericMessage(BcpMessage bcpMessage) + { + return new TriggerMessage(name: bcpMessage.GetParamValue(NameParamName)); + } + + public BcpMessage ToGenericMessage() + { + return new BcpMessage( + command: Command, + parameters: new JObject + { + { NameParamName, TriggerName } + } + ); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Trigger/TriggerMessage.cs.meta b/Runtime/Messages/Trigger/TriggerMessage.cs.meta new file mode 100644 index 00000000..0ee120d2 --- /dev/null +++ b/Runtime/Messages/Trigger/TriggerMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7f33e0a2d1a4b534bbb6e13e5bd5c0a2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Trigger/TriggerMessageHandler.cs b/Runtime/Messages/Trigger/TriggerMessageHandler.cs new file mode 100644 index 00000000..da4c5183 --- /dev/null +++ b/Runtime/Messages/Trigger/TriggerMessageHandler.cs @@ -0,0 +1,9 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.Trigger +{ + public class TriggerMessageHandler : BcpMessageHandler + { + public override string Command => TriggerMessage.Command; + + protected override ParseDelegate Parse => TriggerMessage.FromGenericMessage; + } +} \ No newline at end of file diff --git a/Runtime/Messages/Trigger/TriggerMessageHandler.cs.meta b/Runtime/Messages/Trigger/TriggerMessageHandler.cs.meta new file mode 100644 index 00000000..cca7b432 --- /dev/null +++ b/Runtime/Messages/Trigger/TriggerMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5f766cbe8cf3bc84f9686435c4834e79 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 3e3f9c6a58a7c82b17df2956e12f925fb0ac331d Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 29 Oct 2024 20:35:41 +0100 Subject: [PATCH 54/98] Enqueue messages regardless of connection status --- Runtime/Behaviours/HelloResponse.cs | 2 +- Runtime/Core/BcpInterface.cs | 33 ++++++++----------- Runtime/Core/SharedEventListener.cs | 22 ++----------- Runtime/Messages/Reset/ResetMessageHandler.cs | 2 +- 4 files changed, 18 insertions(+), 41 deletions(-) diff --git a/Runtime/Behaviours/HelloResponse.cs b/Runtime/Behaviours/HelloResponse.cs index c10f7bf4..444a8505 100644 --- a/Runtime/Behaviours/HelloResponse.cs +++ b/Runtime/Behaviours/HelloResponse.cs @@ -40,7 +40,7 @@ private void HelloMessageReceived(object sender, HelloMessage message) message: "unknown protocol version", commandThatCausedError: originalHelloMessage); } - bcpInterface.TrySendMessage(response); + bcpInterface.EnqueueMessage(response); } } } \ No newline at end of file diff --git a/Runtime/Core/BcpInterface.cs b/Runtime/Core/BcpInterface.cs index d45759ed..c1da6f84 100644 --- a/Runtime/Core/BcpInterface.cs +++ b/Runtime/Core/BcpInterface.cs @@ -9,7 +9,7 @@ namespace FutureBoxSystems.MpfMediaController { public class BcpInterface : MonoBehaviour { - public ConnectionState ConnectionState => server != null ? server.ConnectionState : ConnectionState.NotConnected; + public ConnectionState ConnectionState => Server.ConnectionState; [SerializeField] private int port = 5050; [SerializeField] @@ -21,6 +21,7 @@ public class BcpInterface : MonoBehaviour private bool logSentMessages = false; private BcpServer server; + private BcpServer Server => server ??= new BcpServer(port); public delegate void HandleMessage(BcpMessage message); private readonly Dictionary messageHandlers = new(); @@ -53,30 +54,24 @@ public void UnregisterMessageHandler(string command, HandleMessage handle) Debug.LogWarning($"[BcpInterface] Cannot remove message handler for command '{command}', because it is not registered."); } - public bool TrySendMessage(ISentMessage message) + public void EnqueueMessage(ISentMessage message) { - if (ConnectionState == ConnectionState.Connected) - { - BcpMessage bcpMessage = message.ToGenericMessage(); - if (logSentMessages) - Debug.Log($"[BcpInterface] Sending message: {bcpMessage}"); - server.EnqueueMessage(bcpMessage); - return true; - } - return false; + BcpMessage bcpMessage = message.ToGenericMessage(); + if (logSentMessages) + Debug.Log($"[BcpInterface] Sending message: {bcpMessage}"); + Server.EnqueueMessage(bcpMessage); } public void RequestDisconnect() { if (ConnectionState == ConnectionState.Connected) - server.RequestDisconnect(); + Server.RequestDisconnect(); } private async void OnEnable() { - server ??= new BcpServer(port); - server.StateChanged += HandleServerStateChanged; - await server.OpenConnectionAsync(); + Server.StateChanged += HandleServerStateChanged; + await Server.OpenConnectionAsync(); } private void HandleServerStateChanged(object sender, ConnectionStateChangedEventArgs e) @@ -88,7 +83,7 @@ private void Update() { float startTime = Time.unscaledTime; float timeSpentMs = 0f; - while (timeSpentMs < frameTimeBudgetMs && server.TryDequeueReceivedMessage(out var message)) + while (timeSpentMs < frameTimeBudgetMs && Server.TryDequeueReceivedMessage(out var message)) { HandleReceivedMessage(message); timeSpentMs = (Time.unscaledTime - startTime) * 1000f; @@ -114,14 +109,14 @@ private void HandleReceivedMessage(BcpMessage message) else { Debug.LogError($"[BcpInterface] No parser registered for message with command '{message.Command}' Message: {message}"); - TrySendMessage(new ErrorMessage("unknown command", message.ToString())); + EnqueueMessage(new ErrorMessage("unknown command", message.ToString())); } } private async void OnDisable() { - await server.CloseConnectionAsync(); - server.StateChanged -= HandleServerStateChanged; + await Server.CloseConnectionAsync(); + Server.StateChanged -= HandleServerStateChanged; } } } \ No newline at end of file diff --git a/Runtime/Core/SharedEventListener.cs b/Runtime/Core/SharedEventListener.cs index dc0e82bf..09542c03 100644 --- a/Runtime/Core/SharedEventListener.cs +++ b/Runtime/Core/SharedEventListener.cs @@ -20,7 +20,6 @@ public SharedEventListener( this.bcpInterface = bcpInterface; this.createStartListeningMessage = createStartListeningMessage; this.createStopListeningMessage = createStopListeningMessage; - bcpInterface.ConnectionStateChanged += BcpInterface_ConnectionStateChanged; } public void AddListener(object listener, EventType _event) @@ -28,36 +27,19 @@ public void AddListener(object listener, EventType _event) if (listeners.TryAdd(_event, new HashSet { listener })) { var startListeningMsg = createStartListeningMessage(_event); - bcpInterface.TrySendMessage(startListeningMsg); + bcpInterface.EnqueueMessage(startListeningMsg); } else if (!listeners[_event].Add(listener)) Debug.LogError($"[EventPool] Cannot add listener '{listener}' to event '{_event}' because it was already added."); } - private void BcpInterface_ConnectionStateChanged(object sender, ConnectionState e) - { - if (e == ConnectionState.Connected) - { - foreach (var kvp in listeners) - { - EventType _event = kvp.Key; - HashSet listeners = kvp.Value; - if (listeners.Count > 0) - { - var startListeningMsg = createStartListeningMessage(_event); - bcpInterface.TrySendMessage(startListeningMsg); - } - } - } - } - public void RemoveListener(object listener, EventType _event) { if (listeners.TryGetValue(_event, out var listenersForThisEvent) && listenersForThisEvent.Remove(listener)) { var stopListeningMsg = createStopListeningMessage(_event); - bcpInterface.TrySendMessage(stopListeningMsg); + bcpInterface.EnqueueMessage(stopListeningMsg); } else Debug.LogError($"[EventPool] Cannot remove listener '{listener}' from event '{_event}' because it is not a listener."); diff --git a/Runtime/Messages/Reset/ResetMessageHandler.cs b/Runtime/Messages/Reset/ResetMessageHandler.cs index ba04efb7..ce0cd5fc 100644 --- a/Runtime/Messages/Reset/ResetMessageHandler.cs +++ b/Runtime/Messages/Reset/ResetMessageHandler.cs @@ -8,7 +8,7 @@ public class ResetMessageHandler : BcpMessageHandler protected override void AfterEvent() { base.AfterEvent(); - bcpInterface.TrySendMessage(new ResetCompleteMessage()); + bcpInterface.EnqueueMessage(new ResetCompleteMessage()); } } } \ No newline at end of file From fc52ec0ee1133066e74cfa5b76bae5aed9198504 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 29 Oct 2024 20:40:01 +0100 Subject: [PATCH 55/98] Remove colon from BcpInterface inspector --- Editor/BcpInterfaceInspector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Editor/BcpInterfaceInspector.cs b/Editor/BcpInterfaceInspector.cs index a83a23ef..52d26316 100644 --- a/Editor/BcpInterfaceInspector.cs +++ b/Editor/BcpInterfaceInspector.cs @@ -21,7 +21,7 @@ public override void OnInspectorGUI() if (bcpInterface != null) { var connectionState = bcpInterface.ConnectionState; - EditorGUILayout.LabelField("Connection status:", connectionState.ToString()); + EditorGUILayout.LabelField("Connection status", connectionState.ToString()); } base.OnInspectorGUI(); } From efdfdd03064876ffad84b13531a9ea353b7057fa Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 29 Oct 2024 20:40:18 +0100 Subject: [PATCH 56/98] Remove connection state event from BcpInterface --- Runtime/Core/BcpInterface.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Runtime/Core/BcpInterface.cs b/Runtime/Core/BcpInterface.cs index c1da6f84..68087d85 100644 --- a/Runtime/Core/BcpInterface.cs +++ b/Runtime/Core/BcpInterface.cs @@ -38,8 +38,6 @@ public class BcpInterface : MonoBehaviour createStopListeningMessage: category => new RemoveTriggerMessage(category)); - public event EventHandler ConnectionStateChanged; - public void RegisterMessageHandler(string command, HandleMessage handle) { if (!messageHandlers.TryAdd(command, handle)) @@ -64,19 +62,18 @@ public void EnqueueMessage(ISentMessage message) public void RequestDisconnect() { - if (ConnectionState == ConnectionState.Connected) + if (Server.ConnectionState == ConnectionState.Connected) Server.RequestDisconnect(); } private async void OnEnable() { - Server.StateChanged += HandleServerStateChanged; await Server.OpenConnectionAsync(); } - private void HandleServerStateChanged(object sender, ConnectionStateChangedEventArgs e) + private async void OnDisable() { - ConnectionStateChanged?.Invoke(this, e.CurrentState); + await Server.CloseConnectionAsync(); } private void Update() @@ -112,11 +109,5 @@ private void HandleReceivedMessage(BcpMessage message) EnqueueMessage(new ErrorMessage("unknown command", message.ToString())); } } - - private async void OnDisable() - { - await Server.CloseConnectionAsync(); - Server.StateChanged -= HandleServerStateChanged; - } } } \ No newline at end of file From a4a056b7ba1372dccf5ac1a7d0619edf81ec376f Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 29 Oct 2024 22:47:15 +0100 Subject: [PATCH 57/98] Add switch message handling --- Runtime/BcpInterface.prefab | 14 ++++++ Runtime/Messages/MpfVariableMonitorBase.cs | 4 +- Runtime/Messages/Switch.meta | 8 +++ Runtime/Messages/Switch/SwitchMessage.cs | 49 +++++++++++++++++++ Runtime/Messages/Switch/SwitchMessage.cs.meta | 11 +++++ .../Messages/Switch/SwitchMessageHandler.cs | 13 +++++ .../Switch/SwitchMessageHandler.cs.meta | 11 +++++ Runtime/Messages/Switch/SwitchMonitor.cs | 17 +++++++ Runtime/Messages/Switch/SwitchMonitor.cs.meta | 11 +++++ 9 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 Runtime/Messages/Switch.meta create mode 100644 Runtime/Messages/Switch/SwitchMessage.cs create mode 100644 Runtime/Messages/Switch/SwitchMessage.cs.meta create mode 100644 Runtime/Messages/Switch/SwitchMessageHandler.cs create mode 100644 Runtime/Messages/Switch/SwitchMessageHandler.cs.meta create mode 100644 Runtime/Messages/Switch/SwitchMonitor.cs create mode 100644 Runtime/Messages/Switch/SwitchMonitor.cs.meta diff --git a/Runtime/BcpInterface.prefab b/Runtime/BcpInterface.prefab index 7ea92411..ea7477a7 100644 --- a/Runtime/BcpInterface.prefab +++ b/Runtime/BcpInterface.prefab @@ -26,6 +26,7 @@ GameObject: - component: {fileID: 2727910698276087158} - component: {fileID: 1282676592095372013} - component: {fileID: 6493956983709597485} + - component: {fileID: 3837697693617585428} m_Layer: 0 m_Name: MessageHandlers m_TagString: Untagged @@ -269,6 +270,19 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: bcpInterface: {fileID: 3405300645593462295} +--- !u!114 &3837697693617585428 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4502278156144720521} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6b62026304519d541a9a1381c23cbe3c, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} --- !u!1 &7214112112941309933 GameObject: m_ObjectHideFlags: 0 diff --git a/Runtime/Messages/MpfVariableMonitorBase.cs b/Runtime/Messages/MpfVariableMonitorBase.cs index 963cca84..bf6cb7cc 100644 --- a/Runtime/Messages/MpfVariableMonitorBase.cs +++ b/Runtime/Messages/MpfVariableMonitorBase.cs @@ -3,7 +3,9 @@ namespace FutureBoxSystems.MpfMediaController.Messages { - public abstract class MpfVariableMonitorBase : MonitorBase where VarType : IEquatable where MsgType : MpfVariableMessageBase + public abstract class MpfVariableMonitorBase : MonitorBase + where VarType : IEquatable + where MsgType : MpfVariableMessageBase { [SerializeField] protected string varName; diff --git a/Runtime/Messages/Switch.meta b/Runtime/Messages/Switch.meta new file mode 100644 index 00000000..a670f2cb --- /dev/null +++ b/Runtime/Messages/Switch.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 743d0b5b0d80dd2438d48a153e1873f9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Switch/SwitchMessage.cs b/Runtime/Messages/Switch/SwitchMessage.cs new file mode 100644 index 00000000..221b213e --- /dev/null +++ b/Runtime/Messages/Switch/SwitchMessage.cs @@ -0,0 +1,49 @@ +using Newtonsoft.Json.Linq; +using System; + +namespace FutureBoxSystems.MpfMediaController.Messages.Switch +{ + public class SwitchMessage : EventArgs, ISentMessage + { + public const string Command = "switch"; + private const string NameParamName = "name"; + private const string StateParamName = "state"; + + public readonly string Name; + public readonly bool IsActive; + + public SwitchMessage(string name, bool isActive) + { + Name = name; + IsActive = isActive; + } + + public static SwitchMessage FromGenericMessage(BcpMessage bcpMessage) + { + int intState = bcpMessage.GetParamValue(StateParamName); + bool boolState = intState switch + { + 0 => false, + 1 => true, + _ => throw new ParameterException(StateParamName, bcpMessage) + }; + + return new SwitchMessage( + name: bcpMessage.GetParamValue(NameParamName), + isActive: boolState + ); + } + + public BcpMessage ToGenericMessage() + { + return new BcpMessage( + command: Command, + parameters: new JObject + { + { NameParamName, Name }, + { StateParamName, IsActive ? 1 : 0 } + } + ); + } + } +} \ No newline at end of file diff --git a/Runtime/Messages/Switch/SwitchMessage.cs.meta b/Runtime/Messages/Switch/SwitchMessage.cs.meta new file mode 100644 index 00000000..0f4ed4c6 --- /dev/null +++ b/Runtime/Messages/Switch/SwitchMessage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5b3fa2eb94f200d47af3b83c2a7c3601 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Switch/SwitchMessageHandler.cs b/Runtime/Messages/Switch/SwitchMessageHandler.cs new file mode 100644 index 00000000..8e870a19 --- /dev/null +++ b/Runtime/Messages/Switch/SwitchMessageHandler.cs @@ -0,0 +1,13 @@ +using FutureBoxSystems.MpfMediaController.Messages.Monitor; + +namespace FutureBoxSystems.MpfMediaController.Messages.Switch +{ + public class SwitchMessageHandler : BcpMessageHandler + { + public override string Command => SwitchMessage.Command; + + protected override ParseDelegate Parse => SwitchMessage.FromGenericMessage; + + public override MonitoringCategory MonitoringCategory => MonitoringCategory.Switches; + } +} \ No newline at end of file diff --git a/Runtime/Messages/Switch/SwitchMessageHandler.cs.meta b/Runtime/Messages/Switch/SwitchMessageHandler.cs.meta new file mode 100644 index 00000000..cc0d8dee --- /dev/null +++ b/Runtime/Messages/Switch/SwitchMessageHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6b62026304519d541a9a1381c23cbe3c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Messages/Switch/SwitchMonitor.cs b/Runtime/Messages/Switch/SwitchMonitor.cs new file mode 100644 index 00000000..276ec2ef --- /dev/null +++ b/Runtime/Messages/Switch/SwitchMonitor.cs @@ -0,0 +1,17 @@ +using UnityEngine; + +namespace FutureBoxSystems.MpfMediaController.Messages.Switch +{ + public class SwitchMonitor : MonitorBase + { + [SerializeField] + protected string switchName; + + protected override bool MatchesMonitoringCriteria(SwitchMessage msg) + { + return base.MatchesMonitoringCriteria(msg) && msg.Name == switchName; + } + + protected override bool GetValueFromMessage(SwitchMessage msg) => msg.IsActive; + } +} \ No newline at end of file diff --git a/Runtime/Messages/Switch/SwitchMonitor.cs.meta b/Runtime/Messages/Switch/SwitchMonitor.cs.meta new file mode 100644 index 00000000..1143e551 --- /dev/null +++ b/Runtime/Messages/Switch/SwitchMonitor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6794e26fbfe8f6149be7e5382ede5e2d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 01f44136c5fb5b566864c8be1472ff745b57b0c6 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 29 Oct 2024 23:13:21 +0100 Subject: [PATCH 58/98] Rename SharedEventListener to MpfEventRequester --- Runtime/Core/BcpInterface.cs | 8 ++++---- .../Core/{SharedEventListener.cs => MpfEventRequester.cs} | 4 ++-- ...redEventListener.cs.meta => MpfEventRequester.cs.meta} | 0 3 files changed, 6 insertions(+), 6 deletions(-) rename Runtime/Core/{SharedEventListener.cs => MpfEventRequester.cs} (95%) rename Runtime/Core/{SharedEventListener.cs.meta => MpfEventRequester.cs.meta} (100%) diff --git a/Runtime/Core/BcpInterface.cs b/Runtime/Core/BcpInterface.cs index 68087d85..963c56f5 100644 --- a/Runtime/Core/BcpInterface.cs +++ b/Runtime/Core/BcpInterface.cs @@ -25,14 +25,14 @@ public class BcpInterface : MonoBehaviour public delegate void HandleMessage(BcpMessage message); private readonly Dictionary messageHandlers = new(); - private SharedEventListener monitoringCategories; - public SharedEventListener MonitoringCategories => monitoringCategories ??= new( + private MpfEventRequester monitoringCategories; + public MpfEventRequester MonitoringCategories => monitoringCategories ??= new( bcpInterface: this, createStartListeningMessage: category => new MonitorStartMessage(category), createStopListeningMessage: category => new MonitorStopMessage(category)); - private SharedEventListener mpfEvents; - public SharedEventListener MpfEvents => mpfEvents ??= new( + private MpfEventRequester mpfEvents; + public MpfEventRequester MpfEvents => mpfEvents ??= new( bcpInterface: this, createStartListeningMessage: category => new RegisterTriggerMessage(category), createStopListeningMessage: category => new RemoveTriggerMessage(category)); diff --git a/Runtime/Core/SharedEventListener.cs b/Runtime/Core/MpfEventRequester.cs similarity index 95% rename from Runtime/Core/SharedEventListener.cs rename to Runtime/Core/MpfEventRequester.cs index 09542c03..47e2760b 100644 --- a/Runtime/Core/SharedEventListener.cs +++ b/Runtime/Core/MpfEventRequester.cs @@ -3,7 +3,7 @@ namespace FutureBoxSystems.MpfMediaController { - public class SharedEventListener + public class MpfEventRequester { public delegate ISentMessage CreateMessage(EventType _event); @@ -12,7 +12,7 @@ public class SharedEventListener private readonly CreateMessage createStopListeningMessage; private readonly Dictionary> listeners = new(); - public SharedEventListener( + public MpfEventRequester( BcpInterface bcpInterface, CreateMessage createStartListeningMessage, CreateMessage createStopListeningMessage) diff --git a/Runtime/Core/SharedEventListener.cs.meta b/Runtime/Core/MpfEventRequester.cs.meta similarity index 100% rename from Runtime/Core/SharedEventListener.cs.meta rename to Runtime/Core/MpfEventRequester.cs.meta From 833d6883a4cd01e55065340a7732ce71d190a500 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu, 31 Oct 2024 10:39:27 +0100 Subject: [PATCH 59/98] Add parameters to ball start message --- Runtime/Messages/Ball/BallStartMessage.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Runtime/Messages/Ball/BallStartMessage.cs b/Runtime/Messages/Ball/BallStartMessage.cs index 2c7f46c7..a7d8e05e 100644 --- a/Runtime/Messages/Ball/BallStartMessage.cs +++ b/Runtime/Messages/Ball/BallStartMessage.cs @@ -5,6 +5,22 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Ball public class BallStartMessage : EventArgs { public const string Command = "ball_start"; - public static BallStartMessage FromGenericMessage(BcpMessage _) => new(); + public const string PlayerNumParamName = "player_num"; + public const string BallNumParamName = "ball"; + + public readonly int PlayerNum; + public readonly int BallNum; + + public BallStartMessage(int playerNum, int ballNum) + { + PlayerNum = playerNum; + BallNum = ballNum; + } + + public static BallStartMessage FromGenericMessage(BcpMessage bcpMessage) => + new BallStartMessage( + playerNum: bcpMessage.GetParamValue(PlayerNumParamName), + ballNum: bcpMessage.GetParamValue(BallNumParamName) + ); } -} \ No newline at end of file +} From 7ee7d7b477f1662e6782b87b2fce823b457884a7 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:00:11 +0100 Subject: [PATCH 60/98] Remove duplicate machine var message handler --- Runtime/BcpInterface.prefab | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Runtime/BcpInterface.prefab b/Runtime/BcpInterface.prefab index ea7477a7..95faeae7 100644 --- a/Runtime/BcpInterface.prefab +++ b/Runtime/BcpInterface.prefab @@ -25,7 +25,6 @@ GameObject: - component: {fileID: 3968882011461727216} - component: {fileID: 2727910698276087158} - component: {fileID: 1282676592095372013} - - component: {fileID: 6493956983709597485} - component: {fileID: 3837697693617585428} m_Layer: 0 m_Name: MessageHandlers @@ -257,19 +256,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: bcpInterface: {fileID: 3405300645593462295} ---- !u!114 &6493956983709597485 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 4502278156144720521} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: cdf1f7f6d8df17345ba92944c4fd5214, type: 3} - m_Name: - m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} --- !u!114 &3837697693617585428 MonoBehaviour: m_ObjectHideFlags: 0 From 0664bf9edb79bf4d91f9b038c7c1cfc41877a338 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:00:48 +0100 Subject: [PATCH 61/98] Expand monitoring functions --- Runtime/Core/BcpMessage.cs | 2 +- ...eBoxSystems.MpfUnityMediaController.asmdef | 17 +++++++- Runtime/Messages/MonitorBase.cs | 41 +++++++++++++++---- Runtime/Messages/MonitorBase.cs.meta | 2 +- .../PlayerAdded/PlayerCountMonitor.cs | 8 ++++ .../PlayerAdded/PlayerCountMonitor.cs.meta | 11 +++++ Runtime/Ui.meta | 8 ++++ Runtime/Ui/MonitoredVariableText.cs | 40 ++++++++++++++++++ Runtime/Ui/MonitoredVariableText.cs.meta | 11 +++++ package.json | 5 ++- 10 files changed, 133 insertions(+), 12 deletions(-) create mode 100644 Runtime/Messages/PlayerAdded/PlayerCountMonitor.cs create mode 100644 Runtime/Messages/PlayerAdded/PlayerCountMonitor.cs.meta create mode 100644 Runtime/Ui.meta create mode 100644 Runtime/Ui/MonitoredVariableText.cs create mode 100644 Runtime/Ui/MonitoredVariableText.cs.meta diff --git a/Runtime/Core/BcpMessage.cs b/Runtime/Core/BcpMessage.cs index 63837661..df9c7779 100644 --- a/Runtime/Core/BcpMessage.cs +++ b/Runtime/Core/BcpMessage.cs @@ -39,7 +39,7 @@ public T GetParamValue(string name) return (T)Convert.ChangeType(token, typeof(T)); } - catch (Exception e) when (e is KeyNotFoundException || e is InvalidCastException) + catch (Exception e) when (e is KeyNotFoundException || e is InvalidCastException || e is NullReferenceException) { throw new ParameterException(name, this, e); } diff --git a/Runtime/FutureBoxSystems.MpfUnityMediaController.asmdef b/Runtime/FutureBoxSystems.MpfUnityMediaController.asmdef index a14f6cf6..f48e4b57 100644 --- a/Runtime/FutureBoxSystems.MpfUnityMediaController.asmdef +++ b/Runtime/FutureBoxSystems.MpfUnityMediaController.asmdef @@ -1,3 +1,16 @@ { - "name": "FutureBoxSystems.MpfUnityMediaController" -} + "name": "FutureBoxSystems.MpfUnityMediaController", + "rootNamespace": "", + "references": [ + "Unity.TextMeshPro" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Runtime/Messages/MonitorBase.cs b/Runtime/Messages/MonitorBase.cs index 8ba47eff..2b56a576 100644 --- a/Runtime/Messages/MonitorBase.cs +++ b/Runtime/Messages/MonitorBase.cs @@ -4,7 +4,28 @@ namespace FutureBoxSystems.MpfMediaController.Messages { - public abstract class MonitorBase : MonoBehaviour where VarType : IEquatable where MsgType : EventArgs + public abstract class MonitorBase : MonoBehaviour + { + private object objVarValue; + public object ObjVarValue + { + get => objVarValue; + protected set + { + if (value == objVarValue) + return; + objVarValue = value; + ObjValueChanged?.Invoke(this, objVarValue); + } + } + + public event EventHandler ObjValueChanged; + } + + public abstract class MonitorBase + : MonitorBase + where VarType : IEquatable + where MsgType : EventArgs { [SerializeField] private BcpMessageHandler messageHandler; @@ -12,21 +33,29 @@ public abstract class MonitorBase : MonoBehaviour where VarTyp private ResetMessageHandler resetMessageHandler; public event EventHandler ValueChanged; - private VarType varValue = default; + private VarType varValue; public VarType VarValue { get => varValue; protected set { WasEverUpdated = true; - if ((value == null && VarValue == null)|| value.Equals(varValue)) + if ((value == null && VarValue == null) || value.Equals(varValue)) return; varValue = value; + ObjVarValue = value; ValueChanged?.Invoke(this, varValue); } } + public bool WasEverUpdated { get; private set; } = false; + private void Awake() + { + if (!WasEverUpdated) + ObjVarValue = VarValue; + } + protected virtual void OnEnable() { messageHandler.Received += MessageHandler_Received; @@ -49,10 +78,8 @@ private void ResetMessageHandler_Received(object sender, ResetMessage msg) protected virtual void MessageHandler_Received(object sender, MsgType msg) { - if (!MatchesMonitoringCriteria(msg)) - return; - - VarValue = GetValueFromMessage(msg); + if (MatchesMonitoringCriteria(msg)) + VarValue = GetValueFromMessage(msg); } protected virtual bool MatchesMonitoringCriteria(MsgType msg) => true; diff --git a/Runtime/Messages/MonitorBase.cs.meta b/Runtime/Messages/MonitorBase.cs.meta index f526fc38..aa737f88 100644 --- a/Runtime/Messages/MonitorBase.cs.meta +++ b/Runtime/Messages/MonitorBase.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ad4fb569779bb6d45acea2626dc07f1c +guid: 949b0f0e660406d4ba8754fce60406ae MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Messages/PlayerAdded/PlayerCountMonitor.cs b/Runtime/Messages/PlayerAdded/PlayerCountMonitor.cs new file mode 100644 index 00000000..1e4227a3 --- /dev/null +++ b/Runtime/Messages/PlayerAdded/PlayerCountMonitor.cs @@ -0,0 +1,8 @@ +namespace FutureBoxSystems.MpfMediaController.Messages.PlayerAdded +{ + public class PlayerCountMonitor : MonitorBase + { + // Assumes that player numbers are assigned consecutively starting at 1 + protected override int GetValueFromMessage(PlayerAddedMessage msg) => msg.PlayerNum; + } +} \ No newline at end of file diff --git a/Runtime/Messages/PlayerAdded/PlayerCountMonitor.cs.meta b/Runtime/Messages/PlayerAdded/PlayerCountMonitor.cs.meta new file mode 100644 index 00000000..e11085e0 --- /dev/null +++ b/Runtime/Messages/PlayerAdded/PlayerCountMonitor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: de879e6149edb6343941085d45c86852 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Ui.meta b/Runtime/Ui.meta new file mode 100644 index 00000000..2e543bff --- /dev/null +++ b/Runtime/Ui.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 51d46ccc07643924fa5e40c124286710 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Ui/MonitoredVariableText.cs b/Runtime/Ui/MonitoredVariableText.cs new file mode 100644 index 00000000..f1e2518a --- /dev/null +++ b/Runtime/Ui/MonitoredVariableText.cs @@ -0,0 +1,40 @@ +using UnityEngine; +using TMPro; +using FutureBoxSystems.MpfMediaController.Messages; + +namespace FutureBoxSystems.Ui +{ + [RequireComponent(typeof(TextMeshProUGUI))] + public class MonitoredVariableText : MonoBehaviour + { + [SerializeReference] private MonitorBase monitor; + [SerializeField] private string format = "{0}"; + + private TextMeshProUGUI _textField; + private TextMeshProUGUI TextField + { + get + { + if (_textField == null) + _textField = GetComponent(); + return _textField; + } + } + + private void OnEnable() + { + SetText(monitor.ObjVarValue); + monitor.ObjValueChanged += Monitor_ValueChanged; + } + + private void OnDisable() + { + if (monitor != null) + monitor.ObjValueChanged -= Monitor_ValueChanged; + } + + private void Monitor_ValueChanged(object sender, object value) => SetText(value); + + private void SetText(object value) => TextField.text = string.Format(format, value); + } +} \ No newline at end of file diff --git a/Runtime/Ui/MonitoredVariableText.cs.meta b/Runtime/Ui/MonitoredVariableText.cs.meta new file mode 100644 index 00000000..43ee5bbb --- /dev/null +++ b/Runtime/Ui/MonitoredVariableText.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 94c643cb901e9df428e2b9c671c24a71 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json index e7fa777b..bcb87b05 100644 --- a/package.json +++ b/package.json @@ -3,5 +3,8 @@ "version": "0.1.0", "displayName": "MPF Unity Media Controller", "description": "Communicate with MPF (Mission Pinball Framework) using the BCP (Backpox Control Protocol) to control media playback and user interfaces for a pinball machine", - "unity": "2022.3" + "unity": "2022.3", + "dependencies": { + "com.unity.textmeshpro": "3.0.9" + } } \ No newline at end of file From 28846106c424d81fdb1693e055de98c159771c42 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Wed, 29 Jan 2025 23:39:07 +0100 Subject: [PATCH 62/98] Formatting --- Runtime/Behaviours/DisconnectOnGoodbye.cs | 5 +- Runtime/Behaviours/HelloResponse.cs | 14 +++-- Runtime/Core/BcpInterface.cs | 59 +++++++++++++------ Runtime/Core/BcpMessage.cs | 22 ++++--- Runtime/Core/BcpMessageHandler.cs | 16 +++-- Runtime/Core/BcpServer.cs | 51 +++++++++++++--- Runtime/Core/Exceptions.cs | 33 +++++++++-- Runtime/Core/MpfEventRequester.cs | 21 +++++-- Runtime/Messages/Ball/BallEndMessage.cs | 3 +- .../Messages/Ball/BallEndMessageHandler.cs | 2 +- .../Messages/Ball/BallStartMessageHandler.cs | 2 +- .../Device/Autofire/AutofireDeviceMessage.cs | 5 +- .../Autofire/AutofireDeviceMessageHandler.cs | 5 +- .../Device/BallDevice/BallDeviceMessage.cs | 20 ++++++- .../BallDevice/BallDeviceMessageHandler.cs | 15 +++-- .../ComboSwitch/ComboSwitchDeviceMessage.cs | 13 ++-- .../ComboSwitchDeviceMessageHandler.cs | 10 +++- .../Messages/Device/DeviceAttributeChange.cs | 44 ++++++++++---- Runtime/Messages/Device/DeviceMessage.cs | 6 +- .../Device/DeviceMessageExceptions.cs | 42 ++++++++++--- .../Device/Flipper/FlipperDeviceMessage.cs | 5 +- .../Flipper/FlipperDeviceMessageHandler.cs | 5 +- .../Device/Light/LightDeviceMessage.cs | 9 ++- .../Device/Light/LightDeviceMessageHandler.cs | 7 ++- .../Playfield/PlayfieldDeviceMessage.cs | 12 +++- .../PlayfieldDeviceMessageHandler.cs | 15 +++-- .../Device/SpecificDeviceMessageBase.cs | 2 +- .../Device/SpecificDeviceMessageHandler.cs | 21 +++++-- .../Device/Switch/SwitchDeviceMessage.cs | 5 +- .../Switch/SwitchDeviceMessageHandler.cs | 16 +++-- Runtime/Messages/Error/ErrorMessage.cs | 11 ++-- Runtime/Messages/Error/ErrorMessageHandler.cs | 2 +- Runtime/Messages/Goodbye/GoodbyeMessage.cs | 4 +- .../Messages/Goodbye/GoodbyeMessageHandler.cs | 2 +- Runtime/Messages/Hello/HelloMessage.cs | 12 ++-- Runtime/Messages/Hello/HelloMessageHandler.cs | 2 +- .../MachineVariable/MachineVariableMessage.cs | 7 +-- .../MachineVariableMessageHandler.cs | 2 +- .../MachineVariable/MachineVariableMonitor.cs | 9 ++- .../Monitor/BoolMachineVariableMonitor.cs | 2 +- .../Monitor/FloatMachineVarableMonitor.cs | 2 +- .../Monitor/IntMachineVariableMonitor.cs | 2 +- .../Monitor/StringMachineVariableMonitor.cs | 2 +- Runtime/Messages/Mode/Mode.cs | 2 +- Runtime/Messages/Mode/ModeListMessage.cs | 14 +++-- .../Messages/Mode/ModeListMessageHandler.cs | 2 +- Runtime/Messages/Mode/ModeMonitor.cs | 3 +- Runtime/Messages/Mode/ModeStartMessage.cs | 5 +- .../Messages/Mode/ModeStartMessageHandler.cs | 2 +- Runtime/Messages/Mode/ModeStopMessage.cs | 2 +- .../Messages/Mode/ModeStopMessageHandler.cs | 2 +- .../Messages/Monitor/MonitorStartMessage.cs | 9 ++- .../Messages/Monitor/MonitorStopMessage.cs | 9 ++- .../Messages/Monitor/MonitoringCategory.cs | 11 +++- Runtime/Messages/MonitorBase.cs | 8 +-- Runtime/Messages/MpfVariableMessageBase.cs | 4 +- Runtime/Messages/MpfVariableMonitorBase.cs | 13 ++-- .../PlayerAdded/PlayerAddedMessage.cs | 2 +- .../PlayerAdded/PlayerAddedMessageHandler.cs | 2 +- .../PlayerAdded/PlayerCountMonitor.cs | 2 +- .../PlayerTurnStart/CurrentPlayerMonitor.cs | 2 +- .../PlayerTurnStart/PlayerTurnStartMessage.cs | 2 +- .../PlayerTurnStartMessageHandler.cs | 2 +- .../Monitor/BoolPlayerVariableMonitor.cs | 2 +- .../Monitor/FloatPlayerVariableMonitor.cs | 2 +- .../Monitor/IntPlayerVariableMonitor.cs | 2 +- .../Monitor/StringPlayerVariableMonitor.cs | 2 +- .../PlayerVariableMessageHandler.cs | 2 +- .../PlayerVariable/PlayerVariableMonitor.cs | 11 ++-- .../Messages/Reset/ResetCompleteMessage.cs | 4 +- Runtime/Messages/Reset/ResetMessage.cs | 4 +- Runtime/Messages/Reset/ResetMessageHandler.cs | 2 +- Runtime/Messages/Settings/SettingsMessage.cs | 4 +- .../Settings/SettingsMessageHandler.cs | 2 +- Runtime/Messages/Switch/SwitchMessage.cs | 8 +-- .../Messages/Switch/SwitchMessageHandler.cs | 2 +- Runtime/Messages/Switch/SwitchMonitor.cs | 2 +- Runtime/Messages/Trigger/MpfEventListener.cs | 4 +- .../Trigger/RegisterTriggerMessage.cs | 4 +- .../Messages/Trigger/RemoveTriggerMessage.cs | 4 +- Runtime/Messages/Trigger/TriggerMessage.cs | 9 +-- .../Messages/Trigger/TriggerMessageHandler.cs | 2 +- Runtime/Ui/MonitoredVariableText.cs | 13 ++-- Runtime/Utils/StringEnum.cs | 12 ++-- 84 files changed, 495 insertions(+), 244 deletions(-) diff --git a/Runtime/Behaviours/DisconnectOnGoodbye.cs b/Runtime/Behaviours/DisconnectOnGoodbye.cs index e25e3fbf..81b73059 100644 --- a/Runtime/Behaviours/DisconnectOnGoodbye.cs +++ b/Runtime/Behaviours/DisconnectOnGoodbye.cs @@ -1,5 +1,5 @@ -using UnityEngine; using FutureBoxSystems.MpfMediaController.Messages.Goodbye; +using UnityEngine; namespace FutureBoxSystems.MpfMediaController.Behaviours { @@ -7,6 +7,7 @@ public class DisconnectOnGoodbye : MonoBehaviour { [SerializeField] BcpInterface bcpInterface; + [SerializeField] GoodbyeMessageHandler goodbyeHandler; @@ -26,4 +27,4 @@ private void GoodbyeMessageReceived(object sender, GoodbyeMessage message) bcpInterface.RequestDisconnect(); } } -} \ No newline at end of file +} diff --git a/Runtime/Behaviours/HelloResponse.cs b/Runtime/Behaviours/HelloResponse.cs index 444a8505..c2c87b4b 100644 --- a/Runtime/Behaviours/HelloResponse.cs +++ b/Runtime/Behaviours/HelloResponse.cs @@ -1,7 +1,6 @@ -using UnityEngine; -using FutureBoxSystems.MpfMediaController.Messages.Hello; using FutureBoxSystems.MpfMediaController.Messages.Error; - +using FutureBoxSystems.MpfMediaController.Messages.Hello; +using UnityEngine; namespace FutureBoxSystems.MpfMediaController.Behaviours { @@ -9,6 +8,7 @@ public class HelloResponse : MonoBehaviour { [SerializeField] private BcpInterface bcpInterface; + [SerializeField] private HelloMessageHandler helloHandler; @@ -31,16 +31,18 @@ private void HelloMessageReceived(object sender, HelloMessage message) response = new HelloMessage( Constants.BcpSpecVersion, Constants.MediaControllerName, - Constants.MediaControllerVersion); + Constants.MediaControllerVersion + ); } else { string originalHelloMessage = message.ToGenericMessage().ToString(); response = new ErrorMessage( message: "unknown protocol version", - commandThatCausedError: originalHelloMessage); + commandThatCausedError: originalHelloMessage + ); } bcpInterface.EnqueueMessage(response); } } -} \ No newline at end of file +} diff --git a/Runtime/Core/BcpInterface.cs b/Runtime/Core/BcpInterface.cs index 963c56f5..eb4fefbb 100644 --- a/Runtime/Core/BcpInterface.cs +++ b/Runtime/Core/BcpInterface.cs @@ -1,22 +1,26 @@ using System; using System.Collections.Generic; -using UnityEngine; -using FutureBoxSystems.MpfMediaController.Messages.Monitor; using FutureBoxSystems.MpfMediaController.Messages.Error; +using FutureBoxSystems.MpfMediaController.Messages.Monitor; using FutureBoxSystems.MpfMediaController.Messages.Trigger; +using UnityEngine; namespace FutureBoxSystems.MpfMediaController { public class BcpInterface : MonoBehaviour { public ConnectionState ConnectionState => Server.ConnectionState; + [SerializeField] private int port = 5050; + [SerializeField] [Range(0.1f, 10f)] private float frameTimeBudgetMs = 3f; + [SerializeField] private bool logReceivedMessages = false; + [SerializeField] private bool logSentMessages = false; @@ -26,30 +30,42 @@ public class BcpInterface : MonoBehaviour public delegate void HandleMessage(BcpMessage message); private readonly Dictionary messageHandlers = new(); private MpfEventRequester monitoringCategories; - public MpfEventRequester MonitoringCategories => monitoringCategories ??= new( - bcpInterface: this, - createStartListeningMessage: category => new MonitorStartMessage(category), - createStopListeningMessage: category => new MonitorStopMessage(category)); + public MpfEventRequester MonitoringCategories => + monitoringCategories ??= new( + bcpInterface: this, + createStartListeningMessage: category => new MonitorStartMessage(category), + createStopListeningMessage: category => new MonitorStopMessage(category) + ); private MpfEventRequester mpfEvents; - public MpfEventRequester MpfEvents => mpfEvents ??= new( - bcpInterface: this, - createStartListeningMessage: category => new RegisterTriggerMessage(category), - createStopListeningMessage: category => new RemoveTriggerMessage(category)); - + public MpfEventRequester MpfEvents => + mpfEvents ??= new( + bcpInterface: this, + createStartListeningMessage: category => new RegisterTriggerMessage(category), + createStopListeningMessage: category => new RemoveTriggerMessage(category) + ); public void RegisterMessageHandler(string command, HandleMessage handle) { if (!messageHandlers.TryAdd(command, handle)) - Debug.LogWarning($"[BcpInterface] Cannot add message handler, because command '{command}' already has a handler."); + Debug.LogWarning( + $"[BcpInterface] Cannot add message handler, because command '{command}' " + + "already has a handler." + ); } public void UnregisterMessageHandler(string command, HandleMessage handle) { - if (messageHandlers.TryGetValue(command, out var registeredHandle) && registeredHandle == handle) + if ( + messageHandlers.TryGetValue(command, out var registeredHandle) + && registeredHandle == handle + ) messageHandlers.Remove(command); else - Debug.LogWarning($"[BcpInterface] Cannot remove message handler for command '{command}', because it is not registered."); + Debug.LogWarning( + $"[BcpInterface] Cannot remove message handler for command '{command}', " + + "because it is not registered." + ); } public void EnqueueMessage(ISentMessage message) @@ -80,7 +96,9 @@ private void Update() { float startTime = Time.unscaledTime; float timeSpentMs = 0f; - while (timeSpentMs < frameTimeBudgetMs && Server.TryDequeueReceivedMessage(out var message)) + while ( + timeSpentMs < frameTimeBudgetMs && Server.TryDequeueReceivedMessage(out var message) + ) { HandleReceivedMessage(message); timeSpentMs = (Time.unscaledTime - startTime) * 1000f; @@ -100,14 +118,19 @@ private void HandleReceivedMessage(BcpMessage message) } catch (BcpParseException e) { - Debug.LogError($"[BcpInterface] Failed to parse message. Message: {message} Exception: {e}"); + Debug.LogError( + $"[BcpInterface] Failed to parse message. Message: {message} Exception: {e}" + ); } } else { - Debug.LogError($"[BcpInterface] No parser registered for message with command '{message.Command}' Message: {message}"); + Debug.LogError( + "[BcpInterface] No parser registered for message with command " + + $"'{message.Command}' Message: {message}" + ); EnqueueMessage(new ErrorMessage("unknown command", message.ToString())); } } } -} \ No newline at end of file +} diff --git a/Runtime/Core/BcpMessage.cs b/Runtime/Core/BcpMessage.cs index df9c7779..d61b3730 100644 --- a/Runtime/Core/BcpMessage.cs +++ b/Runtime/Core/BcpMessage.cs @@ -1,9 +1,9 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace FutureBoxSystems.MpfMediaController { @@ -22,7 +22,8 @@ public BcpMessage(string command, JObject parameters, bool hasComplexParams = fa this.hasComplexParams = hasComplexParams; } - public BcpMessage(string command) : this(command, new()) { } + public BcpMessage(string command) + : this(command, new()) { } public T GetParamValue(string name) { @@ -30,7 +31,8 @@ public T GetParamValue(string name) { var token = parameters[name]; - // If string is requested, but parsed type is different, just return the unparsed JSON string + // If string is requested, but parsed type is different, just return the unparsed + // JSON string if (typeof(T) == typeof(string) && token.Type != JTokenType.String) return (T)Convert.ChangeType(token.ToString(Formatting.None), typeof(T)); @@ -39,7 +41,11 @@ public T GetParamValue(string name) return (T)Convert.ChangeType(token, typeof(T)); } - catch (Exception e) when (e is KeyNotFoundException || e is InvalidCastException || e is NullReferenceException) + catch (Exception e) + when (e is KeyNotFoundException + || e is InvalidCastException + || e is NullReferenceException + ) { throw new ParameterException(name, this, e); } @@ -103,7 +109,7 @@ private static string PropertyToParameterString(JProperty property, bool encode) string value; if (property.Value.HasValues) value = property.Value.ToString(Formatting.None); - else + else value = (string)property.Value; if (encode) { @@ -158,7 +164,7 @@ private static JProperty ParameterStringToProperty(string str) "int" => new JValue((int)Convert.ChangeType(valueStr, typeof(int))), "float" => new JValue((float)Convert.ChangeType(valueStr, typeof(float))), "NoneType" => null, - _ => new JValue(valueStr) + _ => new JValue(valueStr), }; } } @@ -175,4 +181,4 @@ public interface ISentMessage { public BcpMessage ToGenericMessage(); } -} \ No newline at end of file +} diff --git a/Runtime/Core/BcpMessageHandler.cs b/Runtime/Core/BcpMessageHandler.cs index 21459ef3..fc5ccc69 100644 --- a/Runtime/Core/BcpMessageHandler.cs +++ b/Runtime/Core/BcpMessageHandler.cs @@ -1,10 +1,11 @@ using System; -using UnityEngine; using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using UnityEngine; namespace FutureBoxSystems.MpfMediaController { - public abstract class BcpMessageHandler : MonoBehaviour where T : EventArgs + public abstract class BcpMessageHandler : MonoBehaviour + where T : EventArgs { [SerializeField] protected BcpInterface bcpInterface; @@ -26,9 +27,11 @@ public event EventHandler Received remove { CommandReceived -= value; - if (bcpInterface != null && - CommandReceived == null && - MonitoringCategory != MonitoringCategory.None) + if ( + bcpInterface != null + && CommandReceived == null + && MonitoringCategory != MonitoringCategory.None + ) { bcpInterface.MonitoringCategories.RemoveListener(this, MonitoringCategory); } @@ -57,6 +60,7 @@ private void Handle(BcpMessage message) } protected virtual void BeforeEvent() { } + protected virtual void AfterEvent() { } } -} \ No newline at end of file +} diff --git a/Runtime/Core/BcpServer.cs b/Runtime/Core/BcpServer.cs index 87f093a9..97cb4c20 100644 --- a/Runtime/Core/BcpServer.cs +++ b/Runtime/Core/BcpServer.cs @@ -20,7 +20,14 @@ public ConnectionStateChangedEventArgs(ConnectionState current, ConnectionState public ConnectionState PreviousState { get; private set; } } - public enum ConnectionState { NotConnected, Connecting, Connected, Disconnecting }; + public enum ConnectionState + { + NotConnected, + Connecting, + Connected, + Disconnecting, + }; + public class BcpServer { public event EventHandler StateChanged; @@ -59,7 +66,13 @@ private set private readonly Queue outboundMessages = new(); private readonly ManualResetEventSlim disconnectRequested = new(false); private readonly int port; - private enum ReceiveEndReason { Finished, Canceled, ClientDisconnected }; + + private enum ReceiveEndReason + { + Finished, + Canceled, + ClientDisconnected, + }; public BcpServer(int port) { @@ -81,8 +94,10 @@ public async Task OpenConnectionAsync() public async Task CloseConnectionAsync() { - if (ConnectionState == ConnectionState.Connected || - ConnectionState == ConnectionState.Connecting) + if ( + ConnectionState == ConnectionState.Connected + || ConnectionState == ConnectionState.Connecting + ) { ConnectionState = ConnectionState.Disconnecting; cts.Cancel(); @@ -137,9 +152,17 @@ private async Task CommunicateAsync(int port, CancellationToken ct) while (!ct.IsCancellationRequested && !disconnectRequested.IsSet) { var sendTask = SendMessagesAsync(stream, ct); - var endReason = await ReceiveMessagesAsync(stream, byteBuffer, stringBuffer, ct); + var endReason = await ReceiveMessagesAsync( + stream, + byteBuffer, + stringBuffer, + ct + ); await sendTask; - if (endReason == ReceiveEndReason.Canceled || endReason == ReceiveEndReason.ClientDisconnected) + if ( + endReason == ReceiveEndReason.Canceled + || endReason == ReceiveEndReason.ClientDisconnected + ) break; await Task.Delay(10); } @@ -158,7 +181,12 @@ private async Task CommunicateAsync(int port, CancellationToken ct) } } - private async Task ReceiveMessagesAsync(NetworkStream stream, byte[] byteBuffer, StringBuilder stringBuffer, CancellationToken ct) + private async Task ReceiveMessagesAsync( + NetworkStream stream, + byte[] byteBuffer, + StringBuilder stringBuffer, + CancellationToken ct + ) { while (stream.DataAvailable && !ct.IsCancellationRequested) { @@ -179,7 +207,10 @@ private async Task ReceiveMessagesAsync(NetworkStream stream, stringBuffer.Append(stringRead); const char terminator = '\n'; int messageLength; - while (!ct.IsCancellationRequested && (messageLength = stringBuffer.ToString().IndexOf(terminator)) > -1) + while ( + !ct.IsCancellationRequested + && (messageLength = stringBuffer.ToString().IndexOf(terminator)) > -1 + ) { var message = stringBuffer.ToString(0, messageLength); stringBuffer.Remove(0, messageLength + 1); @@ -200,7 +231,9 @@ private async Task ReceiveMessagesAsync(NetworkStream stream, private async Task SendMessagesAsync(NetworkStream stream, CancellationToken ct) { - while (!ct.IsCancellationRequested && TryDequeueOutboundMessage(out BcpMessage bcpMessage)) + while ( + !ct.IsCancellationRequested && TryDequeueOutboundMessage(out BcpMessage bcpMessage) + ) { var stringMessage = bcpMessage.ToString(encode: true); stringMessage += "\n"; diff --git a/Runtime/Core/Exceptions.cs b/Runtime/Core/Exceptions.cs index d3d8abf7..aad8967f 100644 --- a/Runtime/Core/Exceptions.cs +++ b/Runtime/Core/Exceptions.cs @@ -6,8 +6,16 @@ public class BcpParseException : Exception { public readonly BcpMessage Culprit; - public BcpParseException(string failReason, BcpMessage culprit = null, Exception innerException = null) - : base($"Failed to parse bcp message: '{(culprit?.ToString() ?? "Unknown")}' Reason: {(failReason ?? "None given")}", innerException) + public BcpParseException( + string failReason, + BcpMessage culprit = null, + Exception innerException = null + ) + : base( + $"Failed to parse bcp message: '{(culprit?.ToString() ?? "Unknown")}' " + + $"Reason: {(failReason ?? "None given")}", + innerException + ) { Culprit = culprit; } @@ -15,13 +23,26 @@ public BcpParseException(string failReason, BcpMessage culprit = null, Exception public class WrongParserException : BcpParseException { - public WrongParserException(BcpMessage culprit, string expectedCommand, Exception innerException = null) - : base($"Wrong parser chosen for message. Parser expected command type: '{expectedCommand}' Actual: '{culprit.Command}'", culprit, innerException) { } + public WrongParserException( + BcpMessage culprit, + string expectedCommand, + Exception innerException = null + ) + : base( + "Wrong parser chosen for message. Parser expected command type: " + + $"'{expectedCommand}' Actual: '{culprit.Command}'", + culprit, + innerException + ) { } } public class ParameterException : BcpParseException { - public ParameterException(string parameterName, BcpMessage culprit = null, Exception innerException = null) + public ParameterException( + string parameterName, + BcpMessage culprit = null, + Exception innerException = null + ) : base($"Missing or invalid parameter '{parameterName}'", culprit, innerException) { } } -} \ No newline at end of file +} diff --git a/Runtime/Core/MpfEventRequester.cs b/Runtime/Core/MpfEventRequester.cs index 47e2760b..d463ec47 100644 --- a/Runtime/Core/MpfEventRequester.cs +++ b/Runtime/Core/MpfEventRequester.cs @@ -15,7 +15,8 @@ public class MpfEventRequester public MpfEventRequester( BcpInterface bcpInterface, CreateMessage createStartListeningMessage, - CreateMessage createStopListeningMessage) + CreateMessage createStopListeningMessage + ) { this.bcpInterface = bcpInterface; this.createStartListeningMessage = createStartListeningMessage; @@ -30,19 +31,27 @@ public void AddListener(object listener, EventType _event) bcpInterface.EnqueueMessage(startListeningMsg); } else if (!listeners[_event].Add(listener)) - Debug.LogError($"[EventPool] Cannot add listener '{listener}' to event '{_event}' because it was already added."); + Debug.LogError( + $"[EventPool] Cannot add listener '{listener}' to event '{_event}' because it " + + "was already added." + ); } public void RemoveListener(object listener, EventType _event) { - if (listeners.TryGetValue(_event, out var listenersForThisEvent) && - listenersForThisEvent.Remove(listener)) + if ( + listeners.TryGetValue(_event, out var listenersForThisEvent) + && listenersForThisEvent.Remove(listener) + ) { var stopListeningMsg = createStopListeningMessage(_event); bcpInterface.EnqueueMessage(stopListeningMsg); } else - Debug.LogError($"[EventPool] Cannot remove listener '{listener}' from event '{_event}' because it is not a listener."); + Debug.LogError( + $"[EventPool] Cannot remove listener '{listener}' from event '{_event}' " + + "because it is not a listener." + ); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Ball/BallEndMessage.cs b/Runtime/Messages/Ball/BallEndMessage.cs index f0b7bf8e..91d9e7f7 100644 --- a/Runtime/Messages/Ball/BallEndMessage.cs +++ b/Runtime/Messages/Ball/BallEndMessage.cs @@ -5,6 +5,7 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Ball public class BallEndMessage : EventArgs { public const string Command = "ball_end"; + public static BallEndMessage FromGenericMessage(BcpMessage _) => new(); } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Ball/BallEndMessageHandler.cs b/Runtime/Messages/Ball/BallEndMessageHandler.cs index 8d5bf101..e1df4edf 100644 --- a/Runtime/Messages/Ball/BallEndMessageHandler.cs +++ b/Runtime/Messages/Ball/BallEndMessageHandler.cs @@ -8,4 +8,4 @@ public class BallEndMessageHandler : BcpMessageHandler protected override ParseDelegate Parse => BallEndMessage.FromGenericMessage; public override MonitoringCategory MonitoringCategory => MonitoringCategory.CoreEvents; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Ball/BallStartMessageHandler.cs b/Runtime/Messages/Ball/BallStartMessageHandler.cs index 1f5f17ec..a9f8da30 100644 --- a/Runtime/Messages/Ball/BallStartMessageHandler.cs +++ b/Runtime/Messages/Ball/BallStartMessageHandler.cs @@ -8,4 +8,4 @@ public class BallStartMessageHandler : BcpMessageHandler protected override ParseDelegate Parse => BallStartMessage.FromGenericMessage; public override MonitoringCategory MonitoringCategory => MonitoringCategory.CoreEvents; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/Autofire/AutofireDeviceMessage.cs b/Runtime/Messages/Device/Autofire/AutofireDeviceMessage.cs index 9269ad16..a08fe7db 100644 --- a/Runtime/Messages/Device/Autofire/AutofireDeviceMessage.cs +++ b/Runtime/Messages/Device/Autofire/AutofireDeviceMessage.cs @@ -4,7 +4,8 @@ public class AutofireDeviceMessage : SpecificDeviceMessageBase { public readonly bool Enabled; - public AutofireDeviceMessage(string deviceName, bool enabled) : base(deviceName) + public AutofireDeviceMessage(string deviceName, bool enabled) + : base(deviceName) { Enabled = enabled; } @@ -19,4 +20,4 @@ public class StateJson public bool enabled; } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs b/Runtime/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs index 773aa634..b3d51ea6 100644 --- a/Runtime/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs +++ b/Runtime/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs @@ -2,7 +2,8 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Device.Autofire { - public class AutofireDeviceMessageHandler : SpecificDeviceMessageHandler + public class AutofireDeviceMessageHandler + : SpecificDeviceMessageHandler { protected override string Type => "autofire"; protected override ParseStateDelegate ParseState => AutofireDeviceMessage.FromStateJson; @@ -16,4 +17,4 @@ protected override void HandleAttributeChange(DeviceAttributeChange change) throw new UnknownDeviceAttributeException(Type, change.AttributeName); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/BallDevice/BallDeviceMessage.cs b/Runtime/Messages/Device/BallDevice/BallDeviceMessage.cs index 3d45f81a..8f453e40 100644 --- a/Runtime/Messages/Device/BallDevice/BallDeviceMessage.cs +++ b/Runtime/Messages/Device/BallDevice/BallDeviceMessage.cs @@ -7,7 +7,14 @@ public class BallDeviceMessage : SpecificDeviceMessageBase public readonly string StatusAsString; public readonly int Balls; - public BallDeviceMessage(string deviceName, int availableBalls, BallDeviceStatus status, string statusAsString, int balls) : base(deviceName) + public BallDeviceMessage( + string deviceName, + int availableBalls, + BallDeviceStatus status, + string statusAsString, + int balls + ) + : base(deviceName) { AvailableBalls = availableBalls; Status = status; @@ -33,19 +40,26 @@ public enum BallDeviceStatus { [StringValue(null)] Unknown, + [StringValue("idle")] Idle, + [StringValue("waiting_for_ball")] WaitingForBall, + [StringValue("waiting_for_target_ready")] WaitingForTargetReady, + [StringValue("ejecting")] Ejecting, + [StringValue("eject_broken")] EjectBroken, + [StringValue("ball_left")] BallLeft, + [StringValue("failed_confirm")] - FailedConfirm + FailedConfirm, } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/BallDevice/BallDeviceMessageHandler.cs b/Runtime/Messages/Device/BallDevice/BallDeviceMessageHandler.cs index 48cb3747..14705497 100644 --- a/Runtime/Messages/Device/BallDevice/BallDeviceMessageHandler.cs +++ b/Runtime/Messages/Device/BallDevice/BallDeviceMessageHandler.cs @@ -2,7 +2,8 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Device.BallDevice { - public class BallDeviceMessageHandler : SpecificDeviceMessageHandler + public class BallDeviceMessageHandler + : SpecificDeviceMessageHandler { protected override string Type => "ball_device"; protected override ParseStateDelegate ParseState => BallDeviceMessage.FromStateJson; @@ -16,10 +17,16 @@ protected override void HandleAttributeChange(DeviceAttributeChange change) switch (change.AttributeName) { case nameof(BallDeviceMessage.StateJson.available_balls): - AvailableBallsChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + AvailableBallsChanged?.Invoke( + this, + change.GetEventArgsForPrimitiveTypes() + ); break; case nameof(BallDeviceMessage.StateJson.state): - StatusChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + StatusChanged?.Invoke( + this, + change.GetEventArgsForPrimitiveTypes() + ); break; case nameof(BallDeviceMessage.StateJson.balls): BallsChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); @@ -29,4 +36,4 @@ protected override void HandleAttributeChange(DeviceAttributeChange change) } } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs b/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs index 8481f226..c9554d4e 100644 --- a/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs +++ b/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs @@ -4,14 +4,17 @@ public class ComboSwitchDeviceMessage : SpecificDeviceMessageBase { public readonly ComboSwitchStatus Status; - public ComboSwitchDeviceMessage(string deviceName, ComboSwitchStatus status) : base(deviceName) + public ComboSwitchDeviceMessage(string deviceName, ComboSwitchStatus status) + : base(deviceName) { Status = status; } public static ComboSwitchDeviceMessage FromStateJson(StateJson state, string deviceName) { - ComboSwitchStatus status = StringEnum.GetValueFromString(state.state); + ComboSwitchStatus status = StringEnum.GetValueFromString( + state.state + ); return new(deviceName, status); } @@ -25,9 +28,11 @@ public enum ComboSwitchStatus { [StringValue("inactive")] Inactive, + [StringValue("both")] Both, + [StringValue("one")] - One + One, } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs b/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs index 714ecefe..5205af06 100644 --- a/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs +++ b/Runtime/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs @@ -2,7 +2,8 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Device.ComboSwitch { - public class ComboSwitchDeviceMessageHandler : SpecificDeviceMessageHandler + public class ComboSwitchDeviceMessageHandler + : SpecificDeviceMessageHandler { protected override string Type => "combo_switch"; protected override ParseStateDelegate ParseState => ComboSwitchDeviceMessage.FromStateJson; @@ -11,9 +12,12 @@ public class ComboSwitchDeviceMessageHandler : SpecificDeviceMessageHandler()); + StatusChanged?.Invoke( + this, + change.GetEventArgsForPrimitiveTypes() + ); else throw new UnknownDeviceAttributeException(Type, change.AttributeName); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/DeviceAttributeChange.cs b/Runtime/Messages/Device/DeviceAttributeChange.cs index dd93b8f4..c5a47c34 100644 --- a/Runtime/Messages/Device/DeviceAttributeChange.cs +++ b/Runtime/Messages/Device/DeviceAttributeChange.cs @@ -1,6 +1,6 @@ -using Newtonsoft.Json; -using System; +using System; using System.Runtime.InteropServices.WindowsRuntime; +using Newtonsoft.Json; using UnityEngine; namespace FutureBoxSystems.MpfMediaController.Messages.Device @@ -18,8 +18,13 @@ public DeviceAttributeChange(string attributeName, string oldValue, string newVa NewValue = newValue; } - public delegate ConversionType ConvertAttributeDelegate(string attributeValue); - public DeviceAttributeChangeEventArgs GetEventArgs(ConvertAttributeDelegate convertAttribute) + public delegate ConversionType ConvertAttributeDelegate( + string attributeValue + ); + + public DeviceAttributeChangeEventArgs GetEventArgs( + ConvertAttributeDelegate convertAttribute + ) { try { @@ -27,21 +32,31 @@ public DeviceAttributeChangeEventArgs GetEventArgs GetEventArgsForPrimitiveTypes() where T : struct + public DeviceAttributeChangeEventArgs GetEventArgsForPrimitiveTypes() + where T : struct { try { - return new((T)Convert.ChangeType(OldValue, typeof(T)), - (T)Convert.ChangeType(NewValue, typeof(T))); + return new( + (T)Convert.ChangeType(OldValue, typeof(T)), + (T)Convert.ChangeType(NewValue, typeof(T)) + ); } catch (InvalidCastException e) { @@ -49,12 +64,15 @@ public DeviceAttributeChangeEventArgs GetEventArgsForPrimitiveTypes() wher } } - public DeviceAttributeChangeEventArgs GetEventArgsForEnums() where T : Enum + public DeviceAttributeChangeEventArgs GetEventArgsForEnums() + where T : Enum { try { - return new(StringEnum.GetValueFromString(OldValue), - StringEnum.GetValueFromString(NewValue)); + return new( + StringEnum.GetValueFromString(OldValue), + StringEnum.GetValueFromString(NewValue) + ); } catch (ArgumentException e) { @@ -91,4 +109,4 @@ public DeviceAttributeChangeEventArgs(AttributeType oldValue, AttributeType newV NewValue = newValue; } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/DeviceMessage.cs b/Runtime/Messages/Device/DeviceMessage.cs index 5e550fd5..802c226c 100644 --- a/Runtime/Messages/Device/DeviceMessage.cs +++ b/Runtime/Messages/Device/DeviceMessage.cs @@ -33,7 +33,11 @@ public static DeviceMessage FromGenericMessage(BcpMessage bcpMessage) try { var arr = bcpMessage.GetParamValue("changes"); - change = new DeviceAttributeChange((string)arr[0], (string)arr[1], (string)arr[2]); + change = new DeviceAttributeChange( + (string)arr[0], + (string)arr[1], + (string)arr[2] + ); } catch (ArgumentOutOfRangeException e) { diff --git a/Runtime/Messages/Device/DeviceMessageExceptions.cs b/Runtime/Messages/Device/DeviceMessageExceptions.cs index c1f4917f..a1e7b0cd 100644 --- a/Runtime/Messages/Device/DeviceMessageExceptions.cs +++ b/Runtime/Messages/Device/DeviceMessageExceptions.cs @@ -4,19 +4,47 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Device { public class WrongDeviceAttributeTypeException : BcpParseException { - public WrongDeviceAttributeTypeException(string name, Type expectedType, string oldValue, string newValue, Exception innerException = null) - : base($"The new and old values of device attribute '{name}' (Old: '{oldValue}', New: {newValue}) could not be cast to the expected type '{expectedType}'", null, innerException) { } + public WrongDeviceAttributeTypeException( + string name, + Type expectedType, + string oldValue, + string newValue, + Exception innerException = null + ) + : base( + $"The new and old values of device attribute '{name}' (Old: '{oldValue}', " + + $"New: {newValue}) could not be cast to the expected type '{expectedType}'", + null, + innerException + ) { } } public class UnknownDeviceAttributeException : BcpParseException { - public UnknownDeviceAttributeException(string attributeName, string deviceType, Exception innerException = null) - : base($"The attribute name '{attributeName}' is not valid for device type '{deviceType}'", null, innerException) { } + public UnknownDeviceAttributeException( + string attributeName, + string deviceType, + Exception innerException = null + ) + : base( + $"The attribute name '{attributeName}' is not valid for device type '{deviceType}'", + null, + innerException + ) { } } public class InvalidDeviceStateException : BcpParseException { - public InvalidDeviceStateException(string type, Type parseFormat, Exception innerException = null) - : base($"Json key 'state' could not be parsed to the type '{parseFormat}'. The type was chosen based on the value of the 'type' key ('{type}'.)", null, innerException) { } + public InvalidDeviceStateException( + string type, + Type parseFormat, + Exception innerException = null + ) + : base( + $"Json key 'state' could not be parsed to the type '{parseFormat}'. The type was " + + $"chosen based on the value of the 'type' key ('{type}'.)", + null, + innerException + ) { } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/Flipper/FlipperDeviceMessage.cs b/Runtime/Messages/Device/Flipper/FlipperDeviceMessage.cs index 50d5aaaf..63484304 100644 --- a/Runtime/Messages/Device/Flipper/FlipperDeviceMessage.cs +++ b/Runtime/Messages/Device/Flipper/FlipperDeviceMessage.cs @@ -4,7 +4,8 @@ public class FlipperDeviceMessage : SpecificDeviceMessageBase { public readonly bool Enabled; - public FlipperDeviceMessage(string deviceName, bool enabled) : base(deviceName) + public FlipperDeviceMessage(string deviceName, bool enabled) + : base(deviceName) { Enabled = enabled; } @@ -19,4 +20,4 @@ public class StateJson public bool enabled; } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs b/Runtime/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs index 82f1a322..71f439a6 100644 --- a/Runtime/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs +++ b/Runtime/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs @@ -2,7 +2,8 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Device.Flipper { - public class FlipperDeviceMessageHandler : SpecificDeviceMessageHandler + public class FlipperDeviceMessageHandler + : SpecificDeviceMessageHandler { protected override string Type => "flipper"; protected override ParseStateDelegate ParseState => FlipperDeviceMessage.FromStateJson; @@ -16,4 +17,4 @@ protected override void HandleAttributeChange(DeviceAttributeChange change) throw new UnknownDeviceAttributeException(Type, change.AttributeName); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/Light/LightDeviceMessage.cs b/Runtime/Messages/Device/Light/LightDeviceMessage.cs index 9297d108..0985637a 100644 --- a/Runtime/Messages/Device/Light/LightDeviceMessage.cs +++ b/Runtime/Messages/Device/Light/LightDeviceMessage.cs @@ -8,14 +8,17 @@ public class LightDeviceMessage : SpecificDeviceMessageBase public const string Type = "light"; public readonly Color LightColor; - public LightDeviceMessage(string deviceName, Color lightColor) : base(deviceName) + public LightDeviceMessage(string deviceName, Color lightColor) + : base(deviceName) { LightColor = lightColor; } public static LightDeviceMessage FromStateJson(StateJson state, string deviceName) { - float r, g, b; + float r, + g, + b; try { r = state.color[0] / 255f; @@ -35,4 +38,4 @@ public class StateJson public int[] color; } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/Light/LightDeviceMessageHandler.cs b/Runtime/Messages/Device/Light/LightDeviceMessageHandler.cs index 7dba9297..1cda28ea 100644 --- a/Runtime/Messages/Device/Light/LightDeviceMessageHandler.cs +++ b/Runtime/Messages/Device/Light/LightDeviceMessageHandler.cs @@ -3,12 +3,13 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Device.Light { - public class LightDeviceMessageHandler : SpecificDeviceMessageHandler + public class LightDeviceMessageHandler + : SpecificDeviceMessageHandler { protected override string Type => LightDeviceMessage.Type; protected override ParseStateDelegate ParseState => LightDeviceMessage.FromStateJson; public event EventHandler> ColorChanged; - + protected override void HandleAttributeChange(DeviceAttributeChange change) { if (change.AttributeName == nameof(LightDeviceMessage.StateJson.color)) @@ -17,4 +18,4 @@ protected override void HandleAttributeChange(DeviceAttributeChange change) throw new UnknownDeviceAttributeException(change.AttributeName, Type); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessage.cs b/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessage.cs index bee9a899..6f598398 100644 --- a/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessage.cs +++ b/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessage.cs @@ -6,7 +6,13 @@ public class PlayfieldDeviceMessage : SpecificDeviceMessageBase public readonly int BallsRequested; public readonly int Balls; - public PlayfieldDeviceMessage(string deviceName, int availableBalls, int ballsRequested, int balls) : base(deviceName) + public PlayfieldDeviceMessage( + string deviceName, + int availableBalls, + int ballsRequested, + int balls + ) + : base(deviceName) { AvailableBalls = availableBalls; BallsRequested = ballsRequested; @@ -21,8 +27,8 @@ public static PlayfieldDeviceMessage FromStateJson(StateJson state, string devic public class StateJson { public int available_balls; - public int balls_requested; + public int balls_requested; public int balls; } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs b/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs index 54041e2f..e68cf592 100644 --- a/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs +++ b/Runtime/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs @@ -2,7 +2,8 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Device.Playfield { - public class PlayfieldDeviceMessageHandler : SpecificDeviceMessageHandler + public class PlayfieldDeviceMessageHandler + : SpecificDeviceMessageHandler { protected override string Type => "playfield"; protected override ParseStateDelegate ParseState => PlayfieldDeviceMessage.FromStateJson; @@ -16,10 +17,16 @@ protected override void HandleAttributeChange(DeviceAttributeChange change) switch (change.AttributeName) { case nameof(PlayfieldDeviceMessage.StateJson.available_balls): - AvailableBallsChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + AvailableBallsChanged?.Invoke( + this, + change.GetEventArgsForPrimitiveTypes() + ); break; case nameof(PlayfieldDeviceMessage.StateJson.balls_requested): - BallsRequestedChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + BallsRequestedChanged?.Invoke( + this, + change.GetEventArgsForPrimitiveTypes() + ); break; case nameof(PlayfieldDeviceMessage.StateJson.balls): BallsChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); @@ -29,4 +36,4 @@ protected override void HandleAttributeChange(DeviceAttributeChange change) } } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/SpecificDeviceMessageBase.cs b/Runtime/Messages/Device/SpecificDeviceMessageBase.cs index ba024ad7..68e03ce9 100644 --- a/Runtime/Messages/Device/SpecificDeviceMessageBase.cs +++ b/Runtime/Messages/Device/SpecificDeviceMessageBase.cs @@ -11,4 +11,4 @@ public SpecificDeviceMessageBase(string name) Name = name; } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs b/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs index 84b8661c..1a79647b 100644 --- a/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs +++ b/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs @@ -1,18 +1,23 @@ -using UnityEngine; -using System; +using System; using Newtonsoft.Json; +using UnityEngine; namespace FutureBoxSystems.MpfMediaController.Messages.Device { - public abstract class SpecificDeviceMessageHandler : MonoBehaviour where MessageType : SpecificDeviceMessageBase + public abstract class SpecificDeviceMessageHandler : MonoBehaviour + where MessageType : SpecificDeviceMessageBase { [SerializeField] private string deviceName; + [SerializeField] private DeviceMessageHandler generalDeviceMessageHandler; protected abstract string Type { get; } - protected delegate MessageType ParseStateDelegate(StateJsonFormat deserializedState, string deviceName); + protected delegate MessageType ParseStateDelegate( + StateJsonFormat deserializedState, + string deviceName + ); protected abstract ParseStateDelegate ParseState { get; } public event EventHandler StateUpdated; @@ -45,7 +50,11 @@ private void HandleDeviceMessageReceived(object sender, DeviceMessage deviceMess } catch (JsonException e) { - throw new InvalidDeviceStateException(deviceMessage.Type, typeof(StateJsonFormat), e); + throw new InvalidDeviceStateException( + deviceMessage.Type, + typeof(StateJsonFormat), + e + ); } MessageType specificDeviceMessage = ParseState(deserializedState, deviceMessage.Name); @@ -54,4 +63,4 @@ private void HandleDeviceMessageReceived(object sender, DeviceMessage deviceMess protected abstract void HandleAttributeChange(DeviceAttributeChange change); } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/Switch/SwitchDeviceMessage.cs b/Runtime/Messages/Device/Switch/SwitchDeviceMessage.cs index aca24649..ba529e00 100644 --- a/Runtime/Messages/Device/Switch/SwitchDeviceMessage.cs +++ b/Runtime/Messages/Device/Switch/SwitchDeviceMessage.cs @@ -5,7 +5,8 @@ public class SwitchDeviceMessage : SpecificDeviceMessageBase public readonly bool IsActive; public readonly int RecycleJitterCount; - public SwitchDeviceMessage(string deviceName, bool isActive, int recycleJitterCount) : base(deviceName) + public SwitchDeviceMessage(string deviceName, bool isActive, int recycleJitterCount) + : base(deviceName) { IsActive = isActive; RecycleJitterCount = recycleJitterCount; @@ -22,4 +23,4 @@ public class StateJson public int recycle_jitter_count; } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/Switch/SwitchDeviceMessageHandler.cs b/Runtime/Messages/Device/Switch/SwitchDeviceMessageHandler.cs index d652e848..a62b3840 100644 --- a/Runtime/Messages/Device/Switch/SwitchDeviceMessageHandler.cs +++ b/Runtime/Messages/Device/Switch/SwitchDeviceMessageHandler.cs @@ -2,7 +2,8 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Device.Switch { - public class SwitchDeviceMessageHandler : SpecificDeviceMessageHandler + public class SwitchDeviceMessageHandler + : SpecificDeviceMessageHandler { protected override string Type => "switch"; protected override ParseStateDelegate ParseState => SwitchDeviceMessage.FromStateJson; @@ -14,13 +15,18 @@ protected override void HandleAttributeChange(DeviceAttributeChange change) switch (change.AttributeName) { case nameof(SwitchDeviceMessage.StateJson.state): - change = new(change.AttributeName, + change = new( + change.AttributeName, ConvertIsActiveString(change.OldValue), - ConvertIsActiveString(change.NewValue)); + ConvertIsActiveString(change.NewValue) + ); IsActiveChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); break; case nameof(SwitchDeviceMessage.StateJson.recycle_jitter_count): - RecycleJitterCountChanged?.Invoke(this, change.GetEventArgsForPrimitiveTypes()); + RecycleJitterCountChanged?.Invoke( + this, + change.GetEventArgsForPrimitiveTypes() + ); break; default: throw new UnknownDeviceAttributeException(change.AttributeName, Type); @@ -32,4 +38,4 @@ private string ConvertIsActiveString(string isActive) return isActive == "0" ? "false" : "true"; } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Error/ErrorMessage.cs b/Runtime/Messages/Error/ErrorMessage.cs index f5ee3707..a9ed5305 100644 --- a/Runtime/Messages/Error/ErrorMessage.cs +++ b/Runtime/Messages/Error/ErrorMessage.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json.Linq; -using System; +using System; +using Newtonsoft.Json.Linq; namespace FutureBoxSystems.MpfMediaController.Messages.Error { @@ -21,9 +21,10 @@ public BcpMessage ToGenericMessage() { return new BcpMessage( command: Command, - parameters: new JObject{ + parameters: new JObject + { { messageName, Message }, - { commandThatCausedErrorName, CommandThatCausedError } + { commandThatCausedErrorName, CommandThatCausedError }, } ); } @@ -36,4 +37,4 @@ public static ErrorMessage FromGenericMessage(BcpMessage bcpMessage) ); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Error/ErrorMessageHandler.cs b/Runtime/Messages/Error/ErrorMessageHandler.cs index 1a437704..6d9736c6 100644 --- a/Runtime/Messages/Error/ErrorMessageHandler.cs +++ b/Runtime/Messages/Error/ErrorMessageHandler.cs @@ -5,4 +5,4 @@ public class ErrorMessageHandler : BcpMessageHandler public override string Command => ErrorMessage.Command; protected override ParseDelegate Parse => ErrorMessage.FromGenericMessage; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Goodbye/GoodbyeMessage.cs b/Runtime/Messages/Goodbye/GoodbyeMessage.cs index df77b727..57418b6d 100644 --- a/Runtime/Messages/Goodbye/GoodbyeMessage.cs +++ b/Runtime/Messages/Goodbye/GoodbyeMessage.cs @@ -5,7 +5,9 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Goodbye public class GoodbyeMessage : EventArgs, ISentMessage { public const string Command = "goodbye"; + public BcpMessage ToGenericMessage() => new(Command); + public static GoodbyeMessage FromGenericMessage(BcpMessage _) => new(); } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Goodbye/GoodbyeMessageHandler.cs b/Runtime/Messages/Goodbye/GoodbyeMessageHandler.cs index f3fa8fdf..a842879d 100644 --- a/Runtime/Messages/Goodbye/GoodbyeMessageHandler.cs +++ b/Runtime/Messages/Goodbye/GoodbyeMessageHandler.cs @@ -5,4 +5,4 @@ public class GoodbyeMessageHandler : BcpMessageHandler public override string Command => GoodbyeMessage.Command; protected override ParseDelegate Parse => GoodbyeMessage.FromGenericMessage; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Hello/HelloMessage.cs b/Runtime/Messages/Hello/HelloMessage.cs index f8f2a263..e0ca658c 100644 --- a/Runtime/Messages/Hello/HelloMessage.cs +++ b/Runtime/Messages/Hello/HelloMessage.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json.Linq; using System; +using Newtonsoft.Json.Linq; namespace FutureBoxSystems.MpfMediaController.Messages.Hello { @@ -24,10 +24,11 @@ public BcpMessage ToGenericMessage() { return new BcpMessage( command: Command, - parameters: new JObject{ + parameters: new JObject + { { versionName, BcpSpecVersion }, { controllerNameName, ControllerName }, - { controllerVersionName, ControllerVersion } + { controllerVersionName, ControllerVersion }, } ); } @@ -37,7 +38,8 @@ public static HelloMessage FromGenericMessage(BcpMessage bcpMessage) return new HelloMessage( version: bcpMessage.GetParamValue(versionName), controllerName: bcpMessage.GetParamValue(controllerNameName), - controllerVersion: bcpMessage.GetParamValue(controllerVersionName)); + controllerVersion: bcpMessage.GetParamValue(controllerVersionName) + ); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Hello/HelloMessageHandler.cs b/Runtime/Messages/Hello/HelloMessageHandler.cs index a16000db..d526facd 100644 --- a/Runtime/Messages/Hello/HelloMessageHandler.cs +++ b/Runtime/Messages/Hello/HelloMessageHandler.cs @@ -5,4 +5,4 @@ public class HelloMessageHandler : BcpMessageHandler public override string Command => HelloMessage.Command; protected override ParseDelegate Parse => HelloMessage.FromGenericMessage; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/MachineVariable/MachineVariableMessage.cs b/Runtime/Messages/MachineVariable/MachineVariableMessage.cs index bb7231ea..b5facdce 100644 --- a/Runtime/Messages/MachineVariable/MachineVariableMessage.cs +++ b/Runtime/Messages/MachineVariable/MachineVariableMessage.cs @@ -6,9 +6,8 @@ public class MachineVariableMessage : MpfVariableMessageBase { public const string Command = "machine_variable"; - public MachineVariableMessage(string name, JToken value) : base(name, value) - { - } + public MachineVariableMessage(string name, JToken value) + : base(name, value) { } public static MachineVariableMessage FromGenericMessage(BcpMessage bcpMessage) { @@ -18,4 +17,4 @@ public static MachineVariableMessage FromGenericMessage(BcpMessage bcpMessage) ); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs b/Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs index a785799d..0df76114 100644 --- a/Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs +++ b/Runtime/Messages/MachineVariable/MachineVariableMessageHandler.cs @@ -8,4 +8,4 @@ public class MachineVariableMessageHandler : BcpMessageHandler MachineVariableMessage.FromGenericMessage; public override MonitoringCategory MonitoringCategory => MonitoringCategory.MachineVars; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/MachineVariable/MachineVariableMonitor.cs b/Runtime/Messages/MachineVariable/MachineVariableMonitor.cs index 6ef6a117..c1a7648a 100644 --- a/Runtime/Messages/MachineVariable/MachineVariableMonitor.cs +++ b/Runtime/Messages/MachineVariable/MachineVariableMonitor.cs @@ -2,8 +2,7 @@ namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar { - public abstract class MachineVariableMonitor - : MpfVariableMonitorBase where VarType : IEquatable - { - } -} \ No newline at end of file + public abstract class MachineVariableMonitor + : MpfVariableMonitorBase + where VarType : IEquatable { } +} diff --git a/Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs b/Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs index 6d682ff8..c8a7b37b 100644 --- a/Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs +++ b/Runtime/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar { public class BoolMachineVariableMonitor : MachineVariableMonitor { } -} \ No newline at end of file +} diff --git a/Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs b/Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs index d007c795..125b26cd 100644 --- a/Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs +++ b/Runtime/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive { public class FloatMachineVarableMonitor : MachineVariableMonitor { } -} \ No newline at end of file +} diff --git a/Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs b/Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs index d8185064..258acb4e 100644 --- a/Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs +++ b/Runtime/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive { public class IntMachineVariableMonitor : MachineVariableMonitor { } -} \ No newline at end of file +} diff --git a/Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs b/Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs index f184c081..8d0f7241 100644 --- a/Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs +++ b/Runtime/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive { public class StringMachineVariableMonitor : MachineVariableMonitor { } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Mode/Mode.cs b/Runtime/Messages/Mode/Mode.cs index 26ad64ff..e7b83ed5 100644 --- a/Runtime/Messages/Mode/Mode.cs +++ b/Runtime/Messages/Mode/Mode.cs @@ -11,4 +11,4 @@ public Mode(string name, int priority) Priority = priority; } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Mode/ModeListMessage.cs b/Runtime/Messages/Mode/ModeListMessage.cs index e7f9543a..15e2ec24 100644 --- a/Runtime/Messages/Mode/ModeListMessage.cs +++ b/Runtime/Messages/Mode/ModeListMessage.cs @@ -1,7 +1,7 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using System; using System.Collections.ObjectModel; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace FutureBoxSystems.MpfMediaController.Messages.Mode { @@ -33,11 +33,15 @@ public static ModeListMessage FromGenericMessage(BcpMessage bcpMessage) } return new ModeListMessage(runningModes); - } - catch (Exception e) when (e is JsonException || e is InvalidCastException || e is IndexOutOfRangeException) + } + catch (Exception e) + when (e is JsonException + || e is InvalidCastException + || e is IndexOutOfRangeException + ) { throw new ParameterException(RunningModesParamName, null, e); } } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Mode/ModeListMessageHandler.cs b/Runtime/Messages/Mode/ModeListMessageHandler.cs index e1877672..6e2de2f5 100644 --- a/Runtime/Messages/Mode/ModeListMessageHandler.cs +++ b/Runtime/Messages/Mode/ModeListMessageHandler.cs @@ -8,4 +8,4 @@ public class ModeListMessageHandler : BcpMessageHandler protected override ParseDelegate Parse => ModeListMessage.FromGenericMessage; public override MonitoringCategory MonitoringCategory => MonitoringCategory.Modes; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Mode/ModeMonitor.cs b/Runtime/Messages/Mode/ModeMonitor.cs index 83bff18f..70400b90 100644 --- a/Runtime/Messages/Mode/ModeMonitor.cs +++ b/Runtime/Messages/Mode/ModeMonitor.cs @@ -10,6 +10,7 @@ public class ModeMonitor : MonoBehaviour [SerializeField] private ModeStartMessageHandler modeStartMessageHandler; + [SerializeField] private ModeStopMessageHandler modeStopMessageHandler; @@ -57,4 +58,4 @@ private void OnModeStopped(object sender, ModeStopMessage msg) IsModeActive = false; } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Mode/ModeStartMessage.cs b/Runtime/Messages/Mode/ModeStartMessage.cs index 5d6acc67..f7f7848c 100644 --- a/Runtime/Messages/Mode/ModeStartMessage.cs +++ b/Runtime/Messages/Mode/ModeStartMessage.cs @@ -21,7 +21,8 @@ public static ModeStartMessage FromGenericMessage(BcpMessage bcpMessage) { return new ModeStartMessage( name: bcpMessage.GetParamValue(NameParamName), - priority: bcpMessage.GetParamValue(PriorityParamName)); + priority: bcpMessage.GetParamValue(PriorityParamName) + ); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Mode/ModeStartMessageHandler.cs b/Runtime/Messages/Mode/ModeStartMessageHandler.cs index 9a826eae..5681b2a9 100644 --- a/Runtime/Messages/Mode/ModeStartMessageHandler.cs +++ b/Runtime/Messages/Mode/ModeStartMessageHandler.cs @@ -8,4 +8,4 @@ public class ModeStartMessageHandler : BcpMessageHandler protected override ParseDelegate Parse => ModeStartMessage.FromGenericMessage; public override MonitoringCategory MonitoringCategory => MonitoringCategory.Modes; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Mode/ModeStopMessage.cs b/Runtime/Messages/Mode/ModeStopMessage.cs index 6647428a..135b4585 100644 --- a/Runtime/Messages/Mode/ModeStopMessage.cs +++ b/Runtime/Messages/Mode/ModeStopMessage.cs @@ -19,4 +19,4 @@ public static ModeStopMessage FromGenericMessage(BcpMessage bcpMessage) return new ModeStopMessage(name: bcpMessage.GetParamValue(NameParamName)); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Mode/ModeStopMessageHandler.cs b/Runtime/Messages/Mode/ModeStopMessageHandler.cs index f8c762df..8aa8a4f2 100644 --- a/Runtime/Messages/Mode/ModeStopMessageHandler.cs +++ b/Runtime/Messages/Mode/ModeStopMessageHandler.cs @@ -8,4 +8,4 @@ public class ModeStopMessageHandler : BcpMessageHandler protected override ParseDelegate Parse => ModeStopMessage.FromGenericMessage; public override MonitoringCategory MonitoringCategory => MonitoringCategory.Modes; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Monitor/MonitorStartMessage.cs b/Runtime/Messages/Monitor/MonitorStartMessage.cs index 027eb41a..6df568e5 100644 --- a/Runtime/Messages/Monitor/MonitorStartMessage.cs +++ b/Runtime/Messages/Monitor/MonitorStartMessage.cs @@ -1,6 +1,6 @@ -using Newtonsoft.Json.Linq; -using System; +using System; using System.Collections.Generic; +using Newtonsoft.Json.Linq; using UnityEngine; namespace FutureBoxSystems.MpfMediaController.Messages.Monitor @@ -20,7 +20,10 @@ public BcpMessage ToGenericMessage() { var categoryString = Category.GetStringValue(); if (string.IsNullOrEmpty(categoryString)) - Debug.LogError("[MonitorStartMessage] Cannot create proper BCP message because monitoring category has no associated string value"); + Debug.LogError( + "[MonitorStartMessage] Cannot create proper BCP message because monitoring " + + "category has no associated string value." + ); return new( command: Command, parameters: new JObject { [categoryName] = categoryString } diff --git a/Runtime/Messages/Monitor/MonitorStopMessage.cs b/Runtime/Messages/Monitor/MonitorStopMessage.cs index f5d3b484..8e64cedd 100644 --- a/Runtime/Messages/Monitor/MonitorStopMessage.cs +++ b/Runtime/Messages/Monitor/MonitorStopMessage.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json.Linq; -using System; +using System; +using Newtonsoft.Json.Linq; using UnityEngine; namespace FutureBoxSystems.MpfMediaController.Messages.Monitor @@ -19,7 +19,10 @@ public BcpMessage ToGenericMessage() { var categoryString = Category.GetStringValue(); if (string.IsNullOrEmpty(categoryString)) - Debug.LogError("[MonitorStopMessage] Cannot create proper BCP message because monitoring category has no associated string value"); + Debug.LogError( + "[MonitorStopMessage] Cannot create proper BCP message because " + + "monitoring category has no associated string value." + ); return new BcpMessage( command: Command, parameters: new JObject { [categoryName] = categoryString } diff --git a/Runtime/Messages/Monitor/MonitoringCategory.cs b/Runtime/Messages/Monitor/MonitoringCategory.cs index f9609048..9cbb1869 100644 --- a/Runtime/Messages/Monitor/MonitoringCategory.cs +++ b/Runtime/Messages/Monitor/MonitoringCategory.cs @@ -4,19 +4,26 @@ public enum MonitoringCategory { [StringValue(null)] None, + [StringValue("events")] Events, + [StringValue("devices")] Devices, + [StringValue("machine_vars")] MachineVars, + [StringValue("player_vars")] PlayerVars, + [StringValue("switches")] Switches, + [StringValue("modes")] Modes, + [StringValue("core_events")] - CoreEvents + CoreEvents, } -} \ No newline at end of file +} diff --git a/Runtime/Messages/MonitorBase.cs b/Runtime/Messages/MonitorBase.cs index 2b56a576..8d5f2a46 100644 --- a/Runtime/Messages/MonitorBase.cs +++ b/Runtime/Messages/MonitorBase.cs @@ -1,5 +1,5 @@ -using FutureBoxSystems.MpfMediaController.Messages.Reset; using System; +using FutureBoxSystems.MpfMediaController.Messages.Reset; using UnityEngine; namespace FutureBoxSystems.MpfMediaController.Messages @@ -22,13 +22,13 @@ protected set public event EventHandler ObjValueChanged; } - public abstract class MonitorBase - : MonitorBase + public abstract class MonitorBase : MonitorBase where VarType : IEquatable where MsgType : EventArgs { [SerializeField] private BcpMessageHandler messageHandler; + [SerializeField] private ResetMessageHandler resetMessageHandler; @@ -86,4 +86,4 @@ protected virtual void MessageHandler_Received(object sender, MsgType msg) protected abstract VarType GetValueFromMessage(MsgType msg); } -} \ No newline at end of file +} diff --git a/Runtime/Messages/MpfVariableMessageBase.cs b/Runtime/Messages/MpfVariableMessageBase.cs index 88267565..69913f63 100644 --- a/Runtime/Messages/MpfVariableMessageBase.cs +++ b/Runtime/Messages/MpfVariableMessageBase.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json.Linq; using System; +using Newtonsoft.Json.Linq; namespace FutureBoxSystems.MpfMediaController.Messages { @@ -16,4 +16,4 @@ public MpfVariableMessageBase(string name, JToken value) Value = value; } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/MpfVariableMonitorBase.cs b/Runtime/Messages/MpfVariableMonitorBase.cs index bf6cb7cc..d8b72e9d 100644 --- a/Runtime/Messages/MpfVariableMonitorBase.cs +++ b/Runtime/Messages/MpfVariableMonitorBase.cs @@ -21,14 +21,15 @@ protected override VarType GetValueFromMessage(MsgType msg) { return (VarType)Convert.ChangeType(msg.Value, typeof(VarType)); } - catch (Exception e) when ( - e is InvalidCastException || - e is FormatException || - e is OverflowException || - e is ArgumentNullException) + catch (Exception e) + when (e is InvalidCastException + || e is FormatException + || e is OverflowException + || e is ArgumentNullException + ) { throw new ParameterException(MpfVariableMessageBase.ValueParamName, null, e); } } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/PlayerAdded/PlayerAddedMessage.cs b/Runtime/Messages/PlayerAdded/PlayerAddedMessage.cs index 071fca59..1fd1f7aa 100644 --- a/Runtime/Messages/PlayerAdded/PlayerAddedMessage.cs +++ b/Runtime/Messages/PlayerAdded/PlayerAddedMessage.cs @@ -19,4 +19,4 @@ public static PlayerAddedMessage FromGenericMessage(BcpMessage bcpMessage) return new PlayerAddedMessage(bcpMessage.GetParamValue(PlayerNumParamName)); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/PlayerAdded/PlayerAddedMessageHandler.cs b/Runtime/Messages/PlayerAdded/PlayerAddedMessageHandler.cs index ac892508..df9faf7f 100644 --- a/Runtime/Messages/PlayerAdded/PlayerAddedMessageHandler.cs +++ b/Runtime/Messages/PlayerAdded/PlayerAddedMessageHandler.cs @@ -8,4 +8,4 @@ public class PlayerAddedMessageHandler : BcpMessageHandler protected override ParseDelegate Parse => PlayerAddedMessage.FromGenericMessage; public override MonitoringCategory MonitoringCategory => MonitoringCategory.CoreEvents; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/PlayerAdded/PlayerCountMonitor.cs b/Runtime/Messages/PlayerAdded/PlayerCountMonitor.cs index 1e4227a3..9f8f1153 100644 --- a/Runtime/Messages/PlayerAdded/PlayerCountMonitor.cs +++ b/Runtime/Messages/PlayerAdded/PlayerCountMonitor.cs @@ -5,4 +5,4 @@ public class PlayerCountMonitor : MonitorBase // Assumes that player numbers are assigned consecutively starting at 1 protected override int GetValueFromMessage(PlayerAddedMessage msg) => msg.PlayerNum; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs b/Runtime/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs index f2d039c8..53a760e1 100644 --- a/Runtime/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs +++ b/Runtime/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs @@ -4,4 +4,4 @@ public class CurrentPlayerMonitor : MonitorBase { protected override int GetValueFromMessage(PlayerTurnStartMessage msg) => msg.PlayerNum; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs b/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs index 4a455e40..03bc4392 100644 --- a/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs +++ b/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs @@ -19,4 +19,4 @@ public static PlayerTurnStartMessage FromGenericMessage(BcpMessage bcpMessage) return new PlayerTurnStartMessage(bcpMessage.GetParamValue(PlayerNumParamName)); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs b/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs index 8fe081f6..8412a388 100644 --- a/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs +++ b/Runtime/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs @@ -8,4 +8,4 @@ public class PlayerTurnStartMessageHandler : BcpMessageHandler PlayerTurnStartMessage.FromGenericMessage; public override MonitoringCategory MonitoringCategory => MonitoringCategory.CoreEvents; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs b/Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs index ab8dc5c8..1c18dcc2 100644 --- a/Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs +++ b/Runtime/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable { public class BoolPlayerVariableMonitor : PlayerVariableMonitor { } -} \ No newline at end of file +} diff --git a/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs b/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs index 3208fb44..ba29e99b 100644 --- a/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs +++ b/Runtime/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable { public class FloatPlayerVariableMonitor : PlayerVariableMonitor { } -} \ No newline at end of file +} diff --git a/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs b/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs index edcbc6b8..2e0eb61b 100644 --- a/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs +++ b/Runtime/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable { public class IntPlayerVariableMonitor : PlayerVariableMonitor { } -} \ No newline at end of file +} diff --git a/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs b/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs index f5280eb5..56d12377 100644 --- a/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs +++ b/Runtime/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs @@ -1,4 +1,4 @@ namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable { public class StringPlayerVariableMonitor : PlayerVariableMonitor { } -} \ No newline at end of file +} diff --git a/Runtime/Messages/PlayerVariable/PlayerVariableMessageHandler.cs b/Runtime/Messages/PlayerVariable/PlayerVariableMessageHandler.cs index b589c840..826e6d7d 100644 --- a/Runtime/Messages/PlayerVariable/PlayerVariableMessageHandler.cs +++ b/Runtime/Messages/PlayerVariable/PlayerVariableMessageHandler.cs @@ -8,4 +8,4 @@ public class PlayerVariableMessageHandler : BcpMessageHandler PlayerVariableMessage.FromGenericMessage; public override MonitoringCategory MonitoringCategory => MonitoringCategory.PlayerVars; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/PlayerVariable/PlayerVariableMonitor.cs b/Runtime/Messages/PlayerVariable/PlayerVariableMonitor.cs index ee55b3da..b75e421c 100644 --- a/Runtime/Messages/PlayerVariable/PlayerVariableMonitor.cs +++ b/Runtime/Messages/PlayerVariable/PlayerVariableMonitor.cs @@ -1,11 +1,13 @@ -using FutureBoxSystems.MpfMediaController.Messages.PlayerTurnStart; using System; using System.Collections.Generic; +using FutureBoxSystems.MpfMediaController.Messages.PlayerTurnStart; using UnityEngine; - + namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable { - public abstract class PlayerVariableMonitor : MpfVariableMonitorBase where VarType : IEquatable + public abstract class PlayerVariableMonitor + : MpfVariableMonitorBase + where VarType : IEquatable { [SerializeField] CurrentPlayerMonitor currentPlayerMonitor; @@ -43,7 +45,8 @@ protected override void MessageHandler_Received(object sender, PlayerVariableMes protected override bool MatchesMonitoringCriteria(PlayerVariableMessage msg) { - return base.MatchesMonitoringCriteria(msg) && msg.PlayerNum == currentPlayerMonitor.VarValue; + return base.MatchesMonitoringCriteria(msg) + && msg.PlayerNum == currentPlayerMonitor.VarValue; } } } diff --git a/Runtime/Messages/Reset/ResetCompleteMessage.cs b/Runtime/Messages/Reset/ResetCompleteMessage.cs index 36c6e73d..01225da3 100644 --- a/Runtime/Messages/Reset/ResetCompleteMessage.cs +++ b/Runtime/Messages/Reset/ResetCompleteMessage.cs @@ -5,7 +5,9 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Reset public class ResetCompleteMessage : EventArgs, ISentMessage { public const string Command = "reset_complete"; + public static ResetCompleteMessage FromGenericMessage(BcpMessage _) => new(); + public BcpMessage ToGenericMessage() => new(Command); } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Reset/ResetMessage.cs b/Runtime/Messages/Reset/ResetMessage.cs index 6754a830..8fb8bb43 100644 --- a/Runtime/Messages/Reset/ResetMessage.cs +++ b/Runtime/Messages/Reset/ResetMessage.cs @@ -5,7 +5,7 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Reset public class ResetMessage : EventArgs { public const string Command = "reset"; - public static ResetMessage FromGenericMessage(BcpMessage _) => new(); + public static ResetMessage FromGenericMessage(BcpMessage _) => new(); } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Reset/ResetMessageHandler.cs b/Runtime/Messages/Reset/ResetMessageHandler.cs index ce0cd5fc..334ad969 100644 --- a/Runtime/Messages/Reset/ResetMessageHandler.cs +++ b/Runtime/Messages/Reset/ResetMessageHandler.cs @@ -11,4 +11,4 @@ protected override void AfterEvent() bcpInterface.EnqueueMessage(new ResetCompleteMessage()); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Settings/SettingsMessage.cs b/Runtime/Messages/Settings/SettingsMessage.cs index d79e4e0c..decb90c5 100644 --- a/Runtime/Messages/Settings/SettingsMessage.cs +++ b/Runtime/Messages/Settings/SettingsMessage.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json.Linq; using System; +using Newtonsoft.Json.Linq; namespace FutureBoxSystems.MpfMediaController.Messages.Settings { @@ -19,4 +19,4 @@ public static SettingsMessage FromGenericMessage(BcpMessage bcpMessage) return new SettingsMessage(bcpMessage.GetParamValue(settingsParamName)); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Settings/SettingsMessageHandler.cs b/Runtime/Messages/Settings/SettingsMessageHandler.cs index de3ee23f..0a7cb4a0 100644 --- a/Runtime/Messages/Settings/SettingsMessageHandler.cs +++ b/Runtime/Messages/Settings/SettingsMessageHandler.cs @@ -8,4 +8,4 @@ public class SettingsMessageHandler : BcpMessageHandler protected override ParseDelegate Parse => SettingsMessage.FromGenericMessage; public override MonitoringCategory MonitoringCategory => MonitoringCategory.MachineVars; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Switch/SwitchMessage.cs b/Runtime/Messages/Switch/SwitchMessage.cs index 221b213e..59599658 100644 --- a/Runtime/Messages/Switch/SwitchMessage.cs +++ b/Runtime/Messages/Switch/SwitchMessage.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json.Linq; using System; +using Newtonsoft.Json.Linq; namespace FutureBoxSystems.MpfMediaController.Messages.Switch { @@ -25,7 +25,7 @@ public static SwitchMessage FromGenericMessage(BcpMessage bcpMessage) { 0 => false, 1 => true, - _ => throw new ParameterException(StateParamName, bcpMessage) + _ => throw new ParameterException(StateParamName, bcpMessage), }; return new SwitchMessage( @@ -41,9 +41,9 @@ public BcpMessage ToGenericMessage() parameters: new JObject { { NameParamName, Name }, - { StateParamName, IsActive ? 1 : 0 } + { StateParamName, IsActive ? 1 : 0 }, } ); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Switch/SwitchMessageHandler.cs b/Runtime/Messages/Switch/SwitchMessageHandler.cs index 8e870a19..e6a98992 100644 --- a/Runtime/Messages/Switch/SwitchMessageHandler.cs +++ b/Runtime/Messages/Switch/SwitchMessageHandler.cs @@ -10,4 +10,4 @@ public class SwitchMessageHandler : BcpMessageHandler public override MonitoringCategory MonitoringCategory => MonitoringCategory.Switches; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Switch/SwitchMonitor.cs b/Runtime/Messages/Switch/SwitchMonitor.cs index 276ec2ef..624149b2 100644 --- a/Runtime/Messages/Switch/SwitchMonitor.cs +++ b/Runtime/Messages/Switch/SwitchMonitor.cs @@ -14,4 +14,4 @@ protected override bool MatchesMonitoringCriteria(SwitchMessage msg) protected override bool GetValueFromMessage(SwitchMessage msg) => msg.IsActive; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Trigger/MpfEventListener.cs b/Runtime/Messages/Trigger/MpfEventListener.cs index 58174ce1..3fb9526a 100644 --- a/Runtime/Messages/Trigger/MpfEventListener.cs +++ b/Runtime/Messages/Trigger/MpfEventListener.cs @@ -7,8 +7,10 @@ public class MpfEventListener : MonoBehaviour { [SerializeField] private string eventName; + [SerializeField] private BcpInterface bcpInterface; + [SerializeField] private TriggerMessageHandler triggerMessageHandler; @@ -34,4 +36,4 @@ private void TriggerMessageHandler_Received(object sender, TriggerMessage msg) Triggered?.Invoke(this, EventArgs.Empty); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Trigger/RegisterTriggerMessage.cs b/Runtime/Messages/Trigger/RegisterTriggerMessage.cs index b51af6d9..e918fd87 100644 --- a/Runtime/Messages/Trigger/RegisterTriggerMessage.cs +++ b/Runtime/Messages/Trigger/RegisterTriggerMessage.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json.Linq; using System; +using Newtonsoft.Json.Linq; namespace FutureBoxSystems.MpfMediaController.Messages.Trigger { @@ -23,4 +23,4 @@ public BcpMessage ToGenericMessage() ); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Trigger/RemoveTriggerMessage.cs b/Runtime/Messages/Trigger/RemoveTriggerMessage.cs index 0850eb6a..3b86693b 100644 --- a/Runtime/Messages/Trigger/RemoveTriggerMessage.cs +++ b/Runtime/Messages/Trigger/RemoveTriggerMessage.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json.Linq; using System; +using Newtonsoft.Json.Linq; namespace FutureBoxSystems.MpfMediaController.Messages.Trigger { @@ -23,4 +23,4 @@ public BcpMessage ToGenericMessage() ); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Trigger/TriggerMessage.cs b/Runtime/Messages/Trigger/TriggerMessage.cs index 78f577e3..13a29a6d 100644 --- a/Runtime/Messages/Trigger/TriggerMessage.cs +++ b/Runtime/Messages/Trigger/TriggerMessage.cs @@ -1,5 +1,5 @@ -using Newtonsoft.Json.Linq; using System; +using Newtonsoft.Json.Linq; namespace FutureBoxSystems.MpfMediaController.Messages.Trigger { @@ -24,11 +24,8 @@ public BcpMessage ToGenericMessage() { return new BcpMessage( command: Command, - parameters: new JObject - { - { NameParamName, TriggerName } - } + parameters: new JObject { { NameParamName, TriggerName } } ); } } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Trigger/TriggerMessageHandler.cs b/Runtime/Messages/Trigger/TriggerMessageHandler.cs index da4c5183..af4a956a 100644 --- a/Runtime/Messages/Trigger/TriggerMessageHandler.cs +++ b/Runtime/Messages/Trigger/TriggerMessageHandler.cs @@ -6,4 +6,4 @@ public class TriggerMessageHandler : BcpMessageHandler protected override ParseDelegate Parse => TriggerMessage.FromGenericMessage; } -} \ No newline at end of file +} diff --git a/Runtime/Ui/MonitoredVariableText.cs b/Runtime/Ui/MonitoredVariableText.cs index f1e2518a..e869c903 100644 --- a/Runtime/Ui/MonitoredVariableText.cs +++ b/Runtime/Ui/MonitoredVariableText.cs @@ -1,14 +1,17 @@ -using UnityEngine; -using TMPro; using FutureBoxSystems.MpfMediaController.Messages; +using TMPro; +using UnityEngine; namespace FutureBoxSystems.Ui { [RequireComponent(typeof(TextMeshProUGUI))] public class MonitoredVariableText : MonoBehaviour { - [SerializeReference] private MonitorBase monitor; - [SerializeField] private string format = "{0}"; + [SerializeReference] + private MonitorBase monitor; + + [SerializeField] + private string format = "{0}"; private TextMeshProUGUI _textField; private TextMeshProUGUI TextField @@ -37,4 +40,4 @@ private void OnDisable() private void SetText(object value) => TextField.text = string.Format(format, value); } -} \ No newline at end of file +} diff --git a/Runtime/Utils/StringEnum.cs b/Runtime/Utils/StringEnum.cs index 93043275..8bb766aa 100644 --- a/Runtime/Utils/StringEnum.cs +++ b/Runtime/Utils/StringEnum.cs @@ -31,7 +31,8 @@ public static string GetStringValue(this Enum value) return attribute.StringValue; } - public static T GetValueFromString(string value) where T : Enum + public static T GetValueFromString(string value) + where T : Enum { return GetValueFromStringUnsafe(value); } @@ -46,8 +47,11 @@ public static T GetValueFromStringUnsafe(string value) foreach (var field in enumType.GetFields(BindingFlags.Public | BindingFlags.Static)) { - if (Attribute.GetCustomAttribute(field, typeof(StringValueAttribute)) is StringValueAttribute attribute) - { + if ( + Attribute.GetCustomAttribute(field, typeof(StringValueAttribute)) + is StringValueAttribute attribute + ) + { if (attribute.StringValue == value) { return (T)field.GetValue(null); @@ -58,4 +62,4 @@ public static T GetValueFromStringUnsafe(string value) throw new ArgumentException($"No enum value with the string value '{value}' found."); } } -} \ No newline at end of file +} From df93c6284f9cc8ce2eddde393a8b0b5001b3a909 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Thu, 30 Jan 2025 00:19:19 +0100 Subject: [PATCH 63/98] await Task.WhenAll in server message loop --- Runtime/Core/BcpServer.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Runtime/Core/BcpServer.cs b/Runtime/Core/BcpServer.cs index 97cb4c20..79a2cce2 100644 --- a/Runtime/Core/BcpServer.cs +++ b/Runtime/Core/BcpServer.cs @@ -152,19 +152,18 @@ private async Task CommunicateAsync(int port, CancellationToken ct) while (!ct.IsCancellationRequested && !disconnectRequested.IsSet) { var sendTask = SendMessagesAsync(stream, ct); - var endReason = await ReceiveMessagesAsync( + var receiveTask = ReceiveMessagesAsync( stream, byteBuffer, stringBuffer, ct ); - await sendTask; - if ( - endReason == ReceiveEndReason.Canceled - || endReason == ReceiveEndReason.ClientDisconnected - ) + await Task.WhenAll(sendTask, receiveTask); + var endReason = await receiveTask; + if (endReason == ReceiveEndReason.Finished) + await Task.Delay(10); + else break; - await Task.Delay(10); } await SendMessagesAsync(stream, ct); disconnectRequested.Reset(); From 836e499f8dc6ed090e13e5ff6e90f785581189ce Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 16 Feb 2025 23:47:00 +0100 Subject: [PATCH 64/98] Handle MPF early shutdown because of BCP --- Runtime/MpfWrangler.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Runtime/MpfWrangler.cs b/Runtime/MpfWrangler.cs index 67a9ed89..261b92a3 100644 --- a/Runtime/MpfWrangler.cs +++ b/Runtime/MpfWrangler.cs @@ -287,11 +287,20 @@ public async Task StopMpf() var client = new MpfHardwareService.MpfHardwareServiceClient(_grpcChannel); try { - await client.QuitAsync( + await Task.Delay(100); + _ = await client.QuitAsync( new QuitRequest(), deadline: DateTime.UtcNow.AddSeconds(1) ); } + catch (RpcException ex) when (_mediaController == MpfMediaController.Other) + { + Logger.Info( + "MPF did not respond to the quit RPC. This is probably because MPF " + + "has already shut down because the BCP connection was closed." + + $"Exception: {ex}" + ); + } finally { try From 05d23c0da528fab1fc518790dbcf0f8e1214b43e Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 16 Feb 2025 23:47:29 +0100 Subject: [PATCH 65/98] Add newtonsoft.json to deps --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index bcb87b05..e623db3e 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "description": "Communicate with MPF (Mission Pinball Framework) using the BCP (Backpox Control Protocol) to control media playback and user interfaces for a pinball machine", "unity": "2022.3", "dependencies": { - "com.unity.textmeshpro": "3.0.9" + "com.unity.textmeshpro": "3.0.9", + "com.unity.nuget.newtonsoft-json": "3.2.1" } } \ No newline at end of file From 630d5282b4c2f4314afa0a7080398287a0301525 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 16 Feb 2025 23:48:05 +0100 Subject: [PATCH 66/98] Replace legacy IMGUI with UiToolkit inspector --- Editor/BcpInterfaceInspector.cs | 34 +++++++++++++++++--------- Editor/BcpInterfaceInspector.cs.meta | 4 ++- Editor/BcpInterfaceInspector.uxml | 7 ++++++ Editor/BcpInterfaceInspector.uxml.meta | 10 ++++++++ 4 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 Editor/BcpInterfaceInspector.uxml create mode 100644 Editor/BcpInterfaceInspector.uxml.meta diff --git a/Editor/BcpInterfaceInspector.cs b/Editor/BcpInterfaceInspector.cs index 52d26316..7f0ddeb2 100644 --- a/Editor/BcpInterfaceInspector.cs +++ b/Editor/BcpInterfaceInspector.cs @@ -1,29 +1,41 @@ using UnityEditor; using UnityEngine; +using UnityEngine.UIElements; namespace FutureBoxSystems.MpfMediaController { [CustomEditor(typeof(BcpInterface))] public class BcpInterfaceInspector : Editor { - private SerializedProperty portProperty; + [SerializeField] + private VisualTreeAsset bcpInterfaceInspectorXml; + + private TextField connectionStateField; private BcpInterface bcpInterface; - private void OnEnable() + public override VisualElement CreateInspectorGUI() { - portProperty = serializedObject.FindProperty("port"); + var ui = bcpInterfaceInspectorXml.Instantiate(); + connectionStateField = ui.Q("connection-state"); bcpInterface = target as BcpInterface; + UpdateConnectionStateField(bcpInterface.ConnectionState); + bcpInterface.ConnectionStateChanged += OnConnectionStateChanged; + return ui; + } + + private void OnDisable() + { + bcpInterface.ConnectionStateChanged -= OnConnectionStateChanged; + } + + private void OnConnectionStateChanged(object sender, ConnectionStateChangedEventArgs args) + { + UpdateConnectionStateField(args.CurrentState); } - public override void OnInspectorGUI() + private void UpdateConnectionStateField(ConnectionState state) { - serializedObject.Update(); - if (bcpInterface != null) - { - var connectionState = bcpInterface.ConnectionState; - EditorGUILayout.LabelField("Connection status", connectionState.ToString()); - } - base.OnInspectorGUI(); + connectionStateField.value = state.ToString(); } } } diff --git a/Editor/BcpInterfaceInspector.cs.meta b/Editor/BcpInterfaceInspector.cs.meta index c47749cb..6741b59d 100644 --- a/Editor/BcpInterfaceInspector.cs.meta +++ b/Editor/BcpInterfaceInspector.cs.meta @@ -3,7 +3,9 @@ guid: 0bea179b36a1e3c4c95091c53c60a399 MonoImporter: externalObjects: {} serializedVersion: 2 - defaultReferences: [] + defaultReferences: + - bcpInterfaceInspectorXml: {fileID: 9197481963319205126, guid: 5b6e50170ee132d418af0df03ae4b41c, + type: 3} executionOrder: 0 icon: {instanceID: 0} userData: diff --git a/Editor/BcpInterfaceInspector.uxml b/Editor/BcpInterfaceInspector.uxml new file mode 100644 index 00000000..637de568 --- /dev/null +++ b/Editor/BcpInterfaceInspector.uxml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Editor/BcpInterfaceInspector.uxml.meta b/Editor/BcpInterfaceInspector.uxml.meta new file mode 100644 index 00000000..19bec1cd --- /dev/null +++ b/Editor/BcpInterfaceInspector.uxml.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 5b6e50170ee132d418af0df03ae4b41c +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0} From a61c36e4e268fc056413522e52da66b761a74344 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 16 Feb 2025 23:48:40 +0100 Subject: [PATCH 67/98] Use readonly instead of properties in ConnectionStateEventArgs --- Runtime/Core/BcpServer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/Core/BcpServer.cs b/Runtime/Core/BcpServer.cs index 79a2cce2..6a5ef288 100644 --- a/Runtime/Core/BcpServer.cs +++ b/Runtime/Core/BcpServer.cs @@ -16,8 +16,8 @@ public ConnectionStateChangedEventArgs(ConnectionState current, ConnectionState PreviousState = previous; } - public ConnectionState CurrentState { get; private set; } - public ConnectionState PreviousState { get; private set; } + public readonly ConnectionState CurrentState; + public readonly ConnectionState PreviousState; } public enum ConnectionState From 7528d64a6c83427876f265e1f8d566a2a589806c Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 16 Feb 2025 23:49:07 +0100 Subject: [PATCH 68/98] Reduce default frame time budget for receiving --- Runtime/BcpInterface.prefab | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Runtime/BcpInterface.prefab b/Runtime/BcpInterface.prefab index 95faeae7..2740e6dc 100644 --- a/Runtime/BcpInterface.prefab +++ b/Runtime/BcpInterface.prefab @@ -316,7 +316,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: port: 5050 - frameTimeBudgetMs: 3 + frameTimeBudgetMs: 1 logReceivedMessages: 0 logSentMessages: 0 --- !u!1 &8567879373765849912 @@ -330,6 +330,7 @@ GameObject: - component: {fileID: 146168304089640666} - component: {fileID: 2143735940723918985} - component: {fileID: 6877878494961934022} + - component: {fileID: 4783129044812347161} m_Layer: 0 m_Name: Behaviours m_TagString: Untagged @@ -380,3 +381,16 @@ MonoBehaviour: m_EditorClassIdentifier: bcpInterface: {fileID: 3405300645593462295} goodbyeHandler: {fileID: 2199375185222848247} +--- !u!114 &4783129044812347161 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8567879373765849912} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 63b1e8e36b98108428c60d300b17dc3d, type: 3} + m_Name: + m_EditorClassIdentifier: + bcpInterface: {fileID: 3405300645593462295} From 1e24e15628bf190040ea9d5c8e9c621173ec996f Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 16 Feb 2025 23:50:11 +0100 Subject: [PATCH 69/98] Say goodbye on shutdown --- Runtime/Core/BcpInterface.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Runtime/Core/BcpInterface.cs b/Runtime/Core/BcpInterface.cs index eb4fefbb..ebe721f1 100644 --- a/Runtime/Core/BcpInterface.cs +++ b/Runtime/Core/BcpInterface.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using FutureBoxSystems.MpfMediaController.Messages.Error; +using FutureBoxSystems.MpfMediaController.Messages.Goodbye; using FutureBoxSystems.MpfMediaController.Messages.Monitor; using FutureBoxSystems.MpfMediaController.Messages.Trigger; using UnityEngine; @@ -10,13 +11,18 @@ namespace FutureBoxSystems.MpfMediaController public class BcpInterface : MonoBehaviour { public ConnectionState ConnectionState => Server.ConnectionState; + public event EventHandler ConnectionStateChanged + { + add { Server.StateChanged += value; } + remove { Server.StateChanged -= value; } + } [SerializeField] private int port = 5050; [SerializeField] [Range(0.1f, 10f)] - private float frameTimeBudgetMs = 3f; + private float frameTimeBudgetMs = 1f; [SerializeField] private bool logReceivedMessages = false; @@ -89,6 +95,7 @@ private async void OnEnable() private async void OnDisable() { + EnqueueMessage(new GoodbyeMessage()); await Server.CloseConnectionAsync(); } From eaa47a3cdb97ecacca66278081157e1199673350 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sun, 16 Feb 2025 23:50:36 +0100 Subject: [PATCH 70/98] Rename disconnect on goodbye behaviour --- .../{DisconnectOnGoodbye.cs => DisconnectOnGoodbyeReceived.cs} | 2 +- ...ectOnGoodbye.cs.meta => DisconnectOnGoodbyeReceived.cs.meta} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename Runtime/Behaviours/{DisconnectOnGoodbye.cs => DisconnectOnGoodbyeReceived.cs} (92%) rename Runtime/Behaviours/{DisconnectOnGoodbye.cs.meta => DisconnectOnGoodbyeReceived.cs.meta} (100%) diff --git a/Runtime/Behaviours/DisconnectOnGoodbye.cs b/Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs similarity index 92% rename from Runtime/Behaviours/DisconnectOnGoodbye.cs rename to Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs index 81b73059..48417ad8 100644 --- a/Runtime/Behaviours/DisconnectOnGoodbye.cs +++ b/Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs @@ -3,7 +3,7 @@ namespace FutureBoxSystems.MpfMediaController.Behaviours { - public class DisconnectOnGoodbye : MonoBehaviour + public class DisconnectOnGoodbyeReceived : MonoBehaviour { [SerializeField] BcpInterface bcpInterface; diff --git a/Runtime/Behaviours/DisconnectOnGoodbye.cs.meta b/Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs.meta similarity index 100% rename from Runtime/Behaviours/DisconnectOnGoodbye.cs.meta rename to Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs.meta From 9a8e961ea014b786a05acadb8a5442b57a518584 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon, 17 Feb 2025 00:09:39 +0100 Subject: [PATCH 71/98] Run bcp server on main thread --- Runtime/Core/BcpServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Core/BcpServer.cs b/Runtime/Core/BcpServer.cs index 6a5ef288..3ec2e2f1 100644 --- a/Runtime/Core/BcpServer.cs +++ b/Runtime/Core/BcpServer.cs @@ -88,7 +88,7 @@ public async Task OpenConnectionAsync() disconnectRequested.Reset(); cts = new CancellationTokenSource(); ConnectionState = ConnectionState.Connecting; - communicationTask = Task.Run(() => CommunicateAsync(port, cts.Token)); + communicationTask = CommunicateAsync(port, cts.Token); } } From 9cdede0cf472c22cc2ab209420956ef2dbb6a2b9 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Mon, 17 Feb 2025 00:12:40 +0100 Subject: [PATCH 72/98] Refactor connection state management in BcpServer --- Runtime/Core/BcpServer.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Runtime/Core/BcpServer.cs b/Runtime/Core/BcpServer.cs index 3ec2e2f1..d301cc4c 100644 --- a/Runtime/Core/BcpServer.cs +++ b/Runtime/Core/BcpServer.cs @@ -87,7 +87,6 @@ public async Task OpenConnectionAsync() { disconnectRequested.Reset(); cts = new CancellationTokenSource(); - ConnectionState = ConnectionState.Connecting; communicationTask = CommunicateAsync(port, cts.Token); } } @@ -99,12 +98,10 @@ public async Task CloseConnectionAsync() || ConnectionState == ConnectionState.Connecting ) { - ConnectionState = ConnectionState.Disconnecting; cts.Cancel(); cts.Dispose(); cts = null; await communicationTask; - ConnectionState = ConnectionState.NotConnected; } } @@ -134,13 +131,13 @@ private bool TryDequeueOutboundMessage(out BcpMessage message) private async Task CommunicateAsync(int port, CancellationToken ct) { + ConnectionState = ConnectionState.Connecting; var listener = new TcpListener(IPAddress.Any, port); try { listener.Start(); while (!ct.IsCancellationRequested) { - ConnectionState = ConnectionState.Connecting; if (listener.Pending()) { using TcpClient client = listener.AcceptTcpClient(); @@ -165,6 +162,7 @@ private async Task CommunicateAsync(int port, CancellationToken ct) else break; } + ConnectionState = ConnectionState.Disconnecting; await SendMessagesAsync(stream, ct); disconnectRequested.Reset(); } @@ -177,6 +175,7 @@ private async Task CommunicateAsync(int port, CancellationToken ct) finally { listener.Stop(); + ConnectionState = ConnectionState.NotConnected; } } From 24c6d0c698d8b97d933b8d2a575553fefe60aa50 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:49:22 +0100 Subject: [PATCH 73/98] Prefix all type parameters with T --- Runtime/Core/MpfEventRequester.cs | 10 +++++----- .../Messages/Device/DeviceAttributeChange.cs | 18 ++++++++--------- .../Device/SpecificDeviceMessageHandler.cs | 10 +++++----- .../MachineVariable/MachineVariableMonitor.cs | 6 +++--- Runtime/Messages/MonitorBase.cs | 20 +++++++++---------- Runtime/Messages/MpfVariableMonitorBase.cs | 12 +++++------ 6 files changed, 37 insertions(+), 39 deletions(-) diff --git a/Runtime/Core/MpfEventRequester.cs b/Runtime/Core/MpfEventRequester.cs index d463ec47..c106102b 100644 --- a/Runtime/Core/MpfEventRequester.cs +++ b/Runtime/Core/MpfEventRequester.cs @@ -3,14 +3,14 @@ namespace FutureBoxSystems.MpfMediaController { - public class MpfEventRequester + public class MpfEventRequester { - public delegate ISentMessage CreateMessage(EventType _event); + public delegate ISentMessage CreateMessage(TEvent _event); private readonly BcpInterface bcpInterface; private readonly CreateMessage createStartListeningMessage; private readonly CreateMessage createStopListeningMessage; - private readonly Dictionary> listeners = new(); + private readonly Dictionary> listeners = new(); public MpfEventRequester( BcpInterface bcpInterface, @@ -23,7 +23,7 @@ CreateMessage createStopListeningMessage this.createStopListeningMessage = createStopListeningMessage; } - public void AddListener(object listener, EventType _event) + public void AddListener(object listener, TEvent _event) { if (listeners.TryAdd(_event, new HashSet { listener })) { @@ -37,7 +37,7 @@ public void AddListener(object listener, EventType _event) ); } - public void RemoveListener(object listener, EventType _event) + public void RemoveListener(object listener, TEvent _event) { if ( listeners.TryGetValue(_event, out var listenersForThisEvent) diff --git a/Runtime/Messages/Device/DeviceAttributeChange.cs b/Runtime/Messages/Device/DeviceAttributeChange.cs index c5a47c34..65e2a227 100644 --- a/Runtime/Messages/Device/DeviceAttributeChange.cs +++ b/Runtime/Messages/Device/DeviceAttributeChange.cs @@ -18,12 +18,10 @@ public DeviceAttributeChange(string attributeName, string oldValue, string newVa NewValue = newValue; } - public delegate ConversionType ConvertAttributeDelegate( - string attributeValue - ); + public delegate T ConvertAttributeDelegate(string attributeValue); - public DeviceAttributeChangeEventArgs GetEventArgs( - ConvertAttributeDelegate convertAttribute + public DeviceAttributeChangeEventArgs GetEventArgs( + ConvertAttributeDelegate convertAttribute ) { try @@ -34,7 +32,7 @@ ConvertAttributeDelegate convertAttribute { throw new WrongDeviceAttributeTypeException( AttributeName, - typeof(ConversionType), + typeof(T), OldValue, NewValue, e @@ -98,12 +96,12 @@ static Color StringToColor(string s) } } - public class DeviceAttributeChangeEventArgs : EventArgs + public class DeviceAttributeChangeEventArgs : EventArgs { - public readonly AttributeType OldValue; - public readonly AttributeType NewValue; + public readonly TAttribute OldValue; + public readonly TAttribute NewValue; - public DeviceAttributeChangeEventArgs(AttributeType oldValue, AttributeType newValue) + public DeviceAttributeChangeEventArgs(TAttribute oldValue, TAttribute newValue) { OldValue = oldValue; NewValue = newValue; diff --git a/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs b/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs index 1a79647b..2679644e 100644 --- a/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs +++ b/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs @@ -4,8 +4,8 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Device { - public abstract class SpecificDeviceMessageHandler : MonoBehaviour - where MessageType : SpecificDeviceMessageBase + public abstract class SpecificDeviceMessageHandler : MonoBehaviour + where TMessage : SpecificDeviceMessageBase { [SerializeField] private string deviceName; @@ -14,12 +14,12 @@ public abstract class SpecificDeviceMessageHandler private DeviceMessageHandler generalDeviceMessageHandler; protected abstract string Type { get; } - protected delegate MessageType ParseStateDelegate( + protected delegate TMessage ParseStateDelegate( StateJsonFormat deserializedState, string deviceName ); protected abstract ParseStateDelegate ParseState { get; } - public event EventHandler StateUpdated; + public event EventHandler StateUpdated; protected void OnEnable() { @@ -57,7 +57,7 @@ private void HandleDeviceMessageReceived(object sender, DeviceMessage deviceMess ); } - MessageType specificDeviceMessage = ParseState(deserializedState, deviceMessage.Name); + TMessage specificDeviceMessage = ParseState(deserializedState, deviceMessage.Name); StateUpdated?.Invoke(this, specificDeviceMessage); } diff --git a/Runtime/Messages/MachineVariable/MachineVariableMonitor.cs b/Runtime/Messages/MachineVariable/MachineVariableMonitor.cs index c1a7648a..43e57e50 100644 --- a/Runtime/Messages/MachineVariable/MachineVariableMonitor.cs +++ b/Runtime/Messages/MachineVariable/MachineVariableMonitor.cs @@ -2,7 +2,7 @@ namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar { - public abstract class MachineVariableMonitor - : MpfVariableMonitorBase - where VarType : IEquatable { } + public abstract class MachineVariableMonitor + : MpfVariableMonitorBase + where TVar : IEquatable { } } diff --git a/Runtime/Messages/MonitorBase.cs b/Runtime/Messages/MonitorBase.cs index 8d5f2a46..05a0bd9b 100644 --- a/Runtime/Messages/MonitorBase.cs +++ b/Runtime/Messages/MonitorBase.cs @@ -22,19 +22,19 @@ protected set public event EventHandler ObjValueChanged; } - public abstract class MonitorBase : MonitorBase - where VarType : IEquatable - where MsgType : EventArgs + public abstract class MonitorBase : MonitorBase + where TVar : IEquatable + where TMessage : EventArgs { [SerializeField] - private BcpMessageHandler messageHandler; + private BcpMessageHandler messageHandler; [SerializeField] private ResetMessageHandler resetMessageHandler; - public event EventHandler ValueChanged; - private VarType varValue; - public VarType VarValue + public event EventHandler ValueChanged; + private TVar varValue; + public TVar VarValue { get => varValue; protected set @@ -76,14 +76,14 @@ private void ResetMessageHandler_Received(object sender, ResetMessage msg) WasEverUpdated = false; } - protected virtual void MessageHandler_Received(object sender, MsgType msg) + protected virtual void MessageHandler_Received(object sender, TMessage msg) { if (MatchesMonitoringCriteria(msg)) VarValue = GetValueFromMessage(msg); } - protected virtual bool MatchesMonitoringCriteria(MsgType msg) => true; + protected virtual bool MatchesMonitoringCriteria(TMessage msg) => true; - protected abstract VarType GetValueFromMessage(MsgType msg); + protected abstract TVar GetValueFromMessage(TMessage msg); } } diff --git a/Runtime/Messages/MpfVariableMonitorBase.cs b/Runtime/Messages/MpfVariableMonitorBase.cs index d8b72e9d..39343fac 100644 --- a/Runtime/Messages/MpfVariableMonitorBase.cs +++ b/Runtime/Messages/MpfVariableMonitorBase.cs @@ -3,23 +3,23 @@ namespace FutureBoxSystems.MpfMediaController.Messages { - public abstract class MpfVariableMonitorBase : MonitorBase - where VarType : IEquatable - where MsgType : MpfVariableMessageBase + public abstract class MpfVariableMonitorBase : MonitorBase + where TVar : IEquatable + where TMessage : MpfVariableMessageBase { [SerializeField] protected string varName; - protected override bool MatchesMonitoringCriteria(MsgType msg) + protected override bool MatchesMonitoringCriteria(TMessage msg) { return base.MatchesMonitoringCriteria(msg) && msg.Name == varName; } - protected override VarType GetValueFromMessage(MsgType msg) + protected override TVar GetValueFromMessage(TMessage msg) { try { - return (VarType)Convert.ChangeType(msg.Value, typeof(VarType)); + return (TVar)Convert.ChangeType(msg.Value, typeof(TVar)); } catch (Exception e) when (e is InvalidCastException From 5f2e950b450ea2b6ba2f0d772e4b373720792b28 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 18 Feb 2025 12:07:16 +0100 Subject: [PATCH 74/98] Format code --- Runtime/Core/Constants.cs | 2 +- Runtime/Messages/Device/DeviceMessageHandler.cs | 2 +- Runtime/Messages/PlayerVariable/PlayerVariableMessage.cs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Runtime/Core/Constants.cs b/Runtime/Core/Constants.cs index ecaa88a4..50972832 100644 --- a/Runtime/Core/Constants.cs +++ b/Runtime/Core/Constants.cs @@ -6,4 +6,4 @@ public static class Constants public const string MediaControllerVersion = "0.1.0"; public const string BcpSpecVersion = "1.1"; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/Device/DeviceMessageHandler.cs b/Runtime/Messages/Device/DeviceMessageHandler.cs index 20ba2bac..094dc8be 100644 --- a/Runtime/Messages/Device/DeviceMessageHandler.cs +++ b/Runtime/Messages/Device/DeviceMessageHandler.cs @@ -8,4 +8,4 @@ public class DeviceMessageHandler : BcpMessageHandler protected override ParseDelegate Parse => DeviceMessage.FromGenericMessage; public override MonitoringCategory MonitoringCategory => MonitoringCategory.Devices; } -} \ No newline at end of file +} diff --git a/Runtime/Messages/PlayerVariable/PlayerVariableMessage.cs b/Runtime/Messages/PlayerVariable/PlayerVariableMessage.cs index 51c57865..45901a34 100644 --- a/Runtime/Messages/PlayerVariable/PlayerVariableMessage.cs +++ b/Runtime/Messages/PlayerVariable/PlayerVariableMessage.cs @@ -9,7 +9,8 @@ public class PlayerVariableMessage : MpfVariableMessageBase public const string PlayerNumParamName = "player_num"; public readonly int PlayerNum; - public PlayerVariableMessage(string name, int playerNum, JToken value) : base(name, value) + public PlayerVariableMessage(string name, int playerNum, JToken value) + : base(name, value) { PlayerNum = playerNum; } From 4d24f748cf16d9621c106de8b7cce399ad6b08d2 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 18 Feb 2025 12:22:23 +0100 Subject: [PATCH 75/98] Rename _event parameter to @event --- Runtime/Core/MpfEventRequester.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Runtime/Core/MpfEventRequester.cs b/Runtime/Core/MpfEventRequester.cs index c106102b..4593cfdf 100644 --- a/Runtime/Core/MpfEventRequester.cs +++ b/Runtime/Core/MpfEventRequester.cs @@ -5,7 +5,7 @@ namespace FutureBoxSystems.MpfMediaController { public class MpfEventRequester { - public delegate ISentMessage CreateMessage(TEvent _event); + public delegate ISentMessage CreateMessage(TEvent @event); private readonly BcpInterface bcpInterface; private readonly CreateMessage createStartListeningMessage; @@ -23,33 +23,33 @@ CreateMessage createStopListeningMessage this.createStopListeningMessage = createStopListeningMessage; } - public void AddListener(object listener, TEvent _event) + public void AddListener(object listener, TEvent @event) { - if (listeners.TryAdd(_event, new HashSet { listener })) + if (listeners.TryAdd(@event, new HashSet { listener })) { - var startListeningMsg = createStartListeningMessage(_event); + var startListeningMsg = createStartListeningMessage(@event); bcpInterface.EnqueueMessage(startListeningMsg); } - else if (!listeners[_event].Add(listener)) + else if (!listeners[@event].Add(listener)) Debug.LogError( - $"[EventPool] Cannot add listener '{listener}' to event '{_event}' because it " + $"[EventPool] Cannot add listener '{listener}' to event '{@event}' because it " + "was already added." ); } - public void RemoveListener(object listener, TEvent _event) + public void RemoveListener(object listener, TEvent @event) { if ( - listeners.TryGetValue(_event, out var listenersForThisEvent) + listeners.TryGetValue(@event, out var listenersForThisEvent) && listenersForThisEvent.Remove(listener) ) { - var stopListeningMsg = createStopListeningMessage(_event); + var stopListeningMsg = createStopListeningMessage(@event); bcpInterface.EnqueueMessage(stopListeningMsg); } else Debug.LogError( - $"[EventPool] Cannot remove listener '{listener}' from event '{_event}' " + $"[EventPool] Cannot remove listener '{listener}' from event '{@event}' " + "because it is not a listener." ); } From d49e7e300f048104291f5b346d2affd69b09aa7f Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 18 Feb 2025 12:34:06 +0100 Subject: [PATCH 76/98] Do not prematurely send stop listening messages --- Runtime/Core/MpfEventRequester.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Runtime/Core/MpfEventRequester.cs b/Runtime/Core/MpfEventRequester.cs index 4593cfdf..afcfdc7b 100644 --- a/Runtime/Core/MpfEventRequester.cs +++ b/Runtime/Core/MpfEventRequester.cs @@ -44,8 +44,12 @@ public void RemoveListener(object listener, TEvent @event) && listenersForThisEvent.Remove(listener) ) { - var stopListeningMsg = createStopListeningMessage(@event); - bcpInterface.EnqueueMessage(stopListeningMsg); + if (listenersForThisEvent.Count == 0) + { + listeners.Remove(@event); + var stopListeningMsg = createStopListeningMessage(@event); + bcpInterface.EnqueueMessage(stopListeningMsg); + } } else Debug.LogError( From 64b4e6d1f2c3b585515b3fef4463bdc1dd77ffbb Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:15:32 +0100 Subject: [PATCH 77/98] Do not use null propagation for Unity objects --- Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs | 2 +- Runtime/Behaviours/HelloResponse.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs b/Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs index 48417ad8..3f73f2d3 100644 --- a/Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs +++ b/Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs @@ -18,7 +18,7 @@ private void OnEnable() private void OnDisable() { - if (goodbyeHandler) + if (goodbyeHandler != null) goodbyeHandler.Received -= GoodbyeMessageReceived; } diff --git a/Runtime/Behaviours/HelloResponse.cs b/Runtime/Behaviours/HelloResponse.cs index c2c87b4b..965b8b16 100644 --- a/Runtime/Behaviours/HelloResponse.cs +++ b/Runtime/Behaviours/HelloResponse.cs @@ -19,7 +19,7 @@ private void OnEnable() private void OnDisable() { - if (helloHandler) + if (helloHandler != null) helloHandler.Received -= HelloMessageReceived; } From 4607e421b482a1278b351ba69320ed5e546d0acc Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 18 Feb 2025 14:32:27 +0100 Subject: [PATCH 78/98] Specify message terminator only once --- Runtime/Core/BcpServer.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Runtime/Core/BcpServer.cs b/Runtime/Core/BcpServer.cs index d301cc4c..c0798791 100644 --- a/Runtime/Core/BcpServer.cs +++ b/Runtime/Core/BcpServer.cs @@ -67,6 +67,8 @@ private set private readonly ManualResetEventSlim disconnectRequested = new(false); private readonly int port; + private const char terminator = '\n'; + private enum ReceiveEndReason { Finished, @@ -203,7 +205,6 @@ CancellationToken ct var stringRead = Encoding.UTF8.GetString(byteBuffer, 0, numBytesRead); stringBuffer.Append(stringRead); - const char terminator = '\n'; int messageLength; while ( !ct.IsCancellationRequested @@ -234,7 +235,7 @@ private async Task SendMessagesAsync(NetworkStream stream, CancellationToken ct) ) { var stringMessage = bcpMessage.ToString(encode: true); - stringMessage += "\n"; + stringMessage += terminator; var packet = Encoding.UTF8.GetBytes(stringMessage); try { From 825171372017ea988e68dacbc757c07fd3448410 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 18 Feb 2025 20:24:54 +0100 Subject: [PATCH 79/98] Add _ prefix to private and protected fields --- Editor/BcpInterfaceInspector.cs | 20 ++--- Editor/BcpInterfaceInspector.cs.meta | 2 +- Editor/BcpInterfaceInspector.uxml | 8 +- Runtime/BcpInterface.prefab | 64 +++++++--------- .../Behaviours/DisconnectOnGoodbyeReceived.cs | 12 +-- Runtime/Behaviours/HelloResponse.cs | 12 +-- Runtime/Core/BcpInterface.cs | 37 +++++----- Runtime/Core/BcpMessage.cs | 32 ++++---- Runtime/Core/BcpMessageHandler.cs | 26 +++---- Runtime/Core/BcpServer.cs | 74 +++++++++---------- Runtime/Core/MpfEventRequester.cs | 30 ++++---- .../Device/SpecificDeviceMessageHandler.cs | 12 +-- Runtime/Messages/Error/ErrorMessage.cs | 12 +-- Runtime/Messages/Hello/HelloMessage.cs | 19 ++--- Runtime/Messages/Mode/ModeListMessage.cs | 6 +- Runtime/Messages/Mode/ModeMonitor.cs | 28 +++---- .../Messages/Monitor/MonitorStartMessage.cs | 4 +- .../Messages/Monitor/MonitorStopMessage.cs | 4 +- Runtime/Messages/MonitorBase.cs | 36 ++++----- Runtime/Messages/MpfVariableMonitorBase.cs | 4 +- .../PlayerVariable/PlayerVariableMonitor.cs | 18 ++--- Runtime/Messages/Reset/ResetMessageHandler.cs | 2 +- Runtime/Messages/Switch/SwitchMonitor.cs | 4 +- Runtime/Messages/Trigger/MpfEventListener.cs | 20 ++--- .../Messages/Trigger/RemoveTriggerMessage.cs | 4 +- Runtime/Ui/MonitoredVariableText.cs | 14 ++-- 26 files changed, 246 insertions(+), 258 deletions(-) diff --git a/Editor/BcpInterfaceInspector.cs b/Editor/BcpInterfaceInspector.cs index 7f0ddeb2..ed26cea6 100644 --- a/Editor/BcpInterfaceInspector.cs +++ b/Editor/BcpInterfaceInspector.cs @@ -8,24 +8,24 @@ namespace FutureBoxSystems.MpfMediaController public class BcpInterfaceInspector : Editor { [SerializeField] - private VisualTreeAsset bcpInterfaceInspectorXml; + private VisualTreeAsset _bcpInterfaceInspectorXml; - private TextField connectionStateField; - private BcpInterface bcpInterface; + private TextField _connectionStateField; + private BcpInterface _bcpInterface; public override VisualElement CreateInspectorGUI() { - var ui = bcpInterfaceInspectorXml.Instantiate(); - connectionStateField = ui.Q("connection-state"); - bcpInterface = target as BcpInterface; - UpdateConnectionStateField(bcpInterface.ConnectionState); - bcpInterface.ConnectionStateChanged += OnConnectionStateChanged; + var ui = _bcpInterfaceInspectorXml.Instantiate(); + _connectionStateField = ui.Q("connection-state"); + _bcpInterface = target as BcpInterface; + UpdateConnectionStateField(_bcpInterface.ConnectionState); + _bcpInterface.ConnectionStateChanged += OnConnectionStateChanged; return ui; } private void OnDisable() { - bcpInterface.ConnectionStateChanged -= OnConnectionStateChanged; + _bcpInterface.ConnectionStateChanged -= OnConnectionStateChanged; } private void OnConnectionStateChanged(object sender, ConnectionStateChangedEventArgs args) @@ -35,7 +35,7 @@ private void OnConnectionStateChanged(object sender, ConnectionStateChangedEvent private void UpdateConnectionStateField(ConnectionState state) { - connectionStateField.value = state.ToString(); + _connectionStateField.value = state.ToString(); } } } diff --git a/Editor/BcpInterfaceInspector.cs.meta b/Editor/BcpInterfaceInspector.cs.meta index 6741b59d..3566e7e0 100644 --- a/Editor/BcpInterfaceInspector.cs.meta +++ b/Editor/BcpInterfaceInspector.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: - - bcpInterfaceInspectorXml: {fileID: 9197481963319205126, guid: 5b6e50170ee132d418af0df03ae4b41c, + - _bcpInterfaceInspectorXml: {fileID: 9197481963319205126, guid: 5b6e50170ee132d418af0df03ae4b41c, type: 3} executionOrder: 0 icon: {instanceID: 0} diff --git a/Editor/BcpInterfaceInspector.uxml b/Editor/BcpInterfaceInspector.uxml index 637de568..968ae69d 100644 --- a/Editor/BcpInterfaceInspector.uxml +++ b/Editor/BcpInterfaceInspector.uxml @@ -1,7 +1,7 @@ - - - - + + + + diff --git a/Runtime/BcpInterface.prefab b/Runtime/BcpInterface.prefab index 2740e6dc..7559a7df 100644 --- a/Runtime/BcpInterface.prefab +++ b/Runtime/BcpInterface.prefab @@ -60,7 +60,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: bf919a90a2e4ed040b8913ce8901228b, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &2199375185222848247 MonoBehaviour: m_ObjectHideFlags: 0 @@ -73,7 +73,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 6f9bc1ba9f51a604db49e1a6e7f59a86, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &615776641453573451 MonoBehaviour: m_ObjectHideFlags: 0 @@ -86,7 +86,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7fd1ee0333546544b9c3dea71e6c20a7, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &1824319182504738973 MonoBehaviour: m_ObjectHideFlags: 0 @@ -99,7 +99,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 359cce4f412e2f24cad70a4f570fac5e, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &3006042140711521680 MonoBehaviour: m_ObjectHideFlags: 0 @@ -112,7 +112,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 63f2dd8dbb07c27498726c42cff3d4e7, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &4146686170121310886 MonoBehaviour: m_ObjectHideFlags: 0 @@ -125,7 +125,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 587867a0f90cc0947a58c70dd2a7eff6, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &7019407901035039939 MonoBehaviour: m_ObjectHideFlags: 0 @@ -138,7 +138,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 88948b8ed19a20e40a42d16e46c70610, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &642617651384461981 MonoBehaviour: m_ObjectHideFlags: 0 @@ -151,7 +151,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: cdf1f7f6d8df17345ba92944c4fd5214, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &4203975233253439991 MonoBehaviour: m_ObjectHideFlags: 0 @@ -164,7 +164,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b65129ea85086ae47af878a4f30e9e69, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &3090677156515762911 MonoBehaviour: m_ObjectHideFlags: 0 @@ -177,7 +177,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 11f6680fde0db0b47a34525af2715218, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &7662757724108484360 MonoBehaviour: m_ObjectHideFlags: 0 @@ -190,7 +190,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2f12a6315c31b7e4a89904664714c88d, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &7963542148954742278 MonoBehaviour: m_ObjectHideFlags: 0 @@ -203,7 +203,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 35edded1d3e1dbf43abd87fd5af57e9c, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &491971619498350422 MonoBehaviour: m_ObjectHideFlags: 0 @@ -216,7 +216,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: dab47b28efdc1874687cf7a107bab2c5, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &3968882011461727216 MonoBehaviour: m_ObjectHideFlags: 0 @@ -229,7 +229,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ed407e67f76aac446b42c742d66192d9, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &2727910698276087158 MonoBehaviour: m_ObjectHideFlags: 0 @@ -242,7 +242,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5e17d18c78dff5746ae1c03a10b14cb9, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &1282676592095372013 MonoBehaviour: m_ObjectHideFlags: 0 @@ -255,7 +255,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5f766cbe8cf3bc84f9686435c4834e79, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!114 &3837697693617585428 MonoBehaviour: m_ObjectHideFlags: 0 @@ -268,7 +268,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 6b62026304519d541a9a1381c23cbe3c, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} --- !u!1 &7214112112941309933 GameObject: m_ObjectHideFlags: 0 @@ -315,10 +315,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 51b9336ad819de34399a83bd1df10416, type: 3} m_Name: m_EditorClassIdentifier: - port: 5050 - frameTimeBudgetMs: 1 - logReceivedMessages: 0 - logSentMessages: 0 + _port: 5050 + _frameTimeBudgetMs: 1 + _logReceivedMessages: 0 + _logSentMessages: 0 --- !u!1 &8567879373765849912 GameObject: m_ObjectHideFlags: 0 @@ -330,7 +330,6 @@ GameObject: - component: {fileID: 146168304089640666} - component: {fileID: 2143735940723918985} - component: {fileID: 6877878494961934022} - - component: {fileID: 4783129044812347161} m_Layer: 0 m_Name: Behaviours m_TagString: Untagged @@ -365,8 +364,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d38f5f799b1bc354c9f85833a5c6c3ba, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} - helloHandler: {fileID: 8178360348569921075} + _bcpInterface: {fileID: 3405300645593462295} + _helloHandler: {fileID: 8178360348569921075} --- !u!114 &6877878494961934022 MonoBehaviour: m_ObjectHideFlags: 0 @@ -379,18 +378,5 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: cf6e722a91a3eed43b7d8f5cf8f929ac, type: 3} m_Name: m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} - goodbyeHandler: {fileID: 2199375185222848247} ---- !u!114 &4783129044812347161 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8567879373765849912} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 63b1e8e36b98108428c60d300b17dc3d, type: 3} - m_Name: - m_EditorClassIdentifier: - bcpInterface: {fileID: 3405300645593462295} + _bcpInterface: {fileID: 3405300645593462295} + _goodbyeHandler: {fileID: 2199375185222848247} diff --git a/Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs b/Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs index 3f73f2d3..e514c59e 100644 --- a/Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs +++ b/Runtime/Behaviours/DisconnectOnGoodbyeReceived.cs @@ -6,25 +6,25 @@ namespace FutureBoxSystems.MpfMediaController.Behaviours public class DisconnectOnGoodbyeReceived : MonoBehaviour { [SerializeField] - BcpInterface bcpInterface; + BcpInterface _bcpInterface; [SerializeField] - GoodbyeMessageHandler goodbyeHandler; + GoodbyeMessageHandler _goodbyeHandler; private void OnEnable() { - goodbyeHandler.Received += GoodbyeMessageReceived; + _goodbyeHandler.Received += GoodbyeMessageReceived; } private void OnDisable() { - if (goodbyeHandler != null) - goodbyeHandler.Received -= GoodbyeMessageReceived; + if (_goodbyeHandler != null) + _goodbyeHandler.Received -= GoodbyeMessageReceived; } private void GoodbyeMessageReceived(object sender, GoodbyeMessage message) { - bcpInterface.RequestDisconnect(); + _bcpInterface.RequestDisconnect(); } } } diff --git a/Runtime/Behaviours/HelloResponse.cs b/Runtime/Behaviours/HelloResponse.cs index 965b8b16..4955393b 100644 --- a/Runtime/Behaviours/HelloResponse.cs +++ b/Runtime/Behaviours/HelloResponse.cs @@ -7,20 +7,20 @@ namespace FutureBoxSystems.MpfMediaController.Behaviours public class HelloResponse : MonoBehaviour { [SerializeField] - private BcpInterface bcpInterface; + private BcpInterface _bcpInterface; [SerializeField] - private HelloMessageHandler helloHandler; + private HelloMessageHandler _helloHandler; private void OnEnable() { - helloHandler.Received += HelloMessageReceived; + _helloHandler.Received += HelloMessageReceived; } private void OnDisable() { - if (helloHandler != null) - helloHandler.Received -= HelloMessageReceived; + if (_helloHandler != null) + _helloHandler.Received -= HelloMessageReceived; } private void HelloMessageReceived(object sender, HelloMessage message) @@ -42,7 +42,7 @@ private void HelloMessageReceived(object sender, HelloMessage message) commandThatCausedError: originalHelloMessage ); } - bcpInterface.EnqueueMessage(response); + _bcpInterface.EnqueueMessage(response); } } } diff --git a/Runtime/Core/BcpInterface.cs b/Runtime/Core/BcpInterface.cs index ebe721f1..3c09c250 100644 --- a/Runtime/Core/BcpInterface.cs +++ b/Runtime/Core/BcpInterface.cs @@ -18,34 +18,34 @@ public event EventHandler ConnectionStateChange } [SerializeField] - private int port = 5050; + private int _port = 5050; [SerializeField] [Range(0.1f, 10f)] - private float frameTimeBudgetMs = 1f; + private float _frameTimeBudgetMs = 1f; [SerializeField] - private bool logReceivedMessages = false; + private bool _logReceivedMessages = false; [SerializeField] - private bool logSentMessages = false; + private bool _logSentMessages = false; - private BcpServer server; - private BcpServer Server => server ??= new BcpServer(port); + private BcpServer _server; + private BcpServer Server => _server ??= new BcpServer(_port); public delegate void HandleMessage(BcpMessage message); - private readonly Dictionary messageHandlers = new(); - private MpfEventRequester monitoringCategories; + private readonly Dictionary _messageHandlers = new(); + private MpfEventRequester _monitoringCategories; public MpfEventRequester MonitoringCategories => - monitoringCategories ??= new( + _monitoringCategories ??= new( bcpInterface: this, createStartListeningMessage: category => new MonitorStartMessage(category), createStopListeningMessage: category => new MonitorStopMessage(category) ); - private MpfEventRequester mpfEvents; + private MpfEventRequester _mpfEvents; public MpfEventRequester MpfEvents => - mpfEvents ??= new( + _mpfEvents ??= new( bcpInterface: this, createStartListeningMessage: category => new RegisterTriggerMessage(category), createStopListeningMessage: category => new RemoveTriggerMessage(category) @@ -53,7 +53,7 @@ public event EventHandler ConnectionStateChange public void RegisterMessageHandler(string command, HandleMessage handle) { - if (!messageHandlers.TryAdd(command, handle)) + if (!_messageHandlers.TryAdd(command, handle)) Debug.LogWarning( $"[BcpInterface] Cannot add message handler, because command '{command}' " + "already has a handler." @@ -63,10 +63,10 @@ public void RegisterMessageHandler(string command, HandleMessage handle) public void UnregisterMessageHandler(string command, HandleMessage handle) { if ( - messageHandlers.TryGetValue(command, out var registeredHandle) + _messageHandlers.TryGetValue(command, out var registeredHandle) && registeredHandle == handle ) - messageHandlers.Remove(command); + _messageHandlers.Remove(command); else Debug.LogWarning( $"[BcpInterface] Cannot remove message handler for command '{command}', " @@ -77,7 +77,7 @@ public void UnregisterMessageHandler(string command, HandleMessage handle) public void EnqueueMessage(ISentMessage message) { BcpMessage bcpMessage = message.ToGenericMessage(); - if (logSentMessages) + if (_logSentMessages) Debug.Log($"[BcpInterface] Sending message: {bcpMessage}"); Server.EnqueueMessage(bcpMessage); } @@ -104,7 +104,8 @@ private void Update() float startTime = Time.unscaledTime; float timeSpentMs = 0f; while ( - timeSpentMs < frameTimeBudgetMs && Server.TryDequeueReceivedMessage(out var message) + timeSpentMs < _frameTimeBudgetMs + && Server.TryDequeueReceivedMessage(out var message) ) { HandleReceivedMessage(message); @@ -114,10 +115,10 @@ private void Update() private void HandleReceivedMessage(BcpMessage message) { - if (logReceivedMessages) + if (_logReceivedMessages) Debug.Log($"[BcpInterface] Message received: {message}"); - if (messageHandlers.TryGetValue(message.Command, out var handler)) + if (_messageHandlers.TryGetValue(message.Command, out var handler)) { try { diff --git a/Runtime/Core/BcpMessage.cs b/Runtime/Core/BcpMessage.cs index d61b3730..72485c43 100644 --- a/Runtime/Core/BcpMessage.cs +++ b/Runtime/Core/BcpMessage.cs @@ -10,16 +10,16 @@ namespace FutureBoxSystems.MpfMediaController public class BcpMessage { public readonly string Command; - private readonly JObject parameters; - private readonly bool hasComplexParams; - private const char commandParamsSeparator = '?'; - private const char paramsSeparator = '&'; + private readonly JObject _parameters; + private readonly bool _hasComplexParams; + private const char CommandParamsSeparator = '?'; + private const char ParamsSeparator = '&'; public BcpMessage(string command, JObject parameters, bool hasComplexParams = false) { Command = command; - this.parameters = parameters; - this.hasComplexParams = hasComplexParams; + this._parameters = parameters; + this._hasComplexParams = hasComplexParams; } public BcpMessage(string command) @@ -29,7 +29,7 @@ public T GetParamValue(string name) { try { - var token = parameters[name]; + var token = _parameters[name]; // If string is requested, but parsed type is different, just return the unparsed // JSON string @@ -37,7 +37,7 @@ public T GetParamValue(string name) return (T)Convert.ChangeType(token.ToString(Formatting.None), typeof(T)); if (typeof(JToken).IsAssignableFrom(typeof(T))) - return (T)(object)parameters[name]; + return (T)(object)_parameters[name]; return (T)Convert.ChangeType(token, typeof(T)); } @@ -56,24 +56,24 @@ public T GetParamValue(string name) public string ToString(bool encode) { var sb = new StringBuilder(Command); - if (parameters.Count > 0) - sb.Append(commandParamsSeparator); + if (_parameters.Count > 0) + sb.Append(CommandParamsSeparator); - if (hasComplexParams) + if (_hasComplexParams) { - sb.Append($"json={parameters.ToString(Formatting.None)}"); + sb.Append($"json={_parameters.ToString(Formatting.None)}"); } else { - var properties = parameters.Properties(); + var properties = _parameters.Properties(); for (int i = 0; i < properties.Count(); i++) { JProperty prop = properties.ElementAt(i); string propStr = PropertyToParameterString(prop, encode); sb.Append(propStr); - bool isLastParam = i == parameters.Count - 1; + bool isLastParam = i == _parameters.Count - 1; if (!isLastParam) - sb.Append(paramsSeparator); + sb.Append(ParamsSeparator); } } return sb.ToString(); @@ -81,7 +81,7 @@ public string ToString(bool encode) public static BcpMessage FromString(string str) { - var parts = str.Split(commandParamsSeparator, paramsSeparator); + var parts = str.Split(CommandParamsSeparator, ParamsSeparator); var command = parts[0].Trim().ToLower(); var containsJson = false; JObject parameters = new(); diff --git a/Runtime/Core/BcpMessageHandler.cs b/Runtime/Core/BcpMessageHandler.cs index fc5ccc69..bb0786e5 100644 --- a/Runtime/Core/BcpMessageHandler.cs +++ b/Runtime/Core/BcpMessageHandler.cs @@ -8,45 +8,45 @@ public abstract class BcpMessageHandler : MonoBehaviour where T : EventArgs { [SerializeField] - protected BcpInterface bcpInterface; + protected BcpInterface _bcpInterface; public abstract string Command { get; } public virtual MonitoringCategory MonitoringCategory => MonitoringCategory.None; protected abstract ParseDelegate Parse { get; } public delegate T ParseDelegate(BcpMessage genericMessage); - private event EventHandler CommandReceived; + private event EventHandler _received; public event EventHandler Received { add { - bool isFirstHandler = CommandReceived == null; - CommandReceived += value; + bool isFirstHandler = _received == null; + _received += value; if (isFirstHandler && MonitoringCategory != MonitoringCategory.None) - bcpInterface.MonitoringCategories.AddListener(this, MonitoringCategory); + _bcpInterface.MonitoringCategories.AddListener(this, MonitoringCategory); } remove { - CommandReceived -= value; + _received -= value; if ( - bcpInterface != null - && CommandReceived == null + _bcpInterface != null + && _received == null && MonitoringCategory != MonitoringCategory.None ) { - bcpInterface.MonitoringCategories.RemoveListener(this, MonitoringCategory); + _bcpInterface.MonitoringCategories.RemoveListener(this, MonitoringCategory); } } } private void OnEnable() { - bcpInterface.RegisterMessageHandler(Command, Handle); + _bcpInterface.RegisterMessageHandler(Command, Handle); } private void OnDisable() { - if (bcpInterface != null) - bcpInterface.UnregisterMessageHandler(Command, Handle); + if (_bcpInterface != null) + _bcpInterface.UnregisterMessageHandler(Command, Handle); } private void Handle(BcpMessage message) @@ -55,7 +55,7 @@ private void Handle(BcpMessage message) throw new WrongParserException(message, Command); T specificMessage = Parse(message); BeforeEvent(); - CommandReceived?.Invoke(this, specificMessage); + _received?.Invoke(this, specificMessage); AfterEvent(); } diff --git a/Runtime/Core/BcpServer.cs b/Runtime/Core/BcpServer.cs index c0798791..f8382730 100644 --- a/Runtime/Core/BcpServer.cs +++ b/Runtime/Core/BcpServer.cs @@ -31,24 +31,24 @@ public enum ConnectionState public class BcpServer { public event EventHandler StateChanged; - private readonly object connectionStateLock = new(); - private ConnectionState connectionState = ConnectionState.NotConnected; + private readonly object _connectionStateLock = new(); + private ConnectionState _connectionState = ConnectionState.NotConnected; public ConnectionState ConnectionState { get { - lock (connectionStateLock) + lock (_connectionStateLock) { - return connectionState; + return _connectionState; } } private set { ConnectionState prevState; - lock (connectionStateLock) + lock (_connectionStateLock) { - prevState = connectionState; - connectionState = value; + prevState = _connectionState; + _connectionState = value; } if (prevState != value) @@ -58,16 +58,16 @@ private set } } - private CancellationTokenSource cts = null; - private Task communicationTask = null; - private readonly object receivedMessagesLock = new(); - private readonly Queue receivedMessages = new(); - private readonly object outboundMessagesLock = new(); - private readonly Queue outboundMessages = new(); - private readonly ManualResetEventSlim disconnectRequested = new(false); - private readonly int port; + private CancellationTokenSource _cts = null; + private Task _communicationTask = null; + private readonly object _receivedMessagesLock = new(); + private readonly Queue _receivedMessages = new(); + private readonly object _outboundMessagesLock = new(); + private readonly Queue _outboundMessages = new(); + private readonly ManualResetEventSlim _disconnectRequested = new(false); + private readonly int _port; - private const char terminator = '\n'; + private const char Terminator = '\n'; private enum ReceiveEndReason { @@ -78,7 +78,7 @@ private enum ReceiveEndReason public BcpServer(int port) { - this.port = port; + _port = port; } public async Task OpenConnectionAsync() @@ -87,9 +87,9 @@ public async Task OpenConnectionAsync() await Task.Yield(); if (ConnectionState == ConnectionState.NotConnected) { - disconnectRequested.Reset(); - cts = new CancellationTokenSource(); - communicationTask = CommunicateAsync(port, cts.Token); + _disconnectRequested.Reset(); + _cts = new CancellationTokenSource(); + _communicationTask = CommunicateAsync(_port, _cts.Token); } } @@ -100,35 +100,35 @@ public async Task CloseConnectionAsync() || ConnectionState == ConnectionState.Connecting ) { - cts.Cancel(); - cts.Dispose(); - cts = null; - await communicationTask; + _cts.Cancel(); + _cts.Dispose(); + _cts = null; + await _communicationTask; } } public bool TryDequeueReceivedMessage(out BcpMessage message) { - lock (receivedMessagesLock) - return receivedMessages.TryDequeue(out message); + lock (_receivedMessagesLock) + return _receivedMessages.TryDequeue(out message); } public void EnqueueMessage(BcpMessage message) { - lock (outboundMessagesLock) - outboundMessages.Enqueue(message); + lock (_outboundMessagesLock) + _outboundMessages.Enqueue(message); } public void RequestDisconnect() { if (ConnectionState == ConnectionState.Connected) - disconnectRequested.Set(); + _disconnectRequested.Set(); } private bool TryDequeueOutboundMessage(out BcpMessage message) { - lock (outboundMessagesLock) - return outboundMessages.TryDequeue(out message); + lock (_outboundMessagesLock) + return _outboundMessages.TryDequeue(out message); } private async Task CommunicateAsync(int port, CancellationToken ct) @@ -148,7 +148,7 @@ private async Task CommunicateAsync(int port, CancellationToken ct) const int bufferSize = 1024; var byteBuffer = new byte[bufferSize]; var stringBuffer = new StringBuilder(); - while (!ct.IsCancellationRequested && !disconnectRequested.IsSet) + while (!ct.IsCancellationRequested && !_disconnectRequested.IsSet) { var sendTask = SendMessagesAsync(stream, ct); var receiveTask = ReceiveMessagesAsync( @@ -166,7 +166,7 @@ private async Task CommunicateAsync(int port, CancellationToken ct) } ConnectionState = ConnectionState.Disconnecting; await SendMessagesAsync(stream, ct); - disconnectRequested.Reset(); + _disconnectRequested.Reset(); } else { @@ -208,7 +208,7 @@ CancellationToken ct int messageLength; while ( !ct.IsCancellationRequested - && (messageLength = stringBuffer.ToString().IndexOf(terminator)) > -1 + && (messageLength = stringBuffer.ToString().IndexOf(Terminator)) > -1 ) { var message = stringBuffer.ToString(0, messageLength); @@ -216,8 +216,8 @@ CancellationToken ct if (message.Length > 0 && !message.StartsWith("#")) { var bcpMessage = BcpMessage.FromString(message); - lock (receivedMessagesLock) - receivedMessages.Enqueue(bcpMessage); + lock (_receivedMessagesLock) + _receivedMessages.Enqueue(bcpMessage); } } } @@ -235,7 +235,7 @@ private async Task SendMessagesAsync(NetworkStream stream, CancellationToken ct) ) { var stringMessage = bcpMessage.ToString(encode: true); - stringMessage += terminator; + stringMessage += Terminator; var packet = Encoding.UTF8.GetBytes(stringMessage); try { diff --git a/Runtime/Core/MpfEventRequester.cs b/Runtime/Core/MpfEventRequester.cs index afcfdc7b..d41aae7a 100644 --- a/Runtime/Core/MpfEventRequester.cs +++ b/Runtime/Core/MpfEventRequester.cs @@ -7,10 +7,10 @@ public class MpfEventRequester { public delegate ISentMessage CreateMessage(TEvent @event); - private readonly BcpInterface bcpInterface; - private readonly CreateMessage createStartListeningMessage; - private readonly CreateMessage createStopListeningMessage; - private readonly Dictionary> listeners = new(); + private readonly BcpInterface _bcpInterface; + private readonly CreateMessage _createStartListeningMessage; + private readonly CreateMessage _createStopListeningMessage; + private readonly Dictionary> _listeners = new(); public MpfEventRequester( BcpInterface bcpInterface, @@ -18,19 +18,19 @@ public MpfEventRequester( CreateMessage createStopListeningMessage ) { - this.bcpInterface = bcpInterface; - this.createStartListeningMessage = createStartListeningMessage; - this.createStopListeningMessage = createStopListeningMessage; + _bcpInterface = bcpInterface; + _createStartListeningMessage = createStartListeningMessage; + _createStopListeningMessage = createStopListeningMessage; } public void AddListener(object listener, TEvent @event) { - if (listeners.TryAdd(@event, new HashSet { listener })) + if (_listeners.TryAdd(@event, new HashSet { listener })) { - var startListeningMsg = createStartListeningMessage(@event); - bcpInterface.EnqueueMessage(startListeningMsg); + var startListeningMsg = _createStartListeningMessage(@event); + _bcpInterface.EnqueueMessage(startListeningMsg); } - else if (!listeners[@event].Add(listener)) + else if (!_listeners[@event].Add(listener)) Debug.LogError( $"[EventPool] Cannot add listener '{listener}' to event '{@event}' because it " + "was already added." @@ -40,15 +40,15 @@ public void AddListener(object listener, TEvent @event) public void RemoveListener(object listener, TEvent @event) { if ( - listeners.TryGetValue(@event, out var listenersForThisEvent) + _listeners.TryGetValue(@event, out var listenersForThisEvent) && listenersForThisEvent.Remove(listener) ) { if (listenersForThisEvent.Count == 0) { - listeners.Remove(@event); - var stopListeningMsg = createStopListeningMessage(@event); - bcpInterface.EnqueueMessage(stopListeningMsg); + _listeners.Remove(@event); + var stopListeningMsg = _createStopListeningMessage(@event); + _bcpInterface.EnqueueMessage(stopListeningMsg); } } else diff --git a/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs b/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs index 2679644e..fe757945 100644 --- a/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs +++ b/Runtime/Messages/Device/SpecificDeviceMessageHandler.cs @@ -8,10 +8,10 @@ public abstract class SpecificDeviceMessageHandler : where TMessage : SpecificDeviceMessageBase { [SerializeField] - private string deviceName; + private string _deviceName; [SerializeField] - private DeviceMessageHandler generalDeviceMessageHandler; + private DeviceMessageHandler _generalDeviceMessageHandler; protected abstract string Type { get; } protected delegate TMessage ParseStateDelegate( @@ -23,13 +23,13 @@ string deviceName protected void OnEnable() { - generalDeviceMessageHandler.Received += HandleDeviceMessageReceived; + _generalDeviceMessageHandler.Received += HandleDeviceMessageReceived; } protected void OnDisable() { - if (generalDeviceMessageHandler) - generalDeviceMessageHandler.Received -= HandleDeviceMessageReceived; + if (_generalDeviceMessageHandler) + _generalDeviceMessageHandler.Received -= HandleDeviceMessageReceived; } private void HandleDeviceMessageReceived(object sender, DeviceMessage deviceMessage) @@ -37,7 +37,7 @@ private void HandleDeviceMessageReceived(object sender, DeviceMessage deviceMess if (deviceMessage.Type != Type) return; - if (deviceMessage.Name != deviceName) + if (deviceMessage.Name != _deviceName) return; if (deviceMessage.Change != null) diff --git a/Runtime/Messages/Error/ErrorMessage.cs b/Runtime/Messages/Error/ErrorMessage.cs index a9ed5305..ad72f880 100644 --- a/Runtime/Messages/Error/ErrorMessage.cs +++ b/Runtime/Messages/Error/ErrorMessage.cs @@ -6,8 +6,8 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Error public class ErrorMessage : EventArgs, ISentMessage { public const string Command = "error"; - private const string messageName = "message"; - private const string commandThatCausedErrorName = "command"; + private const string MessageName = "message"; + private const string CommandThatCausedErrorName = "command"; public string Message { get; private set; } public string CommandThatCausedError { get; private set; } @@ -23,8 +23,8 @@ public BcpMessage ToGenericMessage() command: Command, parameters: new JObject { - { messageName, Message }, - { commandThatCausedErrorName, CommandThatCausedError }, + { MessageName, Message }, + { CommandThatCausedErrorName, CommandThatCausedError }, } ); } @@ -32,8 +32,8 @@ public BcpMessage ToGenericMessage() public static ErrorMessage FromGenericMessage(BcpMessage bcpMessage) { return new ErrorMessage( - message: bcpMessage.GetParamValue(messageName), - commandThatCausedError: bcpMessage.GetParamValue(commandThatCausedErrorName) + message: bcpMessage.GetParamValue(MessageName), + commandThatCausedError: bcpMessage.GetParamValue(CommandThatCausedErrorName) ); } } diff --git a/Runtime/Messages/Hello/HelloMessage.cs b/Runtime/Messages/Hello/HelloMessage.cs index e0ca658c..32f7293b 100644 --- a/Runtime/Messages/Hello/HelloMessage.cs +++ b/Runtime/Messages/Hello/HelloMessage.cs @@ -6,9 +6,10 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Hello public class HelloMessage : EventArgs, ISentMessage { public const string Command = "hello"; - private const string versionName = "version"; - private const string controllerNameName = "controller_name"; - private const string controllerVersionName = "controller_version"; + private const string VersionName = "version"; + private const string ControllerNameName = "controller_name"; + private const string ControllerVersionName = "controller_version"; + public readonly string BcpSpecVersion; public readonly string ControllerName; public readonly string ControllerVersion; @@ -26,9 +27,9 @@ public BcpMessage ToGenericMessage() command: Command, parameters: new JObject { - { versionName, BcpSpecVersion }, - { controllerNameName, ControllerName }, - { controllerVersionName, ControllerVersion }, + { VersionName, BcpSpecVersion }, + { ControllerNameName, ControllerName }, + { ControllerVersionName, ControllerVersion }, } ); } @@ -36,9 +37,9 @@ public BcpMessage ToGenericMessage() public static HelloMessage FromGenericMessage(BcpMessage bcpMessage) { return new HelloMessage( - version: bcpMessage.GetParamValue(versionName), - controllerName: bcpMessage.GetParamValue(controllerNameName), - controllerVersion: bcpMessage.GetParamValue(controllerVersionName) + version: bcpMessage.GetParamValue(VersionName), + controllerName: bcpMessage.GetParamValue(ControllerNameName), + controllerVersion: bcpMessage.GetParamValue(ControllerVersionName) ); } } diff --git a/Runtime/Messages/Mode/ModeListMessage.cs b/Runtime/Messages/Mode/ModeListMessage.cs index 15e2ec24..4ff8ec20 100644 --- a/Runtime/Messages/Mode/ModeListMessage.cs +++ b/Runtime/Messages/Mode/ModeListMessage.cs @@ -9,12 +9,12 @@ public class ModeListMessage : EventArgs { public const string Command = "mode_list"; public const string RunningModesParamName = "running_modes"; - public ReadOnlyCollection RunningModes => Array.AsReadOnly(runningModes); - private readonly Mode[] runningModes; + public ReadOnlyCollection RunningModes => Array.AsReadOnly(_runningModes); + private readonly Mode[] _runningModes; public ModeListMessage(Mode[] runningModes) { - this.runningModes = runningModes; + _runningModes = runningModes; } public static ModeListMessage FromGenericMessage(BcpMessage bcpMessage) diff --git a/Runtime/Messages/Mode/ModeMonitor.cs b/Runtime/Messages/Mode/ModeMonitor.cs index 70400b90..f96665dc 100644 --- a/Runtime/Messages/Mode/ModeMonitor.cs +++ b/Runtime/Messages/Mode/ModeMonitor.cs @@ -6,25 +6,25 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Mode public class ModeMonitor : MonoBehaviour { [SerializeField] - private string modeName; + private string _modeName; [SerializeField] - private ModeStartMessageHandler modeStartMessageHandler; + private ModeStartMessageHandler _modeStartMessageHandler; [SerializeField] - private ModeStopMessageHandler modeStopMessageHandler; + private ModeStopMessageHandler _modeStopMessageHandler; - private bool isModeActive = false; + private bool _isModeActive = false; public bool IsModeActive { - get => isModeActive; + get => _isModeActive; set { - if (value == isModeActive) + if (value == _isModeActive) return; - isModeActive = value; - IsModeActiveChanged?.Invoke(this, isModeActive); + _isModeActive = value; + IsModeActiveChanged?.Invoke(this, _isModeActive); } } @@ -32,19 +32,19 @@ public bool IsModeActive private void OnEnable() { - modeStartMessageHandler.Received += OnModeStarted; - modeStopMessageHandler.Received += OnModeStopped; + _modeStartMessageHandler.Received += OnModeStarted; + _modeStopMessageHandler.Received += OnModeStopped; } private void OnDisable() { - modeStartMessageHandler.Received -= OnModeStarted; - modeStopMessageHandler.Received -= OnModeStopped; + _modeStartMessageHandler.Received -= OnModeStarted; + _modeStopMessageHandler.Received -= OnModeStopped; } private void OnModeStarted(object sender, ModeStartMessage msg) { - if (msg.Name != modeName) + if (msg.Name != _modeName) return; IsModeActive = true; @@ -52,7 +52,7 @@ private void OnModeStarted(object sender, ModeStartMessage msg) private void OnModeStopped(object sender, ModeStopMessage msg) { - if (msg.Name != modeName) + if (msg.Name != _modeName) return; IsModeActive = false; diff --git a/Runtime/Messages/Monitor/MonitorStartMessage.cs b/Runtime/Messages/Monitor/MonitorStartMessage.cs index 6df568e5..9768ad1f 100644 --- a/Runtime/Messages/Monitor/MonitorStartMessage.cs +++ b/Runtime/Messages/Monitor/MonitorStartMessage.cs @@ -8,7 +8,7 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Monitor public class MonitorStartMessage : EventArgs, ISentMessage { public const string Command = "monitor_start"; - private const string categoryName = "category"; + private const string CategoryName = "category"; public readonly MonitoringCategory Category; public MonitorStartMessage(MonitoringCategory category) @@ -26,7 +26,7 @@ public BcpMessage ToGenericMessage() ); return new( command: Command, - parameters: new JObject { [categoryName] = categoryString } + parameters: new JObject { [CategoryName] = categoryString } ); } } diff --git a/Runtime/Messages/Monitor/MonitorStopMessage.cs b/Runtime/Messages/Monitor/MonitorStopMessage.cs index 8e64cedd..df251c83 100644 --- a/Runtime/Messages/Monitor/MonitorStopMessage.cs +++ b/Runtime/Messages/Monitor/MonitorStopMessage.cs @@ -7,7 +7,7 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Monitor public class MonitorStopMessage : EventArgs, ISentMessage { public const string Command = "monitor_stop"; - private const string categoryName = "category"; + private const string CategoryName = "category"; public readonly MonitoringCategory Category; public MonitorStopMessage(MonitoringCategory category) @@ -25,7 +25,7 @@ public BcpMessage ToGenericMessage() ); return new BcpMessage( command: Command, - parameters: new JObject { [categoryName] = categoryString } + parameters: new JObject { [CategoryName] = categoryString } ); } } diff --git a/Runtime/Messages/MonitorBase.cs b/Runtime/Messages/MonitorBase.cs index 05a0bd9b..6288dc8b 100644 --- a/Runtime/Messages/MonitorBase.cs +++ b/Runtime/Messages/MonitorBase.cs @@ -6,16 +6,16 @@ namespace FutureBoxSystems.MpfMediaController.Messages { public abstract class MonitorBase : MonoBehaviour { - private object objVarValue; + private object _objVarValue; public object ObjVarValue { - get => objVarValue; + get => _objVarValue; protected set { - if (value == objVarValue) + if (value == _objVarValue) return; - objVarValue = value; - ObjValueChanged?.Invoke(this, objVarValue); + _objVarValue = value; + ObjValueChanged?.Invoke(this, _objVarValue); } } @@ -27,24 +27,24 @@ public abstract class MonitorBase : MonitorBase where TMessage : EventArgs { [SerializeField] - private BcpMessageHandler messageHandler; + private BcpMessageHandler _messageHandler; [SerializeField] - private ResetMessageHandler resetMessageHandler; + private ResetMessageHandler _resetMessageHandler; public event EventHandler ValueChanged; - private TVar varValue; + private TVar _varValue; public TVar VarValue { - get => varValue; + get => _varValue; protected set { WasEverUpdated = true; - if ((value == null && VarValue == null) || value.Equals(varValue)) + if ((value == null && VarValue == null) || value.Equals(_varValue)) return; - varValue = value; + _varValue = value; ObjVarValue = value; - ValueChanged?.Invoke(this, varValue); + ValueChanged?.Invoke(this, _varValue); } } @@ -58,16 +58,16 @@ private void Awake() protected virtual void OnEnable() { - messageHandler.Received += MessageHandler_Received; - resetMessageHandler.Received += ResetMessageHandler_Received; + _messageHandler.Received += MessageHandler_Received; + _resetMessageHandler.Received += ResetMessageHandler_Received; } protected virtual void OnDisable() { - if (messageHandler) - messageHandler.Received -= MessageHandler_Received; - if (resetMessageHandler) - resetMessageHandler.Received -= ResetMessageHandler_Received; + if (_messageHandler) + _messageHandler.Received -= MessageHandler_Received; + if (_resetMessageHandler) + _resetMessageHandler.Received -= ResetMessageHandler_Received; } private void ResetMessageHandler_Received(object sender, ResetMessage msg) diff --git a/Runtime/Messages/MpfVariableMonitorBase.cs b/Runtime/Messages/MpfVariableMonitorBase.cs index 39343fac..ed185acd 100644 --- a/Runtime/Messages/MpfVariableMonitorBase.cs +++ b/Runtime/Messages/MpfVariableMonitorBase.cs @@ -8,11 +8,11 @@ public abstract class MpfVariableMonitorBase : MonitorBase where VarType : IEquatable { [SerializeField] - CurrentPlayerMonitor currentPlayerMonitor; + private CurrentPlayerMonitor _currentPlayerMonitor; - protected Dictionary varPerPlayer = new(); + protected Dictionary _varPerPlayer = new(); protected override void OnEnable() { base.OnEnable(); - currentPlayerMonitor.ValueChanged += CurrentPlayerMonitor_ValueChanged; + _currentPlayerMonitor.ValueChanged += CurrentPlayerMonitor_ValueChanged; } protected override void OnDisable() { base.OnDisable(); - if (currentPlayerMonitor) - currentPlayerMonitor.ValueChanged -= CurrentPlayerMonitor_ValueChanged; + if (_currentPlayerMonitor) + _currentPlayerMonitor.ValueChanged -= CurrentPlayerMonitor_ValueChanged; } private void CurrentPlayerMonitor_ValueChanged(object sender, int currentPlayerNum) { - varPerPlayer.TryAdd(currentPlayerNum, default); - VarValue = varPerPlayer[currentPlayerNum]; + _varPerPlayer.TryAdd(currentPlayerNum, default); + VarValue = _varPerPlayer[currentPlayerNum]; } protected override void MessageHandler_Received(object sender, PlayerVariableMessage msg) @@ -38,7 +38,7 @@ protected override void MessageHandler_Received(object sender, PlayerVariableMes if (base.MatchesMonitoringCriteria(msg)) { VarType var = GetValueFromMessage(msg); - varPerPlayer[msg.PlayerNum] = var; + _varPerPlayer[msg.PlayerNum] = var; } base.MessageHandler_Received(sender, msg); } @@ -46,7 +46,7 @@ protected override void MessageHandler_Received(object sender, PlayerVariableMes protected override bool MatchesMonitoringCriteria(PlayerVariableMessage msg) { return base.MatchesMonitoringCriteria(msg) - && msg.PlayerNum == currentPlayerMonitor.VarValue; + && msg.PlayerNum == _currentPlayerMonitor.VarValue; } } } diff --git a/Runtime/Messages/Reset/ResetMessageHandler.cs b/Runtime/Messages/Reset/ResetMessageHandler.cs index 334ad969..e9b0443d 100644 --- a/Runtime/Messages/Reset/ResetMessageHandler.cs +++ b/Runtime/Messages/Reset/ResetMessageHandler.cs @@ -8,7 +8,7 @@ public class ResetMessageHandler : BcpMessageHandler protected override void AfterEvent() { base.AfterEvent(); - bcpInterface.EnqueueMessage(new ResetCompleteMessage()); + _bcpInterface.EnqueueMessage(new ResetCompleteMessage()); } } } diff --git a/Runtime/Messages/Switch/SwitchMonitor.cs b/Runtime/Messages/Switch/SwitchMonitor.cs index 624149b2..a3c13d32 100644 --- a/Runtime/Messages/Switch/SwitchMonitor.cs +++ b/Runtime/Messages/Switch/SwitchMonitor.cs @@ -5,11 +5,11 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Switch public class SwitchMonitor : MonitorBase { [SerializeField] - protected string switchName; + protected string _switchName; protected override bool MatchesMonitoringCriteria(SwitchMessage msg) { - return base.MatchesMonitoringCriteria(msg) && msg.Name == switchName; + return base.MatchesMonitoringCriteria(msg) && msg.Name == _switchName; } protected override bool GetValueFromMessage(SwitchMessage msg) => msg.IsActive; diff --git a/Runtime/Messages/Trigger/MpfEventListener.cs b/Runtime/Messages/Trigger/MpfEventListener.cs index 3fb9526a..9f79480b 100644 --- a/Runtime/Messages/Trigger/MpfEventListener.cs +++ b/Runtime/Messages/Trigger/MpfEventListener.cs @@ -6,33 +6,33 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Trigger public class MpfEventListener : MonoBehaviour { [SerializeField] - private string eventName; + private string _eventName; [SerializeField] - private BcpInterface bcpInterface; + private BcpInterface _bcpInterface; [SerializeField] - private TriggerMessageHandler triggerMessageHandler; + private TriggerMessageHandler _triggerMessageHandler; public event EventHandler Triggered; private void OnEnable() { - bcpInterface.MpfEvents.AddListener(this, eventName); - triggerMessageHandler.Received += TriggerMessageHandler_Received; + _bcpInterface.MpfEvents.AddListener(this, _eventName); + _triggerMessageHandler.Received += TriggerMessageHandler_Received; } private void OnDisable() { - if (bcpInterface) - bcpInterface.MpfEvents.RemoveListener(this, eventName); - if (triggerMessageHandler) - triggerMessageHandler.Received -= TriggerMessageHandler_Received; + if (_bcpInterface) + _bcpInterface.MpfEvents.RemoveListener(this, _eventName); + if (_triggerMessageHandler) + _triggerMessageHandler.Received -= TriggerMessageHandler_Received; } private void TriggerMessageHandler_Received(object sender, TriggerMessage msg) { - if (msg.TriggerName == eventName) + if (msg.TriggerName == _eventName) Triggered?.Invoke(this, EventArgs.Empty); } } diff --git a/Runtime/Messages/Trigger/RemoveTriggerMessage.cs b/Runtime/Messages/Trigger/RemoveTriggerMessage.cs index 3b86693b..cecd48e2 100644 --- a/Runtime/Messages/Trigger/RemoveTriggerMessage.cs +++ b/Runtime/Messages/Trigger/RemoveTriggerMessage.cs @@ -6,7 +6,7 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Trigger public class RemoveTriggerMessage : EventArgs, ISentMessage { public const string Command = "remove_trigger"; - private const string eventParamName = "event"; + private const string EventParamName = "event"; public readonly string EventName; @@ -19,7 +19,7 @@ public BcpMessage ToGenericMessage() { return new BcpMessage( command: Command, - parameters: new JObject { { eventParamName, EventName } } + parameters: new JObject { { EventParamName, EventName } } ); } } diff --git a/Runtime/Ui/MonitoredVariableText.cs b/Runtime/Ui/MonitoredVariableText.cs index e869c903..34a3cbb6 100644 --- a/Runtime/Ui/MonitoredVariableText.cs +++ b/Runtime/Ui/MonitoredVariableText.cs @@ -8,10 +8,10 @@ namespace FutureBoxSystems.Ui public class MonitoredVariableText : MonoBehaviour { [SerializeReference] - private MonitorBase monitor; + private MonitorBase _monitor; [SerializeField] - private string format = "{0}"; + private string _format = "{0}"; private TextMeshProUGUI _textField; private TextMeshProUGUI TextField @@ -26,18 +26,18 @@ private TextMeshProUGUI TextField private void OnEnable() { - SetText(monitor.ObjVarValue); - monitor.ObjValueChanged += Monitor_ValueChanged; + SetText(_monitor.ObjVarValue); + _monitor.ObjValueChanged += Monitor_ValueChanged; } private void OnDisable() { - if (monitor != null) - monitor.ObjValueChanged -= Monitor_ValueChanged; + if (_monitor != null) + _monitor.ObjValueChanged -= Monitor_ValueChanged; } private void Monitor_ValueChanged(object sender, object value) => SetText(value); - private void SetText(object value) => TextField.text = string.Format(format, value); + private void SetText(object value) => TextField.text = string.Format(_format, value); } } From 17f11ddf3984d5412bae64d919aca03aef09c123 Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 18 Feb 2025 20:52:19 +0100 Subject: [PATCH 80/98] Always use pascal case for constants --- Runtime/Messages/Settings/SettingsMessage.cs | 4 ++-- Runtime/Messages/Trigger/RegisterTriggerMessage.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Runtime/Messages/Settings/SettingsMessage.cs b/Runtime/Messages/Settings/SettingsMessage.cs index decb90c5..73149e4d 100644 --- a/Runtime/Messages/Settings/SettingsMessage.cs +++ b/Runtime/Messages/Settings/SettingsMessage.cs @@ -6,7 +6,7 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Settings public class SettingsMessage : EventArgs { public const string Command = "settings"; - private const string settingsParamName = "settings"; + private const string SettingsParamName = "settings"; public readonly JArray Settings; public SettingsMessage(JArray settings) @@ -16,7 +16,7 @@ public SettingsMessage(JArray settings) public static SettingsMessage FromGenericMessage(BcpMessage bcpMessage) { - return new SettingsMessage(bcpMessage.GetParamValue(settingsParamName)); + return new SettingsMessage(bcpMessage.GetParamValue(SettingsParamName)); } } } diff --git a/Runtime/Messages/Trigger/RegisterTriggerMessage.cs b/Runtime/Messages/Trigger/RegisterTriggerMessage.cs index e918fd87..2e13db68 100644 --- a/Runtime/Messages/Trigger/RegisterTriggerMessage.cs +++ b/Runtime/Messages/Trigger/RegisterTriggerMessage.cs @@ -6,7 +6,7 @@ namespace FutureBoxSystems.MpfMediaController.Messages.Trigger public class RegisterTriggerMessage : EventArgs, ISentMessage { public const string Command = "register_trigger"; - private const string eventParamName = "event"; + private const string EventParamName = "event"; public readonly string EventName; @@ -19,7 +19,7 @@ public BcpMessage ToGenericMessage() { return new BcpMessage( command: Command, - parameters: new JObject { { eventParamName, EventName } } + parameters: new JObject { { EventParamName, EventName } } ); } } From b8a00492856a61df0f007d71e0cdebc19c825f9b Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 18 Feb 2025 22:37:53 +0100 Subject: [PATCH 81/98] Future Box -> VPE --- Editor/BcpInterfaceInspector.cs | 5 +++-- .../Behaviors/DisconnectOnGoodbyeReceived.cs | 4 ++-- Runtime/MediaController/Behaviors/HelloResponse.cs | 6 +++--- Runtime/MediaController/Core/BcpInterface.cs | 10 +++++----- Runtime/MediaController/Core/BcpMessage.cs | 2 +- Runtime/MediaController/Core/BcpMessageHandler.cs | 4 ++-- Runtime/MediaController/Core/BcpServer.cs | 2 +- Runtime/MediaController/Core/Constants.cs | 4 ++-- Runtime/MediaController/Core/Exceptions.cs | 2 +- Runtime/MediaController/Core/MpfEventRequester.cs | 2 +- .../MediaController/Messages/Ball/BallEndMessage.cs | 2 +- .../Messages/Ball/BallEndMessageHandler.cs | 4 ++-- .../MediaController/Messages/Ball/BallStartMessage.cs | 2 +- .../Messages/Ball/BallStartMessageHandler.cs | 4 ++-- .../Messages/Device/Autofire/AutofireDeviceMessage.cs | 2 +- .../Device/Autofire/AutofireDeviceMessageHandler.cs | 2 +- .../Messages/Device/BallDevice/BallDeviceMessage.cs | 2 +- .../Device/BallDevice/BallDeviceMessageHandler.cs | 2 +- .../Device/ComboSwitch/ComboSwitchDeviceMessage.cs | 2 +- .../ComboSwitch/ComboSwitchDeviceMessageHandler.cs | 2 +- .../Messages/Device/DeviceAttributeChange.cs | 2 +- .../MediaController/Messages/Device/DeviceMessage.cs | 2 +- .../Messages/Device/DeviceMessageExceptions.cs | 2 +- .../Messages/Device/DeviceMessageHandler.cs | 4 ++-- .../Messages/Device/Flipper/FlipperDeviceMessage.cs | 2 +- .../Device/Flipper/FlipperDeviceMessageHandler.cs | 2 +- .../Messages/Device/Light/LightDeviceMessage.cs | 2 +- .../Messages/Device/Light/LightDeviceMessageHandler.cs | 2 +- .../Device/Playfield/PlayfieldDeviceMessage.cs | 2 +- .../Device/Playfield/PlayfieldDeviceMessageHandler.cs | 2 +- .../Messages/Device/SpecificDeviceMessageBase.cs | 2 +- .../Messages/Device/SpecificDeviceMessageHandler.cs | 2 +- .../Messages/Device/Switch/SwitchDeviceMessage.cs | 2 +- .../Device/Switch/SwitchDeviceMessageHandler.cs | 2 +- Runtime/MediaController/Messages/Error/ErrorMessage.cs | 2 +- .../Messages/Error/ErrorMessageHandler.cs | 2 +- .../MediaController/Messages/Goodbye/GoodbyeMessage.cs | 2 +- .../Messages/Goodbye/GoodbyeMessageHandler.cs | 2 +- Runtime/MediaController/Messages/Hello/HelloMessage.cs | 2 +- .../Messages/Hello/HelloMessageHandler.cs | 2 +- .../Messages/MachineVariable/MachineVariableMessage.cs | 2 +- .../MachineVariable/MachineVariableMessageHandler.cs | 4 ++-- .../Messages/MachineVariable/MachineVariableMonitor.cs | 2 +- .../Monitor/BoolMachineVariableMonitor.cs | 2 +- .../Monitor/FloatMachineVarableMonitor.cs | 2 +- .../Monitor/IntMachineVariableMonitor.cs | 2 +- .../Monitor/StringMachineVariableMonitor.cs | 2 +- Runtime/MediaController/Messages/Mode/Mode.cs | 2 +- .../MediaController/Messages/Mode/ModeListMessage.cs | 2 +- .../Messages/Mode/ModeListMessageHandler.cs | 4 ++-- Runtime/MediaController/Messages/Mode/ModeMonitor.cs | 2 +- .../MediaController/Messages/Mode/ModeStartMessage.cs | 2 +- .../Messages/Mode/ModeStartMessageHandler.cs | 4 ++-- .../MediaController/Messages/Mode/ModeStopMessage.cs | 2 +- .../Messages/Mode/ModeStopMessageHandler.cs | 4 ++-- .../Messages/Monitor/MonitorStartMessage.cs | 2 +- .../Messages/Monitor/MonitorStopMessage.cs | 2 +- .../Messages/Monitor/MonitoringCategory.cs | 2 +- Runtime/MediaController/Messages/MonitorBase.cs | 4 ++-- .../MediaController/Messages/MpfVariableMessageBase.cs | 2 +- .../MediaController/Messages/MpfVariableMonitorBase.cs | 2 +- .../Messages/PlayerAdded/PlayerAddedMessage.cs | 2 +- .../Messages/PlayerAdded/PlayerAddedMessageHandler.cs | 4 ++-- .../Messages/PlayerAdded/PlayerCountMonitor.cs | 2 +- .../Messages/PlayerTurnStart/CurrentPlayerMonitor.cs | 2 +- .../Messages/PlayerTurnStart/PlayerTurnStartMessage.cs | 2 +- .../PlayerTurnStart/PlayerTurnStartMessageHandler.cs | 4 ++-- .../Monitor/BoolPlayerVariableMonitor.cs | 2 +- .../Monitor/FloatPlayerVariableMonitor.cs | 2 +- .../PlayerVariable/Monitor/IntPlayerVariableMonitor.cs | 2 +- .../Monitor/StringPlayerVariableMonitor.cs | 2 +- .../Messages/PlayerVariable/PlayerVariableMessage.cs | 4 ++-- .../PlayerVariable/PlayerVariableMessageHandler.cs | 4 ++-- .../Messages/PlayerVariable/PlayerVariableMonitor.cs | 4 ++-- .../Messages/Reset/ResetCompleteMessage.cs | 2 +- Runtime/MediaController/Messages/Reset/ResetMessage.cs | 2 +- .../Messages/Reset/ResetMessageHandler.cs | 2 +- .../Messages/Settings/SettingsMessage.cs | 2 +- .../Messages/Settings/SettingsMessageHandler.cs | 4 ++-- .../MediaController/Messages/Switch/SwitchMessage.cs | 2 +- .../Messages/Switch/SwitchMessageHandler.cs | 4 ++-- .../MediaController/Messages/Switch/SwitchMonitor.cs | 2 +- .../Messages/Trigger/MpfEventListener.cs | 2 +- .../Messages/Trigger/RegisterTriggerMessage.cs | 2 +- .../Messages/Trigger/RemoveTriggerMessage.cs | 2 +- .../MediaController/Messages/Trigger/TriggerMessage.cs | 2 +- .../Messages/Trigger/TriggerMessageHandler.cs | 2 +- Runtime/MediaController/Ui/MonitoredVariableText.cs | 4 ++-- Runtime/MediaController/Utils/StringEnum.cs | 2 +- 89 files changed, 116 insertions(+), 115 deletions(-) diff --git a/Editor/BcpInterfaceInspector.cs b/Editor/BcpInterfaceInspector.cs index ed26cea6..432265d5 100644 --- a/Editor/BcpInterfaceInspector.cs +++ b/Editor/BcpInterfaceInspector.cs @@ -1,11 +1,12 @@ using UnityEditor; using UnityEngine; using UnityEngine.UIElements; +using VisualPinball.Engine.Mpf.Unity.MediaController; -namespace FutureBoxSystems.MpfMediaController +namespace VisualPinball.Engine.Mpf.Unity.Editor { [CustomEditor(typeof(BcpInterface))] - public class BcpInterfaceInspector : Editor + public class BcpInterfaceInspector : UnityEditor.Editor { [SerializeField] private VisualTreeAsset _bcpInterfaceInspectorXml; diff --git a/Runtime/MediaController/Behaviors/DisconnectOnGoodbyeReceived.cs b/Runtime/MediaController/Behaviors/DisconnectOnGoodbyeReceived.cs index e514c59e..97f4b1ce 100644 --- a/Runtime/MediaController/Behaviors/DisconnectOnGoodbyeReceived.cs +++ b/Runtime/MediaController/Behaviors/DisconnectOnGoodbyeReceived.cs @@ -1,7 +1,7 @@ -using FutureBoxSystems.MpfMediaController.Messages.Goodbye; using UnityEngine; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Goodbye; -namespace FutureBoxSystems.MpfMediaController.Behaviours +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Behaviours { public class DisconnectOnGoodbyeReceived : MonoBehaviour { diff --git a/Runtime/MediaController/Behaviors/HelloResponse.cs b/Runtime/MediaController/Behaviors/HelloResponse.cs index 4955393b..d34f8df9 100644 --- a/Runtime/MediaController/Behaviors/HelloResponse.cs +++ b/Runtime/MediaController/Behaviors/HelloResponse.cs @@ -1,8 +1,8 @@ -using FutureBoxSystems.MpfMediaController.Messages.Error; -using FutureBoxSystems.MpfMediaController.Messages.Hello; using UnityEngine; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Error; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Hello; -namespace FutureBoxSystems.MpfMediaController.Behaviours +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Behaviours { public class HelloResponse : MonoBehaviour { diff --git a/Runtime/MediaController/Core/BcpInterface.cs b/Runtime/MediaController/Core/BcpInterface.cs index 3c09c250..8ac01346 100644 --- a/Runtime/MediaController/Core/BcpInterface.cs +++ b/Runtime/MediaController/Core/BcpInterface.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; -using FutureBoxSystems.MpfMediaController.Messages.Error; -using FutureBoxSystems.MpfMediaController.Messages.Goodbye; -using FutureBoxSystems.MpfMediaController.Messages.Monitor; -using FutureBoxSystems.MpfMediaController.Messages.Trigger; using UnityEngine; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Error; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Goodbye; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Trigger; -namespace FutureBoxSystems.MpfMediaController +namespace VisualPinball.Engine.Mpf.Unity.MediaController { public class BcpInterface : MonoBehaviour { diff --git a/Runtime/MediaController/Core/BcpMessage.cs b/Runtime/MediaController/Core/BcpMessage.cs index 72485c43..b87620d7 100644 --- a/Runtime/MediaController/Core/BcpMessage.cs +++ b/Runtime/MediaController/Core/BcpMessage.cs @@ -5,7 +5,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -namespace FutureBoxSystems.MpfMediaController +namespace VisualPinball.Engine.Mpf.Unity.MediaController { public class BcpMessage { diff --git a/Runtime/MediaController/Core/BcpMessageHandler.cs b/Runtime/MediaController/Core/BcpMessageHandler.cs index bb0786e5..09199e72 100644 --- a/Runtime/MediaController/Core/BcpMessageHandler.cs +++ b/Runtime/MediaController/Core/BcpMessageHandler.cs @@ -1,8 +1,8 @@ using System; -using FutureBoxSystems.MpfMediaController.Messages.Monitor; using UnityEngine; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; -namespace FutureBoxSystems.MpfMediaController +namespace VisualPinball.Engine.Mpf.Unity.MediaController { public abstract class BcpMessageHandler : MonoBehaviour where T : EventArgs diff --git a/Runtime/MediaController/Core/BcpServer.cs b/Runtime/MediaController/Core/BcpServer.cs index f8382730..f196b259 100644 --- a/Runtime/MediaController/Core/BcpServer.cs +++ b/Runtime/MediaController/Core/BcpServer.cs @@ -6,7 +6,7 @@ using System.Threading; using System.Threading.Tasks; -namespace FutureBoxSystems.MpfMediaController +namespace VisualPinball.Engine.Mpf.Unity.MediaController { public class ConnectionStateChangedEventArgs : EventArgs { diff --git a/Runtime/MediaController/Core/Constants.cs b/Runtime/MediaController/Core/Constants.cs index 50972832..5395d16e 100644 --- a/Runtime/MediaController/Core/Constants.cs +++ b/Runtime/MediaController/Core/Constants.cs @@ -1,8 +1,8 @@ -namespace FutureBoxSystems.MpfMediaController +namespace VisualPinball.Engine.Mpf.Unity.MediaController { public static class Constants { - public const string MediaControllerName = "Future Box Unity Media Controller"; + public const string MediaControllerName = "Visual Pinball Engine Media Controller"; public const string MediaControllerVersion = "0.1.0"; public const string BcpSpecVersion = "1.1"; } diff --git a/Runtime/MediaController/Core/Exceptions.cs b/Runtime/MediaController/Core/Exceptions.cs index aad8967f..3b6e8a90 100644 --- a/Runtime/MediaController/Core/Exceptions.cs +++ b/Runtime/MediaController/Core/Exceptions.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController +namespace VisualPinball.Engine.Mpf.Unity.MediaController { public class BcpParseException : Exception { diff --git a/Runtime/MediaController/Core/MpfEventRequester.cs b/Runtime/MediaController/Core/MpfEventRequester.cs index d41aae7a..012b7e1e 100644 --- a/Runtime/MediaController/Core/MpfEventRequester.cs +++ b/Runtime/MediaController/Core/MpfEventRequester.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using UnityEngine; -namespace FutureBoxSystems.MpfMediaController +namespace VisualPinball.Engine.Mpf.Unity.MediaController { public class MpfEventRequester { diff --git a/Runtime/MediaController/Messages/Ball/BallEndMessage.cs b/Runtime/MediaController/Messages/Ball/BallEndMessage.cs index 91d9e7f7..c099f601 100644 --- a/Runtime/MediaController/Messages/Ball/BallEndMessage.cs +++ b/Runtime/MediaController/Messages/Ball/BallEndMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Ball +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Ball { public class BallEndMessage : EventArgs { diff --git a/Runtime/MediaController/Messages/Ball/BallEndMessageHandler.cs b/Runtime/MediaController/Messages/Ball/BallEndMessageHandler.cs index e1df4edf..b935fdd4 100644 --- a/Runtime/MediaController/Messages/Ball/BallEndMessageHandler.cs +++ b/Runtime/MediaController/Messages/Ball/BallEndMessageHandler.cs @@ -1,6 +1,6 @@ -using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; -namespace FutureBoxSystems.MpfMediaController.Messages.Ball +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Ball { public class BallEndMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Ball/BallStartMessage.cs b/Runtime/MediaController/Messages/Ball/BallStartMessage.cs index a7d8e05e..0f6bf651 100644 --- a/Runtime/MediaController/Messages/Ball/BallStartMessage.cs +++ b/Runtime/MediaController/Messages/Ball/BallStartMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Ball +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Ball { public class BallStartMessage : EventArgs { diff --git a/Runtime/MediaController/Messages/Ball/BallStartMessageHandler.cs b/Runtime/MediaController/Messages/Ball/BallStartMessageHandler.cs index a9f8da30..d0a5987c 100644 --- a/Runtime/MediaController/Messages/Ball/BallStartMessageHandler.cs +++ b/Runtime/MediaController/Messages/Ball/BallStartMessageHandler.cs @@ -1,6 +1,6 @@ -using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; -namespace FutureBoxSystems.MpfMediaController.Messages.Ball +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Ball { public class BallStartMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessage.cs b/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessage.cs index a08fe7db..cab06342 100644 --- a/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessage.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.Device.Autofire +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Autofire { public class AutofireDeviceMessage : SpecificDeviceMessageBase { diff --git a/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs index b3d51ea6..2b926e23 100644 --- a/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Device.Autofire +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Autofire { public class AutofireDeviceMessageHandler : SpecificDeviceMessageHandler diff --git a/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessage.cs b/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessage.cs index 8f453e40..eaa20bae 100644 --- a/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessage.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.Device.BallDevice +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.BallDevice { public class BallDeviceMessage : SpecificDeviceMessageBase { diff --git a/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessageHandler.cs index 14705497..f56f3823 100644 --- a/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessageHandler.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Device.BallDevice +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.BallDevice { public class BallDeviceMessageHandler : SpecificDeviceMessageHandler diff --git a/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs b/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs index c9554d4e..ef2dd30e 100644 --- a/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.Device.ComboSwitch +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.ComboSwitch { public class ComboSwitchDeviceMessage : SpecificDeviceMessageBase { diff --git a/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs index 5205af06..eb0962ae 100644 --- a/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Device.ComboSwitch +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.ComboSwitch { public class ComboSwitchDeviceMessageHandler : SpecificDeviceMessageHandler diff --git a/Runtime/MediaController/Messages/Device/DeviceAttributeChange.cs b/Runtime/MediaController/Messages/Device/DeviceAttributeChange.cs index 65e2a227..c340c3a9 100644 --- a/Runtime/MediaController/Messages/Device/DeviceAttributeChange.cs +++ b/Runtime/MediaController/Messages/Device/DeviceAttributeChange.cs @@ -3,7 +3,7 @@ using Newtonsoft.Json; using UnityEngine; -namespace FutureBoxSystems.MpfMediaController.Messages.Device +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device { public class DeviceAttributeChange { diff --git a/Runtime/MediaController/Messages/Device/DeviceMessage.cs b/Runtime/MediaController/Messages/Device/DeviceMessage.cs index 802c226c..bd987af1 100644 --- a/Runtime/MediaController/Messages/Device/DeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/DeviceMessage.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json.Linq; -namespace FutureBoxSystems.MpfMediaController.Messages.Device +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device { public class DeviceMessage : EventArgs { diff --git a/Runtime/MediaController/Messages/Device/DeviceMessageExceptions.cs b/Runtime/MediaController/Messages/Device/DeviceMessageExceptions.cs index a1e7b0cd..f7047bd3 100644 --- a/Runtime/MediaController/Messages/Device/DeviceMessageExceptions.cs +++ b/Runtime/MediaController/Messages/Device/DeviceMessageExceptions.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Device +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device { public class WrongDeviceAttributeTypeException : BcpParseException { diff --git a/Runtime/MediaController/Messages/Device/DeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/DeviceMessageHandler.cs index 094dc8be..481ea0e4 100644 --- a/Runtime/MediaController/Messages/Device/DeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/DeviceMessageHandler.cs @@ -1,6 +1,6 @@ -using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; -namespace FutureBoxSystems.MpfMediaController.Messages.Device +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device { public class DeviceMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessage.cs b/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessage.cs index 63484304..3006fe8c 100644 --- a/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessage.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.Device.Flipper +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Flipper { public class FlipperDeviceMessage : SpecificDeviceMessageBase { diff --git a/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs index 71f439a6..7856e198 100644 --- a/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Device.Flipper +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Flipper { public class FlipperDeviceMessageHandler : SpecificDeviceMessageHandler diff --git a/Runtime/MediaController/Messages/Device/Light/LightDeviceMessage.cs b/Runtime/MediaController/Messages/Device/Light/LightDeviceMessage.cs index 0985637a..cccf60d2 100644 --- a/Runtime/MediaController/Messages/Device/Light/LightDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/Light/LightDeviceMessage.cs @@ -1,7 +1,7 @@ using System; using UnityEngine; -namespace FutureBoxSystems.MpfMediaController.Messages.Device.Light +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Light { public class LightDeviceMessage : SpecificDeviceMessageBase { diff --git a/Runtime/MediaController/Messages/Device/Light/LightDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/Light/LightDeviceMessageHandler.cs index 1cda28ea..0d1753f7 100644 --- a/Runtime/MediaController/Messages/Device/Light/LightDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/Light/LightDeviceMessageHandler.cs @@ -1,7 +1,7 @@ using System; using UnityEngine; -namespace FutureBoxSystems.MpfMediaController.Messages.Device.Light +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Light { public class LightDeviceMessageHandler : SpecificDeviceMessageHandler diff --git a/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessage.cs b/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessage.cs index 6f598398..13ee92d6 100644 --- a/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessage.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.Device.Playfield +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Playfield { public class PlayfieldDeviceMessage : SpecificDeviceMessageBase { diff --git a/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs index e68cf592..ce01aa61 100644 --- a/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Device.Playfield +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Playfield { public class PlayfieldDeviceMessageHandler : SpecificDeviceMessageHandler diff --git a/Runtime/MediaController/Messages/Device/SpecificDeviceMessageBase.cs b/Runtime/MediaController/Messages/Device/SpecificDeviceMessageBase.cs index 68e03ce9..69b5b3e3 100644 --- a/Runtime/MediaController/Messages/Device/SpecificDeviceMessageBase.cs +++ b/Runtime/MediaController/Messages/Device/SpecificDeviceMessageBase.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Device +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device { public abstract class SpecificDeviceMessageBase : EventArgs { diff --git a/Runtime/MediaController/Messages/Device/SpecificDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/SpecificDeviceMessageHandler.cs index fe757945..14686032 100644 --- a/Runtime/MediaController/Messages/Device/SpecificDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/SpecificDeviceMessageHandler.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; using UnityEngine; -namespace FutureBoxSystems.MpfMediaController.Messages.Device +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device { public abstract class SpecificDeviceMessageHandler : MonoBehaviour where TMessage : SpecificDeviceMessageBase diff --git a/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessage.cs b/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessage.cs index ba529e00..790c7bc4 100644 --- a/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessage.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.Device.Switch +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Switch { public class SwitchDeviceMessage : SpecificDeviceMessageBase { diff --git a/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessageHandler.cs index a62b3840..38faf6f8 100644 --- a/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessageHandler.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Device.Switch +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Switch { public class SwitchDeviceMessageHandler : SpecificDeviceMessageHandler diff --git a/Runtime/MediaController/Messages/Error/ErrorMessage.cs b/Runtime/MediaController/Messages/Error/ErrorMessage.cs index ad72f880..85bb2978 100644 --- a/Runtime/MediaController/Messages/Error/ErrorMessage.cs +++ b/Runtime/MediaController/Messages/Error/ErrorMessage.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json.Linq; -namespace FutureBoxSystems.MpfMediaController.Messages.Error +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Error { public class ErrorMessage : EventArgs, ISentMessage { diff --git a/Runtime/MediaController/Messages/Error/ErrorMessageHandler.cs b/Runtime/MediaController/Messages/Error/ErrorMessageHandler.cs index 6d9736c6..3f2f05b9 100644 --- a/Runtime/MediaController/Messages/Error/ErrorMessageHandler.cs +++ b/Runtime/MediaController/Messages/Error/ErrorMessageHandler.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.Error +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Error { public class ErrorMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Goodbye/GoodbyeMessage.cs b/Runtime/MediaController/Messages/Goodbye/GoodbyeMessage.cs index 57418b6d..458aa0c6 100644 --- a/Runtime/MediaController/Messages/Goodbye/GoodbyeMessage.cs +++ b/Runtime/MediaController/Messages/Goodbye/GoodbyeMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Goodbye +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Goodbye { public class GoodbyeMessage : EventArgs, ISentMessage { diff --git a/Runtime/MediaController/Messages/Goodbye/GoodbyeMessageHandler.cs b/Runtime/MediaController/Messages/Goodbye/GoodbyeMessageHandler.cs index a842879d..433f4a68 100644 --- a/Runtime/MediaController/Messages/Goodbye/GoodbyeMessageHandler.cs +++ b/Runtime/MediaController/Messages/Goodbye/GoodbyeMessageHandler.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.Goodbye +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Goodbye { public class GoodbyeMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Hello/HelloMessage.cs b/Runtime/MediaController/Messages/Hello/HelloMessage.cs index 32f7293b..ae23f19a 100644 --- a/Runtime/MediaController/Messages/Hello/HelloMessage.cs +++ b/Runtime/MediaController/Messages/Hello/HelloMessage.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json.Linq; -namespace FutureBoxSystems.MpfMediaController.Messages.Hello +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Hello { public class HelloMessage : EventArgs, ISentMessage { diff --git a/Runtime/MediaController/Messages/Hello/HelloMessageHandler.cs b/Runtime/MediaController/Messages/Hello/HelloMessageHandler.cs index d526facd..b96826d0 100644 --- a/Runtime/MediaController/Messages/Hello/HelloMessageHandler.cs +++ b/Runtime/MediaController/Messages/Hello/HelloMessageHandler.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.Hello +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Hello { public class HelloMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessage.cs b/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessage.cs index b5facdce..dfb8a3b9 100644 --- a/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessage.cs +++ b/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessage.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json.Linq; -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar { public class MachineVariableMessage : MpfVariableMessageBase { diff --git a/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessageHandler.cs b/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessageHandler.cs index 0df76114..974089b2 100644 --- a/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessageHandler.cs +++ b/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessageHandler.cs @@ -1,6 +1,6 @@ -using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar { public class MachineVariableMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/MachineVariable/MachineVariableMonitor.cs b/Runtime/MediaController/Messages/MachineVariable/MachineVariableMonitor.cs index 43e57e50..54a1d0a8 100644 --- a/Runtime/MediaController/Messages/MachineVariable/MachineVariableMonitor.cs +++ b/Runtime/MediaController/Messages/MachineVariable/MachineVariableMonitor.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar { public abstract class MachineVariableMonitor : MpfVariableMonitorBase diff --git a/Runtime/MediaController/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs b/Runtime/MediaController/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs index c8a7b37b..d54740e4 100644 --- a/Runtime/MediaController/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs +++ b/Runtime/MediaController/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar { public class BoolMachineVariableMonitor : MachineVariableMonitor { } } diff --git a/Runtime/MediaController/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs b/Runtime/MediaController/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs index 125b26cd..87314924 100644 --- a/Runtime/MediaController/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs +++ b/Runtime/MediaController/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar.Primitive { public class FloatMachineVarableMonitor : MachineVariableMonitor { } } diff --git a/Runtime/MediaController/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs b/Runtime/MediaController/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs index 258acb4e..27aec2ce 100644 --- a/Runtime/MediaController/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs +++ b/Runtime/MediaController/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar.Primitive { public class IntMachineVariableMonitor : MachineVariableMonitor { } } diff --git a/Runtime/MediaController/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs b/Runtime/MediaController/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs index 8d0f7241..4edca301 100644 --- a/Runtime/MediaController/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs +++ b/Runtime/MediaController/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.MachineVar.Primitive +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar.Primitive { public class StringMachineVariableMonitor : MachineVariableMonitor { } } diff --git a/Runtime/MediaController/Messages/Mode/Mode.cs b/Runtime/MediaController/Messages/Mode/Mode.cs index e7b83ed5..c9ad14b6 100644 --- a/Runtime/MediaController/Messages/Mode/Mode.cs +++ b/Runtime/MediaController/Messages/Mode/Mode.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.Mode +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode { public readonly struct Mode { diff --git a/Runtime/MediaController/Messages/Mode/ModeListMessage.cs b/Runtime/MediaController/Messages/Mode/ModeListMessage.cs index 4ff8ec20..787570b1 100644 --- a/Runtime/MediaController/Messages/Mode/ModeListMessage.cs +++ b/Runtime/MediaController/Messages/Mode/ModeListMessage.cs @@ -3,7 +3,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -namespace FutureBoxSystems.MpfMediaController.Messages.Mode +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode { public class ModeListMessage : EventArgs { diff --git a/Runtime/MediaController/Messages/Mode/ModeListMessageHandler.cs b/Runtime/MediaController/Messages/Mode/ModeListMessageHandler.cs index 6e2de2f5..053ff7ab 100644 --- a/Runtime/MediaController/Messages/Mode/ModeListMessageHandler.cs +++ b/Runtime/MediaController/Messages/Mode/ModeListMessageHandler.cs @@ -1,6 +1,6 @@ -using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; -namespace FutureBoxSystems.MpfMediaController.Messages.Mode +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode { public class ModeListMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Mode/ModeMonitor.cs b/Runtime/MediaController/Messages/Mode/ModeMonitor.cs index f96665dc..08367545 100644 --- a/Runtime/MediaController/Messages/Mode/ModeMonitor.cs +++ b/Runtime/MediaController/Messages/Mode/ModeMonitor.cs @@ -1,7 +1,7 @@ using System; using UnityEngine; -namespace FutureBoxSystems.MpfMediaController.Messages.Mode +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode { public class ModeMonitor : MonoBehaviour { diff --git a/Runtime/MediaController/Messages/Mode/ModeStartMessage.cs b/Runtime/MediaController/Messages/Mode/ModeStartMessage.cs index f7f7848c..31e853f4 100644 --- a/Runtime/MediaController/Messages/Mode/ModeStartMessage.cs +++ b/Runtime/MediaController/Messages/Mode/ModeStartMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Mode +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode { public class ModeStartMessage : EventArgs { diff --git a/Runtime/MediaController/Messages/Mode/ModeStartMessageHandler.cs b/Runtime/MediaController/Messages/Mode/ModeStartMessageHandler.cs index 5681b2a9..0ca73484 100644 --- a/Runtime/MediaController/Messages/Mode/ModeStartMessageHandler.cs +++ b/Runtime/MediaController/Messages/Mode/ModeStartMessageHandler.cs @@ -1,6 +1,6 @@ -using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; -namespace FutureBoxSystems.MpfMediaController.Messages.Mode +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode { public class ModeStartMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Mode/ModeStopMessage.cs b/Runtime/MediaController/Messages/Mode/ModeStopMessage.cs index 135b4585..f69e5b25 100644 --- a/Runtime/MediaController/Messages/Mode/ModeStopMessage.cs +++ b/Runtime/MediaController/Messages/Mode/ModeStopMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Mode +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode { public class ModeStopMessage : EventArgs { diff --git a/Runtime/MediaController/Messages/Mode/ModeStopMessageHandler.cs b/Runtime/MediaController/Messages/Mode/ModeStopMessageHandler.cs index 8aa8a4f2..b4548554 100644 --- a/Runtime/MediaController/Messages/Mode/ModeStopMessageHandler.cs +++ b/Runtime/MediaController/Messages/Mode/ModeStopMessageHandler.cs @@ -1,6 +1,6 @@ -using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; -namespace FutureBoxSystems.MpfMediaController.Messages.Mode +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode { public class ModeStopMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Monitor/MonitorStartMessage.cs b/Runtime/MediaController/Messages/Monitor/MonitorStartMessage.cs index 9768ad1f..1a23220d 100644 --- a/Runtime/MediaController/Messages/Monitor/MonitorStartMessage.cs +++ b/Runtime/MediaController/Messages/Monitor/MonitorStartMessage.cs @@ -3,7 +3,7 @@ using Newtonsoft.Json.Linq; using UnityEngine; -namespace FutureBoxSystems.MpfMediaController.Messages.Monitor +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor { public class MonitorStartMessage : EventArgs, ISentMessage { diff --git a/Runtime/MediaController/Messages/Monitor/MonitorStopMessage.cs b/Runtime/MediaController/Messages/Monitor/MonitorStopMessage.cs index df251c83..47c29a09 100644 --- a/Runtime/MediaController/Messages/Monitor/MonitorStopMessage.cs +++ b/Runtime/MediaController/Messages/Monitor/MonitorStopMessage.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json.Linq; using UnityEngine; -namespace FutureBoxSystems.MpfMediaController.Messages.Monitor +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor { public class MonitorStopMessage : EventArgs, ISentMessage { diff --git a/Runtime/MediaController/Messages/Monitor/MonitoringCategory.cs b/Runtime/MediaController/Messages/Monitor/MonitoringCategory.cs index 9cbb1869..e5fa4000 100644 --- a/Runtime/MediaController/Messages/Monitor/MonitoringCategory.cs +++ b/Runtime/MediaController/Messages/Monitor/MonitoringCategory.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.Monitor +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor { public enum MonitoringCategory { diff --git a/Runtime/MediaController/Messages/MonitorBase.cs b/Runtime/MediaController/Messages/MonitorBase.cs index 6288dc8b..4a5637ec 100644 --- a/Runtime/MediaController/Messages/MonitorBase.cs +++ b/Runtime/MediaController/Messages/MonitorBase.cs @@ -1,8 +1,8 @@ using System; -using FutureBoxSystems.MpfMediaController.Messages.Reset; using UnityEngine; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Reset; -namespace FutureBoxSystems.MpfMediaController.Messages +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages { public abstract class MonitorBase : MonoBehaviour { diff --git a/Runtime/MediaController/Messages/MpfVariableMessageBase.cs b/Runtime/MediaController/Messages/MpfVariableMessageBase.cs index 69913f63..de15cded 100644 --- a/Runtime/MediaController/Messages/MpfVariableMessageBase.cs +++ b/Runtime/MediaController/Messages/MpfVariableMessageBase.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json.Linq; -namespace FutureBoxSystems.MpfMediaController.Messages +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages { public abstract class MpfVariableMessageBase : EventArgs { diff --git a/Runtime/MediaController/Messages/MpfVariableMonitorBase.cs b/Runtime/MediaController/Messages/MpfVariableMonitorBase.cs index ed185acd..4d567d00 100644 --- a/Runtime/MediaController/Messages/MpfVariableMonitorBase.cs +++ b/Runtime/MediaController/Messages/MpfVariableMonitorBase.cs @@ -1,7 +1,7 @@ using System; using UnityEngine; -namespace FutureBoxSystems.MpfMediaController.Messages +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages { public abstract class MpfVariableMonitorBase : MonitorBase where TVar : IEquatable diff --git a/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessage.cs b/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessage.cs index 1fd1f7aa..6b1b86c9 100644 --- a/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessage.cs +++ b/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.PlayerAdded +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerAdded { public class PlayerAddedMessage : EventArgs { diff --git a/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessageHandler.cs b/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessageHandler.cs index df9faf7f..f00c315e 100644 --- a/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessageHandler.cs +++ b/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessageHandler.cs @@ -1,6 +1,6 @@ -using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; -namespace FutureBoxSystems.MpfMediaController.Messages.PlayerAdded +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerAdded { public class PlayerAddedMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/PlayerAdded/PlayerCountMonitor.cs b/Runtime/MediaController/Messages/PlayerAdded/PlayerCountMonitor.cs index 9f8f1153..e3653a1c 100644 --- a/Runtime/MediaController/Messages/PlayerAdded/PlayerCountMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerAdded/PlayerCountMonitor.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.PlayerAdded +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerAdded { public class PlayerCountMonitor : MonitorBase { diff --git a/Runtime/MediaController/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs b/Runtime/MediaController/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs index 53a760e1..9c7fa197 100644 --- a/Runtime/MediaController/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.PlayerTurnStart +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerTurnStart { public class CurrentPlayerMonitor : MonitorBase { diff --git a/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs b/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs index 03bc4392..a1a011c5 100644 --- a/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs +++ b/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.PlayerTurnStart +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerTurnStart { public class PlayerTurnStartMessage : EventArgs { diff --git a/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs b/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs index 8412a388..b0dad554 100644 --- a/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs +++ b/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs @@ -1,6 +1,6 @@ -using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; -namespace FutureBoxSystems.MpfMediaController.Messages.PlayerTurnStart +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerTurnStart { public class PlayerTurnStartMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs b/Runtime/MediaController/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs index 1c18dcc2..c048a140 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerVariable { public class BoolPlayerVariableMonitor : PlayerVariableMonitor { } } diff --git a/Runtime/MediaController/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs b/Runtime/MediaController/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs index ba29e99b..82de354d 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerVariable { public class FloatPlayerVariableMonitor : PlayerVariableMonitor { } } diff --git a/Runtime/MediaController/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs b/Runtime/MediaController/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs index 2e0eb61b..251ff716 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerVariable { public class IntPlayerVariableMonitor : PlayerVariableMonitor { } } diff --git a/Runtime/MediaController/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs b/Runtime/MediaController/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs index 56d12377..99dc12bb 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerVariable { public class StringPlayerVariableMonitor : PlayerVariableMonitor { } } diff --git a/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessage.cs b/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessage.cs index 45901a34..850a9908 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessage.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessage.cs @@ -1,7 +1,7 @@ -using FutureBoxSystems.MpfMediaController.Messages.MachineVar; using Newtonsoft.Json.Linq; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar; -namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerVariable { public class PlayerVariableMessage : MpfVariableMessageBase { diff --git a/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessageHandler.cs b/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessageHandler.cs index 826e6d7d..ad879ac5 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessageHandler.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessageHandler.cs @@ -1,6 +1,6 @@ -using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; -namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerVariable { public class PlayerVariableMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMonitor.cs b/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMonitor.cs index c547745d..b8aa2473 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMonitor.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; -using FutureBoxSystems.MpfMediaController.Messages.PlayerTurnStart; using UnityEngine; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerTurnStart; -namespace FutureBoxSystems.MpfMediaController.Messages.PlayerVariable +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerVariable { public abstract class PlayerVariableMonitor : MpfVariableMonitorBase diff --git a/Runtime/MediaController/Messages/Reset/ResetCompleteMessage.cs b/Runtime/MediaController/Messages/Reset/ResetCompleteMessage.cs index 01225da3..10411506 100644 --- a/Runtime/MediaController/Messages/Reset/ResetCompleteMessage.cs +++ b/Runtime/MediaController/Messages/Reset/ResetCompleteMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Reset +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Reset { public class ResetCompleteMessage : EventArgs, ISentMessage { diff --git a/Runtime/MediaController/Messages/Reset/ResetMessage.cs b/Runtime/MediaController/Messages/Reset/ResetMessage.cs index 8fb8bb43..87d33ee9 100644 --- a/Runtime/MediaController/Messages/Reset/ResetMessage.cs +++ b/Runtime/MediaController/Messages/Reset/ResetMessage.cs @@ -1,6 +1,6 @@ using System; -namespace FutureBoxSystems.MpfMediaController.Messages.Reset +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Reset { public class ResetMessage : EventArgs { diff --git a/Runtime/MediaController/Messages/Reset/ResetMessageHandler.cs b/Runtime/MediaController/Messages/Reset/ResetMessageHandler.cs index e9b0443d..0ff05325 100644 --- a/Runtime/MediaController/Messages/Reset/ResetMessageHandler.cs +++ b/Runtime/MediaController/Messages/Reset/ResetMessageHandler.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.Reset +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Reset { public class ResetMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Settings/SettingsMessage.cs b/Runtime/MediaController/Messages/Settings/SettingsMessage.cs index 73149e4d..7c28d2f8 100644 --- a/Runtime/MediaController/Messages/Settings/SettingsMessage.cs +++ b/Runtime/MediaController/Messages/Settings/SettingsMessage.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json.Linq; -namespace FutureBoxSystems.MpfMediaController.Messages.Settings +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Settings { public class SettingsMessage : EventArgs { diff --git a/Runtime/MediaController/Messages/Settings/SettingsMessageHandler.cs b/Runtime/MediaController/Messages/Settings/SettingsMessageHandler.cs index 0a7cb4a0..bfa877a5 100644 --- a/Runtime/MediaController/Messages/Settings/SettingsMessageHandler.cs +++ b/Runtime/MediaController/Messages/Settings/SettingsMessageHandler.cs @@ -1,6 +1,6 @@ -using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; -namespace FutureBoxSystems.MpfMediaController.Messages.Settings +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Settings { public class SettingsMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Switch/SwitchMessage.cs b/Runtime/MediaController/Messages/Switch/SwitchMessage.cs index 59599658..849d770f 100644 --- a/Runtime/MediaController/Messages/Switch/SwitchMessage.cs +++ b/Runtime/MediaController/Messages/Switch/SwitchMessage.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json.Linq; -namespace FutureBoxSystems.MpfMediaController.Messages.Switch +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Switch { public class SwitchMessage : EventArgs, ISentMessage { diff --git a/Runtime/MediaController/Messages/Switch/SwitchMessageHandler.cs b/Runtime/MediaController/Messages/Switch/SwitchMessageHandler.cs index e6a98992..ee12f587 100644 --- a/Runtime/MediaController/Messages/Switch/SwitchMessageHandler.cs +++ b/Runtime/MediaController/Messages/Switch/SwitchMessageHandler.cs @@ -1,6 +1,6 @@ -using FutureBoxSystems.MpfMediaController.Messages.Monitor; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; -namespace FutureBoxSystems.MpfMediaController.Messages.Switch +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Switch { public class SwitchMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Switch/SwitchMonitor.cs b/Runtime/MediaController/Messages/Switch/SwitchMonitor.cs index a3c13d32..0bb7f409 100644 --- a/Runtime/MediaController/Messages/Switch/SwitchMonitor.cs +++ b/Runtime/MediaController/Messages/Switch/SwitchMonitor.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace FutureBoxSystems.MpfMediaController.Messages.Switch +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Switch { public class SwitchMonitor : MonitorBase { diff --git a/Runtime/MediaController/Messages/Trigger/MpfEventListener.cs b/Runtime/MediaController/Messages/Trigger/MpfEventListener.cs index 9f79480b..31f60281 100644 --- a/Runtime/MediaController/Messages/Trigger/MpfEventListener.cs +++ b/Runtime/MediaController/Messages/Trigger/MpfEventListener.cs @@ -1,7 +1,7 @@ using System; using UnityEngine; -namespace FutureBoxSystems.MpfMediaController.Messages.Trigger +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Trigger { public class MpfEventListener : MonoBehaviour { diff --git a/Runtime/MediaController/Messages/Trigger/RegisterTriggerMessage.cs b/Runtime/MediaController/Messages/Trigger/RegisterTriggerMessage.cs index 2e13db68..a247d6be 100644 --- a/Runtime/MediaController/Messages/Trigger/RegisterTriggerMessage.cs +++ b/Runtime/MediaController/Messages/Trigger/RegisterTriggerMessage.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json.Linq; -namespace FutureBoxSystems.MpfMediaController.Messages.Trigger +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Trigger { public class RegisterTriggerMessage : EventArgs, ISentMessage { diff --git a/Runtime/MediaController/Messages/Trigger/RemoveTriggerMessage.cs b/Runtime/MediaController/Messages/Trigger/RemoveTriggerMessage.cs index cecd48e2..79473244 100644 --- a/Runtime/MediaController/Messages/Trigger/RemoveTriggerMessage.cs +++ b/Runtime/MediaController/Messages/Trigger/RemoveTriggerMessage.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json.Linq; -namespace FutureBoxSystems.MpfMediaController.Messages.Trigger +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Trigger { public class RemoveTriggerMessage : EventArgs, ISentMessage { diff --git a/Runtime/MediaController/Messages/Trigger/TriggerMessage.cs b/Runtime/MediaController/Messages/Trigger/TriggerMessage.cs index 13a29a6d..4f7ac256 100644 --- a/Runtime/MediaController/Messages/Trigger/TriggerMessage.cs +++ b/Runtime/MediaController/Messages/Trigger/TriggerMessage.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json.Linq; -namespace FutureBoxSystems.MpfMediaController.Messages.Trigger +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Trigger { public class TriggerMessage : EventArgs, ISentMessage { diff --git a/Runtime/MediaController/Messages/Trigger/TriggerMessageHandler.cs b/Runtime/MediaController/Messages/Trigger/TriggerMessageHandler.cs index af4a956a..18e2cdd0 100644 --- a/Runtime/MediaController/Messages/Trigger/TriggerMessageHandler.cs +++ b/Runtime/MediaController/Messages/Trigger/TriggerMessageHandler.cs @@ -1,4 +1,4 @@ -namespace FutureBoxSystems.MpfMediaController.Messages.Trigger +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Trigger { public class TriggerMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Ui/MonitoredVariableText.cs b/Runtime/MediaController/Ui/MonitoredVariableText.cs index 34a3cbb6..861ba3cb 100644 --- a/Runtime/MediaController/Ui/MonitoredVariableText.cs +++ b/Runtime/MediaController/Ui/MonitoredVariableText.cs @@ -1,8 +1,8 @@ -using FutureBoxSystems.MpfMediaController.Messages; using TMPro; using UnityEngine; +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages; -namespace FutureBoxSystems.Ui +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Ui { [RequireComponent(typeof(TextMeshProUGUI))] public class MonitoredVariableText : MonoBehaviour diff --git a/Runtime/MediaController/Utils/StringEnum.cs b/Runtime/MediaController/Utils/StringEnum.cs index 8bb766aa..8d235324 100644 --- a/Runtime/MediaController/Utils/StringEnum.cs +++ b/Runtime/MediaController/Utils/StringEnum.cs @@ -2,7 +2,7 @@ using System; using System.Reflection; -namespace FutureBoxSystems.MpfMediaController +namespace VisualPinball.Engine.Mpf.Unity.MediaController { /// /// Associates an enum value with a string From 1f60ede1a974559249b865a405b821a927b625ca Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Tue, 18 Feb 2025 22:55:31 +0100 Subject: [PATCH 82/98] Add license preamble to all new code files --- .../Behaviors/DisconnectOnGoodbyeReceived.cs | 11 +++++++++++ Runtime/MediaController/Behaviors/HelloResponse.cs | 11 +++++++++++ Runtime/MediaController/Core/BcpInterface.cs | 11 +++++++++++ Runtime/MediaController/Core/BcpMessage.cs | 11 +++++++++++ Runtime/MediaController/Core/BcpMessageHandler.cs | 13 ++++++++++++- Runtime/MediaController/Core/BcpServer.cs | 11 +++++++++++ Runtime/MediaController/Core/Constants.cs | 11 +++++++++++ Runtime/MediaController/Core/Exceptions.cs | 13 ++++++++++++- Runtime/MediaController/Core/MpfEventRequester.cs | 11 +++++++++++ .../Messages/Ball/BallEndMessage.cs | 13 ++++++++++++- .../Messages/Ball/BallEndMessageHandler.cs | 13 ++++++++++++- .../Messages/Ball/BallStartMessage.cs | 13 ++++++++++++- .../Messages/Ball/BallStartMessageHandler.cs | 13 ++++++++++++- .../Device/Autofire/AutofireDeviceMessage.cs | 13 ++++++++++++- .../Autofire/AutofireDeviceMessageHandler.cs | 13 ++++++++++++- .../Device/BallDevice/BallDeviceMessage.cs | 13 ++++++++++++- .../Device/BallDevice/BallDeviceMessageHandler.cs | 13 ++++++++++++- .../Device/ComboSwitch/ComboSwitchDeviceMessage.cs | 11 +++++++++++ .../ComboSwitch/ComboSwitchDeviceMessageHandler.cs | 11 +++++++++++ .../Messages/Device/DeviceAttributeChange.cs | 14 ++++++++++++-- .../Messages/Device/DeviceMessage.cs | 13 ++++++++++++- .../Messages/Device/DeviceMessageExceptions.cs | 13 ++++++++++++- .../Messages/Device/DeviceMessageHandler.cs | 13 ++++++++++++- .../Device/Flipper/FlipperDeviceMessage.cs | 13 ++++++++++++- .../Device/Flipper/FlipperDeviceMessageHandler.cs | 13 ++++++++++++- .../Messages/Device/Light/LightDeviceMessage.cs | 11 +++++++++++ .../Device/Light/LightDeviceMessageHandler.cs | 11 +++++++++++ .../Device/Playfield/PlayfieldDeviceMessage.cs | 13 ++++++++++++- .../Playfield/PlayfieldDeviceMessageHandler.cs | 13 ++++++++++++- .../Messages/Device/SpecificDeviceMessageBase.cs | 13 ++++++++++++- .../Device/SpecificDeviceMessageHandler.cs | 13 ++++++++++++- .../Messages/Device/Switch/SwitchDeviceMessage.cs | 13 ++++++++++++- .../Device/Switch/SwitchDeviceMessageHandler.cs | 13 ++++++++++++- .../MediaController/Messages/Error/ErrorMessage.cs | 13 ++++++++++++- .../Messages/Error/ErrorMessageHandler.cs | 13 ++++++++++++- .../Messages/Goodbye/GoodbyeMessage.cs | 11 +++++++++++ .../Messages/Goodbye/GoodbyeMessageHandler.cs | 13 ++++++++++++- .../MediaController/Messages/Hello/HelloMessage.cs | 11 +++++++++++ .../Messages/Hello/HelloMessageHandler.cs | 13 ++++++++++++- .../MachineVariable/MachineVariableMessage.cs | 11 +++++++++++ .../MachineVariableMessageHandler.cs | 11 +++++++++++ .../MachineVariable/MachineVariableMonitor.cs | 11 +++++++++++ .../Monitor/BoolMachineVariableMonitor.cs | 11 +++++++++++ .../Monitor/FloatMachineVarableMonitor.cs | 11 +++++++++++ .../Monitor/IntMachineVariableMonitor.cs | 11 +++++++++++ .../Monitor/StringMachineVariableMonitor.cs | 11 +++++++++++ Runtime/MediaController/Messages/Mode/Mode.cs | 11 +++++++++++ .../Messages/Mode/ModeListMessage.cs | 11 +++++++++++ .../Messages/Mode/ModeListMessageHandler.cs | 11 +++++++++++ .../MediaController/Messages/Mode/ModeMonitor.cs | 11 +++++++++++ .../Messages/Mode/ModeStartMessage.cs | 11 +++++++++++ .../Messages/Mode/ModeStartMessageHandler.cs | 11 +++++++++++ .../Messages/Mode/ModeStopMessage.cs | 11 +++++++++++ .../Messages/Mode/ModeStopMessageHandler.cs | 11 +++++++++++ .../Messages/Monitor/MonitorStartMessage.cs | 13 ++++++++++++- .../Messages/Monitor/MonitorStopMessage.cs | 13 ++++++++++++- .../Messages/Monitor/MonitoringCategory.cs | 13 ++++++++++++- Runtime/MediaController/Messages/MonitorBase.cs | 11 +++++++++++ .../Messages/MpfVariableMessageBase.cs | 11 +++++++++++ .../Messages/MpfVariableMonitorBase.cs | 11 +++++++++++ .../Messages/PlayerAdded/PlayerAddedMessage.cs | 11 +++++++++++ .../PlayerAdded/PlayerAddedMessageHandler.cs | 11 +++++++++++ .../Messages/PlayerAdded/PlayerCountMonitor.cs | 11 +++++++++++ .../PlayerTurnStart/CurrentPlayerMonitor.cs | 11 +++++++++++ .../PlayerTurnStart/PlayerTurnStartMessage.cs | 11 +++++++++++ .../PlayerTurnStartMessageHandler.cs | 11 +++++++++++ .../Monitor/BoolPlayerVariableMonitor.cs | 11 +++++++++++ .../Monitor/FloatPlayerVariableMonitor.cs | 11 +++++++++++ .../Monitor/IntPlayerVariableMonitor.cs | 11 +++++++++++ .../Monitor/StringPlayerVariableMonitor.cs | 11 +++++++++++ .../PlayerVariable/PlayerVariableMessage.cs | 11 +++++++++++ .../PlayerVariable/PlayerVariableMessageHandler.cs | 11 +++++++++++ .../PlayerVariable/PlayerVariableMonitor.cs | 11 +++++++++++ .../Messages/Reset/ResetCompleteMessage.cs | 13 ++++++++++++- .../MediaController/Messages/Reset/ResetMessage.cs | 13 ++++++++++++- .../Messages/Reset/ResetMessageHandler.cs | 13 ++++++++++++- .../Messages/Settings/SettingsMessage.cs | 11 +++++++++++ .../Messages/Settings/SettingsMessageHandler.cs | 11 +++++++++++ .../Messages/Switch/SwitchMessage.cs | 11 +++++++++++ .../Messages/Switch/SwitchMessageHandler.cs | 11 +++++++++++ .../Messages/Switch/SwitchMonitor.cs | 11 +++++++++++ .../Messages/Trigger/MpfEventListener.cs | 11 +++++++++++ .../Messages/Trigger/RegisterTriggerMessage.cs | 11 +++++++++++ .../Messages/Trigger/RemoveTriggerMessage.cs | 11 +++++++++++ .../Messages/Trigger/TriggerMessage.cs | 11 +++++++++++ .../Messages/Trigger/TriggerMessageHandler.cs | 11 +++++++++++ .../MediaController/Ui/MonitoredVariableText.cs | 11 +++++++++++ Runtime/MediaController/Utils/StringEnum.cs | 13 ++++++++++++- 88 files changed, 1001 insertions(+), 34 deletions(-) diff --git a/Runtime/MediaController/Behaviors/DisconnectOnGoodbyeReceived.cs b/Runtime/MediaController/Behaviors/DisconnectOnGoodbyeReceived.cs index 97f4b1ce..55f7a39a 100644 --- a/Runtime/MediaController/Behaviors/DisconnectOnGoodbyeReceived.cs +++ b/Runtime/MediaController/Behaviors/DisconnectOnGoodbyeReceived.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using UnityEngine; using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Goodbye; diff --git a/Runtime/MediaController/Behaviors/HelloResponse.cs b/Runtime/MediaController/Behaviors/HelloResponse.cs index d34f8df9..5a44adaf 100644 --- a/Runtime/MediaController/Behaviors/HelloResponse.cs +++ b/Runtime/MediaController/Behaviors/HelloResponse.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using UnityEngine; using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Error; using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Hello; diff --git a/Runtime/MediaController/Core/BcpInterface.cs b/Runtime/MediaController/Core/BcpInterface.cs index 8ac01346..34fe53d6 100644 --- a/Runtime/MediaController/Core/BcpInterface.cs +++ b/Runtime/MediaController/Core/BcpInterface.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using System.Collections.Generic; using UnityEngine; diff --git a/Runtime/MediaController/Core/BcpMessage.cs b/Runtime/MediaController/Core/BcpMessage.cs index b87620d7..3301aec8 100644 --- a/Runtime/MediaController/Core/BcpMessage.cs +++ b/Runtime/MediaController/Core/BcpMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using System.Collections.Generic; using System.Linq; diff --git a/Runtime/MediaController/Core/BcpMessageHandler.cs b/Runtime/MediaController/Core/BcpMessageHandler.cs index 09199e72..ce225cb2 100644 --- a/Runtime/MediaController/Core/BcpMessageHandler.cs +++ b/Runtime/MediaController/Core/BcpMessageHandler.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; using UnityEngine; using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; diff --git a/Runtime/MediaController/Core/BcpServer.cs b/Runtime/MediaController/Core/BcpServer.cs index f196b259..06fc3b7a 100644 --- a/Runtime/MediaController/Core/BcpServer.cs +++ b/Runtime/MediaController/Core/BcpServer.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using System.Collections.Generic; using System.Net; diff --git a/Runtime/MediaController/Core/Constants.cs b/Runtime/MediaController/Core/Constants.cs index 5395d16e..15e7ac37 100644 --- a/Runtime/MediaController/Core/Constants.cs +++ b/Runtime/MediaController/Core/Constants.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController { public static class Constants diff --git a/Runtime/MediaController/Core/Exceptions.cs b/Runtime/MediaController/Core/Exceptions.cs index 3b6e8a90..b33476da 100644 --- a/Runtime/MediaController/Core/Exceptions.cs +++ b/Runtime/MediaController/Core/Exceptions.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController { diff --git a/Runtime/MediaController/Core/MpfEventRequester.cs b/Runtime/MediaController/Core/MpfEventRequester.cs index 012b7e1e..49c21685 100644 --- a/Runtime/MediaController/Core/MpfEventRequester.cs +++ b/Runtime/MediaController/Core/MpfEventRequester.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System.Collections.Generic; using UnityEngine; diff --git a/Runtime/MediaController/Messages/Ball/BallEndMessage.cs b/Runtime/MediaController/Messages/Ball/BallEndMessage.cs index c099f601..eab33d2b 100644 --- a/Runtime/MediaController/Messages/Ball/BallEndMessage.cs +++ b/Runtime/MediaController/Messages/Ball/BallEndMessage.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Ball { diff --git a/Runtime/MediaController/Messages/Ball/BallEndMessageHandler.cs b/Runtime/MediaController/Messages/Ball/BallEndMessageHandler.cs index b935fdd4..8dec4474 100644 --- a/Runtime/MediaController/Messages/Ball/BallEndMessageHandler.cs +++ b/Runtime/MediaController/Messages/Ball/BallEndMessageHandler.cs @@ -1,4 +1,15 @@ -using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Ball { diff --git a/Runtime/MediaController/Messages/Ball/BallStartMessage.cs b/Runtime/MediaController/Messages/Ball/BallStartMessage.cs index 0f6bf651..1da60f2f 100644 --- a/Runtime/MediaController/Messages/Ball/BallStartMessage.cs +++ b/Runtime/MediaController/Messages/Ball/BallStartMessage.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Ball { diff --git a/Runtime/MediaController/Messages/Ball/BallStartMessageHandler.cs b/Runtime/MediaController/Messages/Ball/BallStartMessageHandler.cs index d0a5987c..6b863a42 100644 --- a/Runtime/MediaController/Messages/Ball/BallStartMessageHandler.cs +++ b/Runtime/MediaController/Messages/Ball/BallStartMessageHandler.cs @@ -1,4 +1,15 @@ -using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Ball { diff --git a/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessage.cs b/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessage.cs index cab06342..22a080b7 100644 --- a/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessage.cs @@ -1,4 +1,15 @@ -namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Autofire +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Autofire { public class AutofireDeviceMessage : SpecificDeviceMessageBase { diff --git a/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs index 2b926e23..caa9ed1c 100644 --- a/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/Autofire/AutofireDeviceMessageHandler.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Autofire { diff --git a/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessage.cs b/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessage.cs index eaa20bae..4881c03e 100644 --- a/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessage.cs @@ -1,4 +1,15 @@ -namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.BallDevice +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.BallDevice { public class BallDeviceMessage : SpecificDeviceMessageBase { diff --git a/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessageHandler.cs index f56f3823..5ea9f69f 100644 --- a/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/BallDevice/BallDeviceMessageHandler.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.BallDevice { diff --git a/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs b/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs index ef2dd30e..7303b221 100644 --- a/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.ComboSwitch { public class ComboSwitchDeviceMessage : SpecificDeviceMessageBase diff --git a/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs index eb0962ae..9d1a3598 100644 --- a/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/ComboSwitch/ComboSwitchDeviceMessageHandler.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.ComboSwitch diff --git a/Runtime/MediaController/Messages/Device/DeviceAttributeChange.cs b/Runtime/MediaController/Messages/Device/DeviceAttributeChange.cs index c340c3a9..ef118075 100644 --- a/Runtime/MediaController/Messages/Device/DeviceAttributeChange.cs +++ b/Runtime/MediaController/Messages/Device/DeviceAttributeChange.cs @@ -1,5 +1,15 @@ -using System; -using System.Runtime.InteropServices.WindowsRuntime; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; using Newtonsoft.Json; using UnityEngine; diff --git a/Runtime/MediaController/Messages/Device/DeviceMessage.cs b/Runtime/MediaController/Messages/Device/DeviceMessage.cs index bd987af1..4f8d2b76 100644 --- a/Runtime/MediaController/Messages/Device/DeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/DeviceMessage.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; using Newtonsoft.Json.Linq; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device diff --git a/Runtime/MediaController/Messages/Device/DeviceMessageExceptions.cs b/Runtime/MediaController/Messages/Device/DeviceMessageExceptions.cs index f7047bd3..8095a031 100644 --- a/Runtime/MediaController/Messages/Device/DeviceMessageExceptions.cs +++ b/Runtime/MediaController/Messages/Device/DeviceMessageExceptions.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device { diff --git a/Runtime/MediaController/Messages/Device/DeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/DeviceMessageHandler.cs index 481ea0e4..7d5b008d 100644 --- a/Runtime/MediaController/Messages/Device/DeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/DeviceMessageHandler.cs @@ -1,4 +1,15 @@ -using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device { diff --git a/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessage.cs b/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessage.cs index 3006fe8c..230d590e 100644 --- a/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessage.cs @@ -1,4 +1,15 @@ -namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Flipper +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Flipper { public class FlipperDeviceMessage : SpecificDeviceMessageBase { diff --git a/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs index 7856e198..cb4bc891 100644 --- a/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/Flipper/FlipperDeviceMessageHandler.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Flipper { diff --git a/Runtime/MediaController/Messages/Device/Light/LightDeviceMessage.cs b/Runtime/MediaController/Messages/Device/Light/LightDeviceMessage.cs index cccf60d2..b566a456 100644 --- a/Runtime/MediaController/Messages/Device/Light/LightDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/Light/LightDeviceMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using UnityEngine; diff --git a/Runtime/MediaController/Messages/Device/Light/LightDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/Light/LightDeviceMessageHandler.cs index 0d1753f7..2d287003 100644 --- a/Runtime/MediaController/Messages/Device/Light/LightDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/Light/LightDeviceMessageHandler.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using UnityEngine; diff --git a/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessage.cs b/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessage.cs index 13ee92d6..eedd5b72 100644 --- a/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessage.cs @@ -1,4 +1,15 @@ -namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Playfield +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Playfield { public class PlayfieldDeviceMessage : SpecificDeviceMessageBase { diff --git a/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs index ce01aa61..b6f4fca7 100644 --- a/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/Playfield/PlayfieldDeviceMessageHandler.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Playfield { diff --git a/Runtime/MediaController/Messages/Device/SpecificDeviceMessageBase.cs b/Runtime/MediaController/Messages/Device/SpecificDeviceMessageBase.cs index 69b5b3e3..27707169 100644 --- a/Runtime/MediaController/Messages/Device/SpecificDeviceMessageBase.cs +++ b/Runtime/MediaController/Messages/Device/SpecificDeviceMessageBase.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device { diff --git a/Runtime/MediaController/Messages/Device/SpecificDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/SpecificDeviceMessageHandler.cs index 14686032..dbc3bcfa 100644 --- a/Runtime/MediaController/Messages/Device/SpecificDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/SpecificDeviceMessageHandler.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; using Newtonsoft.Json; using UnityEngine; diff --git a/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessage.cs b/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessage.cs index 790c7bc4..523936de 100644 --- a/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessage.cs +++ b/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessage.cs @@ -1,4 +1,15 @@ -namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Switch +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Switch { public class SwitchDeviceMessage : SpecificDeviceMessageBase { diff --git a/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessageHandler.cs b/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessageHandler.cs index 38faf6f8..2f3199ba 100644 --- a/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessageHandler.cs +++ b/Runtime/MediaController/Messages/Device/Switch/SwitchDeviceMessageHandler.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Device.Switch { diff --git a/Runtime/MediaController/Messages/Error/ErrorMessage.cs b/Runtime/MediaController/Messages/Error/ErrorMessage.cs index 85bb2978..7246d2c1 100644 --- a/Runtime/MediaController/Messages/Error/ErrorMessage.cs +++ b/Runtime/MediaController/Messages/Error/ErrorMessage.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; using Newtonsoft.Json.Linq; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Error diff --git a/Runtime/MediaController/Messages/Error/ErrorMessageHandler.cs b/Runtime/MediaController/Messages/Error/ErrorMessageHandler.cs index 3f2f05b9..aca4dc0c 100644 --- a/Runtime/MediaController/Messages/Error/ErrorMessageHandler.cs +++ b/Runtime/MediaController/Messages/Error/ErrorMessageHandler.cs @@ -1,4 +1,15 @@ -namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Error +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Error { public class ErrorMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Goodbye/GoodbyeMessage.cs b/Runtime/MediaController/Messages/Goodbye/GoodbyeMessage.cs index 458aa0c6..786e0569 100644 --- a/Runtime/MediaController/Messages/Goodbye/GoodbyeMessage.cs +++ b/Runtime/MediaController/Messages/Goodbye/GoodbyeMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Goodbye diff --git a/Runtime/MediaController/Messages/Goodbye/GoodbyeMessageHandler.cs b/Runtime/MediaController/Messages/Goodbye/GoodbyeMessageHandler.cs index 433f4a68..2212389e 100644 --- a/Runtime/MediaController/Messages/Goodbye/GoodbyeMessageHandler.cs +++ b/Runtime/MediaController/Messages/Goodbye/GoodbyeMessageHandler.cs @@ -1,4 +1,15 @@ -namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Goodbye +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Goodbye { public class GoodbyeMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Hello/HelloMessage.cs b/Runtime/MediaController/Messages/Hello/HelloMessage.cs index ae23f19a..570543e8 100644 --- a/Runtime/MediaController/Messages/Hello/HelloMessage.cs +++ b/Runtime/MediaController/Messages/Hello/HelloMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using Newtonsoft.Json.Linq; diff --git a/Runtime/MediaController/Messages/Hello/HelloMessageHandler.cs b/Runtime/MediaController/Messages/Hello/HelloMessageHandler.cs index b96826d0..3729f96f 100644 --- a/Runtime/MediaController/Messages/Hello/HelloMessageHandler.cs +++ b/Runtime/MediaController/Messages/Hello/HelloMessageHandler.cs @@ -1,4 +1,15 @@ -namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Hello +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Hello { public class HelloMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessage.cs b/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessage.cs index dfb8a3b9..5c5b1c6a 100644 --- a/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessage.cs +++ b/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using Newtonsoft.Json.Linq; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar diff --git a/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessageHandler.cs b/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessageHandler.cs index 974089b2..47705c11 100644 --- a/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessageHandler.cs +++ b/Runtime/MediaController/Messages/MachineVariable/MachineVariableMessageHandler.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar diff --git a/Runtime/MediaController/Messages/MachineVariable/MachineVariableMonitor.cs b/Runtime/MediaController/Messages/MachineVariable/MachineVariableMonitor.cs index 54a1d0a8..934edae5 100644 --- a/Runtime/MediaController/Messages/MachineVariable/MachineVariableMonitor.cs +++ b/Runtime/MediaController/Messages/MachineVariable/MachineVariableMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar diff --git a/Runtime/MediaController/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs b/Runtime/MediaController/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs index d54740e4..8ca6a421 100644 --- a/Runtime/MediaController/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs +++ b/Runtime/MediaController/Messages/MachineVariable/Monitor/BoolMachineVariableMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar { public class BoolMachineVariableMonitor : MachineVariableMonitor { } diff --git a/Runtime/MediaController/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs b/Runtime/MediaController/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs index 87314924..726d9b26 100644 --- a/Runtime/MediaController/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs +++ b/Runtime/MediaController/Messages/MachineVariable/Monitor/FloatMachineVarableMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar.Primitive { public class FloatMachineVarableMonitor : MachineVariableMonitor { } diff --git a/Runtime/MediaController/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs b/Runtime/MediaController/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs index 27aec2ce..76b28066 100644 --- a/Runtime/MediaController/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs +++ b/Runtime/MediaController/Messages/MachineVariable/Monitor/IntMachineVariableMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar.Primitive { public class IntMachineVariableMonitor : MachineVariableMonitor { } diff --git a/Runtime/MediaController/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs b/Runtime/MediaController/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs index 4edca301..36109777 100644 --- a/Runtime/MediaController/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs +++ b/Runtime/MediaController/Messages/MachineVariable/Monitor/StringMachineVariableMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar.Primitive { public class StringMachineVariableMonitor : MachineVariableMonitor { } diff --git a/Runtime/MediaController/Messages/Mode/Mode.cs b/Runtime/MediaController/Messages/Mode/Mode.cs index c9ad14b6..baa91030 100644 --- a/Runtime/MediaController/Messages/Mode/Mode.cs +++ b/Runtime/MediaController/Messages/Mode/Mode.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode { public readonly struct Mode diff --git a/Runtime/MediaController/Messages/Mode/ModeListMessage.cs b/Runtime/MediaController/Messages/Mode/ModeListMessage.cs index 787570b1..08c039db 100644 --- a/Runtime/MediaController/Messages/Mode/ModeListMessage.cs +++ b/Runtime/MediaController/Messages/Mode/ModeListMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using System.Collections.ObjectModel; using Newtonsoft.Json; diff --git a/Runtime/MediaController/Messages/Mode/ModeListMessageHandler.cs b/Runtime/MediaController/Messages/Mode/ModeListMessageHandler.cs index 053ff7ab..c05a46cb 100644 --- a/Runtime/MediaController/Messages/Mode/ModeListMessageHandler.cs +++ b/Runtime/MediaController/Messages/Mode/ModeListMessageHandler.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode diff --git a/Runtime/MediaController/Messages/Mode/ModeMonitor.cs b/Runtime/MediaController/Messages/Mode/ModeMonitor.cs index 08367545..292776ac 100644 --- a/Runtime/MediaController/Messages/Mode/ModeMonitor.cs +++ b/Runtime/MediaController/Messages/Mode/ModeMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using UnityEngine; diff --git a/Runtime/MediaController/Messages/Mode/ModeStartMessage.cs b/Runtime/MediaController/Messages/Mode/ModeStartMessage.cs index 31e853f4..5b7d926d 100644 --- a/Runtime/MediaController/Messages/Mode/ModeStartMessage.cs +++ b/Runtime/MediaController/Messages/Mode/ModeStartMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode diff --git a/Runtime/MediaController/Messages/Mode/ModeStartMessageHandler.cs b/Runtime/MediaController/Messages/Mode/ModeStartMessageHandler.cs index 0ca73484..f3d2985e 100644 --- a/Runtime/MediaController/Messages/Mode/ModeStartMessageHandler.cs +++ b/Runtime/MediaController/Messages/Mode/ModeStartMessageHandler.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode diff --git a/Runtime/MediaController/Messages/Mode/ModeStopMessage.cs b/Runtime/MediaController/Messages/Mode/ModeStopMessage.cs index f69e5b25..7f579490 100644 --- a/Runtime/MediaController/Messages/Mode/ModeStopMessage.cs +++ b/Runtime/MediaController/Messages/Mode/ModeStopMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode diff --git a/Runtime/MediaController/Messages/Mode/ModeStopMessageHandler.cs b/Runtime/MediaController/Messages/Mode/ModeStopMessageHandler.cs index b4548554..bf54a4aa 100644 --- a/Runtime/MediaController/Messages/Mode/ModeStopMessageHandler.cs +++ b/Runtime/MediaController/Messages/Mode/ModeStopMessageHandler.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Mode diff --git a/Runtime/MediaController/Messages/Monitor/MonitorStartMessage.cs b/Runtime/MediaController/Messages/Monitor/MonitorStartMessage.cs index 1a23220d..57abe4d6 100644 --- a/Runtime/MediaController/Messages/Monitor/MonitorStartMessage.cs +++ b/Runtime/MediaController/Messages/Monitor/MonitorStartMessage.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; using System.Collections.Generic; using Newtonsoft.Json.Linq; using UnityEngine; diff --git a/Runtime/MediaController/Messages/Monitor/MonitorStopMessage.cs b/Runtime/MediaController/Messages/Monitor/MonitorStopMessage.cs index 47c29a09..374e3e68 100644 --- a/Runtime/MediaController/Messages/Monitor/MonitorStopMessage.cs +++ b/Runtime/MediaController/Messages/Monitor/MonitorStopMessage.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; using Newtonsoft.Json.Linq; using UnityEngine; diff --git a/Runtime/MediaController/Messages/Monitor/MonitoringCategory.cs b/Runtime/MediaController/Messages/Monitor/MonitoringCategory.cs index e5fa4000..cea81b8c 100644 --- a/Runtime/MediaController/Messages/Monitor/MonitoringCategory.cs +++ b/Runtime/MediaController/Messages/Monitor/MonitoringCategory.cs @@ -1,4 +1,15 @@ -namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor { public enum MonitoringCategory { diff --git a/Runtime/MediaController/Messages/MonitorBase.cs b/Runtime/MediaController/Messages/MonitorBase.cs index 4a5637ec..9eae62fa 100644 --- a/Runtime/MediaController/Messages/MonitorBase.cs +++ b/Runtime/MediaController/Messages/MonitorBase.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using UnityEngine; using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Reset; diff --git a/Runtime/MediaController/Messages/MpfVariableMessageBase.cs b/Runtime/MediaController/Messages/MpfVariableMessageBase.cs index de15cded..46c9c05a 100644 --- a/Runtime/MediaController/Messages/MpfVariableMessageBase.cs +++ b/Runtime/MediaController/Messages/MpfVariableMessageBase.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using Newtonsoft.Json.Linq; diff --git a/Runtime/MediaController/Messages/MpfVariableMonitorBase.cs b/Runtime/MediaController/Messages/MpfVariableMonitorBase.cs index 4d567d00..6165b756 100644 --- a/Runtime/MediaController/Messages/MpfVariableMonitorBase.cs +++ b/Runtime/MediaController/Messages/MpfVariableMonitorBase.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using UnityEngine; diff --git a/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessage.cs b/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessage.cs index 6b1b86c9..d3fb449a 100644 --- a/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessage.cs +++ b/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerAdded diff --git a/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessageHandler.cs b/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessageHandler.cs index f00c315e..2f83bce3 100644 --- a/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessageHandler.cs +++ b/Runtime/MediaController/Messages/PlayerAdded/PlayerAddedMessageHandler.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerAdded diff --git a/Runtime/MediaController/Messages/PlayerAdded/PlayerCountMonitor.cs b/Runtime/MediaController/Messages/PlayerAdded/PlayerCountMonitor.cs index e3653a1c..50707945 100644 --- a/Runtime/MediaController/Messages/PlayerAdded/PlayerCountMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerAdded/PlayerCountMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerAdded { public class PlayerCountMonitor : MonitorBase diff --git a/Runtime/MediaController/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs b/Runtime/MediaController/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs index 9c7fa197..a16cbb77 100644 --- a/Runtime/MediaController/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerTurnStart/CurrentPlayerMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerTurnStart { public class CurrentPlayerMonitor : MonitorBase diff --git a/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs b/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs index a1a011c5..d857845e 100644 --- a/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs +++ b/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerTurnStart diff --git a/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs b/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs index b0dad554..49eb0c15 100644 --- a/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs +++ b/Runtime/MediaController/Messages/PlayerTurnStart/PlayerTurnStartMessageHandler.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerTurnStart diff --git a/Runtime/MediaController/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs b/Runtime/MediaController/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs index c048a140..f128b45e 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/Monitor/BoolPlayerVariableMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerVariable { public class BoolPlayerVariableMonitor : PlayerVariableMonitor { } diff --git a/Runtime/MediaController/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs b/Runtime/MediaController/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs index 82de354d..6eb2b868 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/Monitor/FloatPlayerVariableMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerVariable { public class FloatPlayerVariableMonitor : PlayerVariableMonitor { } diff --git a/Runtime/MediaController/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs b/Runtime/MediaController/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs index 251ff716..a4af02df 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/Monitor/IntPlayerVariableMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerVariable { public class IntPlayerVariableMonitor : PlayerVariableMonitor { } diff --git a/Runtime/MediaController/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs b/Runtime/MediaController/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs index 99dc12bb..965c1e7a 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/Monitor/StringPlayerVariableMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerVariable { public class StringPlayerVariableMonitor : PlayerVariableMonitor { } diff --git a/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessage.cs b/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessage.cs index 850a9908..89cd8fa0 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessage.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using Newtonsoft.Json.Linq; using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.MachineVar; diff --git a/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessageHandler.cs b/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessageHandler.cs index ad879ac5..70f023e4 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessageHandler.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMessageHandler.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.PlayerVariable diff --git a/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMonitor.cs b/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMonitor.cs index b8aa2473..338d06eb 100644 --- a/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMonitor.cs +++ b/Runtime/MediaController/Messages/PlayerVariable/PlayerVariableMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using System.Collections.Generic; using UnityEngine; diff --git a/Runtime/MediaController/Messages/Reset/ResetCompleteMessage.cs b/Runtime/MediaController/Messages/Reset/ResetCompleteMessage.cs index 10411506..03bfd921 100644 --- a/Runtime/MediaController/Messages/Reset/ResetCompleteMessage.cs +++ b/Runtime/MediaController/Messages/Reset/ResetCompleteMessage.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Reset { diff --git a/Runtime/MediaController/Messages/Reset/ResetMessage.cs b/Runtime/MediaController/Messages/Reset/ResetMessage.cs index 87d33ee9..21762b26 100644 --- a/Runtime/MediaController/Messages/Reset/ResetMessage.cs +++ b/Runtime/MediaController/Messages/Reset/ResetMessage.cs @@ -1,4 +1,15 @@ -using System; +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Reset { diff --git a/Runtime/MediaController/Messages/Reset/ResetMessageHandler.cs b/Runtime/MediaController/Messages/Reset/ResetMessageHandler.cs index 0ff05325..ca807735 100644 --- a/Runtime/MediaController/Messages/Reset/ResetMessageHandler.cs +++ b/Runtime/MediaController/Messages/Reset/ResetMessageHandler.cs @@ -1,4 +1,15 @@ -namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Reset +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Reset { public class ResetMessageHandler : BcpMessageHandler { diff --git a/Runtime/MediaController/Messages/Settings/SettingsMessage.cs b/Runtime/MediaController/Messages/Settings/SettingsMessage.cs index 7c28d2f8..fad185be 100644 --- a/Runtime/MediaController/Messages/Settings/SettingsMessage.cs +++ b/Runtime/MediaController/Messages/Settings/SettingsMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using Newtonsoft.Json.Linq; diff --git a/Runtime/MediaController/Messages/Settings/SettingsMessageHandler.cs b/Runtime/MediaController/Messages/Settings/SettingsMessageHandler.cs index bfa877a5..4927fe29 100644 --- a/Runtime/MediaController/Messages/Settings/SettingsMessageHandler.cs +++ b/Runtime/MediaController/Messages/Settings/SettingsMessageHandler.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Settings diff --git a/Runtime/MediaController/Messages/Switch/SwitchMessage.cs b/Runtime/MediaController/Messages/Switch/SwitchMessage.cs index 849d770f..85a18cce 100644 --- a/Runtime/MediaController/Messages/Switch/SwitchMessage.cs +++ b/Runtime/MediaController/Messages/Switch/SwitchMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using Newtonsoft.Json.Linq; diff --git a/Runtime/MediaController/Messages/Switch/SwitchMessageHandler.cs b/Runtime/MediaController/Messages/Switch/SwitchMessageHandler.cs index ee12f587..8355b570 100644 --- a/Runtime/MediaController/Messages/Switch/SwitchMessageHandler.cs +++ b/Runtime/MediaController/Messages/Switch/SwitchMessageHandler.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Monitor; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Switch diff --git a/Runtime/MediaController/Messages/Switch/SwitchMonitor.cs b/Runtime/MediaController/Messages/Switch/SwitchMonitor.cs index 0bb7f409..73c82516 100644 --- a/Runtime/MediaController/Messages/Switch/SwitchMonitor.cs +++ b/Runtime/MediaController/Messages/Switch/SwitchMonitor.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using UnityEngine; namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Switch diff --git a/Runtime/MediaController/Messages/Trigger/MpfEventListener.cs b/Runtime/MediaController/Messages/Trigger/MpfEventListener.cs index 31f60281..c7bab4a5 100644 --- a/Runtime/MediaController/Messages/Trigger/MpfEventListener.cs +++ b/Runtime/MediaController/Messages/Trigger/MpfEventListener.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using UnityEngine; diff --git a/Runtime/MediaController/Messages/Trigger/RegisterTriggerMessage.cs b/Runtime/MediaController/Messages/Trigger/RegisterTriggerMessage.cs index a247d6be..345e4417 100644 --- a/Runtime/MediaController/Messages/Trigger/RegisterTriggerMessage.cs +++ b/Runtime/MediaController/Messages/Trigger/RegisterTriggerMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using Newtonsoft.Json.Linq; diff --git a/Runtime/MediaController/Messages/Trigger/RemoveTriggerMessage.cs b/Runtime/MediaController/Messages/Trigger/RemoveTriggerMessage.cs index 79473244..c74772da 100644 --- a/Runtime/MediaController/Messages/Trigger/RemoveTriggerMessage.cs +++ b/Runtime/MediaController/Messages/Trigger/RemoveTriggerMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using Newtonsoft.Json.Linq; diff --git a/Runtime/MediaController/Messages/Trigger/TriggerMessage.cs b/Runtime/MediaController/Messages/Trigger/TriggerMessage.cs index 4f7ac256..257f2cc9 100644 --- a/Runtime/MediaController/Messages/Trigger/TriggerMessage.cs +++ b/Runtime/MediaController/Messages/Trigger/TriggerMessage.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using System; using Newtonsoft.Json.Linq; diff --git a/Runtime/MediaController/Messages/Trigger/TriggerMessageHandler.cs b/Runtime/MediaController/Messages/Trigger/TriggerMessageHandler.cs index 18e2cdd0..c77865f6 100644 --- a/Runtime/MediaController/Messages/Trigger/TriggerMessageHandler.cs +++ b/Runtime/MediaController/Messages/Trigger/TriggerMessageHandler.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + namespace VisualPinball.Engine.Mpf.Unity.MediaController.Messages.Trigger { public class TriggerMessageHandler : BcpMessageHandler diff --git a/Runtime/MediaController/Ui/MonitoredVariableText.cs b/Runtime/MediaController/Ui/MonitoredVariableText.cs index 861ba3cb..7f7d05e4 100644 --- a/Runtime/MediaController/Ui/MonitoredVariableText.cs +++ b/Runtime/MediaController/Ui/MonitoredVariableText.cs @@ -1,3 +1,14 @@ +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + using TMPro; using UnityEngine; using VisualPinball.Engine.Mpf.Unity.MediaController.Messages; diff --git a/Runtime/MediaController/Utils/StringEnum.cs b/Runtime/MediaController/Utils/StringEnum.cs index 8d235324..2f87759e 100644 --- a/Runtime/MediaController/Utils/StringEnum.cs +++ b/Runtime/MediaController/Utils/StringEnum.cs @@ -1,4 +1,15 @@ -// Based on: https://weblogs.asp.net/stefansedich/enum-with-string-values-in-c +// Visual Pinball Engine +// Copyright (C) 2025 freezy and VPE Team +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +// Based on: https://weblogs.asp.net/stefansedich/enum-with-string-values-in-c using System; using System.Reflection; From 1b15a4b22f485b00bb7bc1640e314065e650ef1b Mon Sep 17 00:00:00 2001 From: arthurkehrwald <50906979+arthurkehrwald@users.noreply.github.com> Date: Sat, 22 Feb 2025 15:29:32 +0100 Subject: [PATCH 83/98] Integrate media controller --- Editor/BcpInterfaceInspector.cs | 42 -- Editor/BcpInterfaceInspector.cs.meta | 13 - Editor/BcpInterfaceInspector.uxml | 7 - Editor/BcpInterfaceInspector.uxml.meta | 10 - .../Inspector/MpfGamelogicEngineInspector.cs | 92 +++- .../MpfGamelogicEngineInspector.uxml | 46 +- Editor/Inspector/MpfMonitorInspector.cs | 87 ++++ .../Inspector/MpfMonitorInspector.cs.meta | 2 +- Runtime/BcpInterface.prefab | 382 ----------------- Runtime/BcpInterface.prefab.meta | 7 - Runtime/MediaController/Behaviors.meta | 8 - .../Behaviors/DisconnectOnGoodbyeReceived.cs | 41 -- .../Behaviors/HelloResponse.cs | 59 --- Runtime/MediaController/Core/BcpInterface.cs | 192 ++++++--- .../MediaController/Core/BcpMessageHandler.cs | 44 +- .../Core/BcpMessageHandlers.cs | 94 +++++ .../BcpMessageHandlers.cs.meta} | 2 +- Runtime/MediaController/Core/BcpServer.cs | 140 ++++--- .../MediaController/Core/MpfEventRequester.cs | 40 +- .../Messages/Ball/BallEndMessageHandler.cs | 3 + .../Messages/Ball/BallStartMessageHandler.cs | 3 + .../Messages/Device/DeviceMessageHandler.cs | 3 + .../Device/SpecificDeviceMessageHandler.cs | 14 +- .../Messages/Error/ErrorMessage.cs | 12 +- .../Messages/Error/ErrorMessageHandler.cs | 3 + .../Messages/Goodbye/GoodbyeMessageHandler.cs | 3 + .../Messages/Hello/HelloMessageHandler.cs | 8 + .../MachineVariableMessageHandler.cs | 3 + .../MachineVariable/MachineVariableMonitor.cs | 5 +- .../Messages/Mode/ModeListMessageHandler.cs | 3 + .../Messages/Mode/ModeMonitor.cs | 27 +- .../Messages/Mode/ModeStartMessageHandler.cs | 3 + .../Messages/Mode/ModeStopMessageHandler.cs | 3 + .../Messages/Monitor/MonitorStartMessage.cs | 5 +- .../Messages/Monitor/MonitorStopMessage.cs | 4 +- .../MediaController/Messages/MonitorBase.cs | 26 +- .../PlayerAdded/PlayerAddedMessageHandler.cs | 3 + .../PlayerAdded/PlayerCountMonitor.cs | 2 + .../PlayerTurnStart/CurrentPlayerMonitor.cs | 2 + .../PlayerTurnStartMessageHandler.cs | 3 + .../PlayerVariable/PlayerVariableMessage.cs | 1 - .../PlayerVariableMessageHandler.cs | 3 + .../PlayerVariable/PlayerVariableMonitor.cs | 1 + .../Messages/Reset/ResetMessageHandler.cs | 7 +- .../Settings/SettingsMessageHandler.cs | 3 + .../Messages/Switch/SwitchMessageHandler.cs | 3 + .../Messages/Switch/SwitchMonitor.cs | 2 + .../Messages/Trigger/MpfEventListener.cs | 22 +- .../Messages/Trigger/TriggerMessageHandler.cs | 3 + .../Ui/MonitoredVariableText.cs | 17 +- Runtime/MpfGamelogicEngine.cs | 242 +++++++++-- Runtime/MpfWrangler.cs | 394 +++++++++++------- 52 files changed, 1120 insertions(+), 1024 deletions(-) delete mode 100644 Editor/BcpInterfaceInspector.cs delete mode 100644 Editor/BcpInterfaceInspector.cs.meta delete mode 100644 Editor/BcpInterfaceInspector.uxml delete mode 100644 Editor/BcpInterfaceInspector.uxml.meta create mode 100644 Editor/Inspector/MpfMonitorInspector.cs rename Runtime/MediaController/Behaviors/DisconnectOnGoodbyeReceived.cs.meta => Editor/Inspector/MpfMonitorInspector.cs.meta (83%) delete mode 100644 Runtime/BcpInterface.prefab delete mode 100644 Runtime/BcpInterface.prefab.meta delete mode 100644 Runtime/MediaController/Behaviors.meta delete mode 100644 Runtime/MediaController/Behaviors/DisconnectOnGoodbyeReceived.cs delete mode 100644 Runtime/MediaController/Behaviors/HelloResponse.cs create mode 100644 Runtime/MediaController/Core/BcpMessageHandlers.cs rename Runtime/MediaController/{Behaviors/HelloResponse.cs.meta => Core/BcpMessageHandlers.cs.meta} (83%) diff --git a/Editor/BcpInterfaceInspector.cs b/Editor/BcpInterfaceInspector.cs deleted file mode 100644 index 432265d5..00000000 --- a/Editor/BcpInterfaceInspector.cs +++ /dev/null @@ -1,42 +0,0 @@ -using UnityEditor; -using UnityEngine; -using UnityEngine.UIElements; -using VisualPinball.Engine.Mpf.Unity.MediaController; - -namespace VisualPinball.Engine.Mpf.Unity.Editor -{ - [CustomEditor(typeof(BcpInterface))] - public class BcpInterfaceInspector : UnityEditor.Editor - { - [SerializeField] - private VisualTreeAsset _bcpInterfaceInspectorXml; - - private TextField _connectionStateField; - private BcpInterface _bcpInterface; - - public override VisualElement CreateInspectorGUI() - { - var ui = _bcpInterfaceInspectorXml.Instantiate(); - _connectionStateField = ui.Q("connection-state"); - _bcpInterface = target as BcpInterface; - UpdateConnectionStateField(_bcpInterface.ConnectionState); - _bcpInterface.ConnectionStateChanged += OnConnectionStateChanged; - return ui; - } - - private void OnDisable() - { - _bcpInterface.ConnectionStateChanged -= OnConnectionStateChanged; - } - - private void OnConnectionStateChanged(object sender, ConnectionStateChangedEventArgs args) - { - UpdateConnectionStateField(args.CurrentState); - } - - private void UpdateConnectionStateField(ConnectionState state) - { - _connectionStateField.value = state.ToString(); - } - } -} diff --git a/Editor/BcpInterfaceInspector.cs.meta b/Editor/BcpInterfaceInspector.cs.meta deleted file mode 100644 index 3566e7e0..00000000 --- a/Editor/BcpInterfaceInspector.cs.meta +++ /dev/null @@ -1,13 +0,0 @@ -fileFormatVersion: 2 -guid: 0bea179b36a1e3c4c95091c53c60a399 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: - - _bcpInterfaceInspectorXml: {fileID: 9197481963319205126, guid: 5b6e50170ee132d418af0df03ae4b41c, - type: 3} - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/BcpInterfaceInspector.uxml b/Editor/BcpInterfaceInspector.uxml deleted file mode 100644 index 968ae69d..00000000 --- a/Editor/BcpInterfaceInspector.uxml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/Editor/BcpInterfaceInspector.uxml.meta b/Editor/BcpInterfaceInspector.uxml.meta deleted file mode 100644 index 19bec1cd..00000000 --- a/Editor/BcpInterfaceInspector.uxml.meta +++ /dev/null @@ -1,10 +0,0 @@ -fileFormatVersion: 2 -guid: 5b6e50170ee132d418af0df03ae4b41c -ScriptedImporter: - internalIDToNameTable: [] - externalObjects: {} - serializedVersion: 2 - userData: - assetBundleName: - assetBundleVariant: - script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0} diff --git a/Editor/Inspector/MpfGamelogicEngineInspector.cs b/Editor/Inspector/MpfGamelogicEngineInspector.cs index e439c0ed..2434117e 100644 --- a/Editor/Inspector/MpfGamelogicEngineInspector.cs +++ b/Editor/Inspector/MpfGamelogicEngineInspector.cs @@ -17,11 +17,11 @@ using System.Linq; using System.Threading; using Grpc.Core; -using Mono.Cecil; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; +using VisualPinball.Engine.Mpf.Unity.MediaController; using VisualPinball.Unity; namespace VisualPinball.Engine.Mpf.Unity.Editor @@ -38,6 +38,9 @@ public class MpfGamelogicEngineInspector : UnityEditor.Editor private PropertyField _connectDelayField; private VisualElement _commandLineOptionsContainer; private VisualElement _startupBehaviorOptionsContainer; + private TextField _mpfStateField; + private TextField _mediaControllerStateField; + private VisualElement _bcpOptionsContainer; public override VisualElement CreateInspectorGUI() { @@ -63,12 +66,9 @@ public override VisualElement CreateInspectorGUI() if (!string.IsNullOrWhiteSpace(path)) { - path = path.Replace("\\", "/"); - if (path.Contains("StreamingAssets/")) - path = "./StreamingAssets/" + path.Split("StreamingAssets/")[1]; - + path = MpfWranglerOptions.RealPathToSerializedPath(path); var machineFolderProp = serializedObject.FindProperty( - $"_mpfWrangler._machineFolder" + $"_wranglerOptions._machineFolder" ); machineFolderProp.stringValue = path; serializedObject.ApplyModifiedProperties(); @@ -77,7 +77,7 @@ public override VisualElement CreateInspectorGUI() ); var getDescBtn = root.Q