Пример #1
2
        private SoundInfo LoadSound(XElement soundNode, string basePath)
        {
            SoundInfo sound = new SoundInfo { Name = soundNode.RequireAttribute("name").Value };

            sound.Loop = soundNode.TryAttribute<bool>("loop");

            sound.Volume = soundNode.TryAttribute<float>("volume", 1);

            XAttribute pathattr = soundNode.Attribute("path");
            XAttribute trackAttr = soundNode.Attribute("track");
            if (pathattr != null)
            {
                sound.Type = AudioType.Wav;
                sound.Path = FilePath.FromRelative(pathattr.Value, basePath);
            }
            else if (trackAttr != null)
            {
                sound.Type = AudioType.NSF;

                int track;
                if (!trackAttr.Value.TryParse(out track) || track <= 0) throw new GameXmlException(trackAttr, "Sound track attribute must be an integer greater than zero.");
                sound.NsfTrack = track;

                sound.Priority = soundNode.TryAttribute<byte>("priority", 100);
            }
            else
            {
                sound.Type = AudioType.Unknown;
            }

            return sound;
        }
        public EntityPlacement Load(XElement node)
        {
            EntityPlacement info = new EntityPlacement();

            info.Id = node.TryAttribute("id", Guid.NewGuid().ToString());

            info.entity = node.TryAttribute("name", node.GetAttribute<string>("entity"));

            info.state = node.TryAttribute("state", "Start");

            info.screenX = node.GetAttribute<int>("x");
            info.screenY = node.GetAttribute<int>("y");

            var dirAttr = node.Attribute("direction");
            if (dirAttr != null)
            {
                Direction dir = Direction.Left;
                Enum.TryParse<Direction>(dirAttr.Value, true, out dir);
                info.direction = dir;
            }

            var respawnAttr = node.Attribute("respawn");
            if (respawnAttr != null)
            {
                RespawnBehavior respawn = RespawnBehavior.Offscreen;
                Enum.TryParse<RespawnBehavior>(respawnAttr.Value, true, out respawn);
                info.respawn = respawn;
            }

            return info;
        }
Пример #3
0
        public static SceneAutoscrollCommandInfo LoadAutoscrollCommand(XElement node)
        {
            var info = new SceneAutoscrollCommandInfo();

            info.Speed = node.TryAttribute<double>("speed", 1);
            info.StartX = node.TryAttribute<int>("startX", 128);

            return info;
        }
Пример #4
0
        public RangeFilter LoadRangeFilter(XElement node)
        {
            if (node == null)
                return null;

            return new RangeFilter() {
                Min = node.TryAttribute<float?>("min"),
                Max = node.TryAttribute<float?>("max")
            };
        }
        private VelocityEffectInfo LoadVelocity(XElement prop)
        {
            if (prop == null)
                return null;

            var dir = prop.TryAttribute<string>("direction", "Same");
            return new VelocityEffectInfo() {
                Magnitude = prop.TryAttribute<float?>("magnitude"),
                MagnitudeVarName = prop.TryAttribute<string>("magnitudeVar"),
                Direction = (MovementEffectDirection)Enum.Parse(typeof(MovementEffectDirection), dir)
            };
        }
        public SceneCommandInfo Load(XElement node, string basePath)
        {
            var info = new ScenePlayCommandInfo();

            info.Track = node.TryAttribute<int>("nsftrack", node.TryAttribute<int>("track"));

            XElement intro = node.Element("Intro");
            XElement loop = node.Element("Loop");
            info.IntroPath = (intro != null) ? FilePath.FromRelative(intro.Value, basePath) : null;
            info.LoopPath = (loop != null) ? FilePath.FromRelative(loop.Value, basePath) : null;

            return info;
        }
        public IComponentInfo Load(XElement node, Project project)
        {
            var component = new CollisionComponentInfo();

            foreach (var boxnode in node.Elements("Hitbox"))
            {
                var box = GetHitbox(boxnode);

                foreach (var groupnode in boxnode.Elements("Hits"))
                    box.Hits.Add(groupnode.Value);

                foreach (var groupnode in boxnode.Elements("Group"))
                    box.Groups.Add(groupnode.Value);

                foreach (var resistNode in boxnode.Elements("Resist"))
                {
                    var resistName = resistNode.GetAttribute<string>("name");
                    float mult = resistNode.GetAttribute<float>("multiply");
                    box.Resistance.Add(resistName, mult);
                }

                component.HitBoxes.Add(box);
            }

            component.Enabled = node.TryAttribute<bool>("Enabled");

            return component;
        }
Пример #8
0
        private static MenuStateInfo LoadMenuState(XElement node, string basePath)
        {
            var info = new MenuStateInfo();

            info.Name = node.RequireAttribute("name").Value;

            info.Fade = node.TryAttribute<bool>("fade");

            var startNode = node.Element("SelectOption");
            if (startNode != null)
            {
                var startNameAttr = startNode.Attribute("name");
                var startVarAttr = startNode.Attribute("var");

                if (startNameAttr != null)
                {
                    info.StartOptionName = startNameAttr.Value;
                }

                if (startVarAttr != null)
                {
                    info.StartOptionVar = startVarAttr.Value;
                }
            }

            info.Commands = LoadCommands(node, basePath);

            return info;
        }
 public IEffectPartInfo Load(XElement partNode)
 {
     return new AddInventoryEffectPartInfo() {
         ItemName = partNode.RequireAttribute("item").Value,
         Quantity = partNode.TryAttribute<int>("quantity", 1)
     };
 }
        public SceneCommandInfo Load(XElement node, string basePath)
        {
            var info = new SceneTextCommandInfo();
            info.Content = node.TryAttribute<string>("content");
            info.Name = node.TryAttribute<string>("name");
            info.Speed = node.TryAttribute<int>("speed");
            info.X = node.GetAttribute<int>("x");
            info.Y = node.GetAttribute<int>("y");

            var bindingNode = node.Element("Binding");
            if (bindingNode != null) info.Binding = _bindingReader.Load(bindingNode);

            info.Font = node.TryAttribute<string>("font");

            return info;
        }
Пример #11
0
        public IIncludedObject Load(Project project, XElement xmlNode)
        {
            var info = new EntityInfo() {
                Name = xmlNode.RequireAttribute("name").Value,
                MaxAlive = xmlNode.TryAttribute<int>("maxAlive", 50),
                GravityFlip = xmlNode.TryElementValue<bool>("GravityFlip"),
                Components = new List<IComponentInfo>()
            };

            ReadEditorData(xmlNode, info);

            var deathNode = xmlNode.Element("Death");
            if (deathNode != null)
                info.Death = _effectReader.Load(deathNode);

            foreach (var compReader in ComponentReaders)
            {
                var element = compReader.NodeName != null ? xmlNode.Element(compReader.NodeName) : xmlNode;
                if (element != null)
                {
                    var comp = compReader.Load(element, project);
                    if (comp != null)
                        info.Components.Add(comp);
                }
            }

            if (info.PositionComponent == null)
                info.Components.Add(new PositionComponentInfo());

            if (info.MovementComponent == null && HasMovementEffects(info))
                info.Components.Add(new MovementComponentInfo() { EffectInfo = new MovementEffectPartInfo() });

            project.AddEntity(info);
            return info;
        }
        private static HitBoxInfo GetHitbox(XElement boxnode)
        {
            float width = boxnode.GetAttribute<float>("width");
            float height = boxnode.GetAttribute<float>("height");
            float x = boxnode.GetAttribute<float>("x");
            float y = boxnode.GetAttribute<float>("y");

            var box = new HitBoxInfo() {
                Name = boxnode.TryAttribute<string>("name"),
                Box = new Common.Geometry.RectangleF(x, y, width, height),
                ContactDamage = boxnode.TryAttribute<float>("damage"),
                Environment = boxnode.TryAttribute<bool>("environment", true),
                PushAway = boxnode.TryAttribute<bool>("pushaway", true),
                PropertiesName = boxnode.TryAttribute<string>("properties", "Default")
            };
            return box;
        }
        public IComponentInfo Load(XElement node, Project project)
        {
            var comp = new HealthComponentInfo();
            comp.Max = node.TryAttribute<float>("max", node.TryElementValue<float>("Max"));

            comp.StartValue = node.TryAttribute<float?>("startValue");

            XElement meterNode = node.Element("Meter");
            if (meterNode != null)
            {
                comp.Meter = _meterReader.LoadMeter(meterNode, project.BaseDir);
            }

            comp.FlashFrames = node.TryAttribute("flash", node.TryElementValue<int>("Flash"));

            return comp;
        }
        public IEffectPartInfo Load(XElement partNode)
        {
            var info = new SpawnEffectPartInfo();
            info.Name = partNode.GetAttribute<string>("name");
            info.State = partNode.TryAttribute<string>("state", "Start");

            info.Position = (PositionEffectPartInfo)_positionReader.Load(partNode);

            return info;
        }
Пример #15
0
        public CollisionBox(XElement xmlNode)
            : base(xmlNode)
        {
            ID = nextID;
            nextID++;

            Hits = new List<string>();
            Groups = new List<string>();
            resistance = new Dictionary<string, float>();
            Properties = TileProperties.Default;

            foreach (XElement groupnode in xmlNode.Elements("Hits"))
            {
                Hits.Add(groupnode.Value);
            }

            foreach (XElement groupnode in xmlNode.Elements("Group"))
            {
                Groups.Add(groupnode.Value);
            }

            foreach (XElement resistNode in xmlNode.Elements("Resist"))
            {
                XAttribute nameAttr = resistNode.RequireAttribute("name");

                float mult = resistNode.GetAttribute<float>("multiply");

                resistance.Add(nameAttr.Value, mult);
            }

            XAttribute boxnameAttr = xmlNode.Attribute("name");
            if (boxnameAttr != null) Name = boxnameAttr.Value;

            ContactDamage = xmlNode.TryAttribute<float>("damage");

            Environment = xmlNode.TryAttribute<bool>("environment", true);

            PushAway = xmlNode.TryAttribute<bool>("pushaway", true);

            XAttribute propAttr = xmlNode.Attribute("properties");
            if (propAttr != null) Properties = Game.CurrentGame.TileProperties.GetProperties(propAttr.Value);
        }
        public HandlerTransfer Load(XElement node)
        {
            HandlerTransfer transfer = new HandlerTransfer();

            var modeAttr = node.Attribute("mode");
            var mode = HandlerMode.Next;
            if (modeAttr != null)
            {
                Enum.TryParse<HandlerMode>(modeAttr.Value, true, out mode);
            }

            transfer.Mode = mode;

            if (mode == HandlerMode.Push)
            {
                transfer.Pause = node.TryAttribute<bool>("pause");
            }

            if (mode != HandlerMode.Pop)
            {
                switch (node.RequireAttribute("type").Value.ToLower())
                {
                    case "stage":
                        transfer.Type = HandlerType.Stage;
                        break;

                    case "scene":
                        transfer.Type = HandlerType.Scene;
                        break;

                    case "menu":
                        transfer.Type = HandlerType.Menu;
                        break;
                }

                transfer.Name = node.RequireAttribute("name").Value;
            }

            transfer.Fade = node.TryAttribute<bool>("fade");

            return transfer;
        }
        public SceneCommandInfo Load(XElement node, string basePath)
        {
            var info = new SceneMoveCommandInfo();
            info.Name = node.RequireAttribute("name").Value;

            info.Duration = node.TryAttribute<int>("duration");

            info.X = node.GetAttribute<int>("x");
            info.Y = node.GetAttribute<int>("y");
            return info;
        }
Пример #18
0
 public static Effect ParseEffect(XElement effectNode)
 {
     if (effectNode.Attribute("change") != null)
     {
         float changeval = effectNode.TryAttribute<float>("change");
         return entity =>
         {
             entity.GetComponent<HealthComponent>().Health += changeval;
         };
     }
     return entity => { };
 }
Пример #19
0
        public static Effect ParseEffect(XElement node)
        {
            string soundname = node.RequireAttribute("name").Value;
            bool playing = node.TryAttribute<bool>("playing", true);

            return entity =>
            {
                entity.GetOrCreateComponent("Sound");
                SoundMessage msg = new SoundMessage(entity, soundname, playing);
                entity.SendMessage(msg);
            };
        }
Пример #20
0
        private KeyFrameInfo LoadKeyFrame(XElement node, string basePath)
        {
            var info = new KeyFrameInfo();

            info.Frame = node.GetAttribute<int>("frame");

            info.Fade = node.TryAttribute<bool>("fade");

            info.Commands = _commandReader.LoadCommands(node, basePath);

            return info;
        }
Пример #21
0
        public MeterInfo LoadMeter(XElement meterNode, string basePath)
        {
            MeterInfo meter = new MeterInfo();

            meter.Name = meterNode.TryAttribute<string>("name") ?? "";

            meter.Position = new PointF(meterNode.GetAttribute<float>("x"), meterNode.GetAttribute<float>("y"));

            XAttribute imageAttr = meterNode.RequireAttribute("image");
            meter.TickImage = FilePath.FromRelative(imageAttr.Value, basePath);

            XAttribute backAttr = meterNode.Attribute("background");
            if (backAttr != null)
            {
                meter.Background = FilePath.FromRelative(backAttr.Value, basePath);
            }

            bool horiz = false;
            XAttribute dirAttr = meterNode.Attribute("orientation");
            if (dirAttr != null)
            {
                horiz = (dirAttr.Value == "horizontal");
            }
            meter.Orient = horiz ? MegaMan.Common.MeterInfo.Orientation.Horizontal : MegaMan.Common.MeterInfo.Orientation.Vertical;

            int x = meterNode.TryAttribute<int>("tickX");
            int y = meterNode.TryAttribute<int>("tickY");

            meter.TickOffset = new Point(x, y);

            XElement soundNode = meterNode.Element("Sound");
            if (soundNode != null) meter.Sound = IncludeFileXmlReader.LoadSound(soundNode, basePath);

            XElement bindingNode = meterNode.Element("Binding");
            if (bindingNode != null) meter.Binding = _bindingReader.Load(bindingNode);

            return meter;
        }
 public SceneCommandInfo Load(XElement node, string basePath)
 {
     var info = new SceneFillCommandInfo();
     var nameAttr = node.Attribute("name");
     if (nameAttr != null) info.Name = nameAttr.Value;
     var colorAttr = node.RequireAttribute("color");
     var color = colorAttr.Value;
     var split = color.Split(',');
     info.Red = byte.Parse(split[0]);
     info.Green = byte.Parse(split[1]);
     info.Blue = byte.Parse(split[2]);
     info.X = node.GetAttribute<int>("x");
     info.Y = node.GetAttribute<int>("y");
     info.Width = node.GetAttribute<int>("width");
     info.Height = node.GetAttribute<int>("height");
     info.Layer = node.TryAttribute<int>("layer");
     return info;
 }
Пример #23
0
        internal EffectInfo Load(XElement effectNode)
        {
            var info = new EffectInfo();
            info.Name = effectNode.TryAttribute<string>("name");

            var filterNode = effectNode.Element("EntityFilter");
            if (filterNode != null)
            {
                info.Filter = new EntityFilterInfo() {
                    Type = filterNode.TryElementValue<string>("Type")
                };

                var direction = filterNode.TryElementValue<string>("Direction");
                if (direction != null)
                {
                    try
                    {
                        info.Filter.Direction = (Direction)Enum.Parse(typeof(Direction), direction, true);
                    }
                    catch
                    {
                        throw new GameXmlException(filterNode, "Entity filter direction was not valid.");
                    }
                }

                var positionNode = filterNode.Element("Position");
                if (positionNode != null)
                {
                    info.Filter.Position = new PositionFilter() {
                        X = LoadRangeFilter(positionNode.Element("X")),
                        Y = LoadRangeFilter(positionNode.Element("Y"))
                    };
                }
            }

            var parts = new List<IEffectPartInfo>();

            foreach (var node in effectNode.Elements().Where(e => e.Name != "EntityFilter"))
                parts.Add(LoadPart(node));

            info.Parts = parts;

            return info;
        }
Пример #24
0
        public static EntityPlacement LoadEntityPlacement(XElement entity)
        {
            EntityPlacement info = new EntityPlacement();

            info.Id = entity.TryAttribute<string>("id", Guid.NewGuid().ToString());

            var nameAttr = entity.Attribute("name");
            if (nameAttr == null)
                nameAttr = entity.RequireAttribute("entity");

            info.entity = nameAttr.Value;

            string state = "Start";
            XAttribute stateAttr = entity.Attribute("state");
            if (stateAttr != null) state = stateAttr.Value;
            info.state = state;

            info.screenX = entity.GetAttribute<int>("x");
            info.screenY = entity.GetAttribute<int>("y");

            var dirAttr = entity.Attribute("direction");
            if (dirAttr != null)
            {
                Direction dir = Direction.Left;
                Enum.TryParse<Direction>(dirAttr.Value, true, out dir);
                info.direction = dir;
            }

            var respawnAttr = entity.Attribute("respawn");
            if (respawnAttr != null)
            {
                RespawnBehavior respawn = RespawnBehavior.Offscreen;
                Enum.TryParse<RespawnBehavior>(respawnAttr.Value, true, out respawn);
                info.respawn = respawn;
            }

            return info;
        }
Пример #25
0
        public void Load(Project project, XElement node)
        {
            var scene = new SceneInfo();

            LoadHandlerBase(scene, node, project.BaseDir);

            scene.Duration = node.GetAttribute<int>("duration");

            scene.CanSkip = node.TryAttribute<bool>("canskip");

            foreach (var keyNode in node.Elements("Keyframe"))
            {
                scene.KeyFrames.Add(LoadKeyFrame(keyNode, project.BaseDir));
            }

            var transferNode = node.Element("Next");
            if (transferNode != null)
            {
                scene.NextHandler = LoadHandlerTransfer(transferNode);
            }

            project.AddScene(scene);
        }
Пример #26
0
        public TriggerInfo Load(XElement triggerNode)
        {
            string conditionString;
            if (triggerNode.Attribute("condition") != null)
                conditionString = triggerNode.GetAttribute<string>("condition");
            else
                conditionString = triggerNode.Element("Condition").Value;

            var effectNode = triggerNode.Element("Effect");
            var effect = _effectReader.Load(effectNode);

            var elseNode = triggerNode.Element("Else");
            var elseEffect = (elseNode != null) ? _effectReader.Load(elseNode) : null;

            var priority = triggerNode.TryAttribute<int?>("priority");

            return new TriggerInfo() {
                Condition = conditionString,
                Effect = effect,
                Else = elseEffect,
                Priority = priority
            };
        }
 public IComponentInfo Load(XElement node, Project project)
 {
     var posInfo = new PositionComponentInfo();
     posInfo.PersistOffscreen = node.TryAttribute<bool>("persistoffscreen");
     return posInfo;
 }
Пример #28
0
        public static Effect LoadEffectAction(XElement node)
        {
            Effect effect = e => { };

            switch (node.Name.LocalName)
            {
                case "Call":
                    effect = GetLateBoundEffect(node.Value);
                    break;

                case "Spawn":
                    effect = LoadSpawnEffect(node);
                    break;

                case "Remove":
                    effect = entity => { entity.Remove(); };
                    break;

                case "Die":
                    effect = entity => { entity.Die(); };
                    break;

                case "AddInventory":
                    string itemName = node.RequireAttribute("item").Value;
                    int quantity = node.TryAttribute<int>("quantity", 1);

                    effect = entity =>
                    {
                        Game.CurrentGame.Player.CollectItem(itemName, quantity);
                    };
                    break;

                case "RemoveInventory":
                    string itemNameUse = node.RequireAttribute("item").Value;
                    int quantityUse = node.TryAttribute<int>("quantity", 1);

                    effect = entity =>
                    {
                        Game.CurrentGame.Player.UseItem(itemNameUse, quantityUse);
                    };
                    break;

                case "UnlockWeapon":
                    string weaponName = node.RequireAttribute("name").Value;

                    effect = entity =>
                    {
                        Game.CurrentGame.Player.UnlockWeapon(weaponName);
                    };
                    break;

                case "DefeatBoss":
                    string name = node.RequireAttribute("name").Value;

                    effect = entity =>
                    {
                        Game.CurrentGame.Player.DefeatBoss(name);
                    };
                    break;

                case "Lives":
                    int add = int.Parse(node.RequireAttribute("add").Value);
                    effect = entity =>
                    {
                        Game.CurrentGame.Player.Lives += add;
                    };
                    break;

                case "GravityFlip":
                    bool flip = node.GetValue<bool>();
                    effect = entity => { entity.Container.IsGravityFlipped = flip; };
                    break;

                case "Func":
                    effect = entity => { };
                    string[] statements = node.Value.Split(';');
                    foreach (string st in statements.Where(st => !string.IsNullOrEmpty(st.Trim())))
                    {
                        LambdaExpression lambda = System.Linq.Dynamic.DynamicExpression.ParseLambda(
                            new[] { posParam, moveParam, sprParam, inputParam, collParam, ladderParam, timerParam, healthParam, stateParam, weaponParam, playerParam },
                            typeof(SplitEffect),
                            null,
                            st,
                            dirDict);
                        effect += CloseEffect((SplitEffect)lambda.Compile());
                    }
                    break;

                case "Trigger":
                    string conditionString;
                    if (node.Attribute("condition") != null) conditionString = node.RequireAttribute("condition").Value;
                    else conditionString = node.Element("Condition").Value;

                    Condition condition = ParseCondition(conditionString);
                    Effect triggerEffect = LoadTriggerEffect(node.Element("Effect"));
                    effect += (e) =>
                    {
                        if (condition(e)) triggerEffect(e);
                    };
                    break;

                case "Pause":
                    effect = entity => { entity.Paused = true; };
                    break;

                case "Unpause":
                    effect = entity => { entity.Paused = false; };
                    break;

                case "Next":
                    var transfer = GameXmlReader.LoadHandlerTransfer(node);
                    effect = e => { Game.CurrentGame.ProcessHandler(transfer); };
                    break;

                case "Palette":
                    var paletteName = node.RequireAttribute("name").Value;
                    var paletteIndex = node.GetAttribute<int>("index");
                    effect = e =>
                    {
                        var palette = PaletteSystem.Get(paletteName);
                        if (palette != null)
                        {
                            palette.CurrentIndex = paletteIndex;
                        }
                    };
                    break;

                case "Delay":
                    var delayFrames = node.GetAttribute<int>("frames");
                    var delayEffect = LoadEffect(node);
                    effect = e =>
                    {
                        Engine.Instance.DelayedCall(() => delayEffect(e), null, delayFrames);
                    };
                    break;

                case "SetVar":
                    var varname = node.RequireAttribute("name").Value;
                    var value = node.RequireAttribute("value").Value;
                    effect = e =>
                    {
                        Game.CurrentGame.Player.SetVar(varname, value);
                    };
                    break;

                default:
                    effect = GameEntity.ParseComponentEffect(node);
                    break;
            }
            return effect;
        }
Пример #29
0
        public override void LoadXml(XElement node)
        {
            XElement maxNode = node.Element("Max");
            if (maxNode != null)
            {
                maxHealth = maxNode.GetValue<float>();
            }

            StartHealth = node.TryAttribute<float>("startValue", MaxHealth);

            XElement meterNode = node.Element("Meter");
            if (meterNode != null)
            {
                var meterInfo = HandlerXmlReader.LoadMeter(meterNode, Game.CurrentGame.BasePath);
                meter = HealthMeter.Create(meterInfo, true);
                meter.MaxValue = maxHealth;
                meter.IsPlayer = (Parent.Name == "Player");
            }

            XElement flashNode = node.Element("Flash");
            if (flashNode != null)
            {
                flashtime = flashNode.TryValue<int>();
            }
        }
Пример #30
0
        private static Effect ParseMovementBehavior(XElement prop, Axis axis)
        {
            Effect action;

            float? mag = prop.TryAttribute<float?>("magnitude");

            if (mag != 0)
            {
                XAttribute dirattr = prop.Attribute("direction");
                string direction;
                direction = dirattr == null ? "Same" : dirattr.Value;
                switch (direction)
                {
                    case "Up":
                        action = entity =>
                        {
                            MovementComponent mov = entity.GetComponent<MovementComponent>();
                            if (mov != null) mov.VelocityY = -1 * (mag?? Math.Abs(mov.VelocityY));
                        };
                        break;

                    case "Down":
                        action = entity =>
                        {
                            MovementComponent mov = entity.GetComponent<MovementComponent>();
                            if (mov != null) mov.VelocityY = (mag?? Math.Abs(mov.VelocityY));
                        };
                        break;

                    case "Left":
                        action = entity =>
                        {
                            MovementComponent mov = entity.GetComponent<MovementComponent>();
                            if (mov != null) mov.VelocityX = -mag?? -1 * Math.Abs(mov.VelocityX);
                        };
                        break;

                    case "Right":
                        action = entity =>
                        {
                            MovementComponent mov = entity.GetComponent<MovementComponent>();
                            if (mov != null) mov.VelocityX = mag?? Math.Abs(mov.VelocityX);
                        };
                        break;

                    case "Same":
                        action = entity =>
                        {
                            if (mag == null) return;
                            float fmag = mag ?? 0;

                            MovementComponent mov = entity.GetComponent<MovementComponent>();
                            if (mov == null) return;
                            Direction dir = mov.Direction;

                            if (axis != Axis.Y) mov.VelocityX = (dir == Direction.Right) ? fmag : ((dir == Direction.Left) ? -fmag : 0);
                            if (axis != Axis.X) mov.VelocityY = (dir == Direction.Down) ? fmag : ((dir == Direction.Up) ? -fmag : 0);
                        };
                        break;

                    case "Reverse":
                        action = entity =>
                        {
                            if (mag == null) return;
                            float fmag = mag ?? 0;

                            MovementComponent mov = entity.GetComponent<MovementComponent>();
                            if (mov == null) return;
                            Direction dir = mov.Direction;

                            if (axis != Axis.Y) mov.VelocityX = (dir == Direction.Left) ? fmag : ((dir == Direction.Right) ? -fmag : 0);
                            if (axis != Axis.X) mov.VelocityY = (dir == Direction.Up) ? fmag : ((dir == Direction.Down) ? -fmag : 0);
                        };
                        break;

                    case "Inherit":
                        action = entity =>
                        {
                            MovementComponent mov = entity.GetComponent<MovementComponent>();
                            if (mov == null) return;
                            if (entity.Parent != null)
                            {
                                Direction dir = entity.Parent.Direction;

                                if (axis != Axis.Y) mov.VelocityX = (dir == Direction.Right) ? (mag?? Math.Abs(mov.VelocityX)) : ((dir == Direction.Left) ? (-mag?? -1 * Math.Abs(mov.VelocityX)) : 0);
                                if (axis != Axis.X) mov.VelocityY = (dir == Direction.Down) ? (mag?? Math.Abs(mov.VelocityY)) : ((dir == Direction.Up) ? (-mag?? -1 * Math.Abs(mov.VelocityY)) : 0);
                            }
                            else mov.VelocityY = 0;
                        };
                        break;

                    case "Input":
                        action = entity =>
                        {
                            MovementComponent mov = entity.GetComponent<MovementComponent>();
                            InputComponent input = entity.GetComponent<InputComponent>();
                            if (mov == null || input == null) return;

                            if (axis != Axis.Y)
                            {
                                if (input.Left) mov.VelocityX = -mag?? -1 * Math.Abs(mov.VelocityX);
                                else if (input.Right) mov.VelocityX = mag?? Math.Abs(mov.VelocityX);
                            }
                            if (axis != Axis.X)
                            {
                                if (input.Down) mov.VelocityY = mag?? Math.Abs(mov.VelocityY);
                                else if (input.Up) mov.VelocityY = -mag?? -1 * Math.Abs(mov.VelocityY);
                                else mov.VelocityY = 0;
                            }
                        };
                        break;

                    case "Player":
                        action = entity =>
                        {
                            MovementComponent mov = entity.GetComponent<MovementComponent>();
                            PositionComponent pos = entity.GetComponent<PositionComponent>();
                            if (mov == null || pos == null) return;

                            GameEntity player = entity.Entities.GetEntityById("Player");
                            PositionComponent playerPos = player.GetComponent<PositionComponent>();

                            if (axis == Axis.X)
                            {
                                if (pos.Position.X > playerPos.Position.X) mov.VelocityX = -mag?? -1 * Math.Abs(mov.VelocityX);
                                else if (pos.Position.X < playerPos.Position.X) mov.VelocityX = mag?? Math.Abs(mov.VelocityX);
                            }
                            else if (axis == Axis.Y)
                            {
                                if (pos.Position.Y > playerPos.Position.Y) mov.VelocityY = -mag?? -1 * Math.Abs(mov.VelocityY);
                                else if (pos.Position.Y < playerPos.Position.Y) mov.VelocityY = mag?? Math.Abs(mov.VelocityY);
                            }
                            else
                            {
                                float dx = playerPos.Position.X - pos.Position.X;
                                float dy = playerPos.Position.Y - pos.Position.Y;
                                double hyp = Math.Pow(dx, 2) + Math.Pow(dy, 2);
                                hyp = Math.Pow(hyp, 0.5);

                                mov.VelocityX = (float)(mag * dx / hyp);
                                mov.VelocityY = (float)(mag * dy / hyp);
                            }
                        };
                        break;

                    default: action = new Effect(entity => { }); break;
                }
            }
            else
            {
                if (axis == Axis.X) action = entity =>
                {
                    MovementComponent mov = entity.GetComponent<MovementComponent>();
                    if (mov != null) mov.VelocityX = 0;
                };
                else action = entity =>
                {
                    MovementComponent mov = entity.GetComponent<MovementComponent>();
                    if (mov != null) mov.VelocityY = 0;
                };
            }

            return action;
        }