00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.map;
00023
00024 import com.realtime.crossfire.jxclient.faces.Face;
00025 import com.realtime.crossfire.jxclient.faces.FaceCache;
00026 import com.realtime.crossfire.jxclient.faces.FaceImages;
00027 import com.realtime.crossfire.jxclient.faces.FaceImagesUtils;
00028 import com.realtime.crossfire.jxclient.faces.FacesManager;
00029 import com.realtime.crossfire.jxclient.faces.TestFacesManager;
00030 import com.realtime.crossfire.jxclient.server.crossfire.messages.Map2;
00031 import java.io.IOException;
00032 import javax.swing.ImageIcon;
00033 import org.jetbrains.annotations.NotNull;
00034 import org.junit.Assert;
00035 import org.junit.Test;
00036
00042 public class MapUpdaterStateTest {
00043
00047 @NotNull
00048 private static final byte[] PNG32X32 = {
00049 (byte)0x89,
00050 (byte)0x50,
00051 (byte)0x4e,
00052 (byte)0x47,
00053 (byte)0x0d,
00054 (byte)0x0a,
00055 (byte)0x1a,
00056 (byte)0x0a,
00057 (byte)0x00,
00058 (byte)0x00,
00059 (byte)0x00,
00060 (byte)0x0d,
00061 (byte)0x49,
00062 (byte)0x48,
00063 (byte)0x44,
00064 (byte)0x52,
00065 (byte)0x00,
00066 (byte)0x00,
00067 (byte)0x00,
00068 (byte)0x20,
00069 (byte)0x00,
00070 (byte)0x00,
00071 (byte)0x00,
00072 (byte)0x20,
00073 (byte)0x08,
00074 (byte)0x06,
00075 (byte)0x00,
00076 (byte)0x00,
00077 (byte)0x00,
00078 (byte)0x73,
00079 (byte)0x7a,
00080 (byte)0x7a,
00081 (byte)0xf4,
00082 (byte)0x00,
00083 (byte)0x00,
00084 (byte)0x00,
00085 (byte)0x01,
00086 (byte)0x73,
00087 (byte)0x52,
00088 (byte)0x47,
00089 (byte)0x42,
00090 (byte)0x00,
00091 (byte)0xae,
00092 (byte)0xce,
00093 (byte)0x1c,
00094 (byte)0xe9,
00095 (byte)0x00,
00096 (byte)0x00,
00097 (byte)0x00,
00098 (byte)0x1a,
00099 (byte)0x49,
00100 (byte)0x44,
00101 (byte)0x41,
00102 (byte)0x54,
00103 (byte)0x58,
00104 (byte)0xc3,
00105 (byte)0xed,
00106 (byte)0xc1,
00107 (byte)0x01,
00108 (byte)0x01,
00109 (byte)0x00,
00110 (byte)0x00,
00111 (byte)0x00,
00112 (byte)0x82,
00113 (byte)0x20,
00114 (byte)0xff,
00115 (byte)0xaf,
00116 (byte)0x6e,
00117 (byte)0x48,
00118 (byte)0x40,
00119 (byte)0x01,
00120 (byte)0x00,
00121 (byte)0x00,
00122 (byte)0x00,
00123 (byte)0xef,
00124 (byte)0x06,
00125 (byte)0x10,
00126 (byte)0x20,
00127 (byte)0x00,
00128 (byte)0x01,
00129 (byte)0x97,
00130 (byte)0xf7,
00131 (byte)0x57,
00132 (byte)0xd7,
00133 (byte)0x00,
00134 (byte)0x00,
00135 (byte)0x00,
00136 (byte)0x00,
00137 (byte)0x49,
00138 (byte)0x45,
00139 (byte)0x4e,
00140 (byte)0x44,
00141 (byte)0xae,
00142 (byte)0x42,
00143 (byte)0x60,
00144 (byte)0x82,
00145 };
00146
00150 @NotNull
00151 private static final byte[] PNG64X64 = {
00152 (byte)0x89,
00153 (byte)0x50,
00154 (byte)0x4e,
00155 (byte)0x47,
00156 (byte)0x0d,
00157 (byte)0x0a,
00158 (byte)0x1a,
00159 (byte)0x0a,
00160 (byte)0x00,
00161 (byte)0x00,
00162 (byte)0x00,
00163 (byte)0x0d,
00164 (byte)0x49,
00165 (byte)0x48,
00166 (byte)0x44,
00167 (byte)0x52,
00168 (byte)0x00,
00169 (byte)0x00,
00170 (byte)0x00,
00171 (byte)0x40,
00172 (byte)0x00,
00173 (byte)0x00,
00174 (byte)0x00,
00175 (byte)0x40,
00176 (byte)0x08,
00177 (byte)0x06,
00178 (byte)0x00,
00179 (byte)0x00,
00180 (byte)0x00,
00181 (byte)0xaa,
00182 (byte)0x69,
00183 (byte)0x71,
00184 (byte)0xde,
00185 (byte)0x00,
00186 (byte)0x00,
00187 (byte)0x00,
00188 (byte)0x01,
00189 (byte)0x73,
00190 (byte)0x52,
00191 (byte)0x47,
00192 (byte)0x42,
00193 (byte)0x00,
00194 (byte)0xae,
00195 (byte)0xce,
00196 (byte)0x1c,
00197 (byte)0xe9,
00198 (byte)0x00,
00199 (byte)0x00,
00200 (byte)0x00,
00201 (byte)0x27,
00202 (byte)0x49,
00203 (byte)0x44,
00204 (byte)0x41,
00205 (byte)0x54,
00206 (byte)0x78,
00207 (byte)0xda,
00208 (byte)0xed,
00209 (byte)0xc1,
00210 (byte)0x01,
00211 (byte)0x0d,
00212 (byte)0x00,
00213 (byte)0x00,
00214 (byte)0x00,
00215 (byte)0xc2,
00216 (byte)0xa0,
00217 (byte)0xf7,
00218 (byte)0x4f,
00219 (byte)0x6d,
00220 (byte)0x0e,
00221 (byte)0x37,
00222 (byte)0xa0,
00223 (byte)0x00,
00224 (byte)0x00,
00225 (byte)0x00,
00226 (byte)0x00,
00227 (byte)0x00,
00228 (byte)0x00,
00229 (byte)0x00,
00230 (byte)0x00,
00231 (byte)0x00,
00232 (byte)0x00,
00233 (byte)0x00,
00234 (byte)0x00,
00235 (byte)0x00,
00236 (byte)0x00,
00237 (byte)0x00,
00238 (byte)0x80,
00239 (byte)0x77,
00240 (byte)0x03,
00241 (byte)0x40,
00242 (byte)0x40,
00243 (byte)0x00,
00244 (byte)0x01,
00245 (byte)0xaf,
00246 (byte)0x7a,
00247 (byte)0x0e,
00248 (byte)0xe8,
00249 (byte)0x00,
00250 (byte)0x00,
00251 (byte)0x00,
00252 (byte)0x00,
00253 (byte)0x49,
00254 (byte)0x45,
00255 (byte)0x4e,
00256 (byte)0x44,
00257 (byte)0xae,
00258 (byte)0x42,
00259 (byte)0x60,
00260 (byte)0x82,
00261 };
00262
00266 @NotNull
00267 private static final byte[] PNG128X256 = {
00268 (byte)0x89,
00269 (byte)0x50,
00270 (byte)0x4e,
00271 (byte)0x47,
00272 (byte)0x0d,
00273 (byte)0x0a,
00274 (byte)0x1a,
00275 (byte)0x0a,
00276 (byte)0x00,
00277 (byte)0x00,
00278 (byte)0x00,
00279 (byte)0x0d,
00280 (byte)0x49,
00281 (byte)0x48,
00282 (byte)0x44,
00283 (byte)0x52,
00284 (byte)0x00,
00285 (byte)0x00,
00286 (byte)0x00,
00287 (byte)0x80,
00288 (byte)0x00,
00289 (byte)0x00,
00290 (byte)0x01,
00291 (byte)0x00,
00292 (byte)0x08,
00293 (byte)0x06,
00294 (byte)0x00,
00295 (byte)0x00,
00296 (byte)0x00,
00297 (byte)0x7b,
00298 (byte)0xf9,
00299 (byte)0x7e,
00300 (byte)0xa7,
00301 (byte)0x00,
00302 (byte)0x00,
00303 (byte)0x00,
00304 (byte)0x01,
00305 (byte)0x73,
00306 (byte)0x52,
00307 (byte)0x47,
00308 (byte)0x42,
00309 (byte)0x00,
00310 (byte)0xae,
00311 (byte)0xce,
00312 (byte)0x1c,
00313 (byte)0xe9,
00314 (byte)0x00,
00315 (byte)0x00,
00316 (byte)0x00,
00317 (byte)0x95,
00318 (byte)0x49,
00319 (byte)0x44,
00320 (byte)0x41,
00321 (byte)0x54,
00322 (byte)0x78,
00323 (byte)0xda,
00324 (byte)0xed,
00325 (byte)0xc1,
00326 (byte)0x01,
00327 (byte)0x01,
00328 (byte)0x00,
00329 (byte)0x00,
00330 (byte)0x00,
00331 (byte)0x80,
00332 (byte)0x90,
00333 (byte)0xfe,
00334 (byte)0xaf,
00335 (byte)0xee,
00336 (byte)0x08,
00337 (byte)0x0a,
00338 (byte)0x00,
00339 (byte)0x00,
00340 (byte)0x00,
00341 (byte)0x00,
00342 (byte)0x00,
00343 (byte)0x00,
00344 (byte)0x00,
00345 (byte)0x00,
00346 (byte)0x00,
00347 (byte)0x00,
00348 (byte)0x00,
00349 (byte)0x00,
00350 (byte)0x00,
00351 (byte)0x00,
00352 (byte)0x00,
00353 (byte)0x00,
00354 (byte)0x00,
00355 (byte)0x00,
00356 (byte)0x00,
00357 (byte)0x00,
00358 (byte)0x00,
00359 (byte)0x00,
00360 (byte)0x00,
00361 (byte)0x00,
00362 (byte)0x00,
00363 (byte)0x00,
00364 (byte)0x00,
00365 (byte)0x00,
00366 (byte)0x00,
00367 (byte)0x00,
00368 (byte)0x00,
00369 (byte)0x00,
00370 (byte)0x00,
00371 (byte)0x00,
00372 (byte)0x00,
00373 (byte)0x00,
00374 (byte)0x00,
00375 (byte)0x00,
00376 (byte)0x00,
00377 (byte)0x00,
00378 (byte)0x00,
00379 (byte)0x00,
00380 (byte)0x00,
00381 (byte)0x00,
00382 (byte)0x00,
00383 (byte)0x00,
00384 (byte)0x00,
00385 (byte)0x00,
00386 (byte)0x00,
00387 (byte)0x00,
00388 (byte)0x00,
00389 (byte)0x00,
00390 (byte)0x00,
00391 (byte)0x00,
00392 (byte)0x00,
00393 (byte)0x00,
00394 (byte)0x00,
00395 (byte)0x00,
00396 (byte)0x00,
00397 (byte)0x00,
00398 (byte)0x00,
00399 (byte)0x00,
00400 (byte)0x00,
00401 (byte)0x00,
00402 (byte)0x00,
00403 (byte)0x00,
00404 (byte)0x00,
00405 (byte)0x00,
00406 (byte)0x00,
00407 (byte)0x00,
00408 (byte)0x00,
00409 (byte)0x00,
00410 (byte)0x00,
00411 (byte)0x00,
00412 (byte)0x00,
00413 (byte)0x00,
00414 (byte)0x00,
00415 (byte)0x00,
00416 (byte)0x00,
00417 (byte)0x00,
00418 (byte)0x00,
00419 (byte)0x00,
00420 (byte)0x00,
00421 (byte)0x00,
00422 (byte)0x00,
00423 (byte)0x00,
00424 (byte)0x00,
00425 (byte)0x00,
00426 (byte)0x00,
00427 (byte)0x00,
00428 (byte)0x00,
00429 (byte)0x00,
00430 (byte)0x00,
00431 (byte)0x00,
00432 (byte)0x00,
00433 (byte)0x00,
00434 (byte)0x00,
00435 (byte)0x00,
00436 (byte)0x00,
00437 (byte)0x00,
00438 (byte)0x00,
00439 (byte)0x00,
00440 (byte)0x00,
00441 (byte)0x00,
00442 (byte)0x00,
00443 (byte)0x00,
00444 (byte)0x00,
00445 (byte)0x00,
00446 (byte)0x00,
00447 (byte)0x00,
00448 (byte)0x00,
00449 (byte)0x00,
00450 (byte)0x00,
00451 (byte)0x00,
00452 (byte)0x00,
00453 (byte)0x00,
00454 (byte)0x00,
00455 (byte)0x00,
00456 (byte)0x00,
00457 (byte)0x00,
00458 (byte)0x00,
00459 (byte)0x00,
00460 (byte)0x00,
00461 (byte)0x00,
00462 (byte)0x00,
00463 (byte)0x00,
00464 (byte)0x80,
00465 (byte)0xaa,
00466 (byte)0x01,
00467 (byte)0x01,
00468 (byte)0x1e,
00469 (byte)0x00,
00470 (byte)0x01,
00471 (byte)0xbc,
00472 (byte)0x1b,
00473 (byte)0xb9,
00474 (byte)0x6f,
00475 (byte)0x00,
00476 (byte)0x00,
00477 (byte)0x00,
00478 (byte)0x00,
00479 (byte)0x49,
00480 (byte)0x45,
00481 (byte)0x4e,
00482 (byte)0x44,
00483 (byte)0xae,
00484 (byte)0x42,
00485 (byte)0x60,
00486 (byte)0x82,
00487 };
00488
00494 @Test
00495 public void testFogOfWar1() throws IOException {
00496 final FaceCache faceCache = new FaceCache();
00497 final FacesManager facesManager = new TestFacesManager(faceCache);
00498 defineFace(faceCache, 1, "M", PNG64X64);
00499 defineFace(faceCache, 2, "_", PNG32X32);
00500
00501 final MapUpdaterState mapUpdaterState = new MapUpdaterState(facesManager, null);
00502
00503 mapUpdaterState.newMap(5, 5);
00504 synchronized (mapUpdaterState.mapBegin()) {
00505 mapUpdaterState.mapFace(new Location(0, 0, 0), 2, true);
00506 mapUpdaterState.mapFace(new Location(1, 0, 0), 2, true);
00507 mapUpdaterState.mapFace(new Location(0, 1, 0), 2, true);
00508 mapUpdaterState.mapFace(new Location(1, 1, 0), 2, true);
00509 mapUpdaterState.mapFace(new Location(1, 1, 6), 1, true);
00510 mapUpdaterState.mapEnd(true);
00511 }
00512 Assert.assertEquals(""+"[H0=_,T6=M][H0=_,T6=M]\n"+"[H0=_,T6=M][H0=_,H6=M]\n", toString(mapUpdaterState.getMap(), 0, 0, 2, 2));
00513
00514 synchronized (mapUpdaterState.mapBegin()) {
00515 mapUpdaterState.mapClear(1, 0);
00516 mapUpdaterState.mapEnd(true);
00517 }
00518 Assert.assertEquals(""+"[H0=_,T6=M][#,H0=_,T6=M]\n"+"[H0=_,T6=M][H0=_,H6=M]\n", toString(mapUpdaterState.getMap(), 0, 0, 2, 2));
00519
00520 synchronized (mapUpdaterState.mapBegin()) {
00521 mapUpdaterState.mapClear(1, 1);
00522 mapUpdaterState.mapEnd(true);
00523 }
00524 Assert.assertEquals(""+"[H0=_][#,H0=_,T6=M]\n"+"[H0=_][#,H0=_,H6=M]\n", toString(mapUpdaterState.getMap(), 0, 0, 2, 2));
00525 }
00526
00531 @Test
00532 public void testDisplayArtifacts1() throws IOException {
00533 final FaceCache faceCache = new FaceCache();
00534 final FacesManager facesManager = new TestFacesManager(faceCache);
00535 defineFace(faceCache, 307, "behemoth.x31", PNG64X64);
00536 defineFace(faceCache, 308, "behemoth.x32", PNG64X64);
00537 defineFace(faceCache, 309, "behemoth.x33", PNG64X64);
00538 defineFace(faceCache, 310, "behemoth.x71", PNG64X64);
00539 defineFace(faceCache, 932, "charwoman.132", PNG32X32);
00540 defineFace(faceCache, 4607, "woodfloor.111", PNG32X32);
00541 defineFace(faceCache, 312, "behemoth.x73", PNG64X64);
00542
00543 final MapUpdaterState mapUpdaterState = new MapUpdaterState(facesManager, null);
00544
00545 mapUpdaterState.newMap(10, 10);
00546 synchronized (mapUpdaterState.mapBegin()) {
00547 mapUpdaterState.mapFace(new Location(7, 8, 0), 4607, true);
00548 mapUpdaterState.mapFace(new Location(8, 8, 0), 4607, true);
00549 mapUpdaterState.mapFace(new Location(9, 8, 0), 4607, true);
00550 mapUpdaterState.mapFace(new Location(7, 9, 0), 4607, true);
00551 mapUpdaterState.mapFace(new Location(8, 9, 0), 4607, true);
00552 mapUpdaterState.mapFace(new Location(9, 9, 0), 4607, true);
00553 mapUpdaterState.mapFace(new Location(9, 9, 6), 312, true);
00554 mapUpdaterState.mapEnd(true);
00555 }
00556
00557 mapUpdaterState.tick(26);
00558 synchronized (mapUpdaterState.mapBegin()) {
00559 mapUpdaterState.mapFace(new Location(9, 9, 6), 307, true);
00560 mapUpdaterState.mapEnd(true);
00561 }
00562
00563 mapUpdaterState.tick(27);
00564 mapUpdaterState.tick(28);
00565 synchronized (mapUpdaterState.mapBegin()) {
00566 mapUpdaterState.mapFace(new Location(9, 9, 6), 308, true);
00567 mapUpdaterState.mapEnd(true);
00568 }
00569
00570 mapUpdaterState.tick(29);
00571 synchronized (mapUpdaterState.mapBegin()) {
00572 mapUpdaterState.mapFace(new Location(0, 5, 6), 0, true);
00573 mapUpdaterState.mapEnd(true);
00574 }
00575
00576 mapUpdaterState.tick(30);
00577 synchronized (mapUpdaterState.mapBegin()) {
00578 mapUpdaterState.mapFace(new Location(9, 9, 6), 309, true);
00579 mapUpdaterState.mapEnd(true);
00580 }
00581
00582 mapUpdaterState.tick(31);
00583 mapUpdaterState.tick(32);
00584 synchronized (mapUpdaterState.mapBegin()) {
00585 mapUpdaterState.mapFace(new Location(9, 9, 6), 308, true);
00586 mapUpdaterState.mapEnd(true);
00587 }
00588
00589 mapUpdaterState.tick(33);
00590 mapUpdaterState.tick(34);
00591 synchronized (mapUpdaterState.mapBegin()) {
00592 mapUpdaterState.mapFace(new Location(9, 9, 6), 0, true);
00593 mapUpdaterState.mapFace(new Location(10, 9, 6), 307, true);
00594 mapUpdaterState.mapEnd(true);
00595 }
00596
00597 mapUpdaterState.tick(35);
00598 mapUpdaterState.tick(36);
00599 synchronized (mapUpdaterState.mapBegin()) {
00600 mapUpdaterState.mapFace(new Location(0, 6, 6), 932, true);
00601 mapUpdaterState.mapFace(new Location(9, 9, 6), 312, true);
00602 mapUpdaterState.mapClear(10, 9);
00603 mapUpdaterState.mapEnd(true);
00604 }
00605
00606 mapUpdaterState.tick(37);
00607 mapUpdaterState.tick(38);
00608 synchronized (mapUpdaterState.mapBegin()) {
00609 mapUpdaterState.mapFace(new Location(8, 9, 6), 310, true);
00610 mapUpdaterState.mapFace(new Location(9, 9, 6), 0, true);
00611 mapUpdaterState.mapEnd(true);
00612 }
00613
00614 mapUpdaterState.tick(39);
00615
00616 Assert.assertEquals(""+"[H0=woodfloor.111,T6=behemoth.x71][H0=woodfloor.111,T6=behemoth.x71][H0=woodfloor.111][]\n"+"[H0=woodfloor.111,T6=behemoth.x71][H0=woodfloor.111,H6=behemoth.x71][H0=woodfloor.111][#,H6=behemoth.x31]\n", toString(mapUpdaterState.getMap(), 7, 8, 4, 2));
00617 }
00618
00623 @Test
00624 public void testDisplayArtifacts2() throws IOException {
00625 final FaceCache faceCache = new FaceCache();
00626 final FacesManager facesManager = new TestFacesManager(faceCache);
00627 defineFace(faceCache, 7, "a.x11", PNG64X64);
00628 defineFace(faceCache, 8, "b.x12", PNG64X64);
00629
00630 final MapUpdaterState mapUpdaterState = new MapUpdaterState(facesManager, null);
00631
00632 mapUpdaterState.newMap(10, 10);
00633 synchronized (mapUpdaterState.mapBegin()) {
00634 mapUpdaterState.mapFace(new Location(5, 10, 6), 7, true);
00635 mapUpdaterState.mapEnd(true);
00636 }
00637
00638 synchronized (mapUpdaterState.mapBegin()) {
00639 mapUpdaterState.mapFace(new Location(4, 10, 6), 8, true);
00640 mapUpdaterState.mapClear(5, 10);
00641 mapUpdaterState.mapEnd(true);
00642 }
00643
00644 Assert.assertEquals(""+"[T6=b.x12][T6=b.x12][]\n"+"[T6=b.x12][H6=b.x12][#,H6=a.x11]\n", toString(mapUpdaterState.getMap(), 3, 9, 3, 2));
00645 }
00646
00651 @Test
00652 public void testDisplayArtifacts3() throws IOException {
00653 final FaceCache faceCache = new FaceCache();
00654 final FacesManager facesManager = new TestFacesManager(faceCache);
00655 final MapUpdaterState mapUpdaterState = new MapUpdaterState(facesManager, null);
00656
00657 mapUpdaterState.newMap(23, 16);
00658 defineFace(faceCache, 1316, "demon_lord.x11", PNG128X256);
00659
00660 synchronized (mapUpdaterState.mapBegin()) {
00661 mapUpdaterState.mapFace(new Location(4, 17, 6), 1316, true);
00662 mapUpdaterState.mapEnd(true);
00663 }
00664
00665 synchronized (mapUpdaterState.mapBegin()) {
00666 mapUpdaterState.mapScroll(-1, 0);
00667 mapUpdaterState.mapFace(new Location(5, 17, 6), 1316, true);
00668 mapUpdaterState.mapEnd(true);
00669 }
00670
00671 synchronized (mapUpdaterState.mapBegin()) {
00672 mapUpdaterState.mapClear(5, 17);
00673 mapUpdaterState.mapFace(new Location(6, 17, 6), 1316, true);
00674 mapUpdaterState.mapEnd(true);
00675 }
00676
00677 synchronized (mapUpdaterState.mapBegin()) {
00678 mapUpdaterState.mapScroll(-1, 0);
00679 mapUpdaterState.mapFace(new Location(7, 17, 6), 1316, true);
00680 mapUpdaterState.mapEnd(true);
00681 }
00682
00683 synchronized (mapUpdaterState.mapBegin()) {
00684 mapUpdaterState.mapScroll(-1, 0);
00685 mapUpdaterState.mapFace(new Location(8, 17, 6), 1316, true);
00686 mapUpdaterState.mapEnd(true);
00687 }
00688
00689 synchronized (mapUpdaterState.mapBegin()) {
00690 mapUpdaterState.mapScroll(-1, 0);
00691 mapUpdaterState.mapFace(new Location(9, 17, 6), 1316, true);
00692 mapUpdaterState.mapEnd(true);
00693 }
00694 Assert.assertEquals(""+"[][T6=demon_lord.x11][T6=demon_lord.x11][T6=demon_lord.x11][T6=demon_lord.x11][][][][]\n", toString(mapUpdaterState.getMap(), 5, 10, 9, 1));
00695
00696 synchronized (mapUpdaterState.mapBegin()) {
00697 mapUpdaterState.mapScroll(-1, 0);
00698 mapUpdaterState.mapFace(new Location(11, 17, 6), 1316, true);
00699 mapUpdaterState.mapEnd();
00700 }
00701 Assert.assertEquals(""+"[][][][T6=demon_lord.x11][T6=demon_lord.x11][T6=demon_lord.x11][T6=demon_lord.x11][][]\n", toString(mapUpdaterState.getMap(), 5, 10, 9, 1));
00702 }
00703
00714 @NotNull
00715 private static String toString(@NotNull final CfMap map, final int x0, final int y0, final int w, final int h) {
00716 final StringBuilder sb = new StringBuilder();
00717
00718 synchronized (map) {
00719 for (int y = y0; y < y0+h; y++) {
00720 for (int x = x0; x < x0+w; x++) {
00721 sb.append('[');
00722
00723 boolean firstFace = true;
00724
00725 if (map.isFogOfWar(x, y)) {
00726 sb.append('#');
00727 firstFace = false;
00728 }
00729
00730 for (int l = 0; l < Map2.NUM_LAYERS; l++) {
00731 final Face face = map.getFace(x, y, l);
00732 if (face != null) {
00733 if (!firstFace) {
00734 sb.append(',');
00735 }
00736 sb.append('H');
00737 sb.append(l);
00738 sb.append('=');
00739 sb.append(face.getFaceName());
00740 firstFace = false;
00741 }
00742
00743 final CfMapSquare headMapSquare = map.getHeadMapSquare(x, y, l);
00744 if (headMapSquare != null) {
00745 final Face headFace = headMapSquare.getFace(l);
00746 if (!firstFace) {
00747 sb.append(',');
00748 }
00749 sb.append('T');
00750 sb.append(l);
00751 sb.append('=');
00752 sb.append(headFace == null ? "null" : headFace.getFaceName());
00753 firstFace = false;
00754 }
00755 }
00756 sb.append(']');
00757 }
00758 sb.append('\n');
00759 }
00760 }
00761 return sb.toString();
00762 }
00763
00771 private static void defineFace(@NotNull final FaceCache faceCache, final int faceNum, @NotNull final String faceName, @NotNull final byte[] data) {
00772 final Face face = new Face(faceNum, faceName, 0);
00773 faceCache.addFace(face);
00774
00775 final ImageIcon originalImageIcon;
00776 try {
00777 originalImageIcon = new ImageIcon(data);
00778 } catch (final IllegalArgumentException ex) {
00779 Assert.fail("Invalid .png data for face "+face+": "+ex.getMessage());
00780 throw new AssertionError(ex);
00781 }
00782
00783 if (originalImageIcon.getIconWidth() <= 0 || originalImageIcon.getIconHeight() <= 0) {
00784 Assert.fail("Invalid .png size for face "+face);
00785 throw new AssertionError();
00786 }
00787
00788 final FaceImages faceImages = FaceImagesUtils.newFaceImages(originalImageIcon);
00789 face.setFaceImages(faceImages);
00790 }
00791
00792 }