Esempio n. 1
0
 public void RemoveParametr(Parametr removed)
 {
     parametrs.Remove(removed);
 }
Esempio n. 2
0
 public void AddParametr(Parametr newParametr)
 {
     parametrs.Add(newParametr);
 }
Esempio n. 3
0
        /// <summary>
        /// nacteni objektu (Entit) z Xml souboru
        /// </summary>
        /// <param name="xmlFileName">nazev Xml souboru</param>
        /// <returns>null - pokud se nepovedlo nacist soubor
        ///          List Entit - pokud nacteni probehlo uspesne </returns>
        public List <Entity> LoadXML(string xmlFileName)
        {
            XmlDocument XmlFile = new XmlDocument();

            if (!File.Exists(xmlFileName))
            {
                return(null);
            }
            XmlFile.Load(xmlFileName);

            XmlNodeList objects = XmlFile.DocumentElement.GetElementsByTagName("Objekts");

            entityCount = objects[0].ChildNodes.Count;
            for (progress = 0; progress < objects[0].ChildNodes.Count; progress++)
            {
                bool loadSpecialTexture = false;

                List <string> specialTextureType = new List <string>();
                List <string> specialTextureName = new List <string>();

                XmlNodeList parametrs = objects[0].ChildNodes[progress].ChildNodes;

                Entity loaded = new Entity(objects[0].ChildNodes[progress].InnerText);
                loaded.Type = objects[0].ChildNodes[progress].Attributes[0].InnerText;


                for (int n = 0; n < parametrs.Count; n++)
                {
                    Parametr actual = new Parametr();

                    actual.type = parametrs[n].Attributes[0].InnerText;
                    actual.name = parametrs[n].Name;

                    string typeOfValue = parametrs[n].Attributes[1].Name;

                    if (typeOfValue.CompareTo("string") == 0)
                    {
                        if (actual.type.CompareTo("Texture") == 0)
                        {
                            loadSpecialTexture = true;
                            specialTextureType.Add(parametrs[n].Attributes[1].InnerText);
                            specialTextureName.Add(parametrs[n].Name);
                        }
                        else if (actual.type.CompareTo("Bitmap") == 0)
                        {
                            loaded = LoadBitMap(loaded, parametrs[n].Attributes[1].InnerText, actual.name);
                        }
                        else if (actual.type.CompareTo("Shader") == 0)
                        {
                            loaded = LoadShaderFromFile(loaded, parametrs[n].Attributes[1].InnerText, actual.name);
                        }
                        else if (actual.type.CompareTo("Animation") == 0)
                        {
                            loaded = LoadAnimatedObject(loaded, parametrs[n].Attributes[1].InnerText, actual.name);
                        }
                        else
                        {
                            actual.value = parametrs[n].Attributes[1].InnerText;
                            loaded.AddParametr(actual);
                        }
                    }
                    else if (typeOfValue.CompareTo("matrix") == 0)
                    {
                        actual.value = ConvertStringToMatrix(parametrs[n].Attributes[1].InnerText);
                        loaded.AddParametr(actual);
                    }
                    else if (typeOfValue.CompareTo("color") == 0)
                    {
                        actual.value = ConvertStringToColor(parametrs[n].Attributes[1].InnerText);
                        loaded.AddParametr(actual);
                    }
                    else if (typeOfValue.CompareTo("bool") == 0)
                    {
                        actual.value = ConvertStringToBool(parametrs[n].Attributes[1].InnerText);
                        loaded.AddParametr(actual);
                    }
                    else if (typeOfValue.CompareTo("int") == 0)
                    {
                        actual.value = int.Parse(parametrs[n].Attributes[1].InnerText);
                        loaded.AddParametr(actual);
                    }
                    else if (typeOfValue.CompareTo("float") == 0)
                    {
                        actual.value = float.Parse(parametrs[n].Attributes[1].InnerText);
                        loaded.AddParametr(actual);
                    }
                    else if (typeOfValue.CompareTo("lenght") == 0)
                    {
                        string[] urls = new string[int.Parse(parametrs[n].Attributes[1].InnerText)];

                        for (int m = 0; m < parametrs[n].ChildNodes.Count; m++)
                        {
                            urls[m] = parametrs[n].ChildNodes[m].Attributes[1].InnerText;
                        }
                        if (actual.type.CompareTo("meshX") == 0)
                        {
                            loaded = LoadMeshFromFile(loaded, urls, parametrs[n].Name);
                        }
                        else
                        {
                            loaded = LoadTexturesFromFile(loaded, urls, parametrs[n].Attributes[0].InnerText, parametrs[n].Name);
                        }
                    }
                    else
                    {
                        throw new Exception("Chyba pri nacitani parametru z xml neznamy typ" + typeOfValue);
                    }
                }
                if (loadSpecialTexture)
                {
                    LoadSpecialTextures(loaded, specialTextureType, specialTextureName);
                }

                if (loaded["SpecialTextureUrl"] != null)
                {
                    loaded.RemoveParametr(loaded["SpecialTextureUrl"]);
                }
                entities.Add(loaded);
            }
            return(entities);
        }