Ejemplo n.º 1
0
        public UserData(string fileName)
        {
            XmlDocument XMLDoc = null;
            XmlElement  XMLRoot;

            try
            {
                using (System.IO.StreamReader file = new System.IO.StreamReader(Settings.ModelDir + fileName))
                {
                    // tiedosto muistiin
                    string data = file.ReadToEnd();

                    XMLDoc = new XmlDocument();
                    XMLDoc.LoadXml(data);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }

            // Validate the File
            XMLRoot = XMLDoc.DocumentElement;
            if (XMLRoot.Name != "userData")
            {
                Log.Error("Error [" + fileName + "] Invalid .userdata File. Missing <userData>");
            }

            XmlElement pElement;

            pElement = (XmlElement)XMLRoot.SelectSingleNode("object");
            if (pElement != null)
            {
                string userDataID, userData;

                userDataID = XML.GetAttrib(pElement, "__id");
                userData   = pElement.InnerText;

                if (userDataID.Length > 0 && userData != null && userData.Length > 0)
                {
                    Data.Add(userDataID, userData);
                }
            }
        }
Ejemplo n.º 2
0
        void LoadParticles(string fileName, ParticleCallback particleCallback)
        {
            XmlDocument XMLDoc = null;
            XmlElement  XMLRoot;

            try
            {
                using (System.IO.StreamReader file = new System.IO.StreamReader(Settings.ParticleDir + fileName))
                {
                    // tiedosto muistiin
                    string data = file.ReadToEnd();
                    XMLDoc = new XmlDocument();
                    XMLDoc.LoadXml(data);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
            // Validate the File
            XMLRoot = XMLDoc.DocumentElement;
            if (XMLRoot.Name != "particles")
            {
                Log.Error("Error [" + fileName + "] Invalid .particles.xml File. Missing <particles>");
            }

            Name = XML.GetAttrib(XMLRoot, "name");
            string billboard   = XML.GetAttrib(XMLRoot, "billboard");
            bool   translucent = XML.GetAttribBool(XMLRoot, "translucent", false);
            bool   castshadows = XML.GetAttribBool(XMLRoot, "castshadows", false);

            origValues.count               = (int)XML.GetAttribFloat(XMLRoot, "count", 0);
            origValues.life                = XML.GetAttribFloat(XMLRoot, "life", 0);
            origValues.life_max            = XML.GetAttribFloat(XMLRoot, "life_max", origValues.life);
            origValues.zrotation           = XML.GetAttribFloat(XMLRoot, "zrotation", 0);
            origValues.zrotation_max       = XML.GetAttribFloat(XMLRoot, "zrotation_max", origValues.zrotation);
            origValues.zrotation_adder     = XML.GetAttribFloat(XMLRoot, "zrotation_adder", 0);
            origValues.zrotation_adder_max = XML.GetAttribFloat(XMLRoot, "zrotation_adder_max", origValues.zrotation_adder);
            origValues.size                = XML.GetAttribFloat(XMLRoot, "size", 0);
            origValues.size_max            = XML.GetAttribFloat(XMLRoot, "size_max", origValues.size);

            XmlElement node = (XmlElement)XMLRoot.SelectSingleNode("position");

            origValues.pos = new Vector3(XML.GetAttribFloat(node, "x", 0),
                                         XML.GetAttribFloat(node, "y", 0),
                                         XML.GetAttribFloat(node, "z", 0));
            origValues.posMax = new Vector3(XML.GetAttribFloat(node, "x_max", origValues.pos.X),
                                            XML.GetAttribFloat(node, "y_max", origValues.pos.Y),
                                            XML.GetAttribFloat(node, "z_max", origValues.pos.Z));


            node           = (XmlElement)XMLRoot.SelectSingleNode("direction");
            origValues.dir = new Vector3(XML.GetAttribFloat(node, "x", 0),
                                         XML.GetAttribFloat(node, "y", 0),
                                         XML.GetAttribFloat(node, "z", 0));
            origValues.dirMax = new Vector3(XML.GetAttribFloat(node, "x_max", origValues.dir.X),
                                            XML.GetAttribFloat(node, "y_max", origValues.dir.Y),
                                            XML.GetAttribFloat(node, "z_max", origValues.dir.Z));

            node            = (XmlElement)XMLRoot.SelectSingleNode("gravitation");
            origValues.grav = new Vector3(XML.GetAttribFloat(node, "x", 0),
                                          XML.GetAttribFloat(node, "y", 0),
                                          XML.GetAttribFloat(node, "z", 0));

            node             = (XmlElement)XMLRoot.SelectSingleNode("color");
            origValues.color = new Vector4(XML.GetAttribFloat(node, "r", 0),
                                           XML.GetAttribFloat(node, "g", 0),
                                           XML.GetAttribFloat(node, "b", 0),
                                           XML.GetAttribFloat(node, "a", 0));
            origValues.colorMax = new Vector4(XML.GetAttribFloat(node, "r_max", origValues.color.X),
                                              XML.GetAttribFloat(node, "g_max", origValues.color.Y),
                                              XML.GetAttribFloat(node, "b_max", origValues.color.Z),
                                              XML.GetAttribFloat(node, "a_max", origValues.color.W));

            SetParticle(Billboard.Load(billboard), translucent, castshadows, particleCallback);
            Reset();
        }