Exemple #1
0
 public void ParseSettings()
 {
     //Go through ALL of the headers
     foreach (var header in settings.Headers)
     {
         //Check all thier values
         foreach (var key in settings[header].Keys)
         {
             //if they have THIS Providers SettingsPostfix then deal with it
             if (key.EndsWith(SettingsPostfix))
             {
                 KeyCondition result = new KeyCondition(null);
                 if (Parser.TryParse <KeyCondition>(settings[header][key], ref result))
                 {
                     //Remove SettingsPostfix from the key
                     //On a unsuccessful Parse, stop
                     this.Add(header + "." + key.Substring(0, key.Length - SettingsPostfix.Length - 1),
                              result);
                 }
                 else
                 {
                     throw new InvalidDataException("Input Settings failed to load");
                 }
             }
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Parses a Key binding
        /// </summary>
        /// <returns><c>non-null</c>, if setting was parsed, <c>null</c> otherwise error has occured.</returns>
        /// <param name="keystring">Key string.</param>
        /// <remarks>Key String is a + sperated list containing English letters or scan-codes
        /// refer to https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Input/Keys.cs for scan-codes
        /// </remarks>
        /// <note>This is to be a parser for Rhovlyn.Engine.Util.Parser and follows the delegate ObjectParser</note>
        public static object ParseKeyBinding(string keystring)
        {
            var key = new KeyCondition();

            key.Keys = new List <Keys>();
            var segs = keystring.Split('+');

            foreach (var seg in segs)
            {
                //Convert a singel letter to scancode
                if (seg.Length == 1)
                {
                    //XNA Scan codes for letters are mapped to UTF-8's upper case english letters
                    var bytes = System.Text.UTF8Encoding.UTF8.GetBytes(seg.ToUpper());
                    if (bytes.Length == 1)
                    {
                        if (bytes[0] >= 65 && bytes[0] <= 90)
                        {
                            key.Keys.Add((Keys)bytes[0]);
                            continue;
                        }
                    }
                }
                //Read in as Scancodes
                int code;
                if (int.TryParse(seg, out code))
                {
                    key.Keys.Add((Keys)code);
                }
                else
                {
                    return(null);
                }
            }
            return(key);
        }