/// <summary> /// Create a tuningOptionID from devClass and xmlInstance (jsN for joysticks, 1 for gamepad) /// </summary> /// <param name="deviceClass">Joysstick or Gamepad class name</param> /// <param name="instance">The xml instance number or 1 for gamepad</param> /// <returns>An ID or a dummy ID if the instance is not found</returns> public static string TuneOptionIDfromJsN(string deviceClass, int instance) { // only search for joysticks if (JoystickCls.IsDeviceClass(deviceClass)) { for (int i = 0; i < m_jsMap.Length; i++) { if (m_jsMap[i] == instance) { return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, i.ToString( ))); } } // not found return return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, -1)); // will not be found in the collection } else if (GamepadCls.IsDeviceClass(deviceClass)) { // gamepad return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, instance)); } else if (MouseCls.IsDeviceClass(deviceClass)) { // mouse return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, instance)); } else { return(string.Format("{0}{1}{2}", deviceClass, ID_Delimiter, instance)); } }
/// <summary> /// Returns the xml instance (jsN for Joysticks) part of an ID /// </summary> /// <param name="TO_ID">A tuningOptionID</param> /// <returns>The xml instance part</returns> public static int XmlInstanceFromID(string TO_ID) { int inst = 0; string[] e = TO_ID.Split(ID_Delimiter); if (e.Length > 1) { string deviceClass = ClassFromID(TO_ID); inst = int.Parse(e[1]); if (JoystickCls.IsDeviceClass(deviceClass)) { if (inst >= 0) { return(m_jsMap[inst]); } else { return(inst); } } else { //Gamepad, mouse return(inst); } } else { return(-1); } }
// translate a ToID built from JsN into the internal collection key private static string ToIDfromJsToID(string toIDjs) { string deviceClass = ClassFromID(toIDjs); // only search for joysticks if (JoystickCls.IsDeviceClass(deviceClass)) { string[] e = toIDjs.Split(ID_Delimiter); if (e.Length > 1) { int i = int.Parse(e[1]); return(TuneOptionIDfromJsN(e[0], i)); } else { return(""); } } else { // gamepad, mouse return(toIDjs); } }
/// <summary> /// Read an Options from XML - do some sanity check /// </summary> /// <param name="xml">the XML action fragment</param> /// <returns>True if an action was decoded</returns> public bool fromXML(XElement options) { /* * This can be a lot of the following options * try to do our best.... * * <options type="joystick" instance="1"> * .. * </options> * * * <options type="joystick" instance="1"> * .. * </options> * */ string instance = (string)options.Attribute("instance"); // mandadory string type = (string)options.Attribute("type"); // mandadory if (!int.TryParse(instance, out int nInstance)) { nInstance = 0; } // now dispatch to the instance to capture the content if (JoystickCls.IsDeviceClass(type)) { string toID = TuneOptionIDfromJsN(JoystickCls.DeviceClass, nInstance); // now this might not be availabe if devices have been changed if (this.ContainsKey(toID)) { this[toID].fromXML(options); } else { log.InfoFormat("Read XML Options - joystick instance {0} is not available - dropped this content", nInstance); } } else if (GamepadCls.IsDeviceClass(type)) { string toID = TuneOptionID(GamepadCls.DeviceClass, nInstance); if (this.ContainsKey(toID))// 20170513: bugfix if gamepad is in the XML but not connected right now - ignore { this[toID].fromXML(options); } else { log.InfoFormat("Read XML Options - xboxpad instance {0} is not available - dropped this content", nInstance); } } else if (KeyboardCls.IsDeviceClass(type)) // CIG names mouse - keyboard { string toID = TuneOptionID(MouseCls.DeviceClass, nInstance); if (this.ContainsKey(toID)) { this[toID].fromXML(options); } else { log.InfoFormat("Read XML Options - keyboard(mouse) instance {0} is not available - dropped this content", nInstance); } } return(true); }