public Profile( string name, IEnumerable <Button> modifiers, IAnalogHandler leftAnalogHandler, IAnalogHandler rightAnalogHandler, IDictionary <InputKey, IButtonHandler> buttonHandlers) { Name = name; Modifiers = modifiers?.ToList() ?? new List <Button>(); LeftAnalogHandler = leftAnalogHandler; RightAnalogHandler = rightAnalogHandler; ButtonHandlers = new Dictionary <InputKey, IButtonHandler>(buttonHandlers); }
public Profile CreateProfile(ProfileConfiguration profileConfig) { IAnalogHandler leftHandler = null; IAnalogHandler rightHandler = null; var handlers = new Dictionary <InputKey, IButtonHandler>(); var modifiers = new HashSet <Button>(); void SetAnalog(AnalogBinding analogBinding, IAnalogHandler analogHandler) { if (analogBinding.ThumbStick == ThumbStick.Left) { leftHandler = analogHandler; } else { rightHandler = analogHandler; } } foreach (var binding in profileConfig.Bindings) { switch (binding) { case MouseMapping mouseMapping: SetAnalog(mouseMapping, new MovementHandler(new MouseMovementActuator(Mouse), RootConfiguration.Mouse)); break; case ScrollMapping scrollMapping: SetAnalog(scrollMapping, new MovementHandler(new MouseScrollActuator(Mouse), RootConfiguration.Scroll)); break; case RadialMenuMapping radialMenuMapping: SetAnalog(radialMenuMapping, new RadialHandler(new MenuPointerActuator(MenuController), RootConfiguration.Menu)); break; case KeyMapping keyMapping: handlers[keyMapping.InputKey] = new KeyMapHandler(new KeyMapActuator(Keyboard, Mouse, keyMapping.Keys)); break; case ModMapping modMapping: if (modMapping.InputKey < InputKey.ModA) { modifiers.Add((Button)modMapping.InputKey); } break; case PressBinding pressBinding: handlers[pressBinding.InputKey] = pressBinding.Repeat ? (IButtonHandler) new KeyPressRepeatHandler(ActionFactory.Create(pressBinding.Action), RootConfiguration.Repeat) : new KeyPressHandler(ActionFactory.Create(pressBinding.Action)); break; case PressHoldBinding pressHoldBinding: handlers[pressHoldBinding.InputKey] = new KeyPressHoldHandler( ActionFactory.Create(pressHoldBinding.PressAction), ActionFactory.Create(pressHoldBinding.HoldAction), RootConfiguration.Hold); break; } } return(new Profile(profileConfig.Name, modifiers, leftHandler, rightHandler, handlers)); }