Пример #1
0
        internal void PrepareNodesForCopy(IList <CNode> nodes)
        {
            CScriptSerializer.PrepareNodesForSerialization(nodes);
            for (int i = 0; i < nodes.Count; i++)
            {
                if (nodes[i] is CKlaxVariableNode variableNode)
                {
                    if (variableNode.SourceVariable == null)
                    {
                        throw new NullReferenceException("Tried to serialize a KlaxVariable node without a valid reference to an existing variable");
                    }

                    variableNode.m_sourceVariableGuid = variableNode.SourceVariable.Guid;
                }
            }
        }
Пример #2
0
        internal void PrepareNodesForSerialization(CKlaxScriptObject outerScriptObject)
        {
            CScriptSerializer.PrepareNodesForSerialization(m_nodes);
            Dictionary <CKlaxVariable, int> objectVariableToIndex = new Dictionary <CKlaxVariable, int>();

            for (var i = 0; i < outerScriptObject.KlaxVariables.Count; i++)
            {
                objectVariableToIndex.Add(outerScriptObject.KlaxVariables[i], i);
            }

            Dictionary <CKlaxVariable, int> localVariableToIndex = new Dictionary <CKlaxVariable, int>();

            for (int i = 0; i < m_localVariables.Count; i++)
            {
                localVariableToIndex.Add(m_localVariables[i], i);
            }

            for (int i = 0; i < m_nodes.Count; i++)
            {
                if (m_nodes[i] is CKlaxVariableNode variableNode)
                {
                    if (variableNode.SourceVariable == null)
                    {
                        throw new NullReferenceException("Tried to serialize a KlaxVariable node without a valid reference to an existing variable");
                    }

                    if (objectVariableToIndex.TryGetValue(variableNode.SourceVariable, out int index))
                    {
                        variableNode.m_sourceVariableIndex = index;
                        variableNode.m_bIsLocalVariable    = false;
                        continue;
                    }

                    if (localVariableToIndex.TryGetValue(variableNode.SourceVariable, out int localIndex))
                    {
                        variableNode.m_sourceVariableIndex = localIndex;
                        variableNode.m_bIsLocalVariable    = true;
                        continue;
                    }

                    throw new Exception("KlaxVariable Node Referenced a variable that does not exist in its context");
                }
            }
        }