Beispiel #1
0
        public Animation(BinaryReader reader)
        {
            int magicCode;

            if ((magicCode = reader.ReadInt32()) != MagicCode)
            {
                throw new InvalidProgramException($"Magic Code {magicCode.ToString("X08")} not recognized.");
            }

            TotalFramesCount = reader.ReadInt32();

            int spriteSheetsCount = reader.ReadByte();

            SpriteSheets = new List <string>(spriteSheetsCount);
            while (spriteSheetsCount-- > 0)
            {
                SpriteSheets.Add(StringEncoding.GetString(reader));
            }

            int collisionBoxesCount = reader.ReadByte();

            CollisionBoxes = new List <string>(collisionBoxesCount);
            while (collisionBoxesCount-- > 0)
            {
                CollisionBoxes.Add(StringEncoding.GetString(reader));
            }

            var animationsCount = reader.ReadInt16();

            Animations = new List <AnimationEntry>(animationsCount);
            while (animationsCount-- > 0)
            {
                Animations.Add(new AnimationEntry(reader, CollisionBoxes.Count));
            }
        }
Beispiel #2
0
        public void SaveChanges(BinaryWriter writer)
        {
            writer.Write(MagicCode);

            var animationsCount = (ushort)Math.Min(Animations.Count, ushort.MaxValue);

            TotalFramesCount = Animations.Take(animationsCount).Sum(x => x.Frames.Count);
            writer.Write(TotalFramesCount);

            var spriteSheetsCount = (byte)Math.Min(SpriteSheets.Count, byte.MaxValue);

            writer.Write(spriteSheetsCount);
            for (int i = 0; i < spriteSheetsCount; i++)
            {
                var item = SpriteSheets[i];
                writer.Write(StringEncoding.GetBytes(item));
            }

            var collisionBoxesCount = (byte)Math.Min(CollisionBoxes.Count, byte.MaxValue);

            writer.Write(collisionBoxesCount);
            for (int i = 0; i < collisionBoxesCount; i++)
            {
                var item = CollisionBoxes[i];
                writer.Write(StringEncoding.GetBytes(item));
            }

            writer.Write(animationsCount);
            for (int i = 0; i < animationsCount; i++)
            {
                Animations[i].SaveChanges(writer);
            }
        }
Beispiel #3
0
 private void SubWrite(BinaryWriter writer)
 {
     writer.Write(StringEncoding.GetBytes(Name));
     writer.Write((short)Frames.Count);
     writer.Write((short)Speed);
     writer.Write((byte)Loop);
     writer.Write((byte)Flags);
     foreach (var entry in Frames)
     {
         entry.SaveChanges(writer);
     }
 }
Beispiel #4
0
        // This part is tricky...
        // Sonic Mania has a different hitboxes count. If you import an
        // animation that has a different hitboxes count than the acutal
        // animation, we need to handle this special case.
        private void SubRead(BinaryReader reader, int cbDst, int cbSrc)
        {
            Name = StringEncoding.GetString(reader);

            var framesCount = reader.ReadInt16();

            Speed = reader.ReadInt16();
            Loop  = reader.ReadByte();
            Flags = reader.ReadByte();
            for (int i = 0; i < framesCount; i++)
            {
                Frames.Add(new Frame(reader, cbDst));
            }
        }