Exemplo n.º 1
0
    public XMLNodeList GetNodeList(string path)
    {
        XMLNodeList nodeList = GetObject(path) as XMLNodeList;

        if (nodeList == null)
            nodeList = new XMLNodeList ();

        return nodeList;
    }
Exemplo n.º 2
0
    public void Birth(string target)
    {
        activated = false;
        canPoison = false;

        gameplay = Gameplay.Instance();

        tavern = Tavern.Instance();

        strJob = target;

        AssignClass();

        transform.Find("Collider").GetComponent <BoxCollider>().enabled = false;

        XMLNodeList heroesXML = gameplay.xml.GetNodeList("doc>0>units>0>heroes>0>hero");

        heroXML = heroesXML[intJob] as XMLNode;

        levelsXML = heroXML.GetNodeList("levels>0>level");

        transform.parent = GameObject.Find("Heroes").transform;

        safe = false;

        status = "Fine";

        maxNumberOfTargets = 1;
        focusIndex         = 0;

        clericHealCooldown = 90;
        battlecryCooldown  = 360;
        stealthCooldown    = 360;

        transform.position = new Vector3(mousePosition.x, mousePosition.y + 60f, -20f);

        lv = Tavern.Instance().level - 1;
        LevelUp();

        firstName = firstNames[intJob, Random.Range(0, firstNames.GetLength(1))];
        lastName  = lastNames[intJob, Random.Range(0, lastNames.GetLength(1))];

        GameObject obj;

        obj = Instantiate(Resources.Load("CI", typeof(GameObject)) as GameObject) as GameObject;
        obj.transform.parent        = transform;
        obj.transform.localPosition = Vector3.zero;

        TextMesh textMesh;

        textMesh      = obj.transform.Find("Name").GetComponent <TextMesh>();
        textMesh.text = firstName + " " + lastName;

        healthBar      = obj.transform.Find("Health/Bar").gameObject;
        healthBarWidth = healthBar.transform.localScale.x;

        gameplay.heroes.Add(this);
        index = gameplay.heroes.IndexOf(this);

        name = name.Split("("[0])[0];
    }
Exemplo n.º 3
0
    public static XMLNode Parse(string content)
    {
        // Set up variables
        bool   inMetaTag             = false;
        bool   inComment             = false;
        bool   inCDATA               = false;
        bool   inElement             = false;
        bool   collectNodeName       = false;
        bool   collectAttributeName  = false;
        bool   collectAttributeValue = false;
        bool   quoted    = false;
        string attName   = "";
        string attValue  = "";
        string nodeName  = "";
        string textValue = "";
        //string nodeContents = "";

        XMLNodeList parents = new XMLNodeList();

        XMLNode rootNode = new XMLNode();

        rootNode["_text"] = "";

        XMLNode currentNode = rootNode;

        // Process Input
        for (int i = 0; i < content.Length; i++)
        {
            // Store current and nearby characters
            char c, cn, cnn, cp;
            cn = cnn = cp = '\x00';
            c  = content[i];
            if ((i + 1) < content.Length)
            {
                cn = content[i + 1];
            }
            if ((i + 2) < content.Length)
            {
                cnn = content[i + 2];
            }
            if (i > 0)
            {
                cp = content[i - 1];
            }


            // Process Meta Tag information
            if (inMetaTag)
            {
                if (c == QMARK && cn == GT) // End of Meta Tag
                {
                    inMetaTag = false;
                    i++;
                }
                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == QMARK) // Start of Meta Tag
                {
                    inMetaTag = true;
                    continue;
                }
            }


            // Process Comment information
            if (inComment)
            {
                if (cp == DASH && c == DASH && cn == GT) // End of comment
                {
                    inComment = false;
                    i++;
                }
                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == EXCLAMATION) // Start of comment or CDATA
                {
                    if (content.Length > (i + 9) && content.Substring(i, 9) == "<![CDATA[")
                    {
                        inCDATA = true;
                        i      += 8;
                    }
                    else
                    {
                        inComment = true;
                    }
                    continue;
                }
            }


            // Process CDATA information
            if (inCDATA)
            {
                if (c == SQR && cn == SQR && cnn == GT)
                {
                    inCDATA = false;
                    i      += 2;
                    continue;
                }
                textValue += c;
                continue;
            }


            // Process Elements
            if (inElement)
            {
                if (collectNodeName)
                {
                    if (c == SPACE)
                    {
                        collectNodeName = false;
                    }
                    else if (c == GT)
                    {
                        collectNodeName = false;
                        inElement       = false;
                    }


                    if (!collectNodeName && nodeName.Length > 0)
                    {
                        if (nodeName[0] == SLASH)
                        {
                            // close tag
                            if (textValue.Length > 0)
                            {
                                currentNode["_text"] += textValue;
                            }

                            textValue   = "";
                            nodeName    = "";
                            currentNode = parents.Pop();
                        }
                        else
                        {
                            if (textValue.Length > 0)
                            {
                                currentNode["_text"] += textValue;
                            }
                            textValue = "";
                            XMLNode newNode = new XMLNode();
                            newNode["_text"] = "";
                            newNode["_name"] = nodeName;

                            if (!currentNode.ContainsKey(nodeName))
                            {
                                currentNode[nodeName] = new XMLNodeList();
                            }
                            XMLNodeList a = currentNode[nodeName] as XMLNodeList;
                            a.Push(newNode);
                            parents.Push(currentNode);
                            currentNode = newNode;
                            nodeName    = "";
                        }
                    }
                    else
                    {
                        nodeName += c;
                    }
                }
                else
                {
                    if (!quoted && c == SLASH && cn == GT)
                    {
                        inElement             = false;
                        collectAttributeName  = false;
                        collectAttributeValue = false;
                        if (attName != "")
                        {
                            if (attValue != "")
                            {
                                currentNode["@" + attName] = attValue;
                            }
                            else
                            {
                                currentNode["@" + attName] = true;
                            }
                        }

                        i++;
                        currentNode = parents.Pop();
                        attName     = "";
                        attValue    = "";
                    }
                    else if (!quoted && c == GT)
                    {
                        inElement             = false;
                        collectAttributeName  = false;
                        collectAttributeValue = false;
                        if (attName != "")
                        {
                            currentNode["@" + attName] = attValue;
                        }

                        attName  = "";
                        attValue = "";
                    }
                    else
                    {
                        if (collectAttributeName)
                        {
                            if (c == SPACE || c == EQUALS)
                            {
                                collectAttributeName  = false;
                                collectAttributeValue = true;
                            }
                            else
                            {
                                attName += c;
                            }
                        }
                        else if (collectAttributeValue)
                        {
                            if (c == QUOTE)
                            {
                                if (quoted)
                                {
                                    collectAttributeValue      = false;
                                    currentNode["@" + attName] = attValue;
                                    attValue = "";
                                    attName  = "";
                                    quoted   = false;
                                }
                                else
                                {
                                    quoted = true;
                                }
                            }
                            else
                            {
                                if (quoted)
                                {
                                    attValue += c;
                                }
                                else
                                {
                                    if (c == SPACE)
                                    {
                                        collectAttributeValue      = false;
                                        currentNode["@" + attName] = attValue;
                                        attValue = "";
                                        attName  = "";
                                    }
                                }
                            }
                        }
                        else if (c == SPACE)
                        {
                        }
                        else
                        {
                            collectAttributeName = true;
                            attName  = "" + c;
                            attValue = "";
                            quoted   = false;
                        }
                    }
                }
            }
            else
            {
                if (c == LT) // Start of new element
                {
                    inElement       = true;
                    collectNodeName = true;
                }
                else
                {
                    textValue += c; // text between elements
                }
            }
        }

        return(rootNode);
    }
Exemplo n.º 4
0
    public XMLNode Parse(string content)
    {
        XMLNode rootNode = new XMLNode();

        rootNode["_text"] = "";

        string nodeContents = "";

        bool   inElement             = false;
        bool   collectNodeName       = false;
        bool   collectAttributeName  = false;
        bool   collectAttributeValue = false;
        bool   quoted    = false;
        string attName   = "";
        string attValue  = "";
        string nodeName  = "";
        string textValue = "";

        bool inMetaTag = false;
        bool inComment = false;
        bool inCDATA   = false;

        XMLNodeList parents = new XMLNodeList();

        XMLNode currentNode = rootNode;

        for (int i = 0; i < content.Length; i++)
        {
            char c   = content[i];
            char cn  = '~';             // unused char
            char cnn = '~';             // unused char
            char cp  = '~';             // unused char

            if ((i + 1) < content.Length)
            {
                cn = content[i + 1];
            }
            if ((i + 2) < content.Length)
            {
                cnn = content[i + 2];
            }
            if (i > 0)
            {
                cp = content[i - 1];
            }

            if (inMetaTag)
            {
                if (c == QMARK && cn == GT)
                {
                    inMetaTag = false;
                    i++;
                }

                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == QMARK)
                {
                    inMetaTag = true;
                    continue;
                }
            }

            if (inComment)
            {
                if (cp == DASH && c == DASH && cn == GT)
                {
                    inComment = false;
                    i++;
                }

                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == EXCLAMATION)
                {
                    if (content.Length > i + 9 && content.Substring(i, 9) == "<![CDATA[")
                    {
                        inCDATA = true;
                        i      += 8;
                    }
                    else
                    {
                        inComment = true;
                    }

                    continue;
                }
            }

            if (inCDATA)
            {
                if (c == SQR && cn == SQR && cnn == GT)
                {
                    inCDATA = false;
                    i      += 2;
                    continue;
                }

                textValue += c;
                continue;
            }


            if (inElement)
            {
                if (collectNodeName)
                {
                    if (c == SPACE)
                    {
                        collectNodeName = false;
                    }
                    else if (c == GT)
                    {
                        collectNodeName = false;
                        inElement       = false;
                    }



                    if (!collectNodeName && nodeName.Length > 0)
                    {
                        if (nodeName[0] == SLASH)
                        {
                            // close tag
                            if (textValue.Length > 0)
                            {
                                currentNode["_text"] += textValue;
                            }

                            textValue   = "";
                            nodeName    = "";
                            currentNode = parents.Pop();
                        }
                        else
                        {
                            if (textValue.Length > 0)
                            {
                                currentNode["_text"] += textValue;
                            }

                            textValue = "";
                            XMLNode newNode = new XMLNode();
                            newNode["_text"] = "";
                            newNode["_name"] = nodeName;

                            if (currentNode[nodeName] == null)
                            {
                                currentNode[nodeName] = new XMLNodeList();
                            }

                            XMLNodeList a = (XMLNodeList)currentNode[nodeName];
                            a.Push(newNode);
                            parents.Push(currentNode);
                            currentNode = newNode;
                            nodeName    = "";
                        }
                    }
                    else
                    {
                        nodeName += c;
                    }
                }
                else
                {
                    if (!quoted && c == SLASH && cn == GT)
                    {
                        inElement             = false;
                        collectAttributeName  = false;
                        collectAttributeValue = false;
                        if (attName.Length > 0)
                        {
                            if (attValue.Length > 0)
                            {
                                currentNode["@" + attName] = attValue;
                            }
                            else
                            {
                                currentNode["@" + attName] = true;
                            }
                        }

                        i++;
                        currentNode = parents.Pop();
                        attName     = "";
                        attValue    = "";
                    }
                    else if (!quoted && c == GT)
                    {
                        inElement             = false;
                        collectAttributeName  = false;
                        collectAttributeValue = false;
                        if (attName.Length > 0)
                        {
                            currentNode["@" + attName] = attValue;
                        }

                        attName  = "";
                        attValue = "";
                    }
                    else
                    {
                        if (collectAttributeName)
                        {
                            if (c == SPACE || c == EQUALS)
                            {
                                collectAttributeName  = false;
                                collectAttributeValue = true;
                            }
                            else
                            {
                                attName += c;
                            }
                        }
                        else if (collectAttributeValue)
                        {
                            if (c == QUOTE || c == QUOTE2)
                            {
                                if (quoted)
                                {
                                    collectAttributeValue      = false;
                                    currentNode["@" + attName] = attValue;
                                    attValue = "";
                                    attName  = "";
                                    quoted   = false;
                                }
                                else
                                {
                                    quoted = true;
                                }
                            }
                            else
                            {
                                if (quoted)
                                {
                                    attValue += c;
                                }
                                else
                                {
                                    if (c == SPACE)
                                    {
                                        collectAttributeValue      = false;
                                        currentNode["@" + attName] = attValue;
                                        attValue = "";
                                        attName  = "";
                                    }
                                }
                            }
                        }
                        else if (c == SPACE)
                        {
                        }
                        else
                        {
                            collectAttributeName = true;
                            attName  = "" + c;
                            attValue = "";
                            quoted   = false;
                        }
                    }
                }
            }
            else
            {
                if (c == LT)
                {
                    inElement       = true;
                    collectNodeName = true;
                }
                else
                {
                    textValue += c;
                }
            }
        }

        return(rootNode);
    }
Exemplo n.º 5
0
        public object Parse(string content)
        {

            XMLNode rootNode = new XMLNode();
            rootNode["_text"] = "";

            //string nodeContents = "";

            bool inElement = false;
            bool collectNodeName = false;
            bool collectAttributeName = false;
            bool collectAttributeValue = false;
            bool quoted = false;
            string attName = "";
            string attValue = "";
            string nodeName = "";
            string textValue = "";

            bool inMetaTag = false;
            bool inComment = false;
            bool inCDATA = false;

            XMLNodeList parents = new XMLNodeList();

            XMLNode currentNode = rootNode;
            for (int i = 0; i < content.Length; i++)
            {

                char c = content[i];
                char cn = 'x';
                char cnn = 'x';
                char cp = 'x';
                if ((i + 1) < content.Length) cn = content[i + 1];
                if ((i + 2) < content.Length) cnn = content[i + 2];
                if (i > 0) cp = content[i - 1];

                if (inMetaTag)
                {
                    if (c == QMARK && cn == GT)
                    {
                        inMetaTag = false;
                        i++;
                    }
                    continue;
                }
                else
                {
                    if (!quoted && c == LT && cn == QMARK)
                    {
                        inMetaTag = true;
                        continue;
                    }
                }

                if (inComment)
                {
                    if (cp == DASH && c == DASH && cn == GT)
                    {
                        inComment = false;
                        i++;
                    }
                    continue;
                }
                else
                {
                    if (!quoted && c == LT && cn == EXCLAMATION)
                    {

                        if (content.Length > i + 9 && content.Substring(i, 9) == "<![CDATA[")
                        {
                            inCDATA = true;
                            i += 8;
                        }
                        else
                        {
                            inComment = true;
                        }
                        continue;
                    }
                }

                if (inCDATA)
                {
                    if (c == SQR && cn == SQR && cnn == GT)
                    {
                        inCDATA = false;
                        i += 2;
                        continue;
                    }
                    textValue += c;
                    continue;
                }


                if (inElement)
                {
                    if (collectNodeName)
                    {
                        if (c == SPACE)
                        {
                            collectNodeName = false;
                        }
                        else if (c == GT)
                        {
                            collectNodeName = false;
                            inElement = false;
                        }



                        if (!collectNodeName && nodeName.Length > 0)
                        {
                            if (nodeName[0] == SLASH)
                            {
                                // close tag
                                if (textValue.Length > 0)
                                {
                                    currentNode["_text"] += textValue;
                                }

                                textValue = "";
                                nodeName = "";
                                currentNode = (XMLNode)parents[(int)(parents.Count - 1)];
                                parents.RemoveAt((parents.Count-1));
                            }
                            else
                            {

                                if (textValue.Length > 0)
                                {
                                    currentNode["_text"] += textValue;
                                }
                                textValue = "";
                                XMLNode newNode = new XMLNode();
                                newNode["_text"] = "";
                                newNode["_name"] = nodeName;

                                if (currentNode[nodeName]==null)
                                {
                                    currentNode[nodeName] = new XMLNodeList();
                                }
                                ArrayList a = (ArrayList)currentNode[nodeName];
                                a.Add(newNode);
                                parents.Add(currentNode);
                                currentNode = newNode;
                                nodeName = "";
                            }
                        }
                        else
                        {
                            nodeName += c;
                        }
                    }
                    else
                    {

                        if (!quoted && c == SLASH && cn == GT)
                        {
                            inElement = false;
                            collectAttributeName = false;
                            collectAttributeValue = false;
                            if (attName!=null)
                            {
                                if (attValue!=null)
                                {
                                    currentNode["@" + attName] = attValue;
                                }
                                else
                                {
                                    currentNode["@" + attName] = true;
                                }
                            }

                            i++;
                            currentNode = (XMLNode)parents[(int)(parents.Count - 1)];
                            parents.RemoveAt((parents.Count - 1));
                            attName = "";
                            attValue = "";
                        }
                        else if (!quoted && c == GT)
                        {
                            inElement = false;
                            collectAttributeName = false;
                            collectAttributeValue = false;
                            if (attName!=null)
                            {
                                currentNode["@" + attName] = attValue;
                            }

                            attName = "";
                            attValue = "";
                        }
                        else
                        {
                            if (collectAttributeName)
                            {
                                if (c == SPACE || c == EQUALS)
                                {
                                    collectAttributeName = false;
                                    collectAttributeValue = true;
                                }
                                else
                                {
                                    attName += c;
                                }
                            }
                            else if (collectAttributeValue)
                            {
                                if (c == QUOTE)
                                {
                                    if (quoted)
                                    {
                                        collectAttributeValue = false;
                                        currentNode["@" + attName] = attValue;
                                        attValue = "";
                                        attName = "";
                                        quoted = false;
                                    }
                                    else
                                    {
                                        quoted = true;
                                    }
                                }
                                else
                                {
                                    if (quoted)
                                    {
                                        attValue += c;
                                    }
                                    else
                                    {
                                        if (c == SPACE)
                                        {
                                            collectAttributeValue = false;
                                            currentNode["@" + attName] = attValue;
                                            attValue = "";
                                            attName = "";
                                        }
                                    }
                                }
                            }
                            else if (c == SPACE)
                            {

                            }
                            else
                            {
                                collectAttributeName = true;
                                attName = "" + c;
                                attValue = "";
                                quoted = false;
                            }
                        }
                    }
                }
                else
                {
                    if (c == LT)
                    {
                        inElement = true;
                        collectNodeName = true;
                    }
                    else
                    {
                        textValue += c;
                    }

                }

            }

            return rootNode;
        }
Exemplo n.º 6
0
 private object GetObject(string path)
 {
     string[] bits = path.Split(">"[0]);
     XMLNode currentNode=this;
     XMLNodeList currentNodeList = new XMLNodeList();
     bool listMode=false;
     object ob;
     for(int i=0;i<bits.Length;i++)
     {
         string segment = bits[i];
         if(listMode)
         {
             ob=currentNode= currentNodeList[int.Parse(segment)] as XMLNode;
             listMode=false;
         }
         else
         {
             if(currentNode.Children_.ContainsKey(segment)) {
                 ob=currentNode.Children_[segment];
                 currentNodeList=ob as XMLNodeList;
                 listMode=true;
             }
             else
             {
                 if(currentNode.Attributes_.ContainsKey(segment))
                 {
                     ob = currentNode.Attributes_[segment];
                 }
                 else
                 {
                     ob = currentNode.Text;
                 }
                 // reached a leaf node/attribute
                 if(i!=(bits.Length-1))
                 {
                     // unexpected leaf node
                     string actualPath="";
                     for(int j=0;j<=i;j++)
                     {
                         actualPath=actualPath+">"+bits[j];
                     }
                 }
                 return ob;
             }
         }
     }
     if(listMode) return currentNodeList;
     else return currentNode;
 }
Exemplo n.º 7
0
        public XMLNode Parse( string content )
        {
            XMLNode rootNode = new XMLNode();
            //rootNode["_text"]="";

            bool inElement=false;
            bool collectNodeName=false;
            bool collectAttributeName=false;
            bool collectAttributeValue=false;
            bool quoted=false;
            string attName="";
            string attValue="";
            string nodeName="";
            string textValue="";

            bool inMetaTag=false;
            bool inComment=false;
            bool inDoctype=false;
            bool inCDATA=false;

            XMLNodeList parents=new XMLNodeList();

            XMLNode currentNode=rootNode;
            for(var i=0;i<content.Length;i++)
            {
            char c=content[i];
            char cn='\0';
            char cnn='\0';
            char cp='\0';
            if((i+1)<content.Length) cn=content[i+1];
            if((i+2)<content.Length) cnn=content[i+2];
            if(i>0)cp=content[i-1];

            if(inMetaTag)
            {
                if(c==QMARK && cn==GT)
                {
                    inMetaTag=false;
                    i++;
                }
                continue;
            }
            else
            {
                if(!quoted && c==LT && cn==QMARK)
                {
                    inMetaTag=true;
                    continue;
                }
            }

            if(inDoctype)
            {
                if(cn==GT)
                {
                    inDoctype=false;
                    i++;
                }
                continue;
            }
            else if(inComment)
            {
                if(cp==DASH && c==DASH && cn==GT)
                {
                    inComment=false;
                    i++;
                }
                continue;
            }
            else
            {
                if(!quoted && c==LT && cn==EXCLAMATION)
                {
                    if(content.Length>i+9 && content.Substring(i,9)=="<![CDATA[")
                    {
                        inCDATA=true;
                        i+=8;
                    }
                    else if(content.Length > i+9 && content.Substring(i,9)=="<!DOCTYPE")
                    {
                        inDoctype=true;
                        i+=8;
                    }
                    else if(content.Length > i+2 && content.Substring(i,4)=="<!--")
                    {
                        inComment=true;
                        i+=3;
                    }
                    continue;
                }
            }

            if(inCDATA)
            {
                if(c==SQR && cn==SQR && cnn==GT)
                {
                    inCDATA=false;
                    i+=2;
                    continue;
                }
                textValue+=c;
                continue;
            }

            if(inElement)
            {
                // Retrieving <NODE> name
                if(collectNodeName)
                {
                    if(c==SPACE)
                    {
                        collectNodeName=false;
                    }
                    else if(c==GT)
                    {
                        collectNodeName=false;
                        inElement=false;
                    }
                    else if(c==SLASH && cn==GT)
                    {
                        collectNodeName=false;
                        i--;
                    }

                    if(!collectNodeName && nodeName.Length>0)
                    {
                        if(nodeName[0]==SLASH)
                        {
                            // close tag
                            if(textValue.Length>0)
                            {
                                //currentNode["_text"]+=textValue;
                                currentNode.Text += textValue;
                            }

                            textValue="";
                            nodeName="";
                            currentNode=parents[parents.Count-1];
                            parents.RemoveAt(parents.Count-1);
                        }
                        else
                        {
                            if(textValue.Length>0)
                            {
                                //currentNode["_text"]+=textValue;
                                currentNode.Text += textValue;
                            }
                            textValue="";
                            XMLNode newNode=new XMLNode();
                            newNode.Text ="";
                            newNode.Name=nodeName;

                            if(!currentNode.Children_.ContainsKey(nodeName))
                            {
                                currentNode.Children_.Add(nodeName, new XMLNodeList());
                            }
                            XMLNodeList a = currentNode.Children_[nodeName];
                            a.Add(newNode);
                            parents.Add(currentNode);
                            currentNode=newNode;
                            nodeName="";
                        }
                    }
                    else
                    {
                        nodeName+=c;
                    }
                }
                else
                {

                    // 1. Checking for self closing node />
                    // while not in a quote
                    if(!quoted && c==SLASH && cn==GT)
                    {
                        inElement=false;
                        collectAttributeName=false;
                        collectAttributeValue=false;
                        if(attName!=null && attName!="")
                        {
                            if(attValue!=null && attValue!="")
                            {
                                currentNode.Attributes_[attName] = attValue;
                            }
                            else
                            {
                                currentNode.Attributes_[attName]="true";
                            }
                        }

                        i++;
                        currentNode = parents[parents.Count-1];
                        parents.RemoveAt(parents.Count-1);
                        attName="";
                        attValue="";
                    }

                    // 2. Check for Closing a node >
                    else if(!quoted && c==GT)
                    {
                        inElement=false;
                        collectAttributeName=false;
                        collectAttributeValue=false;
                        if(attName!=null && attName!="")
                        {
                            currentNode.Attributes_[attName]=attValue;
                        }

                        attName="";
                        attValue="";
                    }

                    // 3. Otherwise grab the attribute OR the attribValue
                    else
                    {
                        // 3.a. Add to the attribute name
                        if(collectAttributeName)
                        {
                            if(c==SPACE || c==EQUALS)
                            {
                                collectAttributeName=false;
                                collectAttributeValue=true;
                            }
                            else
                            {
                                attName+=c;
                            }
                        }
                        // 3.b. Or add to the attribute value
                        //      if we're in AttributeValue mode
                        else if(collectAttributeValue)
                        {
                            // Begin or end quoting
                            if(c==QUOTE)
                            {
                                // End quoting if already in quote mode
                                if(quoted)
                                {
                                    collectAttributeValue=false;
                                    currentNode.Attributes_[attName]=attValue;
                                    attValue="";
                                    attName="";
                                    quoted=false;
                                }
                                // Otherwise ENTER quoting mode
                                else quoted=true;
                            }

                            // For everything else
                            else
                            {
                                // Add to value if we're in quote mode
                                if(quoted) attValue+=c;

                                // Otherwise if we're not in quote mode
                                else
                                {
                                    // And the character is a space, reset
                                    // the attribute register
                                    if(c==SPACE)
                                    {
                                        collectAttributeValue=false;
                                        //currentNode[ATTRIB_APPEND+attName]=attValue;
                                        currentNode.Attributes_[attName]=attValue;
                                        attValue="";
                                        attName="";
                                    }
                                }
                            }
                        }

                        // 3.c. If it's a space, do NOTHING
                        else if(c==SPACE){}

                        // 3.d. For anything else, switch to Grab Attribute mode
                        else
                        {
                            collectAttributeName=true;
                            attName=""+c;
                            attValue="";
                            quoted=false;
                        }
                    }
                }
            }
            else
            {
                if(c==LT)
                {
                    inElement=true;
                    collectNodeName=true;
                }
                else
                {
                    // this is where we can check for the 5 xml entities
                    // TODO: add support for unicode/decimal versions of entities.
                    if(c==AMP)
                    {
                        if(content.Length>i+5 && content.Substring(i,5)=="&amp;")
                        {
                            textValue+='&';
                            i+=4;
                        }
                        else if(content.Length>i+6 && content.Substring(i,6)=="&quot;")
                        {
                            textValue+='"';
                            i+=5;
                        }
                        else if(content.Length>i+6 && content.Substring(i,6)=="&apos;")
                        {
                            textValue+='\'';
                            i+=5;
                        }
                        else if(content.Length>i+4 && content.Substring(i,4)=="&lt;")
                        {
                            textValue+='<';
                            i+=3;
                        }
                        else if(content.Length>i+4 && content.Substring(i,4)=="&gt;")
                        {
                            textValue+='>';
                            i+=3;
                        }
                    }
                    else
                    {
                        textValue+=c;
                    }
                }

            }
            }

            return rootNode;
        }
Exemplo n.º 8
0
    public XMLNode Parse(string content)
    {
        XMLNode xMLNode = new XMLNode();

        xMLNode["_text"] = new StringBuilder();
        bool          flag           = false;
        bool          flag2          = false;
        bool          flag3          = false;
        bool          flag4          = false;
        bool          flag5          = false;
        StringBuilder stringBuilder  = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        StringBuilder stringBuilder3 = new StringBuilder();
        StringBuilder stringBuilder4 = new StringBuilder();
        bool          flag6          = false;
        bool          flag7          = false;
        bool          flag8          = false;
        XMLNodeList   xMLNodeList    = new XMLNodeList();
        XMLNode       xMLNode2       = xMLNode;

        for (int i = 0; i < content.Length; i++)
        {
            char c  = content[i];
            char c2 = '~';
            char c3 = '~';
            char c4 = '~';
            if (i + 1 < content.Length)
            {
                c2 = content[i + 1];
            }
            if (i + 2 < content.Length)
            {
                c3 = content[i + 2];
            }
            if (i > 0)
            {
                c4 = content[i - 1];
            }
            if (flag6)
            {
                if (c == this.QMARK && c2 == this.GT)
                {
                    flag6 = false;
                    i++;
                }
            }
            else if (!flag5 && c == this.LT && c2 == this.QMARK)
            {
                flag6 = true;
            }
            else if (flag7)
            {
                if (c4 == this.DASH && c == this.DASH && c2 == this.GT)
                {
                    flag7 = false;
                    i++;
                }
            }
            else if (!flag5 && c == this.LT && c2 == this.EXCLAMATION)
            {
                if (content.Length > i + 9 && content.Substring(i, 9) == "<![CDATA[")
                {
                    flag8 = true;
                    i    += 8;
                }
                else
                {
                    flag7 = true;
                }
            }
            else if (flag8)
            {
                if (c == this.SQR && c2 == this.SQR && c3 == this.GT)
                {
                    flag8 = false;
                    i    += 2;
                }
                else
                {
                    stringBuilder4.Append(c);
                }
            }
            else if (flag)
            {
                if (flag2)
                {
                    if (c == this.SPACE)
                    {
                        flag2 = false;
                    }
                    else if (c == this.GT)
                    {
                        flag2 = false;
                        flag  = false;
                    }
                    if (!flag2 && stringBuilder.Length > 0)
                    {
                        if (stringBuilder[0] == this.SLASH)
                        {
                            if (stringBuilder4.Length > 0)
                            {
                            }
                            stringBuilder4.Remove(0, stringBuilder4.Length);
                            stringBuilder.Remove(0, stringBuilder.Length);
                            xMLNode2 = xMLNodeList.Pop();
                        }
                        else
                        {
                            if (stringBuilder4.Length > 0)
                            {
                            }
                            stringBuilder4.Remove(0, stringBuilder4.Length);
                            string  text     = stringBuilder.ToString();
                            XMLNode xMLNode3 = new XMLNode();
                            xMLNode3["_text"] = new StringBuilder();
                            xMLNode3["_name"] = text;
                            if (xMLNode2[text] == null)
                            {
                                xMLNode2[text] = new XMLNodeList();
                            }
                            XMLNodeList xMLNodeList2 = (XMLNodeList)xMLNode2[text];
                            xMLNodeList2.Push(xMLNode3);
                            xMLNodeList.Push(xMLNode2);
                            xMLNode2 = xMLNode3;
                            stringBuilder.Remove(0, stringBuilder.Length);
                        }
                    }
                    else
                    {
                        stringBuilder.Append(c);
                    }
                }
                else if (!flag5 && c == this.SLASH && c2 == this.GT)
                {
                    flag  = false;
                    flag3 = false;
                    flag4 = false;
                    if (stringBuilder2.Length > 0)
                    {
                        if (stringBuilder3.Length > 0)
                        {
                            xMLNode2[stringBuilder2.Insert(0, '@').ToString()] = stringBuilder3.ToString();
                        }
                        else
                        {
                            xMLNode2[stringBuilder2.Insert(0, '@').ToString()] = true;
                        }
                    }
                    i++;
                    xMLNode2 = xMLNodeList.Pop();
                    stringBuilder2.Remove(0, stringBuilder2.Length);
                    stringBuilder3.Remove(0, stringBuilder3.Length);
                }
                else if (!flag5 && c == this.GT)
                {
                    flag  = false;
                    flag3 = false;
                    flag4 = false;
                    if (stringBuilder2.Length > 0)
                    {
                        xMLNode2[stringBuilder2.Insert(0, '@').ToString()] = stringBuilder3.ToString();
                    }
                    stringBuilder2.Remove(0, stringBuilder2.Length);
                    stringBuilder3.Remove(0, stringBuilder3.Length);
                }
                else if (flag3)
                {
                    if (c == this.SPACE || c == this.EQUALS)
                    {
                        flag3 = false;
                        flag4 = true;
                    }
                    else
                    {
                        stringBuilder2.Append(c);
                    }
                }
                else if (flag4)
                {
                    if (c == this.QUOTE || c == this.QUOTE2)
                    {
                        if (flag5)
                        {
                            flag4 = false;
                            xMLNode2[stringBuilder2.Insert(0, '@').ToString()] = stringBuilder3.ToString();
                            stringBuilder2.Remove(0, stringBuilder2.Length);
                            stringBuilder3.Remove(0, stringBuilder3.Length);
                            flag5 = false;
                        }
                        else
                        {
                            flag5 = true;
                        }
                    }
                    else if (flag5)
                    {
                        stringBuilder3.Append(c);
                    }
                    else if (c == this.SPACE)
                    {
                        flag4 = false;
                        xMLNode2[stringBuilder2.Insert(0, '@').ToString()] = stringBuilder3.ToString();
                        stringBuilder2.Remove(0, stringBuilder2.Length);
                        stringBuilder3.Remove(0, stringBuilder3.Length);
                    }
                }
                else if (c != this.SPACE)
                {
                    flag3 = true;
                    stringBuilder2.Remove(0, stringBuilder2.Length).Append(c);
                    stringBuilder3.Remove(0, stringBuilder3.Length);
                    flag5 = false;
                }
            }
            else if (c == this.LT)
            {
                flag  = true;
                flag2 = true;
            }
            else
            {
                stringBuilder4.Append(c);
            }
        }
        return(xMLNode);
    }
Exemplo n.º 9
0
    void Start()
    {
        //array = new string[999];
        XMLParser parser = new XMLParser();
        XMLNode   tmp    = parser.Parse(XMLScript.ToString());

        ratio = img.rectTransform.rect.width / img.rectTransform.rect.height;
        //	Debug.Log (XMLScript.ToString());
        //	Debug.Log (tmp.Count);

        /*ip.img.sprite = spriteArray [4];
         * int height = spriteArray [4].texture.height;
         * int width = spriteArray [4].texture.width;
         * Debug.Log (spriteArray [4].name);
         * Debug.Log (spriteArray [4].texture.height);
         * Debug.Log (spriteArray [4].texture.width);
         * //this is width /   height
         * float ratio = 180.0f / 120.0f;
         * float otherratio = (float)width / (float)height;
         * Debug.Log ("Ratio: " + ratio);
         * Debug.Log ("other ratio: " + otherratio);
         * if (otherratio > ratio)
         * {
         *      Debug.Log (otherratio / ratio);
         *      ip.img.transform.localScale = new Vector3 (1, 1 / (otherratio / ratio), 1);
         * }*/
        /*	if(width > 180)
         *      {
         *              //if the width is the one that excceds
         *              //we resize the width so that it remains in 180 range
         *              int dif = width - 180;
         *              //now we need to translate this diff for the height as well
         *              //we get the ratio of how much height to move per width unit
         *              int newHeight = height -(int)( (float)height/(float)width * (float)dif);
         *              spriteArray[0].texture.Resize(180,newHeight);
         *      }*/
        //ip.img.transform.localScale = new Vector3 (1, 1, 1);

        /*
         * //EXAMPLE  ON HOW TO GET A SINGLE VAL
         * string val = tmp.GetValue ("Test1>0>Info>0>Title>0>_text");
         * Debug.Log (val);
         * val = tmp.GetValue ("Test1>0>Info>1>Title>0>_text");
         * Debug.Log (val);
         *
         * //THIS GETS THE ARRAY OF INFO , WHICH MEANS HOW MANY PANELS
         * //I NEED TO MAKE
         * XMLNodeList arr =tmp.GetNodeList("Test1>0>Info");
         * Debug.Log (arr.Count);
         */
        XMLNodeList arr = tmp.GetNodeList("Test1>0>Info");
        Vector3     pos = toDup.transform.position;

        for (int i = 0; i < arr.Count; ++i)
        {
            //i need to change the way the image is positioned
            GameObject newobj = (GameObject)Instantiate(toDup, pos, Quaternion.identity);
            newobj.transform.parent     = this.transform;
            newobj.transform.localScale = new Vector3(1, 1, 1);
            pos    = toDup.transform.localPosition;
            pos.x += 300 * i;
            newobj.transform.localPosition = pos;
            //InfoPanel nIP = newobj.GetComponent<InfoPanel>();
            //GrabAllData (tmp, i,nIP);
        }
        toDup.SetActive(false);
    }
Exemplo n.º 10
0
    private void ConnectXML()
    {
        string resourcePath = fileRoot + xmlFile;

        XMLNode     xml     = XMLParser.Parse((Resources.Load(resourcePath, typeof(TextAsset)) as TextAsset).text);
        XMLNodeList xmlList = xml.GetNodeList(xmlRoot);

        XMLNode xmlSubNode = xmlList[PRODUCTS] as XMLNode;

        XMLNodeList productsXML = xmlSubNode.GetNodeList("products>0>product");

        for (int j = 0; j < productsXML.Count; j++)
        {
            XMLNode productXML = productsXML[j] as XMLNode;
            Product product    = new Product();

            product.name        = productXML.GetValue("@name");
            product.tag         = productXML.GetValue("@tag");
            product.cost        = float.Parse(productXML.GetValue("@cost"));
            product.price       = float.Parse(productXML.GetValue("@retail"));
            product.upgradeCost = float.Parse(productXML.GetValue("@upgrade"));
            product.time        = float.Parse(productXML.GetValue("@time"));
            product.viability   = int.Parse(productXML.GetValue("@viability"));
            product.customers   = int.Parse(productXML.GetValue("@customers"));

            products.Add(product);
        }

        // Debug.Log(products);
        xmlSubNode = xmlList[ENTERTAINMENTS] as XMLNode;
        XMLNodeList entertainmentXML = xmlSubNode.GetNodeList("entertainments>0>entertainment");

        for (int j = 0; j < entertainmentXML.Count; j++)
        {
            XMLNode       entertainmentsXML = entertainmentXML[j] as XMLNode;
            Entertainment entertainment     = new Entertainment();

            entertainment.name        = entertainmentsXML.GetValue("@name");
            entertainment.tag         = entertainmentsXML.GetValue("@tag");
            entertainment.cost        = float.Parse(entertainmentsXML.GetValue("@cost"));
            entertainment.price       = float.Parse(entertainmentsXML.GetValue("@retail"));
            entertainment.upgradeCost = float.Parse(entertainmentsXML.GetValue("@upgrade"));
            entertainment.time        = float.Parse(entertainmentsXML.GetValue("@time"));
            entertainment.viability   = int.Parse(entertainmentsXML.GetValue("@viability"));
            entertainment.buyers      = int.Parse(entertainmentsXML.GetValue("@buyers"));
            entertainment.advertisers = int.Parse(entertainmentsXML.GetValue("@advertisers"));
            // entertainment.priceable = entertainmentsXML.GetValue("@priceable");

            entertainments.Add(entertainment);
        }

        xmlSubNode = xmlList[SOFTWARES] as XMLNode;
        XMLNodeList softwareXML = xmlSubNode.GetNodeList("softwares>0>software");

        for (int j = 0; j < softwareXML.Count; j++)
        {
            XMLNode  softwaresXML = softwareXML[j] as XMLNode;
            Software software     = new Software();

            software.name        = softwaresXML.GetValue("@name");
            software.tag         = softwaresXML.GetValue("@tag");
            software.cost        = float.Parse(softwaresXML.GetValue("@cost"));
            software.price       = float.Parse(softwaresXML.GetValue("@retail"));
            software.upgradeCost = float.Parse(softwaresXML.GetValue("@upgrade"));
            software.time        = float.Parse(softwaresXML.GetValue("@time"));
            software.viability   = int.Parse(softwaresXML.GetValue("@viability"));
            software.buyers      = int.Parse(softwaresXML.GetValue("@buyers"));
            // software.priceable = softwaresXML.GetValue("@priceable");

            softwares.Add(software);
        }

        xmlSubNode = xmlList[SERVICES] as XMLNode;
        XMLNodeList servicesXML = xmlSubNode.GetNodeList("services>0>service");

        for (int j = 0; j < servicesXML.Count; j++)
        {
            XMLNode serviceXML = servicesXML[j] as XMLNode;
            Service service    = new Service();

            service.name        = serviceXML.GetValue("@name");
            service.tag         = serviceXML.GetValue("@tag");
            service.cost        = float.Parse(serviceXML.GetValue("@cost"));
            service.price       = float.Parse(serviceXML.GetValue("@retail"));
            service.upgradeCost = float.Parse(serviceXML.GetValue("@upgrade"));
            service.time        = float.Parse(serviceXML.GetValue("@time"));
            service.viability   = int.Parse(serviceXML.GetValue("@viability"));
            service.buyers      = int.Parse(serviceXML.GetValue("@customers"));
            // service.priceable = serviceXML.GetValue("@priceable");
            service.profitMethod = serviceXML.GetValue("@profitMethod");

            services.Add(service);
        }

        xmlSubNode = xmlList[WORKERS] as XMLNode;
        XMLNodeList workersXML = xmlSubNode.GetNodeList("workers>0>worker");

        for (int j = 0; j < workersXML.Count; j++)
        {
            XMLNode workerXML = workersXML[j] as XMLNode;
            Worker  worker    = new Worker();

            worker.name       = workerXML.GetValue("@name");
            worker.tag        = workerXML.GetValue("@tag");
            worker.cost       = float.Parse(workerXML.GetValue("@cost"));
            worker.discipline = workerXML.GetValue("@discipline");
            // worker.price = float.Parse(workerXMl.GetValue("@price"));
            // worker.upgradeCost = float.Parse(workerXMl.GetValue("@cost"));
            // worker.time = float.Parse(workerXMl.GetValue("@time"));
            // worker.viability = int.Parse(workerXMl.GetValue("@viability"));
            // worker.customers = int.Parse(workerXMl.GetValue("@customers"));

            workers.Add(worker);
        }

        xmlSubNode = xmlList[MARKETING] as XMLNode;
        XMLNodeList marketingXML = xmlSubNode.GetNodeList("marketing>0>tool");

        for (int j = 0; j < marketingXML.Count; j++)
        {
            XMLNode       toolXML = marketingXML[j] as XMLNode;
            MarketingTool tool    = new MarketingTool();

            tool.name = toolXML.GetValue("@name");
            tool.tag  = toolXML.GetValue("@tag");
            tool.cost = float.Parse(toolXML.GetValue("@cost"));
            // tool.price = float.Parse(toolXML.GetValue("@price"));
            // tool.upgradeCost = float.Parse(toolXML.GetValue("@cost"));
            // tool.time = float.Parse(toolXML.GetValue("@time"));
            // tool.viability = int.Parse(toolXML.GetValue("@viability"));
            // tool.customers = int.Parse(toolXML.GetValue("@customers"));

            marketingTools.Add(tool);
        }
    }
Exemplo n.º 11
0
        public XMLNode Parse(string content)
        {
            XMLNode xMLNode = new XMLNode();

            xMLNode["_text"] = "";
            bool        flag        = false;
            bool        flag2       = false;
            bool        flag3       = false;
            bool        flag4       = false;
            bool        flag5       = false;
            string      text        = "";
            string      text2       = "";
            string      text3       = "";
            string      text4       = "";
            bool        flag6       = false;
            bool        flag7       = false;
            bool        flag8       = false;
            XMLNodeList xMLNodeList = new XMLNodeList();
            XMLNode     xMLNode2    = xMLNode;

            for (int i = 0; i < content.Length; i++)
            {
                char c  = content[i];
                char c2 = '~';
                char c3 = '~';
                char c4 = '~';
                if (i + 1 < content.Length)
                {
                    c2 = content[i + 1];
                }
                if (i + 2 < content.Length)
                {
                    c3 = content[i + 2];
                }
                if (i > 0)
                {
                    c4 = content[i - 1];
                }
                if (flag6)
                {
                    if (c == QMARK && c2 == GT)
                    {
                        flag6 = false;
                        i++;
                    }
                }
                else if (!flag5 && c == LT && c2 == QMARK)
                {
                    flag6 = true;
                }
                else if (flag7)
                {
                    if (c4 == DASH && c == DASH && c2 == GT)
                    {
                        flag7 = false;
                        i++;
                    }
                }
                else if (!flag5 && c == LT && c2 == EXCLAMATION)
                {
                    if (content.Length > i + 9 && content.Substring(i, 9) == "<![CDATA[")
                    {
                        flag8 = true;
                        i    += 8;
                    }
                    else
                    {
                        flag7 = true;
                    }
                }
                else if (flag8)
                {
                    if (c == SQR && c2 == SQR && c3 == GT)
                    {
                        flag8 = false;
                        i    += 2;
                    }
                    else
                    {
                        text4 += c;
                    }
                }
                else if (flag)
                {
                    if (flag2)
                    {
                        if (c == SPACE)
                        {
                            flag2 = false;
                        }
                        else if (c == GT)
                        {
                            flag2 = false;
                            flag  = false;
                        }
                        if (!flag2 && text3.Length > 0)
                        {
                            if (text3[0] == SLASH)
                            {
                                if (text4.Length > 0)
                                {
                                    XMLNode xMLNode3;
                                    XMLNode xMLNode4 = (xMLNode3 = xMLNode2);
                                    object  obj      = xMLNode3["_text"];
                                    xMLNode4["_text"] = string.Concat(obj, text4);
                                }
                                text4    = "";
                                text3    = "";
                                xMLNode2 = xMLNodeList.Pop();
                                continue;
                            }
                            if (text4.Length > 0)
                            {
                                XMLNode xMLNode5;
                                XMLNode xMLNode6 = (xMLNode5 = xMLNode2);
                                object  obj      = xMLNode5["_text"];
                                xMLNode6["_text"] = string.Concat(obj, text4);
                            }
                            text4 = "";
                            XMLNode xMLNode7 = new XMLNode();
                            xMLNode7["_text"] = "";
                            xMLNode7["_name"] = text3;
                            if (xMLNode2[text3] == null)
                            {
                                xMLNode2[text3] = new XMLNodeList();
                            }
                            XMLNodeList xMLNodeList2 = (XMLNodeList)xMLNode2[text3];
                            xMLNodeList2.Push(xMLNode7);
                            xMLNodeList.Push(xMLNode2);
                            xMLNode2 = xMLNode7;
                            text3    = "";
                        }
                        else
                        {
                            text3 += c;
                        }
                    }
                    else if (!flag5 && c == SLASH && c2 == GT)
                    {
                        flag  = false;
                        flag3 = false;
                        flag4 = false;
                        if (text.Length > 0)
                        {
                            if (text2.Length > 0)
                            {
                                xMLNode2["@" + text] = text2;
                            }
                            else
                            {
                                xMLNode2["@" + text] = true;
                            }
                        }
                        i++;
                        xMLNode2 = xMLNodeList.Pop();
                        text     = "";
                        text2    = "";
                    }
                    else if (!flag5 && c == GT)
                    {
                        flag  = false;
                        flag3 = false;
                        flag4 = false;
                        if (text.Length > 0)
                        {
                            xMLNode2["@" + text] = text2;
                        }
                        text  = "";
                        text2 = "";
                    }
                    else if (flag3)
                    {
                        if (c == SPACE || c == EQUALS)
                        {
                            flag3 = false;
                            flag4 = true;
                        }
                        else
                        {
                            text += c;
                        }
                    }
                    else if (flag4)
                    {
                        if (c == QUOTE || c == QUOTE2)
                        {
                            if (flag5)
                            {
                                flag4 = false;
                                xMLNode2["@" + text] = text2;
                                text2 = "";
                                text  = "";
                                flag5 = false;
                            }
                            else
                            {
                                flag5 = true;
                            }
                        }
                        else if (flag5)
                        {
                            text2 += c;
                        }
                        else if (c == SPACE)
                        {
                            flag4 = false;
                            xMLNode2["@" + text] = text2;
                            text2 = "";
                            text  = "";
                        }
                    }
                    else if (c != SPACE)
                    {
                        flag3 = true;
                        text  = "" + c;
                        text2 = "";
                        flag5 = false;
                    }
                }
                else if (c == LT)
                {
                    flag  = true;
                    flag2 = true;
                }
                else
                {
                    text4 += c;
                }
            }
            return(xMLNode);
        }
Exemplo n.º 12
0
    bool loadDevices(ref XMLNode nodes)
    {
        XMLNodeList nodeList = nodes.GetNodeList("retinaProData>0>ArrayOfRetinaProDevice>0>retinaProDevice");

        if (nodeList == null)
        {
            return(false);
        }

        foreach (XMLNode node in nodeList)
        {
            retinaProRuntimeDevice rd = new retinaProRuntimeDevice();

            foreach (DictionaryEntry pair in node)
            {
                if (pair.Key.ToString().CompareTo("name") == 0)
                {
                    XMLNodeList vs = (XMLNodeList)pair.Value;
                    foreach (XMLNode v in vs)
                    {
                        foreach (DictionaryEntry dp in v)
                        {
                            if (dp.Key.ToString().CompareTo("_text") == 0)
                            {
                                rd.name = dp.Value.ToString();
                            }
                        }
                    }
                }
                else if (pair.Key.ToString().CompareTo("pixelSize") == 0)
                {
                    XMLNodeList vs = (XMLNodeList)pair.Value;
                    foreach (XMLNode v in vs)
                    {
                        foreach (DictionaryEntry dp in v)
                        {
                            if (dp.Key.ToString().CompareTo("_text") == 0)
                            {
                                string str = dp.Value.ToString();
                                Single.TryParse(str, out rd.pixelSize);
                            }
                        }
                    }
                }
                else if (pair.Key.ToString().CompareTo("screens") == 0)
                {
                    XMLNodeList vs = (XMLNodeList)pair.Value;
                    foreach (XMLNode v in vs)
                    {
                        retinaProRuntimeScreen rs = new retinaProRuntimeScreen();

                        foreach (DictionaryEntry dp in v)
                        {
                            if (dp.Key.ToString().CompareTo("width") == 0)
                            {
                                XMLNodeList vs2 = (XMLNodeList)dp.Value;
                                foreach (XMLNode v2 in vs2)
                                {
                                    foreach (DictionaryEntry dp2 in v2)
                                    {
                                        if (dp2.Key.ToString().CompareTo("_text") == 0)
                                        {
                                            string str = dp2.Value.ToString();
                                            Int32.TryParse(str, out rs.width);
                                        }
                                    }
                                }
                            }
                            else if (dp.Key.ToString().CompareTo("height") == 0)
                            {
                                XMLNodeList vs2 = (XMLNodeList)dp.Value;
                                foreach (XMLNode v2 in vs2)
                                {
                                    foreach (DictionaryEntry dp2 in v2)
                                    {
                                        if (dp2.Key.ToString().CompareTo("_text") == 0)
                                        {
                                            string str = dp2.Value.ToString();
                                            Int32.TryParse(str, out rs.height);
                                        }
                                    }
                                }
                            }
                            else if (dp.Key.ToString().CompareTo("useForBothLandscapePortrait") == 0)
                            {
                                XMLNodeList vs2 = (XMLNodeList)dp.Value;
                                foreach (XMLNode v2 in vs2)
                                {
                                    foreach (DictionaryEntry dp2 in v2)
                                    {
                                        if (dp2.Key.ToString().CompareTo("_text") == 0)
                                        {
                                            string str = dp2.Value.ToString();
                                            Boolean.TryParse(str, out rs.useForBothLandscapePortrait);
                                        }
                                    }
                                }
                            }
                        }

                        rd.screens.Add(rs);
                    }
                }
                else if (pair.Key.ToString().CompareTo("rootWidth") == 0)
                {
                    XMLNodeList vs = (XMLNodeList)pair.Value;
                    foreach (XMLNode v in vs)
                    {
                        foreach (DictionaryEntry dp in v)
                        {
                            if (dp.Key.ToString().CompareTo("_text") == 0)
                            {
                                string str = dp.Value.ToString();

                                Int32.TryParse(str, out rd.rootWidth);
                            }
                        }
                    }
                }
                else if (pair.Key.ToString().CompareTo("rootHeight") == 0)
                {
                    XMLNodeList vs = (XMLNodeList)pair.Value;
                    foreach (XMLNode v in vs)
                    {
                        foreach (DictionaryEntry dp in v)
                        {
                            if (dp.Key.ToString().CompareTo("_text") == 0)
                            {
                                string str = dp.Value.ToString();

                                Int32.TryParse(str, out rd.rootHeight);
                            }
                        }
                    }
                }
                else if (pair.Key.ToString().CompareTo("rootAuto") == 0)
                {
                    XMLNodeList vs = (XMLNodeList)pair.Value;
                    foreach (XMLNode v in vs)
                    {
                        foreach (DictionaryEntry dp in v)
                        {
                            if (dp.Key.ToString().CompareTo("_text") == 0)
                            {
                                string str = dp.Value.ToString();

                                bool.TryParse(str, out rd.rootAuto);
                            }
                        }
                    }
                }
                else if (pair.Key.ToString().CompareTo("rootUseBothPortLand") == 0)
                {
                    XMLNodeList vs = (XMLNodeList)pair.Value;
                    foreach (XMLNode v in vs)
                    {
                        foreach (DictionaryEntry dp in v)
                        {
                            if (dp.Key.ToString().CompareTo("_text") == 0)
                            {
                                string str = dp.Value.ToString();

                                bool.TryParse(str, out rd.rootUseBothPortLand);
                            }
                        }
                    }
                }
            }

            // add one to the device list
            deviceList.Add(rd);
#if RETINAPRO_DEBUGLOG
            {
                string debug = "";

                debug += "RetinaPro Device = " + rd.name + ", ";
                debug += "pixelSize = " + rd.pixelSize + ", ";
                if (rd.rootAuto)
                {
                    debug += "root = Auto, ";
                }
                else
                {
                    debug += "root (" + rd.rootWidth + " x " + rd.rootHeight + "), Port & Land = " + rd.rootUseBothPortLand + ", ";
                }

                for (int si = 0; si < rd.screens.Count; si++)
                {
                    debug += "screen[" + si + "] = { " + rd.screens[si].width + " X " + rd.screens[si].height + ", Port & Land = " + rd.screens[si].useForBothLandscapePortrait + " }";
                    if (si != rd.screens.Count - 1)
                    {
                        debug += ", ";
                    }
                }

                Debug.Log(debug);
            }
#endif
        }

        return(true);
    }
Exemplo n.º 13
0
        private void parserMsgList(IDictionary <string, IDictionary <int, string> > dict, XMLNodeList nodeList)
        {
            string      key                   = null;
            string      subKey                = null;
            XMLNodeList childList             = null;
            IDictionary <int, string> subDict = null;

            foreach (XMLNode tipNode in nodeList)
            {
                key       = tipNode.GetValue("@key");
                childList = tipNode.GetNodeList("msg");
                if (StringUtils.isEmpty(key))
                {
                    continue;
                }

                subDict = new Dictionary <int, string>();
                foreach (XMLNode msgNode in childList)
                {
                    subKey = msgNode.GetValue("@key");
                    if (StringUtils.isEmpty(subKey))
                    {
                        continue;
                    }
                    subDict.Add(int.Parse(subKey), msgNode.GetValue("_text"));
                    //Debug.Log("key:" + key + ",subKey:" + subKey + ",msg:" + msgNode.GetValue("_text"));
                }
                dict.Add(key, subDict);
            }
        }
Exemplo n.º 14
0
    public XMLNode Parse(string content, int iOffset = 0)
    {
        XMLNode rootNode = new XMLNode();

        //rootNode["_text"] = System.String.Empty;
        rootNode["_text"] = new StringBuilder();

        bool inElement             = false;
        bool collectNodeName       = false;
        bool collectAttributeName  = false;
        bool collectAttributeValue = false;
        bool quoted = false;

        StringBuilder nodeNameStrBuilder  = new StringBuilder();
        StringBuilder attNameStrBuilder   = new StringBuilder();
        StringBuilder attValueStrBuilder  = new StringBuilder();
        StringBuilder textValueStrBuilder = new StringBuilder();

        bool inMetaTag = false;
        bool inComment = false;
        bool inCDATA   = false;

        XMLNodeList parents = new XMLNodeList();

        XMLNode currentNode = rootNode;

        for (int i = iOffset; i < content.Length; i++)
        {
            char c   = content[i];
            char cn  = '~'; // unused char
            char cnn = '~'; // unused char
            char cp  = '~'; // unused char

            if ((i + 1) < content.Length)
            {
                cn = content[i + 1];
            }
            if ((i + 2) < content.Length)
            {
                cnn = content[i + 2];
            }
            if (i > 0)
            {
                cp = content[i - 1];
            }

            if (inMetaTag)
            {
                if (c == QMARK && cn == GT)
                {
                    inMetaTag = false;
                    i++;
                }

                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == QMARK)
                {
                    inMetaTag = true;
                    continue;
                }
            }

            if (inComment)
            {
                if (cp == DASH && c == DASH && cn == GT)
                {
                    inComment = false;
                    i++;
                }

                continue;
            }
            else
            {
                if (!quoted && c == LT && cn == EXCLAMATION)
                {
                    if ((content.Length > i + 9) && string.Compare("< ![CDATA[", 0, content, i, 9) == 0)
                    {
                        inCDATA = true;
                        i      += 8;
                    }
                    else
                    {
                        inComment = true;
                    }

                    continue;
                }
            }

            if (inCDATA)
            {
                if (c == SQR && cn == SQR && cnn == GT)
                {
                    inCDATA = false;
                    i      += 2;
                    continue;
                }

                textValueStrBuilder.Append(c);
                continue;
            }

            if (inElement)
            {
                if (collectNodeName)
                {
                    if (c == SPACE)
                    {
                        collectNodeName = false;
                    }
                    else if (c == GT)
                    {
                        collectNodeName = false;
                        inElement       = false;
                    }

                    if (!collectNodeName && nodeNameStrBuilder.Length > 0)
                    {
                        if (nodeNameStrBuilder[0] == SLASH)
                        {
                            // close tag
                            if (textValueStrBuilder.Length > 0)
                            {
                                //currentNode["_text"] = textValueStrBuilder.ToString();
                                //currentNode["_text"] += textValueStrBuilder.ToString();
                                //(currentNode["_text"] as StringBuilder).Append( textValueStrBuilder.ToString() );
                            }

                            textValueStrBuilder.Remove(0, textValueStrBuilder.Length);
                            nodeNameStrBuilder.Remove(0, nodeNameStrBuilder.Length);
                            currentNode = parents.Pop();
                        }
                        else
                        {
                            if (textValueStrBuilder.Length > 0)
                            {
                                //currentNode["_text"] = textValueStrBuilder.ToString();
                                //currentNode["_text"] += textValueStrBuilder.ToString();
                                //(currentNode["_text"] as StringBuilder).Append( textValueStrBuilder.ToString() );
                            }

                            textValueStrBuilder.Remove(0, textValueStrBuilder.Length);
                            string  nodeNameString = nodeNameStrBuilder.ToString();
                            XMLNode newNode        = new XMLNode();
                            //newNode["_text"] = System.String.Empty;
                            newNode["_text"] = new StringBuilder();
                            newNode["_name"] = nodeNameString;

                            if (currentNode[nodeNameString] == null)
                            {
                                currentNode[nodeNameString] = new XMLNodeList();
                            }

                            XMLNodeList a = (XMLNodeList)currentNode[nodeNameString];
                            a.Push(newNode);
                            parents.Push(currentNode);
                            currentNode = newNode;
                            nodeNameStrBuilder.Remove(0, nodeNameStrBuilder.Length);
                        }
                    }
                    else
                    {
                        nodeNameStrBuilder.Append(c);
                    }
                }
                else
                {
                    if (!quoted && c == SLASH && cn == GT)
                    {
                        inElement             = false;
                        collectAttributeName  = false;
                        collectAttributeValue = false;

                        if (attNameStrBuilder.Length > 0)
                        {
                            if (attValueStrBuilder.Length > 0)
                            {
                                currentNode[attNameStrBuilder.Insert(0, '@').ToString()] = attValueStrBuilder.ToString();
                            }
                            else
                            {
                                currentNode[attNameStrBuilder.Insert(0, '@').ToString()] = true;
                            }
                        }

                        i++;
                        currentNode = parents.Pop();
                        attNameStrBuilder.Remove(0, attNameStrBuilder.Length);
                        attValueStrBuilder.Remove(0, attValueStrBuilder.Length);
                    }
                    else if (!quoted && c == GT)
                    {
                        inElement             = false;
                        collectAttributeName  = false;
                        collectAttributeValue = false;

                        if (attNameStrBuilder.Length > 0)
                        {
                            currentNode[attNameStrBuilder.Insert(0, '@').ToString()] = attValueStrBuilder.ToString();
                        }

                        attNameStrBuilder.Remove(0, attNameStrBuilder.Length);
                        attValueStrBuilder.Remove(0, attValueStrBuilder.Length);
                    }
                    else
                    {
                        if (collectAttributeName)
                        {
                            if (c == SPACE || c == EQUALS)
                            {
                                collectAttributeName  = false;
                                collectAttributeValue = true;
                            }
                            else
                            {
                                attNameStrBuilder.Append(c);
                            }
                        }
                        else if (collectAttributeValue)
                        {
                            if (c == QUOTE || c == QUOTE2)
                            {
                                if (quoted)
                                {
                                    collectAttributeValue = false;
                                    currentNode[attNameStrBuilder.Insert(0, '@').ToString()] = attValueStrBuilder.ToString();

                                    attNameStrBuilder.Remove(0, attNameStrBuilder.Length);
                                    attValueStrBuilder.Remove(0, attValueStrBuilder.Length);
                                    quoted = false;
                                }
                                else
                                {
                                    quoted = true;
                                }
                            }
                            else
                            {
                                if (quoted)
                                {
                                    attValueStrBuilder.Append(c);
                                }
                                else
                                {
                                    if (c == SPACE)
                                    {
                                        collectAttributeValue = false;
                                        currentNode[attNameStrBuilder.Insert(0, '@').ToString()] = attValueStrBuilder.ToString();
                                        attNameStrBuilder.Remove(0, attNameStrBuilder.Length);
                                        attValueStrBuilder.Remove(0, attValueStrBuilder.Length);
                                    }
                                }
                            }
                        }
                        else if (c == SPACE)
                        {
                        }
                        else
                        {
                            collectAttributeName = true;

                            attNameStrBuilder.Remove(0, attNameStrBuilder.Length).Append(c);
                            attValueStrBuilder.Remove(0, attValueStrBuilder.Length);
                            quoted = false;
                        }
                    }
                }
            }
            else
            {
                if (c == LT)
                {
                    inElement       = true;
                    collectNodeName = true;
                }
                else
                {
                    textValueStrBuilder.Append(c);
                }
            }
        }

        return(rootNode);
    }
Exemplo n.º 15
0
    /// <summary>
    /// 设置更新引导参数
    /// </summary>
    /// <param name="text">引导文件信息</param>
    public static void SetUpdateGuideInfo(string xmlString)
    {
        if (string.IsNullOrEmpty(xmlString))
        {
            return;
        }
        int index = xmlString.IndexOf('<');

        xmlString = xmlString.Substring(index);
        xmlString.Trim();

        XMLParser   parse       = new XMLParser();
        XMLNode     rootnode    = parse.Parse(xmlString);
        XMLNodeList xmlNodeList = (XMLNodeList)rootnode["Resources"];

        if (xmlNodeList == null)
        {
            return;
        }
        ///解析首段中的类型定义
        for (int i = 0; i < xmlNodeList.Count; i++)
        {
            XMLNode     xmlnode        = xmlNodeList[i] as XMLNode;
            XMLNodeList childNodeList1 = xmlnode.GetNodeList("Resource");
            if (childNodeList1 != null)
            {
                for (int j = 0; j < childNodeList1.Count; j++)
                {
                    XMLNode childnode = childNodeList1[j] as XMLNode;
                    Dictionary <string, string> resource = new Dictionary <string, string>();
                    string strID = string.Empty;
                    foreach (System.Collections.DictionaryEntry objDE in childnode)
                    {
                        if (objDE.Value == null)
                        {
                            continue;
                        }

                        string strKey = objDE.Key as string;
                        if (strKey[0] != '@')
                        {
                            continue;
                        }

                        strKey = strKey.Substring(1);
                        if (strKey == "ID")
                        {
                            strID = (string)objDE.Value;
                        }
                        else
                        {
                            if (resource.ContainsKey(strKey))
                            {
                                resource[strKey] = (string)objDE.Value;
                            }
                            else
                            {
                                resource.Add(strKey, (string)objDE.Value);
                            }
                        }
                    }
                    if (mDictUpdaterGuide.ContainsKey(strID))
                    {
                        mDictUpdaterGuide[strID] = resource;
                    }
                    else
                    {
                        mDictUpdaterGuide.Add(strID, resource);
                    }
                }
            }
        }
    }
Exemplo n.º 16
0
    //------------------------------------------------充值列表相关------------------------------------------------

    /// <summary>
    /// 设置服务器信息
    /// </summary>
    /// <param name="text">服务器列表文本</param>
    public static void SetPushServerList(string xmlString)
    {
        int index = xmlString.IndexOf('<');

        xmlString = xmlString.Substring(index);
        xmlString.Trim();
        XMLParser   parse       = new XMLParser();
        XMLNode     rootnode    = parse.Parse(xmlString);
        XMLNodeList xmlNodeList = (XMLNodeList)rootnode["PushServers"];

        if (xmlNodeList == null)
        {
            return;
        }

        ///解析首段中的类型定义
        for (int i = 0; i < xmlNodeList.Count; i++)
        {
            XMLNode     xmlnode       = xmlNodeList[i] as XMLNode;
            XMLNodeList childNodeList = xmlnode.GetNodeList("Server");
            if (childNodeList != null)
            {
                for (int j = 0; j < childNodeList.Count; j++)
                {
                    XMLNode        childnode = childNodeList[j] as XMLNode;
                    PushServerInfo psInfo    = new PushServerInfo();
                    foreach (System.Collections.DictionaryEntry objDE in childnode)
                    {
                        if (objDE.Value == null)
                        {
                            continue;
                        }

                        string strKey = objDE.Key as string;
                        if (strKey[0] != '@')
                        {
                            continue;
                        }

                        strKey = strKey.Substring(1);
                        if (strKey == "ID")
                        {
                            psInfo.strServerID = objDE.Value as string;
                        }
                        else if (strKey == "Name")
                        {
                            psInfo.strServerName = objDE.Value as string;
                        }
                        else if (strKey == "IP")
                        {
                            psInfo.strServerIP = objDE.Value as string;
                        }
                        else if (strKey == "Port")
                        {
                            psInfo.strServerPort = objDE.Value as string;
                        }
                        else if (strKey == "ApiKey")
                        {
                            psInfo.strApiKey = objDE.Value as string;
                        }
                    }
                    mDictPushServerList.Add(psInfo);
                }
            }
        }
    }