Beispiel #1
0
        /// <summary>
        /// Read an ActionMaps 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(string xml)
        {
            log.Debug("ActionMapsCls.fromXML - Entry");

            XmlReaderSettings settings = new XmlReaderSettings( );

            settings.ConformanceLevel = ConformanceLevel.Fragment;
            settings.IgnoreWhitespace = true;
            settings.IgnoreComments   = true;
            XmlReader reader = XmlReader.Create(new StringReader(xml), settings);

            reader.Read( );
            // read the header element
            if (reader.Name == "ActionMaps")
            {
                if (reader.HasAttributes)
                {
                    version = reader["version"];
                    if (version == "0")
                    {
                        version = ACM_VERSION;         // update from legacy to actual version
                    }
                    // get the joystick mapping if there is one
                    for (int i = 0; i < JoystickCls.JSnum_MAX; i++)
                    {
                        jsN[i]     = reader[string.Format("js{0}", i + 1)];
                        jsNGUID[i] = reader[string.Format("js{0}G", i + 1)];
                    }
                }
                else
                {
                    return(false);
                }
            }

            // now handle the js assignment from the map
            // Reset with the found mapping
            DeviceInst.JoystickListRef.ResetJsNAssignment(jsNGUID);
            // Only now create the default optiontree for this map, containing included joysticks and the gamepad
            CreateNewOptions( );

            // now read the CIG content of the map
            reader.Read( ); // move to next element

            // could be actionmap OR (AC 0.9) deviceoptions OR options

            while (!reader.EOF) //!string.IsNullOrEmpty( x ) ) {

            {
                if (reader.Name.ToLowerInvariant( ) == "actionmap")
                {
                    string       x   = reader.ReadOuterXml( );
                    ActionMapCls acm = new ActionMapCls( );
                    if (acm.fromXML(x))
                    {
                        this.Merge(acm); // merge list
                    }
                }
                else if (reader.Name.ToLowerInvariant( ) == "customisationuiheader")
                {
                    string x = reader.ReadOuterXml( );
                    m_uiCustHeader.fromXML(x);
                }
                else if (reader.Name.ToLowerInvariant( ) == "deviceoptions")
                {
                    string x = reader.ReadOuterXml( );
                    m_deviceOptions.fromXML(x);
                }
                else if (reader.Name.ToLowerInvariant( ) == "options")
                {
                    string x = reader.ReadOuterXml( );
                    m_tuningOptions.fromXML(x);
                }
                else
                {
                    reader.Read( );
                }
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Read an ActionMaps 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(string xml)
        {
            log.Debug("ActionMapsCls.fromXML - Entry");

            XmlReaderSettings settings = new XmlReaderSettings {
                ConformanceLevel = ConformanceLevel.Fragment,
                IgnoreWhitespace = true,
                IgnoreComments   = true
            };

            using (XmlReader reader = XmlReader.Create(new StringReader(xml), settings)) {
                reader.MoveToContent( );
                if (reader.EOF)
                {
                    return(false);
                }

                if (XNode.ReadFrom(reader) is XElement el)
                {
                    // read the header element
                    if (el.Name.LocalName == "ActionMaps")
                    {
                        if (el.HasAttributes)
                        {
                            version = (string)el.Attribute("version");
                            if (version == "0")
                            {
                                version = ACM_VERSION;     // update from legacy to actual version
                            }
                            // get the joystick mapping if there is one
                            for (int i = 0; i < JoystickCls.JSnum_MAX; i++)
                            {
                                jsN[i]     = (string)el.Attribute(string.Format("js{0}", i + 1));
                                jsNGUID[i] = (string)el.Attribute(string.Format("js{0}G", i + 1));
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    // now handle the js assignment from the map
                    // Reset with the found mapping
                    DeviceInst.JoystickListRef.ResetJsNAssignment(jsNGUID);
                    // Only now create the default optiontree for this map, containing included joysticks and the gamepad
                    CreateNewOptions( );


                    // now read the CIG content of the map

                    IEnumerable <XElement> actionmaps = from x in el.Elements( )
                                                        where (x.Name == "actionmap")
                                                        select x;
                    foreach (XElement actionmap in actionmaps)
                    {
                        ActionMapCls acm = new ActionMapCls( );
                        if (acm.fromXML(actionmap))
                        {
                            this.Merge(acm); // merge list
                        }
                    }

                    IEnumerable <XElement> custHeaders = from x in el.Elements( )
                                                         where (x.Name == UICustHeader.XmlName)
                                                         select x;
                    foreach (XElement custHeader in custHeaders)
                    {
                        m_uiCustHeader.fromXML(custHeader);
                    }

                    IEnumerable <XElement> deviceOptions = from x in el.Elements( )
                                                           where (x.Name == "deviceoptions")
                                                           select x;
                    foreach (XElement deviceOption in deviceOptions)
                    {
                        m_deviceOptions.fromXML(deviceOption);
                    }

                    IEnumerable <XElement> options = from x in el.Elements( )
                                                     where (x.Name == "options")
                                                     select x;
                    foreach (XElement option in options)
                    {
                        m_tuningOptions.fromXML(option);
                    }

                    IEnumerable <XElement> modifiers = from x in el.Elements( )
                                                       where (x.Name == "modifiers")
                                                       select x;
                    foreach (XElement modifier in modifiers)
                    {
                        SC.Modifiers.Instance.FromXML(modifier);
                    }
                }
            }
            return(true);
        }