public DCSLuaDiffsButtonElement Copy()
        {
            DCSLuaDiffsButtonElement result = new DCSLuaDiffsButtonElement();

            result.Keyname = Keyname;
            result.Title   = Title;
            for (int i = 0; i < added.Count; ++i)
            {
                result.added.Add(added[i].Copy());
            }
            for (int i = 0; i < removed.Count; ++i)
            {
                result.removed.Add(removed[i].Copy());
            }
            return(result);
        }
Ejemplo n.º 2
0
        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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        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);
                                }
                            }
                        }
                    }
                }
            }
        }