Gridarta Editor
MapRendererTest.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.var.atrinik.gui.map.renderer;
21 
22 import java.awt.Point;
23 import java.util.Collections;
42 import org.jetbrains.annotations.NotNull;
43 import org.junit.Assert;
44 import org.junit.Test;
45 
52 public class MapRendererTest {
53 
57  @NotNull
59 
63  @Test
64  public void testPaintEmpty() {
65  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1);
66  final TestMapRenderer renderer = newRenderer(mapModel);
67  renderer.getFullImage();
68  Assert.assertEquals("", renderer.getPaintingOperations());
69  }
70 
74  @Test
75  public void testPaintNormal() {
76  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1);
77  mapModel.beginTransaction("TEST");
78  try {
79  mapModelCreator.addGameObjectToMap(mapModel, "arch", "name", 0, 0, mapModelCreator.getTopmostInsertionMode());
80  } finally {
81  mapModel.endTransaction();
82  }
83  final TestMapRenderer renderer = newRenderer(mapModel);
84  renderer.getFullImage();
85  Assert.assertEquals("1.00 0.00 0.00 1.00 0.00 0.00\n", renderer.getPaintingOperations());
86  }
87 
91  @Test
92  public void testPaintAlign1() {
93  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1);
94  mapModel.beginTransaction("TEST");
95  try {
96  final TestGameObject gameObject = mapModelCreator.newGameObject("arch", "name");
97  gameObject.setAttributeInt(DefaultIsoGameObject.ALIGN, 5);
98  mapModel.addGameObjectToMap(gameObject, new Point(0, 0), mapModelCreator.getTopmostInsertionMode());
99  } finally {
100  mapModel.endTransaction();
101  }
102  final TestMapRenderer renderer = newRenderer(mapModel);
103  renderer.getFullImage();
104  Assert.assertEquals("1.00 0.00 0.00 1.00 5.00 0.00\n", renderer.getPaintingOperations());
105  }
106 
110  @Test
111  public void testPaintAlign2() {
112  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1);
113  mapModel.beginTransaction("TEST");
114  try {
115  final TestGameObject gameObject = mapModelCreator.newGameObject("arch", "name");
116  gameObject.setAttributeInt(DefaultIsoGameObject.ALIGN, -5);
117  mapModel.addGameObjectToMap(gameObject, new Point(0, 0), mapModelCreator.getTopmostInsertionMode());
118  } finally {
119  mapModel.endTransaction();
120  }
121  final TestMapRenderer renderer = newRenderer(mapModel);
122  renderer.getFullImage();
123  Assert.assertEquals("1.00 0.00 0.00 1.00 -5.00 0.00\n", renderer.getPaintingOperations());
124  }
125 
129  @Test
130  public void testPaintZ1() {
131  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1);
132  mapModel.beginTransaction("TEST");
133  try {
134  final TestGameObject gameObject = mapModelCreator.newGameObject("arch", "name");
135  gameObject.setAttributeInt(DefaultIsoGameObject.LAYER, 3);
136  gameObject.setAttributeInt(DefaultIsoGameObject.Z, 5);
137  mapModel.addGameObjectToMap(gameObject, new Point(0, 0), mapModelCreator.getTopmostInsertionMode());
138  } finally {
139  mapModel.endTransaction();
140  }
141  final TestMapRenderer renderer = newRenderer(mapModel);
142  renderer.getFullImage();
143  Assert.assertEquals("1.00 0.00 0.00 1.00 0.00 -5.00\n", renderer.getPaintingOperations());
144  }
145 
149  @Test
150  public void testPaintZ2() {
151  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1);
152  mapModel.beginTransaction("TEST");
153  try {
154  final TestGameObject gameObject = mapModelCreator.newGameObject("arch", "name");
155  gameObject.setAttributeInt(DefaultIsoGameObject.LAYER, 3);
156  gameObject.setAttributeInt(DefaultIsoGameObject.Z, -5);
157  mapModel.addGameObjectToMap(gameObject, new Point(0, 0), mapModelCreator.getTopmostInsertionMode());
158  } finally {
159  mapModel.endTransaction();
160  }
161  final TestMapRenderer renderer = newRenderer(mapModel);
162  renderer.getFullImage();
163  Assert.assertEquals("1.00 0.00 0.00 1.00 0.00 5.00\n", renderer.getPaintingOperations());
164  }
165 
169  @Test
170  public void testPaintZoom1() {
171  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1);
172  mapModel.beginTransaction("TEST");
173  try {
174  final TestGameObject gameObject = mapModelCreator.newGameObject("arch", "name");
175  gameObject.setAttributeInt(DefaultIsoGameObject.ZOOM, 50);
176  mapModel.addGameObjectToMap(gameObject, new Point(0, 0), mapModelCreator.getTopmostInsertionMode());
177  } finally {
178  mapModel.endTransaction();
179  }
180  final TestMapRenderer renderer = newRenderer(mapModel);
181  renderer.getFullImage();
182  Assert.assertEquals("0.500 0.00 0.00 0.500 0.00 0.00\n", renderer.getPaintingOperations());
183  }
184 
188  @Test
189  public void testPaintZoom2() {
190  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1);
191  mapModel.beginTransaction("TEST");
192  try {
193  final TestGameObject gameObject = mapModelCreator.newGameObject("arch", "name");
194  gameObject.setAttributeInt(DefaultIsoGameObject.ZOOM, 100);
195  mapModel.addGameObjectToMap(gameObject, new Point(0, 0), mapModelCreator.getTopmostInsertionMode());
196  } finally {
197  mapModel.endTransaction();
198  }
199  final TestMapRenderer renderer = newRenderer(mapModel);
200  renderer.getFullImage();
201  Assert.assertEquals("1.00 0.00 0.00 1.00 0.00 0.00\n", renderer.getPaintingOperations());
202  }
203 
207  @Test
208  public void testPaintZoom3() {
209  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1);
210  mapModel.beginTransaction("TEST");
211  try {
212  final TestGameObject gameObject = mapModelCreator.newGameObject("arch", "name");
213  gameObject.setAttributeInt(DefaultIsoGameObject.ZOOM, 110);
214  mapModel.addGameObjectToMap(gameObject, new Point(0, 0), mapModelCreator.getTopmostInsertionMode());
215  } finally {
216  mapModel.endTransaction();
217  }
218  final TestMapRenderer renderer = newRenderer(mapModel);
219  renderer.getFullImage();
220  Assert.assertEquals("1.10 0.00 0.00 1.10 0.00 0.00\n", renderer.getPaintingOperations()); // XXX: why not shift y = -0.1?
221  }
222 
226  @Test
227  public void testPaintZoom4() {
228  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1);
229  mapModel.beginTransaction("TEST");
230  try {
231  final TestGameObject gameObject = mapModelCreator.newGameObject("arch", "name");
232  gameObject.setAttributeInt(DefaultIsoGameObject.ZOOM, 200);
233  mapModel.addGameObjectToMap(gameObject, new Point(0, 0), mapModelCreator.getTopmostInsertionMode());
234  } finally {
235  mapModel.endTransaction();
236  }
237  final TestMapRenderer renderer = newRenderer(mapModel);
238  renderer.getFullImage();
239  Assert.assertEquals("2.00 0.00 0.00 2.00 0.00 -1.00\n", renderer.getPaintingOperations());
240  }
241 
245  @Test
246  public void testPaintCombined1() {
247  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1);
248  mapModel.beginTransaction("TEST");
249  try {
250  final TestGameObject gameObject = mapModelCreator.newGameObject("arch", "name");
251  gameObject.setAttributeInt(DefaultIsoGameObject.LAYER, 3);
252  gameObject.setAttributeInt(DefaultIsoGameObject.ALIGN, 5);
253  gameObject.setAttributeInt(DefaultIsoGameObject.ROTATE, 20);
254  gameObject.setAttributeInt(DefaultIsoGameObject.Z, 15);
255  gameObject.setAttributeInt(DefaultIsoGameObject.ZOOM, 75);
256  mapModel.addGameObjectToMap(gameObject, new Point(0, 0), mapModelCreator.getTopmostInsertionMode());
257  } finally {
258  mapModel.endTransaction();
259  }
260  final TestMapRenderer renderer = newRenderer(mapModel);
261  renderer.getFullImage();
262  Assert.assertEquals("0.705 -0.257 0.257 0.705 5.00 -15.0\n", renderer.getPaintingOperations());
263  }
264 
270  @NotNull
272  final MapViewSettings mapViewSettings = mapModelCreator.getMapViewSettings();
273  final NamedFilter defaultNamedFilterList = new NamedFilter(Collections.emptyList());
274  final EditorSettings editorSettings = new DefaultEditorSettings();
275  final FilterControl<TestGameObject, TestMapArchObject, TestArchetype> filterControl = new DefaultFilterControl<>(defaultNamedFilterList, editorSettings);
276  final MapGrid mapGrid = new MapGrid(mapModel.getMapArchObject().getMapSize());
277  final IsoMapSquareInfo isoMapSquareInfo = new IsoMapSquareInfo(1, 1, 1, 1);
278  final MultiPositionData multiPositionData = new MultiPositionData(isoMapSquareInfo);
279  final ResourceIcons resourceIcons = mapModelCreator.getResourceIcons();
280  final GridMapSquarePainter gridMapSquarePainter = new GridMapSquarePainter(resourceIcons);
282  return new TestMapRenderer(mapViewSettings, filterControl, mapModel, mapGrid, multiPositionData, isoMapSquareInfo, gridMapSquarePainter, gameObjectParser, resourceIcons);
283  }
284 
285 }
A Filter that aggregates named filters.
MapModel< TestGameObject, TestMapArchObject, TestArchetype > newMapModel(final int w, final int h)
Creates a new MapModel instance.
A MapModel reflects the data of a map.
Definition: MapModel.java:75
Graphical User Interface of Gridarta.
Reading and writing of maps, handling of paths.
Helper class for regression tests to create MapModel instances.
String getPaintingOperations()
Returns and clears the accumulated painting operations.
void endTransaction()
End a transaction.
static final String ZOOM
The name of the "zoom" attribute.
static final String LAYER
The name of the "layer" attribute.
void testPaintNormal()
Checks rendering game objects without attributes that affect rendering.
void testPaintEmpty()
Checks rendering no game objects.
Interface for classes that read or write GameObject instances.
Default implementation of EditorSettings.
A MapArchObject implementation for testing purposes.
void testPaintZoom1()
Checks that DefaultIsoGameObject#ZOOM scales.
Base package of all Gridarta classes.
void addGameObjectToMap(@NotNull G gameObject, @NotNull Point pos, @NotNull InsertionMode< G, A, R > insertionMode)
Add a gameObject to the map.
void testPaintZ1()
Checks that DefaultIsoGameObject#Z shifts the y coordinate.
final TestMapModelCreator mapModelCreator
The TestMapModelCreator for creating MapModel instances.
TestGameObject newGameObject(@NotNull final String archetypeName, @NotNull final String objectName)
Creates a new game object.
Container for settings that affect the rendering of maps.
static final String Z
The name of the "z" attribute.
GameObjects are the objects based on Archetypes found on maps.
The MultiPositionData class stores an array of numbers which is required in order to calculate displa...
Regression tests that net.sf.gridarta.gui.map.renderer.IsoMapRenderer correctly interprets DefaultIso...
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
Definition: MapGrid.java:45
The filter package contains the classes for Filters.
Definition: BtnPopup.java:20
void testPaintCombined1()
Checks that a combination of attributes works as expected.
static final String ROTATE
The name of the "rotate" attribute.
void testPaintAlign1()
Checks that DefaultIsoGameObject#ALIGN shifts the x coordinate.
Base classes for rendering maps.
Provides information about isometric map squares.
GameObjectParser< TestGameObject, TestMapArchObject, TestArchetype > newGameObjectParser()
Creates a new GameObjectParser instance.
void testPaintZoom3()
Checks that DefaultIsoGameObject#ZOOM scales.
ResourceIcons getResourceIcons()
Returns the ResourceIcons instance.
Creates ImageIcon instances from resources.
void addGameObjectToMap(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final String archetypeName, @NotNull final String name, final int x, final int y, @NotNull final InsertionMode< TestGameObject, TestMapArchObject, TestArchetype > insertionMode)
Inserts a game object into a map.
MapViewSettings getMapViewSettings()
Returns the MapViewSettings instance.
An Archetype implementation for testing purposes.
void testPaintAlign2()
Checks that DefaultIsoGameObject#ALIGN shifts the x coordinate.
A GameObject implementation for testing purposes.
void testPaintZ2()
Checks that DefaultIsoGameObject#Z shifts the y coordinate.
InsertionMode< TestGameObject, TestMapArchObject, TestArchetype > getTopmostInsertionMode()
Returns the "topmost" insertion mode.
void beginTransaction(@NotNull String name)
Starts a new transaction.
Default implementation for GameObject implementing classes.
Settings that apply to the editor.
static final String ALIGN
The name of the "align" attribute.
TestMapRenderer newRenderer(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel)
Creates a new TestMapRenderer instance for a MapModel.
void testPaintZoom4()
Checks that DefaultIsoGameObject#ZOOM scales.
void testPaintZoom2()
Checks that DefaultIsoGameObject#ZOOM scales.