Example #1
0
        public static IList <InputBindingViewModel> ToBindings <TAction>(
            LanguageTable languageTable,
            InputBindingGroup bindingGroup,
            EmptyBinding <TAction>[] mappableBindings,
            InputSourceMapping <TAction> inputMapping,
            Maybe <UnityInputDeviceProfile> currentControllerProfile)
        {
            // TODO Optimize for garbage collection, use object pool
            var l = languageTable.AsFunc;

            var bindings = new List <InputBindingViewModel>();

            for (int i = 0; i < mappableBindings.Length; i++)
            {
                var    mappableBinding = mappableBindings[i];
                var    inputSources    = inputMapping.Mappings.GetOrDefault(mappableBinding.Id, null) ?? ImmutableList <InputSource> .Empty;
                string binding;
                if (inputSources.Count > 0)
                {
                    binding = InputSource2String(languageTable, inputSources[0], currentControllerProfile);
                }
                else
                {
                    binding = null;
                }
                bindings.Add(new InputBindingViewModel(
                                 new InputBindingId(bindingGroup, mappableBinding.Id),
                                 l(bindingGroup.ToString().ToUnderscoreCase()),
                                 l(mappableBinding.Id.ToString().ToUnderscoreCase()),
                                 l(mappableBinding.BindingType.ToUnderscoreCase()),
                                 binding));
            }
            return(bindings);
        }
Example #2
0
 public static IEnumerable <InputBindingViewModel> ToBindings(LanguageTable languageTable,
                                                              InputSourceMapping <ParachuteAction> inputMapping,
                                                              Maybe <UnityInputDeviceProfile> currentControllerProfile)
 {
     return(InputBindingView.ToBindings(languageTable, InputBindingGroup.Parachute, EmptyBindings, inputMapping,
                                        currentControllerProfile));
 }
Example #3
0
        public InputBindings(
            InputSourceMapping <TAction> initialMapping,
            IObservable <InputSettings> inputSettingChanges,
            IImmutableDictionary <InputDefaults, InputSourceMapping <TAction> > defaultMappings)
        {
            _defaultMappings    = defaultMappings;
            _usesDefaultMapping = false;
            foreach (var defaultMapping in defaultMappings.Values)
            {
                if (initialMapping.Equals(defaultMapping))
                {
                    _usesDefaultMapping = true;
                }
            }

            _inputMappings = new BehaviorSubject <InputSourceMapping <TAction> >(initialMapping);
            _inputMappings.Subscribe(mapping => {
                _currentMapping = mapping;
            });
            _activeControllerId      = null;
            _activeControllerUpdates = new BehaviorSubject <JoystickActivator.Controller?>(null);

            _actionMap = _inputMappings.CombineLatest(
                _activeControllerUpdates,
                inputSettingChanges.DistinctUntilChanged(EqualityComparer <InputSettings> .Default),
                (mapping, controller, settings) => {
                var controllerId = controller.HasValue ? controller.Value.Id : null;
                return(new ActionMapConfig <TAction> {
                    InputMapping = mapping,
                    ControllerId = controllerId,
                    InputSettings = settings
                });
            });
        }
Example #4
0
 public static void Serialize2Disk <TTargetId>(this InputSourceMapping <TTargetId> inputMapping, string path)
 {
     using (var fileStream = new FileStream(path, FileMode.Create))
         using (var textWriter = new StreamWriter(fileStream)) {
             Serializer.Serialize(textWriter, inputMapping);
         }
 }
Example #5
0
        public void UpdateMapping(TAction action, InputSource inputSource)
        {
            var mappings = _currentMapping
                           .Mappings
                           .SetItem(action, ImmutableList.Create <InputSource>(inputSource));

            _usesDefaultMapping = false;
            var updatedMapping = new InputSourceMapping <TAction>(mappings, formatVersion: InputSourceMapping <TAction> .CurrentFormatVersion);

            _inputMappings.OnNext(updatedMapping);
        }
Example #6
0
            private static InputMap <WingsuitAction, float> CreateControllerAxisInput(
                InputSourceMapping <WingsuitAction> inputMapping, InputSettings inputSettings, Peripherals.ControllerPeripheral peripheral)
            {
                var controllerAxisSourceMap = peripheral.Axes;

                var inputWithJoystickAxisSource = inputMapping.ApplyMapping(controllerAxisSourceMap, Adapters.MergeAxes);

                // Circularize input of pitch and roll if both are mapped to a joystick
                if (new [] { WingsuitAction.PitchUp, WingsuitAction.PitchDown, WingsuitAction.RollLeft, WingsuitAction.RollRight }.All(inputWithJoystickAxisSource.Keys.Contains))
                {
                    var            pitchUp           = inputWithJoystickAxisSource.Source[WingsuitAction.PitchUp];
                    var            pitchDown         = inputWithJoystickAxisSource.Source[WingsuitAction.PitchDown];
                    var            rollLeft          = inputWithJoystickAxisSource.Source[WingsuitAction.RollLeft];
                    var            rollRight         = inputWithJoystickAxisSource.Source[WingsuitAction.RollRight];
                    Func <Vector2> circularizedInput = () => InputUtilities.CircularizeInput(new Vector2(rollRight() - rollLeft(), pitchUp() - pitchDown()));
                    inputWithJoystickAxisSource = inputWithJoystickAxisSource.Source
                                                  .SetItem(WingsuitAction.PitchUp, () => Adapters.FilterPositiveInput(circularizedInput().y))
                                                  .SetItem(WingsuitAction.PitchDown, () => Adapters.Abs(Adapters.FilterNegativeInput(circularizedInput().y)))
                                                  .SetItem(WingsuitAction.RollLeft, () => Adapters.Abs(Adapters.FilterNegativeInput(circularizedInput().x)))
                                                  .SetItem(WingsuitAction.RollRight, () => Adapters.FilterPositiveInput(circularizedInput().x))
                                                  .ToInputMap();
                }
                // Scale all pitch, roll and yaw input of a joystick
                inputWithJoystickAxisSource = inputWithJoystickAxisSource.Adapt <WingsuitAction, float, float>((id, pollFn) => {
                    if (PilotBodyMovementActions.Contains(id))
                    {
                        return(pollFn.Adapt <float, float>(i => MathUtils.ScaleQuadratically(i, inputSettings.InputGamma)));
                    }
                    else if (PilotArmMovementActions.Contains(id))
                    {
                        return(pollFn.Adapt <float, float>(i => MathUtils.ScaleQuadratically(i, 2)));
                    }
                    return(pollFn);
                });
                return(inputWithJoystickAxisSource);
            }
Example #7
0
 public static string Serialize <TTargetId>(this InputSourceMapping <TTargetId> inputMapping)
 {
     return(Serializer.Serialize2String(inputMapping.Mappings));
 }