/// <summary> /// Update raw data from bindings. /// </summary> /// <param name="newBind">The new binding.</param> /// <param name="fieldName">The field name.</param> private void UpdateFieldsFromBinding(InputBinding newBind, string fieldName) { var mCtrl = (JArray)settingValues[fieldName]; JToken tk; JToken tk2; // Keyboard tk = mCtrl.Where(x => (int)x["type"] == 0).FirstOrDefault(); if (tk == null) { tk2 = JObject.FromObject(new { axis = 0, button = (int)newBind.KeyBinding, negate = 0, type = 0 }); mCtrl.Add(tk2); } else { tk["button"] = (int)newBind.KeyBinding; if (newBind.KeyBinding == DIKCode.NONE) { tk.Remove(); } } // Mouse var info = RawMouseCode.FromMouseCode(newBind.MouseBinding); tk = mCtrl.Where(x => (int)x["type"] == 1).FirstOrDefault(); if (tk == null) { tk2 = JObject.FromObject(new { axis = info.Axis, button = info.Button, negate = info.Negate, type = 1 }); mCtrl.Add(tk2); } else { tk["axis"] = info.Axis; tk["button"] = info.Button; tk["negate"] = info.Negate; if (newBind.MouseBinding == MouseCode.None) { tk.Remove(); } } }
/// <summary> /// Create a binding from raw data. /// </summary> /// <param name="fieldName">The field name.</param> /// <returns></returns> private InputBinding BindingFromFieldName(string fieldName) { var ib = new InputBinding(DIKCode.NONE, MouseCode.None); foreach (var input in settingValues[fieldName]) { if ((int)input["type"] == 0) { // Keyboard ib.KeyBinding = DIKCodes.Parse((int)input["button"]); } if ((int)input["type"] == 1) { // Mouse ib.MouseBinding = RawMouseCode.ToMouseCode( (int)input["axis"], (int)input["button"], (int)input["negate"] ); } } return(ib); }