public DCSAxisBind Copy() { DCSAxisBind result = new DCSAxisBind(); result.key = key; result.filter = filter.Copy(); return(result); }
public DCSAxisBind toDCSAxisBind() { DCSAxisBind result = new DCSAxisBind(); if (JAxis.Length < 1 || Joystick.Length < 1) { return(null); } result.key = JAxis.ToString(); DCSAxisFilter daf = new DCSAxisFilter(); result.filter = daf; daf.curviture = Curviture; daf.deadzone = Deadzone; daf.inverted = Inverted ?? false; daf.slider = Slider ?? false; daf.saturationX = SaturationX; daf.saturationY = SaturationY; return(result); }
public static Bind GetBindFromAxisElement(DCSAxisBind dab, string id, string joystick, string plane, bool inv = false, bool slid = false, bool curv = false, bool dz = false, bool sx = false, bool sy = false) { Relation r = new Relation(); Bind b = new Bind(r); string shorten = MainStructure.ShortenDeviceName(joystick); string relationName = shorten + dab.key; r.ISAXIS = true; b.JAxis = dab.key; b.Joystick = joystick; if (dab.filter != null) { b.Inverted = dab.filter.inverted; b.Curviture = dab.filter.curviture; if (b.Curviture == null) { b.Curviture = new List <double>(); } if (b.Curviture.Count < 1) { b.Curviture.Add(0.0); } b.Deadzone = dab.filter.deadzone; b.Slider = dab.filter.slider; b.SaturationX = dab.filter.saturationX; b.SaturationY = dab.filter.saturationY; } else { b.Inverted = false; b.Slider = false; b.Curviture = new List <double>(); b.Curviture.Add(0.0); b.SaturationX = 1.0; b.SaturationY = 1.0; b.Deadzone = 0; } if (inv) { relationName = relationName + "i" + b.Inverted.ToString(); } if (slid) { relationName = relationName + "s" + b.Slider.ToString(); } if (curv && b.Curviture.Count > 0) { relationName = relationName + "c" + b.Curviture[0].ToString(new CultureInfo("en-US")).Substring(0, 4); } if (dz) { relationName = relationName + "d" + b.Deadzone.ToString(new CultureInfo("en-US")).Substring(0, 4); } if (sx) { relationName = relationName + "x" + b.SaturationX.ToString(new CultureInfo("en-US")).Substring(0, 4); } if (sy) { relationName = relationName + "y" + b.SaturationY.ToString(new CultureInfo("en-US")).Substring(0, 4); } r.NAME = relationName; r.AddNode(id, plane); return(b); }
public void RemoveKey(string key, bool onlyIfDefault = false) { if (!onlyIfDefault) { List <string> toRemove = new List <string>(); foreach (KeyValuePair <string, DCSLuaDiffsAxisElement> kvp in axisDiffs) { for (int i = kvp.Value.added.Count - 1; i >= 0; i--) { if (kvp.Value.added[i].key == key) { if (kvp.Value.removed.Count == 0 && kvp.Value.added.Count == 1) { if (!toRemove.Contains(kvp.Key)) { toRemove.Add(kvp.Key); } } else { kvp.Value.added.RemoveAt(i); } } } } for (int i = 0; i < toRemove.Count; ++i) { axisDiffs.Remove(toRemove[i]); } toRemove.Clear(); foreach (KeyValuePair <string, DCSLuaDiffsButtonElement> kvp in keyDiffs) { for (int i = kvp.Value.added.Count - 1; i >= 0; i--) { if (kvp.Value.added[i].key == key) { if (kvp.Value.removed.Count == 0 && kvp.Value.added.Count == 1) { if (!toRemove.Contains(kvp.Key)) { toRemove.Add(kvp.Key); } } else { kvp.Value.added.RemoveAt(i); } } } } for (int i = 0; i < toRemove.Count; ++i) { axisDiffs.Remove(toRemove[i]); } } DCSLuaInput defs = getDefaultBinds(); foreach (KeyValuePair <string, DCSLuaDiffsAxisElement> kvp in defs.axisDiffs) { foreach (DCSAxisBind kvpa in kvp.Value.removed) { if (kvpa.key == key) { if (!axisDiffs.ContainsKey(kvp.Key)) { axisDiffs.Add(kvp.Key, new DCSLuaDiffsAxisElement()); axisDiffs[kvp.Key].Keyname = kvp.Key; } DCSLuaDiffsAxisElement element = axisDiffs[kvp.Key]; bool found = false; for (int i = 0; i < element.removed.Count; ++i) { if (element.removed[i].key == key) { found = true; break; } } if (!found) { DCSAxisBind dab = new DCSAxisBind(); dab.key = key; element.removed.Add(dab); } } } } foreach (KeyValuePair <string, DCSLuaDiffsButtonElement> kvp in defs.keyDiffs) { foreach (DCSButtonBind kvpa in kvp.Value.removed) { if (kvpa.key == key) { if (!keyDiffs.ContainsKey(kvp.Key)) { keyDiffs.Add(kvp.Key, new DCSLuaDiffsButtonElement()); keyDiffs[kvp.Key].Keyname = kvp.Key; } DCSLuaDiffsButtonElement element = keyDiffs[kvp.Key]; bool found = false; for (int i = 0; i < element.removed.Count; ++i) { if (element.removed[i].key == key) { found = true; break; } } if (!found) { DCSButtonBind dab = new DCSButtonBind(); dab.key = key; element.removed.Add(dab); } } } } }
public void AnalyzeRawLuaInput(string content) { if (!content.Contains('{')) { return; } string cleaned = MainStructure.GetContentBetweenSymbols(content, "{", "}"); Dictionary <object, object> dct = MainStructure.CreateAttributeDictFromLua(content); if (dct.ContainsKey("axisDiffs")) { foreach (KeyValuePair <object, object> kvp in (Dictionary <object, object>)dct["axisDiffs"]) { DCSLuaDiffsAxisElement current = new DCSLuaDiffsAxisElement(); current.Keyname = (string)kvp.Key; if (axisDiffs.ContainsKey(current.Keyname)) { axisDiffs[current.Keyname] = current; } else { axisDiffs.Add(current.Keyname, current); } if (((Dictionary <object, object>)kvp.Value).ContainsKey("name")) { current.Title = (string)((Dictionary <object, object>)kvp.Value)["name"]; } if (((Dictionary <object, object>)kvp.Value).ContainsKey("added")) { Dictionary <object, object> dictAdded = (Dictionary <object, object>)((Dictionary <object, object>)kvp.Value)["added"]; foreach (KeyValuePair <object, object> kvpAdded in dictAdded) { if (((Dictionary <object, object>)kvpAdded.Value).ContainsKey("key")) { DCSAxisBind dab = new DCSAxisBind(); dab.key = (string)((Dictionary <object, object>)kvpAdded.Value)["key"]; if (((Dictionary <object, object>)kvpAdded.Value).ContainsKey("filter")) { DCSAxisFilter daf = new DCSAxisFilter(); dab.filter = daf; daf.deadzone = (double)((Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["filter"])["deadzone"]; daf.inverted = (bool)((Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["filter"])["invert"]; daf.slider = (bool)((Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["filter"])["slider"]; daf.saturationX = (double)((Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["filter"])["saturationX"]; daf.saturationY = (double)((Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["filter"])["saturationY"]; foreach (KeyValuePair <object, object> kvpCurve in (Dictionary <object, object>)((Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["filter"])["curvature"]) { daf.curviture.Add((double)kvpCurve.Value); } } if (!current.doesAddedContainKey(dab.key)) { current.added.Add(dab); current.removeItemFromRemoved(dab.key); } } } } if (((Dictionary <object, object>)kvp.Value).ContainsKey("removed")) { Dictionary <object, object> dictRemoved = (Dictionary <object, object>)((Dictionary <object, object>)kvp.Value)["removed"]; foreach (KeyValuePair <object, object> kvpRemoved in dictRemoved) { if (((Dictionary <object, object>)kvpRemoved.Value).ContainsKey("key")) { DCSAxisBind dab = new DCSAxisBind(); dab.key = (string)((Dictionary <object, object>)kvpRemoved.Value)["key"]; if (!current.doesRemovedContainKey(dab.key)) { current.removed.Add(dab); current.removeItemFromAdded(dab.key); } } } } } } if (dct.ContainsKey("keyDiffs")) { foreach (KeyValuePair <object, object> kvp in (Dictionary <object, object>)dct["keyDiffs"]) { DCSLuaDiffsButtonElement current = new DCSLuaDiffsButtonElement(); current.Keyname = (string)kvp.Key; if (keyDiffs.ContainsKey(current.Keyname)) { keyDiffs[current.Keyname] = current; } else { keyDiffs.Add(current.Keyname, current); } if (((Dictionary <object, object>)kvp.Value).ContainsKey("name")) { current.Title = (string)((Dictionary <object, object>)kvp.Value)["name"]; } if (((Dictionary <object, object>)kvp.Value).ContainsKey("added")) { Dictionary <object, object> dictAdded = (Dictionary <object, object>)((Dictionary <object, object>)kvp.Value)["added"]; foreach (KeyValuePair <object, object> kvpAdded in dictAdded) { if (((Dictionary <object, object>)kvpAdded.Value).ContainsKey("key")) { DCSButtonBind dab = new DCSButtonBind(); dab.key = (string)((Dictionary <object, object>)kvpAdded.Value)["key"]; if (!current.doesAddedContainKey(dab.key)) { current.added.Add(dab); current.removeItemFromRemoved(dab.key); } if (((Dictionary <object, object>)kvpAdded.Value).ContainsKey("reformers")) { foreach (KeyValuePair <object, object> kvpReformers in (Dictionary <object, object>)((Dictionary <object, object>)kvpAdded.Value)["reformers"]) { if (!dab.reformers.Contains((string)kvpReformers.Value)) { dab.reformers.Add((string)kvpReformers.Value); } } } } } } if (((Dictionary <object, object>)kvp.Value).ContainsKey("removed")) { Dictionary <object, object> dictRemoved = (Dictionary <object, object>)((Dictionary <object, object>)kvp.Value)["removed"]; foreach (KeyValuePair <object, object> kvpRemoved in dictRemoved) { if (((Dictionary <object, object>)kvpRemoved.Value).ContainsKey("key")) { DCSButtonBind dab = new DCSButtonBind(); dab.key = (string)((Dictionary <object, object>)kvpRemoved.Value)["key"]; if (!current.doesRemovedContainKey(dab.key)) { current.removed.Add(dab); current.removeItemFromAdded(dab.key); } } } } } } }