Exemplo n.º 1
0
    //gets the parsed infrormation from the default and dataStorage files and parses it to retrieve the flocking rule values.
    public void extractXmlValues(XmlParsedInformation rootNode)
    {
        //get the list of flockingRules and the speed parameter.
        List <XmlParsedInformation> flockingRules = rootNode.getElementsByName("flockingRule");
        XmlParsedInformation        speedElement  = rootNode.getFirstElementByName("speed");

        speed = parseAttribute("speed", "value", speedElement.getAttribute("value"));

        //parse the flocking rules and set the values.
        foreach (XmlParsedInformation element in flockingRules)
        {
            string elementName = element.getAttribute("name");

            switch (elementName)
            {
            case "Alignment":
                _alignment.minDist = parseAttribute(name, "minDist", element.getAttribute("minDist"));
                _alignment.maxDist = parseAttribute(name, "maxDist", element.getAttribute("maxDist"));
                _alignment.scalar  = parseAttribute(name, "scalar", element.getAttribute("scalar"));
                break;

            case "Cohesion":
                _cohesion.minDist = parseAttribute(name, "minDist", element.getAttribute("minDist"));
                _cohesion.maxDist = parseAttribute(name, "maxDist", element.getAttribute("maxDist"));
                _cohesion.scalar  = parseAttribute(name, "scalar", element.getAttribute("scalar"));
                break;

            case "Separation":
                _separation.minDist = parseAttribute(name, "minDist", element.getAttribute("minDist"));
                _separation.maxDist = parseAttribute(name, "maxDist", element.getAttribute("maxDist"));
                _separation.scalar  = parseAttribute(name, "scalar", element.getAttribute("scalar"));
                break;
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// creates a new element for every child in the rootnode.
    /// It then proceeds to create an xmlParsedInformation class where it stores that info in a tree.
    /// </summary>
    /// <param name="current"></param>
    /// <returns>returns the rootnode when it is parsed.</returns>
    private XmlParsedInformation parseXmlDocument(XmlElement current)
    {
        XmlAttributeCollection attributes = current.Attributes;
        XmlParsedInformation   xmlinfo    = new XmlParsedInformation( );

        xmlinfo.elementName = current.Name;
        foreach (XmlAttribute attr in attributes)
        {
            xmlinfo.addAttribute(attr.Name, attr.Value);
        }

        //loop through every node in the current element
        foreach (XmlNode node in current.ChildNodes)
        {
            //if the node itself is an element, we do the same thing as for the root element, until all child elements have been parsed.
            if (node.NodeType == XmlNodeType.Element)
            {
                XmlElement element = ( XmlElement )node;
                xmlinfo.addChild(parseXmlDocument(element));
            }
            else if (node.NodeType == XmlNodeType.Text)
            {
                xmlinfo.text = node.InnerText;
            }
        }
        return(xmlinfo);
    }
Exemplo n.º 3
0
    // Use this for initialization
    void Awake( )
    {
        _dataStorage = readDataStorageXml("dataStorage.xml");
        _defaults    = readDataStorageXml("default");

        extractXmlValues(_dataStorage);
    }
Exemplo n.º 4
0
    public XmlParsedInformation readDataStorageXml(string fileName)
    {
        //get the xml-file from the xmlreadWrite class.
        XmlDocument          doc      = XmlReadWrite.getInstance( ).readXmlDocument(fileName);
        XmlParsedInformation rootNode = XmlReadWrite.getInstance( ).parseXmlDocument(doc);

        return(rootNode);
    }
Exemplo n.º 5
0
 //find elements with the specific name. This is a recursive function.
 private void findChildrenWithName(XmlParsedInformation current, string name, ref List <XmlParsedInformation> children)
 {
     if (current.elementName == name)
     {
         children.Add(current);
     }
     foreach (XmlParsedInformation child in current.getChildren( ))
     {
         findChildrenWithName(child, name, ref children);
     }
 }
Exemplo n.º 6
0
    //gets the parsed infrormation from the default and dataStorage files and parses it to retrieve the flocking rule values.
    public void extractXmlValues(XmlParsedInformation rootNode)
    {
        //get the list of flockingRules and the speed parameter.
        List <XmlParsedInformation> flockingRules = rootNode.getElementsByName("flockingRule");
        XmlParsedInformation        speedElement  = rootNode.getFirstElementByName("speed");

        speed = parseAttribute("speed", "value", speedElement.getAttribute("value"));

        //parse the flocking rules and set the values.
        foreach (XmlParsedInformation element in flockingRules)
        {
            string elementName = element.getAttribute("name");

            switch (elementName)
            {
            case "Alignment":
                alignmentMinDist = parseAttribute(name, "minDist", element.getAttribute("minDist"));
                alignmentMaxDist = parseAttribute(name, "maxDist", element.getAttribute("maxDist"));
                alignmentScale   = parseAttribute(name, "scalar", element.getAttribute("scalar"));
                break;

            case "Cohesion":
                cohesionMinDist = parseAttribute(name, "minDist", element.getAttribute("minDist"));
                cohesionMaxDist = parseAttribute(name, "maxDist", element.getAttribute("maxDist"));
                cohesionScale   = parseAttribute(name, "scalar", element.getAttribute("scalar"));
                break;

            case "Separation":
                separationMinDist = parseAttribute(name, "minDist", element.getAttribute("minDist"));
                separationMaxDist = parseAttribute(name, "maxDist", element.getAttribute("maxDist"));
                separationScale   = parseAttribute(name, "scalar", element.getAttribute("scalar"));
                break;
            }
        }
        //set the sliders current values.
        slider_speed.value = speed;

        slider_alignmentMinDist.value = alignmentMinDist;
        slider_alignmentMaxDist.value = alignmentMaxDist;
        slider_alignmentScale.value   = alignmentScale;

        slider_cohesionMinDist.value = cohesionMinDist;
        slider_cohesionMaxDist.value = cohesionMaxDist;
        slider_cohesionScale.value   = cohesionScale;

        slider_separationMinDist.value = separationMinDist;
        slider_separationMaxDist.value = separationMaxDist;
        slider_separationScale.value   = separationScale;
    }
Exemplo n.º 7
0
 public void addChild(XmlParsedInformation value)
 {
     _children.Add(value);
 }