Skip to content

Commit ec3f11b

Browse files
committed
api: Make it bridge compatible.
1 parent 70c2d6d commit ec3f11b

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

VisualPinball.Engine.Mpf.Unity/Runtime/MpfGamelogicEngine.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,26 @@ public class MpfGamelogicEngine : MonoBehaviour, IGamelogicEngine
3131

3232
public GamelogicEngineSwitch[] AvailableSwitches => availableSwitches;
3333
public GamelogicEngineCoil[] AvailableCoils => availableCoils;
34-
public GamelogicEngineLamp[] AvailableLamps => availableLamps;
35-
public GamelogicEngineWire[] AvailableWires => availableWires;
36-
34+
public GamelogicEngineLamp[] AvailableLamps => availableLamps;
35+
public GamelogicEngineWire[] AvailableWires => availableWires;
36+
3737
public event EventHandler<LampEventArgs> OnLampChanged;
3838
public event EventHandler<LampsEventArgs> OnLampsChanged;
3939
public event EventHandler<LampColorEventArgs> OnLampColorChanged;
4040
public event EventHandler<CoilEventArgs> OnCoilChanged;
4141
public event EventHandler<AvailableDisplays> OnDisplaysAvailable;
4242
public event EventHandler<DisplayFrameData> OnDisplayFrame;
43+
public event EventHandler<SwitchEventArgs2> OnSwitchChanged;
4344

4445
[NonSerialized]
4546
private MpfApi _api;
4647

4748
public string machineFolder;
4849

49-
[SerializeField] private GamelogicEngineSwitch[] availableSwitches = new GamelogicEngineSwitch[0];
50-
[SerializeField] private GamelogicEngineCoil[] availableCoils = new GamelogicEngineCoil[0];
51-
[SerializeField] private GamelogicEngineLamp[] availableLamps = new GamelogicEngineLamp[0];
52-
[SerializeField] private GamelogicEngineWire[] availableWires = new GamelogicEngineWire[0];
50+
[SerializeField] private GamelogicEngineSwitch[] availableSwitches = Array.Empty<GamelogicEngineSwitch>();
51+
[SerializeField] private GamelogicEngineCoil[] availableCoils = Array.Empty<GamelogicEngineCoil>();
52+
[SerializeField] private GamelogicEngineLamp[] availableLamps = Array.Empty<GamelogicEngineLamp>();
53+
[SerializeField] private GamelogicEngineWire[] availableWires = Array.Empty<GamelogicEngineWire>();
5354

5455
private Player _player;
5556
private Dictionary<string, int> _switchIds = new Dictionary<string, int>();
@@ -124,6 +125,8 @@ public void Switch(string id, bool isClosed)
124125
} else {
125126
Logger.Error("Unmapped MPF switch " + id);
126127
}
128+
129+
OnSwitchChanged?.Invoke(this, new SwitchEventArgs2(id, isClosed));
127130
}
128131

129132
public void GetMachineDescription()
@@ -138,13 +141,28 @@ public void GetMachineDescription()
138141
Logger.Error($"Unable to get machine description. Check maching config. {e.Message}");
139142
}
140143

141-
if (md != null) {
144+
if (md != null) {
142145
availableSwitches = md.GetSwitches().ToArray();
143146
availableCoils = md.GetCoils().ToArray();
144147
availableLamps = md.GetLights().ToArray();
145148
}
146149
}
147150

151+
public void SetCoil(string id, bool isEnabled)
152+
{
153+
OnCoilChanged?.Invoke(this, new CoilEventArgs(id, isEnabled));
154+
}
155+
156+
public void SetLamp(string id, int value, bool isCoil = false, LampSource source = LampSource.Lamp)
157+
{
158+
OnLampChanged?.Invoke(this, new LampEventArgs(id, value, isCoil, source));
159+
}
160+
161+
public void SetLamp(string id, Color color)
162+
{
163+
OnLampColorChanged?.Invoke(this, new LampColorEventArgs(id, color));
164+
}
165+
148166
private void OnEnableCoil(object sender, EnableCoilRequest e)
149167
{
150168
if (_coilNames.ContainsKey(e.CoilNumber)) {
@@ -263,5 +281,6 @@ private void OnDestroy()
263281
_api.Dispose();
264282
}
265283
}
284+
266285
}
267286
}

0 commit comments

Comments
 (0)