Gridarta Editor
DefaultMapReaderTest.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.io;
21 
22 import java.awt.Point;
23 import java.io.File;
24 import java.io.IOException;
25 import java.util.List;
34 import net.sf.gridarta.utils.Size2D;
35 import org.junit.Assert;
36 import org.junit.Test;
37 
42 public class DefaultMapReaderTest {
43 
49  @Test
50  public void testReorderMultiSquares() throws DuplicateArchetypeException, IOException {
51  final TestMapControlCreator mapControlCreator = new TestMapControlCreator();
52  final TestMapModelCreator mapModelCreator = mapControlCreator.getMapModelCreator();
53  final File mapFile = File.createTempFile("gridarta", null);
54  final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = mapControlCreator.newMapControl(mapControlCreator.getPathManager().getMapFile(mapFile), "test", new Size2D(2, 1));
56  final TestArchetype arch1x1 = mapModelCreator.getArchetype("arch1x1");
57  final TestArchetype arch2x1 = mapModelCreator.newArchetype("arch2x1");
58  final TestArchetype arch2x1b = mapModelCreator.newArchetype("arch2x1b");
59  arch2x1b.setMultiX(1);
60  arch2x1.addTailPart(arch2x1b);
61  mapModelCreator.getArchetypeSet().addArchetype(arch2x1);
62  mapModel.insertArchToMap(arch1x1, null, new Point(0, 0), false);
63  mapModel.insertArchToMap(arch1x1, null, new Point(1, 0), false);
64  mapModel.insertArchToMap(arch2x1, null, new Point(0, 0), false);
65  mapModel.insertArchToMap(arch1x1, null, new Point(0, 0), false);
66  mapModel.insertArchToMap(arch1x1, null, new Point(1, 0), false);
67  mapControl.save();
69  final List<TestGameObject> objects = reader.getGameObjects();
70  Assert.assertEquals(6, objects.size());
71  Assert.assertEquals("arch1x1", objects.get(0).getArchetype().getArchetypeName());
72  Assert.assertEquals("arch2x1", objects.get(1).getArchetype().getArchetypeName());
73  Assert.assertEquals("arch1x1", objects.get(2).getArchetype().getArchetypeName());
74  Assert.assertEquals("arch1x1", objects.get(3).getArchetype().getArchetypeName());
75  Assert.assertEquals("arch1x1", objects.get(4).getArchetype().getArchetypeName());
76  Assert.assertEquals("arch2x1b", objects.get(5).getArchetype().getArchetypeName());
77  }
78 
79 }
void save()
Saves the map to a file.
A MapModel reflects the data of a map.
Definition: MapModel.java:75
void testReorderMultiSquares()
Checks that map loading doesn&#39;t reorder multi-square game objects.
ArchetypeSet< TestGameObject, TestMapArchObject, TestArchetype > getArchetypeSet()
Returns the ArchetypeSet.
Helper class for regression tests to create MapModel instances.
TestMapModelCreator getMapModelCreator()
Returns the TestMapModelCreator instance.
Helper class for creating MapControl instances for regression tests.
Default implementation of MapReader.
MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath)
Returns a MapFile instance from an AbsoluteMapPath.
Regression tests for DefaultMapReader.
A MapArchObject implementation for testing purposes.
MapModel< G, A, R > getMapModel()
Returns the map model.
Base package of all Gridarta classes.
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.
GameObjects are the objects based on Archetypes found on maps.
G insertArchToMap(@NotNull BaseObject< G, A, R, ?> templateBaseObject, @Nullable G nextGameObject, @NotNull Point pos, boolean join)
Insert a game object to the map at a specified position.
TestArchetype newArchetype(@NotNull final String archetypeName)
Creates a new TestArchetype instance but doesn&#39;t add it to the archetype set.
TestArchetype getArchetype(@NotNull final String archetypeName)
Returns an archetype.
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
An Archetype implementation for testing purposes.
A GameObject implementation for testing purposes.
DefaultMapReader< TestGameObject, TestMapArchObject, TestArchetype > newMapReader(@NotNull final File mapFile)
Creates a new instance.
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
MapControl< TestGameObject, TestMapArchObject, TestArchetype > newMapControl(@Nullable final MapFile mapFile, @NotNull final String mapName, @NotNull final Size2D mapSize)
Creates a new map control.