11
11
12
12
using System . Collections . Generic ;
13
13
using System . Linq ;
14
+ using System . Text . RegularExpressions ;
14
15
using Mpf . Vpe ;
16
+ using VisualPinball . Engine . Common ;
15
17
using VisualPinball . Engine . Game . Engines ;
16
18
17
19
namespace VisualPinball . Engine . Mpf . Unity
@@ -20,14 +22,92 @@ public static class MpfExtensions
20
22
{
21
23
public static IEnumerable < GamelogicEngineSwitch > GetSwitches ( this MachineDescription md )
22
24
{
23
- return md . Switches . Select ( sw => new GamelogicEngineSwitch ( sw . Name , int . Parse ( sw . HardwareNumber ) ) {
24
- NormallyClosed = sw . SwitchType . ToLower ( ) == "nc"
25
+ return md . Switches . Select ( sw => {
26
+ var gleSw = new GamelogicEngineSwitch ( sw . Name , int . Parse ( sw . HardwareNumber ) ) {
27
+ NormallyClosed = sw . SwitchType . ToLower ( ) == "nc"
28
+ } ;
29
+
30
+ if ( Regex . Match ( sw . Name , "l(eft)?_?flipper|flipper_?l(eft)?" , RegexOptions . IgnoreCase ) . Success ) {
31
+ gleSw . Description = "Left Flipper Button" ;
32
+ gleSw . InputActionHint = InputConstants . ActionLeftFlipper ;
33
+
34
+ } if ( Regex . Match ( sw . Name , "r(ight)?_?flipper|flipper_?r(ight)?" , RegexOptions . IgnoreCase ) . Success ) {
35
+ gleSw . Description = "Right Flipper Button" ;
36
+ gleSw . InputActionHint = InputConstants . ActionRightFlipper ;
37
+
38
+ } else if ( Regex . Match ( sw . Name , "plunger" , RegexOptions . IgnoreCase ) . Success ) {
39
+ gleSw . Description = "Plunger Button" ;
40
+ gleSw . InputActionHint = InputConstants . ActionPlunger ;
41
+
42
+ } else if ( Regex . Match ( sw . Name , "start" , RegexOptions . IgnoreCase ) . Success ) {
43
+ gleSw . Description = "Start Button" ;
44
+ gleSw . InputActionHint = InputConstants . ActionStartGame ;
45
+
46
+ } else if ( Regex . Match ( sw . Name , "trough_?jam" , RegexOptions . IgnoreCase ) . Success ) {
47
+ gleSw . Description = "Trough: Jam Switch" ;
48
+ gleSw . DeviceHint = "^Trough\\ s*\\ d?" ;
49
+ gleSw . DeviceItemHint = "jam" ;
50
+
51
+ } else {
52
+ var troughSwitchMatch = Regex . Match ( sw . Name , "trough_?(\\ d+)" , RegexOptions . IgnoreCase ) ;
53
+ if ( troughSwitchMatch . Success ) {
54
+ var num = troughSwitchMatch . Groups [ 1 ] . Value ;
55
+ gleSw . Description = $ "Trough { num } ";
56
+ gleSw . DeviceHint = "^Trough\\ s*\\ d?" ;
57
+ gleSw . DeviceItemHint = num ;
58
+ }
59
+ }
60
+
61
+ return gleSw ;
25
62
} ) ;
26
63
}
27
64
28
65
public static IEnumerable < GamelogicEngineCoil > GetCoils ( this MachineDescription md )
29
66
{
30
- return md . Coils . Select ( coil => new GamelogicEngineCoil ( coil . Name , int . Parse ( coil . HardwareNumber ) ) ) ;
67
+ var leftFlipperCoil = string . Empty ;
68
+ var rightFlipperCoil = string . Empty ;
69
+ var leftFlipperHoldCoil = string . Empty ;
70
+ var rightFlipperHoldCoil = string . Empty ;
71
+
72
+ var coils = md . Coils . Select ( coil => {
73
+ var gleCoil = new GamelogicEngineCoil ( coil . Name , int . Parse ( coil . HardwareNumber ) ) ;
74
+
75
+ if ( Regex . Match ( coil . Name , "(l(eft)?_?flipper|flipper_?l(eft)?_?(main)?)$" , RegexOptions . IgnoreCase ) . Success ) {
76
+ gleCoil . Description = "Left Flipper" ;
77
+ gleCoil . PlayfieldItemHint = "^(LeftFlipper|LFlipper|FlipperLeft|FlipperL)$" ;
78
+ leftFlipperCoil = coil . Name ;
79
+
80
+ } else if ( Regex . Match ( coil . Name , "(l(eft)?_?flipper|flipper_?l(eft)?)_?hold$" , RegexOptions . IgnoreCase ) . Success ) {
81
+ gleCoil . Description = "Left Flipper (hold)" ;
82
+ leftFlipperHoldCoil = coil . Name ;
83
+
84
+ } else if ( Regex . Match ( coil . Name , "(r(ight)?_?flipper|flipper_?r(ight)?_?(main)?)$" , RegexOptions . IgnoreCase ) . Success ) {
85
+ gleCoil . Description = "Right Flipper" ;
86
+ gleCoil . PlayfieldItemHint = "^(RightFlipper|RFlipper|FlipperRight|FlipperR)$" ;
87
+ rightFlipperCoil = coil . Name ;
88
+
89
+ } else if ( Regex . Match ( coil . Name , "(r(ight)?_?flipper|flipper_?r(ight)?)_?hold$" , RegexOptions . IgnoreCase ) . Success ) {
90
+ gleCoil . Description = "Right Flipper (hold)" ;
91
+ rightFlipperHoldCoil = coil . Name ;
92
+
93
+ } else if ( Regex . Match ( coil . Name , "trough_?eject" , RegexOptions . IgnoreCase ) . Success ) {
94
+ gleCoil . Description = "Trough Eject" ;
95
+ gleCoil . DeviceHint = "^Trough\\ s*\\ d?" ;
96
+ gleCoil . DeviceItemHint = "eject" ;
97
+ }
98
+
99
+ return gleCoil ;
100
+ } ) . ToArray ( ) ;
101
+
102
+ foreach ( var coil in coils ) {
103
+ if ( coil . Id == leftFlipperHoldCoil ) {
104
+ coil . MainCoilIdOfHoldCoil = leftFlipperCoil ;
105
+ } else if ( coil . Id == rightFlipperHoldCoil ) {
106
+ coil . MainCoilIdOfHoldCoil = rightFlipperCoil ;
107
+ }
108
+ }
109
+
110
+ return coils ;
31
111
}
32
112
33
113
public static IEnumerable < GamelogicEngineLamp > GetLights ( this MachineDescription md )
0 commit comments