 |
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(
"""
140 [H0=_,T6=M][H0=_,T6=M]
141 [H0=_,T6=M][H0=_,H6=M]
144 synchronized (mapUpdaterState.
mapBegin()) {
146 mapUpdaterState.
mapEnd(
true);
148 Assert.assertEquals(
"""
149 [H0=_,T6=M][#,H0=_,T6=M]
150 [H0=_,T6=M][H0=_,H6=M]
153 synchronized (mapUpdaterState.
mapBegin()) {
155 mapUpdaterState.
mapEnd(
true);
157 Assert.assertEquals(
"""
180 mapUpdaterState.
newMap(10, 10);
181 synchronized (mapUpdaterState.
mapBegin()) {
189 mapUpdaterState.
mapEnd(
true);
192 mapUpdaterState.
tick(26);
193 synchronized (mapUpdaterState.
mapBegin()) {
195 mapUpdaterState.
mapEnd(
true);
198 mapUpdaterState.
tick(27);
199 mapUpdaterState.
tick(28);
200 synchronized (mapUpdaterState.
mapBegin()) {
202 mapUpdaterState.
mapEnd(
true);
205 mapUpdaterState.
tick(29);
206 synchronized (mapUpdaterState.
mapBegin()) {
208 mapUpdaterState.
mapEnd(
true);
211 mapUpdaterState.
tick(30);
212 synchronized (mapUpdaterState.
mapBegin()) {
214 mapUpdaterState.
mapEnd(
true);
217 mapUpdaterState.
tick(31);
218 mapUpdaterState.
tick(32);
219 synchronized (mapUpdaterState.
mapBegin()) {
221 mapUpdaterState.
mapEnd(
true);
224 mapUpdaterState.
tick(33);
225 mapUpdaterState.
tick(34);
226 synchronized (mapUpdaterState.
mapBegin()) {
229 mapUpdaterState.
mapEnd(
true);
232 mapUpdaterState.
tick(35);
233 mapUpdaterState.
tick(36);
234 synchronized (mapUpdaterState.
mapBegin()) {
238 mapUpdaterState.
mapEnd(
true);
241 mapUpdaterState.
tick(37);
242 mapUpdaterState.
tick(38);
243 synchronized (mapUpdaterState.
mapBegin()) {
246 mapUpdaterState.
mapEnd(
true);
249 mapUpdaterState.
tick(39);
251 Assert.assertEquals(
"""
252 [H0=woodfloor.111,T6=behemoth.x71][H0=woodfloor.111,T6=behemoth.x71][H0=woodfloor.111][]
253 [H0=woodfloor.111,T6=behemoth.x71][H0=woodfloor.111,H6=behemoth.x71][H0=woodfloor.111][#,H6=behemoth.x31]
269 mapUpdaterState.
newMap(10, 10);
270 synchronized (mapUpdaterState.
mapBegin()) {
272 mapUpdaterState.
mapEnd(
true);
275 synchronized (mapUpdaterState.
mapBegin()) {
278 mapUpdaterState.
mapEnd(
true);
281 Assert.assertEquals(
"""
282 [T6=b.x12][T6=b.x12][]
283 [T6=b.x12][H6=b.x12][#,H6=a.x11]
296 mapUpdaterState.
newMap(23, 16);
299 synchronized (mapUpdaterState.
mapBegin()) {
301 mapUpdaterState.
mapEnd(
true);
304 synchronized (mapUpdaterState.
mapBegin()) {
307 mapUpdaterState.
mapEnd(
true);
310 synchronized (mapUpdaterState.
mapBegin()) {
313 mapUpdaterState.
mapEnd(
true);
316 synchronized (mapUpdaterState.
mapBegin()) {
319 mapUpdaterState.
mapEnd(
true);
322 synchronized (mapUpdaterState.
mapBegin()) {
325 mapUpdaterState.
mapEnd(
true);
328 synchronized (mapUpdaterState.
mapBegin()) {
331 mapUpdaterState.
mapEnd(
true);
333 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));
335 synchronized (mapUpdaterState.
mapBegin()) {
340 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));
354 private static String
toString(@NotNull
final CfMap map,
final int x0,
final int y0,
final int w,
final int h) {
355 final StringBuilder sb =
new StringBuilder();
358 for (
int y = y0; y < y0+h; y++) {
359 for (
int x = x0; x < x0+w; x++) {
362 boolean firstFace =
true;
364 if (map.isFogOfWar(x, y)) {
370 final Face face = map.getFace(x, y, l);
383 if (headMapSquare !=
null) {
391 sb.append(headFace ==
null ?
"null" : headFace.
getFaceName());
410 private static void defineFace(@NotNull
final FaceCache faceCache,
final int faceNum, @NotNull
final String faceName,
final byte @NotNull [] data) {
411 final Face face =
new Face(faceNum, faceName, 0);
412 faceCache.addFace(face);
414 final ImageIcon originalImageIcon;
416 originalImageIcon =
new ImageIcon(data);
417 }
catch (
final IllegalArgumentException ex) {
418 Assert.fail(
"Invalid .png data for face "+face+
": "+ex.getMessage());
419 throw new AssertionError(ex);
422 if (originalImageIcon.getIconWidth() <= 0 || originalImageIcon.getIconHeight() <= 0) {
423 Assert.fail(
"Invalid .png size for face "+face);
424 throw new AssertionError();
static final byte[] PNG32X32
A .png file of size 64x64.
Maintains a mapping of face numbers to face data.
void mapScroll(final int dx, final int dy)
Part of "map2" parsing: scroll the map view.
Regression tests for MapUpdaterState.
Model class maintaining the CfItems known to the player.
void mapFace(@NotNull final Location location, final int faceNum)
Part of "map2" parsing: set the face of a cell.
A cache for Face instances.
void tick(final int tickNo)
A "tick" command has been received.
Manages animations received from the server.
Utility class for creating FaceImages instances.
Represents a map (as seen by the client).
CfMapSquare getHeadMapSquare(final int layer)
Returns the map square of the head of a multi-square object.
void newMap(final int mapWidth, final int mapHeight)
A "newmap" command has been received.
Manages image information ("faces") needed to display the map view, items, and spell icons.
void testDisplayArtifacts1()
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.
void testDisplayArtifacts3()
Checks that a regression causing display artifacts is fixed.
CfMap getMap()
Returns the current map instance.
A FacesManager for regression tests.
Object mapBegin()
Parsing of a "map2" command has been started.
void testDisplayArtifacts2()
Checks that a regression causing display artifacts is fixed.
static FaceImages newFaceImages(@NotNull final ImageIcon originalImageIcon)
Creates a new FaceImages instance from an "original" face; the "scaled" and "magic map" sized images ...
Interface defining constants for the "map2" Crossfire protocol message.
Face getFace(final int layer)
Returns the face of a layer.
Manages a set of animated faces.
static final byte[] PNG128X256
A .png file of size 128x256.
Consists of three ImageIcons representing a Face.
String getFaceName()
Returns the face name.
void testFogOfWar1()
Checks that a cleared multi-tile face causes all affected tiles to become fog-of-war.
void mapEnd()
Parsing of "map2" has been finished.
static final byte[] PNG64X64
A .png file of size 64x64.
int NUM_LAYERS
The total number of map layers to display.
Represents a square in a CfMap.
Update a CfMap model from protocol commands.
void setFaceImages(@NotNull final FaceImages faceImages)
Sets the images.
void mapClear(final int x, final int y)
Part of "map2" parsing: clear a cell.
static void defineFace(@NotNull final FaceCache faceCache, final int faceNum, @NotNull final String faceName, final byte @NotNull[] data)
Adds a new face to a FaceCache.