28
28
29
29
namespace VisualPinball . Engine . PinMAME
30
30
{
31
- [ AddComponentMenu ( "Visual Pinball/Mechs/PinMAME Mech Handler" ) ]
32
- public class PinMameMechComponent : MonoBehaviour , IMechHandler , ISwitchDeviceComponent , ICoilDeviceComponent , ISerializationCallbackReceiver
31
+ [ AddComponentMenu ( "Pinball/Mechs/PinMAME Mech Handler" ) ]
32
+ public class PinMameMechComponent : MonoBehaviour , IMechHandler , ISwitchDeviceComponent , ICoilDeviceComponent ,
33
+ IPinballEventEmitter , ISerializationCallbackReceiver
33
34
{
34
35
#region Data
35
36
@@ -78,6 +79,11 @@ public class PinMameMechComponent : MonoBehaviour, IMechHandler, ISwitchDeviceCo
78
79
[ SerializeField ] private string _solenoid2 ;
79
80
80
81
public event EventHandler < MechEventArgs > OnMechUpdate ;
82
+ public event EventHandler < PinballEventArgs > OnPinballEvent ;
83
+ public PinballEvent [ ] Events => new [ ] {
84
+ new PinballEvent ( EventNameSpeed , PinballEventUnit . DegreesPerSecond ) ,
85
+ new PinballEvent ( EventNamePosition , PinballEventUnit . Degrees ) ,
86
+ } ;
81
87
82
88
public PinMameMechConfig Config ( List < SwitchMapping > switchMappings , List < CoilMapping > coilMappings , Dictionary < string , int > switchIdToPinMameIdMappings , Dictionary < string , int > coilIdToPinMameIdMappings )
83
89
{
@@ -155,6 +161,9 @@ public PinMameMechConfig Config(List<SwitchMapping> switchMappings, List<CoilMap
155
161
156
162
private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
157
163
164
+ private const string EventNameSpeed = "Mech Speed" ;
165
+ private const string EventNamePosition = "Mech Position" ;
166
+
158
167
#endregion
159
168
160
169
#region Wiring
@@ -173,15 +182,16 @@ public PinMameMechConfig Config(List<SwitchMapping> switchMappings, List<CoilMap
173
182
174
183
public IEnumerable < GamelogicEngineCoil > AvailableCoils {
175
184
get {
176
- switch ( Type )
177
- {
185
+ switch ( Type ) {
178
186
case PinMameMechType . OneSolenoid :
179
187
return new [ ] { new GamelogicEngineCoil ( _solenoid1 ) { Description = "Motor Power" } } ;
188
+
180
189
case PinMameMechType . OneDirectionalSolenoid :
181
190
return new [ ] {
182
191
new GamelogicEngineCoil ( _solenoid1 ) { Description = "Motor Power" } ,
183
192
new GamelogicEngineCoil ( _solenoid2 ) { Description = "Motor Direction" } ,
184
193
} ;
194
+
185
195
case PinMameMechType . TwoDirectionalSolenoids :
186
196
return new [ ] {
187
197
new GamelogicEngineCoil ( _solenoid1 ) { Description = "Motor Clockwise" } ,
@@ -193,16 +203,20 @@ public IEnumerable<GamelogicEngineCoil> AvailableCoils {
193
203
new GamelogicEngineCoil ( _solenoid1 ) { Description = "Stepper 1" } ,
194
204
new GamelogicEngineCoil ( _solenoid2 ) { Description = "Stepper 2" } ,
195
205
} ;
206
+
196
207
case PinMameMechType . FourStepperSolenoids :
197
208
return new [ ] {
198
209
new GamelogicEngineCoil ( _solenoid1 ) { Description = "First Stepper" } ,
199
210
} ;
211
+
200
212
default :
201
213
throw new ArgumentOutOfRangeException ( ) ;
202
214
}
203
215
}
204
216
}
205
217
218
+ IApiCoil ICoilDeviceComponent . CoilDevice ( string deviceId ) => null ; // fixme
219
+
206
220
#endregion
207
221
208
222
#region Runtime
@@ -225,6 +239,8 @@ private void Start()
225
239
public void UpdateMech ( PinMameMechInfo data )
226
240
{
227
241
OnMechUpdate ? . Invoke ( this , new MechEventArgs ( data . Speed , data . Pos ) ) ;
242
+ OnPinballEvent ? . Invoke ( this , new PinballEventArgs ( EventNameSpeed , data . Speed , PinballEventUnit . MetersPerSecond ) ) ;
243
+ OnPinballEvent ? . Invoke ( this , new PinballEventArgs ( EventNamePosition , data . Pos , PinballEventUnit . Degrees ) ) ;
228
244
}
229
245
230
246
#endregion
0 commit comments