20 package net.sf.gridarta.model.mapcontrol;
23 import java.io.IOException;
60 import org.jetbrains.annotations.NotNull;
61 import org.jetbrains.annotations.Nullable;
62 import org.junit.Assert;
154 mapManager = tmpMapManager;
157 pickmapManager = tmpPickmapManager;
180 return mapManager.
newMap(null, mapArchObject, mapFile,
true);
315 @Nullable File directoryToDelete = mapsDirectory;
318 directoryToDelete = null;
320 if (directoryToDelete != null) {
324 return mapsDirectory;
332 private void createMaps(@NotNull
final String[] specs)
throws IOException {
333 for (
final String spec : specs) {
335 if (tmp.length != 2) {
336 throw new IllegalArgumentException();
340 final String mapName = tmp[1];
342 final File file = mapFile.
getFile();
343 if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
344 throw new IOException(
"cannot create directory: " + file.getParentFile());
350 mapControl.
saveAs(mapFile);
363 private static File
createTempDir(@NotNull
final String prefix)
throws IOException {
364 final String tmpDir = System.getProperty(
"java.io.tmpdir");
365 if (tmpDir == null) {
366 throw new IOException(
"the system property 'java.io.tmpdir' does not exist");
369 final File tmpFile =
new File(tmpDir);
370 if (!tmpFile.exists() && !tmpFile.mkdirs()) {
371 throw new IOException(
"cannot create temporary directory " + tmpFile);
374 final File result = File.createTempFile(prefix, null);
375 if (!result.delete()) {
376 throw new IOException(
"cannot delete temporary file " + result);
378 if (!result.mkdir()) {
379 throw new IOException(
"cannot create temporary directory " + result);
390 final File[] files = dir.listFiles();
392 for (
final File file : files) {
393 if (file.isDirectory()) {
395 }
else if (!file.delete()) {
396 Assert.fail(
"cannot delete file " + file);
401 Assert.fail(
"cannot delete directory " + dir);
A factory for creating MapModel instances.
void createMaps(@NotNull final String[] specs)
Creates a set of map files in the maps directory.
Default implementation of MapWriter.
ExitMatcher< TestGameObject, TestMapArchObject, TestArchetype > getExitMatcher()
Returns the ExitMatcher.
final MapArchObjectFactory< TestMapArchObject > mapArchObjectFactory
The MapArchObjectFactory instance.
Utility class for string manipulation.
MapModel< TestGameObject, TestMapArchObject, TestArchetype > newMapModel(final int w, final int h)
Creates a new MapModel instance.
static final int EXIT_TYPE
The archetype type used for "exit" game objects.
This class contains methods for converting relative map paths to absolute map paths and vice versa...
A MapModel reflects the data of a map.
A MapManager manages all opened maps.
static void deleteTempDir(@NotNull final File dir)
Deletes a temporary directory.
Reading and writing of maps, handling of paths.
Interface for classes that match GameObjects.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
PathManager getPathManager()
Returns the PathManager.
MapControl< G, A, R > newMap(@Nullable List< G > objects, @NotNull A mapArchObject, @Nullable MapFile mapFile, boolean interactive)
Creates a new map control without view.
ArchetypeSet< TestGameObject, TestMapArchObject, TestArchetype > getArchetypeSet()
Returns the ArchetypeSet.
Helper class for regression tests to create MapModel instances.
Settings that apply to a project.
Implements AutojoinList related functions.
Interface for classes that write map files.
Helper class for creating MapModel instances for regression tests.
A factory for creating MapReader instances.
void setMapName(@NotNull final String name)
Sets the map name.
TestMapModelCreator getMapModelCreator()
Returns the TestMapModelCreator instance.
An MapControlFactory implementation for testing purposes.
Helper class for creating MapControl instances for regression tests.
MapWriter< TestGameObject, TestMapArchObject, TestArchetype > getMapWriter()
Returns the MapWriter instance.
Default implementation of MapReader.
MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath)
Returns a MapFile instance from an AbsoluteMapPath.
Factory for creating MapArchObject instances.
MapArchObjectFactory< TestMapArchObject > getMapArchObjectFactory()
Returns the MapArchObjectFactory instance.
Interface for classes that read or write GameObject instances.
An MapReaderFactory implementation for testing purposes.
MapModelFactory< TestGameObject, TestMapArchObject, TestArchetype > getMapModelFactory()
Returns the MapModelFactory instance.
FaceObjectProviders getFaceObjectProviders()
Returns the FaceObjectProviders instance.
static File createTempDir(@NotNull final String prefix)
Creates an empty directory in the default temporary directory using the given prefix.
final GameObjectParser< TestGameObject, TestMapArchObject, TestArchetype > gameObjectParser
The GameObjectParser instance.
A MapArchObject implementation for testing purposes.
Factory for creating MapArchObjectParser instances.
InsertionModeSet< TestGameObject, TestMapArchObject, TestArchetype > getInsertionModeSet()
Returns the InsertionModeSet instance.
final ProjectSettings projectSettings
The ProjectSettings instance.
A newMapArchObject(boolean addDefaultAttributes)
Creates a new MapArchObject instance.
MapModel< G, A, R > getMapModel()
Returns the map model.
Abstract base class for MapManager implementations.
Base package of all Gridarta classes.
final PathManager pathManager
The PathManager instance.
File createMapsDirectory(@NotNull final String... specs)
Creates a maps directory consisting of a set of maps.
AutojoinListsHelper newAutojoinListsHelper()
Returns a new AutojoinListsHelper instance.
A FileControl implementation for testing purposes.
final MapManager< TestGameObject, TestMapArchObject, TestArchetype > pickmapManager
The pickmap MapManager instance.
Selects valid exit game objects from maps.
An Exception indicating that an Archetype name is not unique.
TestMapControlCreator()
Creates a new instance.
void setFileControl(@NotNull final FileControl< G, A, R > fileControl)
GameObjects are the objects based on Archetypes found on maps.
void setMapsDirectory(@NotNull File mapsDirectory)
Sets the default maps directory.
final ExitMatcher< TestGameObject, TestMapArchObject, TestArchetype > exitMatcher
The ExitMatcher instance.
A MapArchObjectFactory for regression tests.
ArchetypeSet< TestGameObject, TestMapArchObject, TestArchetype > getArchetypeSet()
Returns the ArchetypeSet.
InsertionModeSet< TestGameObject, TestMapArchObject, TestArchetype > getInsertionModeSet()
Returns the InsertionModeSet.
ProjectSettings getProjectSettings()
Returns the ProjectSettings.
TestMapModelHelper newMapModelCreator()
Creates a new TestMapModelHelper instance.
void setMapSize(@NotNull final Size2D mapSize)
Sets the map size.
final MapArchObjectParserFactory< TestMapArchObject > mapArchObjectParserFactory
The MapArchObjectParserFactory instance.
GameObjectParser< TestGameObject, TestMapArchObject, TestArchetype > newGameObjectParser()
Creates a new GameObjectParser instance.
TestMapModelHelper newTestMapModelHelper()
Creates a new TestMapModelHelper instance.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
The view of the archetype chooser.
Currently nothing more than a marker interface for unification.
File getFile()
Returns a File for this map file.
AutojoinLists< TestGameObject, TestMapArchObject, TestArchetype > getAutojoinLists()
Returns the AutojoinLists instance.
An Archetype implementation for testing purposes.
An GameObjectMatcher matching certain archetype types.
A GameObject implementation for testing purposes.
File getMapsDirectory()
Returns the default maps directory.
Interface that captures similarities between different ArchetypeSet implementations.
static final Pattern PATTERN_COLON
The pattern that matches a single colon (":").
DefaultMapReader< TestGameObject, TestMapArchObject, TestArchetype > newMapReader(@NotNull final File mapFile)
Creates a new instance.
final MapWriter< TestGameObject, TestMapArchObject, TestArchetype > mapWriter
The MapWriter instance.
An ProjectSettings implementation for testing purposes.
GameObjectMatchers getGameObjectMatchers()
Returns the GameObjectMatchers instance.
InsertionMode< TestGameObject, TestMapArchObject, TestArchetype > getTopmostInsertionMode()
Returns the "topmost" insertion mode.
void saveAs(@NotNull MapFile mapFile)
Saves the file with the given map file.
final MapManager< TestGameObject, TestMapArchObject, TestArchetype > mapManager
The MapManager instance.
final TestMapModelCreator mapModelCreator
The TestMapModelCreator instance.
GameObjectFactory< TestGameObject, TestMapArchObject, TestArchetype > getGameObjectFactory()
Returns the GameObjectFactory instance.
final MapModelFactory< TestGameObject, TestMapArchObject, TestArchetype > mapModelFactory
The MapModelFactory instance.
The location of a map file with a map directory.
A MapArchObjectParserFactory for regression tests.
MapManager< TestGameObject, TestMapArchObject, TestArchetype > getMapManager()
Returns the MapManager.
MapManager< TestGameObject, TestMapArchObject, TestArchetype > getPickmapManager()
Returns the pickmap manager instance.
The class Size2D represents a 2d rectangular area.
MapControl< TestGameObject, TestMapArchObject, TestArchetype > newMapControl(@Nullable final MapFile mapFile, @NotNull final String mapName, @NotNull final Size2D mapSize)
Creates a new map control.