Exemplo n.º 1
0
        internal static Animation Read(Stream input, Endian endian)
        {
            var name          = input.ReadString(endian);
            var frameNum      = input.ReadValueU32(endian);
            var loop          = input.ReadValueB8();
            var rootAnimation = RootAnimation.Read(input, endian);

            var layerAnimationCount = input.ReadValueU32(endian);

            if (layerAnimationCount >= 32)
            {
                throw new FormatException("too many animation layers");
            }
            var layerAnimations = new LayerAnimation[layerAnimationCount];

            for (uint i = 0; i < layerAnimationCount; i++)
            {
                layerAnimations[i] = LayerAnimation.Read(input, endian);
            }

            var nullAnimationCount = input.ReadValueU32(endian);

            if (nullAnimationCount >= 32)
            {
                throw new FormatException("too many null layers");
            }
            var nullAnimations = new NullAnimation[nullAnimationCount];

            for (uint k = 0; k < nullAnimationCount; k++)
            {
                nullAnimations[k] = NullAnimation.Read(input, endian);
            }

            var triggerCount = input.ReadValueU32(endian);

            if (triggerCount >= 32)
            {
                throw new FormatException("too many triggers");
            }
            var triggers = new Trigger[triggerCount];

            for (uint i = 0; i < triggerCount; i++)
            {
                triggers[i] = Trigger.Read(input, endian);
            }

            Animation instance;

            instance.Name            = name;
            instance.FrameNum        = frameNum;
            instance.Loop            = loop;
            instance.RootAnimation   = rootAnimation;
            instance.LayerAnimations = layerAnimations;
            instance.NullAnimations  = nullAnimations;
            instance.Triggers        = triggers;
            return(instance);
        }
Exemplo n.º 2
0
        internal static void Write(Stream output, LayerAnimation instance, Endian endian)
        {
            output.WriteValueU32(instance.LayerId, endian);
            output.WriteValueB8(instance.Visible);

            var frameCount = instance.Frames == null ? 0 : instance.Frames.Length;

            output.WriteValueS32(frameCount, endian);
            if (instance.Frames != null)
            {
                foreach (var frame in instance.Frames)
                {
                    frame.Write(output, endian);
                }
            }
        }