Exemplo n.º 1
0
        /// <summary>
        /// Recursive method to save the Option's value and its variants'
        /// and children's values to the node.
        /// </summary>
        private void SaveNode(ValueStore.Node node, Option option, bool isDefaultNode = false)
        {
            if (!isDefaultNode && option.IsDefaultVariant)
            {
                var defaultVariant = node.GetOrCreateVariant(option.VariantDefaultParameter);
                SaveNode(defaultVariant, option, isDefaultNode: true);

                for (int i = node.variants.Count - 1; i >= 0; i--)
                {
                    if (option.GetVariant(node.variants[i].name, create:false) == null)
                    {
                        node.RemoveVariant(i);
                    }
                }

                foreach (var variantOption in option.Variants)
                {
                    var variantNode = node.GetOrCreateVariant(variantOption.VariantParameter);
                    SaveNode(variantNode, variantOption);
                }
            }
            else
            {
                node.Value = option.Save();

                foreach (var childOption in option.Children)
                {
                    var childNode = node.GetOrCreateChild(childOption.Name);
                    SaveNode(childNode, childOption);
                }
            }
        }
Exemplo n.º 2
0
        static ValueStore.Node GetNodeRecursive(ValueStore.Node current, Match match, int index)
        {
            Capture next;
            var     groupIndex = FindNextCapture(match, index, out next);

            if (groupIndex < 0)
            {
                Debug.LogWarning("Unexpected end of captures in match: " + match);
                return(current);
            }
            else if (groupIndex == 2)
            {
                var child = current.GetOrCreateChild(next.Value);
                return(GetNodeRecursive(child, match, next.Index + next.Length));
            }
            else if (groupIndex == 3 || groupIndex == 4)
            {
                var isQuoted = (groupIndex == 3);
                var variant  = current.GetOrCreateVariant(ProcessQuotedString(next.Value, isQuoted));
                return(GetNodeRecursive(variant, match, next.Index + next.Length));
            }
            else
            {
                return(current);
            }
        }