Ejemplo n.º 1
0
        public void Serialize(GMDataWriter writer)
        {
            writer.WritePointerString(Name);
            writer.WritePointerString(Caption);
            writer.Write(Width); writer.Write(Height);
            writer.Write(Speed);
            writer.WriteWideBoolean(Persistent);
            writer.Write(BackgroundColor);
            writer.WriteWideBoolean(DrawBackgroundColor);
            writer.Write(CreationCodeID);
            int flags = (int)Flags;

            if (writer.VersionInfo.IsNumberAtLeast(2, 3))
            {
                flags |= 0x30000;
            }
            else if (writer.VersionInfo.IsNumberAtLeast(2))
            {
                flags |= 0x20000;
            }
            writer.Write(flags);
            writer.WritePointer(Backgrounds);
            writer.WritePointer(Views);
            writer.WritePointer(GameObjects);
            writer.WritePointer(Tiles);
            writer.WriteWideBoolean(Physics);
            writer.Write(Top); writer.Write(Left);
            writer.Write(Right); writer.Write(Bottom);
            writer.Write(GravityX); writer.Write(GravityY);
            writer.Write(PixelsToMeters);
            int sequencePatch = -1;

            if (writer.VersionInfo.IsNumberAtLeast(2))
            {
                writer.WritePointer(Layers);
                if (writer.VersionInfo.IsNumberAtLeast(2, 3))
                {
                    sequencePatch = writer.Offset;
                    writer.Write(0);
                }
            }

            writer.WriteObjectPointer(Backgrounds);
            Backgrounds.Serialize(writer);
            writer.WriteObjectPointer(Views);
            Views.Serialize(writer);
            writer.WriteObjectPointer(GameObjects);
            GameObjects.Serialize(writer);
            writer.WriteObjectPointer(Tiles);
            Tiles.Serialize(writer);
            if (writer.VersionInfo.IsNumberAtLeast(2))
            {
                writer.WriteObjectPointer(Layers);
                Layers.Serialize(writer);
                if (writer.VersionInfo.IsNumberAtLeast(2, 3))
                {
                    // Patch and write sequence IDs
                    int returnTo = writer.Offset;
                    writer.Offset = sequencePatch;
                    writer.Write(returnTo);
                    writer.Offset = returnTo;

                    writer.Write(SequenceIDs.Count);
                    foreach (int i in SequenceIDs)
                    {
                        writer.Write(i);
                    }
                }
            }
        }