示例#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 override object Clone()
        {
            ActiveArea aa = (ActiveArea)base.Clone();
            //can not be two identical id
            string id = aa.getId() + "-" + (new System.Random().Next(1000).ToString());

            aa.setId(id);
            aa.conditions    = (conditions != null ? (Conditions)conditions.Clone() : null);
            aa.height        = height;
            aa.width         = width;
            aa.x             = x;
            aa.y             = y;
            aa.influenceArea = (influenceArea != null ? (InfluenceArea)influenceArea.Clone() : null);
            aa.rectangular   = rectangular;
            aa.Vector2s      = (Vector2s != null ? new List <Vector2>() : null);
            foreach (Vector2 p in Vector2s)
            {
                aa.Vector2s.Add(new Vector2(p.x, p.y));
            }
            return(aa);
        }
示例#3
0
 /**
  * Adds an active area
  *
  * @param activeArea
  *            the active area to add
  */
 public void addActiveArea(ActiveArea activeArea)
 {
     activeAreas.Add(activeArea);
 }
示例#4
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);
        }