public SwitchListData(SwitchMapping switchMapping)
        {
            Id             = switchMapping.Id;
            NormallyClosed = switchMapping.IsNormallyClosed;
            Description    = switchMapping.Description;
            Source         = switchMapping.Source;
            InputActionMap = switchMapping.InputActionMap;
            InputAction    = switchMapping.InputAction;
            Constant       = switchMapping.Constant;
            Device         = switchMapping.Device;
            if (string.IsNullOrEmpty(switchMapping.DeviceItem) && Device != null && Device.AvailableSwitches.Count() == 1)
            {
                DeviceItem = Device.AvailableSwitches.First().Id;
            }
            else
            {
                DeviceItem = switchMapping.DeviceItem;
            }

            PulseDelay = switchMapping.PulseDelay;

            SwitchMapping = switchMapping;
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 public bool SwitchDeviceExists(ISwitchDeviceComponent component)
 => _switchDevices.ContainsKey(component);
Exemplo n.º 4
0
 internal void RegisterSwitchDevice(ISwitchDeviceComponent component, IApiSwitchDevice switchDeviceApi)
 => _switchDevices[component] = switchDeviceApi;
Exemplo n.º 5
0
 internal IApiSwitch Switch(ISwitchDeviceComponent component, string deviceSwitchId)
 => _switchDevices.ContainsKey(component) ? _switchDevices[component].Switch(deviceSwitchId) : null;
Exemplo n.º 6
0
 internal IApiSwitch Switch(ISwitchDeviceComponent component, string switchItem) => _player.Switch(component, switchItem);
Exemplo n.º 7
0
 /// <summary>
 /// Links a switch device to an existing switch mapping if it matches a given name.
 /// </summary>
 /// <param name="tableComponent">Table component for retrieving mappings.</param>
 /// <param name="elementName">The name that the switch device's GameObject has to match in order to be linked.</param>
 /// <param name="switchId">The ID of the switch mapping that the switch device will be linked to</param>
 /// <param name="switchDevice">The switch device to be linked</param>
 protected static void LinkSwitch(TableComponent tableComponent, string elementName, string switchId, ISwitchDeviceComponent switchDevice)
 {
     if (!string.Equals(switchDevice.gameObject.name, elementName, StringComparison.OrdinalIgnoreCase))
     {
         return;
     }
     LinkSwitch(tableComponent, switchId, switchDevice);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Links a switch device to an existing switch mapping.
        /// </summary>
        /// <param name="tableComponent">Table component for retrieving mappings.</param>
        /// <param name="switchId">The ID of the switch mapping that the switch device will be linked to</param>
        /// <param name="switchDevice">The switch device to be linked</param>
        /// <param name="switchDeviceItem">Switch ID inside of the device item. If null, the first switch will be used.</param>
        protected static void LinkSwitch(TableComponent tableComponent, string switchId, ISwitchDeviceComponent switchDevice, string switchDeviceItem = null)
        {
            var switchMapping = tableComponent.MappingConfig.Switches.FirstOrDefault(sw => sw.Id == switchId);

            if (switchMapping == null)
            {
                return;
            }
            switchMapping.Device     = switchDevice;
            switchMapping.DeviceItem = switchDeviceItem ?? switchDevice.AvailableSwitches.First().Id;
        }
 public void ClearDevice()
 {
     Device     = null;
     DeviceItem = null;
     Update();
 }