From: <aki...@us...> - 2008-07-25 17:55:25
|
Revision: 4428 http://gridarta.svn.sourceforge.net/gridarta/?rev=4428&view=rev Author: akirschbaum Date: 2008-07-25 17:55:30 +0000 (Fri, 25 Jul 2008) Log Message: ----------- Improve map model transaction system to distinguish between 'square changes' and 'game object changes'. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gameobject/GameObjectContainer.java trunk/src/app/net/sf/gridarta/gui/GameObjectAttributesPanel.java trunk/src/app/net/sf/gridarta/map/DefaultMapModel.java trunk/src/app/net/sf/gridarta/map/MapModelListener.java trunk/src/app/net/sf/gridarta/map/MapSquare.java Added Paths: ----------- trunk/src/test/net/sf/gridarta/map/ trunk/src/test/net/sf/gridarta/map/DefaultMapModelTest.java Modified: trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2008-07-25 17:35:39 UTC (rev 4427) +++ trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2008-07-25 17:55:30 UTC (rev 4428) @@ -116,9 +116,9 @@ /** {@inheritDoc} */ public void mapObjectsChanged(final MapModelEvent<GameObject, MapArchObject, Archetype> e) { - final GameObject[] gameObjects = e.getGameObjects(); + final net.sf.gridarta.gameobject.GameObject<GameObject, MapArchObject, Archetype>[] gameObjects = e.getGameObjects(); if (gameObjects != null) { - for (final GameObject gameObject : gameObjects) { + for (final net.sf.gridarta.gameobject.GameObject<GameObject, MapArchObject, Archetype> gameObject : gameObjects) { if (!gameObject.isInContainer()) { final MapSquare<GameObject, MapArchObject, Archetype> square = gameObject.getMapSquare(); if (square != null) { Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2008-07-25 17:35:39 UTC (rev 4427) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2008-07-25 17:55:30 UTC (rev 4428) @@ -537,6 +537,15 @@ return container != null ? container.getMapSquare() : null; } + /** {@inheritDoc} */ + @Override + protected void notifyChanged() { + final MapSquare<G, A, R> mapSquare = getMapSquare(); + if (mapSquare != null) { + mapSquare.getMapModel().gameObjectChanged((G) this); + } + } + /** Move this GameObject top. Does nothing if the object has no container. */ public void moveTop() { if (isArchetype()) { Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObjectContainer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObjectContainer.java 2008-07-25 17:35:39 UTC (rev 4427) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObjectContainer.java 2008-07-25 17:55:30 UTC (rev 4428) @@ -423,15 +423,9 @@ public abstract MapSquare<G, A, R> getMapSquare(); /** - * Tell the model that this MapSquare has changed. This method must be - * invoked by all other methods that change something. + * Notify the map model that this container has changed. */ - protected final void notifyChanged() { - final MapSquare<G, A, R> square = getMapSquare(); - if (square != null) { - square.getMapModel().squareChanged(square); - } - } + protected abstract void notifyChanged(); /** * {@inheritDoc} Modified: trunk/src/app/net/sf/gridarta/gui/GameObjectAttributesPanel.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/GameObjectAttributesPanel.java 2008-07-25 17:35:39 UTC (rev 4427) +++ trunk/src/app/net/sf/gridarta/gui/GameObjectAttributesPanel.java 2008-07-25 17:55:30 UTC (rev 4428) @@ -244,7 +244,11 @@ /** {@inheritDoc} */ public void mapObjectsChanged(final MapModelEvent<G, A, R> e) { - // ignore + for (final G gameObject : e.getGameObjects()) { + if (selectedGameObject == gameObject) { + refreshDisplay(); + } + } } /** {@inheritDoc} */ Modified: trunk/src/app/net/sf/gridarta/map/DefaultMapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/DefaultMapModel.java 2008-07-25 17:35:39 UTC (rev 4427) +++ trunk/src/app/net/sf/gridarta/map/DefaultMapModel.java 2008-07-25 17:55:30 UTC (rev 4428) @@ -317,6 +317,16 @@ } } + // discard changed game objects that are now out of map bounds + final Iterator<G> it2 = changedGameObjects.iterator(); + while (it2.hasNext()) { + final G gameObject = it2.next(); + final G topGameObject = gameObject.getTopContainer(); + if (topGameObject.getMapX() >= mapSize.getWidth() || topGameObject.getMapY() >= mapSize.getHeight()) { + it2.remove(); + } + } + fireMapSizeChanged(); } } @@ -362,9 +372,6 @@ } else { synchronized (changedGameObjects) { changedGameObjects.add(gameObject); - synchronized (changedSquares) { - changedSquares.add(gameObject.getMapSquare()); - } } } } @@ -401,15 +408,24 @@ if (transactionDepth == 0) { commitTransaction(); } else if (fireEvent && transactionDepth == 1) { - if (!changedGameObjects.isEmpty()) { - fireGameObjectsChangedEvent(changedGameObjects.toArray((G[]) new GameObject[changedGameObjects.size()])); - } - if (!changedSquares.isEmpty()) { - fireMapSquaresChangedEvent(changedSquares.toArray(new MapSquare[changedSquares.size()])); - } + fireEvents(); } } + /** + * Deliver all pending events. + */ + private void fireEvents() { + if (!changedGameObjects.isEmpty()) { + fireGameObjectsChangedEvent(changedGameObjects.toArray((G[]) new GameObject[changedGameObjects.size()])); + changedGameObjects.clear(); + } + if (!changedSquares.isEmpty()) { + fireMapSquaresChangedEvent(changedSquares.toArray(new MapSquare[changedSquares.size()])); + changedSquares.clear(); + } + } + /** {@inheritDoc} */ public void endAllTransactions() { if (transactionDepth > 0) { @@ -424,10 +440,7 @@ private void commitTransaction() { transactionDepth = 0; transactionThread = null; - if (!changedSquares.isEmpty()) { - fireMapSquaresChangedEvent(changedSquares.toArray(new MapSquare[changedSquares.size()])); - changedSquares.clear(); - } + fireEvents(); fireEndTransaction(); } Modified: trunk/src/app/net/sf/gridarta/map/MapModelListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapModelListener.java 2008-07-25 17:35:39 UTC (rev 4427) +++ trunk/src/app/net/sf/gridarta/map/MapModelListener.java 2008-07-25 17:55:30 UTC (rev 4428) @@ -42,9 +42,6 @@ * <li>A GameObject was removed from a MapSquare</li> * <li>A GameObject was moved up or down within a MapSquare</li> * </ul> - * Currently, this event also is fired in case of inventory items. In - * future, this event will only be fired for changes to the top level - * contents of a MapSquare. * @param e EventObject with event information */ void mapSquaresChanged(MapModelEvent<G, A, R> e); @@ -57,7 +54,6 @@ * <li>The inventory of a GameObject has changed (items added, removed or * moved)</li> * </ul> - * Currently, this event type is unused. * @param e EventObject with event information */ void mapObjectsChanged(MapModelEvent<G, A, R> e); Modified: trunk/src/app/net/sf/gridarta/map/MapSquare.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapSquare.java 2008-07-25 17:35:39 UTC (rev 4427) +++ trunk/src/app/net/sf/gridarta/map/MapSquare.java 2008-07-25 17:55:30 UTC (rev 4428) @@ -62,7 +62,6 @@ this.mapModel = mapModel; this.mapX = mapX; this.mapY = mapY; - notifyChanged(); } /** @@ -94,6 +93,12 @@ } /** {@inheritDoc} */ + @Override + protected void notifyChanged() { + mapModel.squareChanged(this); + } + + /** {@inheritDoc} */ @NotNull @Override protected MapSquare<G, A, R> clone() throws CloneNotSupportedException { Added: trunk/src/test/net/sf/gridarta/map/DefaultMapModelTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/map/DefaultMapModelTest.java (rev 0) +++ trunk/src/test/net/sf/gridarta/map/DefaultMapModelTest.java 2008-07-25 17:55:30 UTC (rev 4428) @@ -0,0 +1,977 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package test.net.sf.gridarta.map; + +import java.awt.Point; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; +import javax.swing.ImageIcon; +import javax.swing.JList; +import javax.swing.filechooser.FileFilter; +import net.sf.gridarta.AbstractMainControl; +import net.sf.gridarta.CFArchTypeList; +import net.sf.gridarta.GlobalSettings; +import net.sf.gridarta.GridartaObjectsFactory; +import net.sf.gridarta.MainControl; +import net.sf.gridarta.Size2D; +import net.sf.gridarta.gameobject.AbstractArchetypeParser; +import net.sf.gridarta.gameobject.AbstractArchetypeSet; +import net.sf.gridarta.gameobject.Archetype; +import net.sf.gridarta.gameobject.ArchetypeParser; +import net.sf.gridarta.gameobject.ArchetypeSet; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.gameobject.anim.AnimationObjects; +import net.sf.gridarta.gameobject.face.FaceObjects; +import net.sf.gridarta.gameobject.match.GameObjectMatcher; +import net.sf.gridarta.gui.GameObjectAttributesPanel; +import net.sf.gridarta.gui.MainActions; +import net.sf.gridarta.gui.MainView; +import net.sf.gridarta.gui.ObjectChooser; +import net.sf.gridarta.gui.archetypechooser.ArchetypeChooserControl; +import net.sf.gridarta.gui.map.LevelRenderer; +import net.sf.gridarta.gui.map.MapView; +import net.sf.gridarta.gui.map.MapViewBasic; +import net.sf.gridarta.gui.selectedsquare.SelectedSquareControl; +import net.sf.gridarta.gui.selectedsquare.SelectedSquareView; +import net.sf.gridarta.io.GameObjectParser; +import net.sf.gridarta.io.MapArchObjectParser; +import net.sf.gridarta.io.MapReader; +import net.sf.gridarta.map.DefaultMapControl; +import net.sf.gridarta.map.DefaultMapModel; +import net.sf.gridarta.map.InsertionMode; +import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.map.MapArchObjectListener; +import net.sf.gridarta.map.MapControl; +import net.sf.gridarta.map.MapModel; +import net.sf.gridarta.map.MapModelEvent; +import net.sf.gridarta.map.MapModelListener; +import net.sf.gridarta.map.MapSquare; +import net.sf.gridarta.spells.GameObjectSpell; +import net.sf.gridarta.spells.NumberSpell; +import net.sf.gridarta.spells.Spells; +import net.sf.japi.swing.ActionFactory; +import net.sf.japi.swing.misc.Progress; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * Test for {@link DefaultMapModel}. + * @author Andreas Kirschbaum + */ +@SuppressWarnings({"FeatureEnvy"}) +// This is a test. It has feature envy by definition. +public class DefaultMapModelTest { + + /** + * The map model listener registered to {@link #mapModel} to record map + * changes. + */ + private final MapModelListener<TestGameObject, TestMapArchObject, TestArchetype> mapModelListener = new MapModelListener<TestGameObject, TestMapArchObject, TestArchetype>() { + + /** {@inheritDoc} */ + public void mapSizeChanged(final MapModelEvent<TestGameObject, TestMapArchObject, TestArchetype> e) { + log("mapSizeChanged", e); + } + + /** {@inheritDoc} */ + public void mapSquaresChanged(final MapModelEvent<TestGameObject, TestMapArchObject, TestArchetype> e) { + log("mapSquaresChanged", e); + } + + /** {@inheritDoc} */ + public void mapObjectsChanged(final MapModelEvent<TestGameObject, TestMapArchObject, TestArchetype> e) { + log("mapObjectsChanged", e); + } + + /** {@inheritDoc} */ + public void errorsChanged(@NotNull final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel) { + result.append("errorsChanged"); + } + + /** {@inheritDoc} */ + public void mapMetaChanged(@NotNull final TestMapArchObject mapArchObject) { + result.append("mapMetaChanged"); + } + + }; + + /** + * Collects the map model changes. + */ + private final StringBuilder result = new StringBuilder(); + + /** + * The gridarta objects factory to use. + */ + private GridartaObjectsFactory<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> gridartaObjectsFactory = null; + + /** + * The map model that gets changed. + */ + private DefaultMapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = null; + + /** Test case for an empty transaction. */ + @Test + public void testEmpty() { + mapModel.beginTransaction("TEST"); + mapModel.endTransaction(); + Assert.assertEquals("", result.toString()); + } + + /** Test case for {@link DefaultMapModel#resizeMap(Size2D)}. */ + @Test + public void testResizeMap1() { + mapModel.beginTransaction("TEST"); + mapModel.resizeMap(new Size2D(4, 3)); + mapModel.endTransaction(); + Assert.assertEquals( + "mapSizeChanged:\n" + + "type SIZE_CHANGED\n" + + "no squares\n" + + "no game objects\n", + result.toString()); + } + + /** Test case for {@link DefaultMapModel#resizeMap(Size2D)}. */ + @Test + public void testResizeMap2() { + mapModel.beginTransaction("TEST"); + mapModel.resizeMap(new Size2D(4, 3)); + mapModel.endTransaction(); + + result.setLength(0); + mapModel.beginTransaction("TEST"); + mapModel.resizeMap(new Size2D(4, 3)); + mapModel.endTransaction(); + Assert.assertEquals("", result.toString()); + } + + /** Test case for {@link DefaultMapModel#resizeMap(Size2D)}. */ + @Test + public void testResizeMap3() { + mapModel.beginTransaction("TEST"); + mapModel.resizeMap(new Size2D(4, 3)); + addGameObjectToMap(mapModel, "1", 1, 2, InsertionMode.AUTO); + mapModel.endTransaction(); + + result.setLength(0); + mapModel.beginTransaction("TEST"); + addGameObjectToMap(mapModel, "1", 2, 2, InsertionMode.AUTO); + mapModel.resizeMap(new Size2D(1, 2)); // cancels square changed event + mapModel.endTransaction(); + Assert.assertEquals( + "mapSizeChanged:\n" + + "type SIZE_CHANGED\n" + + "no squares\n" + + "no game objects\n", + result.toString()); + } + + /** Test case for {@link DefaultMapModel#resizeMap(Size2D)}. */ + @Test + public void testResizeMap4() { + mapModel.beginTransaction("TEST"); + mapModel.resizeMap(new Size2D(4, 3)); + addGameObjectToMap(mapModel, "1", 1, 2, InsertionMode.AUTO); + mapModel.endTransaction(); + + result.setLength(0); + mapModel.beginTransaction("TEST"); + for (final TestGameObject gameObject : mapModel.getMapSquare(new Point(1, 2))) { + gameObject.setAttributeString("key", "value"); + } + addGameObjectToMap(mapModel, "1", 2, 2, InsertionMode.AUTO); + mapModel.resizeMap(new Size2D(1, 2)); // cancels square changed event + mapModel.endTransaction(); + Assert.assertEquals( + "mapSizeChanged:\n" + + "type SIZE_CHANGED\n" + + "no squares\n" + + "no game objects\n", + result.toString()); + } + + /** Test case for {@link DefaultMapModel#addGameObjectToMap(GameObject, InsertionMode)}. */ + @Test + public void testAddGameObjectToMap1() { + mapModel.beginTransaction("TEST"); + mapModel.resizeMap(new Size2D(4, 3)); + mapModel.endTransaction(); + + result.setLength(0); + mapModel.beginTransaction("TEST"); + addGameObjectToMap(mapModel, "1", 1, 2, InsertionMode.AUTO); + mapModel.endTransaction(); + Assert.assertEquals( + "mapSquaresChanged:\n" + + "type SQUARES_CHANGED\n" + + "square 1 2\n" + + "no game objects\n", + result.toString()); + } + + /** Test case for {@link DefaultMapModel#addGameObjectToMap(GameObject, InsertionMode)}. */ + @Test + public void testAddGameObjectToMap2() { + mapModel.beginTransaction("TEST"); + mapModel.resizeMap(new Size2D(4, 3)); + mapModel.endTransaction(); + + result.setLength(0); + mapModel.beginTransaction("TEST"); + addGameObjectToMap(mapModel, "1", 1, 2, InsertionMode.AUTO); + addGameObjectToMap(mapModel, "1", 1, 2, InsertionMode.AUTO); + addGameObjectToMap(mapModel, "1", 2, 2, InsertionMode.AUTO); + mapModel.endTransaction(); + Assert.assertEquals( + "mapSquaresChanged:\n" + + "type SQUARES_CHANGED\n" + + "square 1 2\n" + + "square 2 2\n" + + "no game objects\n", + result.toString()); + } + + /** Test case for changed objects. */ + @Test + public void testModifiedGameObject1() { + mapModel.beginTransaction("TEST"); + mapModel.resizeMap(new Size2D(4, 3)); + addGameObjectToMap(mapModel, "1", 1, 2, InsertionMode.AUTO); + mapModel.endTransaction(); + + result.setLength(0); + mapModel.beginTransaction("TEST"); + for (final TestGameObject gameObject : mapModel.getMapSquare(new Point(1, 2))) { + insertGameObject(gameObject, "2"); + } + mapModel.endTransaction(); + Assert.assertEquals( + "mapObjectsChanged:\n" + + "type GAMEOBJECTS_CHANGED\n" + + "no squares\n" + + "game object 1 2 1\n", + result.toString()); + } + + /** Test case for changed objects. */ + @Test + public void testModifiedGameObject2() { + mapModel.beginTransaction("TEST"); + mapModel.resizeMap(new Size2D(4, 3)); + addGameObjectToMap(mapModel, "1", 1, 2, InsertionMode.AUTO); + mapModel.endTransaction(); + + result.setLength(0); + mapModel.beginTransaction("TEST"); + for (final TestGameObject gameObject : mapModel.getMapSquare(new Point(1, 2))) { + gameObject.setAttributeString("key", "value"); + } + mapModel.endTransaction(); + Assert.assertEquals( + "mapObjectsChanged:\n" + + "type GAMEOBJECTS_CHANGED\n" + + "no squares\n" + + "game object 1 2 1\n", + result.toString()); + } + + /** + * Inserts a game object into a map. + * @param mapModel the map to add to + * @param name the name of the game object to add + * @param x the x coordinate to add to + * @param y the y coordinate to add to + * @param insertionMode the insertion mode to use + */ + private void addGameObjectToMap(final DefaultMapModel mapModel, final String name, final int x, final int y, final InsertionMode insertionMode) { + final TestGameObject gameObject = newGameObject(name); + gameObject.setMapX(x); + gameObject.setMapY(y); + mapModel.addGameObjectToMap(gameObject, insertionMode); + } + + /** + * Inserts a game object into the inventory of another game object. + * @param gameObject the game object to add to + * @param name the name of the game object to add + */ + private void insertGameObject(final TestGameObject gameObject, final String name) { + final TestGameObject inv = newGameObject(name); + gameObject.addLast(inv); + } + + /** + * Creates a new game object. + * @param objectName the object name to set + * @return the game object + */ + private TestGameObject newGameObject(final String objectName) { + final TestGameObject gameObject = gridartaObjectsFactory.newGameObject(); + gameObject.getArchetype().setObjName(objectName); + return gameObject; + } + + /** + * Records a change event. + * @param name the event name + * @param e the event details + */ + private void log(final String name, final MapModelEvent<TestGameObject, TestMapArchObject, TestArchetype> e) { + result.append(name); + result.append(":\n"); + result.append("type "); + result.append(e.getType()); + result.append("\n"); + final MapSquare<TestGameObject, TestMapArchObject, TestArchetype>[] mapSquares = e.getSquares(); + if (mapSquares != null) { + final SortedSet<String> lines = new TreeSet<String>(); + for (final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare : mapSquares) { + lines.add("square " + mapSquare.getMapX() + " " + mapSquare.getMapY() + "\n"); + } + for (final String line : lines) { + result.append(line); + } + } else { + result.append("no squares\n"); + } + final GameObject<TestGameObject, TestMapArchObject, TestArchetype>[] gameObjects = e.getGameObjects(); + if (gameObjects != null) { + final SortedSet<String> lines = new TreeSet<String>(); + for (final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject : gameObjects) { + lines.add("game object " + gameObject.getMapX() + " " + gameObject.getMapY() + " " + gameObject.getBestName() + "\n"); + } + for (final String line : lines) { + result.append(line); + } + } else { + result.append("no game objects\n"); + } + } + + /** + * Sets up a test. + */ + @Before + public void setUp() { + final ActionFactory actionFactory = ActionFactory.getFactory("test"); + gridartaObjectsFactory = new TestGridartaObjectsFactory(); + final TestMainControl mainControl = new TestMainControl(gridartaObjectsFactory, "test"); + final ArchetypeSet<TestGameObject, TestMapArchObject, TestArchetype> archetypeSet = new TestArchetypeSet(gridartaObjectsFactory); + final SelectedSquareControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> selectedSquareControl = new SelectedSquareControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic>(actionFactory, mainControl, true, null, archetypeSet); + final TestMapArchObject mapArchObject = new TestMapArchObject(); + final ArchetypeChooserControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> archetypeChooserControl = new ArchetypeChooserControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic>(mainControl, false); + final TestMapControl mapControl = new TestMapControl(gridartaObjectsFactory, mainControl, null, mapArchObject, false, null, archetypeChooserControl, selectedSquareControl.getSelectedSquareView()); + mapModel = new DefaultMapModel<TestGameObject, TestMapArchObject, TestArchetype>(mainControl, mapControl, null, mapArchObject, null, archetypeChooserControl); + + result.setLength(0); + mapModel.addMapModelListener(mapModelListener); + Assert.assertEquals("", result.toString()); + } + + /** + * A {@link MainControl} implementation for testing purposes. + */ + private static class TestMainControl extends AbstractMainControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> { + + /** + * Creates a new instance. + * @param gridartaObjectsFactory the gridaarta objects factory to use + * @param key the action factory key to use + */ + protected TestMainControl(@NotNull final GridartaObjectsFactory<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> gridartaObjectsFactory, @NotNull final String key) { + super(gridartaObjectsFactory, key); + } + + /** {@inheritDoc} */ + public GlobalSettings getGlobalSettings() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public FileFilter getScriptFileFilter() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public String getScriptSuffix() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public ArchetypeSet<TestGameObject, TestMapArchObject, TestArchetype> getArchetypeSet() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public ArchetypeParser<TestGameObject, TestMapArchObject, TestArchetype> getArchetypeParser() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public AnimationObjects<?> getAnimationObjects() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public MainView<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> getMainView() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public MapView<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> getCurrentMapView() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public boolean saveLevelAsWanted(@NotNull final MapControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> testGameObjectTestMapArchObjectTestArchetypeTestMapViewBasicMapControl) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void revert(@NotNull final MapControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> testGameObjectTestMapArchObjectTestArchetypeTestMapViewBasicMapControl) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void exit() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public String getConfigurationDirectory() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public String getCollectedDirectory() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public CFArchTypeList getTypeList() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public Spells<NumberSpell> getNumberSpells() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public Spells<GameObjectSpell<TestGameObject, TestMapArchObject, TestArchetype>> getGameObjectSpells() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void doExit() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void openAttrDialog(final TestGameObject gameObject) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void validateMap(final MapModel<TestGameObject, TestMapArchObject, TestArchetype> map) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void reloadFaces() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public boolean isAutoJoin() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public ObjectChooser<TestGameObject, TestMapArchObject, TestArchetype> getObjectChooser() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public MainActions<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> getMainActions() { + throw new AssertionError(); + } + } + + /** + * A {@link MapControl} implementation for testing purposes. + */ + private static class TestMapControl extends DefaultMapControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> { + + /** + * Creates a new instance + * @param gridartaObjectsFactory the gridarta objects factory to use + * @param mainControl the main control + * @param objects the objects to insert + * @param mapArchObject the map arch object to use + * @param isPickmap whether this map control is a pickmap + * @param exitTypeGameObjectMatcher the exit matcher to use + * @param archetypeChooserControl the archetype chooser control to use + * @param selectedSquareView the selected square view to use + */ + public TestMapControl(@NotNull final GridartaObjectsFactory<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> gridartaObjectsFactory, @NotNull final MainControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> mainControl, @Nullable final List<TestGameObject> objects, @NotNull final TestMapArchObject mapArchObject, final boolean isPickmap, @Nullable final GameObjectMatcher exitTypeGameObjectMatcher, @NotNull final ArchetypeChooserControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> archetypeChooserControl, @NotNull final SelectedSquareView<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> selectedSquareView) { + super(gridartaObjectsFactory, mainControl, objects, mapArchObject, isPickmap, exitTypeGameObjectMatcher, archetypeChooserControl, selectedSquareView); + } + + } + + /** + * A {@link MapArchObject} implementation for testing purposes. + */ + private static class TestMapArchObject implements MapArchObject<TestMapArchObject> { + + /** + * The current map size. + */ + private Size2D mapSize = Size2D.ONE; + + /** {@inheritDoc} */ + public void setState(@NotNull final TestMapArchObject mapArchObject) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public String getMapDisplayName() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setMapSize(@NotNull final Size2D mapSize) { + this.mapSize = mapSize; + } + + /** {@inheritDoc} */ + @NotNull + public Size2D getMapSize() { + return mapSize; + } + + /** {@inheritDoc} */ + @NotNull + public String getMapName() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setMapName(@NotNull final String name) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public int getEnterX() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setEnterX(final int enterX) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public int getEnterY() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setEnterY(final int enterY) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public boolean isOutdoor() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setOutdoor(final boolean outdoor) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public int getResetTimeout() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setResetTimeout(final int resetTimeout) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public int getSwapTime() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setSwapTime(final int swapTime) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public int getDifficulty() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setDifficulty(final int difficulty) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public boolean isFixedReset() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setFixedReset(final boolean fixedReset) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public int getDarkness() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setDarkness(final int darkness) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public int getTilePaths() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public String getTilePath(final int direction) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setTilePath(final int direction, @NotNull final String tilePath) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public TestMapArchObject createClone() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void addMapArchObjectListener(@NotNull final MapArchObjectListener<TestMapArchObject> mapArchObjectListener) { + // ignore + } + + /** {@inheritDoc} */ + public void removeMapArchObjectListener(@NotNull final MapArchObjectListener<TestMapArchObject> mapArchObjectListener) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void resetModified() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void beginTransaction() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void endTransaction() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void endTransaction(final boolean fireEvent) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void addText(@NotNull final String text) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setText(final String text) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public String getText() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void updateModifiedAttribute() { + throw new AssertionError(); + } + + } + + /** + * A {@link MapViewBasic} implementation for testing purposes. + */ + private static class TestMapViewBasic extends MapViewBasic<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> { + + /** + * Creates a new instance. + * @param mapControl the map control + * @param initial the initial view position + * @param xScrollDistance the x scroll distance + * @param yScrollDistance the y scroll distance + * @param selectedSquareView the selected square view to use + */ + protected TestMapViewBasic(@NotNull final MapControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> mapControl, @Nullable final Point initial, final int xScrollDistance, final int yScrollDistance, @NotNull final SelectedSquareView<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> selectedSquareView) { + super(mapControl, initial, xScrollDistance, yScrollDistance, selectedSquareView); + } + + /** {@inheritDoc} */ + public void init(@NotNull final MapView mapView) { + throw new AssertionError(); + } + + } + + /** + * A {@link GameObject} implementation for testing purposes. + */ + private static class TestGameObject extends GameObject<TestGameObject, TestMapArchObject, TestArchetype> { + + /** The serial version UID. */ + private static final long serialVersionUID = 1; + + /** {@inheritDoc} */ + public TestGameObject createGameObject() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public boolean isMulti() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setAnimName(@Nullable final String animName) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public String getAnimName() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public boolean usesDirection() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void setObjectFace() { + // ignore + } + + /** {@inheritDoc} */ + public void setRealFace(@Nullable final String name) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public TestGameObject createClone(final int posx, final int posy) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public TestGameObject createMultiClone(final int posx, final int posy) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void propagateElevation(final TestGameObject gameObject) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void addEventsToJList(@NotNull final JList list) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public boolean isScripted() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void modifyEventScript(final int eventType, final int task, @NotNull final JList eventList, @NotNull final GameObjectAttributesPanel<TestGameObject, TestMapArchObject, TestArchetype, ?> mapanel) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void addEventScript(@NotNull final JList eventList, @NotNull final GameObjectAttributesPanel<TestGameObject, TestMapArchObject, TestArchetype, ?> mapanel) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void postParseGameObject(final int editType) { + throw new AssertionError(); + } + + } + + /** + * An {@link Archetype} implementation for testing purposes. + */ + private static class TestArchetype extends TestGameObject { + + /** + * The serial version UID. + */ + private static final long serialVersionUID = 1; + } + + /** + * An {@link GridartaObjectsFactory} implementation for testing purposes. + */ + private static class TestGridartaObjectsFactory implements GridartaObjectsFactory<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> { + + /** {@inheritDoc} */ + @NotNull + public TestMapArchObject newMapArchObject(final boolean addDefaultAttributes) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public TestGameObject newGameObject() { + final TestGameObject gameObject = new TestGameObject(); + gameObject.setArchetype(new TestArchetype()); + return gameObject; + } + + /** {@inheritDoc} */ + @NotNull + public MapReader<TestGameObject, TestMapArchObject> newMapReader(@NotNull final File file) throws FileNotFoundException { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public TestArchetype newUndefinedArchetype(@NotNull final String archetypeName) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public MapArchObjectParser<TestMapArchObject> newMapArchObjectParser() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public GameObjectParser<TestGameObject, TestMapArchObject, TestArchetype> newGameObjectParser() { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public MapControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> newMapControl(@Nullable final List<TestGameObject> objects, @NotNull final TestMapArchObject mapArchObject) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public MapControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> newPickmapControl(@Nullable final List<TestGameObject> objects, @NotNull final TestMapArchObject mapArchObject) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public LevelRenderer newSimpleLevelRenderer(@NotNull final MapModel<TestGameObject, TestMapArchObject, TestArchetype> testGameObjectTestMapArchObjectTestArchetypeMapModel, @NotNull final ArchetypeSet<TestGameObject, TestMapArchObject, TestArchetype> testGameObjectTestMapArchObjectTestArchetypeArchetypeSet) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public MapView<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> newMapView(@NotNull final MapControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> testGameObjectTestMapArchObjectTestArchetypeTestMapViewBasicMapControl, @Nullable final Point viewPosition, final int viewCounter) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void init(@NotNull final FaceObjects faceObjects, @NotNull final ObjectChooser<TestGameObject, TestMapArchObject, TestArchetype> testGameObjectTestMapArchObjectTestArchetypeObjectChooser, @NotNull final ArchetypeChooserControl<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> testGameObjectTestMapArchObjectTestArchetypeTestMapViewBasicArchetypeChooserControl, @NotNull final SelectedSquareView<TestGameObject, TestMapArchObject, TestArchetype, TestMapViewBasic> testGameObjectTestMapArchObjectTestArchetypeTestMapViewBasicSelectedSquareView) { + throw new AssertionError(); + } + } + + /** + * An {@link ArchetypeSet} implementation for testing purposes. + */ + private static class TestArchetypeSet extends AbstractArchetypeSet<TestGameObject, TestMapArchObject, TestArchetype> { + + /** + * Creates a new instance. + * @param gridartaObjectsFactory the gridarta objects factory to use + */ + private TestArchetypeSet(@NotNull final GridartaObjectsFactory<TestGameObject, TestMapArchObject, TestArchetype, ?> gridartaObjectsFactory) { + super(gridartaObjectsFactory); + } + + /** {@inheritDoc} */ + public void loadArchetypes(@NotNull final AbstractArchetypeParser<TestGameObject, TestMapArchObject, TestArchetype> testGameObjectTestMapArchObjectTestArchetypeAbstractArchetypeParser) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public ImageIcon getFace(@NotNull final TestArchetype archetype) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + @NotNull + public ImageIcon getFace(@NotNull final TestGameObject gameObject) { + throw new AssertionError(); + } + + /** {@inheritDoc} */ + public void collect(@NotNull final Progress progress, @NotNull final File dir) throws IOException { + throw new AssertionError(); + } + + } + +} // class DefaultMapModelTest Property changes on: trunk/src/test/net/sf/gridarta/map/DefaultMapModelTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |