Gridarta Editor
AutoInsertionModeTest.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.model.mapmodel;
21 
22 import java.awt.Point;
23 import java.util.Iterator;
31 import org.jetbrains.annotations.NotNull;
32 import org.junit.Assert;
33 import org.junit.Before;
34 import org.junit.Test;
35 
40 public class AutoInsertionModeTest {
41 
45  private static final int TYPE_FLOOR = 1;
46 
50  private static final int TYPE_WALL = 2;
51 
55  private static final int TYPE_BELOW_FLOOR = 3;
56 
60  private static final int TYPE_SYSTEM = 4;
61 
65  @NotNull
67 
71  @NotNull
73 
78  @NotNull
80 
84  @NotNull
86 
90  @NotNull
92 
96  @NotNull
98 
103 
108  @Test
110  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1);
111  mapModel.beginTransaction("test");
112  try {
113  mapModelCreator.addGameObjectToMap(mapModel, "floor", "1", 0, 0, topmostInsertionMode);
114  mapModelCreator.addGameObjectToMap(mapModel, "wall", "2", 0, 0, topmostInsertionMode);
115  mapModelCreator.addGameObjectToMap(mapModel, "sys", "3", 0, 0, topmostInsertionMode);
116  mapModelCreator.addGameObjectToMap(mapModel, "wall", "4", 0, 0, autoInsertionMode);
117  } finally {
118  mapModel.endTransaction();
119  }
120  final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(new Point(0, 0));
121  final Iterator<TestGameObject> it = mapSquare.iterator();
122  Assert.assertTrue(it.hasNext());
123  Assert.assertEquals("1", it.next().getBestName());
124  Assert.assertTrue(it.hasNext());
125  Assert.assertEquals("4", it.next().getBestName());
126  Assert.assertTrue(it.hasNext());
127  Assert.assertEquals("3", it.next().getBestName());
128  Assert.assertFalse(it.hasNext());
129  }
130 
134  @Test
135  public void testInsertSystemObject2() {
136  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1);
137  mapModel.beginTransaction("test");
138  try {
139  mapModelCreator.addGameObjectToMap(mapModel, "floor", "1", 0, 0, topmostInsertionMode);
140  mapModelCreator.addGameObjectToMap(mapModel, "sys", "3", 0, 0, topmostInsertionMode);
141  mapModelCreator.addGameObjectToMap(mapModel, "wall", "4", 0, 0, autoInsertionMode);
142  } finally {
143  mapModel.endTransaction();
144  }
145  final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(new Point(0, 0));
146  final Iterator<TestGameObject> it = mapSquare.iterator();
147  Assert.assertTrue(it.hasNext());
148  Assert.assertEquals("1", it.next().getBestName());
149  Assert.assertTrue(it.hasNext());
150  Assert.assertEquals("4", it.next().getBestName());
151  Assert.assertTrue(it.hasNext());
152  Assert.assertEquals("3", it.next().getBestName());
153  Assert.assertFalse(it.hasNext());
154  }
155 
160  @Before
161  public void setUp() throws DuplicateArchetypeException {
162  mapModelCreator = new TestMapModelCreator(false);
163 
164  final TestArchetype floorArchetype = mapModelCreator.newArchetype("floor");
165  floorArchetype.setAttributeInt(BaseObject.TYPE, TYPE_FLOOR);
166  mapModelCreator.getArchetypeSet().addArchetype(floorArchetype);
167 
168  final TestArchetype wallArchetype = mapModelCreator.newArchetype("wall");
169  wallArchetype.setAttributeInt(BaseObject.TYPE, TYPE_WALL);
170  mapModelCreator.getArchetypeSet().addArchetype(wallArchetype);
171 
172  final TestArchetype sysArchetype = mapModelCreator.newArchetype("sys");
173  sysArchetype.setAttributeInt(BaseObject.TYPE, TYPE_SYSTEM);
174  mapModelCreator.getArchetypeSet().addArchetype(sysArchetype);
175  }
176 
177 }
final InsertionMode< TestGameObject, TestMapArchObject, TestArchetype > topmostInsertionMode
The topmost-insertion mode.
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
Interface for classes that match GameObjects.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
ArchetypeSet< TestGameObject, TestMapArchObject, TestArchetype > getArchetypeSet()
Returns the ArchetypeSet.
Helper class for regression tests to create MapModel instances.
void endTransaction()
End a transaction.
final GameObjectMatcher belowFloorGameObjectMatcher
A GameObjectMatcher that matches objects to be put below the floor.
void testInsertSystemObject2()
Checks that the auto-insertion mode works as expected.
final GameObjectMatcher systemGameObjectMatcher
A GameObjectMatcher that matches system objects.
A MapArchObject implementation for testing purposes.
String TYPE
The attribute name of the object&#39;s type.
Definition: BaseObject.java:66
Base package of all Gridarta classes.
static final int TYPE_SYSTEM
The archetype type for system objects.
TestMapModelCreator mapModelCreator
The TestMapModelCreator instance.
An Exception indicating that an Archetype name is not unique.
final GameObjectMatcher wallGameObjectMatcher
A GameObjectMatcher that matches wall objects.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
GameObjects are the objects based on Archetypes found on maps.
static final int TYPE_BELOW_FLOOR
The archetype type for objects to be put below the floor.
TestArchetype newArchetype(@NotNull final String archetypeName)
Creates a new TestArchetype instance but doesn&#39;t add it to the archetype set.
static final int TYPE_WALL
The archetype type for wall objects.
Iterator< G > iterator()
The Iterator returned does not recurse, it only contains objects on the first level.
final InsertionMode< TestGameObject, TestMapArchObject, TestArchetype > autoInsertionMode
The auto-insertion mode.
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.
An Archetype implementation for testing purposes.
An GameObjectMatcher matching certain archetype types.
A GameObject implementation for testing purposes.
Automatically guess the insertion position.
void beginTransaction(@NotNull String name)
Starts a new transaction.
static final int TYPE_FLOOR
The archetype type for floor objects.
void testInsertSystemObject1()
Checks that the auto-insertion mode works as expected.
final GameObjectMatcher floorGameObjectMatcher
A GameObjectMatcher that matches floor objects.