Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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);
}
}
Expand Down
43 changes: 19 additions & 24 deletions VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ 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<EventArgs> OnStarted;
public event EventHandler<LampEventArgs> OnLampChanged;
public event EventHandler<LampsEventArgs> OnLampsChanged;
public event EventHandler<LampColorEventArgs> OnLampColorChanged;
public event EventHandler<CoilEventArgs> OnCoilChanged;
public event EventHandler<AvailableDisplays> OnDisplaysAvailable;
public event EventHandler<RequestedDisplays> OnDisplaysRequested;
public event EventHandler<DisplayFrameData> OnDisplayFrame;
public event EventHandler<SwitchEventArgs2> OnSwitchChanged;

Expand All @@ -47,9 +47,9 @@ public class MpfGamelogicEngine : MonoBehaviour, IGamelogicEngine

public string machineFolder;

[SerializeField] private GamelogicEngineSwitch[] availableSwitches = Array.Empty<GamelogicEngineSwitch>();
[SerializeField] private GamelogicEngineCoil[] availableCoils = Array.Empty<GamelogicEngineCoil>();
[SerializeField] private GamelogicEngineLamp[] availableLamps = Array.Empty<GamelogicEngineLamp>();
[SerializeField] private GamelogicEngineSwitch[] requiredSwitches = Array.Empty<GamelogicEngineSwitch>();
[SerializeField] private GamelogicEngineCoil[] requiredCoils = Array.Empty<GamelogicEngineCoil>();
[SerializeField] private GamelogicEngineLamp[] requiredLamps = Array.Empty<GamelogicEngineLamp>();
[SerializeField] private GamelogicEngineWire[] availableWires = Array.Empty<GamelogicEngineWire>();

private Player _player;
Expand All @@ -68,16 +68,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);
Expand Down Expand Up @@ -144,9 +144,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();
}
}

Expand All @@ -160,14 +160,9 @@ 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 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)
Expand Down Expand Up @@ -221,7 +216,7 @@ private void OnFadeLight(object sender, FadeLightRequest e)
var args = new List<LampEventArgs>();
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);
}
Expand Down Expand Up @@ -271,8 +266,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.");
Expand Down