Gridarta Editor
PropagateElevationTest.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 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.crossfire.model.gameobject;
21 
22 import java.util.Iterator;
26 import org.jetbrains.annotations.NotNull;
27 import org.junit.Assert;
28 import org.junit.Test;
29 
35 public class PropagateElevationTest {
36 
41  @Test
42  public void testAddFirst() {
43  final GameObjectCreator gameObjectCreator = new GameObjectCreator();
44  final GameObjectContainer<GameObject, MapArchObject, Archetype> gameObjectContainer = gameObjectCreator.newGameObject(0);
45 
46  // first game object => keep
47  gameObjectContainer.addFirst(gameObjectCreator.newGameObject(123));
48  check(gameObjectContainer, 123);
49 
50  // without elevation => propagate
51  gameObjectContainer.addFirst(gameObjectCreator.newGameObject(0));
52  check(gameObjectContainer, 123);
53 
54  // with elevation => ignore but propagate
55  gameObjectContainer.addFirst(gameObjectCreator.newGameObject(321));
56  check(gameObjectContainer, 123);
57  }
58 
63  @Test
64  public void testAddLast() {
65  final GameObjectCreator gameObjectCreator = new GameObjectCreator();
66  final GameObjectContainer<GameObject, MapArchObject, Archetype> gameObjectContainer = gameObjectCreator.newGameObject(0);
67 
68  // first game object => keep
69  gameObjectContainer.addLast(gameObjectCreator.newGameObject(123));
70  check(gameObjectContainer, 123);
71 
72  // without elevation => keep
73  gameObjectContainer.addLast(gameObjectCreator.newGameObject(0));
74  check(gameObjectContainer, 123, 0);
75 
76  // with elevation => keep
77  gameObjectContainer.addLast(gameObjectCreator.newGameObject(321));
78  check(gameObjectContainer, 123, 0, 321);
79  }
80 
85  @Test
86  public void testInsertBefore() {
87  final GameObjectCreator gameObjectCreator = new GameObjectCreator();
88  final GameObjectContainer<GameObject, MapArchObject, Archetype> gameObjectContainer = gameObjectCreator.newGameObject(0);
89 
90  // first game object => keep
91  gameObjectContainer.insertBefore(gameObjectCreator.newGameObject(1), null);
92  check(gameObjectContainer, 1);
93 
94  // without elevation => propagate
95  gameObjectContainer.insertBefore(gameObjectCreator.newGameObject(0), null);
96  check(gameObjectContainer, 1, 0);
97 
98  // with elevation => ignore but propagate
99  final GameObject ob1 = gameObjectCreator.newGameObject(2);
100  gameObjectContainer.insertBefore(ob1, null);
101  check(gameObjectContainer, 1, 0, 0);
102 
103  // with elevation => keep
104  gameObjectContainer.insertBefore(gameObjectCreator.newGameObject(3), ob1);
105  check(gameObjectContainer, 1, 3, 0, 0);
106 
107  // with elevation => ignore but propagate
108  gameObjectContainer.insertBefore(gameObjectCreator.newGameObject(4), null);
109  check(gameObjectContainer, 1, 0, 3, 0, 0);
110  }
111 
116  @Test
117  public void testInsertAfter() {
118  final GameObjectCreator gameObjectCreator = new GameObjectCreator();
119  final GameObjectContainer<GameObject, MapArchObject, Archetype> gameObjectContainer = gameObjectCreator.newGameObject(0);
120 
121  // first game object => keep
122  gameObjectContainer.insertAfter(null, gameObjectCreator.newGameObject(1));
123  check(gameObjectContainer, 1);
124 
125  // at end => keep
126  final GameObject ob1 = gameObjectCreator.newGameObject(2);
127  gameObjectContainer.insertAfter(null, ob1);
128  check(gameObjectContainer, 1, 2);
129 
130  // at front, without elevation => propagate
131  gameObjectContainer.insertAfter(ob1, gameObjectCreator.newGameObject(0));
132  check(gameObjectContainer, 1, 0, 2);
133 
134  // middle => keep
135  gameObjectContainer.insertAfter(ob1, gameObjectCreator.newGameObject(3));
136  check(gameObjectContainer, 1, 0, 3, 2);
137 
138  // at front, with elevation => ignore but propagate
139  gameObjectContainer.insertAfter(gameObjectContainer.getFirst(), gameObjectCreator.newGameObject(4));
140  check(gameObjectContainer, 1, 0, 0, 3, 2);
141  }
142 
147  @Test
148  public void testMoveBottom() {
149  final GameObjectCreator gameObjectCreator = new GameObjectCreator();
150  final GameObjectContainer<GameObject, MapArchObject, Archetype> container1 = newContainer(gameObjectCreator, 1, 0, 0, 0);
151  container1.moveBottom(get(container1, 0));
152  check(container1, 1, 0, 0, 0);
153  container1.moveBottom(get(container1, 1));
154  check(container1, 1, 0, 0, 0);
155  container1.moveBottom(get(container1, 3));
156  check(container1, 1, 0, 0, 0);
157  }
158 
163  @Test
164  public void testMoveDown() {
165  final GameObjectCreator gameObjectCreator = new GameObjectCreator();
166  final GameObjectContainer<GameObject, MapArchObject, Archetype> container1 = newContainer(gameObjectCreator, 1, 0, 0, 0);
167  container1.moveDown(get(container1, 0));
168  check(container1, 1, 0, 0, 0);
169  container1.moveDown(get(container1, 1));
170  check(container1, 1, 0, 0, 0);
171  container1.moveDown(get(container1, 3));
172  check(container1, 1, 0, 0, 0);
173  }
174 
179  @Test
180  public void testMoveUp() {
181  final GameObjectCreator gameObjectCreator = new GameObjectCreator();
182  final GameObjectContainer<GameObject, MapArchObject, Archetype> container1 = newContainer(gameObjectCreator, 1, 0, 0, 0);
183  container1.moveUp(get(container1, 0));
184  check(container1, 1, 0, 0, 0);
185  container1.moveUp(get(container1, 1));
186  check(container1, 1, 0, 0, 0);
187  container1.moveUp(get(container1, 3));
188  check(container1, 1, 0, 0, 0);
189  }
190 
195  @Test
196  public void testMoveTop() {
197  final GameObjectCreator gameObjectCreator = new GameObjectCreator();
198  final GameObjectContainer<GameObject, MapArchObject, Archetype> container1 = newContainer(gameObjectCreator, 1, 0, 0, 0);
199  container1.moveTop(get(container1, 0));
200  check(container1, 1, 0, 0, 0);
201  container1.moveTop(get(container1, 1));
202  check(container1, 1, 0, 0, 0);
203  container1.moveTop(get(container1, 3));
204  check(container1, 1, 0, 0, 0);
205  }
206 
211  @Test
212  public void testRemove() {
213  final GameObjectCreator gameObjectCreator = new GameObjectCreator();
214  final GameObjectContainer<GameObject, MapArchObject, Archetype> container1 = newContainer(gameObjectCreator, 1, 0, 0, 0);
215  container1.remove(get(container1, 0));
216  check(container1, 1, 0, 0);
217  container1.remove(get(container1, 2));
218  check(container1, 1, 0);
219  container1.remove(get(container1, 0));
220  check(container1, 1);
221  container1.remove(get(container1, 0));
222  check(container1);
223  }
224 
229  @Test
230  public void testReplace() {
231  final GameObjectCreator gameObjectCreator = new GameObjectCreator();
232  final GameObjectContainer<GameObject, MapArchObject, Archetype> container1 = newContainer(gameObjectCreator, 1, 0, 0, 0);
233  container1.replace(get(container1, 0), gameObjectCreator.newGameObject(2));
234  check(container1, 1, 0, 0, 0);
235  container1.replace(get(container1, 1), gameObjectCreator.newGameObject(3));
236  check(container1, 1, 3, 0, 0);
237  container1.replace(get(container1, 0), gameObjectCreator.newGameObject(4));
238  check(container1, 1, 3, 0, 0);
239  }
240 
245  @Test
246  public void testIterator() {
247  final GameObjectCreator gameObjectCreator = new GameObjectCreator();
248  final GameObjectContainer<GameObject, MapArchObject, Archetype> container1 = newContainer(gameObjectCreator, 1, 0, 0, 0, 0, 0);
249  final Iterator<GameObject> it = container1.iterator();
250  it.next();
251  it.remove();
252  check(container1, 1, 0, 0, 0, 0);
253  it.next();
254  it.remove();
255  check(container1, 1, 0, 0, 0);
256  it.next();
257  it.next();
258  it.remove();
259  check(container1, 1, 0, 0);
260  }
261 
266  @Test
267  public void testReverse() {
268  final GameObjectCreator gameObjectCreator = new GameObjectCreator();
269  final GameObjectContainer<GameObject, MapArchObject, Archetype> container1 = newContainer(gameObjectCreator, 1, 0, 0, 0, 0, 0);
270  final Iterator<GameObject> it = container1.reverse().iterator();
271  it.next();
272  it.remove();
273  check(container1, 1, 0, 0, 0, 0);
274  it.next();
275  it.remove();
276  check(container1, 1, 0, 0, 0);
277  it.next();
278  it.next();
279  it.remove();
280  check(container1, 1, 0, 0);
281  it.next();
282  it.remove();
283  check(container1, 1, 0);
284  it.next();
285  it.remove();
286  check(container1, 1);
287  Assert.assertFalse(it.hasNext());
288  }
289 
297  @NotNull
298  private static GameObjectContainer<GameObject, MapArchObject, Archetype> newContainer(@NotNull final GameObjectCreator gameObjectCreator, final int... elevations) {
299  final GameObjectContainer<GameObject, MapArchObject, Archetype> gameObject = gameObjectCreator.newGameObject(0);
300  for (final int elevation : elevations) {
301  gameObject.addLast(gameObjectCreator.newGameObject(elevation));
302  }
303  return gameObject;
304  }
305 
312  @NotNull
313  private static GameObject get(@NotNull final Iterable<GameObject> gameObjects, final int index) {
314  int left = index;
315  for (final GameObject gameObject : gameObjects) {
316  if (left == 0) {
317  return gameObject;
318  }
319  left--;
320  }
321 
322  Assert.fail("index " + index + " not found");
323  throw new AssertionError();
324  }
325 
331  private static void check(@NotNull final Iterable<GameObject> gameObjects, final int... elevation) {
332  int i = 0;
333  for (final GameObject gameObject : gameObjects) {
334  final int thisElevation = gameObject.getAttributeInt(GameObject.ELEVATION);
335  final int expectedElevation = i < elevation.length ? elevation[i] : 0;
336  Assert.assertEquals(gameObject.getBestName(), expectedElevation, thisElevation);
337  i++;
338  }
339  }
340 
341 }
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.testAddFirst
void testAddFirst()
Checks that GameObjectContainer#addFirst(net.sf.gridarta.model.gameobject.GameObject) does work corre...
Definition: PropagateElevationTest.java:42
net.sf.gridarta.var.crossfire.model.archetype
Definition: Archetype.java:20
net.sf.gridarta
Base package of all Gridarta classes.
net.sf
net.sf.gridarta.var
net.sf.gridarta.model.baseobject.GameObjectContainer.getFirst
G getFirst()
Returns the first GameObject contained in this container.
Definition: GameObjectContainer.java:192
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.testMoveTop
void testMoveTop()
Checks that GameObjectContainer#moveTop(net.sf.gridarta.model.gameobject.GameObject) does work correc...
Definition: PropagateElevationTest.java:196
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.testMoveBottom
void testMoveBottom()
Checks that GameObjectContainer#moveBottom(net.sf.gridarta.model.gameobject.GameObject) does work cor...
Definition: PropagateElevationTest.java:148
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.check
static void check(@NotNull final Iterable< GameObject > gameObjects, final int... elevation)
Checks some game objects for expected elevation values.
Definition: PropagateElevationTest.java:331
net.sf.gridarta.model.baseobject.GameObjectContainer.moveBottom
void moveBottom(@NotNull final G gameObject)
Moves a game object to bottom.
Definition: GameObjectContainer.java:389
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.testMoveDown
void testMoveDown()
Checks that GameObjectContainer#moveDown(net.sf.gridarta.model.gameobject.GameObject) does work corre...
Definition: PropagateElevationTest.java:164
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.testMoveUp
void testMoveUp()
Checks that GameObjectContainer#moveUp(net.sf.gridarta.model.gameobject.GameObject) does work correct...
Definition: PropagateElevationTest.java:180
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.testIterator
void testIterator()
Checks that GameObjectContainer#iterator()'s {} does work correctly.
Definition: PropagateElevationTest.java:246
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.testReverse
void testReverse()
Checks that GameObjectContainer#reverse()'s {} does work correctly.
Definition: PropagateElevationTest.java:267
net
net.sf.gridarta.var.crossfire.model.archetype.Archetype
Implements Crossfire archetypes.
Definition: Archetype.java:30
net.sf.gridarta.var.crossfire.model.gameobject.GameObject.ELEVATION
static final String ELEVATION
The name of the "elevation" attribute.
Definition: GameObject.java:52
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest
Checks that GameObjectContainers correctly propagate elevation information when being modified.
Definition: PropagateElevationTest.java:35
net.sf.gridarta.var.crossfire.model.maparchobject.MapArchObject
MapArchObject contains the specific meta data about a map that is stored in the map-arch,...
Definition: MapArchObject.java:39
net.sf.gridarta.model.baseobject.GameObjectContainer.insertBefore
void insertBefore(@NotNull final G gameObject, @Nullable final G nextGameObject)
Adds a game object before another.
Definition: GameObjectContainer.java:507
net.sf.gridarta.model.baseobject.GameObjectContainer.addLast
void addLast(@NotNull final G gameObject)
Adds the given game object at the end of this container.
Definition: GameObjectContainer.java:413
net.sf.gridarta.model.baseobject.GameObjectContainer.remove
void remove(@NotNull final G gameObject)
Removes a game object from this container.
Definition: GameObjectContainer.java:250
net.sf.gridarta.model.baseobject.GameObjectContainer.iterator
Iterator< G > iterator()
The Iterator returned does not recurse, it only contains objects on the first level.
Definition: GameObjectContainer.java:106
net.sf.gridarta.var.crossfire
Main package of Gridarta4Crossfire, contains all classes specific to the Crossfire version of the Gri...
net.sf.gridarta.model.baseobject.GameObjectContainer.reverse
transient Iterable< G > reverse
Iterable implementation for reverse traversal.
Definition: GameObjectContainer.java:75
net.sf.gridarta.var.crossfire.model
net.sf.gridarta.model.baseobject.GameObjectContainer.moveTop
void moveTop(@NotNull final G gameObject)
Moves a game object to top.
Definition: GameObjectContainer.java:314
net.sf.gridarta.model.baseobject.GameObjectContainer.insertAfter
void insertAfter(@Nullable final G previousGameObject, @NotNull final G gameObject)
Adds a game object after another.
Definition: GameObjectContainer.java:461
net.sf.gridarta.model
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.var.crossfire.model.maparchobject
Definition: DefaultMapArchObjectFactory.java:20
net.sf.gridarta.var.crossfire.model.gameobject.GameObjectCreator
Creates GameObjects.
Definition: GameObjectCreator.java:36
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.testAddLast
void testAddLast()
Checks that GameObjectContainer#addLast(net.sf.gridarta.model.gameobject.GameObject) does work correc...
Definition: PropagateElevationTest.java:64
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.testInsertAfter
void testInsertAfter()
Checks that net.sf.gridarta.model.gameobject.GameObject) does work correctly.
Definition: PropagateElevationTest.java:117
net.sf.gridarta.model.baseobject.GameObjectContainer.addFirst
void addFirst(@NotNull final G gameObject)
Adds the given game object at the end of this container.
Definition: GameObjectContainer.java:435
net.sf.gridarta.var.crossfire.model.gameobject.GameObject
Handles the Crossfire GameObjects.
Definition: GameObject.java:41
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.testReplace
void testReplace()
Checks that net.sf.gridarta.model.gameobject.GameObject) does work correctly.
Definition: PropagateElevationTest.java:230
net.sf.gridarta.model.baseobject.GameObjectContainer.moveUp
void moveUp(@NotNull final G gameObject)
Moves a game object up.
Definition: GameObjectContainer.java:339
net.sf.gridarta.model.baseobject.GameObjectContainer
Base class for classes that contain GameObjects as children in the sense of containment.
Definition: GameObjectContainer.java:50
net.sf.gridarta.model.baseobject.GameObjectContainer.moveDown
void moveDown(@NotNull final G gameObject)
Moves a game object down.
Definition: GameObjectContainer.java:364
net.sf.gridarta.model.baseobject.GameObjectContainer.replace
void replace(@NotNull final G oldGameObject, @NotNull final G newGameObject)
Replaces a game object with another one.
Definition: GameObjectContainer.java:542
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.newContainer
static GameObjectContainer< GameObject, MapArchObject, Archetype > newContainer(@NotNull final GameObjectCreator gameObjectCreator, final int... elevations)
Creates a new GameObjectContainer that contains game objects with the given elevation values.
Definition: PropagateElevationTest.java:298
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.testInsertBefore
void testInsertBefore()
Checks that net.sf.gridarta.model.gameobject.GameObject) does work correctly.
Definition: PropagateElevationTest.java:86
net.sf.gridarta.var.crossfire.model.gameobject.GameObjectCreator.newGameObject
GameObject newGameObject(final int elevation)
Creates a new GameObject.
Definition: GameObjectCreator.java:73
net.sf.gridarta.var.crossfire.model.gameobject.PropagateElevationTest.testRemove
void testRemove()
Checks that GameObjectContainer#remove(net.sf.gridarta.model.gameobject.GameObject) does work correct...
Definition: PropagateElevationTest.java:212
it
This document describes some hints and requirements for general development on the CrossfireEditor If you plan to make changes to the editor code or setup please read the following and keep it in derived from a basic editor application called Gridder by Pasi Ker�nen so please communicate with best through the cf devel mailing before considering any fundamental changes About code DO NOT USE TABS No matter what Java development platform you are please configure insert indent Tabs are displayed totally different in every editor and there are millions of different editors out there The insertion of tabs in the source code is messing up the syntax formatting in a way that is UNREPAIRABLE Apart from please keep code indentation accurate This is not just good it helps to keep code readable and in that way dramatically decreases the chance for overlooked bugs Everyone is welcomed to correct indentation errors wherever they are spotted Before you start to do this please double check that your editor is really configured to insert spaces Line feeds may be checked in either in windows or in unix linux style All reasonable text and java editors can deal with both linefeed formats Converting line feeds is but in this case please make sure that only linefeed characters are changed and nothing else is affected Due to the platform independent nature of the editor has the potential to run on almost any given operating system the build process differs greatly between systems as well as java environments In the several people have attempted to add build scripts along with structural changes to optimize the setup on one particular system environment which has led to conflict Please do *not *attempt to change the structure or any directories for the mere purpose of improving a build process or performance in a java environment Build scripts may be placed in the root it would be especially fine if it is just one or two files but the latter is not required Please excuse me for placing such restriction I and many users of the editor greatly appreciate build scripts We just had some real troubles over this issue in the past and I don t want to have them repeated the editor has relatively high performance requirements I ve spent a lot of extra work to keep everything as fast and memory efficient as possible when you add new data fields or calculations in the archetype please make sure they are as efficient as possible and worth both the time and space they consume Now don t be afraid too much No development would be possible without adding calculations and data at all Just bear in mind unlike for many other open source performance does make a difference for the CrossfireEditor The for as many systems as possible In case you are unexperienced with java and note that the graphics look different on every and with every font They also have different sizes proportions and behave different A seemingly trivial and effectless change can wreck havoc for the same GUI run on another system please don t be totally afraid of it
Definition: Developer_README.txt:76