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-2023 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 }
net.sf.gridarta.model.archetype.TestArchetype
An Archetype implementation for testing purposes.
Definition: TestArchetype.java:30
net.sf.gridarta.model.mapmodel.MapModel.insertArchToMap
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.
net.sf.gridarta.model.mapmodel.TestMapModelCreator.newArchetype
TestArchetype newArchetype(@NotNull final String archetypeName)
Creates a new TestArchetype instance but doesn't add it to the archetype set.
Definition: TestMapModelCreator.java:285
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.gameobject.TestGameObject
A GameObject implementation for testing purposes.
Definition: TestGameObject.java:34
net.sf
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.model.mapmodel.TestMapModelCreator
Helper class for regression tests to create MapModel instances.
Definition: TestMapModelCreator.java:63
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.mapcontrol
Definition: DefaultMapControl.java:20
net.sf.gridarta.model.mapcontrol.TestMapControlCreator.getPathManager
PathManager getPathManager()
Returns the PathManager.
Definition: TestMapControlCreator.java:188
net.sf.gridarta.model.io.DefaultMapReaderTest.testReorderMultiSquares
void testReorderMultiSquares()
Checks that map loading doesn't reorder multi-square game objects.
Definition: DefaultMapReaderTest.java:50
net.sf.gridarta.model.mapcontrol.TestMapControlCreator
Helper class for creating MapControl instances for regression tests.
Definition: TestMapControlCreator.java:68
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.mapmodel.TestMapModelCreator.getArchetypeSet
ArchetypeSet< TestGameObject, TestMapArchObject, TestArchetype > getArchetypeSet()
Returns the ArchetypeSet.
Definition: TestMapModelCreator.java:349
net.sf.gridarta.model.io.PathManager.getMapFile
MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath)
Returns a MapFile instance from an AbsoluteMapPath.
Definition: PathManager.java:72
net.sf.gridarta.model.mapcontrol.TestMapControlCreator.newMapReader
DefaultMapReader< TestGameObject, TestMapArchObject, TestArchetype > newMapReader(@NotNull final File mapFile)
Creates a new instance.
Definition: TestMapControlCreator.java:298
net.sf.gridarta.model.mapcontrol.MapControl.save
void save()
Saves the map to a file.
net.sf.gridarta.model.mapmodel.TestMapModelCreator.getArchetype
TestArchetype getArchetype(@NotNull final String archetypeName)
Returns an archetype.
Definition: TestMapModelCreator.java:249
net.sf.gridarta.model.io.DefaultMapReader
Default implementation of MapReader.
Definition: DefaultMapReader.java:41
net.sf.gridarta.model
net.sf.gridarta.model.mapcontrol.TestMapControlCreator.newMapControl
MapControl< TestGameObject, TestMapArchObject, TestArchetype > newMapControl(@Nullable final MapFile mapFile, @NotNull final String mapName, @NotNull final Size2D mapSize)
Creates a new map control.
Definition: TestMapControlCreator.java:176
net.sf.gridarta.model.archetype.DuplicateArchetypeException
An Exception indicating that an Archetype name is not unique.
Definition: DuplicateArchetypeException.java:29
net.sf.gridarta.model.mapcontrol.MapControl
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
net.sf.gridarta.model.mapcontrol.TestMapControlCreator.getMapModelCreator
TestMapModelCreator getMapModelCreator()
Returns the TestMapModelCreator instance.
Definition: TestMapControlCreator.java:251
net.sf.gridarta.model.mapcontrol.MapControl.getMapModel
MapModel< G, A, R > getMapModel()
Returns the map model.
net.sf.gridarta.model.maparchobject.TestMapArchObject
A MapArchObject implementation for testing purposes.
Definition: TestMapArchObject.java:28
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.io.DefaultMapReader.getGameObjects
List< G > getGameObjects()
Definition: DefaultMapReader.java:88
net.sf.gridarta.utils.Size2D
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.model.io.DefaultMapReaderTest
Regression tests for DefaultMapReader.
Definition: DefaultMapReaderTest.java:42
net.sf.gridarta.model.archetype.Archetype.setMultiX
void setMultiX(int multiX)
Sets the x-position of this part of a multi-part object.