summaryrefslogtreecommitdiff
path: root/Plugins/MonoGame.Extended/source/MonoGame.Extended.Content.Pipeline/Animations/AstridAnimatorWriter.cs
blob: 6f56f3fe732f06ca32f30ca9a72e2527738da7ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;

namespace MonoGame.Extended.Content.Pipeline.Animations
{
    [ContentTypeWriter]
    public class AstridAnimatorWriter : ContentTypeWriter<AstridAnimatorProcessorResult>
    {
        public override string GetRuntimeReader(TargetPlatform targetPlatform)
        {
            return "MonoGame.Extended.Animations.SpriteSheets.SpriteSheetAnimationFactoryReader, MonoGame.Extended.Animations";
        }

        protected override void Write(ContentWriter writer, AstridAnimatorProcessorResult input)
        {
            var data = input.Data;

            writer.Write(input.TextureAtlasAssetName);
            writer.Write(input.Frames.Count);

            foreach (var frame in input.Frames)
                writer.Write(frame);

            writer.Write(data.Animations.Count);

            foreach (var animation in data.Animations)
            {
                writer.Write(animation.Name);
                writer.Write(animation.FramesPerSecond);
                writer.Write(animation.IsLooping);
                writer.Write(animation.IsReversed);
                writer.Write(animation.IsPingPong);
                writer.Write(animation.Frames.Count);

                foreach (var frame in animation.Frames)
                    writer.Write(input.Frames.IndexOf(frame));
            }
        }
    }
}