Skip to content

Commit 8db572d

Browse files
committed
made more methods use MapIterator
1 parent 00c7b2b commit 8db572d

3 files changed

Lines changed: 15 additions & 29 deletions

File tree

src/main/java/net/ddns/endercypt/cs2dmap/library/map/sub/extra/map/MapArray.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,36 +94,32 @@ public void circle(int x1, int y1, int x2, int y2, TileAction tileAction)
9494
double rxc = x1 + xc;
9595
double ryc = y1 + yc;
9696

97-
for (int x = x1; x < x2 + 1; x++)
97+
iterate(x1, y1, x2, y2, new MapIterator()
9898
{
99-
for (int y = y1; y < y2 + 1; y++)
99+
@Override
100+
public void process(int x, int y, Tile tile)
100101
{
101-
if (isInBounds(x, y))
102+
double xoffset = 1.0 / xc * Math.abs(x - rxc);
103+
double yoffset = 1.0 / yc * Math.abs(y - ryc);
104+
double dist = Math.hypot(xoffset, yoffset);
105+
if (dist <= 1.0)
102106
{
103-
double xoffset = 1.0 / xc * Math.abs(x - rxc);
104-
double yoffset = 1.0 / yc * Math.abs(y - ryc);
105-
double dist = Math.hypot(xoffset, yoffset);
106-
if (dist <= 1.0)
107-
{
108-
tileAction.process(tile(x, y));
109-
}
107+
tileAction.process(tile(x, y));
110108
}
111109
}
112-
}
110+
});
113111
}
114112

115113
public void rectangle(int x1, int y1, int x2, int y2, TileAction tileAction)
116114
{
117-
for (int x = x1; x < x2 + 1; x++)
115+
iterate(x1, y1, x2, y2, new MapIterator()
118116
{
119-
for (int y = y1; y < y2 + 1; y++)
117+
@Override
118+
public void process(int x, int y, Tile tile)
120119
{
121-
if (isInBounds(x, y))
122-
{
123-
tileAction.process(tile(x, y));
124-
}
120+
tileAction.process(tile(x, y));
125121
}
126-
}
122+
});
127123
}
128124

129125
public void fill(TileAction tileAction)

src/main/java/net/ddns/endercypt/cs2dmap/library/map/sub/extra/map/MapIterator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.ddns.endercypt.cs2dmap.library.map.obj.tile.Tile;
44

5+
@FunctionalInterface
56
public interface MapIterator
67
{
78
public void process(int x, int y, Tile tile);

src/main/java/test/CreateMap.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
import net.ddns.endercypt.cs2dmap.library.map.obj.entity.type.info.Info_Hostage;
1111
import net.ddns.endercypt.cs2dmap.library.map.obj.entity.type.info.Info_T;
1212
import net.ddns.endercypt.cs2dmap.library.map.obj.entity.type.info.Info_Hostage.HostageLooks;
13-
import net.ddns.endercypt.cs2dmap.library.map.obj.tile.Tile;
1413
import net.ddns.endercypt.cs2dmap.library.map.obj.tile.modifier.ColorTileModifier;
1514
import net.ddns.endercypt.cs2dmap.library.map.sub.Cs2dBackground;
1615
import net.ddns.endercypt.cs2dmap.library.map.sub.Cs2dEntities;
1716
import net.ddns.endercypt.cs2dmap.library.map.sub.Cs2dMapArray;
1817
import net.ddns.endercypt.cs2dmap.library.map.sub.Cs2dTiles;
19-
import net.ddns.endercypt.cs2dmap.library.map.sub.extra.map.MapIterator;
2018
import net.ddns.endercypt.cs2dmap.library.map.sub.extra.map.MapSection;
2119
import net.ddns.endercypt.cs2dmap.library.map.sub.extra.tile.TileMode;
2220
import net.ddns.endercypt.cs2dmap.library.map.sub.extra.tile.action.TileActions;
@@ -50,15 +48,6 @@ public static void main(String[] args) throws IOException
5048
map.tile(2, 9).setFrame(5);
5149
map.tile(5, 8).setTileModifier(new ColorTileModifier(255, 0, 0, 1));
5250

53-
map.iterate(new MapIterator()
54-
{
55-
@Override
56-
public void process(int x, int y, Tile tile)
57-
{
58-
tile.setFrame(15);
59-
}
60-
});
61-
6251
MapSection copy = map.copy(0, 0, 5, 5);
6352
copy.pasteInto(map, -1, -1);
6453

0 commit comments

Comments
 (0)