コード例 #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     OnParse?.Invoke(progressBar1);
 }
コード例 #2
0
        public void ParseMapping(string mappingJsonContents)
        {
            var ser     = new System.Web.Script.Serialization.JavaScriptSerializer();
            var mapping = ser.DeserializeObject(mappingJsonContents) as Dictionary <string, object>;

            MappedControllerIndexes.Clear();
            KeyboardMappings.Clear();

            foreach (var pair in mapping)
            {
                System.Console.WriteLine($"Loading mapping for {pair.Key} ...");

                var shorthand       = pair.Value as object[];
                var controllerIndex = (int)shorthand[0];
                var controllerKey   = (string)shorthand[1];
                var didMap          = false;

                switch (controllerKey)
                {
                case "LeftTrigger":
                case "RightTrigger":
                case "LeftStickX":
                case "LeftStickY":
                case "RightStickX":
                case "RightStickY": {
                    var maxValue = short.MaxValue;

                    if (controllerKey == "LeftTrigger" || controllerKey == "RightTrigger")
                    {
                        maxValue = byte.MaxValue;
                    }

                    var axis           = (X360Axis)System.Enum.Parse(typeof(X360Axis), controllerKey);
                    var multipliers    = ParseAxisMultipliers(shorthand);
                    var downMultiplier = multipliers[0];
                    var upMultiplier   = multipliers[1];
                    var downValue      = (int)System.Math.Round(maxValue * downMultiplier);
                    var upValue        = (int)System.Math.Round(0 * upMultiplier);

                    KeyboardMappings[pair.Key] = new KeyboardDownToAxis {
                        DownValue = downValue, UpValue = upValue, Index = controllerIndex, Axis = axis
                    };
                    didMap = true;

                    break;
                }

                default: {
                    var button = (X360Buttons)System.Enum.Parse(typeof(X360Buttons), controllerKey);

                    KeyboardMappings[pair.Key] = new KeyboardDownToButton {
                        Index = controllerIndex, Button = button
                    };
                    didMap = true;

                    break;
                }
                }

                if (didMap)
                {
                    if (!MappedControllerIndexes.Contains(controllerIndex))
                    {
                        MappedControllerIndexes.Add(controllerIndex);
                    }
                }
            }

            OnParse?.Invoke(this, new System.EventArgs());
        }
コード例 #3
0
 public SyntaxNotifier(OnParse onParse)
 {
     _onParse = onParse;
 }