Exemplo n.º 1
0
        private void WalkSyntaxTreeForIndentations(LuaNode node, int[] indentations)
        {
            if (node is LuaBlockNode)
            {
                // if block span occupys two lines or more, add indentation for it
                if (node.Span.Location.Line == node.EndLine)
                {
                    if (node.Span.Location.Line != node.Parent.Span.Location.Line)
                    {
                        indentations[node.Span.Location.Line] += 1;
                    }
                }

                if (node.Span.Location.Line != node.EndLine)
                {
                    for (int i = node.Span.Location.Line;
                         i <= node.EndLine; ++i)
                    {
                        indentations[i] += 1;
                    }
                }
            }
            foreach (AstNode childNode in node.ChildNodes)
            {
                if (!(childNode is NullNode))
                {
                    WalkSyntaxTreeForIndentations(childNode as LuaNode, indentations);
                }
            }
        }
Exemplo n.º 2
0
    private static void InitLuaNode(LuaNode node)
    {
        Debug.Log("初始化LuaNode: " + node.nodeName);
        Transform transform = node.transform;

        // List<Component> validComponentList = new List<Component>();
        GetAllValidTransfrom(node, node.components, transform);
        // Debug.Log("validComponentList Count: " + validComponentList.Count);
        // if (validComponentList.Count > 0)
        // {
        //     Dictionary<Transform, List<Component>> map = new Dictionary<Transform, List<Component>>();
        //     foreach (Component item in validComponentList)
        //     {
        //         Transform parent = item.transform.parent;
        //         if (!map.ContainsKey(parent))
        //         {
        //             map.Add(parent, new List<Component>());
        //         }
        //         map[parent].Add(item);
        //     }
        //     node.componentMap = map;
        // }

        if (node.children != null)
        {
            foreach (LuaNode child in node.children)
            {
                InitLuaNode(child);
            }
        }
    }
Exemplo n.º 3
0
    public bool Load(string name)
    {
        uint num = XSingleton <XCommon> .singleton.XHash(name);

        if (!this.Find(num))
        {
            GameObject gameObject  = UICamera.mainCamera.gameObject;
            GameObject gameObject2 = XSingleton <XResourceLoaderMgr> .singleton.CreateFromPrefab(name, true, false) as GameObject;

            gameObject2.transform.parent        = UICamera.mainCamera.transform;
            gameObject2.transform.localPosition = Vector3.zero;
            gameObject2.transform.localRotation = Quaternion.identity;
            gameObject2.transform.localScale    = Vector3.one;
            gameObject2.layer = gameObject.layer;
            gameObject2.name  = name.Substring(name.LastIndexOf('/') + 1);
            LuaNode value = default(LuaNode);
            LuaDlg  dlg   = gameObject2.AddComponent <LuaDlg>();
            value.dlg  = dlg;
            value.go   = gameObject2;
            value.name = name;
            value.id   = num;
            value.dlg.OnShow();
            if (!this.m_stask.ContainsKey(num))
            {
                this.m_stask.Add(num, value);
            }
            return(true);
        }
        if (this.Find(num))
        {
            this.m_stask[num].go.SetActive(true);
            this.m_stask[num].dlg.OnShow();
        }
        return(false);
    }
Exemplo n.º 4
0
    private static void ExportLua(GameObject prefab, string savePath)
    {
        LuaNode node = new LuaNode("", prefab.transform);

        InitLuaNode(node);

        WriteLuaFile(node, savePath, prefab.name);
    }
Exemplo n.º 5
0
    private static void WriteLuaNodeDefine(StreamWriter sw, LuaNode node, string head)
    {
        // 局部变量
        sw.WriteLine();
        string str = head;

        if (string.IsNullOrEmpty(str))
        {
            str = "local ";
        }
        sw.WriteLine(string.Format("{0}{1} = {{}}", str, node.nodeName));
    }
Exemplo n.º 6
0
        private void WalkASTForCompletionSource(LuaNode node, int triggerPosition, HashSet <Declaration> res)
        {
            if (node == null)
            {
                return;
            }

            if (node is LuaBlockNode)
            {
                if (node.Parent is LuaChunkNode)
                {
                    foreach (var declaration in ((LuaBlockNode)node).Locals)
                    {
                        if (triggerPosition > declaration.Scope.StartPosition)
                        {
                            res.Add(declaration);
                        }
                    }
                }
                else
                {
                    foreach (var declaration in ((LuaBlockNode)node).Locals)
                    {
                        if (triggerPosition > declaration.Scope.StartPosition &&
                            triggerPosition < declaration.Scope.EndPosition)
                        {
                            res.Add(declaration);
                        }
                    }
                }

                foreach (var declaration in ((LuaBlockNode)node).Globals)
                {
                    if (triggerPosition > declaration.Scope.StartPosition)
                    {
                        res.Add(declaration);
                    }
                }

                foreach (var declaration in ((LuaBlockNode)node).Requires)
                {
                    res.Add(declaration);
                }
            }
            foreach (AstNode child in node.ChildNodes)
            {
                if (!(child is NullNode))
                {
                    WalkASTForCompletionSource(child as LuaNode, triggerPosition, res);
                }
            }
        }
Exemplo n.º 7
0
        private static void RetrieveIndentationsFromSyntaxTree(ITextView view, out int[] indentations)
        {
            int lineNumber = view.TextSnapshot.LineCount;

            indentations = new int[lineNumber];
            //LuaNode root = NPLTextViewCreationListener.AstRoot;
            LuaNode root = null;

            for (int i = 0; i < lineNumber; ++i)
            {
                indentations[i] = -1;
            }
            IterateAstTree(view, root, indentations);
        }
Exemplo n.º 8
0
    private static void WriteLuaNodeMethod(StreamWriter sw, LuaNode node, string parent)
    {
        string str = node.nodeName;

        // 如果是第二个词缀首字母大写
        if (!string.IsNullOrEmpty(parent))
        {
            str = str.Substring(0, 1).ToUpper() + str.Substring(1);
        }

        if (node.type == LuaNodeType.COMMON || node.type == LuaNodeType.LIST)
        {
            if (node.components != null)
            {
                foreach (Component component in node.components)
                {
                    if (component is BoxCollider)
                    {
                        sw.WriteLine();
                        sw.WriteLine("function this.{2}{1}{0}Clicked()", component.name.Replace("btn", ""), str, parent);
                        sw.WriteLine("\tlog('{2}{1}{0}Clicked')", component.name.Replace("btn", ""), str, parent);
                        sw.WriteLine("\t");
                        sw.WriteLine("end");
                    }
                }
            }
        }
        else if (node.type == LuaNodeType.TEMPLATE)
        {
            sw.WriteLine();
            sw.WriteLine("function this.{0}NodeUpdate(node, data)", node.nodeName);
            foreach (Component component in node.components)
            {
                if (component is UIWidget || component is UIGrid)
                {
                    sw.WriteLine(string.Format("\tlocal {0} = node:Find('{1}'):GetComponent('{2}')", component.name, GetNodePath(component.transform, node.transform), component.GetType()));
                }
            }
            sw.WriteLine("\t");
            sw.WriteLine("end");
        }

        if (node.children != null)
        {
            foreach (LuaNode child in node.children)
            {
                WriteLuaNodeMethod(sw, child, parent + str);
            }
        }
    }
Exemplo n.º 9
0
 public bool IDHide(uint id)
 {
     if (this.m_stask.Count > 0 && this.Find(id))
     {
         LuaNode luaNode = this.m_stask[id];
         if (luaNode.go != null)
         {
             luaNode.go.SetActive(false);
         }
         luaNode.dlg.OnHide();
         return(true);
     }
     return(true);
 }
Exemplo n.º 10
0
 private static void IterateAstTree(ITextView view, LuaNode node, int[] indentations)
 {
     if (node is LuaBlockNode)
     {
         for (int i = node.Span.Location.Line;
              i <= view.TextSnapshot.GetLineNumberFromPosition(node.Span.EndPosition - 1); ++i)
         {
             indentations[i] += 1;
         }
     }
     foreach (LuaNode childNode in node.GetChildNodes())
     {
         IterateAstTree(view, childNode, indentations);
     }
 }
Exemplo n.º 11
0
        private void GetDeclarationsByName(LuaNode node, Declaration declaration, List <Declaration> foundDeclarations)
        {
            if (node is LuaBlockNode)
            {
                //node = node as LuaBlockNode;
                foreach (var local in ((LuaBlockNode)node).Locals)
                {
                    if (local.Equal(declaration))
                    {
                        if (declaration.Scope.StartPosition >= local.Scope.StartPosition &&
                            declaration.Scope.EndPosition <= local.Scope.EndPosition)
                        {
                            foundDeclarations.Add(local);
                        }
                        else if (declaration.Scope.EndPosition == local.Scope.StartPosition)
                        {
                            foundDeclarations.Add(local);
                        }
                    }
                }

                foreach (var global in ((LuaBlockNode)node).Globals)
                {
                    if (global.Equal(declaration))
                    {
                        if (declaration.Scope.StartPosition >= global.Scope.StartPosition &&
                            declaration.Scope.EndPosition <= global.Scope.EndPosition)
                        {
                            foundDeclarations.Add(global);
                        }
                        else if (declaration.Scope.EndPosition == global.Scope.StartPosition)
                        {
                            foundDeclarations.Add(global);
                        }
                    }
                }
            }
            foreach (AstNode child in node.ChildNodes)
            {
                if (!(child is NullNode))
                {
                    GetDeclarationsByName(child as LuaNode, declaration, foundDeclarations);
                }
            }
        }
Exemplo n.º 12
0
 private void WalkASTForDeclarations(LuaNode node)
 {
     if (node is LuaBlockNode)
     {
         foreach (AstNode child in node.ChildNodes)
         {
             if (child is IDeclaration)
             {
                 ((IDeclaration)child).GetDeclarations((node as LuaBlockNode), this);
             }
         }
     }
     foreach (AstNode child in node.ChildNodes)
     {
         if (!(child is NullNode))
         {
             WalkASTForDeclarations(child as LuaNode);
         }
     }
 }
Exemplo n.º 13
0
 private IEnumerable <Declaration> RetreiveGlobalDeclarationsFromAST(LuaNode node)
 {
     if (node is LuaBlockNode)
     {
         foreach (var global in ((LuaBlockNode)node).Globals)
         {
             yield return(global);
         }
     }
     foreach (AstNode child in node.ChildNodes)
     {
         if (!(child is NullNode))
         {
             foreach (var declaration in RetreiveGlobalDeclarationsFromAST(child as LuaNode))
             {
                 yield return(declaration);
             }
         }
     }
 }
Exemplo n.º 14
0
        // Get global declarations from files in project other than the current file
        //public IEnumerable<Declaration> GetGlobalDeclarationInProject()
        //{
        //    var entries = _entry.Analyzer.GetAnalysisEntries();
        //    var validEntries = entries.Where((entry) => entry.FilePath != _entry.FilePath && entry.Model != null);
        //    List<Declaration> res = new List<Declaration>();
        //    for (int i = 0; i < validEntries.Count(); ++i)
        //    {
        //        res.Concat(validEntries.ElementAt(i).Model.GetGlobalDeclarations());
        //    }
        //    return res;
        //}

        private void GetGlobalDeclarationsByName(LuaNode node, Declaration declaration, List <Declaration> foundedDeclarations)
        {
            if (node is LuaBlockNode)
            {
                foreach (var global in ((LuaBlockNode)node).Globals)
                {
                    if (global.Equal(declaration))
                    {
                        foundedDeclarations.Add(global);
                    }
                }
            }
            foreach (AstNode child in node.ChildNodes)
            {
                if (!(child is NullNode))
                {
                    GetGlobalDeclarationsByName(child as LuaNode, declaration, foundedDeclarations);
                }
            }
        }
Exemplo n.º 15
0
    private LuaNode TokenizeBracedContent(string strText, int iPrevDelimiterIndex = -1)
    {
        ++_iParseCallCount;

        LuaNode node = new LuaNode();

        try
        {
            //print("START iPrevDelimiterIndex: " + iPrevDelimiterIndex);

            // If we're at the start of parsing, search for the first open brace.
            if (iPrevDelimiterIndex < 0)
            {
                iPrevDelimiterIndex = strText.IndexOf('{');

                //print("MODIFIED iPrevDelimiterIndex: " + iPrevDelimiterIndex);
            }

            // If we've found a open brace character continue.
            if (iPrevDelimiterIndex > -1)
            {
                // Store the starting point of the node.
                node.iStartIndex = iPrevDelimiterIndex;

                ++iPrevDelimiterIndex;

                int iDelimiterIndex = -1;

                // Loop until we've found a closing brace.
                while (node.iEndIndex < 0)
                {
                    // Search for the next delimiter.
                    iDelimiterIndex = strText.IndexOfAny(_arrDelimiters, iPrevDelimiterIndex);

                    // If we've found a delimiter, process it.
                    if (iDelimiterIndex > -1)
                    {
                        int iSubLength = iDelimiterIndex - iPrevDelimiterIndex;
                        string strStatement = strText.Substring(iPrevDelimiterIndex, iSubLength);
                        //print("strStatement (" + iPrevDelimiterIndex + "-" + iDelimiterIndex + "): " + strStatement);
                        strStatement =
                            strStatement.Trim()
                                .Replace("\\\"", "\"")
                                .Replace("\\t", "\t")
                                .Replace("\\r", "\r")
                                .Replace("\\n", "\n")
                                .Replace("\\\\", "\\");

                        // Ignore LUA comments.
                        if (strStatement.StartsWith("--"))
                        {
                            iDelimiterIndex = strText.IndexOf('\n', iPrevDelimiterIndex);
                            //print("END OF COMMENT - iDelimiterIndex: " + iDelimiterIndex);
                            if (iDelimiterIndex < 0)
                            {
                                iDelimiterIndex = strText.Length - 1;
                                break;
                            }
                        }
                        else if (strText[iDelimiterIndex] == '"')
                        {
                            ++iDelimiterIndex;

                            int iStringStartIndex = iDelimiterIndex;
                            int iStringEndIndex = -1;
                            while (iStringEndIndex < 0)
                            {
                                iStringEndIndex = strText.IndexOf('"', iStringStartIndex);

                                if (iStringEndIndex > -1)
                                {
                                    // If this is an escaped double quote, keep searching.
                                    if (strText[iStringEndIndex - 1] == '\\')
                                    {
                                        iStringStartIndex = iStringEndIndex + 1;
                                        iStringEndIndex = -1;
                                    }
                                    else
                                    {
                                        iSubLength = iStringEndIndex - iDelimiterIndex;

                                        strStatement =
                                            strText.Substring(iDelimiterIndex, iSubLength).Trim()
                                                .Replace("\\\"", "\"")
                                                .Replace("\\t", "\t")
                                                .Replace("\\r", "\r")
                                                .Replace("\\n", "\n")
                                                .Replace("\\\\", "\\");

                                        if (strStatement.Length > 0)
                                        {
                                            node.lstTokens.Add(strStatement);
                                        }

                                        iDelimiterIndex = iStringEndIndex;
                                    }
                                }
                                else
                                {
                                    throw new Exception("Unable find closing double quote for string.");
                                }
                            }
                        }
                        else
                        {
                            if (strStatement.Length > 0)
                            {
                                node.lstTokens.Add(strStatement);
                            }

                            if (strText[iDelimiterIndex] == '}')
                            {
                                node.iEndIndex = iDelimiterIndex;
                            }
                            else
                                if (strText[iDelimiterIndex] == '{')
                            {
                                //print("Parsing new node - iDelimiterIndex: " + iDelimiterIndex);

                                LuaNode nodeChild = TokenizeBracedContent(strText, iDelimiterIndex);

                                //print("Done parsing new node - iEndIndex: " + nodeChild.iEndIndex);

                                if (nodeChild.strError != null)
                                {
                                    node.strError = nodeChild.strError;
                                    node.iErrorDepth = nodeChild.iErrorDepth + 1;

                                    break;
                                }

                                node.lstChildren.Add(nodeChild);

                                iDelimiterIndex = nodeChild.iEndIndex;

                                if (_iParseCallCount > 3)
                                {
                                    // break;
                                }
                            }
                        }

                        iPrevDelimiterIndex = iDelimiterIndex + 1;
                    }
                    else
                    {
                        throw new Exception("Unable find closing brace.");
                    }
                }
            }
            else
            {
                throw new Exception("Unable find opening brace.");
            }
        }
        catch (Exception e)
        {
            node.strError = "ERROR: " + e.Message;
            node.iErrorDepth = 0;
        }

        return node;
    }
Exemplo n.º 16
0
    private static void WriteLuaNodeBind(StreamWriter sw, LuaNode node, string parent)
    {
        sw.WriteLine();
        if (node.components.Count > 0)
        {
            if (node.type == LuaNodeType.COMMON)
            {
                sw.WriteLine(string.Format("\t{2}{0} = {{}}", node.nodeName, GetNodePath(node.transform), parent));
                sw.WriteLine(string.Format("\t{2}{0}.go = m_transform:Find('{1}').gameObject", node.nodeName, GetNodePath(node.transform), parent));
                foreach (Component component in node.components)
                {
                    // sw.WriteLine(string.Format("\tlocal {0} = m_transform:Find('{1}')", pair.Key.name, GetNodePath(pair.Key)));
                    // foreach (Component component in pair.Value)
                    // {
                    if (component is UIWidget || component is UIGrid)
                    {
                        sw.WriteLine(string.Format("\t{3}{2}.{0} = {3}{2}.go.transform:Find('{4}'):GetComponent('{1}')", component.name, component.GetType(), node.nodeName, parent, GetNodePath(component.transform, node.transform)));
                    }
                    else if (component is BoxCollider)
                    {
                        string str = parent;
                        while (str.Contains("."))
                        {
                            int index = str.IndexOf(".");
                            str = str.Remove(index, 1);
                            if (str.Contains("."))
                            {
                                str = str.Substring(0, index) + str.Substring(index, 1).ToUpper() + str.Substring(index + 1);
                            }
                        }

                        string str2 = node.nodeName;
                        if (!string.IsNullOrEmpty(parent))
                        {
                            str2 = str2.Substring(0, 1).ToUpper() + str2.Substring(1);
                        }
                        str = str + str2 + component.name.Replace("btn", "");

                        sw.WriteLine(string.Format("\t{2}{1}.{0} = {2}{1}.go.transform:Find('{3}').gameObject", component.name, node.nodeName, parent, GetNodePath(component.transform, node.transform)));
                        sw.WriteLine(string.Format("\tm_luaBehaviour:AddClick({3}{2}.{0}, this.{4}Clicked);", component.name, component.name.Replace("btn", ""), node.nodeName, parent, str));
                    }
                    // }
                }
            }
            else if (node.type == LuaNodeType.LIST)
            {
                sw.WriteLine(string.Format("\t{2}{0} = {{}}", node.nodeName, GetNodePath(node.transform), parent));
                sw.WriteLine(string.Format("\tlocal {0} = m_transform:Find('{1}')", node.nodeName, GetNodePath(node.transform)));
                sw.WriteLine(string.Format("\tfor i = 0, {0}.childCount - 1 do", node.nodeName));
                sw.WriteLine(string.Format("\t\tlocal child = {0}:GetChild(i)", node.nodeName));
                if (node.components[0].transform.parent == node.transform)
                {
                    if (node.components.Count == 1)
                    {
                        foreach (Component component in node.components)
                        {
                            if (component is UIWidget || component is UIGrid)
                            {
                                sw.WriteLine(string.Format("\t\t{2}{1}[i + 1] = child:GetComponent('{0}')", component.GetType(), node.nodeName, parent));
                            }
                            else if (component is BoxCollider)
                            {
                                sw.WriteLine(string.Format("\t\t{1}{0}[i + 1] = child.gameObject", node.nodeName, parent));
                                string str = parent;
                                while (str.Contains("."))
                                {
                                    int index = str.IndexOf(".");
                                    str = str.Remove(index, 1);
                                    if (str.Contains("."))
                                    {
                                        str = str.Substring(0, index) + str.Substring(index, 1).ToUpper() + str.Substring(index + 1);
                                    }
                                }

                                string str2 = node.nodeName;
                                if (!string.IsNullOrEmpty(parent))
                                {
                                    str2 = str2.Substring(0, 1).ToUpper() + str2.Substring(1);
                                }
                                str = str + str2 + component.name.Replace("btn", "");
                                sw.WriteLine(string.Format("\t\tm_luaBehaviour:AddClick({2}{1}[i + 1], this.{3}Clicked);", component.name.Replace("btn", ""), node.nodeName, parent, str));
                            }
                        }
                    }
                }
                else
                {
                    sw.WriteLine(string.Format("\t\t{1}{0}[i + 1] = {{}}", node.nodeName, parent));
                    foreach (Component component in node.components)
                    {
                        if (component is UIWidget || component is UIGrid)
                        {
                            sw.WriteLine(string.Format("\t\t{3}{2}[i + 1].{0} = child:Find('{0}'):GetComponent('{1}')", GetNodePath(component.transform, node.transform.GetChild(0)), component.GetType(), node.nodeName, parent));
                        }
                        else if (component is BoxCollider)
                        {
                            sw.WriteLine(string.Format("\t\t{2}{1}[i + 1].{0} = child:Find('{0}').gameObject", GetNodePath(component.transform, node.transform.GetChild(0)), node.nodeName, parent));
                            string str = parent;
                            while (str.Contains("."))
                            {
                                int index = str.IndexOf(".");
                                str = str.Remove(index, 1);
                                if (str.Contains("."))
                                {
                                    str = str.Substring(0, index) + str.Substring(index, 1).ToUpper() + str.Substring(index + 1);
                                }
                            }

                            string str2 = node.nodeName;
                            if (!string.IsNullOrEmpty(parent))
                            {
                                str2 = str2.Substring(0, 1).ToUpper() + str2.Substring(1);
                            }
                            str = str + str2 + component.name.Replace("btn", "");
                            sw.WriteLine(string.Format("\t\tm_luaBehaviour:AddClick({3}{2}[i + 1].{0}, this.{4}Clicked);", component.name, component.name.Replace("btn", ""), node.nodeName, parent, str));
                        }
                    }
                }
                sw.WriteLine("\tend");
            }
            else if (node.type == LuaNodeType.TEMPLATE)
            {
                sw.WriteLine(string.Format("\t{2}{1} = m_transform:Find('{0}').gameObject", GetNodePath(node.transform), node.nodeName, parent));
                return;
            }
        }

        if (node.children != null)
        {
            foreach (LuaNode child in node.children)
            {
                string np = parent + node.nodeName;
                if (!string.IsNullOrEmpty(np))
                {
                    np = np + '.';
                }
                WriteLuaNodeBind(sw, child, np);
            }
        }
    }
Exemplo n.º 17
0
    private static void WriteLuaFile(LuaNode node, string savePath, string name)
    {
        savePath = string.Format("{0}/{1}.lua", savePath, name);
        Debug.Log("SavePath: " + savePath);
        if (File.Exists(savePath))
        {
            int option = EditorUtility.DisplayDialogComplex("文件已存在",
                                                            savePath + "已存在, 是否替换?",
                                                            "替换",
                                                            "取消",
                                                            "保留两者");

            switch (option)
            {
            case 0:
                File.Delete(savePath);
                break;

            case 1:
                return;

            case 2:
                savePath = savePath.Replace(".lua", "_auto.lua");
                if (File.Exists(savePath))
                {
                    File.Delete(savePath);
                }
                break;

            default:
                Debug.LogError("Unrecognized option.");
                break;
            }
        }

        FileStream   fs = new FileStream(savePath, FileMode.Create);
        StreamWriter sw = new StreamWriter(fs);

        //开始写入
        sw.WriteLine("--[[Created by lua UI script exporter.]]");
        sw.WriteLine(string.Format("{0} = {{}}", name));

        sw.WriteLine();
        sw.WriteLine(string.Format("local this = {0}", name));
        sw.WriteLine();
        sw.WriteLine("local m_transform");
        sw.WriteLine("local m_luaBehaviour");
        sw.WriteLine();


        // 局部变量
        if (node.children != null)
        {
            foreach (LuaNode child in node.children)
            {
                sw.WriteLine(string.Format("local {0} = {{}}", child.nodeName));
            }
        }

        // Awake方法
        sw.WriteLine();
        sw.WriteLine("function this.Awake(obj)");
        sw.WriteLine("\tm_luaBehaviour = obj:GetComponent('LuaBehaviour')");
        sw.WriteLine("\tm_transform = obj.transform");
        WriteLuaNodeBind(sw, node, "");

        sw.WriteLine("end");

        sw.WriteLine();
        sw.WriteLine("function this.Start()");
        sw.WriteLine("\t");
        sw.WriteLine("end");
        WriteLuaNodeMethod(sw, node, "");

        //清空缓冲区
        sw.Flush();
        //关闭流
        sw.Close();
        fs.Close();
    }
Exemplo n.º 18
0
    private void TokensToString(StringBuilder strbText, LuaNode node, int iIndentationLevel = 0)
    {
        if (node.lstTokens.Count > 0)
        {
            strbText.Append(new String('\t', iIndentationLevel));
            strbText.Append(node.lstTokens[0]);
            for (int iTokenIndex = 1; iTokenIndex < node.lstTokens.Count; ++iTokenIndex)
            {
                strbText.Append("  |  ");
                strbText.Append(node.lstTokens[iTokenIndex]);
            }
            strbText.AppendLine();
            strbText.AppendLine();
        }

        for (int iChildIndex = 0; iChildIndex < node.lstChildren.Count; ++iChildIndex)
        {
            LuaNode childNode = node.lstChildren[iChildIndex];

            TokensToString(strbText, childNode, iIndentationLevel + 1);
        }
    }
Exemplo n.º 19
0
    public static void ExtractDialogueEntries(LuaNode node, ref DiaEntry_Label entry_Label, bool bClearEntries = true, int iLuaNodeIndex = 0)
    {
        if (bClearEntries)
        {
            lstEntries_IfGoto.Clear();
            dictEntries_Label.Clear();
            lstEntries_Label.Clear();
        }

        if (node.lstTokens.Count > 0)
        {
            string strType = node.lstTokens[0].ToLower();

            if (strType.Equals("if"))
            {
                try
                {
                    if (node.lstTokens.Count == 5)
                    {
                        DiaEntry_IfGoto entry = new DiaEntry_IfGoto();
                        entry.key = node.lstTokens[1];
                        entry.op = node.lstTokens[2];
                        entry.value = node.lstTokens[3];
                        entry.label = node.lstTokens[4];

                        //Debug.LogError(entry.key+"\t"+entry.op+"\t"+entry.value+"\t"+entry.label+"**************");

                        if (entry_Label == null)
                        {
                            // General
                            lstEntries_IfGoto.Add(entry);
                        }
                        else
                        {
                            if (entry_Label.lstBranches.Count > 0)
                            {
                                // Branch
                                DiaBranch_Label branch = entry_Label.lstBranches.Last();
                                branch.lstIfGotos.Add(entry);
                            }
                            else
                            {
                                // Label
                                entry_Label.lstInitialIfGotos.Add(entry);
                            }
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'if' entry does not contain exactly 5 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'if' node - " + e);
                }
            }
            else if (strType.Equals("goto"))
            {
                try
                {
                    if (node.lstTokens.Count == 2)
                    {
                        // Only set the 'label' value because this is a straight goto.
                        DiaEntry_IfGoto entry = new DiaEntry_IfGoto();
                        entry.label = node.lstTokens[1];

                        if (entry_Label == null)
                        {
                            // General
                            lstEntries_IfGoto.Add(entry);
                        }
                        else
                        {
                            if (entry_Label.lstBranches.Count > 0)
                            {
                                // NOTE: Nothing is currently done with branch.lstIfGotos.

                                // Branch
                                DiaBranch_Label branch = entry_Label.lstBranches.Last();
                                branch.lstIfGotos.Add(entry);
                            }
                            else
                            {
                                // Label
                                entry_Label.lstInitialIfGotos.Add(entry);
                            }
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'goto' entry does not contain exactly 2 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'goto' node - " + e);
                }
            }
            else if (strType.Equals("label"))
            {
                try
                {
                    if (node.lstTokens.Count == 2)
                    {
                        entry_Label = new DiaEntry_Label();
                        entry_Label.name = node.lstTokens[1];
                        entry_Label.index = lstEntries_Label.Count;

                        dictEntries_Label.Add(entry_Label.name, entry_Label);
                        lstEntries_Label.Add(entry_Label);
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'label' entry does not contain exactly 2 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'label' node - " + e);
                }
            }
            else if (strType.Equals("n"))
            {
                try
                {
                    if (node.lstTokens.Count == 2)
                    {
                        // print("n - entry_Label is NULL: " + (entry_Label == null).ToString());

                        if (entry_Label != null)
                        {
                            DiaEntry_NpcText entry = new DiaEntry_NpcText();
                            entry.text = Regex.Unescape(node.lstTokens[1]);

                            DiaBranch_Label branch = new DiaBranch_Label();
                            branch.npcText = entry;

                            entry_Label.lstBranches.Add(branch);
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'n' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'n' entry does not contain exactly 2 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'n' node - " + e);
                }
            }
            else if (strType.Equals("n1"))
            {
                try
                {
                    if (node.lstTokens.Count == 3)
                    {
                        if (entry_Label != null)
                        {
                            DiaEntry_NpcText entry = new DiaEntry_NpcText();
                            entry.text = Regex.Unescape(node.lstTokens[1]);

                            entry.arg1 = node.lstTokens[2];

                            DiaBranch_Label branch = new DiaBranch_Label();
                            branch.npcText = entry;

                            entry_Label.lstBranches.Add(branch);
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'n1' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'n1' entry does not contain exactly 3 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'n1' node - " + e);
                }
            }
            else if (strType.Equals("n2"))
            {
                try
                {
                    if (node.lstTokens.Count == 4)
                    {
                        if (entry_Label != null)
                        {
                            DiaEntry_NpcText entry = new DiaEntry_NpcText();
                            entry.text = Regex.Unescape(node.lstTokens[1]);

                            entry.arg1 = node.lstTokens[2];
                            entry.arg2 = node.lstTokens[3];

                            DiaBranch_Label branch = new DiaBranch_Label();
                            branch.npcText = entry;

                            entry_Label.lstBranches.Add(branch);
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'n2' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'n2' entry does not contain exactly 4 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'n2' node - " + e);
                }
            }
            else if (strType.Equals("n3"))
            {
                try
                {
                    if (node.lstTokens.Count == 5)
                    {
                        if (entry_Label != null)
                        {
                            DiaEntry_NpcText entry = new DiaEntry_NpcText();
                            entry.text = Regex.Unescape(node.lstTokens[1]);

                            entry.arg1 = node.lstTokens[2];
                            entry.arg2 = node.lstTokens[3];
                            entry.arg3 = node.lstTokens[4];

                            DiaBranch_Label branch = new DiaBranch_Label();
                            branch.npcText = entry;

                            entry_Label.lstBranches.Add(branch);
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'n3' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'n3' entry does not contain exactly 5 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'n3' node - " + e);
                }
            }
            else if (strType.Equals("ns"))
            {
                try
                {
                    if (node.lstTokens.Count == 3)
                    {
                        if (entry_Label != null)
                        {
                            DiaEntry_NpcText entry = new DiaEntry_NpcText();
                            entry.text = Regex.Unescape(node.lstTokens[1]);

                            string strAudioName = node.lstTokens[2];
                            entry.sound.Url = strAudioName;

                            DiaBranch_Label branch = new DiaBranch_Label();
                            branch.npcText = entry;

                            entry_Label.lstBranches.Add(branch);
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'ns' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'ns' entry does not contain exactly 3 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'ns' node - " + e);
                }
            }
            else if (strType.Equals("ns1"))
            {
                try
                {
                    if (node.lstTokens.Count == 4)
                    {
                        if (entry_Label != null)
                        {
                            DiaEntry_NpcText entry = new DiaEntry_NpcText();
                            entry.text = Regex.Unescape(node.lstTokens[1]);

                            string strAudioName = node.lstTokens[2];
                            entry.sound.Url = strAudioName;

                            entry.arg1 = node.lstTokens[3];

                            DiaBranch_Label branch = new DiaBranch_Label();
                            branch.npcText = entry;

                            entry_Label.lstBranches.Add(branch);

                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'ns1' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'ns1' entry does not contain exactly 4 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'ns1' node - " + e);
                }
            }
            else if (strType.Equals("ns2"))
            {
                try
                {
                    if (node.lstTokens.Count == 5)
                    {
                        if (entry_Label != null)
                        {
                            DiaEntry_NpcText entry = new DiaEntry_NpcText();
                            entry.text = Regex.Unescape(node.lstTokens[1]);

                            string strAudioName = node.lstTokens[2];
                            entry.sound.Url = strAudioName;

                            entry.arg1 = node.lstTokens[3];
                            entry.arg2 = node.lstTokens[4];

                            DiaBranch_Label branch = new DiaBranch_Label();
                            branch.npcText = entry;

                            entry_Label.lstBranches.Add(branch);
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'ns2' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'ns2' entry does not contain exactly 5 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'ns2' node - " + e);
                }
            }
            else if (strType.Equals("ns3"))
            {
                try
                {
                    if (node.lstTokens.Count == 6)
                    {
                        if (entry_Label != null)
                        {
                            DiaEntry_NpcText entry = new DiaEntry_NpcText();
                            entry.text = Regex.Unescape(node.lstTokens[1]);

                            string strAudioName = node.lstTokens[2];
                            entry.sound.Url = strAudioName;

                            entry.arg1 = node.lstTokens[3];
                            entry.arg2 = node.lstTokens[4];
                            entry.arg3 = node.lstTokens[5];

                            DiaBranch_Label branch = new DiaBranch_Label();
                            branch.npcText = entry;

                            entry_Label.lstBranches.Add(branch);
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'ns3' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'ns3' entry does not contain exactly 6 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'ns3' node - " + e);
                }
            }
            else if (strType.Equals("p"))
            {
                try
                {
                    if (node.lstTokens.Count == 2)
                    {
                        if (entry_Label != null)
                        {
                            if (entry_Label.lstBranches.Count > 0)
                            {
                                DiaEntry_PcText entry = new DiaEntry_PcText();
                                entry.text = Regex.Unescape(node.lstTokens[1]);

                                DiaBranch_Label branch = entry_Label.lstBranches.Last();
                                branch.lstPcTexts.Add(entry);
                            }
                            else
                            {
                                Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'p' entry found before any 'n' or 'ns' entries for label '" + entry_Label.name + "'.");
                            }
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'p' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'p' entry does not contain exactly 2 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'p' node - " + e);
                }
            }
            else if (strType.Equals("pg"))
            {
                try
                {
                    if (node.lstTokens.Count == 3)
                    {
                        if (entry_Label != null)
                        {
                            if (entry_Label.lstBranches.Count > 0)
                            {
                                DiaEntry_PcText entry = new DiaEntry_PcText();
                                entry.text = Regex.Unescape(node.lstTokens[1]);
                                entry.gotoLabel = node.lstTokens[2];

                                DiaBranch_Label branch = entry_Label.lstBranches.Last();
                                branch.lstPcTexts.Add(entry);
                            }
                            else
                            {
                                Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg' entry found before any 'n' or 'ns' entries for label '" + entry_Label.name + "'.");
                            }
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg' entry does not contain exactly 3 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'pg' node - " + e);
                }
            }
            else if (strType.Equals("pgs"))
            {
                try
                {
                    if (node.lstTokens.Count == 4)
                    {
                        if (entry_Label != null)
                        {
                            if (entry_Label.lstBranches.Count > 0)
                            {
                                DiaEntry_PcText entry = new DiaEntry_PcText();
                                entry.text = Regex.Unescape(node.lstTokens[1]);
                                entry.gotoLabel = node.lstTokens[2];
                                entry.score = node.lstTokens[3];

                                DiaBranch_Label branch = entry_Label.lstBranches.Last();
                                branch.lstPcTexts.Add(entry);
                            }
                            else
                            {
                                Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'pgs' entry found before any 'n' or 'ns' entries for label '" + entry_Label.name + "'.");
                            }
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'pgs' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'pgs' entry does not contain exactly 4 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'pgs' node - " + e);
                }
            }
            else if (strType.Equals("pg1"))
            {
                try
                {
                    if (node.lstTokens.Count == 4)
                    {
                        if (entry_Label != null)
                        {
                            if (entry_Label.lstBranches.Count > 0)
                            {
                                DiaEntry_PcText entry = new DiaEntry_PcText();
                                entry.text = Regex.Unescape(node.lstTokens[1]);
                                entry.gotoLabel = node.lstTokens[2];
                                entry.arg1 = node.lstTokens[3];

                                // Format the text based on legacy formatting rules.
                                //entry.text = LegacyFormatSubstitute(entry.text, arg1);

                                DiaBranch_Label branch = entry_Label.lstBranches.Last();
                                branch.lstPcTexts.Add(entry);
                            }
                            else
                            {
                                Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg1' entry found before any 'n' or 'ns' entries for label '" + entry_Label.name + "'.");
                            }
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg1' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg1' entry does not contain exactly 4 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'pg' node - " + e);
                }
            }
            else if (strType.Equals("pg1s"))
            {
                try
                {
                    if (node.lstTokens.Count == 5)
                    {
                        if (entry_Label != null)
                        {
                            if (entry_Label.lstBranches.Count > 0)
                            {
                                DiaEntry_PcText entry = new DiaEntry_PcText();
                                entry.text = Regex.Unescape(node.lstTokens[1]);
                                entry.gotoLabel = node.lstTokens[2];
                                entry.arg1 = node.lstTokens[3];
                                entry.score = node.lstTokens[4];

                                // Format the text based on legacy formatting rules.
                                //entry.text = LegacyFormatSubstitute(entry.text, arg1);

                                DiaBranch_Label branch = entry_Label.lstBranches.Last();
                                branch.lstPcTexts.Add(entry);
                            }
                            else
                            {
                                Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg1s' entry found before any 'n' or 'ns' entries for label '" + entry_Label.name + "'.");
                            }
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg1s' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg1s' entry does not contain exactly 5 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'pg' node - " + e);
                }
            }
            else if (strType.Equals("pg2"))
            {
                try
                {
                    if (node.lstTokens.Count == 5)
                    {
                        if (entry_Label != null)
                        {
                            if (entry_Label.lstBranches.Count > 0)
                            {
                                DiaEntry_PcText entry = new DiaEntry_PcText();
                                entry.text = Regex.Unescape(node.lstTokens[1]);
                                entry.gotoLabel = node.lstTokens[2];
                                entry.arg1 = node.lstTokens[3];
                                entry.arg2 = node.lstTokens[4];

                                // Format the text based on legacy formatting rules.
                                //entry.text = LegacyFormatSubstitute(entry.text, arg1);
                                //entry.text = LegacyFormatSubstitute(entry.text, arg2);

                                DiaBranch_Label branch = entry_Label.lstBranches.Last();
                                branch.lstPcTexts.Add(entry);
                            }
                            else
                            {
                                Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg2' entry found before any 'n' or 'ns' entries for label '" + entry_Label.name + "'.");
                            }
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg2' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg2' entry does not contain exactly 5 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'pg' node - " + e);
                }
            }
            else if (strType.Equals("pg2s"))
            {
                try
                {
                    if (node.lstTokens.Count == 6)
                    {
                        if (entry_Label != null)
                        {
                            if (entry_Label.lstBranches.Count > 0)
                            {
                                DiaEntry_PcText entry = new DiaEntry_PcText();
                                entry.text = Regex.Unescape(node.lstTokens[1]);
                                entry.gotoLabel = node.lstTokens[2];
                                entry.arg1 = node.lstTokens[3];
                                entry.arg2 = node.lstTokens[4];
                                entry.score = node.lstTokens[5];

                                // Format the text based on legacy formatting rules.
                                //entry.text = LegacyFormatSubstitute(entry.text, arg1);
                                //entry.text = LegacyFormatSubstitute(entry.text, arg2);

                                DiaBranch_Label branch = entry_Label.lstBranches.Last();
                                branch.lstPcTexts.Add(entry);
                            }
                            else
                            {
                                Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg2s' entry found before any 'n' or 'ns' entries for label '" + entry_Label.name + "'.");
                            }
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg2s' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'pg2s' entry does not contain exactly 6 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'pg' node - " + e);
                }
            }
            else if (strType.Equals("wait"))
            {
                try
                {
                    if (node.lstTokens.Count == 2)
                    {
                        if (entry_Label != null)
                        {
                            if (entry_Label.lstBranches.Count > 0)
                            {
                                DiaEntry_PcText entry = new DiaEntry_PcText();
                                //entry.text = "[Leave] (Wait Placeholder)";
                                entry.text = "Ok.";
                                entry.gotoLabel = node.lstTokens[1];

                                DiaBranch_Label branch = entry_Label.lstBranches.Last();
                                branch.lstPcTexts.Add(entry);
                            }
                            else
                            {
                                Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'wait' entry found before any 'n' or 'ns' entries for label '" + entry_Label.name + "'.");
                            }
                        }
                        else
                        {
                            Debug.LogError("!!! ERROR - Node: " + iLuaNodeIndex + " - 'wait' entry found in mode other than Label.");
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'wait' entry does not contain exactly 2 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'wait' node - " + e);
                }
            }
            else if (strType.Equals("fun"))
            {
                try
                {
                    if (node.lstTokens.Count == 2)
                    {
                        DiaEntry_Function entry = new DiaEntry_Function();
                        entry.name = node.lstTokens[1];

                        if (entry_Label != null)
                        {

                            if (entry_Label.lstBranches.Count > 0)
                            {
                                DiaBranch_Label branch = entry_Label.lstBranches.Last();
                                branch.lstFunctions.Add(entry);
                            }
                            else
                            {
                                entry_Label.lstInitialFunctions.Add(entry);
                            }
                        }
                        else
                        {
                            lstEntries_Function.Add(entry);
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'fun' entry does not contain exactly 2 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'fun' node - " + e);
                }
            }
            else if (strType.Equals("fun2"))
            {
                try
                {
                    if (node.lstTokens.Count == 3)
                    {
                        DiaEntry_Function entry = new DiaEntry_Function();
                        entry.name = node.lstTokens[1];
                        entry.arg1 = node.lstTokens[2];

                        if (entry_Label != null)
                        {
                            if (entry_Label.lstBranches.Count > 0)
                            {
                                DiaBranch_Label branch = entry_Label.lstBranches.Last();
                                branch.lstFunctions.Add(entry);
                            }
                            else
                            {
                                entry_Label.lstInitialFunctions.Add(entry);
                            }
                        }
                        else
                        {
                            lstEntries_Function.Add(entry);
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'fun2' entry does not contain exactly 3 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'fun2' node - " + e);
                }
            }
            else if (strType.Equals("fun3"))
            {
                try
                {
                    if (node.lstTokens.Count == 4)
                    {
                        DiaEntry_Function entry = new DiaEntry_Function();
                        entry.name = node.lstTokens[1];
                        entry.arg1 = node.lstTokens[2];
                        entry.arg2 = node.lstTokens[3];

                        if (entry_Label != null)
                        {
                            if (entry_Label.lstBranches.Count > 0)
                            {
                                DiaBranch_Label branch = entry_Label.lstBranches.Last();
                                branch.lstFunctions.Add(entry);
                            }
                            else
                            {
                                entry_Label.lstInitialFunctions.Add(entry);
                            }
                        }
                        else
                        {
                            lstEntries_Function.Add(entry);
                        }
                    }
                    else
                    {
                        string strError = "!!! ERROR - Node: " + iLuaNodeIndex + " - 'fun3' entry does not contain exactly 4 tokens. Found token count: " + node.lstTokens.Count;
                        strError += "\r\n";
                        foreach (string strToken in node.lstTokens)
                        {
                            strError += "  |  " + strToken;
                        }
                        Debug.LogError(strError);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("!!! ERROR - DialogueOverlay.ExtractDialogueEntries() - 'fun3' node - " + e);
                }
            }

        }

        foreach (LuaNode childNode in node.lstChildren)
        {
            ExtractDialogueEntries(childNode, ref entry_Label, false, ++iLuaNodeIndex);
        }
    }
Exemplo n.º 20
0
    private static void GetAllValidTransfrom(LuaNode node, List <Component> list, Transform transform)
    {
        if (node.type == LuaNodeType.LIST && transform == node.transform)
        {
            if (transform.childCount > 0)
            {
                transform = transform.GetChild(0);
            }
            else
            {
                Debug.LogError("列表节点没有子节点:" + transform.name);
                return;
            }
        }

        if (transform)
        {
            if (transform.name.Contains("Node") && transform != node.transform)
            {
                if (node.children == null)
                {
                    node.children = new List <LuaNode>();
                }
                string nodeName = transform.name.Replace("Node", "");
                Debug.Log(string.Format("{0}找到子节点{1}", node.nodeName, nodeName));
                LuaNode child = new LuaNode(nodeName, transform);
                if (transform.name.Contains("temp"))
                {
                    child.type = LuaNodeType.TEMPLATE;
                }
                node.children.Add(child);
                return;
            }

            if (transform.name.Contains("Array") && transform != node.transform)
            {
                if (node.children == null)
                {
                    node.children = new List <LuaNode>();
                }
                string nodeName = transform.name;
                Debug.Log(string.Format("{0}找到子节点{1}", node.nodeName, nodeName));
                LuaNode child = new LuaNode(nodeName, transform);
                child.type = LuaNodeType.LIST;
                node.children.Add(child);
                return;
            }

            if (transform.name == "static")
            {
                return;
            }

            Component component = null;

            if (transform.GetComponent <UILabel>() != null && transform.name.Contains("lab"))
            {
                component = transform.GetComponent <UILabel>();
            }
            else if (transform.GetComponent <UISprite>() != null && transform.name.Contains("spr"))
            {
                component = transform.GetComponent <UISprite>();
            }
            else if (transform.GetComponent <UITexture>() != null && transform.name.Contains("tex"))
            {
                component = transform.GetComponent <UITexture>();
            }
            else if (transform.GetComponent <BoxCollider>() != null && transform.name.Contains("btn"))
            {
                component = transform.GetComponent <BoxCollider>();
            }
            else if (transform.GetComponent <UIGrid>() != null && transform.name.Contains("grid"))
            {
                component = transform.GetComponent <UIGrid>();
            }

            // Debug.Log("检测节点: " + transform.name + " component: " + component);

            if (component != null)
            {
                list.Add(component);
                Debug.Log("检测节点: " + transform.name + " component: " + component + " list: " + list.Count);
            }

            if (transform.childCount > 0)
            {
                foreach (Transform child in transform)
                {
                    GetAllValidTransfrom(node, list, child);
                }
            }
        }
    }