22using FEZRepacker . Core . Definitions . Game . XNA ;
33using FEZRepacker . Core . FileSystem ;
44using FEZRepacker . Core . Helpers ;
5+ using FEZRepacker . Core . Helpers . Json ;
56
67using SixLabors . ImageSharp ;
78using SixLabors . ImageSharp . Formats . Gif ;
9+ using SixLabors . ImageSharp . Formats . Png ;
810using SixLabors . ImageSharp . PixelFormats ;
911using SixLabors . ImageSharp . Processing ;
1012
@@ -14,23 +16,53 @@ namespace FEZRepacker.Core.Conversion.Formats
1416{
1517 internal class AnimatedTextureConverter : FormatConverter < AnimatedTexture >
1618 {
17- const int FramePadding = 1 ;
19+ private const string GifFileFormat = ".gif" ;
20+ private const string BundleFileFormat = ".fezanim" ;
1821
19- public override string FileFormat => ".gif" ;
22+ public override string [ ] FileFormats => [ GifFileFormat , BundleFileFormat ] ;
2023
2124 public override FileBundle ConvertTyped ( AnimatedTexture txt )
2225 {
26+ if ( Settings . UseAnimationSheet )
27+ {
28+ var bundle = ConfiguredJsonSerializer . SerializeToFileBundle ( BundleFileFormat , txt ) ;
29+ var atlasTexture = new Texture2D ( )
30+ {
31+ Format = SurfaceFormat . Color ,
32+ Width = txt . AtlasWidth ,
33+ Height = txt . AtlasHeight ,
34+ TextureData = txt . TextureData
35+ } ;
36+ using var animationAtlas = TexturesUtil . ImageFromTexture2D ( atlasTexture ) ;
37+ bundle . AddFile ( animationAtlas . SaveAsMemoryStream ( new PngEncoder ( ) ) , ".png" ) ;
38+
39+ return bundle ;
40+ }
41+
2342 using var animation = AnimatedTextureToGif ( txt ) ;
2443
2544 var outStream = animation . SaveAsMemoryStream (
2645 new GifEncoder { ColorTableMode = GifColorTableMode . Local }
2746 ) ;
2847
29- return FileBundle . Single ( outStream , FileFormat ) ;
48+ return FileBundle . Single ( outStream , GifFileFormat ) ;
3049 }
3150
3251 public override AnimatedTexture DeconvertTyped ( FileBundle bundle )
3352 {
53+ if ( bundle . MainExtension == BundleFileFormat )
54+ {
55+ var animatedTexture = ConfiguredJsonSerializer . DeserializeFromFileBundle < AnimatedTexture > ( bundle ) ;
56+
57+ using var atlasImage = Image . Load < Rgba32 > ( bundle . RequireData ( ".png" ) ) ;
58+ var atlasTexture = TexturesUtil . ImageToTexture2D ( atlasImage ) ;
59+
60+ animatedTexture . AtlasWidth = atlasTexture . Width ;
61+ animatedTexture . AtlasHeight = atlasTexture . Height ;
62+ animatedTexture . TextureData = atlasTexture . TextureData ;
63+ return animatedTexture ;
64+ }
65+
3466 using var animation = Image . Load < Rgba32 > ( bundle . RequireData ( "" ) ) ;
3567 return AnimationImageToAnimatedTexture ( animation ) ;
3668 }
0 commit comments