Beispiel #1
0
        private SearchExpressionNode LoadNodeData(SearchExpressionNode node, IDictionary info)
        {
            if (SJSON.TryGetValue(info, ExpressionField.name, out var name))
            {
                node.name = Convert.ToString(name);
            }

            if (SJSON.TryGetValue(info, ExpressionField.value, out var value))
            {
                node.value = value;
            }

            if (node.type == ExpressionType.Expression)
            {
                var nestedExpression = new SearchExpression(m_SearchOptions);

                if (node.value is string expressionPath && File.Exists(expressionPath))
                {
                    nestedExpression.Load(expressionPath);
                }
                else if (SJSON.TryGetValue(info, ExpressionField.source, out var source) && source is IDictionary sourceData)
                {
                    nestedExpression.Load(sourceData);
                }

                if (nestedExpression.m_EvalNode != null && nestedExpression.m_EvalNode.source != null)
                {
                    node.source = nestedExpression.m_EvalNode.source;
                }
            }
Beispiel #2
0
 private void ExportSJSON()
 {
     EditorGUIUtility.systemCopyBuffer = SJSON.Encode(m_Expression.Export());
 }
Beispiel #3
0
 public void Load(string path)
 {
     Load((IDictionary)SJSON.Load(path));
 }
Beispiel #4
0
 public void Parse(string sjson)
 {
     Load((IDictionary)SJSON.LoadString(sjson));
 }
 public void Save(string path)
 {
     SJSON.Save(Export(), path);
 }
        private SearchExpressionNode LoadNodeData(SearchExpressionNode node, IDictionary info)
        {
            if (SJSON.TryGetValue(info, ExpressionField.name, out var name))
            {
                node.name = Convert.ToString(name);
            }

            if (SJSON.TryGetValue(info, ExpressionField.value, out var value))
            {
                node.value = value;
            }

            if (SJSON.TryGetValue(info, ExpressionField.source, out var source))
            {
                if (source is IDictionary nestedSource)
                {
                    node.source = ParseNode(nestedSource);
                }
                else if (node.type == ExpressionType.Provider)
                {
                    node.value = (string)source;
                }
                else if (m_Nodes.TryGetValue((string)source, out var sourceNode))
                {
                    node.source = sourceNode;
                }
                else
                {
                    throw new ExpressionException($"Expression node {node.id} has an invalid source {source}");
                }
            }

            if (SJSON.TryGetValue(info, ExpressionField.position, out var _obj) && _obj is object[] position && position.Length == 2)
            {
                node.position = new Vector2((float)(double)position[0], (float)(double)position[1]);
            }

            if (SJSON.TryGetValue(info, ExpressionField.variables, out var variablesData))
            {
                var variables = (IDictionary)variablesData;
                foreach (var v in variables)
                {
                    var varName     = (string)((DictionaryEntry)v).Key;
                    var valueSource = ((DictionaryEntry)v).Value;
                    if (valueSource == null)
                    {
                        node.AddVariable(varName);
                    }
                    else if (valueSource is IDictionary nestedSource)
                    {
                        node.AddVariable(varName, ParseNode(nestedSource));
                    }
                    else if (valueSource is string && m_Nodes.TryGetValue((string)valueSource, out var sourceNode))
                    {
                        node.AddVariable(varName, sourceNode);
                    }
                    else
                    {
                        throw new ExpressionException(node, $"Expression node {node.id} has an invalid variable {varName} with source {valueSource}");
                    }
                }
            }

            if (SJSON.TryGetValue(info, ExpressionField.properties, out var propertiesData))
            {
                var properties = (IDictionary)propertiesData;
                foreach (var v in properties)
                {
                    var propertyName  = (string)((DictionaryEntry)v).Key;
                    var propertyValue = ((DictionaryEntry)v).Value;
                    node.SetProperty(propertyName, propertyValue);
                }
            }

            return(node);
        }