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;
        }
        public void Write(EntityInfo entity, string filepath)
        {
            XmlTextWriter writer = new XmlTextWriter(filepath, null);
            writer.Formatting = Formatting.Indented;
            writer.Indentation = 1;
            writer.IndentChar = '\t';

            Write(entity, writer);

            writer.Close();
        }
        private void LoadEntity(EntityInfo info)
        {
            if (entities.ContainsKey(info.Name))
                throw new GameEntityException("You have defined two entities both named \"" + info.Name + "\".");

            var entity = new GameEntity();
            entity.Name = info.Name;

            entities[info.Name] = entity;

            entity.IsGravitySensitive = info.GravityFlip;

            if (info.Death != null)
                entity.OnDeath = EffectParser.LoadTriggerEffect(info.Death);

            if (info.SpriteComponent != null)
                LoadSpriteComponent(entity, info.SpriteComponent);

            if (info.PositionComponent != null || info.SpriteComponent != null)
                LoadPositionComponent(entity, info.PositionComponent);

            if (info.MovementComponent != null)
                LoadMovementComponent(info.MovementComponent, entity);

            if (info.InputComponent != null)
                entity.AddComponent(new InputComponent());

            if (info.CollisionComponent != null)
                LoadCollisionComponent(entity, info.CollisionComponent);

            if (info.StateComponent != null)
                LoadStateComponent(entity, info.StateComponent);

            if (info.HealthComponent != null)
                LoadHealthComponent(entity, info.HealthComponent);

            if (info.WeaponComponent != null)
                LoadWeaponComponent(entity, info.WeaponComponent);

            if (info.LadderComponent != null)
                LoadLadderComponent(entity, info.LadderComponent);

            // everyone gets these
            entity.AddComponent(new SoundComponent());
            entity.AddComponent(new TimerComponent());
            entity.AddComponent(new VarsComponent());
        }
Example #4
0
        public void Load(Project project, XElement xmlNode)
        {
            foreach (var node in xmlNode.Elements("Entity"))
            {
                var info = new EntityInfo() {
                    Name = node.RequireAttribute("name").Value,
                    MaxAlive = node.TryAttribute<int>("maxAlive", 50)
                };

                var editorData = node.Element("EditorData");
                if (editorData != null)
                {
                    info.EditorData = new EntityEditorData() {
                        DefaultSpriteName = editorData.TryAttribute<string>("defaultSprite"),
                        HideFromPlacement = editorData.TryAttribute<bool>("hide", false)
                    };
                }

                FilePath sheetPath = null;
                var sheetNode = node.Element("Tilesheet");
                if (sheetNode != null)
                    sheetPath = FilePath.FromRelative(sheetNode.Value, project.BaseDir);

                foreach (var spriteNode in node.Elements("Sprite"))
                {
                    if (sheetPath == null)
                    {
                        var sprite = GameXmlReader.LoadSprite(spriteNode, project.BaseDir);
                        info.Sprites.Add(sprite.Name ?? "Default", sprite);
                    }
                    else
                    {
                        var sprite = GameXmlReader.LoadSprite(spriteNode);
                        sprite.SheetPath = sheetPath;
                        info.Sprites.Add(sprite.Name ?? "Default", sprite);
                    }

                }

                project.AddEntity(info);
            }
        }
        public EntityPlacementControlViewModel(EntityPlacement placement, EntityInfo entityInfo, ScreenDocument screen)
        {
            if (placement == null)
                throw new ArgumentNullException("placement");

            if (entityInfo == null)
                throw new ArgumentNullException("entityInfo");

            if (screen == null)
                throw new ArgumentNullException("screen");

            this.Placement = placement;
            this._entityInfo = entityInfo;
            this._screen = screen;

            DeleteCommand = new RelayCommand(Delete);
            FlipCommand = new RelayCommand(Flip);
            RespawnCommand = new RelayCommand(SetRespawnMode);
            StartStateCommand = new RelayCommand(SetStartState);

            ViewModelMediator.Current.GetEvent<ZoomChangedEventArgs>().Subscribe(ZoomChanged);
        }
        internal void Write(EntityInfo entity, XmlWriter writer)
        {
            writer.WriteStartElement("Entity");
            writer.WriteAttributeString("name", entity.Name);
            writer.WriteAttributeString("maxAlive", entity.MaxAlive.ToString());

            writer.WriteElementString("GravityFlip", entity.GravityFlip.ToString());

            if (entity.EditorData != null)
            {
                writer.WriteStartElement("EditorData");

                if (entity.DefaultSprite != null)
                    writer.WriteAttributeString("defaultSprite", entity.DefaultSprite.Name);

                writer.WriteAttributeString("hide", entity.EditorData.HideFromPlacement.ToString());
                writer.WriteEndElement();
            }

            foreach (var component in entity.Components)
                WritePart(component, writer);

            writer.WriteEndElement();
        }
 public EntityToolBehavior(EntityInfo entity, int snapX, int snapY)
 {
     _entity = entity;
     _snapX = snapX;
     _snapY = snapY;
 }
 private static void ReadEditorData(XElement xmlNode, EntityInfo info)
 {
     var editorData = xmlNode.Element("EditorData");
     if (editorData != null)
     {
         info.EditorData = new EntityEditorData() {
             DefaultSpriteName = editorData.TryAttribute<string>("defaultSprite"),
             HideFromPlacement = editorData.TryAttribute<bool>("hide", false)
         };
     }
 }
        private bool HasMovementEffects(EntityInfo info)
        {
            var parts = info.StateComponent.Triggers.SelectMany(t => t.Trigger.Effect.Parts);
            parts = parts.Concat(info.StateComponent.States.SelectMany(s => s.Initializer.Parts));
            parts = parts.Concat(info.StateComponent.States.SelectMany(s => s.Logic.Parts));
            parts = parts.Concat(info.StateComponent.States.SelectMany(s => s.Triggers.SelectMany(t => t.Effect.Parts)));

            return parts.OfType<MovementEffectPartInfo>().Any();
        }
 public void SaveEntity(EntityInfo entity, string path)
 {
     var writer = _writerProvider.GetEntityWriter();
     writer.Write(entity, path);
 }
Example #11
0
 public void RemoveEntity(EntityInfo entity)
 {
     _entities.Remove(entity);
 }
Example #12
0
 public void AddEntity(EntityInfo entity)
 {
     _entities.Add(entity);
 }
Example #13
0
 public void RemoveEntity(EntityInfo entity, Point location)
 {
     screen.Layers[0].Entities.RemoveAll(i =>
         i.entity == entity.Name && i.screenX == location.X && i.screenY == location.Y
     );
     Dirty = true;
     if (EntitiesChanged != null) EntitiesChanged();
 }
Example #14
0
        public EntityPlacement AddEntity(EntityInfo entity, Point location)
        {
            var info = new EntityPlacement {
                entity = entity.Name,
                screenX = location.X,
                screenY = location.Y,
            };

            screen.Layers[0].Entities.Add(info);

            Dirty = true;

            return info;
        }
Example #15
0
 public EntityToolBehavior(EntityInfo entity)
 {
     _entity = entity;
 }
Example #16
0
        public static SpriteModel ForEntity(EntityInfo entity, ProjectDocument project)
        {
            var hasSprites = entity.SpriteComponent != null && entity.SpriteComponent.Sprites.Any();

            if (!hasSprites)
            {
                var allEffectParts = entity.StateComponent.States.SelectMany(s => s.Initializer.Parts.Concat(s.Logic.Parts).Concat(s.Triggers.SelectMany(t => t.Effect.Parts)));
                var spawn = allEffectParts.OfType<SpawnEffectPartInfo>().Select(s => s.Name).FirstOrDefault();
                if (spawn != null)
                {
                    var spawnEntity = project.EntityByName(spawn);
                    return new OverlaySpriteModel(spawnEntity.DefaultSprite, "spawn.png");
                }
            }

            return new SpriteModel(entity.DefaultSprite);
        }
 public EntityViewModel(EntityInfo entity, ProjectDocument project)
 {
     _entity = entity;
     _project = project;
 }