예제 #1
0
        /// <inheritdoc/>
        public virtual string Serialize(IInputTemplate inputTemplate, IInputMapping inputMapping)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(this.ConfigurationSerializer.SerializeHeader(
                                     inputTemplate.Descriptor.SectionName.Replace("{N}", inputTemplate.PlayerIndex.ToString())));

            IConfigurationSection inputOptions = inputTemplate;

            foreach (var config in inputOptions.Descriptor.Options)
            {
                stringBuilder.AppendLine(this.ConfigurationSerializer.SerializeLine(
                                             config.OptionName.Replace("{N}", inputTemplate.PlayerIndex.ToString()),
                                             inputOptions.Values[config.OptionKey].Value));
            }

            foreach (var input in inputTemplate.Options)
            {
                stringBuilder.AppendLine(this.SerializeInput(
                                             input.OptionName.Replace("{N}", inputTemplate.PlayerIndex.ToString()),
                                             inputTemplate.Values[input.KeyName], inputMapping));
            }

            stringBuilder.Append(this.ConfigurationSerializer.SerializeFooter(
                                     inputTemplate.Descriptor.SectionName.Replace("{N}", inputTemplate.PlayerIndex.ToString())));

            return(stringBuilder.ToString());
        }
        /* Win32 End */
        public override string CompileController(int playerIndex, IPlatformInfo platformInfo, IControllerDefinition controllerDefinition, IControllerTemplate controllerTemplate, IControllerProfile controllerProfile, IInputTemplate inputTemplate)
        {
            var controllerMappings = controllerProfile.ProfileType == ControllerProfileType.KEYBOARD_PROFILE ?
                                     controllerTemplate.KeyboardControllerMappings : controllerTemplate.GamepadControllerMappings;
            string deviceName            = this.CoreInstance.ControllerPortsDatabase.GetDeviceInPort(platformInfo, playerIndex);
            IList <IInputDevice> devices = new InputManager().GetGamepads();

            if (!devices.Select(device => device.DI_ProductName).Contains(deviceName) || !(devices.Where(device => device.XI_IsXInput).Count() == 0))
            { //todo fix this
                if (deviceName == InputDeviceNames.XInputDevice1)
                {
                    var xinputDevice = devices.Where(device => device.XI_IsXInput).Where(device => device.XI_GamepadIndex == 1).FirstOrDefault();
                    if (!xinputDevice.Equals(null))
                    {
                        controllerMappings["default"].KeyMappings["JOYPAD_INDEX"] = xinputDevice.DeviceIndex.ToString();
                    }
                }
                if (deviceName == InputDeviceNames.XInputDevice2)
                {
                    var xinputDevice = devices.Where(device => device.XI_IsXInput).Where(device => device.XI_GamepadIndex == 1).FirstOrDefault();
                    if (!xinputDevice.Equals(null))
                    {
                        controllerMappings["default"].KeyMappings["JOYPAD_INDEX"] = xinputDevice.DeviceIndex.ToString();
                    }
                }
                if (deviceName == InputDeviceNames.XInputDevice3)
                {
                    var xinputDevice = devices.Where(device => device.XI_IsXInput).Where(device => device.XI_GamepadIndex == 1).FirstOrDefault();
                    if (!xinputDevice.Equals(null))
                    {
                        controllerMappings["default"].KeyMappings["JOYPAD_INDEX"] = xinputDevice.DeviceIndex.ToString();
                    }
                }
                if (deviceName == InputDeviceNames.XInputDevice4)
                {
                    var xinputDevice = devices.Where(device => device.XI_IsXInput).Where(device => device.XI_GamepadIndex == 1).FirstOrDefault();
                    if (!xinputDevice.Equals(null))
                    {
                        controllerMappings["default"].KeyMappings["JOYPAD_INDEX"] = xinputDevice.DeviceIndex.ToString();
                    }
                }
                if (devices.Select(device => device.DI_ProductName).Contains(deviceName))
                {
                    controllerMappings["default"].KeyMappings["JOYPAD_INDEX"] = devices.Where(device => device.DI_ProductName == deviceName).First().DeviceIndex.ToString();
                }
            }
            else
            {
                controllerProfile  = controllerDefinition.ProfileStore[InputDeviceNames.KeyboardDevice];
                controllerMappings = controllerTemplate.KeyboardControllerMappings;
                playerIndex        = 1; //Force Keyboard player 1 if no controllers detected
            }
            return(base.CompileController(playerIndex, platformInfo, controllerDefinition, controllerTemplate, controllerProfile, inputTemplate, controllerMappings));
        }
예제 #3
0
 public InputTemplateCircularInterceptor(IInputTemplate <T> @this)
 {
     this.@this = @this;
 }
예제 #4
0
        public override string CompileController(int playerIndex, IPlatformInfo platformInfo, IControllerDefinition controllerDefinition, IControllerTemplate controllerTemplate, IGamepadAbstraction gamepadAbstraction, IInputTemplate inputTemplate, IReadOnlyDictionary <string, IControllerMapping> controllerMappings, IGameInfo gameInfo)
        {
            if (gamepadAbstraction.ProfileType == ControllerProfileType.NULL_PROFILE)
            {
                return(string.Empty);
            }
            var template = new StringBuilder(inputTemplate.StringTemplate);

            foreach (IControllerInput input in controllerDefinition.ControllerInputs.Values)
            {
                string templateKey   = controllerMappings["default"].InputMappings[input.InputName];
                string inputSetting  = gamepadAbstraction[input.GamepadAbstraction];
                string emulatorValue = gamepadAbstraction.ProfileType == ControllerProfileType.KEYBOARD_PROFILE ?
                                       inputTemplate.KeyboardMappings.First().Value[inputSetting] : inputTemplate.GamepadMappings.First().Value[inputSetting];
                template.Replace($"{{{templateKey}}}", emulatorValue);
            }

            if (platformInfo.PlatformID == StonePlatforms.NINTENDO_WII && controllerDefinition.ControllerID == "GCN_CONTROLLER")
            {
                template.Replace("{N}", (playerIndex - 4).ToString()); //Account for GCPad being in controller positions 5-8.
            }
            else
            {
                template.Replace("{N}", playerIndex.ToString()); //Player Index
            }

            foreach (string key in inputTemplate.TemplateKeys)
            {
                template.Replace($"{{{key}}}",
                                 controllerMappings["default"].KeyMappings.ContainsKey(key)
                        ? controllerMappings["default"].KeyMappings[key]
                        : inputTemplate.NoBind);
            }
            return(template.ToString());
        }
예제 #5
0
        public override string CompileController(int playerIndex, IPlatformInfo platformInfo, IControllerDefinition controllerDefinition, IControllerTemplate controllerTemplate, IGamepadAbstraction gamepadAbstraction, IInputTemplate inputTemplate, IGameInfo gameInfo)
        {
            var controllerMappings = gamepadAbstraction.ProfileType == ControllerProfileType.KEYBOARD_PROFILE ?
                                     controllerTemplate.KeyboardControllerMappings : controllerTemplate.GamepadControllerMappings;

            string deviceName            = gamepadAbstraction.DeviceName;
            IList <IInputDevice> devices = new InputManager().GetGamepads();

            if (deviceName == null)
            {
                deviceName = String.Empty;
            }

            int realWiimoteAmount = devices.Count(device => device.DI_ProductName.Contains("RVL-CNT"));

            if (controllerDefinition.ControllerID == "WII_COMBINED_CONTROLLER")
            {
                //All wiimotes have the same attachment
                int wiimote_extension = this.ConfigurationFlagStore.GetValue(gameInfo, "wiimote_extension", ConfigurationFlagTypes.SELECT_FLAG);
                controllerMappings["default"].KeyMappings["EXTENSION"] = this.ConfigurationFlags["wiimote_extension"].SelectValues[wiimote_extension].Value;

                if (playerIndex <= realWiimoteAmount)
                {
                    controllerMappings["default"].KeyMappings["SOURCE"] = "2"; //Real Wiimotes take precedence
                }
                else
                {
                    controllerMappings["default"].KeyMappings["SOURCE"] = "1"; //Emulated Wiimote
                }
            }

            if (deviceName.Equals(InputDeviceNames.KeyboardDevice, StringComparison.InvariantCultureIgnoreCase))
            {
                controllerMappings["default"].KeyMappings["DEVICE"] = "DInput/0/Keyboard Mouse";
                return(this.CompileController(playerIndex, platformInfo, controllerDefinition, controllerTemplate,
                                              gamepadAbstraction, inputTemplate, controllerMappings, gameInfo));
            }
            string xinputDevice = "XInput/{0}/Gamepad";
            string dintpuDevice = "DInput/{0}/{1}";

            if (deviceName.Equals(InputDeviceNames.XInputDevice1, StringComparison.InvariantCultureIgnoreCase))
            {
                controllerMappings["default"].KeyMappings["DEVICE"] =
                    String.Format(xinputDevice, 0);
            }
            else if (deviceName.Equals(InputDeviceNames.XInputDevice2, StringComparison.InvariantCultureIgnoreCase))
            {
                controllerMappings["default"].KeyMappings["DEVICE"] =
                    String.Format(xinputDevice, 1);
            }
            else if (deviceName.Equals(InputDeviceNames.XInputDevice3, StringComparison.InvariantCultureIgnoreCase))
            {
                controllerMappings["default"].KeyMappings["DEVICE"] =
                    String.Format(xinputDevice, 2);
            }
            else if (deviceName.Equals(InputDeviceNames.XInputDevice4, StringComparison.InvariantCultureIgnoreCase))
            {
                controllerMappings["default"].KeyMappings["DEVICE"] =
                    String.Format(xinputDevice, 3);
            }
            else if (devices.Select(device => device.DI_ProductName).Contains(deviceName))
            {
                var device = devices.First(d => d.DI_ProductName == deviceName);
                controllerMappings["default"].KeyMappings["DEVICE"] =
                    String.Format(dintpuDevice, device.DI_ProductName, device.DeviceIndex);
            }
            return(this.CompileController(playerIndex, platformInfo, controllerDefinition, controllerTemplate, gamepadAbstraction, inputTemplate, controllerMappings, gameInfo));
        }
예제 #6
0
 public virtual string CompileController(int playerIndex, IPlatformInfo platformInfo, IInputTemplate inputTemplate, IGameInfo gameInfo)
 {
     string deviceName = this.CoreInstance.Get<IControllerPortsDatabase>().GetDeviceInPort(platformInfo, playerIndex);
     string controllerId = platformInfo.ControllerPorts[playerIndex];
     IControllerDefinition controllerDefinition = this.CoreInstance.Controllers[controllerId];
     IGamepadAbstraction gamepadAbstraction = this.CoreInstance.Get<IGamepadAbstractionDatabase>()[deviceName];
     return this.CompileController(playerIndex,
         platformInfo,
         controllerDefinition,
         this.ControllerTemplates[controllerId],
         gamepadAbstraction,
         inputTemplate,
         gameInfo);
 }
예제 #7
0
        public virtual string CompileController(int playerIndex, IPlatformInfo platformInfo, IControllerDefinition controllerDefinition, IControllerTemplate controllerTemplate, IGamepadAbstraction gamepadAbstraction, IInputTemplate inputTemplate, IReadOnlyDictionary<string, IControllerMapping> controllerMappings, IGameInfo gameInfo)
        {
            if (gamepadAbstraction.ProfileType == ControllerProfileType.NULL_PROFILE) return string.Empty;
            var template = new StringBuilder(inputTemplate.StringTemplate);
            foreach (IControllerInput input in controllerDefinition.ControllerInputs.Values)
            {
                string templateKey = controllerMappings["default"].InputMappings[input.InputName];
                string inputSetting = gamepadAbstraction[input.GamepadAbstraction];
                string emulatorValue = gamepadAbstraction.ProfileType == ControllerProfileType.KEYBOARD_PROFILE ?
                    inputTemplate.KeyboardMappings.First().Value[inputSetting] : inputTemplate.GamepadMappings.First().Value[inputSetting];
                template.Replace($"{{{templateKey}}}", emulatorValue);
            }

            foreach (var key in inputTemplate.TemplateKeys)
            {
                template.Replace("{N}", playerIndex.ToString()); //Player Index
                if (controllerMappings["default"].KeyMappings.ContainsKey(key))
                {
                    template.Replace($"{{{key}}}", controllerMappings["default"].KeyMappings[key]); //Non-input keys
                }
                else
                {
                    template.Replace($"{{{key}}}", inputTemplate.NoBind); //Non-input keys
                }
            }
            return template.ToString();
        }
예제 #8
0
 public virtual string CompileController(int playerIndex, IPlatformInfo platformInfo, IControllerDefinition controllerDefinition, IControllerTemplate controllerTemplate, IGamepadAbstraction gamepadAbstraction, IInputTemplate inputTemplate, IGameInfo gameInfo)
 {
     if (gamepadAbstraction.ProfileType == ControllerProfileType.NULL_PROFILE) return string.Empty;
     var controllerMappings = gamepadAbstraction.ProfileType == ControllerProfileType.KEYBOARD_PROFILE ?
         controllerTemplate.KeyboardControllerMappings : controllerTemplate.GamepadControllerMappings;
     return this.CompileController(playerIndex, platformInfo, controllerDefinition, controllerTemplate, gamepadAbstraction, inputTemplate, controllerMappings, gameInfo);
 }
        public override string CompileController(int playerIndex, IPlatformInfo platformInfo, IControllerDefinition controllerDefinition, IControllerTemplate controllerTemplate, IGamepadAbstraction gamepadAbstraction, IInputTemplate inputTemplate, IGameInfo gameInfo)
        {
            var controllerMappings = gamepadAbstraction.ProfileType == ControllerProfileType.KEYBOARD_PROFILE ?
               controllerTemplate.KeyboardControllerMappings : controllerTemplate.GamepadControllerMappings;

            string deviceName = gamepadAbstraction.DeviceName;
            IList<IInputDevice> devices = new InputManager().GetGamepads();
            if (deviceName == null) deviceName = String.Empty;

            int realWiimoteAmount = devices.Count(device => device.DI_ProductName.Contains("RVL-CNT"));

            if(controllerDefinition.ControllerID == "WII_COMBINED_CONTROLLER")
            {
                //All wiimotes have the same attachment
                int wiimote_extension = this.ConfigurationFlagStore.GetValue(gameInfo, "wiimote_extension", ConfigurationFlagTypes.SELECT_FLAG);
                controllerMappings["default"].KeyMappings["EXTENSION"] = this.ConfigurationFlags["wiimote_extension"].SelectValues[wiimote_extension].Value;

                if (playerIndex <= realWiimoteAmount)
                {
                    controllerMappings["default"].KeyMappings["SOURCE"] = "2"; //Real Wiimotes take precedence
                }
                else
                {
                    controllerMappings["default"].KeyMappings["SOURCE"] = "1"; //Emulated Wiimote
                }
            }

            if (deviceName.Equals(InputDeviceNames.KeyboardDevice, StringComparison.InvariantCultureIgnoreCase))
            {
                controllerMappings["default"].KeyMappings["DEVICE"] = "DInput/0/Keyboard Mouse";
                return this.CompileController(playerIndex, platformInfo, controllerDefinition, controllerTemplate,
                    gamepadAbstraction, inputTemplate, controllerMappings, gameInfo);
            }
            string xinputDevice = "XInput/{0}/Gamepad";
            string dintpuDevice = "DInput/{0}/{1}";
            if (deviceName.Equals(InputDeviceNames.XInputDevice1, StringComparison.InvariantCultureIgnoreCase))
            {
                controllerMappings["default"].KeyMappings["DEVICE"] =
                    String.Format(xinputDevice, 0);
            }
            else if (deviceName.Equals(InputDeviceNames.XInputDevice2, StringComparison.InvariantCultureIgnoreCase))
            {
                controllerMappings["default"].KeyMappings["DEVICE"] =
                    String.Format(xinputDevice, 1);
            }
            else if (deviceName.Equals(InputDeviceNames.XInputDevice3, StringComparison.InvariantCultureIgnoreCase))
            {
                controllerMappings["default"].KeyMappings["DEVICE"] =
                    String.Format(xinputDevice, 2);
            }
            else if (deviceName.Equals(InputDeviceNames.XInputDevice4, StringComparison.InvariantCultureIgnoreCase))
            {
                controllerMappings["default"].KeyMappings["DEVICE"] =
                    String.Format(xinputDevice, 3);
            }
            else if (devices.Select(device => device.DI_ProductName).Contains(deviceName))
            {
                var device = devices.First(d => d.DI_ProductName == deviceName);
                controllerMappings["default"].KeyMappings["DEVICE"] =
                    String.Format(dintpuDevice, device.DI_ProductName, device.DeviceIndex);
            }
            return this.CompileController(playerIndex, platformInfo, controllerDefinition, controllerTemplate, gamepadAbstraction, inputTemplate, controllerMappings, gameInfo);
        }
        public override string CompileController(int playerIndex, IPlatformInfo platformInfo, IControllerDefinition controllerDefinition, IControllerTemplate controllerTemplate, IGamepadAbstraction gamepadAbstraction, IInputTemplate inputTemplate, IReadOnlyDictionary<string, IControllerMapping> controllerMappings, IGameInfo gameInfo)
        {
            if (gamepadAbstraction.ProfileType == ControllerProfileType.NULL_PROFILE) return string.Empty;
            var template = new StringBuilder(inputTemplate.StringTemplate);
            foreach (IControllerInput input in controllerDefinition.ControllerInputs.Values)
            {
                string templateKey = controllerMappings["default"].InputMappings[input.InputName];
                string inputSetting = gamepadAbstraction[input.GamepadAbstraction];
                string emulatorValue = gamepadAbstraction.ProfileType == ControllerProfileType.KEYBOARD_PROFILE ?
                    inputTemplate.KeyboardMappings.First().Value[inputSetting] : inputTemplate.GamepadMappings.First().Value[inputSetting];
                template.Replace($"{{{templateKey}}}", emulatorValue);
            }

            if (platformInfo.PlatformID == StonePlatforms.NINTENDO_WII && controllerDefinition.ControllerID == "GCN_CONTROLLER")
            {
                template.Replace("{N}", (playerIndex - 4).ToString()); //Account for GCPad being in controller positions 5-8.
            }
            else
            {
                template.Replace("{N}", playerIndex.ToString()); //Player Index
            }

            foreach (string key in inputTemplate.TemplateKeys)
            {
                template.Replace($"{{{key}}}",
                    controllerMappings["default"].KeyMappings.ContainsKey(key)
                        ? controllerMappings["default"].KeyMappings[key]
                        : inputTemplate.NoBind);
            }
            return template.ToString();
        }