private Grabbable CreateGrabbable(Rectangle maprect, Map map, bool clearout) { Check.NullArgument<Map>(map, "map"); Grabbable grab = new Grabbable(maprect, true); int width = maprect.Width + 1; int height = maprect.Height + 1; ActionBatchAction<PlaceTileAction> batchaction = new ActionBatchAction<PlaceTileAction>(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var mappoint = new MapPoint(x + maprect.X, y + maprect.Y); if (!ComponentHelpers.PointInMap(map, mappoint)) continue; GrabbedTile tile = new GrabbedTile(new MapPoint(x, y)) { Layer1 = map.GetLayerValue(mappoint, MapLayers.UnderLayer), Layer2 = map.GetLayerValue(mappoint, MapLayers.BaseLayer), Layer3 = map.GetLayerValue(mappoint, MapLayers.MiddleLayer), Layer4 = map.GetLayerValue(mappoint, MapLayers.TopLayer) }; grab.Tiles.Add(tile); } } return grab; }
public static Map ResizeMap(Map map, MapPoint newsize) { Map newMap = new Map(); newMap.Name = map.Name; newMap.TextureName = map.TextureName; newMap.Texture = map.Texture; newMap.TileSize = map.TileSize; foreach (var animation in map.AnimatedTiles) newMap.AnimatedTiles.Add(animation.Key, animation.Value); newMap.MapSize = newsize; newMap.UnderLayer = new int[newsize.IntX * newsize.IntY]; newMap.BaseLayer = new int[newsize.IntX * newsize.IntY]; newMap.MiddleLayer = new int[newsize.IntX * newsize.IntY]; newMap.TopLayer = new int[newsize.IntX * newsize.IntY]; newMap.CollisionLayer = new int[newsize.IntX * newsize.IntY]; newMap.OpaqueLayer = new int[newsize.IntX * newsize.IntY]; for (int i = 0; i < (newMap.MapSize.X * newMap.MapSize.Y); i++) { newMap.UnderLayer[i] = -1; newMap.BaseLayer[i] = -1; newMap.MiddleLayer[i] = -1; newMap.TopLayer[i] = -1; newMap.CollisionLayer[i] = -1; newMap.OpaqueLayer[i] = -1; } for (int y = 0; y < newsize.Y; y++) { for (int x = 0; x < newsize.X; x++) { // If it's outside the Y range always fill with -1 if (y >= map.MapSize.Y) { newMap.SetLayerValue(new MapPoint(x, y), MapLayers.UnderLayer, -1); continue; } // If it's outside the X range but not the Y range, fill with 0 if (x >= map.MapSize.X) { newMap.SetLayerValue(new MapPoint(x, y), MapLayers.UnderLayer, -1); continue; } //Fill the new location with the value of the old location newMap.SetLayerValue(new MapPoint(x, y), MapLayers.UnderLayer, map.GetLayerValue(new MapPoint(x, y), MapLayers.UnderLayer)); newMap.SetLayerValue(new MapPoint(x, y), MapLayers.BaseLayer, map.GetLayerValue(new MapPoint(x, y), MapLayers.BaseLayer)); newMap.SetLayerValue(new MapPoint(x, y), MapLayers.MiddleLayer, map.GetLayerValue(new MapPoint(x, y), MapLayers.MiddleLayer)); newMap.SetLayerValue(new MapPoint(x, y), MapLayers.TopLayer, map.GetLayerValue(new MapPoint(x, y), MapLayers.TopLayer)); newMap.SetLayerValue(new MapPoint(x, y), MapLayers.CollisionLayer, map.GetLayerValue(new MapPoint(x, y), MapLayers.CollisionLayer)); newMap.SetLayerValue(new MapPoint(x, y), MapLayers.OpaqueLayer, map.GetLayerValue(new MapPoint(x, y), MapLayers.OpaqueLayer)); } } return newMap; }
/// <summary> /// Performs a flood fill beginning on the target square /// </summary> /// <param name="map">The map to perform the operation on</param> /// <param name="layer">The layer to perform on</param> /// <param name="x">The x location to begin filling</param> /// <param name="y">The y location to begin filling</param> /// <param name="oldtileid">The ID of the tile to begin replacing.</param> /// <param name="newtileid">The ID of the replacement tile.</param> private void FloodFill(Map map, MapLayers layer, int x, int y, int oldtileid, int newtileid) { int value = map.GetLayerValue(new MapPoint(x, y), layer); if (value != oldtileid || value == newtileid) return; var action = new PlaceTileAction(x, y, layer, newtileid); action.Do(context); tmpactions.Add(action); if (x + 1 < MapEditorManager.CurrentMap.MapSize.X) this.FloodFill(map, layer, x + 1, y, oldtileid, newtileid); if (x - 1 >= 0) this.FloodFill(map, layer, x - 1, y, oldtileid, newtileid); if (y + 1 < MapEditorManager.CurrentMap.MapSize.Y) this.FloodFill(map, layer, x, y + 1, oldtileid, newtileid); if (y - 1 >= 0) this.FloodFill(map, layer, x, y - 1, oldtileid, newtileid); }