Crossfire JXClient, Trunk  R20561
MapUpdaterStateTest.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.map;
23 
31 import java.io.IOException;
32 import javax.swing.ImageIcon;
33 import org.jetbrains.annotations.NotNull;
34 import org.junit.Assert;
35 import org.junit.Test;
36 
42 public class MapUpdaterStateTest {
43 
47  @NotNull
48  private static final byte[] PNG32X32 = {
49  (byte)0x89,
50  (byte)0x50,
51  (byte)0x4e,
52  (byte)0x47,
53  (byte)0x0d,
54  (byte)0x0a,
55  (byte)0x1a,
56  (byte)0x0a,
57  (byte)0x00,
58  (byte)0x00,
59  (byte)0x00,
60  (byte)0x0d,
61  (byte)0x49,
62  (byte)0x48,
63  (byte)0x44,
64  (byte)0x52,
65  (byte)0x00,
66  (byte)0x00,
67  (byte)0x00,
68  (byte)0x20,
69  (byte)0x00,
70  (byte)0x00,
71  (byte)0x00,
72  (byte)0x20,
73  (byte)0x08,
74  (byte)0x06,
75  (byte)0x00,
76  (byte)0x00,
77  (byte)0x00,
78  (byte)0x73,
79  (byte)0x7a,
80  (byte)0x7a,
81  (byte)0xf4,
82  (byte)0x00,
83  (byte)0x00,
84  (byte)0x00,
85  (byte)0x01,
86  (byte)0x73,
87  (byte)0x52,
88  (byte)0x47,
89  (byte)0x42,
90  (byte)0x00,
91  (byte)0xae,
92  (byte)0xce,
93  (byte)0x1c,
94  (byte)0xe9,
95  (byte)0x00,
96  (byte)0x00,
97  (byte)0x00,
98  (byte)0x1a,
99  (byte)0x49,
100  (byte)0x44,
101  (byte)0x41,
102  (byte)0x54,
103  (byte)0x58,
104  (byte)0xc3,
105  (byte)0xed,
106  (byte)0xc1,
107  (byte)0x01,
108  (byte)0x01,
109  (byte)0x00,
110  (byte)0x00,
111  (byte)0x00,
112  (byte)0x82,
113  (byte)0x20,
114  (byte)0xff,
115  (byte)0xaf,
116  (byte)0x6e,
117  (byte)0x48,
118  (byte)0x40,
119  (byte)0x01,
120  (byte)0x00,
121  (byte)0x00,
122  (byte)0x00,
123  (byte)0xef,
124  (byte)0x06,
125  (byte)0x10,
126  (byte)0x20,
127  (byte)0x00,
128  (byte)0x01,
129  (byte)0x97,
130  (byte)0xf7,
131  (byte)0x57,
132  (byte)0xd7,
133  (byte)0x00,
134  (byte)0x00,
135  (byte)0x00,
136  (byte)0x00,
137  (byte)0x49,
138  (byte)0x45,
139  (byte)0x4e,
140  (byte)0x44,
141  (byte)0xae,
142  (byte)0x42,
143  (byte)0x60,
144  (byte)0x82,
145  };
146 
150  @NotNull
151  private static final byte[] PNG64X64 = {
152  (byte)0x89,
153  (byte)0x50,
154  (byte)0x4e,
155  (byte)0x47,
156  (byte)0x0d,
157  (byte)0x0a,
158  (byte)0x1a,
159  (byte)0x0a,
160  (byte)0x00,
161  (byte)0x00,
162  (byte)0x00,
163  (byte)0x0d,
164  (byte)0x49,
165  (byte)0x48,
166  (byte)0x44,
167  (byte)0x52,
168  (byte)0x00,
169  (byte)0x00,
170  (byte)0x00,
171  (byte)0x40,
172  (byte)0x00,
173  (byte)0x00,
174  (byte)0x00,
175  (byte)0x40,
176  (byte)0x08,
177  (byte)0x06,
178  (byte)0x00,
179  (byte)0x00,
180  (byte)0x00,
181  (byte)0xaa,
182  (byte)0x69,
183  (byte)0x71,
184  (byte)0xde,
185  (byte)0x00,
186  (byte)0x00,
187  (byte)0x00,
188  (byte)0x01,
189  (byte)0x73,
190  (byte)0x52,
191  (byte)0x47,
192  (byte)0x42,
193  (byte)0x00,
194  (byte)0xae,
195  (byte)0xce,
196  (byte)0x1c,
197  (byte)0xe9,
198  (byte)0x00,
199  (byte)0x00,
200  (byte)0x00,
201  (byte)0x27,
202  (byte)0x49,
203  (byte)0x44,
204  (byte)0x41,
205  (byte)0x54,
206  (byte)0x78,
207  (byte)0xda,
208  (byte)0xed,
209  (byte)0xc1,
210  (byte)0x01,
211  (byte)0x0d,
212  (byte)0x00,
213  (byte)0x00,
214  (byte)0x00,
215  (byte)0xc2,
216  (byte)0xa0,
217  (byte)0xf7,
218  (byte)0x4f,
219  (byte)0x6d,
220  (byte)0x0e,
221  (byte)0x37,
222  (byte)0xa0,
223  (byte)0x00,
224  (byte)0x00,
225  (byte)0x00,
226  (byte)0x00,
227  (byte)0x00,
228  (byte)0x00,
229  (byte)0x00,
230  (byte)0x00,
231  (byte)0x00,
232  (byte)0x00,
233  (byte)0x00,
234  (byte)0x00,
235  (byte)0x00,
236  (byte)0x00,
237  (byte)0x00,
238  (byte)0x80,
239  (byte)0x77,
240  (byte)0x03,
241  (byte)0x40,
242  (byte)0x40,
243  (byte)0x00,
244  (byte)0x01,
245  (byte)0xaf,
246  (byte)0x7a,
247  (byte)0x0e,
248  (byte)0xe8,
249  (byte)0x00,
250  (byte)0x00,
251  (byte)0x00,
252  (byte)0x00,
253  (byte)0x49,
254  (byte)0x45,
255  (byte)0x4e,
256  (byte)0x44,
257  (byte)0xae,
258  (byte)0x42,
259  (byte)0x60,
260  (byte)0x82,
261  };
262 
266  @NotNull
267  private static final byte[] PNG128X256 = {
268  (byte)0x89,
269  (byte)0x50,
270  (byte)0x4e,
271  (byte)0x47,
272  (byte)0x0d,
273  (byte)0x0a,
274  (byte)0x1a,
275  (byte)0x0a,
276  (byte)0x00,
277  (byte)0x00,
278  (byte)0x00,
279  (byte)0x0d,
280  (byte)0x49,
281  (byte)0x48,
282  (byte)0x44,
283  (byte)0x52,
284  (byte)0x00,
285  (byte)0x00,
286  (byte)0x00,
287  (byte)0x80,
288  (byte)0x00,
289  (byte)0x00,
290  (byte)0x01,
291  (byte)0x00,
292  (byte)0x08,
293  (byte)0x06,
294  (byte)0x00,
295  (byte)0x00,
296  (byte)0x00,
297  (byte)0x7b,
298  (byte)0xf9,
299  (byte)0x7e,
300  (byte)0xa7,
301  (byte)0x00,
302  (byte)0x00,
303  (byte)0x00,
304  (byte)0x01,
305  (byte)0x73,
306  (byte)0x52,
307  (byte)0x47,
308  (byte)0x42,
309  (byte)0x00,
310  (byte)0xae,
311  (byte)0xce,
312  (byte)0x1c,
313  (byte)0xe9,
314  (byte)0x00,
315  (byte)0x00,
316  (byte)0x00,
317  (byte)0x95,
318  (byte)0x49,
319  (byte)0x44,
320  (byte)0x41,
321  (byte)0x54,
322  (byte)0x78,
323  (byte)0xda,
324  (byte)0xed,
325  (byte)0xc1,
326  (byte)0x01,
327  (byte)0x01,
328  (byte)0x00,
329  (byte)0x00,
330  (byte)0x00,
331  (byte)0x80,
332  (byte)0x90,
333  (byte)0xfe,
334  (byte)0xaf,
335  (byte)0xee,
336  (byte)0x08,
337  (byte)0x0a,
338  (byte)0x00,
339  (byte)0x00,
340  (byte)0x00,
341  (byte)0x00,
342  (byte)0x00,
343  (byte)0x00,
344  (byte)0x00,
345  (byte)0x00,
346  (byte)0x00,
347  (byte)0x00,
348  (byte)0x00,
349  (byte)0x00,
350  (byte)0x00,
351  (byte)0x00,
352  (byte)0x00,
353  (byte)0x00,
354  (byte)0x00,
355  (byte)0x00,
356  (byte)0x00,
357  (byte)0x00,
358  (byte)0x00,
359  (byte)0x00,
360  (byte)0x00,
361  (byte)0x00,
362  (byte)0x00,
363  (byte)0x00,
364  (byte)0x00,
365  (byte)0x00,
366  (byte)0x00,
367  (byte)0x00,
368  (byte)0x00,
369  (byte)0x00,
370  (byte)0x00,
371  (byte)0x00,
372  (byte)0x00,
373  (byte)0x00,
374  (byte)0x00,
375  (byte)0x00,
376  (byte)0x00,
377  (byte)0x00,
378  (byte)0x00,
379  (byte)0x00,
380  (byte)0x00,
381  (byte)0x00,
382  (byte)0x00,
383  (byte)0x00,
384  (byte)0x00,
385  (byte)0x00,
386  (byte)0x00,
387  (byte)0x00,
388  (byte)0x00,
389  (byte)0x00,
390  (byte)0x00,
391  (byte)0x00,
392  (byte)0x00,
393  (byte)0x00,
394  (byte)0x00,
395  (byte)0x00,
396  (byte)0x00,
397  (byte)0x00,
398  (byte)0x00,
399  (byte)0x00,
400  (byte)0x00,
401  (byte)0x00,
402  (byte)0x00,
403  (byte)0x00,
404  (byte)0x00,
405  (byte)0x00,
406  (byte)0x00,
407  (byte)0x00,
408  (byte)0x00,
409  (byte)0x00,
410  (byte)0x00,
411  (byte)0x00,
412  (byte)0x00,
413  (byte)0x00,
414  (byte)0x00,
415  (byte)0x00,
416  (byte)0x00,
417  (byte)0x00,
418  (byte)0x00,
419  (byte)0x00,
420  (byte)0x00,
421  (byte)0x00,
422  (byte)0x00,
423  (byte)0x00,
424  (byte)0x00,
425  (byte)0x00,
426  (byte)0x00,
427  (byte)0x00,
428  (byte)0x00,
429  (byte)0x00,
430  (byte)0x00,
431  (byte)0x00,
432  (byte)0x00,
433  (byte)0x00,
434  (byte)0x00,
435  (byte)0x00,
436  (byte)0x00,
437  (byte)0x00,
438  (byte)0x00,
439  (byte)0x00,
440  (byte)0x00,
441  (byte)0x00,
442  (byte)0x00,
443  (byte)0x00,
444  (byte)0x00,
445  (byte)0x00,
446  (byte)0x00,
447  (byte)0x00,
448  (byte)0x00,
449  (byte)0x00,
450  (byte)0x00,
451  (byte)0x00,
452  (byte)0x00,
453  (byte)0x00,
454  (byte)0x00,
455  (byte)0x00,
456  (byte)0x00,
457  (byte)0x00,
458  (byte)0x00,
459  (byte)0x00,
460  (byte)0x00,
461  (byte)0x00,
462  (byte)0x00,
463  (byte)0x00,
464  (byte)0x80,
465  (byte)0xaa,
466  (byte)0x01,
467  (byte)0x01,
468  (byte)0x1e,
469  (byte)0x00,
470  (byte)0x01,
471  (byte)0xbc,
472  (byte)0x1b,
473  (byte)0xb9,
474  (byte)0x6f,
475  (byte)0x00,
476  (byte)0x00,
477  (byte)0x00,
478  (byte)0x00,
479  (byte)0x49,
480  (byte)0x45,
481  (byte)0x4e,
482  (byte)0x44,
483  (byte)0xae,
484  (byte)0x42,
485  (byte)0x60,
486  (byte)0x82,
487  };
488 
494  @Test
495  public void testFogOfWar1() throws IOException {
496  final FaceCache faceCache = new FaceCache();
497  final FacesManager facesManager = new TestFacesManager(faceCache);
498  defineFace(faceCache, 1, "M", PNG64X64);
499  defineFace(faceCache, 2, "_", PNG32X32);
500 
501  final MapUpdaterState mapUpdaterState = new MapUpdaterState(facesManager, null);
502 
503  mapUpdaterState.newMap(5, 5);
504  synchronized (mapUpdaterState.mapBegin()) {
505  mapUpdaterState.mapFace(new Location(0, 0, 0), 2, true);
506  mapUpdaterState.mapFace(new Location(1, 0, 0), 2, true);
507  mapUpdaterState.mapFace(new Location(0, 1, 0), 2, true);
508  mapUpdaterState.mapFace(new Location(1, 1, 0), 2, true);
509  mapUpdaterState.mapFace(new Location(1, 1, 6), 1, true);
510  mapUpdaterState.mapEnd(true);
511  }
512  Assert.assertEquals(""+"[H0=_,T6=M][H0=_,T6=M]\n"+"[H0=_,T6=M][H0=_,H6=M]\n", toString(mapUpdaterState.getMap(), 0, 0, 2, 2));
513 
514  synchronized (mapUpdaterState.mapBegin()) {
515  mapUpdaterState.mapClear(1, 0);
516  mapUpdaterState.mapEnd(true);
517  }
518  Assert.assertEquals(""+"[H0=_,T6=M][#,H0=_,T6=M]\n"+"[H0=_,T6=M][H0=_,H6=M]\n", toString(mapUpdaterState.getMap(), 0, 0, 2, 2));
519 
520  synchronized (mapUpdaterState.mapBegin()) {
521  mapUpdaterState.mapClear(1, 1);
522  mapUpdaterState.mapEnd(true);
523  }
524  Assert.assertEquals(""+"[H0=_][#,H0=_,T6=M]\n"+"[H0=_][#,H0=_,H6=M]\n", toString(mapUpdaterState.getMap(), 0, 0, 2, 2));
525  }
526 
531  @Test
532  public void testDisplayArtifacts1() throws IOException {
533  final FaceCache faceCache = new FaceCache();
534  final FacesManager facesManager = new TestFacesManager(faceCache);
535  defineFace(faceCache, 307, "behemoth.x31", PNG64X64);
536  defineFace(faceCache, 308, "behemoth.x32", PNG64X64);
537  defineFace(faceCache, 309, "behemoth.x33", PNG64X64);
538  defineFace(faceCache, 310, "behemoth.x71", PNG64X64);
539  defineFace(faceCache, 932, "charwoman.132", PNG32X32);
540  defineFace(faceCache, 4607, "woodfloor.111", PNG32X32);
541  defineFace(faceCache, 312, "behemoth.x73", PNG64X64);
542 
543  final MapUpdaterState mapUpdaterState = new MapUpdaterState(facesManager, null);
544 
545  mapUpdaterState.newMap(10, 10);
546  synchronized (mapUpdaterState.mapBegin()) {
547  mapUpdaterState.mapFace(new Location(7, 8, 0), 4607, true);
548  mapUpdaterState.mapFace(new Location(8, 8, 0), 4607, true);
549  mapUpdaterState.mapFace(new Location(9, 8, 0), 4607, true);
550  mapUpdaterState.mapFace(new Location(7, 9, 0), 4607, true);
551  mapUpdaterState.mapFace(new Location(8, 9, 0), 4607, true);
552  mapUpdaterState.mapFace(new Location(9, 9, 0), 4607, true);
553  mapUpdaterState.mapFace(new Location(9, 9, 6), 312, true);
554  mapUpdaterState.mapEnd(true);
555  }
556 
557  mapUpdaterState.tick(26);
558  synchronized (mapUpdaterState.mapBegin()) {
559  mapUpdaterState.mapFace(new Location(9, 9, 6), 307, true);
560  mapUpdaterState.mapEnd(true);
561  }
562 
563  mapUpdaterState.tick(27);
564  mapUpdaterState.tick(28);
565  synchronized (mapUpdaterState.mapBegin()) {
566  mapUpdaterState.mapFace(new Location(9, 9, 6), 308, true);
567  mapUpdaterState.mapEnd(true);
568  }
569 
570  mapUpdaterState.tick(29);
571  synchronized (mapUpdaterState.mapBegin()) {
572  mapUpdaterState.mapFace(new Location(0, 5, 6), 0, true);
573  mapUpdaterState.mapEnd(true);
574  }
575 
576  mapUpdaterState.tick(30);
577  synchronized (mapUpdaterState.mapBegin()) {
578  mapUpdaterState.mapFace(new Location(9, 9, 6), 309, true);
579  mapUpdaterState.mapEnd(true);
580  }
581 
582  mapUpdaterState.tick(31);
583  mapUpdaterState.tick(32);
584  synchronized (mapUpdaterState.mapBegin()) {
585  mapUpdaterState.mapFace(new Location(9, 9, 6), 308, true);
586  mapUpdaterState.mapEnd(true);
587  }
588 
589  mapUpdaterState.tick(33);
590  mapUpdaterState.tick(34);
591  synchronized (mapUpdaterState.mapBegin()) {
592  mapUpdaterState.mapFace(new Location(9, 9, 6), 0, true);
593  mapUpdaterState.mapFace(new Location(10, 9, 6), 307, true);
594  mapUpdaterState.mapEnd(true);
595  }
596 
597  mapUpdaterState.tick(35);
598  mapUpdaterState.tick(36);
599  synchronized (mapUpdaterState.mapBegin()) {
600  mapUpdaterState.mapFace(new Location(0, 6, 6), 932, true);
601  mapUpdaterState.mapFace(new Location(9, 9, 6), 312, true);
602  mapUpdaterState.mapClear(10, 9);
603  mapUpdaterState.mapEnd(true);
604  }
605 
606  mapUpdaterState.tick(37);
607  mapUpdaterState.tick(38);
608  synchronized (mapUpdaterState.mapBegin()) {
609  mapUpdaterState.mapFace(new Location(8, 9, 6), 310, true);
610  mapUpdaterState.mapFace(new Location(9, 9, 6), 0, true);
611  mapUpdaterState.mapEnd(true);
612  }
613 
614  mapUpdaterState.tick(39);
615 
616  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));
617  }
618 
623  @Test
624  public void testDisplayArtifacts2() throws IOException {
625  final FaceCache faceCache = new FaceCache();
626  final FacesManager facesManager = new TestFacesManager(faceCache);
627  defineFace(faceCache, 7, "a.x11", PNG64X64);
628  defineFace(faceCache, 8, "b.x12", PNG64X64);
629 
630  final MapUpdaterState mapUpdaterState = new MapUpdaterState(facesManager, null);
631 
632  mapUpdaterState.newMap(10, 10);
633  synchronized (mapUpdaterState.mapBegin()) {
634  mapUpdaterState.mapFace(new Location(5, 10, 6), 7, true);
635  mapUpdaterState.mapEnd(true);
636  }
637 
638  synchronized (mapUpdaterState.mapBegin()) {
639  mapUpdaterState.mapFace(new Location(4, 10, 6), 8, true);
640  mapUpdaterState.mapClear(5, 10);
641  mapUpdaterState.mapEnd(true);
642  }
643 
644  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));
645  }
646 
651  @Test
652  public void testDisplayArtifacts3() throws IOException {
653  final FaceCache faceCache = new FaceCache();
654  final FacesManager facesManager = new TestFacesManager(faceCache);
655  final MapUpdaterState mapUpdaterState = new MapUpdaterState(facesManager, null);
656 
657  mapUpdaterState.newMap(23, 16);
658  defineFace(faceCache, 1316, "demon_lord.x11", PNG128X256);
659 
660  synchronized (mapUpdaterState.mapBegin()) {
661  mapUpdaterState.mapFace(new Location(4, 17, 6), 1316, true);
662  mapUpdaterState.mapEnd(true);
663  }
664 
665  synchronized (mapUpdaterState.mapBegin()) {
666  mapUpdaterState.mapScroll(-1, 0);
667  mapUpdaterState.mapFace(new Location(5, 17, 6), 1316, true);
668  mapUpdaterState.mapEnd(true);
669  }
670 
671  synchronized (mapUpdaterState.mapBegin()) {
672  mapUpdaterState.mapClear(5, 17);
673  mapUpdaterState.mapFace(new Location(6, 17, 6), 1316, true);
674  mapUpdaterState.mapEnd(true);
675  }
676 
677  synchronized (mapUpdaterState.mapBegin()) {
678  mapUpdaterState.mapScroll(-1, 0);
679  mapUpdaterState.mapFace(new Location(7, 17, 6), 1316, true);
680  mapUpdaterState.mapEnd(true);
681  }
682 
683  synchronized (mapUpdaterState.mapBegin()) {
684  mapUpdaterState.mapScroll(-1, 0);
685  mapUpdaterState.mapFace(new Location(8, 17, 6), 1316, true);
686  mapUpdaterState.mapEnd(true);
687  }
688 
689  synchronized (mapUpdaterState.mapBegin()) {
690  mapUpdaterState.mapScroll(-1, 0);
691  mapUpdaterState.mapFace(new Location(9, 17, 6), 1316, true);
692  mapUpdaterState.mapEnd(true);
693  }
694  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));
695 
696  synchronized (mapUpdaterState.mapBegin()) {
697  mapUpdaterState.mapScroll(-1, 0);
698  mapUpdaterState.mapFace(new Location(11, 17, 6), 1316, true);
699  mapUpdaterState.mapEnd();
700  }
701  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));
702  }
703 
714  @NotNull
715  private static String toString(@NotNull final CfMap map, final int x0, final int y0, final int w, final int h) {
716  final StringBuilder sb = new StringBuilder();
717  //noinspection SynchronizationOnLocalVariableOrMethodParameter
718  synchronized (map) {
719  for (int y = y0; y < y0+h; y++) {
720  for (int x = x0; x < x0+w; x++) {
721  sb.append('[');
722 
723  boolean firstFace = true;
724 
725  if (map.isFogOfWar(x, y)) {
726  sb.append('#');
727  firstFace = false;
728  }
729 
730  for (int l = 0; l < Map2.NUM_LAYERS; l++) {
731  final Face face = map.getFace(x, y, l);
732  if (face != null) {
733  if (!firstFace) {
734  sb.append(',');
735  }
736  sb.append('H');
737  sb.append(l);
738  sb.append('=');
739  sb.append(face.getFaceName());
740  firstFace = false;
741  }
742 
743  final CfMapSquare headMapSquare = map.getHeadMapSquare(x, y, l);
744  if (headMapSquare != null) {
745  final Face headFace = headMapSquare.getFace(l);
746  if (!firstFace) {
747  sb.append(',');
748  }
749  sb.append('T');
750  sb.append(l);
751  sb.append('=');
752  sb.append(headFace == null ? "null" : headFace.getFaceName());
753  firstFace = false;
754  }
755  }
756  sb.append(']');
757  }
758  sb.append('\n');
759  }
760  }
761  return sb.toString();
762  }
763 
771  private static void defineFace(@NotNull final FaceCache faceCache, final int faceNum, @NotNull final String faceName, @NotNull final byte[] data) {
772  final Face face = new Face(faceNum, faceName, 0);
773  faceCache.addFace(face);
774 
775  final ImageIcon originalImageIcon;
776  try {
777  originalImageIcon = new ImageIcon(data);
778  } catch (final IllegalArgumentException ex) {
779  Assert.fail("Invalid .png data for face "+face+": "+ex.getMessage());
780  throw new AssertionError(ex);
781  }
782 
783  if (originalImageIcon.getIconWidth() <= 0 || originalImageIcon.getIconHeight() <= 0) {
784  Assert.fail("Invalid .png size for face "+face);
785  throw new AssertionError();
786  }
787 
788  final FaceImages faceImages = FaceImagesUtils.newFaceImages(originalImageIcon);
789  face.setFaceImages(faceImages);
790  }
791 
792 }
CfMapSquare getHeadMapSquare(final int layer)
Returns the map square of the head of a multi-square object.
static FaceImages newFaceImages(@NotNull final ImageIcon originalImageIcon)
Creates a new FaceImages instance from an "original" face; the "scaled" and "magic map" sized images ...
void mapClear(final int x, final int y)
Part of "map2" parsing: clear a cell.the x-coordinate the y-coordinate
Represents a square in a CfMap.
CfMap getMap()
Returns the current map instance.
Represents a map (as seen by the client).
Definition: CfMap.java:45
Utility class for creating FaceImages instances.
void testDisplayArtifacts3()
Checks that a regression causing display artifacts is fixed.
static String toString(@NotNull final CfMap map, final int x0, final int y0, final int w, final int h)
Returns a string representation of a rectangular area of a CfMap instance.
Object mapBegin()
Parsing of a "map2" command has been started.the synchronization object which must besynchronized wh...
Manages image information ("faces") needed to display the map view, items, and spell icons...
Consists of three ImageIcons representing a Face.
Definition: FaceImages.java:31
int NUM_LAYERS
The total number of map layers to display.
Definition: Map2.java:33
void testDisplayArtifacts1()
Checks that a regression causing display artifacts is fixed.
void testDisplayArtifacts2()
Checks that a regression causing display artifacts is fixed.
Interface defining constants for the "map2" Crossfire protocol message.
Definition: Map2.java:28
Update a CfMap model from protocol commands.
String getFaceName()
Returns the face name.
Definition: Face.java:124
static void defineFace(@NotNull final FaceCache faceCache, final int faceNum, @NotNull final String faceName, @NotNull final byte[] data)
Adds a new face to a FaceCache.
static final byte [] PNG64X64
A .png file of size 64x64.
Face getFace(final int layer)
Returns the face of a layer.
static final byte [] PNG128X256
A .png file of size 128x256.
void mapScroll(final int dx, final int dy)
Part of "map2" parsing: scroll the map view.the x-distance the y-distance
void setFaceImages(@NotNull final FaceImages faceImages)
Sets the images.
Definition: Face.java:92
void mapEnd()
Parsing of "map2" has been finished.
static final byte [] PNG32X32
A .png file of size 64x64.
void testFogOfWar1()
Checks that a cleared multi-tile face causes all affected tiles to become fog-of-war.
void tick(final int tickNo)
A "tick" command has been received.the current tick
void newMap(final int mapWidth, final int mapHeight)
A "newmap" command has been received.the map width the map height
void mapFace(@NotNull final Location location, final int faceNum)
Part of "map2" parsing: set the face of a cell.the location the face ID
Maintains a mapping of face numbers to face data.