Esempio n. 1
0
 public override GR.Memory.ByteBuffer SaveToBuffer()
 {
     return(m_Charset.SaveToBuffer());
 }
Esempio n. 2
0
        public GR.Memory.ByteBuffer SaveToBuffer()
        {
            GR.Memory.ByteBuffer projectFile = new GR.Memory.ByteBuffer();

            GR.IO.FileChunk chunkProjectInfo = new GR.IO.FileChunk(Types.FileChunk.MAP_PROJECT_INFO);
            // version
            chunkProjectInfo.AppendU32(0);
            chunkProjectInfo.AppendString(ExternalCharset);
            chunkProjectInfo.AppendI32(ShowGrid ? 1 : 0);
            projectFile.Append(chunkProjectInfo.ToBuffer());

            GR.IO.FileChunk chunkCharset = new GR.IO.FileChunk(Types.FileChunk.MAP_CHARSET);
            chunkCharset.Append(Charset.SaveToBuffer());
            projectFile.Append(chunkCharset.ToBuffer());

            GR.IO.FileChunk chunkProjectData = new GR.IO.FileChunk(Types.FileChunk.MAP_PROJECT_DATA);

            GR.IO.FileChunk chunkMCData = new GR.IO.FileChunk(Types.FileChunk.MULTICOLOR_DATA);
            chunkMCData.AppendU8((byte)Mode);
            chunkMCData.AppendU8((byte)BackgroundColor);
            chunkMCData.AppendU8((byte)MultiColor1);
            chunkMCData.AppendU8((byte)MultiColor2);
            chunkMCData.AppendU8((byte)BGColor4);
            chunkProjectData.Append(chunkMCData.ToBuffer());

            foreach (Tile tile in Tiles)
            {
                GR.IO.FileChunk chunkTile = new GR.IO.FileChunk(Types.FileChunk.MAP_TILE);

                chunkTile.AppendString(tile.Name);
                chunkTile.AppendI32(tile.Chars.Width);
                chunkTile.AppendI32(tile.Chars.Height);
                for (int j = 0; j < tile.Chars.Height; ++j)
                {
                    for (int i = 0; i < tile.Chars.Width; ++i)
                    {
                        TileChar tChar = tile.Chars[i, j];
                        chunkTile.AppendU8(tChar.Character);
                        chunkTile.AppendU8(tChar.Color);
                    }
                }
                chunkProjectData.Append(chunkTile.ToBuffer());
            }
            foreach (Map map in Maps)
            {
                GR.IO.FileChunk chunkMap = new GR.IO.FileChunk(Types.FileChunk.MAP);

                GR.IO.FileChunk chunkMapInfo = new GR.IO.FileChunk(Types.FileChunk.MAP_INFO);

                chunkMapInfo.AppendString(map.Name);
                chunkMapInfo.AppendI32(map.TileSpacingX);
                chunkMapInfo.AppendI32(map.TileSpacingY);
                chunkMapInfo.AppendI32(map.AlternativeMultiColor1 + 1);
                chunkMapInfo.AppendI32(map.AlternativeMultiColor2 + 1);
                chunkMapInfo.AppendI32(map.AlternativeBackgroundColor + 1);
                chunkMapInfo.AppendI32(map.AlternativeBGColor4 + 1);
                chunkMapInfo.AppendI32((int)map.AlternativeMode + 1);
                chunkMap.Append(chunkMapInfo.ToBuffer());

                GR.IO.FileChunk chunkMapData = new GR.IO.FileChunk(Types.FileChunk.MAP_DATA);
                chunkMapData.AppendI32(map.Tiles.Width);
                chunkMapData.AppendI32(map.Tiles.Height);
                for (int j = 0; j < map.Tiles.Height; ++j)
                {
                    for (int i = 0; i < map.Tiles.Width; ++i)
                    {
                        chunkMapData.AppendI32(map.Tiles[i, j]);
                    }
                }
                chunkMap.Append(chunkMapData.ToBuffer());

                if (map.ExtraDataText.Length > 0)
                {
                    GR.IO.FileChunk chunkMapExtraData = new GR.IO.FileChunk(Types.FileChunk.MAP_EXTRA_DATA_TEXT);

                    chunkMapExtraData.AppendString(map.ExtraDataText);

                    chunkMap.Append(chunkMapExtraData.ToBuffer());
                }
                if (map.ExtraDataOld.Length > 0)
                {
                    GR.IO.FileChunk chunkMapExtraData = new GR.IO.FileChunk(Types.FileChunk.MAP_EXTRA_DATA);

                    chunkMapExtraData.AppendU32(map.ExtraDataOld.Length);
                    chunkMapExtraData.Append(map.ExtraDataOld);

                    chunkMap.Append(chunkMapExtraData.ToBuffer());
                }
                chunkProjectData.Append(chunkMap.ToBuffer());
            }

            projectFile.Append(chunkProjectData.ToBuffer());
            return(projectFile);
        }