From e457c417be01c4c6dc958a20831b913145472731 Mon Sep 17 00:00:00 2001 From: freezy Date: Thu, 10 Feb 2022 20:25:57 +0100 Subject: [PATCH 1/3] api: Adapt to upstream changes. --- .../Editor/MpfGamelogicEngineInspector.cs | 16 +++++----- .../Runtime/MpfGamelogicEngine.cs | 31 ++++++++++--------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/VisualPinball.Engine.Mpf.Unity/Editor/MpfGamelogicEngineInspector.cs b/VisualPinball.Engine.Mpf.Unity/Editor/MpfGamelogicEngineInspector.cs index b4c7463f..f26a5d31 100644 --- a/VisualPinball.Engine.Mpf.Unity/Editor/MpfGamelogicEngineInspector.cs +++ b/VisualPinball.Engine.Mpf.Unity/Editor/MpfGamelogicEngineInspector.cs @@ -29,7 +29,7 @@ public class MpfGamelogicEngineInspector : UnityEditor.Editor private bool _foldoutCoils; private bool _foldoutLamps; - private bool HasData => _mpfEngine.AvailableSwitches.Length + _mpfEngine.AvailableCoils.Length + _mpfEngine.AvailableLamps.Length > 0; + private bool HasData => _mpfEngine.RequestedSwitches.Length + _mpfEngine.RequestedCoils.Length + _mpfEngine.RequestedLamps.Length > 0; private void OnEnable() { @@ -82,32 +82,32 @@ public override void OnInspectorGUI() }; // list switches, coils and lamps - if (_mpfEngine.AvailableCoils.Length + _mpfEngine.AvailableSwitches.Length + _mpfEngine.AvailableLamps.Length > 0) { + if (_mpfEngine.RequestedCoils.Length + _mpfEngine.RequestedSwitches.Length + _mpfEngine.RequestedLamps.Length > 0) { if (_foldoutSwitches = EditorGUILayout.BeginFoldoutHeaderGroup(_foldoutSwitches, "Switches")) { - foreach (var sw in _mpfEngine.AvailableSwitches) { + foreach (var sw in _mpfEngine.RequestedSwitches) { EditorGUILayout.LabelField(new GUIContent($" [{sw.InternalId}] {sw.Id} ", Icons.Switch(sw.NormallyClosed, IconSize.Small))); } - if (_mpfEngine.AvailableSwitches.Length == 0) { + if (_mpfEngine.RequestedSwitches.Length == 0) { EditorGUILayout.LabelField("No switches in this machine.", naStyle); } } EditorGUILayout.EndFoldoutHeaderGroup(); if (_foldoutCoils = EditorGUILayout.BeginFoldoutHeaderGroup(_foldoutCoils, "Coils")) { - foreach (var sw in _mpfEngine.AvailableCoils) { + foreach (var sw in _mpfEngine.RequestedCoils) { EditorGUILayout.LabelField(new GUIContent($" [{sw.InternalId}] {sw.Id} ", Icons.Coil(IconSize.Small))); } - if (_mpfEngine.AvailableCoils.Length == 0) { + if (_mpfEngine.RequestedCoils.Length == 0) { EditorGUILayout.LabelField("No coils in this machine.", naStyle); } } EditorGUILayout.EndFoldoutHeaderGroup(); if (_foldoutLamps = EditorGUILayout.BeginFoldoutHeaderGroup(_foldoutLamps, "Lamps")) { - foreach (var sw in _mpfEngine.AvailableLamps) { + foreach (var sw in _mpfEngine.RequestedLamps) { EditorGUILayout.LabelField(new GUIContent($" [{sw.InternalId}] {sw.Id} ", Icons.Light(IconSize.Small))); } - if (_mpfEngine.AvailableLamps.Length == 0) { + if (_mpfEngine.RequestedLamps.Length == 0) { EditorGUILayout.LabelField("No lamps in this machine.", naStyle); } } diff --git a/VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs b/VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs index ef06ba56..e38772fb 100644 --- a/VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs +++ b/VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs @@ -29,16 +29,17 @@ public class MpfGamelogicEngine : MonoBehaviour, IGamelogicEngine { public string Name { get; } = "Mission Pinball Framework"; - public GamelogicEngineSwitch[] AvailableSwitches => availableSwitches; - public GamelogicEngineCoil[] AvailableCoils => availableCoils; - public GamelogicEngineLamp[] AvailableLamps => availableLamps; + public GamelogicEngineSwitch[] RequestedSwitches => requiredSwitches; + public GamelogicEngineCoil[] RequestedCoils => requiredCoils; + public GamelogicEngineLamp[] RequestedLamps => requiredLamps; public GamelogicEngineWire[] AvailableWires => availableWires; + public event EventHandler OnStarted; public event EventHandler OnLampChanged; public event EventHandler OnLampsChanged; public event EventHandler OnLampColorChanged; public event EventHandler OnCoilChanged; - public event EventHandler OnDisplaysAvailable; + public event EventHandler OnDisplaysRequested; public event EventHandler OnDisplayFrame; public event EventHandler OnSwitchChanged; @@ -47,9 +48,9 @@ public class MpfGamelogicEngine : MonoBehaviour, IGamelogicEngine public string machineFolder; - [SerializeField] private GamelogicEngineSwitch[] availableSwitches = Array.Empty(); - [SerializeField] private GamelogicEngineCoil[] availableCoils = Array.Empty(); - [SerializeField] private GamelogicEngineLamp[] availableLamps = Array.Empty(); + [SerializeField] private GamelogicEngineSwitch[] requiredSwitches = Array.Empty(); + [SerializeField] private GamelogicEngineCoil[] requiredCoils = Array.Empty(); + [SerializeField] private GamelogicEngineLamp[] requiredLamps = Array.Empty(); [SerializeField] private GamelogicEngineWire[] availableWires = Array.Empty(); private Player _player; @@ -68,16 +69,16 @@ public void OnInit(Player player, TableApi tableApi, BallManager ballManager) { _player = player; _switchIds.Clear(); - foreach (var sw in availableSwitches) { + foreach (var sw in requiredSwitches) { _switchIds[sw.Id] = sw.InternalId; _switchNames[sw.InternalId.ToString()] = sw.Id; } _coilNames.Clear(); - foreach (var coil in availableCoils) { + foreach (var coil in requiredCoils) { _coilNames[coil.InternalId.ToString()] = coil.Id; } _lampNames.Clear(); - foreach (var lamp in availableLamps) { + foreach (var lamp in requiredLamps) { _lampNames[lamp.InternalId.ToString()] = lamp.Id; } _api = new MpfApi(machineFolder); @@ -144,9 +145,9 @@ public void GetMachineDescription() } if (md != null) { - availableSwitches = md.GetSwitches().ToArray(); - availableCoils = md.GetCoils().ToArray(); - availableLamps = md.GetLights().ToArray(); + requiredSwitches = md.GetSwitches().ToArray(); + requiredCoils = md.GetCoils().ToArray(); + requiredLamps = md.GetLights().ToArray(); } } @@ -271,8 +272,8 @@ private void OnDmdFrame(object sender, SetDmdFrameRequest frame) foreach (var dmd in config.Dmds) { Logger.Info($"[MPF] Announcing display \"{dmd.Name}\" @ {dmd.Width}x{dmd.Height}"); lock (_dispatchQueue) { - _dispatchQueue.Enqueue(() => OnDisplaysAvailable?.Invoke(this, - new AvailableDisplays(new DisplayConfig(dmd.Name, dmd.Width, dmd.Height, true)))); + _dispatchQueue.Enqueue(() => OnDisplaysRequested?.Invoke(this, + new RequestedDisplays(new DisplayConfig(dmd.Name, dmd.Width, dmd.Height, true)))); } } Logger.Info("[MPF] Displays announced."); From be3da189d744d080e54b2dac5e2beb73b28c26b9 Mon Sep 17 00:00:00 2001 From: freezy Date: Thu, 17 Feb 2022 22:07:24 +0100 Subject: [PATCH 2/3] api: Use LampState instead of float. --- VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs b/VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs index e38772fb..0dd9c4ed 100644 --- a/VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs +++ b/VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs @@ -166,9 +166,9 @@ public void SetLamp(string id, Color color) OnLampColorChanged?.Invoke(this, new LampColorEventArgs(id, color)); } - public float GetLamp(string id) + public LampState GetLamp(string id) { - return _player.LampStatuses.ContainsKey(id) ? _player.LampStatuses[id] : 0; + return _player.LampStatuses.ContainsKey(id) ? _player.LampStatuses[id] : LampState.Default; } public bool GetSwitch(string id) From 97ad44035d665444d8565e2bf5c6e5ab79d8715c Mon Sep 17 00:00:00 2001 From: freezy Date: Mon, 21 Feb 2022 22:27:19 +0100 Subject: [PATCH 3/3] api: Update to upstream changes. --- .../Runtime/MpfGamelogicEngine.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs b/VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs index 0dd9c4ed..13edd6b3 100644 --- a/VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs +++ b/VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs @@ -37,7 +37,6 @@ public class MpfGamelogicEngine : MonoBehaviour, IGamelogicEngine public event EventHandler OnStarted; public event EventHandler OnLampChanged; public event EventHandler OnLampsChanged; - public event EventHandler OnLampColorChanged; public event EventHandler OnCoilChanged; public event EventHandler OnDisplaysRequested; public event EventHandler OnDisplayFrame; @@ -161,11 +160,6 @@ public void SetLamp(string id, float value, bool isCoil = false, LampSource sour OnLampChanged?.Invoke(this, new LampEventArgs(id, value, isCoil, source)); } - public void SetLamp(string id, Color color) - { - OnLampColorChanged?.Invoke(this, new LampColorEventArgs(id, color)); - } - public LampState GetLamp(string id) { return _player.LampStatuses.ContainsKey(id) ? _player.LampStatuses[id] : LampState.Default; @@ -222,7 +216,7 @@ private void OnFadeLight(object sender, FadeLightRequest e) var args = new List(); foreach (var fade in e.Fades) { if (_lampNames.ContainsKey(fade.LightNumber)) { - args.Add(new LampEventArgs(_lampNames[fade.LightNumber], (int)(fade.TargetBrightness * 255))); + args.Add(new LampEventArgs(_lampNames[fade.LightNumber], fade.TargetBrightness)); } else { Logger.Error("Unmapped MPF lamp " + fade.LightNumber); }