@@ -31,25 +31,26 @@ public class MpfGamelogicEngine : MonoBehaviour, IGamelogicEngine
31
31
32
32
public GamelogicEngineSwitch [ ] AvailableSwitches => availableSwitches ;
33
33
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
+
37
37
public event EventHandler < LampEventArgs > OnLampChanged ;
38
38
public event EventHandler < LampsEventArgs > OnLampsChanged ;
39
39
public event EventHandler < LampColorEventArgs > OnLampColorChanged ;
40
40
public event EventHandler < CoilEventArgs > OnCoilChanged ;
41
41
public event EventHandler < AvailableDisplays > OnDisplaysAvailable ;
42
42
public event EventHandler < DisplayFrameData > OnDisplayFrame ;
43
+ public event EventHandler < SwitchEventArgs2 > OnSwitchChanged ;
43
44
44
45
[ NonSerialized ]
45
46
private MpfApi _api ;
46
47
47
48
public string machineFolder ;
48
49
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 > ( ) ;
53
54
54
55
private Player _player ;
55
56
private Dictionary < string , int > _switchIds = new Dictionary < string , int > ( ) ;
@@ -124,6 +125,8 @@ public void Switch(string id, bool isClosed)
124
125
} else {
125
126
Logger . Error ( "Unmapped MPF switch " + id ) ;
126
127
}
128
+
129
+ OnSwitchChanged ? . Invoke ( this , new SwitchEventArgs2 ( id , isClosed ) ) ;
127
130
}
128
131
129
132
public void GetMachineDescription ( )
@@ -138,13 +141,28 @@ public void GetMachineDescription()
138
141
Logger . Error ( $ "Unable to get machine description. Check maching config. { e . Message } ") ;
139
142
}
140
143
141
- if ( md != null ) {
144
+ if ( md != null ) {
142
145
availableSwitches = md . GetSwitches ( ) . ToArray ( ) ;
143
146
availableCoils = md . GetCoils ( ) . ToArray ( ) ;
144
147
availableLamps = md . GetLights ( ) . ToArray ( ) ;
145
148
}
146
149
}
147
150
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
+
148
166
private void OnEnableCoil ( object sender , EnableCoilRequest e )
149
167
{
150
168
if ( _coilNames . ContainsKey ( e . CoilNumber ) ) {
@@ -263,5 +281,6 @@ private void OnDestroy()
263
281
_api . Dispose ( ) ;
264
282
}
265
283
}
284
+
266
285
}
267
286
}
0 commit comments