20 package net.sf.gridarta.model.mapmodel;
22 import java.awt.Point;
23 import java.util.Collection;
24 import java.util.List;
26 import java.util.TreeSet;
38 import org.jetbrains.annotations.NotNull;
39 import org.jetbrains.annotations.Nullable;
40 import org.junit.Assert;
41 import org.junit.Test;
47 @SuppressWarnings(
"FeatureEnvy")
59 public void mapSizeChanged(@NotNull
final Size2D newSize) {
60 log(
"mapSizeChanged", null, null);
65 log(
"mapSquaresChanged", mapSquares, null);
69 public void mapObjectsChanged(@NotNull
final Set<TestGameObject> gameObjects, @NotNull
final Set<TestGameObject> transientGameObjects) {
70 if (!gameObjects.isEmpty()) {
71 log(
"mapObjectsChanged", null, gameObjects);
73 if (!transientGameObjects.isEmpty()) {
74 log(
"mapObjectsTransientChanged", null, transientGameObjects);
80 result.append(
"errorsChanged");
84 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
89 public void modifiedChanged() {
103 public void mapMetaChanged() {
104 result.append(
"mapMetaChanged");
108 public void mapSizeChanged(@NotNull
final Size2D mapSize) {
118 private final StringBuilder result =
new StringBuilder();
130 Assert.assertEquals(
"", result.toString());
144 final StringBuilder expectedResult =
new StringBuilder();
145 expectedResult.append(
"mapSizeChanged:\n");
146 expectedResult.append(
"no squares\n");
147 expectedResult.append(
"no game objects\n");
148 Assert.assertEquals(expectedResult.toString(), result.toString());
167 Assert.assertEquals(
"", result.toString());
188 final StringBuilder expectedResult =
new StringBuilder();
189 expectedResult.append(
"mapSizeChanged:\n");
190 expectedResult.append(
"no squares\n");
191 expectedResult.append(
"no game objects\n");
192 Assert.assertEquals(expectedResult.toString(), result.toString());
211 gameObject.setAttributeString(
"key",
"value");
216 final StringBuilder expectedResult =
new StringBuilder();
217 expectedResult.append(
"mapSizeChanged:\n");
218 expectedResult.append(
"no squares\n");
219 expectedResult.append(
"no game objects\n");
220 Assert.assertEquals(expectedResult.toString(), result.toString());
240 final StringBuilder expectedResult =
new StringBuilder();
241 expectedResult.append(
"mapObjectsChanged:\n");
242 expectedResult.append(
"no squares\n");
243 expectedResult.append(
"game object 1 2 1\n");
244 expectedResult.append(
"mapSquaresChanged:\n");
245 expectedResult.append(
"square 1 2\n");
246 expectedResult.append(
"no game objects\n");
247 Assert.assertEquals(expectedResult.toString(), result.toString());
269 final StringBuilder expectedResult =
new StringBuilder();
270 expectedResult.append(
"mapObjectsChanged:\n");
271 expectedResult.append(
"no squares\n");
272 expectedResult.append(
"game object 1 2 1\n");
273 expectedResult.append(
"game object 2 2 1\n");
274 expectedResult.append(
"mapSquaresChanged:\n");
275 expectedResult.append(
"square 1 2\n");
276 expectedResult.append(
"square 2 2\n");
277 expectedResult.append(
"no game objects\n");
278 Assert.assertEquals(expectedResult.toString(), result.toString());
300 final StringBuilder expectedResult =
new StringBuilder();
301 expectedResult.append(
"mapObjectsChanged:\n");
302 expectedResult.append(
"no squares\n");
303 expectedResult.append(
"game object 0 0 2\n");
304 expectedResult.append(
"game object 1 2 1\n");
305 Assert.assertEquals(expectedResult.toString(), result.toString());
324 gameObject.setAttributeString(
"key",
"value");
327 final StringBuilder expectedResult =
new StringBuilder();
328 expectedResult.append(
"mapObjectsChanged:\n");
329 expectedResult.append(
"no squares\n");
330 expectedResult.append(
"game object 1 2 1\n");
331 Assert.assertEquals(expectedResult.toString(), result.toString());
353 Assert.assertEquals(1, gameObjects.size());
354 Assert.assertEquals(gameObject, gameObjects.get(0));
377 Assert.assertNotNull(gameObjectWithout);
378 Assert.assertFalse(archetypeWithoutDirection.
usesDirection());
380 Assert.assertNotNull(gameObjectWith);
381 Assert.assertTrue(archetypeWithDirection.usesDirection());
406 Assert.assertNotNull(g1);
407 Assert.assertEquals(1, g1.getEditType());
412 Assert.assertEquals(2, g1.getEditType());
417 Assert.assertEquals(0, g1.getEditType());
423 Assert.assertEquals(4, g1.getEditType());
424 Assert.assertEquals(0, g2.getEditType());
430 Assert.assertEquals(4, g1.getEditType());
431 Assert.assertEquals(0, g2.getEditType());
432 Assert.assertEquals(0, g3.getEditType());
437 Assert.assertEquals(4, g1.getEditType());
438 Assert.assertEquals(2, g2.getEditType());
439 Assert.assertEquals(0, g3.getEditType());
444 Assert.assertEquals(0, g1.getEditType());
445 Assert.assertEquals(2, g2.getEditType());
446 Assert.assertEquals(2, g3.getEditType());
451 Assert.assertEquals(4, g1.getEditType());
452 Assert.assertEquals(2, g2.getEditType());
453 Assert.assertEquals(0, g3.getEditType());
458 Assert.assertEquals(4, g1.getEditType());
459 Assert.assertEquals(4, g2.getEditType());
460 Assert.assertEquals(0, g3.getEditType());
465 Assert.assertEquals(0, g1.getEditType());
466 Assert.assertEquals(0, g2.getEditType());
471 Assert.assertEquals(0, g1.getEditType());
486 result.append(
":\n");
487 if (mapSquares != null) {
488 final Collection<String> lines =
new TreeSet<>();
490 lines.add(
"square " + mapSquare.getMapX() +
" " + mapSquare.getMapY() +
"\n");
492 for (
final String line : lines) {
496 result.append(
"no squares\n");
498 if (gameObjects != null) {
499 final Collection<String> lines =
new TreeSet<>();
501 lines.add(
"game object " + gameObject.getMapX() +
" " + gameObject.getMapY() +
" " + gameObject.getBestName() +
"\n");
503 for (
final String line : lines) {
507 result.append(
"no game objects\n");
522 mapModel.
getMapArchObject().addMapArchObjectListener(mapArchObjectListener);
523 Assert.assertEquals(
"", result.toString());
Test for DefaultMapModel.
Interface for listeners listening on map arch object changes.
void testResizeMap2()
Test case for net.sf.gridarta.model.maparchobject.MapArchObject#setMapSize(Size2D).
void addActiveEditType(int editType)
Add edit type to the bitmask of active types.
A MapModel reflects the data of a map.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
void testAddGameObjectToMap2()
Test case for Point, InsertionMode).
void testResizeMap3()
Test case for net.sf.gridarta.model.maparchobject.MapArchObject#setMapSize(Size2D).
void insertGameObject(@NotNull final GameObject< TestGameObject, TestMapArchObject, TestArchetype > gameObject, @NotNull final String archetypeName, @NotNull final String name)
Inserts a game object into the inventory of another game object.
Helper class for regression tests to create MapModel instances.
void testEmpty()
Test case for an empty transaction.
This package contains the framework for validating maps.
void endTransaction()
End a transaction.
void removeGameObject(@NotNull G gameObject, boolean join)
Delete an existing GameObject from the map.
Interface for listeners listening on MapModel events.
void testResizeMap4()
Test case for net.sf.gridarta.model.maparchobject.MapArchObject#setMapSize(Size2D).
void testResizeMap1()
Test case for net.sf.gridarta.model.maparchobject.MapArchObject#setMapSize(Size2D).
Decorates an arbitrary GameObjectMatcher with a localized name that is suitable for the user interfac...
void testUpdateDirectionOnInsert()
Test case for DefaultMapModel#getAllGameObjects(): the BaseObject#DIRECTION attribute is set only if ...
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
A MapArchObject implementation for testing purposes.
InsertionModeSet< TestGameObject, TestMapArchObject, TestArchetype > getInsertionModeSet()
Returns the InsertionModeSet instance.
void log(@NotNull final String name, @Nullable final Iterable< MapSquare< TestGameObject, TestMapArchObject, TestArchetype >> mapSquares, @Nullable final Iterable< TestGameObject > gameObjects)
Records a change event.
String TYPE
The attribute name of the object's type.
G insertBaseObject(@NotNull BaseObject< G, A, R, ?> baseObject, @NotNull Point pos, boolean allowMany, boolean join, @NotNull InsertionMode< G, A, R > insertionMode)
Inserts a BaseObject to a map.
void addGameObjectMatcher(@NotNull final NamedGameObjectMatcher gameObjectMatcher)
Adds a new GameObjectMatcher.
void testAddGameObjectToMap1()
Test case for Point, InsertionMode).
Base package of all Gridarta classes.
Reflects a game object (object on a map).
void testModifiedGameObject1()
Test case for changed objects.
void testEditType1()
Checks that modifications correctly update edit types.
String DIRECTION
The attribute name of the object's direction.
void setMultiY(int multiY)
Sets the y-position of this part of a multi-part object.
void testGetAllGameObjects1()
Test case for DefaultMapModel#getAllGameObjects(): for a 1x2 game object only the head should be retu...
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.
boolean usesDirection()
Return whether this base object uses the "direction" attribute.
Maintains GameObjectMatcher instances.
TestArchetype getArchetype(@NotNull final String archetypeName)
Returns an archetype.
void setUsesDirection(boolean usesDirection)
Sets the return value of usesDirection().
void addTailPart(@NotNull T tail)
Appends a tail to this GameObject.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
void testModifiedGameObject2()
Test case for changed objects.
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.
ArchetypeChooserModel< TestGameObject, TestMapArchObject, TestArchetype > getArchetypeChooserModel()
Returns the ArchetypeChooserModel instance.
An interface for classes that collect errors.
An Archetype implementation for testing purposes.
An GameObjectMatcher matching certain archetype types.
A GameObject implementation for testing purposes.
GameObjectMatchers getGameObjectMatchers()
Returns the GameObjectMatchers instance.
void beginTransaction(@NotNull String name)
Starts a new transaction.
List< G > getAllGameObjects()
Returns all game objects.
GameObjectFactory< TestGameObject, TestMapArchObject, TestArchetype > getGameObjectFactory()
Returns the GameObjectFactory instance.
MapModel< TestGameObject, TestMapArchObject, TestArchetype > newMapModel(@NotNull final TestMapModelCreator mapModelCreator)
Creates a new MapModel instance.
The location of a map file with a map directory.
The class Size2D represents a 2d rectangular area.