Gridarta Editor
TestMapModelCreator.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.awt.image.BufferedImage;
24 import javax.swing.ImageIcon;
55 import net.sf.gridarta.utils.Size2D;
56 import org.jetbrains.annotations.NotNull;
57 import org.junit.Assert;
58 
63 public class TestMapModelCreator {
64 
68  @NotNull
70 
74  @NotNull
76 
80  @NotNull
82 
86  @NotNull
88 
92  @NotNull
94 
98  @NotNull
100 
104  @NotNull
106 
110  @NotNull
112 
116  @NotNull
118 
122  @NotNull
124 
128  @NotNull
130 
134  @NotNull
136 
141  public TestMapModelCreator(final boolean createIcons) {
142  autojoinLists = new AutojoinLists<>();
143  resourceIcons = new ResourceIcons();
144  if (createIcons) {
145  final ImageIcon imageIcon = new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB));
146  for (final String iconName : ICON_NAMES) {
147  resourceIcons.addToCache(iconName, imageIcon);
148  }
149  }
150  final FaceObjects faceObjects = new TestFaceObjects();
151  faceObjectProviders = new FaceObjectProviders(0, faceObjects, resourceIcons);
152  final FaceProvider faceProvider = new EmptyFaceProvider();
153  faceObjectProviders.setNormal(faceProvider);
154  final ArchetypeFactory<TestGameObject, TestMapArchObject, TestArchetype> archetypeFactory = new TestArchetypeFactory(faceObjectProviders, animationObjects);
155  archetypeSet = new DefaultArchetypeSet<>(archetypeFactory, null);
156  gameObjectFactory = new TestGameObjectFactory(faceObjectProviders, animationObjects);
157  topmostInsertionMode = new TopmostInsertionMode<>();
159  }
160 
167  @NotNull
169  final TestMapArchObject mapArchObject = new TestMapArchObject();
170  mapArchObject.setMapSize(new Size2D(w, h));
172  }
173 
180  @NotNull
181  public TestGameObject newGameObject(@NotNull final String archetypeName, @NotNull final String objectName) {
182  final TestArchetype archetype = getArchetype(archetypeName);
183  final TestGameObject gameObject = new TestGameObject(archetype, faceObjectProviders, animationObjects);
184  gameObject.setAttributeString(BaseObject.NAME, objectName);
185  return gameObject;
186  }
187 
197  public 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) {
198  final TestGameObject gameObject = newGameObject(archetypeName, name);
199  mapModel.addGameObjectToMap(gameObject, new Point(x, y), insertionMode);
200  }
201 
208  public void insertGameObject(@NotNull final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject, @NotNull final String archetypeName, @NotNull final String name) {
209  final TestGameObject inv = newGameObject(archetypeName, name);
210  gameObject.addLast(inv);
211  }
212 
217  @NotNull
219  return insertionModeSet;
220  }
221 
226  @NotNull
228  return topmostInsertionMode;
229  }
230 
236  @NotNull
237  public TestArchetype getArchetype(@NotNull final String archetypeName) {
238  try {
239  return archetypeSet.getArchetype(archetypeName);
240  } catch (final UndefinedArchetypeException ignored) {
241  // ignore
242  }
243 
244  final TestArchetype archetype = newArchetype(archetypeName);
245  try {
246  archetypeSet.addArchetype(archetype);
247  } catch (final DuplicateArchetypeException ex) {
248  Assert.fail(ex.getMessage());
249  throw new AssertionError(ex);
250  }
251  return archetype;
252  }
253 
260  @NotNull
261  public TestArchetype newArchetype(@NotNull final String archetypeName) {
262  return new TestDefaultArchetype(archetypeName, faceObjectProviders, animationObjects);
263  }
264 
269  @NotNull
271  return gameObjectFactory;
272  }
273 
278  @NotNull
280  return mapViewSettings;
281  }
282 
288  @NotNull
290  return new TestMapModelHelper(topmostInsertionMode, gameObjectFactory, archetypeSet, faceObjectProviders, animationObjects);
291  }
292 
297  @NotNull
299  return autojoinLists;
300  }
301 
306  @NotNull
308  return archetypeChooserModel;
309  }
310 
315  @NotNull
317  return gameObjectMatchers;
318  }
319 
324  @NotNull
326  return archetypeSet;
327  }
328 
334  return new TestGameObjectParser(gameObjectFactory, archetypeSet);
335  }
336 
341  @NotNull
343  return faceObjectProviders;
344  }
345 
350  @NotNull
352  return resourceIcons;
353  }
354 
355 }
A FaceObjects for regression tests.
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
Reading and writing of maps, handling of paths.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
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.
TestMapModelCreator(final boolean createIcons)
Creates a new instance.
ArchetypeSet< TestGameObject, TestMapArchObject, TestArchetype > getArchetypeSet()
Returns the ArchetypeSet.
Helper class for regression tests to create MapModel instances.
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...
An AnimationObjects for regression tests.
final GameObjectFactory< TestGameObject, TestMapArchObject, TestArchetype > gameObjectFactory
The GameObjectFactory instance.
This interface represents a lazy loader that provides images on demand.
Interface for classes that read or write GameObject instances.
FaceObjectProviders getFaceObjectProviders()
Returns the FaceObjectProviders instance.
final GameObjectMatchers gameObjectMatchers
The GameObjectMatchers instance.
A MapArchObject implementation for testing purposes.
final MapViewSettings mapViewSettings
The MapViewSettings instance.
InsertionModeSet< TestGameObject, TestMapArchObject, TestArchetype > getInsertionModeSet()
Returns the InsertionModeSet instance.
final FaceObjectProviders faceObjectProviders
The FaceObjectProviders instance.
A factory for creating Archetype instances.
Base package of all Gridarta classes.
final InsertionModeSet< TestGameObject, TestMapArchObject, TestArchetype > insertionModeSet
The InsertionModeSet instance.
Reflects a game object (object on a map).
Definition: GameObject.java:36
An Archetype implementation for testing purposes.
Abstract factory for creating GameObject instances.
R getArchetype(@NotNull String archetypeName)
Returns an Archetype by its name.
final AutojoinLists< TestGameObject, TestMapArchObject, TestArchetype > autojoinLists
The AutojoinLists instance.
An Exception indicating that an Archetype name is not unique.
TestGameObject newGameObject(@NotNull final String archetypeName, @NotNull final String objectName)
Creates a new game object.
Container for settings that affect the rendering of maps.
AnimationObjects is a container for AnimationObjects.
GameObjects are the objects based on Archetypes found on maps.
final ArchetypeSet< TestGameObject, TestMapArchObject, TestArchetype > archetypeSet
The ArchetypeSet instance.
final AnimationObjects animationObjects
The AnimationObjects instance.
void setNormal(@NotNull final FaceProvider normalFaceProvider)
Sets the normal FaceProvider.
static final String DEFAULT_PREVIEW
The default map preview to use if no icon can be created.
Maintains GameObjectMatcher instances.
FaceObjects is a container for FaceObjects.
TestArchetype newArchetype(@NotNull final String archetypeName)
Creates a new TestArchetype instance but doesn&#39;t add it to the archetype set.
void addArchetype(@NotNull R archetype)
Adds an Archetype to this Set.
static final String DEFAULT_ICON
The default map icon to use if no icon can be created.
static final String SQUARE_SELECTED_SQUARE_NORTH
void setMapSize(@NotNull final Size2D mapSize)
Sets the map size.
TestArchetype getArchetype(@NotNull final String archetypeName)
Returns an archetype.
static final String [] ICON_NAMES
Predefined icon names.
An ArchetypeFactory implementation for testing purposes.
GameObjectParser< TestGameObject, TestMapArchObject, TestArchetype > newGameObjectParser()
Creates a new GameObjectParser instance.
static final String SQUARE_SELECTED_SQUARE_SOUTH
TestMapModelHelper newTestMapModelHelper()
Creates a new TestMapModelHelper instance.
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
final ArchetypeChooserModel< TestGameObject, TestMapArchObject, TestArchetype > archetypeChooserModel
The ArchetypeChooserModel instance.
Manages a mapping between archetypes to AutojoinLists.
ResourceIcons getResourceIcons()
Returns the ResourceIcons instance.
A MapViewSettings implementation for regression tests.
Creates ImageIcon instances from resources.
String NAME
The attribute name of the object&#39;s name.
Definition: BaseObject.java:60
final ResourceIcons resourceIcons
The ResourceIcons instance.
AutojoinLists< TestGameObject, TestMapArchObject, TestArchetype > getAutojoinLists()
Returns the AutojoinLists instance.
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.
static final String SQUARE_SELECTED_SQUARE_EAST
MapViewSettings getMapViewSettings()
Returns the MapViewSettings instance.
ArchetypeChooserModel< TestGameObject, TestMapArchObject, TestArchetype > getArchetypeChooserModel()
Returns the ArchetypeChooserModel instance.
An Archetype implementation for testing purposes.
static final String SQUARE_PRE_SELECTED_SQUARE
An GameObjectMatcher matching certain archetype types.
A GameObject implementation for testing purposes.
Interface that captures similarities between different ArchetypeSet implementations.
GameObjectMatchers getGameObjectMatchers()
Returns the GameObjectMatchers instance.
InsertionMode< TestGameObject, TestMapArchObject, TestArchetype > getTopmostInsertionMode()
Returns the "topmost" insertion mode.
static final String SQUARE_SELECTED_SQUARE_WEST
static final String SQUARE_SELECTED_SQUARE
final InsertionMode< TestGameObject, TestMapArchObject, TestArchetype > topmostInsertionMode
The "topmost" InsertionMode instance.
A FaceProvider that does not return any faces.
GameObjectFactory< TestGameObject, TestMapArchObject, TestArchetype > getGameObjectFactory()
Returns the GameObjectFactory instance.
A GameObjectParser for regression tests.
Implementation of MapModel that covers the similarities between crossfire and daimonin.
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30