Skip to content

Commit 95f2768

Browse files
committed
fix: Send switch IDs instead of names when initializing.
1 parent 6a588b2 commit 95f2768

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

VisualPinball.Engine.Mpf.Test/Program.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ public static async Task Main(string[] args)
3939
var mpfApi = new MpfApi(machineFolder);
4040

4141
mpfApi.Launch(new MpfConsoleOptions {
42-
ShowLogInsteadOfConsole = true,
43-
CatchStdOut = true,
42+
//ShowLogInsteadOfConsole = true,
43+
//CatchStdOut = true,
4444
});
4545

4646
mpfApi.StartGame(new Dictionary<string, bool> {
47-
{"sw_11", false},
47+
{"1", true},
48+
{"2", true},
49+
{"3", true},
50+
{"4", true},
51+
{"5", true},
52+
{"6", true},
4853
});
4954
mpfApi.Client.OnConfigureHardwareRule += (_, request) => {
5055
Console.WriteLine($"[MPF] configure hw/rule: sw{request.SwitchNumber} -> c{request.CoilNumber} @{request.HoldPower} | pulse: {request.PulseMs}ms @{request.PulsePower}");

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,16 @@ public void OnInit(Player player, TableApi tableApi, BallManager ballManager)
8181
_api.Client.OnRemoveHardwareRule += OnRemoveHardwareRule;
8282
_api.Client.OnFadeLight += OnFadeLight;
8383

84-
_api.StartGame(player.SwitchStatusesClosed);
84+
// map initial switches
85+
var mappedSwitchStatuses = new Dictionary<string, bool>();
86+
foreach (var swName in player.SwitchStatusesClosed.Keys) {
87+
if (_switchIds.ContainsKey(swName)) {
88+
mappedSwitchStatuses[_switchIds[swName].ToString()] = player.SwitchStatusesClosed[swName];
89+
} else {
90+
Logger.Warn($"Unknown intial switch name \"{swName}\".");
91+
}
92+
}
93+
_api.StartGame(mappedSwitchStatuses);
8594
}
8695

8796
public void Switch(string id, bool isClosed)

VisualPinball.Engine.Mpf/MpfClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void StartGame(Dictionary<string, bool> initialSwitches, bool handleStrea
5353
ms.InitialSwitchStates.Add(sw, initialSwitches[sw]);
5454
}
5555

56-
Logger.Info("Starting client...");
56+
Logger.Info("Starting player with machine state: " + ms);
5757
_commandStream = _client.Start(ms);
5858

5959
if (handleStream) {

0 commit comments

Comments
 (0)