예제 #1
0
        private static GamelogicEngineSwitch GuessSwitchDeviceItem(GamelogicEngineSwitch engineSwitch, ISwitchDeviceComponent device)
        {
            // if there's only one switch, it's the one.
            if (device.AvailableSwitches.Count() == 1 && string.IsNullOrEmpty(engineSwitch.DeviceItemHint))
            {
                return(device.AvailableSwitches.First());
            }

            // otherwise, if not hint, we can't know.
            if (string.IsNullOrEmpty(engineSwitch.DeviceItemHint))
            {
                return(null);
            }

            // match by regex
            foreach (var deviceSwitch in device.AvailableSwitches)
            {
                var regex = new Regex(engineSwitch.DeviceItemHint, RegexOptions.IgnoreCase);
                if (regex.Match(deviceSwitch.Id).Success)
                {
                    return(deviceSwitch);
                }
            }
            return(null);
        }
예제 #2
0
        private static int GuessSwitchSource(GamelogicEngineSwitch engineSwitch)
        {
            if (!string.IsNullOrEmpty(engineSwitch.DeviceHint))
            {
                return(SwitchSource.Device);
            }

            return(!string.IsNullOrEmpty(engineSwitch.InputActionHint) ? SwitchSource.InputSystem : SwitchSource.Playfield);
        }
예제 #3
0
        private static SwitchSource GuessSwitchSource(GamelogicEngineSwitch engineSwitch)
        {
            if (!string.IsNullOrEmpty(engineSwitch.DeviceHint))
            {
                return(SwitchSource.Playfield);
            }

            if (engineSwitch.ConstantHint != SwitchConstantHint.None)
            {
                return(SwitchSource.Constant);
            }

            return(!string.IsNullOrEmpty(engineSwitch.InputActionHint) ? SwitchSource.InputSystem : SwitchSource.Playfield);
        }
예제 #4
0
 private static GamelogicEngineSwitch GuessDeviceSwitch(GamelogicEngineSwitch engineSwitch, ISwitchableDevice device)
 {
     if (!string.IsNullOrEmpty(engineSwitch.DeviceItemHint))
     {
         foreach (var deviceSwitch in device.AvailableSwitches)
         {
             var regex = new Regex(engineSwitch.DeviceItemHint.ToLower());
             if (regex.Match(deviceSwitch.Id).Success)
             {
                 return(deviceSwitch);
             }
         }
     }
     return(default);
예제 #5
0
        public static IEnumerable <GamelogicEngineSwitch> GetSwitches(this MachineDescription md)
        {
            return(md.Switches.Select(sw => {
                var gleSw = new GamelogicEngineSwitch(sw.Name, int.Parse(sw.HardwareNumber))
                {
                    NormallyClosed = sw.SwitchType.ToLower() == "nc"
                };

                if (Regex.Match(sw.Name, "l(eft)?_?flipper|flipper_?l(eft)?", RegexOptions.IgnoreCase).Success)
                {
                    gleSw.Description = "Left Flipper Button";
                    gleSw.InputActionHint = InputConstants.ActionLeftFlipper;
                }
                if (Regex.Match(sw.Name, "r(ight)?_?flipper|flipper_?r(ight)?", RegexOptions.IgnoreCase).Success)
                {
                    gleSw.Description = "Right Flipper Button";
                    gleSw.InputActionHint = InputConstants.ActionRightFlipper;
                }
                else if (Regex.Match(sw.Name, "plunger", RegexOptions.IgnoreCase).Success)
                {
                    gleSw.Description = "Plunger Button";
                    gleSw.InputActionHint = InputConstants.ActionPlunger;
                }
                else if (Regex.Match(sw.Name, "start", RegexOptions.IgnoreCase).Success)
                {
                    gleSw.Description = "Start Button";
                    gleSw.InputActionHint = InputConstants.ActionStartGame;
                }
                else if (Regex.Match(sw.Name, "trough_?jam", RegexOptions.IgnoreCase).Success)
                {
                    gleSw.Description = "Trough: Jam Switch";
                    gleSw.DeviceHint = "^Trough\\s*\\d?";
                    gleSw.DeviceItemHint = "jam";
                }
                else
                {
                    var troughSwitchMatch = Regex.Match(sw.Name, "trough_?(\\d+)", RegexOptions.IgnoreCase);
                    if (troughSwitchMatch.Success)
                    {
                        var num = troughSwitchMatch.Groups[1].Value;
                        gleSw.Description = $"Trough {num}";
                        gleSw.DeviceHint = "^Trough\\s*\\d?";
                        gleSw.DeviceItemHint = num;
                    }
                }

                return gleSw;
            }));
        }
예제 #6
0
        private static ISwitchable GuessPlayfieldSwitch(Dictionary <string, ISwitchable> switches, GamelogicEngineSwitch engineSwitch)
        {
            // first, match by regex if hint provided
            if (!string.IsNullOrEmpty(engineSwitch.PlayfieldItemHint))
            {
                foreach (var switchName in switches.Keys)
                {
                    var regex = new Regex(engineSwitch.PlayfieldItemHint.ToLower());
                    if (regex.Match(switchName).Success)
                    {
                        return(switches[switchName]);
                    }
                }
            }

            // second, match by "swXX" or name
            var matchKey = int.TryParse(engineSwitch.Id, out var numericSwitchId)
                                ? $"sw{numericSwitchId}"
                                : engineSwitch.Id;

            return(switches.ContainsKey(matchKey) ? switches[matchKey] : null);
        }
예제 #7
0
        private static IEnumerable <ISwitchDeviceComponent> GuessSwitchDevices(ISwitchDeviceComponent[] switchDevices, GamelogicEngineSwitch engineSwitch)
        {
            List <ISwitchDeviceComponent> switches = new List <ISwitchDeviceComponent>();

            // if no hint, match by name
            if (string.IsNullOrEmpty(engineSwitch.DeviceHint))
            {
                var matchKey = int.TryParse(engineSwitch.Id, out var numericSwitchId)
                                        ? $"sw{numericSwitchId}"
                                        : engineSwitch.Id;

                var swMatch = switchDevices.FirstOrDefault(sw => sw.name == matchKey);
                if (swMatch != null)
                {
                    switches.Add(swMatch);
                }
            }
            else if (!string.IsNullOrEmpty(engineSwitch.DeviceHint))
            {
                var regex = new Regex(engineSwitch.DeviceHint, RegexOptions.IgnoreCase);
                foreach (var device in switchDevices)
                {
                    if (regex.Match(device.name).Success)
                    {
                        switches.Add(device);
                        if (switches.Count() >= engineSwitch.NumMatches)
                        {
                            return(switches);
                        }
                    }
                }
            }

            return(switches);
        }
예제 #8
0
 private static ISwitchableDevice GuessDevice(Dictionary <string, ISwitchableDevice> switchDevices, GamelogicEngineSwitch engineSwitch)
 {
     // match by regex if hint provided
     if (!string.IsNullOrEmpty(engineSwitch.DeviceHint))
     {
         foreach (var deviceName in switchDevices.Keys)
         {
             var regex = new Regex(engineSwitch.DeviceHint.ToLower());
             if (regex.Match(deviceName).Success)
             {
                 return(switchDevices[deviceName]);
             }
         }
     }
     return(null);
 }