コード例 #1
0
ファイル: MapFile.cs プロジェクト: Starkku/MapTool
        /// <summary>
        /// Remove a single map overlay from the map.
        /// </summary>
        /// <param name="mapOverlay">Map overlay to remove.</param>
        /// <returns>True if map overlay was found and removed, otherwise false.</returns>
        public bool RemoveMapOverlay(MapOverlay mapOverlay)
        {
            if (HasOverlayData && mapOverlays.Remove(mapOverlay))
            {
                overlayDataAltered = true;
                return(true);
            }

            return(false);
        }
コード例 #2
0
ファイル: MapFile.cs プロジェクト: Starkku/MapTool
        /// <summary>
        /// Loads overlay data from map file if it hasn't already been loaded.
        /// </summary>
        /// <returns>Array of error messages if something went wrong, otherwise null.</returns>
        public string[] LoadOverlayData()
        {
            if (mapOverlays != null)
            {
                return new string[] { "Overlay data has already been loaded." }
            }
            ;

            List <string> errorMessages = new List <string>();

            byte[] overlayPack  = new byte[1 << 18];
            string errorMessage = ParseEncodedMapSectionData("OverlayPack", ref overlayPack, true);

            if (errorMessage != null)
            {
                errorMessages.Add(errorMessage);
            }

            byte[] overlayDataPack = new byte[1 << 18];
            errorMessage = ParseEncodedMapSectionData("OverlayDataPack", ref overlayDataPack, true);

            if (errorMessage != null)
            {
                errorMessages.Add(errorMessage);
            }

            if (errorMessages.Count < 1)
            {
                mapOverlays = new List <MapOverlay>(overlayPack.Length);
                for (int i = 0; i < overlayPack.Length; i++)
                {
                    byte       index   = overlayPack[i];
                    byte       frame   = overlayDataPack[i];
                    short      x       = (short)(i % 512);
                    short      y       = (short)((i - x) / 512);
                    MapOverlay overlay = new MapOverlay(x, y, index, frame);
                    overlay.PropertyChanged += MapOverlay_PropertyChanged;
                    mapOverlays.Add(overlay);
                }
                overlayDataAltered = false;
            }

            return(errorMessages.Count > 0 ? errorMessages.ToArray() : null);
        }
コード例 #3
0
ファイル: MapFile.cs プロジェクト: Starkku/MapTool
        /// <summary>
        /// Replaces map overlay with another assuming tile coordinates match an existing map overlay.
        /// </summary>
        /// <param name="mapOverlay">Map overlay to replace existing map overlay with.</param>
        /// <returns>True if map overlay was replaced, otherwise false.</returns>
        public bool ReplaceMapOverlay(MapOverlay mapOverlay)
        {
            if (HasOverlayData)
            {
                int index = mapOverlays.FindIndex(t => t.X == mapOverlay.X && t.Y == mapOverlay.Y);

                if (index < 0)
                {
                    return(false);
                }

                mapOverlays[index]          = mapOverlay;
                mapOverlay.PropertyChanged -= MapOverlay_PropertyChanged;
                mapOverlay.PropertyChanged += MapOverlay_PropertyChanged;
                tileDataAltered             = true;
                return(true);
            }

            return(false);
        }