public IComponentInfo Load(XElement node, Project project) { var spriteComponent = new SpriteComponentInfo(); FilePath sheetPath = null; var sheetNode = node.Element("Tilesheet"); if (sheetNode != null) { sheetPath = FilePath.FromRelative(sheetNode.Value, project.BaseDir); spriteComponent.SheetPath = sheetPath; } foreach (var spriteNode in node.Elements("Sprite")) { if (sheetPath == null) { var sprite = _spriteReader.LoadSprite(spriteNode, project.BaseDir); spriteComponent.Sprites.Add(sprite.Name ?? "Default", sprite); } else { var sprite = _spriteReader.LoadSprite(spriteNode); sprite.SheetPath = sheetPath; spriteComponent.Sprites.Add(sprite.Name ?? "Default", sprite); } } if (spriteComponent.SheetPath != null || spriteComponent.Sprites.Any()) return spriteComponent; else return null; }
private void LoadSpriteComponent(GameEntity entity, SpriteComponentInfo componentInfo) { var spritecomp = new SpriteComponent(); entity.AddComponent(spritecomp); spritecomp.LoadInfo(componentInfo); }
internal void LoadInfo(SpriteComponentInfo componentInfo) { _sheetPath = componentInfo.SheetPath; foreach (var sprite in componentInfo.Sprites.Values) { Add(sprite.Name ?? "Default", sprite, sprite.Part); } }
public IComponentInfo Load(XElement node, Project project) { var spriteComponent = new SpriteComponentInfo(); FilePath sheetPath = null; var sheetNode = node.Element("Tilesheet"); if (sheetNode != null) { sheetPath = FilePath.FromRelative(sheetNode.Value, project.BaseDir); spriteComponent.SheetPath = sheetPath; } foreach (var spriteNode in node.Elements("Sprite")) { if (sheetPath == null) { var sprite = _spriteReader.LoadSprite(spriteNode, project.BaseDir); spriteComponent.Sprites.Add(sprite.Name ?? "Default", sprite); } else { var sprite = _spriteReader.LoadSprite(spriteNode); sprite.SheetPath = sheetPath; spriteComponent.Sprites.Add(sprite.Name ?? "Default", sprite); } } if (spriteComponent.SheetPath != null || spriteComponent.Sprites.Any()) { return(spriteComponent); } else { return(null); } }