7
7
8
8
import java .awt .Graphics ;
9
9
10
- import java .util . ArrayList ;
10
+ import java .awt . geom . Area ;
11
11
import java .util .List ;
12
12
import java .util .Random ;
13
13
import java .util .Stack ;
@@ -51,7 +51,7 @@ public void set(String name, float x2, float y2, boolean drag) {
51
51
}
52
52
53
53
private void update (int x , int y , boolean center ) {
54
- if (!map .getAutoTile ()) return ;
54
+ if (map != null && !map .getAutoTile ()) return ;
55
55
if (x >= 0 && y >= 0 && x < width && y < height ) {
56
56
String name = tileNames [y ][x ];
57
57
if (name == null ) {
@@ -78,7 +78,7 @@ private void update(int x, int y, boolean center) {
78
78
out += 1 ;
79
79
if (x != height -1 &&tileNames [y ][x + 1 ] != null && tileNames [y ][x + 1 ].startsWith (spriteSheet +"_block_" +blockName +"_" ))
80
80
out += 8 ;
81
-
81
+
82
82
switch (out ) {
83
83
case 0 :
84
84
name = spriteSheet +"_block_" +blockName +"_" + "0" ;
@@ -177,8 +177,7 @@ public boolean remove(float x2, float y2) {
177
177
return false ;
178
178
}
179
179
180
- @ Override
181
- public void fill (String name , float x2 , float y2 ) {
180
+ public void fill (Area sel , String name , float x2 , float y2 ) {
182
181
int x = (int ) x2 ;
183
182
int y = (int ) y2 ;
184
183
if (x >= 0 && y >= 0 && x < width && y < height ) {
@@ -193,7 +192,30 @@ public void fill(String name, float x2, float y2) {
193
192
while (!stack .isEmpty ()) {
194
193
Location i = stack .pop ();
195
194
196
- if (check (oldName , i .x , i .y )) {
195
+ if (check (oldName , i .x , i .y ) && (sel == null || (sel != null && sel .contains (i .x *map .getTileSize (), i .y *map .getTileSize ())))) {
196
+ set (name , i .x , i .y , false );
197
+
198
+ if (i .x > 0 ) stack .push (new Location (i .x - 1 , i .y ));
199
+ if (i .y > 0 ) stack .push (new Location (i .x , i .y - 1 ));
200
+ if (i .x < width - 1 ) stack .push (new Location (i .x + 1 , i .y ));
201
+ if (i .y < height - 1 ) stack .push (new Location (i .x , i .y + 1 ));
202
+ }
203
+ }
204
+ }
205
+ }
206
+
207
+ public void fill (Area sel , String name ) {
208
+ int x = sel .getBounds ().x +1 ;
209
+ int y = sel .getBounds ().y +1 ;
210
+ if (x >= 0 && y >= 0 && x < width && y < height ) {
211
+
212
+ Stack <Location > stack = new Stack <>();
213
+ stack .push (new Location (x , y ));
214
+
215
+ while (!stack .isEmpty ()) {
216
+ Location i = stack .pop ();
217
+
218
+ if ((sel == null || (sel != null && sel .contains (i .x *map .getTileSize (), i .y *map .getTileSize ())))) {
197
219
set (name , i .x , i .y , false );
198
220
199
221
if (i .x > 0 ) stack .push (new Location (i .x - 1 , i .y ));
@@ -218,6 +240,10 @@ public GO select(float x, float y) {
218
240
return null ;
219
241
}
220
242
243
+ public void setMap (GameMap map ) {
244
+ this .map = map ;
245
+ }
246
+
221
247
/**
222
248
* @return the tile grid
223
249
*/
@@ -288,6 +314,17 @@ public float biggestY() {
288
314
return smallestY == Integer .MIN_VALUE ? -1 : smallestY ;
289
315
}
290
316
317
+ @ Override
318
+ public TileLayer clone () {
319
+ TileLayer out = new TileLayer (null , depth , width , height , tileSize );
320
+ for (int y = 0 ; y < height ; y ++) {
321
+ for (int x = 0 ; x < width ; x ++) {
322
+ out .tileNames [y ][x ] = tileNames [y ][x ];
323
+ }
324
+ }
325
+ return out ;
326
+ }
327
+
291
328
@ Override
292
329
public String toMapFormat (List <String > names , float sx , float sy , float bx , float by ) {
293
330
int startX = Math .max (0 , (int ) Math .floor (sx ));
0 commit comments