internal static PerTexture AlsoExportImages(string outDir, string baseName, PerTexture perTexture) { foreach (var pair in perTexture.Textures) { var key = pair.Key; var textureFooterData = pair.Value; textureFooterData.TextureAnimationList? .Select((it, index) => (it, index)) .ToList() .ForEach( pair => { var src = pair.it._source; var bitmap = SpriteImageUtil.ToBitmap( src.BitsPerPixel, src.SpriteWidth, src.SpriteHeight, src.NumSpritesInImageData, src.SpriteStride, src.SpriteImage ); var pngFile = Path.Combine(outDir, $"{baseName}.footer-{key}-{pair.index}.png"); bitmap.Save(pngFile, ImageFormat.Png); pair.it.SpriteImageFile = "./" + Path.GetFileName(pngFile); } ); } return(perTexture); }
public int Execute() { var perTexture = new PerTexture(); var barEntries = File.OpenRead(MapFile).Using(Bar.Read); foreach (var entry in barEntries .Where(entry => entry.Type == Bar.EntryType.ModelTexture && ModelTexture.IsValid(entry.Stream)) ) { entry.Stream.SetPosition(0); var modelTexture = ModelTexture.Read(entry.Stream); if (modelTexture.Images == null || !modelTexture.Images.Any()) { return(1); } var footerData = modelTexture.TextureFooterData; perTexture.Textures[entry.Name] = new TextureFooterDataIMEx(footerData); } var outDir = Path.Combine( Path.GetDirectoryName(MapFile), OutputDir ?? "." ); var baseName = Path.GetFileNameWithoutExtension(MapFile); Directory.CreateDirectory(outDir); File.WriteAllText( Path.Combine(outDir, $"{baseName}.footer.yml"), new SerializerBuilder() .WithTypeConverter(new UseJsonStyleArray <short>()) .WithTypeConverter(new UseJsonStyleArray <byte>()) .WithAttributeOverride <TextureFrame>(it => it.Data, new YamlIgnoreAttribute()) .Build() .Serialize(ExportHelper.AlsoExportImages(outDir, baseName, perTexture)) ); return(0); }