Crossfire JXClient, Trunk
|
Go to the documentation of this file.
23 package com.realtime.crossfire.jxclient.map;
34 import javax.swing.ImageIcon;
35 import org.jetbrains.annotations.NotNull;
36 import org.junit.Assert;
37 import org.junit.Test;
48 private static final byte @NotNull []
PNG32X32 = {
49 (byte)0x89, (
byte)0x50, (byte)0x4e, (
byte)0x47, (byte)0x0d, (
byte)0x0a, (byte)0x1a, (
byte)0x0a,
50 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x0d, (byte)0x49, (
byte)0x48, (byte)0x44, (
byte)0x52,
51 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x20, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x20,
52 (byte)0x08, (
byte)0x06, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x73, (byte)0x7a, (
byte)0x7a,
53 (byte)0xf4, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x01, (
byte)0x73, (byte)0x52, (
byte)0x47,
54 (byte)0x42, (
byte)0x00, (byte)0xae, (
byte)0xce, (byte)0x1c, (
byte)0xe9, (byte)0x00, (
byte)0x00,
55 (byte)0x00, (
byte)0x1a, (byte)0x49, (
byte)0x44, (byte)0x41, (
byte)0x54, (byte)0x58, (
byte)0xc3,
56 (byte)0xed, (
byte)0xc1, (byte)0x01, (
byte)0x01, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x82,
57 (byte)0x20, (
byte)0xff, (byte)0xaf, (
byte)0x6e, (byte)0x48, (
byte)0x40, (byte)0x01, (
byte)0x00,
58 (byte)0x00, (
byte)0x00, (byte)0xef, (
byte)0x06, (byte)0x10, (
byte)0x20, (byte)0x00, (
byte)0x01,
59 (byte)0x97, (
byte)0xf7, (byte)0x57, (
byte)0xd7, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
60 (byte)0x49, (
byte)0x45, (byte)0x4e, (
byte)0x44, (byte)0xae, (
byte)0x42, (byte)0x60, (
byte)0x82,
66 private static final byte @NotNull []
PNG64X64 = {
67 (byte)0x89, (
byte)0x50, (byte)0x4e, (
byte)0x47, (byte)0x0d, (
byte)0x0a, (byte)0x1a, (
byte)0x0a,
68 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x0d, (byte)0x49, (
byte)0x48, (byte)0x44, (
byte)0x52,
69 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x40, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x40,
70 (byte)0x08, (
byte)0x06, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0xaa, (byte)0x69, (
byte)0x71,
71 (byte)0xde, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x01, (
byte)0x73, (byte)0x52, (
byte)0x47,
72 (byte)0x42, (
byte)0x00, (byte)0xae, (
byte)0xce, (byte)0x1c, (
byte)0xe9, (byte)0x00, (
byte)0x00,
73 (byte)0x00, (
byte)0x27, (byte)0x49, (
byte)0x44, (byte)0x41, (
byte)0x54, (byte)0x78, (
byte)0xda,
74 (byte)0xed, (
byte)0xc1, (byte)0x01, (
byte)0x0d, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0xc2,
75 (byte)0xa0, (
byte)0xf7, (byte)0x4f, (
byte)0x6d, (byte)0x0e, (
byte)0x37, (byte)0xa0, (
byte)0x00,
76 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
77 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x80, (
byte)0x77,
78 (byte)0x03, (
byte)0x40, (byte)0x40, (
byte)0x00, (byte)0x01, (
byte)0xaf, (byte)0x7a, (
byte)0x0e,
79 (byte)0xe8, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x49, (byte)0x45, (
byte)0x4e,
80 (byte)0x44, (
byte)0xae, (byte)0x42, (
byte)0x60, (byte)0x82,
87 (byte)0x89, (
byte)0x50, (byte)0x4e, (
byte)0x47, (byte)0x0d, (
byte)0x0a, (byte)0x1a, (
byte)0x0a,
88 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x0d, (byte)0x49, (
byte)0x48, (byte)0x44, (
byte)0x52,
89 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x80, (byte)0x00, (
byte)0x00, (byte)0x01, (
byte)0x00,
90 (byte)0x08, (
byte)0x06, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x7b, (byte)0xf9, (
byte)0x7e,
91 (byte)0xa7, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x01, (
byte)0x73, (byte)0x52, (
byte)0x47,
92 (byte)0x42, (
byte)0x00, (byte)0xae, (
byte)0xce, (byte)0x1c, (
byte)0xe9, (byte)0x00, (
byte)0x00,
93 (byte)0x00, (
byte)0x95, (byte)0x49, (
byte)0x44, (byte)0x41, (
byte)0x54, (byte)0x78, (
byte)0xda,
94 (byte)0xed, (
byte)0xc1, (byte)0x01, (
byte)0x01, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x80,
95 (byte)0x90, (
byte)0xfe, (byte)0xaf, (
byte)0xee, (byte)0x08, (
byte)0x0a, (byte)0x00, (
byte)0x00,
96 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
97 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
98 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
99 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
100 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
101 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
102 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
103 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
104 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
105 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
106 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
107 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
108 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
109 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
110 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00,
111 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x00, (byte)0x80, (
byte)0xaa, (byte)0x01, (
byte)0x01,
112 (byte)0x1e, (
byte)0x00, (byte)0x01, (
byte)0xbc, (byte)0x1b, (
byte)0xb9, (byte)0x6f, (
byte)0x00,
113 (byte)0x00, (
byte)0x00, (byte)0x00, (
byte)0x49, (byte)0x45, (
byte)0x4e, (byte)0x44, (
byte)0xae,
114 (byte)0x42, (
byte)0x60, (byte)0x82,
130 mapUpdaterState.
newMap(5, 5);
131 synchronized (mapUpdaterState.
mapBegin()) {
137 mapUpdaterState.
mapEnd(
true);
139 Assert.assertEquals(
""+
"[H0=_,T6=M][H0=_,T6=M]\n"+
"[H0=_,T6=M][H0=_,H6=M]\n",
toString(mapUpdaterState.
getMap(), 0, 0, 2, 2));
141 synchronized (mapUpdaterState.
mapBegin()) {
143 mapUpdaterState.
mapEnd(
true);
145 Assert.assertEquals(
""+
"[H0=_,T6=M][#,H0=_,T6=M]\n"+
"[H0=_,T6=M][H0=_,H6=M]\n",
toString(mapUpdaterState.
getMap(), 0, 0, 2, 2));
147 synchronized (mapUpdaterState.
mapBegin()) {
149 mapUpdaterState.
mapEnd(
true);
151 Assert.assertEquals(
""+
"[H0=_][#,H0=_,T6=M]\n"+
"[H0=_][#,H0=_,H6=M]\n",
toString(mapUpdaterState.
getMap(), 0, 0, 2, 2));
171 mapUpdaterState.
newMap(10, 10);
172 synchronized (mapUpdaterState.
mapBegin()) {
180 mapUpdaterState.
mapEnd(
true);
183 mapUpdaterState.
tick(26);
184 synchronized (mapUpdaterState.
mapBegin()) {
186 mapUpdaterState.
mapEnd(
true);
189 mapUpdaterState.
tick(27);
190 mapUpdaterState.
tick(28);
191 synchronized (mapUpdaterState.
mapBegin()) {
193 mapUpdaterState.
mapEnd(
true);
196 mapUpdaterState.
tick(29);
197 synchronized (mapUpdaterState.
mapBegin()) {
199 mapUpdaterState.
mapEnd(
true);
202 mapUpdaterState.
tick(30);
203 synchronized (mapUpdaterState.
mapBegin()) {
205 mapUpdaterState.
mapEnd(
true);
208 mapUpdaterState.
tick(31);
209 mapUpdaterState.
tick(32);
210 synchronized (mapUpdaterState.
mapBegin()) {
212 mapUpdaterState.
mapEnd(
true);
215 mapUpdaterState.
tick(33);
216 mapUpdaterState.
tick(34);
217 synchronized (mapUpdaterState.
mapBegin()) {
220 mapUpdaterState.
mapEnd(
true);
223 mapUpdaterState.
tick(35);
224 mapUpdaterState.
tick(36);
225 synchronized (mapUpdaterState.
mapBegin()) {
229 mapUpdaterState.
mapEnd(
true);
232 mapUpdaterState.
tick(37);
233 mapUpdaterState.
tick(38);
234 synchronized (mapUpdaterState.
mapBegin()) {
237 mapUpdaterState.
mapEnd(
true);
240 mapUpdaterState.
tick(39);
242 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));
257 mapUpdaterState.
newMap(10, 10);
258 synchronized (mapUpdaterState.
mapBegin()) {
260 mapUpdaterState.
mapEnd(
true);
263 synchronized (mapUpdaterState.
mapBegin()) {
266 mapUpdaterState.
mapEnd(
true);
269 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));
281 mapUpdaterState.
newMap(23, 16);
284 synchronized (mapUpdaterState.
mapBegin()) {
286 mapUpdaterState.
mapEnd(
true);
289 synchronized (mapUpdaterState.
mapBegin()) {
292 mapUpdaterState.
mapEnd(
true);
295 synchronized (mapUpdaterState.
mapBegin()) {
298 mapUpdaterState.
mapEnd(
true);
301 synchronized (mapUpdaterState.
mapBegin()) {
304 mapUpdaterState.
mapEnd(
true);
307 synchronized (mapUpdaterState.
mapBegin()) {
310 mapUpdaterState.
mapEnd(
true);
313 synchronized (mapUpdaterState.
mapBegin()) {
316 mapUpdaterState.
mapEnd(
true);
318 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));
320 synchronized (mapUpdaterState.
mapBegin()) {
325 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));
339 private static String
toString(@NotNull
final CfMap map,
final int x0,
final int y0,
final int w,
final int h) {
340 final StringBuilder sb =
new StringBuilder();
343 for (
int y = y0; y < y0+h; y++) {
344 for (
int x = x0; x < x0+w; x++) {
347 boolean firstFace =
true;
349 if (map.isFogOfWar(x, y)) {
355 final Face face = map.getFace(x, y, l);
368 if (headMapSquare !=
null) {
376 sb.append(headFace ==
null ?
"null" : headFace.
getFaceName());
395 private static void defineFace(@NotNull
final FaceCache faceCache,
final int faceNum, @NotNull
final String faceName,
final byte @NotNull [] data) {
396 final Face face =
new Face(faceNum, faceName, 0);
397 faceCache.addFace(face);
399 final ImageIcon originalImageIcon;
401 originalImageIcon =
new ImageIcon(data);
402 }
catch (
final IllegalArgumentException ex) {
403 Assert.fail(
"Invalid .png data for face "+face+
": "+ex.getMessage());
404 throw new AssertionError(ex);
407 if (originalImageIcon.getIconWidth() <= 0 || originalImageIcon.getIconHeight() <= 0) {
408 Assert.fail(
"Invalid .png size for face "+face);
409 throw new AssertionError();
static FaceImages newFaceImages(@NotNull final ImageIcon originalImageIcon)
void newMap(final int mapWidth, final int mapHeight)
void mapScroll(final int dx, final int dy)
void testDisplayArtifacts2()
void testDisplayArtifacts3()
static void defineFace(@NotNull final FaceCache faceCache, final int faceNum, @NotNull final String faceName, final byte @NotNull[] data)
static final byte[] PNG32X32
static String toString(@NotNull final CfMap map, final int x0, final int y0, final int w, final int h)
void tick(final int tickNo)
void testDisplayArtifacts1()
Face getFace(final int layer)
void setFaceImages(@NotNull final FaceImages faceImages)
CfMapSquare getHeadMapSquare(final int layer)
void mapFace(@NotNull final Location location, final int faceNum)
static final byte[] PNG128X256
void mapClear(final int x, final int y)
static final byte[] PNG64X64