22 package com.realtime.crossfire.jxclient.map;
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;
503 mapUpdaterState.
newMap(5, 5);
504 synchronized (mapUpdaterState.
mapBegin()) {
510 mapUpdaterState.
mapEnd(
true);
512 Assert.assertEquals(
""+
"[H0=_,T6=M][H0=_,T6=M]\n"+
"[H0=_,T6=M][H0=_,H6=M]\n",
toString(mapUpdaterState.
getMap(), 0, 0, 2, 2));
514 synchronized (mapUpdaterState.
mapBegin()) {
516 mapUpdaterState.
mapEnd(
true);
518 Assert.assertEquals(
""+
"[H0=_,T6=M][#,H0=_,T6=M]\n"+
"[H0=_,T6=M][H0=_,H6=M]\n",
toString(mapUpdaterState.
getMap(), 0, 0, 2, 2));
520 synchronized (mapUpdaterState.
mapBegin()) {
522 mapUpdaterState.
mapEnd(
true);
524 Assert.assertEquals(
""+
"[H0=_][#,H0=_,T6=M]\n"+
"[H0=_][#,H0=_,H6=M]\n",
toString(mapUpdaterState.
getMap(), 0, 0, 2, 2));
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);
545 mapUpdaterState.
newMap(10, 10);
546 synchronized (mapUpdaterState.
mapBegin()) {
554 mapUpdaterState.
mapEnd(
true);
557 mapUpdaterState.
tick(26);
558 synchronized (mapUpdaterState.
mapBegin()) {
560 mapUpdaterState.
mapEnd(
true);
563 mapUpdaterState.
tick(27);
564 mapUpdaterState.
tick(28);
565 synchronized (mapUpdaterState.
mapBegin()) {
567 mapUpdaterState.
mapEnd(
true);
570 mapUpdaterState.
tick(29);
571 synchronized (mapUpdaterState.
mapBegin()) {
573 mapUpdaterState.
mapEnd(
true);
576 mapUpdaterState.
tick(30);
577 synchronized (mapUpdaterState.
mapBegin()) {
579 mapUpdaterState.
mapEnd(
true);
582 mapUpdaterState.
tick(31);
583 mapUpdaterState.
tick(32);
584 synchronized (mapUpdaterState.
mapBegin()) {
586 mapUpdaterState.
mapEnd(
true);
589 mapUpdaterState.
tick(33);
590 mapUpdaterState.
tick(34);
591 synchronized (mapUpdaterState.
mapBegin()) {
594 mapUpdaterState.
mapEnd(
true);
597 mapUpdaterState.
tick(35);
598 mapUpdaterState.
tick(36);
599 synchronized (mapUpdaterState.
mapBegin()) {
603 mapUpdaterState.
mapEnd(
true);
606 mapUpdaterState.
tick(37);
607 mapUpdaterState.
tick(38);
608 synchronized (mapUpdaterState.
mapBegin()) {
611 mapUpdaterState.
mapEnd(
true);
614 mapUpdaterState.
tick(39);
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));
632 mapUpdaterState.
newMap(10, 10);
633 synchronized (mapUpdaterState.
mapBegin()) {
635 mapUpdaterState.
mapEnd(
true);
638 synchronized (mapUpdaterState.
mapBegin()) {
641 mapUpdaterState.
mapEnd(
true);
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));
657 mapUpdaterState.
newMap(23, 16);
658 defineFace(faceCache, 1316,
"demon_lord.x11", PNG128X256);
660 synchronized (mapUpdaterState.
mapBegin()) {
662 mapUpdaterState.
mapEnd(
true);
665 synchronized (mapUpdaterState.
mapBegin()) {
668 mapUpdaterState.
mapEnd(
true);
671 synchronized (mapUpdaterState.
mapBegin()) {
674 mapUpdaterState.
mapEnd(
true);
677 synchronized (mapUpdaterState.
mapBegin()) {
680 mapUpdaterState.
mapEnd(
true);
683 synchronized (mapUpdaterState.
mapBegin()) {
686 mapUpdaterState.
mapEnd(
true);
689 synchronized (mapUpdaterState.
mapBegin()) {
692 mapUpdaterState.
mapEnd(
true);
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));
696 synchronized (mapUpdaterState.
mapBegin()) {
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));
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();
719 for (
int y = y0; y < y0+h; y++) {
720 for (
int x = x0; x < x0+w; x++) {
723 boolean firstFace =
true;
725 if (map.isFogOfWar(x, y)) {
731 final Face face = map.getFace(x, y, l);
744 if (headMapSquare != null) {
752 sb.append(headFace == null ?
"null" : headFace.
getFaceName());
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);
775 final ImageIcon originalImageIcon;
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);
783 if (originalImageIcon.getIconWidth() <= 0 || originalImageIcon.getIconHeight() <= 0) {
784 Assert.fail(
"Invalid .png size for face "+face);
785 throw new AssertionError();
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).
A cache for Face instances.
Utility class for creating FaceImages instances.
Regression tests for MapUpdaterState.
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.
int NUM_LAYERS
The total number of map layers to display.
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.
Update a CfMap model from protocol commands.
String getFaceName()
Returns the face name.
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.
A FacesManager for regression tests.
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.
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.