示例#1
0
        public void Write(Stream stream)
        {
            if (ShouldEmitDMYAtFirst)
            {
                // Some map files has style "_DMY" "_KN5". This is for that consistency.
                stream.Write(_DMY);
                stream.Write(0);
            }

            foreach (var item in TextureAnimationList)
            {
                var texaStream = new MemoryStream();

                {
                    item.NumAnimations = Convert.ToUInt16(item.FrameGroupList.Length);
                    var animationTable = new int[item.NumAnimations];

                    for (var pass = 1; pass <= 2; pass++)
                    {
                        texaStream.Position = 0;
                        BinaryMapping.WriteObject(texaStream, item);

                        item.OffsetSlotTable = Convert.ToInt32(texaStream.Position);
                        item.SlotTable.ToList().ForEach(texaStream.Write);

                        texaStream.AlignPosition(4);

                        item.OffsetAnimationTable = Convert.ToInt32(texaStream.Position);
                        texaStream.Write(animationTable);

                        foreach (var(group, groupIndex) in item.FrameGroupList.Select((group, groupIndex) => (group, groupIndex)))
                        {
                            animationTable[groupIndex] = Convert.ToInt32(texaStream.Position);

                            if (group.IndexedFrameList.Any())
                            {
                                int minIdx = group.IndexedFrameList.Keys.Min();
                                int maxIdx = group.IndexedFrameList.Keys.Max();

                                for (; minIdx <= maxIdx; minIdx++)
                                {
                                    group.IndexedFrameList.TryGetValue(minIdx, out TextureFrame frame);
                                    frame = frame ?? new TextureFrame();

                                    BinaryMapping.WriteObject(texaStream, frame);
                                }
                            }
                        }

                        texaStream.AlignPosition(16);
                        item.OffsetSpriteImage = Convert.ToInt32(texaStream.Position);

                        texaStream.Write(item.SpriteImage);
                        texaStream.AlignPosition(16);
                    }
                }

                stream.Write(_DMY);
                stream.Write(0);

                stream.Write(TEXA);
                stream.Write(Convert.ToUInt32(texaStream.Length));

                texaStream.Position = 0;
                texaStream.CopyTo(stream);
            }

            if (UvscList.Any())
            {
                // Before first "UVSC", "_DMY" has to be placed. This is for that consistency.

                stream.Write(_DMY);
                stream.Write(0);

                foreach (var item in UvscList)
                {
                    stream.Write(UVSC);
                    stream.Write(12);
                    BinaryMapping.WriteObject(stream, item);
                }
            }
            else if (TextureAnimationList.Any())
            {
                // Between "TEXA" and "_KN5", "_DMY" has to be placed. This is for that consistency.

                stream.Write(_DMY);
                stream.Write(0);
            }

            if (ShouldEmitKN5)
            {
                stream.Write(_KN5);
            }

            if (UnkFooter != null)
            {
                stream.Write(UnkFooter);
            }
        }