20 package net.sf.gridarta.model.mapmodel;
22 import java.awt.Point;
23 import java.util.regex.Pattern;
38 import org.jetbrains.annotations.NotNull;
39 import org.junit.Assert;
107 public TestMapModelHelper(@NotNull
final InsertionMode<TestGameObject, TestMapArchObject, TestArchetype> topmostInsertionMode, @NotNull
final GameObjectFactory<TestGameObject, TestMapArchObject, TestArchetype> gameObjectFactory, @NotNull
final ArchetypeSet<TestGameObject, TestMapArchObject, TestArchetype> archetypeSet, @NotNull
final FaceObjectProviders faceObjectProviders, @NotNull
final AnimationObjects animationObjects)
throws DuplicateArchetypeException {
113 archetypeSet.addArchetype(floorArchetype);
117 archetypeSet.addArchetype(exitArchetype);
121 archetypeSet.addArchetype(mob21Archetype);
124 mob21Archetype.addTailPart(mob21bArchetype);
125 archetypeSet.addArchetype(mob21bArchetype);
185 final TestGameObject gameObject = mapModel.insertBaseObject(archetype, point,
true, join, topmostInsertionMode);
186 if (gameObject == null) {
187 throw new IllegalArgumentException();
220 final TestGameObject newGameObject = archetype.newInstance(gameObjectFactory);
221 gameObject.addLast(newGameObject);
222 return newGameObject;
231 final Size2D mapSize = mapModel.getMapArchObject().getMapSize();
232 Assert.assertEquals(lines.length, mapSize.
getHeight());
233 final Pattern pattern1 = Pattern.compile(
"\\|");
235 final Point pos =
new Point();
236 for (
int y = 0; y < lines.length; y++) {
237 final CharSequence line = lines[y];
238 final String[] square = pattern1.split(line, -1);
239 Assert.assertEquals(square.length, mapSize.
getWidth());
241 for (
int x = 0; x < square.length; x++) {
242 final String square2 = square[x];
243 final String[] gameObjects = square2.isEmpty() ?
EMPTY_STRING_ARRAY : pattern2.split(square2, -1);
259 final String gameObjectName = gameObject.getBestName();
260 if (i >= gameObjects.length) {
261 Assert.fail(
"map square " + mapSquare.
getMapX() +
"/" + mapSquare.
getMapY() +
" contains excess game object '" + gameObjectName +
"'");
262 }
else if (!gameObjectName.equals(gameObjects[i])) {
263 Assert.fail(
"map square " + mapSquare.
getMapX() +
"/" + mapSquare.
getMapY() +
" contains wrong game object '" + gameObjectName +
"' at index " + i +
", expected '" + gameObjects[i] +
"'");
267 if (i < gameObjects.length) {
268 Assert.fail(
"map square " + mapSquare.
getMapX() +
"/" + mapSquare.
getMapY() +
" is missing game object '" + gameObjects[i] +
"'");
280 final String gameObjectName = gameObject.getBestName();
281 if (i >= gameObjects.length) {
282 Assert.fail(
"map square contains excess game object '" + gameObjectName +
"'");
283 }
else if (gameObject != gameObjects[i]) {
284 Assert.fail(
"map square contains wrong game object '" + gameObjectName +
"' at index " + i +
", expected '" + gameObjects[i].getBestName() +
"'");
288 if (i < gameObjects.length) {
289 Assert.fail(
"map square is missing game object '" + gameObjects[i].getBestName() +
"'");
292 final boolean inContainer = mapSquare instanceof
GameObject;
294 Assert.assertEquals(inContainer, gameObject.isInContainer());
297 Assert.assertFalse(gameObject.isMulti());
300 Assert.assertEquals(gameObject.getArchetype().isMulti(), gameObject.isMulti());
Utility class for string manipulation.
static final int EXIT_TYPE
The archetype type used for "exit" game objects.
A MapModel reflects the data of a map.
Helper class for creating MapModel instances for regression tests.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
TestGameObject insertArchetype(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point, @NotNull final BaseObject< TestGameObject, TestMapArchObject, TestArchetype, ?> archetype, final boolean join)
Inserts an archetype game object into a map model.
static void checkContentsString(@NotNull final MapSquare< TestGameObject, TestMapArchObject, TestArchetype > mapSquare, @NotNull final String... gameObjects)
Checks that a MapSquare contains the given game objects.
TestMapModelHelper(@NotNull final InsertionMode< TestGameObject, TestMapArchObject, TestArchetype > topmostInsertionMode, @NotNull final GameObjectFactory< TestGameObject, TestMapArchObject, TestArchetype > gameObjectFactory, @NotNull final ArchetypeSet< TestGameObject, TestMapArchObject, TestArchetype > archetypeSet, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects)
Creates a new instance.
final TestArchetype exitArchetype
The archetype to create exit game objects.
TestGameObject insertArchetype(@NotNull final GameObjectContainer< TestGameObject, TestMapArchObject, TestArchetype > gameObject, @NotNull final BaseObject< TestGameObject, TestMapArchObject, TestArchetype, ?> archetype)
Inserts an archetype into a game object.
Base class for classes that contain GameObjects as children in the sense of containment.
A MapArchObject implementation for testing purposes.
static void checkContents(@NotNull final Iterable< TestGameObject > mapSquare, @NotNull final BaseObject<?, ?, ?, ?>... gameObjects)
Checks that a MapSquare contains the given game objects.
String TYPE
The attribute name of the object's type.
int getMapX()
Returns the X coordinate of this GameObject on its map.
TestGameObject insertFloor(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point)
Inserts a floorArchetype game object into a map model.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
An Archetype implementation for testing purposes.
Abstract factory for creating GameObject instances.
static final int MOB_TYPE
The archetype type used for "mob" game objects.
TestGameObject insertArchetype(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, final int x, final int y, @NotNull final BaseObject< TestGameObject, TestMapArchObject, TestArchetype, ?> archetype, final boolean join)
Inserts an archetype game object into a map model.
int getMapY()
Returns the Y coordinate of this GameObject on its map.
An Exception indicating that an Archetype name is not unique.
void setMultiX(int multiX)
Sets the x-position of this part of a multi-part object.
AnimationObjects is a container for AnimationObjects.
static final int FLOOR_TYPE
The archetype type used for "floor" game objects.
final TestArchetype floorArchetype
The archetype to create floor game objects.
GameObjects are the objects based on Archetypes found on maps.
static void checkMapContents(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final String... lines)
Checks for expected MapModel's contents.
int getWidth()
Returns the width of the area.
TestGameObject insertMob21(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point)
Inserts a mob21Archetype game object into a map model.
static final Pattern PATTERN_COMMA
The pattern that matches a single comma (",").
TestGameObject insertExit(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point)
Inserts an exitArchetype game object into a map model.
final TestArchetype mob21Archetype
The archetype to create 2x1 mob game objects.
TestGameObject insertExit(@NotNull final GameObjectContainer< TestGameObject, TestMapArchObject, TestArchetype > gameObject)
Inserts an exitArchetype game object into a game object.
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
An Archetype implementation for testing purposes.
A GameObject implementation for testing purposes.
Interface that captures similarities between different ArchetypeSet implementations.
TestGameObject insertMob21(@NotNull final GameObjectContainer< TestGameObject, TestMapArchObject, TestArchetype > gameObject)
Inserts a mob21Archetype game object into a game object.
static final String [] EMPTY_STRING_ARRAY
An empty array of strings.
int getHeight()
Returns the height of the area.
final GameObjectFactory< TestGameObject, TestMapArchObject, TestArchetype > gameObjectFactory
The GameObjectFactory instance.
final InsertionMode< TestGameObject, TestMapArchObject, TestArchetype > topmostInsertionMode
The "topmost" InsertionMode instance.
The class Size2D represents a 2d rectangular area.