Ejemplo n.º 1
0
        private void TreeView_SetActiveOnSettingChanged(string entityId, bool isActive)
        {
            var newRule      = (JObject)rule.DeepClone();
            var ruleVariants = (JArray)newRule["value"];

            for (int i = 0; i < ruleVariants.Count; i++)
            {
                var variantValues = (JArray)ruleVariants[i]["values"];
                if (isActive)
                {
                    for (int j = 0; j < settings.Count; j++)
                    {
                        if (settings[j]["metadata"]["entityId"].Value <string>() == entityId)
                        {
                            JObject newSetting = (JObject)settings[j].DeepClone();
                            variantValues.Add(newSetting);
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < variantValues.Count; j++)
                    {
                        if (variantValues[j]["metadata"]["entityId"].Value <string>() == entityId)
                        {
                            variantValues.RemoveAt(j);
                            break;
                        }
                    }
                }
            }
            MvRuleUpdated?.Invoke(rule, newRule);
        }
Ejemplo n.º 2
0
        private void TreeView_OnAddVariantClicked()
        {
            var newRule      = (JObject)rule.DeepClone();
            var ruleVariants = (JArray)newRule["value"];

            var newVariant = new JObject();

            var currentVariantIndexes = new int[ruleVariants.Count];
            int currentIndex          = 0;

            for (int i = 0; i < ruleVariants.Count; i++)
            {
                if (Int32.TryParse(ruleVariants[i]["id"].Value <string>().Replace("variant-", ""), out currentIndex))
                {
                    currentVariantIndexes[i] = currentIndex;
                }
            }
            var idEndingIndex = currentVariantIndexes.Max() + 1;

            newVariant["id"]     = "variant-" + idEndingIndex;
            newVariant["type"]   = "variant";
            newVariant["values"] = ruleVariants[0]["values"].DeepClone();
            newVariant["weight"] = null;

            ruleVariants.Add(newVariant);
            MvRuleUpdated?.Invoke(rule, newRule);
        }
Ejemplo n.º 3
0
        private void TreeView_OnVariantDeleted(string variantId)
        {
            var newRule      = (JObject)rule.DeepClone();
            var ruleVariants = (JArray)newRule["value"];

            if (ruleVariants.Count > 1)
            {
                for (int i = 0; i < ruleVariants.Count; i++)
                {
                    if (ruleVariants[i]["id"].Value <string>() == variantId)
                    {
                        ruleVariants.RemoveAt(i);
                        MvRuleUpdated?.Invoke(rule, newRule);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void TreeView_UpdateSetting(int whichVariant, string entityId, JToken newValue)
        {
            var newRule      = (JObject)rule.DeepClone();
            var ruleVariants = (JArray)newRule["value"];

            var variantValues = (JArray)ruleVariants[whichVariant]["values"];

            for (int i = 0; i < variantValues.Count; i++)
            {
                if (variantValues[i]["metadata"]["entityId"].Value <string>() == entityId)
                {
                    variantValues[i]["rs"]["value"] = newValue;
                    break;
                }
            }

            MvRuleUpdated?.Invoke(rule, newRule);
        }
Ejemplo n.º 5
0
        private void TreeView_OnSelectAllSettingsToggleClicked(bool allSettingsToggle)
        {
            var newRule         = (JObject)rule.DeepClone();
            var ruleVariants    = (JArray)newRule["value"];
            var newRuleVariants = new JArray();

            // go through variants, add all the settings from settingsList if toggleState
            for (int i = 0; i < ruleVariants.Count; i++)
            {
                var currVariant       = (JObject)ruleVariants[i].DeepClone();
                var currVariantValues = (JArray)currVariant["values"];
                if (allSettingsToggle)
                {
                    for (int j = 0; j < treeView.settingsList.Count; j++)
                    {
                        var valAdded = false;
                        for (int k = 0; k < currVariantValues.Count; k++)
                        {
                            if (currVariantValues[k]["metadata"]["entityId"].Value <string>() == treeView.settingsList[j]["metadata"]["entityId"].Value <string>())
                            {
                                valAdded = true;
                            }
                        }
                        if (!valAdded)
                        {
                            var currSetting = (JObject)treeView.settingsList[j].DeepClone();
                            currVariantValues.Add(currSetting);
                            TreeView_SetActiveOnSettingChanged(currSetting["metadata"]["entityId"].Value <string>(), true);
                        }
                    }
                }
                else
                {
                    currVariantValues.Clear();
                }
                currVariant["values"] = currVariantValues;
                newRuleVariants.Add(currVariant);
            }
            newRule["value"] = newRuleVariants;
            MvRuleUpdated?.Invoke(rule, newRule);
        }
Ejemplo n.º 6
0
        private void TreeView_OnVariantUpdated(JObject oldVariant, JObject newVariant)
        {
            var newRule           = (JObject)rule.DeepClone();
            var ruleVariants      = (JArray)newRule["value"];
            var currentVariantIds = ruleVariants.Select(var => var["id"].Value <string>()).ToArray();

            if (currentVariantIds.Contains(newVariant["id"].Value <string>()) && (newVariant["weight"].Value <string>()) == oldVariant["weight"].Value <string>())
            {
                Debug.LogWarning("Variant id: '" + newVariant["id"].Value <string>() + "' is already used.");
            }
            else
            {
                for (int i = 0; i < ruleVariants.Count; i++)
                {
                    if (ruleVariants[i].ToString() == oldVariant.ToString())
                    {
                        ruleVariants[i] = newVariant;
                    }
                }
                MvRuleUpdated?.Invoke(rule, newRule);
            }
        }