Skip to content

Commit

Permalink
Add: Support 0-prefixed switch names (up to 1000).
Browse files Browse the repository at this point in the history
  • Loading branch information
freezy committed Jan 5, 2023
1 parent c616745 commit 6728f4e
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ private void UpdateCaches()
_pinMameIdToSwitchIdMappings.Clear();
_switchIdToPinMameIdMappings.Clear();

// check aliases first (the switches/coils that aren't an integer)
foreach (var alias in _game.AvailableAliases) {
switch (alias.AliasType) {
case AliasType.Switch:
Expand All @@ -352,16 +353,30 @@ private void UpdateCaches()
}
}


// retrieve the game's switches
foreach (var @switch in _game.AvailableSwitches) {
_switches[@switch.Id] = @switch;

if (int.TryParse(@switch.Id, out int pinMameId)) {
if (int.TryParse(@switch.Id, out var pinMameId)) {
_pinMameIdToSwitchIdMappings[pinMameId] = @switch.Id;
_switchIdToPinMameIdMappings[@switch.Id] = pinMameId;

// add mappings with prefixed 0.
if (pinMameId < 10) {
_switchIdToPinMameIdMappings["0" + @switch.Id] = pinMameId;
_switchIdToPinMameIdMappings["00" + @switch.Id] = pinMameId;

_switches["0" + @switch.Id] = @switch;
_switches["00" + @switch.Id] = @switch;
}
if (pinMameId < 100) {
_switchIdToPinMameIdMappings["0" + @switch.Id] = pinMameId;
_switches["0" + @switch.Id] = @switch;
}
}
}

// retrieve the game's coils
foreach (var coil in _game.AvailableCoils) {
_coils[coil.Id] = coil;

Expand All @@ -371,6 +386,7 @@ private void UpdateCaches()
}
}

// retrieve the game's lamps
foreach (var lamp in _game.AvailableLamps) {
_lamps[lamp.Id] = lamp;

Expand Down

0 comments on commit 6728f4e

Please sign in to comment.