Beispiel #1
0
        /// <summary>
        /// Adds an input handler.
        /// </summary>
        /// <param name="type">the type of input handler</param>
        /// <param name="inputName">the name of the input handler</param>
        /// <returns><c>true</c>if the handler was added</returns>
        ///
        public bool AddMapping(InputManager.InputType type, string inputName)
        {
            IDevice device = null;

            // check for special devices
            if (inputName.Contains("-|+"))
            {
                // plus/minus device
                String[] parts = inputName.Split(new string[] { "-|+" }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length > 1)
                {
                    IDevice deviceMinus = CreateDevice(type, parts[0]);
                    IDevice devicePlus  = CreateDevice(type, parts[1]);
                    if ((devicePlus != null) && (deviceMinus != null))
                    {
                        device = new Device_PlusMinus(devicePlus, deviceMinus);
                    }
                }
            }
            else
            {
                // standard device
                device = CreateDevice(type, inputName);
            }

            if (device != null)
            {
                // success
                devices.Add(device);
            }

            return(device != null);
        }
Beispiel #2
0
        /// <summary>
        /// Adds an input handler.
        /// </summary>
        /// <param name="type">the type of input handler</param>
        /// <param name="inputName">the name of the input handler</param>
        /// <returns><c>true</c>if the handler was added</returns>
        ///
        public bool AddMapping(InputManager.InputType type, string inputName)
        {
            IDevice device = null;

            // check for special devices
            if (inputName.Contains("-|+"))
            {
                // plus/minus device
                string[] parts = inputName.Split(new string[] { "-|+" }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length > 1)
                {
                    IDevice deviceMinus = CreateDevice(type, parts[0]);
                    IDevice devicePlus  = CreateDevice(type, parts[1]);
                    if ((devicePlus != null) && (deviceMinus != null))
                    {
                        device = new Device_PlusMinus(devicePlus, deviceMinus);
                    }
                }
            }
            else if (inputName.Contains("T>") || inputName.Contains("T<"))
            {
                // plus/minus device
                Device_Threshold.EThresholdType thresholdType = inputName.Contains("T>") ?
                                                                Device_Threshold.EThresholdType.GreaterThan :
                                                                Device_Threshold.EThresholdType.LessThan;
                string[] parts = inputName.Split(new string[] { "T>", "T<" }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length > 1)
                {
                    IDevice deviceValue = CreateDevice(type, parts[0]);
                    float   threshold   = 0.5f;
                    float.TryParse(parts[1], out threshold);
                    if (deviceValue != null)
                    {
                        device = new Device_Threshold(deviceValue, thresholdType, threshold);
                    }
                }
            }
            else
            {
                // standard device
                device = CreateDevice(type, inputName);
            }

            if (device != null)
            {
                // success
                devices.Add(device);
            }

            return(device != null);
        }