/// <summary> /// Loads the images specified by an atlas description. /// </summary> private static IEnumerable <TextureAtlasImage> LoadImages(ContentManager content, IContentProcessorMetadata metadata, TextureAtlasDescription atlasDesc) { var result = new Dictionary <String, TextureAtlasImage>(); if (atlasDesc.Images != null) { foreach (var imageDesc in atlasDesc.Images) { var path = imageDesc.Path; if (String.IsNullOrEmpty(path) || path.IndexOfAny(Path.GetInvalidPathChars()) >= 0) { throw new InvalidDataException(UltravioletStrings.InvalidTextureAtlasImagePath); } var name = imageDesc.Name; if (path.Contains("*")) { if (name != null) { throw new InvalidDataException(UltravioletStrings.TextureAtlasWildcardsCannotBeNamed); } var files = ExpandFileExpression(content, ResolveDependencyAssetPath(metadata, Path.Combine(atlasDesc.Metadata.RootDirectory, path))); foreach (var file in files) { var nameFile = Path.GetFileNameWithoutExtension(file); var nameRoot = String.IsNullOrEmpty(Path.GetDirectoryName(path)) ? null : Path.GetDirectoryName(file) .Replace(Path.DirectorySeparatorChar, '\\') .Replace(Path.AltDirectorySeparatorChar, '\\'); name = String.IsNullOrEmpty(nameRoot) ? nameFile : nameRoot + "\\" + nameFile; if (result.ContainsKey(name)) { throw new InvalidOperationException(UltravioletStrings.TextureAtlasAlreadyContainsCell.Format(name)); } var size = GetImageSize(content, file); result[name] = new TextureAtlasImage(name, file, size); } } else { name = name ?? path; path = ResolveDependencyAssetPath(metadata, Path.Combine(atlasDesc.Metadata.RootDirectory, path)); if (result.ContainsKey(name)) { throw new InvalidOperationException(UltravioletStrings.TextureAtlasAlreadyContainsCell.Format(name)); } var size = GetImageSize(content, path); result[name] = new TextureAtlasImage(name, path, size); } } } return(result.Any() ? result.Values.ToList() : null); }
/// <summary> /// Loads the texture atlas' images. /// </summary> /// <param name="content">The <see cref="ContentManager"/> with which to load images.</param> /// <param name="images">The XML element that defines the set of images to load.</param> /// <returns>A value indicating whether any images were loaded.</returns> private Boolean LoadImages(ContentManager content, XElement images) { var imageList = new Dictionary<String, TextureAtlasImage>(); if (images != null) { foreach (var include in images.Elements("Include")) { var path = (String)include; if (String.IsNullOrEmpty(path) || path.IndexOfAny(Path.GetInvalidPathChars()) >= 0) throw new InvalidDataException(UltravioletStrings.InvalidTextureAtlasImagePath); var name = include.AttributeValueString("Name"); if (path.Contains("*")) { if (name != null) throw new InvalidDataException(UltravioletStrings.TextureAtlasWildcardsCannotBeNamed); var files = ExpandFileExpression(content, Path.Combine(RootDirectory, path)); foreach (var file in files) { var nameFile = Path.GetFileNameWithoutExtension(file); var nameRoot = String.IsNullOrEmpty(Path.GetDirectoryName(path)) ? null : Path.GetDirectoryName(file) .Replace(Path.DirectorySeparatorChar, '\\') .Replace(Path.AltDirectorySeparatorChar, '\\'); name = String.IsNullOrEmpty(nameRoot) ? nameFile : nameRoot + "\\" + nameFile; if (imageList.ContainsKey(name)) throw new InvalidOperationException(UltravioletStrings.TextureAtlasAlreadyContainsCell.Format(name)); var size = GetImageSize(content, file); imageList[name] = new TextureAtlasImage(name, file, size); } } else { name = name ?? path; path = Path.Combine(RootDirectory, path); if (imageList.ContainsKey(name)) throw new InvalidOperationException(UltravioletStrings.TextureAtlasAlreadyContainsCell.Format(name)); var size = GetImageSize(content, path); imageList[name] = new TextureAtlasImage(name, path, size); } } } this.imageList = imageList.Values.ToList(); return this.imageList.Any(); }