예제 #1
0
        public object DOMParse(XmlElement element, params object[] parameters)
        {
            XmlNodeList points       = element.SelectNodes("point"),
                        descriptions = element.SelectNodes("description");
            XmlElement conditions    = element.SelectSingleNode("condition") as XmlElement,
                       actionss      = element.SelectSingleNode("actions") as XmlElement,
                       documentation = element.SelectSingleNode("documentation") as XmlElement;

            string id          = element.GetAttribute("id") ?? null;
            bool   rectangular = (element.GetAttribute("rectangular") ?? "yes").Equals("yes");

            int x      = ExParsers.ParseDefault(element.GetAttribute("x"), 0),
                y      = ExParsers.ParseDefault(element.GetAttribute("y"), 0),
                width  = ExParsers.ParseDefault(element.GetAttribute("width"), 0),
                height = ExParsers.ParseDefault(element.GetAttribute("height"), 0);

            bool hasInfluence    = "yes".Equals(element.GetAttribute("hasInfluenceArea"));
            int  influenceX      = ExParsers.ParseDefault(element.GetAttribute("influenceX"), 0),
                 influenceY      = ExParsers.ParseDefault(element.GetAttribute("influenceY"), 0),
                 influenceWidth  = ExParsers.ParseDefault(element.GetAttribute("influenceWidth"), 0),
                 influenceHeight = ExParsers.ParseDefault(element.GetAttribute("influenceHeight"), 0);

            ActiveArea activeArea = new ActiveArea((id == null ? generateId() : id), rectangular, x, y, width, height);

            if (hasInfluence)
            {
                InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                activeArea.setInfluenceArea(influenceArea);
            }

            if (documentation != null)
            {
                activeArea.setDocumentation(documentation.InnerText);
            }

            activeArea.setDescriptions(DOMParserUtility.DOMParse <Description> (descriptions, parameters).ToList());

            foreach (XmlElement el in points)
            {
                if (activeArea != null)
                {
                    activeArea.addVector2(
                        new Vector2(ExParsers.ParseDefault(el.GetAttribute("x"), 0),
                                    ExParsers.ParseDefault(el.GetAttribute("y"), 0)));
                }
            }
            if (actionss != null)
            {
                activeArea.setActions(DOMParserUtility.DOMParse <Action>(actionss.ChildNodes, parameters).ToList());
            }
            if (conditions != null)
            {
                activeArea.setConditions(DOMParserUtility.DOMParse(conditions, parameters) as Conditions ?? new Conditions());
            }

            return(activeArea);
        }
예제 #2
0
        public object DOMParse(XmlElement element, params object[] parameters)
        {
            XmlNodeList points       = element.SelectNodes("point"),
                        descriptions = element.SelectNodes("description");
            XmlElement conditions    = element.SelectSingleNode("condition") as XmlElement,
                       actions       = element.SelectSingleNode("actions") as XmlElement,
                       documentation = element.SelectSingleNode("documentation") as XmlElement;

            string id          = ExString.Default(element.GetAttribute("id"), null);
            bool   rectangular = ExString.EqualsDefault(element.GetAttribute("rectangular"), "yes", true);

            int x      = ExParsers.ParseDefault(element.GetAttribute("x"), 0),
                y      = ExParsers.ParseDefault(element.GetAttribute("y"), 0),
                width  = ExParsers.ParseDefault(element.GetAttribute("width"), 0),
                height = ExParsers.ParseDefault(element.GetAttribute("height"), 0);

            bool hasInfluence    = ExString.EqualsDefault(element.GetAttribute("hasInfluenceArea"), "yes", false);
            int  influenceX      = ExParsers.ParseDefault(element.GetAttribute("influenceX"), 0),
                 influenceY      = ExParsers.ParseDefault(element.GetAttribute("influenceY"), 0),
                 influenceWidth  = ExParsers.ParseDefault(element.GetAttribute("influenceWidth"), 0),
                 influenceHeight = ExParsers.ParseDefault(element.GetAttribute("influenceHeight"), 0);


            var activeArea = new ActiveArea((id ?? generateId()), rectangular, x, y, width, height);

            switch (element.GetAttribute("behaviour"))
            {
            case "atrezzo":      activeArea.setBehaviour(Item.BehaviourType.ATREZZO);      break;

            case "first-action": activeArea.setBehaviour(Item.BehaviourType.FIRST_ACTION); break;

            default:             activeArea.setBehaviour(Item.BehaviourType.NORMAL);       break;
            }

            if (hasInfluence)
            {
                var influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight);
                activeArea.setInfluenceArea(influenceArea);
            }

            if (documentation != null)
            {
                activeArea.setDocumentation(documentation.InnerText);
            }

            activeArea.setDescriptions(DOMParserUtility.DOMParse <Description> (descriptions, parameters).ToList());

            foreach (XmlElement el in points)
            {
                activeArea.addVector2(
                    new Vector2(ExParsers.ParseDefault(el.GetAttribute("x"), 0),
                                ExParsers.ParseDefault(el.GetAttribute("y"), 0)));
            }

            if (actions != null)
            {
                activeArea.setActions(DOMParserUtility.DOMParse <Action>(actions.ChildNodes, parameters).ToList());
            }
            if (conditions != null)
            {
                activeArea.setConditions(DOMParserUtility.DOMParse(conditions, parameters) as Conditions ?? new Conditions());
            }

            return(activeArea);
        }