Пример #1
0
        /// <summary>
        /// Gets current map preview as a bitmap.
        /// </summary>
        /// <returns>Map preview as a bitmap. Null if the preview could not be loaded.</returns>
        public Bitmap GetMapPreview()
        {
            if (previewBitmap != null)
            {
                return(previewBitmap);
            }

            string[] keys = GetKeys("PreviewPack");

            if (keys == null || keys.Length == 0)
            {
                return(null);
            }

            int previewWidth  = PreviewWidth;
            int previewHeight = PreviewHeight;

            if (previewWidth < 1 || previewHeight < 1)
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder();

            foreach (string key in keys)
            {
                sb.Append(GetKey("PreviewPack", key, string.Empty));
            }

            byte[] dataDest = new byte[previewWidth * previewHeight * 3];

            string errorMsg = MapPackHelper.ParseMapPackData(sb.ToString(), ref dataDest);

            if (errorMsg != null)
            {
                return(null);
            }

            previewBitmap = GraphicsUtils.CreateBitmapFromImageData(previewWidth, previewHeight, dataDest);
            return(previewBitmap);
        }
Пример #2
0
        /// <summary>
        /// Parses and decompresses Base64-encoded and compressed data from specified section of map file.
        /// </summary>
        /// <param name="sectionName">Name of the section.</param>
        /// <param name="outputData">Array to put the decompressed data to.</param>
        /// <param name="useLCW">If set to true, treat data as LCW-compressed instead of LZO.</param>
        /// <returns>Error message if something went wrong, otherwise null.</returns>
        private string ParseEncodedMapSectionData(string sectionName, ref byte[] outputData, bool useLCW = false)
        {
            Logger.Info("Parsing " + sectionName + ".");
            string[] values = GetValues(sectionName);

            string msgStart = "Error parsing " + sectionName + ": ";

            if (values == null || values.Length < 1)
            {
                return(msgStart + "Data is empty.");
            }

            string errorMsg = MapPackHelper.ParseMapPackData(values, ref outputData, useLCW);

            if (errorMsg != null)
            {
                return(msgStart + errorMsg);
            }

            return(null);
        }
Пример #3
0
        /// <summary>
        /// Saves Overlay(Data)Pack sections of the map file.
        /// </summary>
        private void SaveOverlayData()
        {
            if (mapOverlays == null || !overlayDataAltered)
            {
                return;
            }

            byte[] overlayPack     = new byte[mapOverlays.Count];
            byte[] overlayDataPack = new byte[mapOverlays.Count];

            for (int i = 0; i < mapOverlays.Count; i++)
            {
                overlayPack[i]     = mapOverlays[i].Index;
                overlayDataPack[i] = mapOverlays[i].FrameIndex;
            }

            string base64_overlayPack     = MapPackHelper.CompressMapPackData(overlayPack, true);
            string base64_overlayDataPack = MapPackHelper.CompressMapPackData(overlayDataPack, true);

            ReplacePackedSectionData("OverlayPack", base64_overlayPack);
            ReplacePackedSectionData("OverlayDataPack", base64_overlayDataPack);
        }
Пример #4
0
        /// <summary>
        /// Saves tile data to map file.
        /// </summary>
        private void SaveTileData()
        {
            if (mapTiles == null || !tileDataAltered)
            {
                return;
            }

            if (mapTiles.Count < 1)
            {
                RemoveSection("IsoMapPack5");
                return;
            }

            byte[] isoMapPack = new byte[mapTiles.Count * 11 + 4];
            int    i          = 0;

            foreach (KeyValuePair <Tuple <int, int>, MapTile> kvp in mapTiles)
            {
                MapTile tile  = kvp.Value;
                byte[]  x     = BitConverter.GetBytes(tile.X);
                byte[]  y     = BitConverter.GetBytes(tile.Y);
                byte[]  tilei = BitConverter.GetBytes(tile.TileIndex);
                isoMapPack[i]      = x[0];
                isoMapPack[i + 1]  = x[1];
                isoMapPack[i + 2]  = y[0];
                isoMapPack[i + 3]  = y[1];
                isoMapPack[i + 4]  = tilei[0];
                isoMapPack[i + 5]  = tilei[1];
                isoMapPack[i + 6]  = tilei[2];
                isoMapPack[i + 7]  = tilei[3];
                isoMapPack[i + 8]  = tile.SubTileIndex;
                isoMapPack[i + 9]  = tile.Level;
                isoMapPack[i + 10] = tile.IceGrowth;
                i += 11;
            }

            ReplacePackedSectionData("IsoMapPack5", MapPackHelper.CompressMapPackData(isoMapPack));
        }
Пример #5
0
        /// <summary>
        /// Replaces current map preview with a provided bitmap image.
        /// </summary>
        /// <returns>True if preview image was successfully replaced, otherwise false.</returns>
        public bool SetMapPreview(Bitmap preview)
        {
            if (preview == null)
            {
                return(false);
            }

            int previewWidth  = preview.Width;
            int previewHeight = preview.Height;

            if (previewWidth < 1 || previewHeight < 1)
            {
                return(false);
            }

            bool success = GraphicsUtils.TryConvertBitmap(preview, out Bitmap convertedPreview, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            if (!success)
            {
                return(false);
            }

            byte[] imageData = GraphicsUtils.GetRawImageDataFromBitmap(convertedPreview);

            if (imageData == null)
            {
                return(false);
            }

            ReplacePackedSectionData("PreviewPack", MapPackHelper.CompressMapPackData(imageData));

            PreviewWidth  = previewWidth;
            PreviewHeight = previewHeight;
            previewBitmap = convertedPreview;

            return(true);
        }