Exemplo n.º 1
0
    private void LoadFactoryData(TinyXmlReader parser, User user)
    {
        while (parser.Read("Factory"))
        {
            if (parser.tagType == TinyXmlReader.TagType.OPENING)
            {
                switch (parser.tagName)
                {
                case "Name":
                    Factory factory = m_game.FindFactory(parser.content, user.faction);
                    if (factory)
                    {
                        user.m_factories.Add(factory);
                    }
                    break;

                case "Weight":
                    AI ai = (user as AI);
                    if (ai)
                    {
                        ai.m_factoriesWeight.Add(float.Parse(parser.content));
                    }
                    break;
                }
            }
        }
    }
Exemplo n.º 2
0
    public static Dictionary<string, string> DictionaryFromXMLString(string xmlString)
    {
        Dictionary<string, string> data = new Dictionary<string, string>();

        TinyXmlReader xmlreader = new TinyXmlReader(xmlString);

        int depth = -1;

        // While still reading valid data
        while (xmlreader.Read())
        {

            if (xmlreader.tagType == TinyXmlReader.TagType.OPENING)
                ++depth;
            else if (xmlreader.tagType == TinyXmlReader.TagType.CLOSING)
                --depth;

            // Useful data is found at depth level 1
            if ((depth == 1) && (xmlreader.tagType == TinyXmlReader.TagType.OPENING))
            {
                if( !data.ContainsKey(xmlreader.tagName) )
                {
                    data.Add(xmlreader.tagName, xmlreader.content);
                }
                else
                {
                    Debug.LogWarning("Data already contained key " + xmlreader.tagName + " with value "+ data[ xmlreader.tagName ] +". Replacing value " + xmlreader.content);
                    data[ xmlreader.tagName ] = xmlreader.content;
                }
            }
        }

        return data;
    }
Exemplo n.º 3
0
    private void LoadMoneyData(TinyXmlReader parser, User user)
    {
        while (parser.Read("Money"))
        {
            if ((parser.tagType == TinyXmlReader.TagType.OPENING))
            {
                switch (parser.tagName)
                {
                case "Base": user.m_money = int.Parse(parser.content); break;

                case "Regen": user.m_income = int.Parse(parser.content); break;

                case "Cooldown": user.m_incomeCooldown = float.Parse(parser.content); break;

                case "Multiplicator": user.m_incomeMultiplicator = float.Parse(parser.content); break;

                case "Price": user.m_incomePrice = int.Parse(parser.content); break;

                case "PriceMultiplicator": user.m_incomePriceMultiplicator = float.Parse(parser.content); break;

                case "RateMultiplicator": user.m_incomeRateMultiplicator = float.Parse(parser.content); break;

                case "RatePrice": user.m_incomeRatePrice = int.Parse(parser.content); break;

                case "RatePriceMultiplicator": user.m_incomeRatePriceMultiplicator = float.Parse(parser.content); break;
                }
            }
        }
    }
Exemplo n.º 4
0
    // ai data
    private void LoadAIData(TinyXmlReader parser, AI ai)
    {
        while (parser.Read("AIData"))
        {
            if ((parser.tagType == TinyXmlReader.TagType.OPENING))
            {
                switch (parser.tagName)
                {
                case "Behaviour": break;                         // TODO

                case "TrySpawnCooldown": ai.m_trySpawnCooldown = float.Parse(parser.content); break;

                case "ForcedSpawnCooldown": ai.m_forcedSpawnCooldown = float.Parse(parser.content); break;

                case "SpellCastCooldown": ai.m_spellCastCooldown = float.Parse(parser.content); break;

                case "SpellCastRange": ai.m_spellCastRange = float.Parse(parser.content); break;

                case "SafetyRange": ai.m_safetyRange = float.Parse(parser.content); break;

                case "SafetyMana": ai.m_safetyMana = float.Parse(parser.content); break;
                }
            }
        }
    }
Exemplo n.º 5
0
 private void LoadFactoriesData(TinyXmlReader parser, User user)
 {
     while (parser.Read("AvailableFactories"))
     {
         if (parser.tagType == TinyXmlReader.TagType.OPENING)
         {
             LoadFactoryData(parser, user);
         }
     }
 }
Exemplo n.º 6
0
 private void LoadSpellsData(TinyXmlReader parser, User user)
 {
     while (parser.Read("AvailableSpells"))
     {
         if ((parser.tagType == TinyXmlReader.TagType.OPENING))
         {
             LoadSpellData(parser, user);
         }
     }
 }
Exemplo n.º 7
0
 public void LoadSidingStructuresData(TinyXmlReader parser, string endLoop, User user)
 {
     while (parser.Read(endLoop))
     {
         if (parser.tagType == TinyXmlReader.TagType.OPENING)
         {
             LoadStructureData(parser, user);
         }
     }
 }
Exemplo n.º 8
0
    //public void LoadStructureData(TinyXmlReader parser, Side side)
    //{
    //    GameObject obj = null;
    //    while(parser.Read("Structure"))
    //    {
    //        if(parser.tagType == TinyXmlReader.TagType.OPENING)
    //        {
    //            switch(parser.tagName)
    //            {
    //                case "Name":
    //                    User user = null;
    //                    if(side == Side.Left)
    //                        user = m_game.player;
    //                    else if(side == Side.Right)
    //                        user = m_game.ai;
    //                    else
    //                        Debug.LogError("LoadStructureData received an unused Side variable");

    //                    obj = Instantiate(m_game.FindStructure(parser.content, user.faction)) as GameObject;
    //                    obj.GetComponentInChildren<Body>().m_side = side;


    //                    obj.transform.parent = user.transform;//m_game.m_map.transform;
    //                    if(parser.content.StartsWith("Spawner"))    // this is bad and you should feel bad
    //                        user.m_spawner = obj.transform;
    //                    break;
    //                case "Position":
    //                    obj.transform.position = GetVector3(parser.content, ';') + m_game.m_map.GetRandomStartingGroundPos();
    //                    break;
    //            }
    //        }
    //    }
    //}

    public void LoadStructureData(TinyXmlReader parser, User user)
    {
        GameObject obj = null;

        while (parser.Read("Structure"))
        {
            if (parser.tagType == TinyXmlReader.TagType.OPENING)
            {
                switch (parser.tagName)
                {
                case "Name":
                    obj = Instantiate(m_game.FindStructure(parser.content, user.faction)) as GameObject;
                    obj.GetComponentInChildren <Body>().m_side = user.m_side;


                    obj.transform.parent = user.transform;    //m_game.m_map.transform;
                    if (parser.content.StartsWith("Spawner")) // this is bad and you should feel bad
                    {
                        user.m_spawner = obj.transform;
                    }
                    break;

                case "Position":
                    // obj.transform.position = GetVector3(parser.content, ';') + m_game.m_map.GetRandomStartingGroundPos();

                    float parsedXValue = 0;

                    if (!float.TryParse(parser.content, out parsedXValue))
                    {
                        Debug.LogError("DataLoader: Incorrect float value for position: " + parser.content);
                    }

                    obj.transform.position = m_game.m_map.GetLocationByPercentage(parsedXValue, user).yAdd(Map.use.GetCenterGround().y);

                    break;

                case "Depth":
                    float parsedZValue = 0;

                    if (!float.TryParse(parser.content, out parsedZValue))
                    {
                        Debug.LogError("DataLoader: Incorrect float value for depth: " + parser.content);
                    }

                    obj.transform.position = obj.transform.position.z(Map.use.GetDepthByPercentage(parsedZValue));
                    break;
                }
            }
        }
    }
Exemplo n.º 9
0
    private void LoadGameData(TinyXmlReader parser)
    {
        while (parser.Read("Game"))
        {
            if (parser.tagType == TinyXmlReader.TagType.OPENING)
            {
                switch (parser.tagName)
                {
                case "Camera": LoadCameraData(parser); break;

                case "Structures": LoadStructuresData(parser); break;
                }
            }
        }
    }
Exemplo n.º 10
0
    public void LoadStructuresData(TinyXmlReader parser)
    {
        while (parser.Read("Structures"))
        {
            if (parser.tagType == TinyXmlReader.TagType.OPENING)
            {
                switch (parser.tagName)
                {
                case "Player": LoadSidingStructuresData(parser, "Player", GameData.use.player); break;

                case "AI": LoadSidingStructuresData(parser, "AI", GameData.use.ai); break;
                }
            }
        }
    }
Exemplo n.º 11
0
 // game data
 public void LoadCameraData(TinyXmlReader parser)
 {
     while (parser.Read("Camera"))
     {
         if (parser.tagType == TinyXmlReader.TagType.OPENING)
         {
             switch (parser.tagName)
             {
             case "Position":
                 m_game.m_camera.gameObject.MoveTo(GetVector3(parser.content, ';')).Time(1f).Execute();     // TODO : lock the camera during that operation
                 break;
             }
         }
     }
 }
Exemplo n.º 12
0
 private void LoadSpellData(TinyXmlReader parser, User user)
 {
     while (parser.Read("Spell"))
     {
         if ((parser.tagType == TinyXmlReader.TagType.OPENING))
         {
             switch (parser.tagName)
             {
             case "Name":
                 Spell spell = m_game.FindSpell(parser.content);
                 if (spell)
                 {
                     user.m_spells.Add(spell);
                 }
                 break;
             }
         }
     }
 }
Exemplo n.º 13
0
    // user data
    private void LoadUserData(TinyXmlReader parser, User user)
    {
        while (parser.Read("UserData"))
        {
            if (parser.tagType == TinyXmlReader.TagType.OPENING)
            {
                switch (parser.tagName)
                {
                case "AvailableFactories": LoadFactoriesData(parser, user); break;

                case "AvailableSpells": LoadSpellsData(parser, user); break;

                case "Money": LoadMoneyData(parser, user); break;

                case "Mana": LoadManaData(parser, user); break;
                }
            }
        }
    }
Exemplo n.º 14
0
    private void LoadData(string xmlData)
    {
        TinyXmlReader parser = new TinyXmlReader(xmlData);

        while (parser.Read())
        {
            if ((parser.tagType == TinyXmlReader.TagType.OPENING))
            {
                switch (parser.tagName)
                {
                case "Game": LoadGameData(parser); break;

                case "Player": LoadUserComponentsData(parser, m_game.player, "Player"); break;

                case "AI": LoadUserComponentsData(parser, m_game.ai, "AI"); break;
                }
            }
        }

        m_game.InstantiateUsersComponents();
    }
Exemplo n.º 15
0
    private void LoadUserComponentsData(TinyXmlReader parser, User user, string endLoop)
    {
        //TODO : get the string here instead of receiving by parameter ?
        while (parser.Read(endLoop))
        {
            if (parser.tagType == TinyXmlReader.TagType.OPENING)
            {
                switch (parser.tagName)
                {
                case "UserData": LoadUserData(parser, user); break;

                case "AIData":
                    AI ai = user as AI;
                    if (ai)
                    {
                        LoadAIData(parser, ai);
                    }
                    break;
                }
            }
        }
    }
Exemplo n.º 16
0
    private void LoadManaData(TinyXmlReader parser, User user)
    {
        while (parser.Read("Mana"))
        {
            if ((parser.tagType == TinyXmlReader.TagType.OPENING))
            {
                switch (parser.tagName)
                {
                case "Base": user.m_manaMax = int.Parse(parser.content); user.Initialize(); break;

                case "Regen": user.m_manaRegen = int.Parse(parser.content); break;

                case "Cooldown": user.m_manaRegenCooldown = float.Parse(parser.content); break;

                case "Multiplicator": user.m_manaRegenMultiplicator = float.Parse(parser.content); break;

                case "Price": user.m_manaRegenPrice = int.Parse(parser.content); break;

                case "PriceMultiplicator": user.m_manaRegenPriceMultiplicator = float.Parse(parser.content); break;
                }
            }
        }
    }
Exemplo n.º 17
0
    public static Dictionary <string, string> DictionaryFromXMLString(string xmlString)
    {
        Dictionary <string, string> data = new Dictionary <string, string>();

        TinyXmlReader xmlreader = new TinyXmlReader(xmlString);

        int depth = -1;

        // While still reading valid data
        while (xmlreader.Read())
        {
            if (xmlreader.tagType == TinyXmlReader.TagType.OPENING)
            {
                ++depth;
            }
            else if (xmlreader.tagType == TinyXmlReader.TagType.CLOSING)
            {
                --depth;
            }

            // Useful data is found at depth level 1
            if ((depth == 1) && (xmlreader.tagType == TinyXmlReader.TagType.OPENING))
            {
                if (!data.ContainsKey(xmlreader.tagName))
                {
                    data.Add(xmlreader.tagName, xmlreader.content);
                }
                else
                {
                    Debug.LogWarning("Data already contained key " + xmlreader.tagName + " with value " + data[xmlreader.tagName] + ". Replacing value " + xmlreader.content);
                    data[xmlreader.tagName] = xmlreader.content;
                }
            }
        }

        return(data);
    }
Exemplo n.º 18
0
 IEnumerator getFeed()
 {
     // if the feed must be updated run the function
     if(updateFeed)
     {
         // Sets updating to true
         updating = true;
         errorFree = true;
         // Gets the data from the url set in the inspector
         // This form is simply to make sure that WWW gets the latest version of the xml document
         WWWForm form = new WWWForm();
         form.AddField("number", 1221);
         WWW feedPost = new WWW(feedURL, form);
         // Returns control to rest of program until it is finished downloading
         yield return feedPost;
         // if there are no errors runs through the function
         if(feedPost.error == null)
         {
             // Creates a instance of TinyXmlReader to loop through the xml document
             // loops through the document and extracts data from each <Feed></Feed>
             // For my use, it extracts the title, date, author and message.
             // it stores this in an array of struc type declared above
             TinyXmlReader reader = new TinyXmlReader(feedPost.data);
             while(reader.Read("Feeds") && (arrayLength < feedLength))
             {
                 while(reader.Read("Feed"))
                 {
                     if(reader.tagName == "Title" && reader.isOpeningTag)
                     {
                         theFeed[arrayLength].Title = reader.content;
                     }
                     if(reader.tagName == "Date" && reader.isOpeningTag)
                     {
                         theFeed[arrayLength].Date = reader.content;
                     }
                     if(reader.tagName == "Author" && reader.isOpeningTag)
                     {
                         theFeed[arrayLength].Author = reader.content;
                     }
                     if(reader.tagName == "Message" && reader.isOpeningTag)
                     {
                         theFeed[arrayLength].Message = reader.content;
                     }
                 }
                 // Increments the counter variable for the array
                 arrayLength++;
             }
         }
         // if there was an error
         else
         {
             // sets all the error messages
             errorFree = false;
             theFeed[0].Title = "Error connecting to Feed...";
             theFeed[0].Message = feedPost.error;
             // Logs an error
             Debug.LogError(feedPost.error);
         }
         // sets the values of the variables to there off state
         updateFeed = false;
         updating = false;
         // sets the last update time
         timeSinceLastUpdate = Time.time + (60 * minutesTillUpdate);
         // Destroys the feedPost...
         feedPost.Dispose();
     }
 }
Exemplo n.º 19
0
    public void Load(string txt)
    {
        TinyXmlReader reader = new TinyXmlReader(txt);

        while (reader.Read())
        {
            string objectName = typeof(T).Name;
            if (reader.tagName == objectName && reader.isOpeningTag)
            {
                T data = new T();
                while (reader.Read())
                {
                    if (reader.isOpeningTag && reader.tagName != objectName)
                    {
                        string fieldName = reader.tagName;
                        System.Reflection.FieldInfo fieldInfo = typeof(T).GetField(fieldName);
                        if (fieldInfo != null)
                        {
                            if (fieldInfo.FieldType == typeof(int))
                            {
                                fieldInfo.SetValue(data, int.Parse(reader.content));
                            }
                            else if (fieldInfo.FieldType == typeof(float))
                            {
                                fieldInfo.SetValue(data, float.Parse(reader.content));
                            }
                            else if (fieldInfo.FieldType == typeof(string))
                            {
                                fieldInfo.SetValue(data, reader.content);
                            }
                            else if (fieldInfo.FieldType == typeof(bool))
                            {
                                fieldInfo.SetValue(data, bool.Parse(reader.content));
                            }
                            else if (fieldInfo.FieldType == typeof(int[]))
                            {
                                List <int> value = new List <int>();
                                while (reader.Read())
                                {
                                    if (reader.tagName == "int" && reader.isOpeningTag)
                                    {
                                        value.Add(int.Parse(reader.content));
                                    }
                                    else if (reader.tagName == fieldName && reader.isOpeningTag == false)
                                    {
                                        fieldInfo.SetValue(data, value.ToArray());
                                        goto ONEOBJ;
                                    }
                                }
                            }
                            else if (fieldInfo.FieldType == typeof(float[]))
                            {
                                List <float> value = new List <float>();
                                while (reader.Read())
                                {
                                    if (reader.tagName == "float" && reader.isOpeningTag)
                                    {
                                        value.Add(float.Parse(reader.content));
                                    }
                                    else if (reader.tagName == fieldName && reader.isOpeningTag == false)
                                    {
                                        fieldInfo.SetValue(data, value.ToArray());
                                        goto ONEOBJ;
                                    }
                                }
                            }
                            else if (fieldInfo.FieldType == typeof(string[]))
                            {
                                List <string> value = new List <string>();
                                while (reader.Read())
                                {
                                    if (reader.tagName == "string" && reader.isOpeningTag)
                                    {
                                        value.Add(reader.content);
                                    }
                                    else if (reader.tagName == fieldName && reader.isOpeningTag == false)
                                    {
                                        fieldInfo.SetValue(data, value.ToArray());
                                        goto ONEOBJ;
                                    }
                                }
                            }
                            else if (fieldInfo.FieldType == typeof(List <string>))
                            {
                                List <string> value = new List <string>();
                                while (reader.Read())
                                {
                                    if (reader.tagName == "string" && reader.isOpeningTag)
                                    {
                                        value.Add(reader.content);
                                    }
                                    else if (reader.tagName == fieldName && reader.isOpeningTag == false)
                                    {
                                        fieldInfo.SetValue(data, value);
                                        goto ONEOBJ;
                                    }
                                }
                            }
                            else if (fieldInfo.FieldType == typeof(List <int>))
                            {
                                List <int> value = new List <int>();
                                while (reader.Read())
                                {
                                    if (reader.tagName == "int" && reader.isOpeningTag)
                                    {
                                        value.Add(int.Parse(reader.content));
                                    }
                                    else if (reader.tagName == fieldName && reader.isOpeningTag == false)
                                    {
                                        fieldInfo.SetValue(data, value);
                                        goto ONEOBJ;
                                    }
                                }
                            }
                            else if (fieldInfo.FieldType == typeof(List <float>))
                            {
                                List <float> value = new List <float>();
                                while (reader.Read())
                                {
                                    if (reader.tagName == "float" && reader.isOpeningTag)
                                    {
                                        value.Add(float.Parse(reader.content));
                                    }
                                    else if (reader.tagName == fieldName && reader.isOpeningTag == false)
                                    {
                                        fieldInfo.SetValue(data, value);
                                        goto ONEOBJ;
                                    }
                                }
                            }
                        }
                    }

ONEOBJ:
                    if (reader.tagName == objectName && reader.isOpeningTag == false)
                    {
                        break;
                    }
                }
                Add(data);
            }
        }

        OnLoaded();
    }
Exemplo n.º 20
0
    // Parse flat xml data of the form: <key>value</key>
    // The data is considered to be found at depth level 1 (the root and header are found on depth level 0).
    public Dictionary<string, string> ParseFrom(string rawdata)
    {
        Dictionary<string, string> data = new Dictionary<string, string>();

        TinyXmlReader xmlreader = new TinyXmlReader(rawdata);

        int depth = -1;

        // While still reading valid data
        while (xmlreader.Read())
        {

            if (xmlreader.tagType == TinyXmlReader.TagType.OPENING)
                ++depth;
            else if (xmlreader.tagType == TinyXmlReader.TagType.CLOSING)
                --depth;

            // Useful data is found at depth level 1
            if ((depth == 1) && (xmlreader.tagType == TinyXmlReader.TagType.OPENING))
                data.Add(xmlreader.tagName, xmlreader.content);
        }
        return data;
    }
Exemplo n.º 21
0
    IEnumerator getFeed()
    {
        // if the feed must be updated run the function
        if (updateFeed)
        {
            // Sets updating to true
            updating  = true;
            errorFree = true;
            // Gets the data from the url set in the inspector
            // This form is simply to make sure that WWW gets the latest version of the xml document
            WWWForm form = new WWWForm();
            form.AddField("number", 1221);
            WWW feedPost = new WWW(feedURL, form);
            // Returns control to rest of program until it is finished downloading
            yield return(feedPost);

            // if there are no errors runs through the function
            if (feedPost.error == null)
            {
                // Creates a instance of TinyXmlReader to loop through the xml document
                // loops through the document and extracts data from each <Feed></Feed>
                // For my use, it extracts the title, date, author and message.
                // it stores this in an array of struc type declared above
                TinyXmlReader reader = new TinyXmlReader(feedPost.data);
                while (reader.Read("Feeds") && (arrayLength < feedLength))
                {
                    while (reader.Read("Feed"))
                    {
                        if (reader.tagName == "Title" && reader.isOpeningTag)
                        {
                            theFeed[arrayLength].Title = reader.content;
                        }
                        if (reader.tagName == "Date" && reader.isOpeningTag)
                        {
                            theFeed[arrayLength].Date = reader.content;
                        }
                        if (reader.tagName == "Author" && reader.isOpeningTag)
                        {
                            theFeed[arrayLength].Author = reader.content;
                        }
                        if (reader.tagName == "Message" && reader.isOpeningTag)
                        {
                            theFeed[arrayLength].Message = reader.content;
                        }
                    }
                    // Increments the counter variable for the array
                    arrayLength++;
                }
            }
            // if there was an error
            else
            {
                // sets all the error messages
                errorFree          = false;
                theFeed[0].Title   = "Error connecting to Feed...";
                theFeed[0].Message = feedPost.error;
                // Logs an error
                Debug.LogError(feedPost.error);
            }
            // sets the values of the variables to there off state
            updateFeed = false;
            updating   = false;
            // sets the last update time
            timeSinceLastUpdate = Time.time + (60 * minutesTillUpdate);
            // Destroys the feedPost...
            feedPost.Dispose();
        }
    }
Exemplo n.º 22
0
    private List <Newsarticle> Parse(string s)
    {
        Newsarticle        currentArticle = null;
        List <Newsarticle> articles       = new List <Newsarticle>();
        var reader = new TinyXmlReader(s);

        while (reader.Read())
        {
            if (isInsideItem)
            {
                if (currentArticle == null)
                {
                    currentArticle = Newsarticle.CreateInstance <Newsarticle>();
                }
                else if (reader.isOpeningTag && reader.tagName == "item" && currentArticle)     // New article
                {
                    articles.Add(currentArticle);
                    currentArticle = Newsarticle.CreateInstance <Newsarticle>();
                }

                if (reader.isOpeningTag)
                {
                    switch (reader.tagName)
                    {
                    case "link":
                        currentArticle.Link = reader.content;
                        break;

                    case "title":
                        currentArticle.Title = reader.content;
                        break;

                    case "pubDate":
                        System.DateTime timestamp;
                        System.DateTime.TryParse(reader.content, out timestamp);
                        currentArticle.PublicationDate = timestamp;
                        break;

                    case "longitude":
                        currentArticle.Longitude = double.Parse(reader.content);
                        break;

                    case "latitude":
                        currentArticle.Latitude = double.Parse(reader.content);
                        break;

                    case "description":
                        currentArticle.ImageUrl    = FindImageUrl(reader.content);
                        currentArticle.Description = FilterOutTags(reader.content);
                        break;

                    case "image":
                        currentArticle.ImageUrl = reader.content;
                        break;

                    default:
                        break;
                    }
                }
            }
            else
            {
                if (reader.isOpeningTag && reader.tagName == "item")
                {
                    isInsideItem = true;
                }
            }
        }
        if (currentArticle)
        {
            articles.Add(currentArticle);
        }
        return(articles);
    }
Exemplo n.º 23
0
 // Use this for initialization
 public EDSAC Populate()
 {
     edsac = new EDSAC();
     reader = new TinyXmlReader(edsacXml.text);
     string readingDebugText = "Debug output from XML population:\n\n";
     while (reader.Read()) {
         if (reader.isOpeningTag) {
             if (reader.tagName == "chassisdefinition") {
                 readingDebugText += "New chassis definition found.\n";
                 EDSAC.ChassisType c = new EDSAC.ChassisType();
                 string key = "";
                 while (reader.tagName != "chassisdefinition" || reader.isOpeningTag) {
                     reader.Read();
                     if (reader.isOpeningTag) {
                         switch(reader.tagName) {
                         case "chassistype":
                             key = reader.content;
                             readingDebugText += "Chassis definition key: " + key + "\n";
                             break;
                         case "testingpoints":
                             switch (reader.content) {
                             case "1":
                                 c.testingPoints = EDSAC.TestingPointsType.TYPE1;
                                 break;
                             case "2":
                                 c.testingPoints = EDSAC.TestingPointsType.TYPE2;
                                 break;
                             case "3":
                                 c.testingPoints = EDSAC.TestingPointsType.TYPE3;
                                 break;
                             case "4":
                                 c.testingPoints = EDSAC.TestingPointsType.TYPE4;
                                 break;
                             }
                             readingDebugText += "Chassis testing points: " + c.testingPoints.ToString() + "\n";
                             break;
                         case "valve":
                             EDSAC.Valve v = new EDSAC.Valve();
                             readingDebugText += "New valve.\n";
                             while (reader.tagName != "valve" || reader.isOpeningTag) {
                                 reader.Read();
                                 if (reader.isOpeningTag) {
                                     switch(reader.tagName) {
                                     case "valvetype":
                                         switch (reader.content) {
                                         case "SmallRed":
                                             v.valveType = EDSAC.ValveType.SMALL_RED;
                                             break;
                                         case "SmallCream":
                                             v.valveType = EDSAC.ValveType.SMALL_CREAM;
                                             break;
                                         case "SmallBlack":
                                             v.valveType = EDSAC.ValveType.SMALL_BLACK;
                                             break;
                                         case "BigFlat":
                                             v.valveType = EDSAC.ValveType.BIG_FLAT;
                                             break;
                                         case "BigShiny":
                                             v.valveType = EDSAC.ValveType.BIG_SHINY;
                                             break;
                                         }
                                         readingDebugText += "Valve type: " + v.valveType.ToString() + "\n";
                                         break;
                                     case "valvex":
                                         v.x = float.Parse(reader.content);
                                         readingDebugText += "Valve x: " + v.x + "\n";
                                         break;
                                     case "valvey":
                                         v.y = float.Parse(reader.content);
                                         readingDebugText += "Valve y: " + v.y + "\n";
                                         break;
                                     }
                                 }
                             }
                             c.valves.Add (v);
                             break;
                         }
                     }
                 }
                 edsac.availableChassisTypes.Add(key, c);
             } else if (reader.tagName == "row") {
                 readingDebugText += "New row found.\n";
                 EDSAC.RowName rowName = EDSAC.RowName.UNKNOWN;
                 while (reader.tagName != "row" || reader.isOpeningTag) {
                     reader.Read();
                     if (reader.isOpeningTag) {
                         switch(reader.tagName) {
                         case "rowname":
                             switch(reader.content) {
                             case "Rear":
                                 rowName = EDSAC.RowName.REAR;
                                 break;
                             case "Middle":
                                 rowName = EDSAC.RowName.MIDDLE;
                                 break;
                             case "Front":
                                 rowName = EDSAC.RowName.FRONT;
                                 break;
                             }
                             readingDebugText += "Row type: " + rowName.ToString() + "\n";
                             break;
                         case "rack":
                             EDSAC.Rack r = new EDSAC.Rack();
                             readingDebugText += "New rack found.\n";
                             while (reader.tagName != "rack" || reader.isOpeningTag) {
                                 reader.Read();
                                 if (reader.isOpeningTag) {
                                     switch(reader.tagName) {
                                     case "racknumber":
                                         r.rackNumber = int.Parse(reader.content);
                                         readingDebugText += "Rack number: " + r.rackNumber + "\n";
                                         break;
                                     case "chassis":
                                         readingDebugText += "New chassis found.\n";
                                         EDSAC.Chassis c = new EDSAC.Chassis();
                                         while (reader.tagName != "chassis" || reader.isOpeningTag) {
                                             reader.Read();
                                             if (reader.isOpeningTag) {
                                                 switch(reader.tagName) {
                                                 case "chassisnumber":
                                                     c.chassisNumber = int.Parse(reader.content);
                                                     readingDebugText += "Chassis number: " + c.chassisNumber + "\n";
                                                     break;
                                                 case "chassisworldlabeltext":
                                                     c.physicalLabelNameText = reader.content;
                                                     readingDebugText += "Chassis label text: " + c.physicalLabelNameText + "\n";
                                                     break;
                                                 case "chassisworldlabelnumber":
                                                     c.physicalLabelNumberText = reader.content;
                                                     readingDebugText += "Chassis label number: " + c.physicalLabelNumberText + "\n";
                                                     break;
                                                 case "chassisuilabel":
                                                     c.uiLabelText = reader.content;
                                                     readingDebugText += "Chassis UI label: " + c.uiLabelText + "\n";
                                                     break;
                                                 case "chassistype":
                                                     if (edsac.availableChassisTypes.ContainsKey(reader.content)) {
                                                         c.chassisType = edsac.availableChassisTypes[reader.content];
                                                     } else {
                                                         c.chassisType = new EDSAC.ChassisType();
                                                     }
                                                     readingDebugText += "Chassis type: " + reader.content + "\n";
                                                     break;
                                                 }
                                             }
                                         }
                                         r.chassis.Add(c);
                                         break;
                                     }
                                 }
                             }
                             edsac.rows[rowName].racks.Add(r);
                             break;
                         }
                     }
                 }
             }
         }
     }
     Debug.Log (readingDebugText);
     return edsac;
 }
Exemplo n.º 24
0
    //ler arquivo XML localmente e retornar o array de levels com um array de jogos em cada level
    void LerXML()
    {
        numeroLevels = 0;

        TextAsset XML = Resources.Load("ListaDeLevels") as TextAsset;

        TinyXmlReader reader = new TinyXmlReader(XML.text);

        while (reader.Read())
        {
            if(reader.tagName.Contains("level") && reader.isOpeningTag)
            {
                numeroLevels++;
            }
        }

        Debug.Log (numeroLevels);
        levels = new Level[numeroLevels];
        numeroJogosLevel = new int[numeroLevels];

        reader = new TinyXmlReader(XML.text);

        int numeroLevel = 0;

        while (reader.Read ())
        {

            if(reader.tagName.Contains("level") && reader.isOpeningTag)
            {
                string tagName = reader.tagName;
                Level level = new Level();
                bool firstName = true;
                int numeroJogos = 0;

                while(reader.Read(tagName))
                {

                    if(reader.tagName == "nome" && reader.isOpeningTag)
                    {
                        if(firstName)
                        {
                            level.nome = reader.content;
                            firstName = false;
                        }
                    }

                    if(reader.tagName == "jogo" && reader.isOpeningTag)
                    {
                        numeroJogos++;
                    }
                }

                Debug.Log ("Numero jogos  level " + numeroLevel + ": " + numeroJogos);
                numeroJogosLevel[numeroLevel] = numeroJogos;
                levels[numeroLevel] = level;
                numeroLevel++;
            }
        }

        reader = new TinyXmlReader(XML.text);

        numeroLevel = 0;
        while (reader.Read ())
        {

            if(reader.tagName.Contains("level") && reader.isOpeningTag)
            {
                string tagName = reader.tagName;
                levels[numeroLevel].StartJogos(numeroJogosLevel[numeroLevel]);
                int numeroJogos = 0;

                while(reader.Read (tagName))
                {
                    if(reader.tagName == "jogo" && reader.isOpeningTag)
                    {
                        Jogo jogo = new Jogo();

                        while(reader.Read ("jogo"))
                        {
                            if(reader.tagName == "nome") jogo.nome = reader.content;
                            if(reader.tagName == "plataforma") jogo.plataforma = reader.content;
                            if(reader.tagName == "genero") jogo.genero = reader.content;
                            if(reader.tagName == "ano") jogo.ano = reader.content;
                            if(reader.tagName == "dificuldade") jogo.dificuldade = int.Parse(reader.content);
                            if(reader.tagName == "resposta") jogo.resposta = reader.content;
                            if(reader.tagName == "dica1") jogo.dica1 = reader.content;
                            if(reader.tagName == "dica2") jogo.dica2 = reader.content;
                            if(reader.tagName == "linkimagem") jogo.linkImagem = reader.content;

                            //Debug.Log(reader.tagName + " | " + reader.content);
                        }

                        levels[numeroLevel].jogos[numeroJogos] = jogo;
                        numeroJogos++;
                    }
                }

                numeroLevel++;
            }
        }
    }