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-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.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 
107  @Test
108  public void testInsertSystemObject1() {
110  mapModel.beginTransaction("test");
111  try {
112  mapModelCreator.addGameObjectToMap(mapModel, "floor", "1", 0, 0, topmostInsertionMode);
113  mapModelCreator.addGameObjectToMap(mapModel, "wall", "2", 0, 0, topmostInsertionMode);
114  mapModelCreator.addGameObjectToMap(mapModel, "sys", "3", 0, 0, topmostInsertionMode);
115  mapModelCreator.addGameObjectToMap(mapModel, "wall", "4", 0, 0, autoInsertionMode);
116  } finally {
117  mapModel.endTransaction();
118  }
119  final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(new Point(0, 0));
120  final Iterator<TestGameObject> it = mapSquare.iterator();
121  Assert.assertTrue(it.hasNext());
122  Assert.assertEquals("1", it.next().getBestName());
123  Assert.assertTrue(it.hasNext());
124  Assert.assertEquals("4", it.next().getBestName());
125  Assert.assertTrue(it.hasNext());
126  Assert.assertEquals("3", it.next().getBestName());
127  Assert.assertFalse(it.hasNext());
128  }
129 
133  @Test
134  public void testInsertSystemObject2() {
136  mapModel.beginTransaction("test");
137  try {
138  mapModelCreator.addGameObjectToMap(mapModel, "floor", "1", 0, 0, topmostInsertionMode);
139  mapModelCreator.addGameObjectToMap(mapModel, "sys", "3", 0, 0, topmostInsertionMode);
140  mapModelCreator.addGameObjectToMap(mapModel, "wall", "4", 0, 0, autoInsertionMode);
141  } finally {
142  mapModel.endTransaction();
143  }
144  final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(new Point(0, 0));
145  final Iterator<TestGameObject> it = mapSquare.iterator();
146  Assert.assertTrue(it.hasNext());
147  Assert.assertEquals("1", it.next().getBestName());
148  Assert.assertTrue(it.hasNext());
149  Assert.assertEquals("4", it.next().getBestName());
150  Assert.assertTrue(it.hasNext());
151  Assert.assertEquals("3", it.next().getBestName());
152  Assert.assertFalse(it.hasNext());
153  }
154 
159  @Before
160  public void setUp() throws DuplicateArchetypeException {
162 
163  final TestArchetype floorArchetype = mapModelCreator.newArchetype("floor");
164  floorArchetype.setAttributeInt(BaseObject.TYPE, TYPE_FLOOR);
165  mapModelCreator.getArchetypeSet().addArchetype(floorArchetype);
166 
167  final TestArchetype wallArchetype = mapModelCreator.newArchetype("wall");
168  wallArchetype.setAttributeInt(BaseObject.TYPE, TYPE_WALL);
169  mapModelCreator.getArchetypeSet().addArchetype(wallArchetype);
170 
171  final TestArchetype sysArchetype = mapModelCreator.newArchetype("sys");
172  sysArchetype.setAttributeInt(BaseObject.TYPE, TYPE_SYSTEM);
173  mapModelCreator.getArchetypeSet().addArchetype(sysArchetype);
174  }
175 
176 }
net.sf.gridarta.model.archetype.TestArchetype
An Archetype implementation for testing purposes.
Definition: TestArchetype.java:30
net.sf.gridarta.model.mapmodel.TestMapModelCreator.newArchetype
TestArchetype newArchetype(@NotNull final String archetypeName)
Creates a new TestArchetype instance but doesn't add it to the archetype set.
Definition: TestMapModelCreator.java:285
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.mapmodel.MapSquare
A single Map Square.
Definition: MapSquare.java:45
net.sf.gridarta.model.mapmodel.MapModel.endTransaction
void endTransaction()
End a transaction.
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest.mapModelCreator
TestMapModelCreator mapModelCreator
The TestMapModelCreator instance.
Definition: AutoInsertionModeTest.java:102
net.sf.gridarta.model.gameobject.TestGameObject
A GameObject implementation for testing purposes.
Definition: TestGameObject.java:34
net.sf
net.sf.gridarta.model.mapmodel.MapModel.beginTransaction
void beginTransaction(@NotNull String name)
Starts a new transaction.
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest.testInsertSystemObject1
void testInsertSystemObject1()
Checks that the auto-insertion mode works as expected.
Definition: AutoInsertionModeTest.java:108
net.sf.gridarta.model.mapmodel.TestMapModelCreator
Helper class for regression tests to create MapModel instances.
Definition: TestMapModelCreator.java:63
net.sf.gridarta.model.match.GameObjectMatcher
Interface for classes that match GameObjects.
Definition: GameObjectMatcher.java:30
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest.belowFloorGameObjectMatcher
final GameObjectMatcher belowFloorGameObjectMatcher
A GameObjectMatcher that matches objects to be put below the floor.
Definition: AutoInsertionModeTest.java:79
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest.topmostInsertionMode
final InsertionMode topmostInsertionMode
The topmost-insertion mode.
Definition: AutoInsertionModeTest.java:97
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest.systemGameObjectMatcher
final GameObjectMatcher systemGameObjectMatcher
A GameObjectMatcher that matches system objects.
Definition: AutoInsertionModeTest.java:85
net.sf.gridarta.model.mapmodel.TestMapModelCreator.newMapModel
MapModel< TestGameObject, TestMapArchObject, TestArchetype > newMapModel(final int w, final int h)
Creates a new MapModel instance.
Definition: TestMapModelCreator.java:168
net.sf.gridarta.model.match.TypeNrsGameObjectMatcher
An GameObjectMatcher matching certain archetype types.
Definition: TypeNrsGameObjectMatcher.java:30
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.model.mapmodel.AutoInsertionModeTest.testInsertSystemObject2
void testInsertSystemObject2()
Checks that the auto-insertion mode works as expected.
Definition: AutoInsertionModeTest.java:134
net.sf.gridarta.model.match
Classes related to matching {GameObjects}, so called { net.sf.gridarta.model.match....
Definition: AndGameObjectMatcher.java:20
net.sf.gridarta.model.mapmodel.TestMapModelCreator.getArchetypeSet
ArchetypeSet< TestGameObject, TestMapArchObject, TestArchetype > getArchetypeSet()
Returns the ArchetypeSet.
Definition: TestMapModelCreator.java:349
net.sf.gridarta.model.mapmodel.AutoInsertionMode
Automatically guess the insertion position.
Definition: AutoInsertionMode.java:35
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest.setUp
void setUp()
Initializes the tests.
Definition: AutoInsertionModeTest.java:160
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest.TYPE_SYSTEM
static final int TYPE_SYSTEM
The archetype type for system objects.
Definition: AutoInsertionModeTest.java:60
net.sf.gridarta.model.mapmodel.InsertionMode
Insertion modes.
Definition: InsertionMode.java:33
net.sf.gridarta.model.baseobject.BaseObject
Definition: BaseObject.java:34
net.sf.gridarta.model.mapmodel.MapModel.getMapSquare
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest.TYPE_BELOW_FLOOR
static final int TYPE_BELOW_FLOOR
The archetype type for objects to be put below the floor.
Definition: AutoInsertionModeTest.java:55
net.sf.gridarta.model
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest.wallGameObjectMatcher
final GameObjectMatcher wallGameObjectMatcher
A GameObjectMatcher that matches wall objects.
Definition: AutoInsertionModeTest.java:72
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest
Regression tests for AutoInsertionMode.
Definition: AutoInsertionModeTest.java:40
net.sf.gridarta.model.mapmodel.TestMapModelCreator.addGameObjectToMap
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 insertionMode)
Inserts a game object into a map.
Definition: TestMapModelCreator.java:209
net.sf.gridarta.model.archetype.DuplicateArchetypeException
An Exception indicating that an Archetype name is not unique.
Definition: DuplicateArchetypeException.java:29
net.sf.gridarta.model.maparchobject.TestMapArchObject
A MapArchObject implementation for testing purposes.
Definition: TestMapArchObject.java:28
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest.floorGameObjectMatcher
final GameObjectMatcher floorGameObjectMatcher
A GameObjectMatcher that matches floor objects.
Definition: AutoInsertionModeTest.java:66
net.sf.gridarta.model.baseobject.BaseObject.TYPE
String TYPE
The attribute name of the object's type.
Definition: BaseObject.java:66
net.sf.gridarta.model.mapmodel.TopmostInsertionMode
Insert topmost.
Definition: TopmostInsertionMode.java:31
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest.TYPE_WALL
static final int TYPE_WALL
The archetype type for wall objects.
Definition: AutoInsertionModeTest.java:50
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest.TYPE_FLOOR
static final int TYPE_FLOOR
The archetype type for floor objects.
Definition: AutoInsertionModeTest.java:45
net.sf.gridarta.model.mapmodel.AutoInsertionModeTest.autoInsertionMode
final InsertionMode autoInsertionMode
The auto-insertion mode.
Definition: AutoInsertionModeTest.java:91
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