Skip to content

Commit 34a3f91

Browse files
committed
editor: Add some basic matching rules to switches and coil.
1 parent d8e8f31 commit 34a3f91

File tree

2 files changed

+84
-3
lines changed

2 files changed

+84
-3
lines changed

VisualPinball.Engine.Mpf.Unity/Editor/MpfGamelogicEngineInspector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public override void OnInspectorGUI()
7070
if (GUILayout.Button("Populate Hardware")) {
7171
if (EditorUtility.DisplayDialog("Mission Pinball Framework", "This will clear all linked switches, coils and lamps and re-populate them. You sure you want to do that?", "Yes", "No")) {
7272
_tableAuthoring.RepopulateHardware(_mpfEngine);
73+
TableSelector.Instance.TableUpdated();
7374
SceneView.RepaintAll();
7475
}
7576
}

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

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
using System.Collections.Generic;
1313
using System.Linq;
14+
using System.Text.RegularExpressions;
1415
using Mpf.Vpe;
16+
using VisualPinball.Engine.Common;
1517
using VisualPinball.Engine.Game.Engines;
1618

1719
namespace VisualPinball.Engine.Mpf.Unity
@@ -20,14 +22,92 @@ public static class MpfExtensions
2022
{
2123
public static IEnumerable<GamelogicEngineSwitch> GetSwitches(this MachineDescription md)
2224
{
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;
2562
});
2663
}
2764

2865
public static IEnumerable<GamelogicEngineCoil> GetCoils(this MachineDescription md)
2966
{
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;
31111
}
32112

33113
public static IEnumerable<GamelogicEngineLamp> GetLights(this MachineDescription md)

0 commit comments

Comments
 (0)