Gridarta Editor
FillUtilsTest.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.floodfill;
21 
22 import java.awt.Point;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.List;
35 import org.junit.Assert;
36 import org.junit.Test;
37 
42 public class FillUtilsTest {
43 
50  @Test
52  final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false);
53  final TestMapModelHelper mapModelHelper = mapModelCreator.newTestMapModelHelper();
54  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(4, 5);
55 
56  final TestArchetype head = mapModelCreator.getArchetype("2x2a");
57  head.setAttributeInt(BaseObject.TYPE, 1);
58  final TestArchetype tail1 = mapModelCreator.getArchetype("2x2b");
59  tail1.setMultiX(1);
60  head.addTailPart(tail1);
61  final TestArchetype tail2 = mapModelCreator.getArchetype("2x2c");
62  tail2.setMultiY(1);
63  head.addTailPart(tail2);
64  final TestArchetype tail3 = mapModelCreator.getArchetype("2x2d");
65  tail3.setMultiX(1);
66  tail3.setMultiY(1);
67  head.addTailPart(tail3);
68 
69  mapModel.beginTransaction("TEST");
70  mapModelHelper.insertArchetype(mapModel, new Point(0, 2), head, false);
71 
72  final Collection<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> selection = new ArrayList<>();
73  selection.add(mapModel.getMapSquare(new Point(2, 0)));
74  final List<TestGameObject> gameObjects = new ArrayList<>();
75  gameObjects.add(mapModelCreator.getGameObjectFactory().createGameObject(head));
76 
77  FillUtils.fill(mapModel, selection, mapModelCreator.getInsertionModeSet().getTopmostInsertionMode(), gameObjects, 100, true);
78  Assert.assertTrue(mapModel.getMapSquare(new Point(2, 0)).isEmpty());
79 
80  FillUtils.fill(mapModel, selection, mapModelCreator.getInsertionModeSet().getTopmostInsertionMode(), gameObjects, 100, false);
81  Assert.assertFalse(mapModel.getMapSquare(new Point(2, 0)).isEmpty());
82  }
83 
84 }
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
Helper class for regression tests to create MapModel instances.
Helper class for creating MapModel instances for regression tests.
A MapArchObject implementation for testing purposes.
InsertionModeSet< TestGameObject, TestMapArchObject, TestArchetype > getInsertionModeSet()
Returns the InsertionModeSet instance.
String TYPE
The attribute name of the object&#39;s type.
Definition: BaseObject.java:66
Base package of all Gridarta classes.
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.
void setMultiY(int multiY)
Sets the y-position of this part of a multi-part object.
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.
Regression tests for FillUtils.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
GameObjects are the objects based on Archetypes found on maps.
TestArchetype getArchetype(@NotNull final String archetypeName)
Returns an archetype.
void testFillAdjacent()
Checks that Collection, net.sf.gridarta.model.mapmodel.InsertionMode, List, int, boolean) works corre...
TestMapModelHelper newTestMapModelHelper()
Creates a new TestMapModelHelper instance.
An Archetype implementation for testing purposes.
Utility class implementing fill operations on map instances.
Definition: FillUtils.java:43
A GameObject implementation for testing purposes.
void beginTransaction(@NotNull String name)
Starts a new transaction.
GameObjectFactory< TestGameObject, TestMapArchObject, TestArchetype > getGameObjectFactory()
Returns the GameObjectFactory instance.