Example #1
0
        /// <summary>
        /// Refreshes the current state. Triggers <see cref="InputChanged"/> event.
        /// </summary>
        /// <returns>if the input was available</returns>
        public bool RefreshInput()
        {
            foreach (var type in XInputHelper.Instance.Values)
            {
                var mapping = mapper.GetMapping(type);
                if (mapping != null)
                {
                    double value = 0;
                    if (mapping.InputType != null)
                    {
                        value = source.Get(mapping.InputType);
                    }
                    values[type] = mapping.GetValue(value);
                }
            }
            if (mapper.SelectedDPad != -1)
            {
                dPads[0] = source.DPads.ElementAt(mapper.SelectedDPad);
            }
            else
            {
                dPads[0] = DPadHelper.GetDirection(GetBool(XInputTypes.UP), GetBool(XInputTypes.DOWN), GetBool(XInputTypes.LEFT), GetBool(XInputTypes.RIGHT));
            }
            var changedDPads  = state.SetDPads(dPads);
            var changedValues = state.SetValues(values.Where(t => !t.Key.IsDPad()).ToDictionary(x => (Enum)x.Key, x => x.Value));

            if (changedDPads.Any() || changedValues.Any())
            {
                InputChanged?.Invoke(this, new DeviceInputChangedEventArgs(changedValues, changedDPads));
            }
            return(true);
        }