Ejemplo n.º 1
0
 public override MapState Execute(MapState state, Selection selection)
 {
     if (KeepInside)
     {
         int minx = int.MaxValue, miny = int.MaxValue, maxx = int.MinValue, maxy = int.MinValue;
         foreach (var tile in state.ActiveLayer.Map.GetAllTiles())
         {
             if (!tile.IsEmpty)
             {
                 minx = Math.Min(minx, tile.X);
                 miny = Math.Min(miny, tile.Y);
                 maxx = Math.Max(maxx, tile.X);
                 maxy = Math.Max(maxy, tile.Y);
             }
         }
         if (minx + DeltaX < 0) DeltaX = -minx;
         if (miny + DeltaY < 0) DeltaY = -miny;
         if (maxx + DeltaX >= state.ActiveLayer.Map.Width) DeltaX = state.ActiveLayer.Map.Width - 1 - maxx;
         if (maxy + DeltaY >= state.ActiveLayer.Map.Height) DeltaY = state.ActiveLayer.Map.Height - 1 - maxy;
     }
     if (DeltaX != 0 || DeltaY != 0)
     {
         Map m = new Map();
         m.SetDimensions(state.ActiveLayer.Map.Width, state.ActiveLayer.Map.Height);
         foreach (var t in state.ActiveLayer.Map.GetAllTiles())
         {
             m.SetTile(t.X, t.Y, new Tile() { IsEmpty = true });
         }
         foreach (var t in state.ActiveLayer.Map.GetAllTiles())
         {
             var x = t.X + DeltaX;
             var y = t.Y + DeltaY;
             if(x >= 0 && y >= 0 && x < m.Width && y < m.Height)
                 m.SetTile(x, y, t);
         }
         state.ActiveLayer.Map = m;
     }
     return state;
 }
Ejemplo n.º 2
0
 public static Map RotateCW(Map thisMap)
 {
     Map map = new Map();
     map.SetDimensions(thisMap.Height, thisMap.Width);
     map.IsHorizontalWrap = thisMap.IsVerticalWrap;
     map.IsVerticalWrap = thisMap.IsHorizontalWrap;
     map.UnparsedData = new List<string>(thisMap.UnparsedData);
     foreach (Tile t in thisMap.GetAllTiles())
     {
         map.SetTile(t.Y, map.Height - 1 - t.X, (Tile)t.Clone());
     }
     Map map2 = (Map)map.Clone();
     foreach (Tile t in map2.GetAllTiles())
     {
         t.IsWOfRiver = false;
         t.IsNOfRiver = false;
     }
     foreach (Tile t in map.GetAllTiles())
     {
         if (t.IsNOfRiver)
         {
             Tile w = map2.GetNeighbour(t.X, t.Y, HorizontalNeighbour.West, VerticalNeighbour.None);
             if (w != null)
             {
                 w.IsWOfRiver = true;
                 if (t.RiverWEDirection == RiverDirection.WEST_TO_EAST)
                     w.RiverNSDirection = RiverDirection.NORTH_TO_SOUTH;
                 else
                     w.RiverNSDirection = RiverDirection.SOUTH_TO_NORTH;
             }
         }
         if (t.IsWOfRiver)
         {
             Tile tt = map2.GetTile(t.X, t.Y);
             tt.IsNOfRiver = true;
             if (t.RiverNSDirection == RiverDirection.NORTH_TO_SOUTH)
                 tt.RiverWEDirection = RiverDirection.EAST_TO_WEST;
             else
                 tt.RiverWEDirection = RiverDirection.WEST_TO_EAST;
         }
     }
     return map2;
 }