Example #1
0
        public static Effect LoadSpawnEffect(XElement node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            string name      = node.RequireAttribute("name").Value;
            string statename = "Start";

            if (node.Attribute("state") != null)
            {
                statename = node.Attribute("state").Value;
            }
            XElement posNodeX = node.Element("X");
            XElement posNodeY = node.Element("Y");
            Effect   posEff   = null;

            if (posNodeX != null)
            {
                posEff = PositionComponent.ParsePositionBehavior(posNodeX, Axis.X);
            }
            if (posNodeY != null)
            {
                posEff += PositionComponent.ParsePositionBehavior(posNodeY, Axis.Y);
            }
            return(entity =>
            {
                GameEntity spawn = entity.Spawn(name);
                if (spawn == null)
                {
                    return;
                }
                StateMessage msg = new StateMessage(entity, statename);
                spawn.SendMessage(msg);
                if (posEff != null)
                {
                    posEff(spawn);
                }
            });
        }