Exemple #1
0
        public static bool saveSourceChildNode(XmlDocument xmlDocument, XmlElement xmlParentElement, SoundGroup listSounds)
        {
            foreach (SoundNode node in listSounds.Nodes)
            {
                if (node.IsGroup() == true)
                {
                    SoundGroup soundGroup        = (SoundGroup)node;
                    XmlElement elementSoundGroup = xmlDocument.CreateElement("GROUP");
                    elementSoundGroup.SetAttribute("name", soundGroup.Name);
                    xmlParentElement.AppendChild(elementSoundGroup);

                    if (saveSourceChildNode(xmlDocument, elementSoundGroup, soundGroup) == false)
                    {
                        return(false);
                    }
                }
                else
                {
                    SoundItem  soundItem        = (SoundItem)node;
                    XmlElement elementSoundItem = xmlDocument.CreateElement("SOUND");
                    elementSoundItem.SetAttribute("name", soundItem.Name);
                    elementSoundItem.SetAttribute("filename", soundItem.Filename);
                    elementSoundItem.SetAttribute("type", soundItem.Type);
                    elementSoundItem.SetAttribute("volume", ((double)soundItem.Volume * 0.01).ToString());

                    if (soundItem.Loop == true)
                    {
                        elementSoundItem.SetAttribute("loop", soundItem.Loop.ToString());
                    }

                    if (soundItem.Unique == true)
                    {
                        elementSoundItem.SetAttribute("unique", soundItem.Unique.ToString());
                    }

                    if (soundItem.Type == SoundItemProperty.typeSound[1])
                    {
                        elementSoundItem.SetAttribute("min_dist", soundItem.MinDistance.ToString());
                        elementSoundItem.SetAttribute("max_dist", soundItem.MaxDistance.ToString());
                        elementSoundItem.SetAttribute("priority", soundItem.Priority.ToString());
                    }

                    xmlParentElement.AppendChild(elementSoundItem);
                }
            }

            return(true);
        }
Exemple #2
0
        private static bool loadResourceParsing(XmlNodeList nodeLists, SoundGroup soundParentGroup)
        {
            // Read nodes
            for (int i = 0; i < nodeLists.Count; i++)
            {
                XmlNode nodeList = nodeLists[i];

                // Read sound
                if (nodeList.Name == "SOUND")
                {
                    string name     = "";
                    string fname    = "";
                    string type     = "";
                    int    volume   = 100;
                    bool   loop     = false;
                    bool   unique   = false;
                    int    mindist  = 100;
                    int    maxdist  = 1000;
                    int    priority = 128;

                    for (int j = 0; j < nodeList.Attributes.Count; j++)
                    {
                        XmlAttribute attrSound = nodeList.Attributes[j];
                        if (attrSound.Name == "name")
                        {
                            name = attrSound.Value;
                        }
                        else if (attrSound.Name == "filename")
                        {
                            fname = attrSound.Value;
                        }
                        else if (attrSound.Name == "type")
                        {
                            type = attrSound.Value;
                        }
                        else if (attrSound.Name == "volume")
                        {
                            volume = (int)(double.Parse(attrSound.Value) * 100.0);
                        }
                        else if (attrSound.Name == "loop")
                        {
                            loop = bool.Parse(attrSound.Value);
                        }
                        else if (attrSound.Name == "unique")
                        {
                            unique = bool.Parse(attrSound.Value);
                        }
                        else if (attrSound.Name == "min_dist")
                        {
                            mindist = int.Parse(attrSound.Value);
                        }
                        else if (attrSound.Name == "max_dist")
                        {
                            maxdist = int.Parse(attrSound.Value);
                        }
                        else if (attrSound.Name == "priority")
                        {
                            priority = int.Parse(attrSound.Value);
                        }
                    }


                    SoundItem soundItem = new SoundItem();
                    soundItem.Parent      = soundParentGroup;
                    soundItem.Name        = name;
                    soundItem.Filename    = fname;
                    soundItem.Type        = type;
                    soundItem.Volume      = volume;
                    soundItem.Loop        = loop;
                    soundItem.Unique      = unique;
                    soundItem.MinDistance = mindist;
                    soundItem.MaxDistance = maxdist;
                    soundItem.Priority    = priority;
                    soundParentGroup.Nodes.Add(soundItem);


                    // Read controls
                    XmlNodeList nodelistControl = nodeList.ChildNodes;
                    for (int j = 0; j < nodelistControl.Count; j++)
                    {
                        XmlNode nodeControl = nodelistControl[j];
                        if (nodeControl.Name != "CONTROL")
                        {
                            continue;
                        }


                        string nameControl  = "";
                        string typeControl  = "";
                        double scaleControl = 1.0;

                        for (int k = 0; k < nodeControl.Attributes.Count; k++)
                        {
                            XmlAttribute attrControl = nodeControl.Attributes[k];
                            if (attrControl.Name == "name")
                            {
                                nameControl = attrControl.Value;
                            }
                            else if (attrControl.Name == "type")
                            {
                                typeControl = attrControl.Value;
                            }
                            else if (attrControl.Name == "volume")
                            {
                                scaleControl = Double.Parse(attrControl.Value);
                            }
                        }
                    }
                }

                // Read group
                else if (nodeList.Name == "GROUP")
                {
                    string name = "";

                    for (int j = 0; j < nodeList.Attributes.Count; j++)
                    {
                        XmlAttribute attrGroup = nodeList.Attributes[j];
                        if (attrGroup.Name == "name")
                        {
                            name = attrGroup.Value;
                        }
                    }

                    SoundGroup soundGroup = new SoundGroup();
                    soundGroup.Parent = soundParentGroup;
                    soundGroup.Name   = name;
                    soundParentGroup.Nodes.Add(soundGroup);

                    XmlNodeList nodelistNext = nodeList.ChildNodes;
                    if (loadResourceParsing(nodelistNext, soundGroup) == false)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }