Gridarta Editor
MapModel.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.mapmodel;
21 
22 import java.awt.Point;
23 import java.io.Serializable;
24 import java.util.List;
30 import org.jetbrains.annotations.NotNull;
31 import org.jetbrains.annotations.Nullable;
32 
75 public interface MapModel<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends Iterable<MapSquare<G, A, R>>, Serializable {
76 
80  void mapClosed();
81 
86  void clearMap();
87 
93  boolean isEmpty();
94 
99  @NotNull
100  A getMapArchObject();
101 
106  void addMapModelListener(@NotNull MapModelListener<G, A, R> listener);
107 
112  void removeMapModelListener(@NotNull MapModelListener<G, A, R> listener);
113 
119 
125 
130  void beginSquareChange(@NotNull MapSquare<G, A, R> mapSquare);
131 
139  void endSquareChange(@NotNull MapSquare<G, A, R> mapSquare);
140 
145  void beginGameObjectChange(@NotNull G gameObject);
146 
154  void endGameObjectChange(@NotNull G gameObject);
155 
163  void transientGameObjectChange(@NotNull G gameObject);
164 
183  void beginTransaction(@NotNull String name);
184 
201  void endTransaction();
202 
229  void endTransaction(boolean fireEvent);
230 
242  void endAllTransactions();
243 
256  int getTransactionDepth();
257 
270  boolean isAnyTransactionActive();
271 
279  @NotNull
280  MapSquare<G, A, R> getMapSquare(@NotNull Point pos);
281 
286  void addObjectListToMap(@NotNull Iterable<G> objects);
287 
297  void addGameObjectToMap(@NotNull G gameObject, @NotNull Point pos, @NotNull InsertionMode<G, A, R> insertionMode);
298 
305  void moveEnv(@NotNull G gameObject, @NotNull Point pos, @NotNull G nextGameObject);
306 
312  void moveInv(@NotNull G gameObject, @NotNull GameObject<G, A, R> prevGameObject);
313 
326  @Nullable
327  G insertBaseObject(@NotNull BaseObject<G, A, R, ?> baseObject, @NotNull Point pos, boolean allowMany, boolean join, @NotNull InsertionMode<G, A, R> insertionMode);
328 
341  @Nullable
342  G insertArchToMap(@NotNull BaseObject<G, A, R, ?> templateBaseObject, @Nullable G nextGameObject, @NotNull Point pos, boolean join);
343 
349  void removeGameObject(@NotNull G gameObject, boolean join);
350 
362  boolean isMultiArchFittingToMap(@NotNull Archetype<G, A, R> archetype, @NotNull Point pos, boolean allowDouble);
363 
368  void setErrors(@NotNull ErrorCollector<G, A, R> errors);
369 
374  @NotNull
376 
385  boolean isAreaEmpty(int left, int top, int width, int height);
386 
393  void addActiveEditType(int editType);
394 
400  void setMapFile(@Nullable MapFile mapFile);
401 
406  @Nullable
408 
419  @NotNull
421 
427  @NotNull
428  List<G> getAllGameObjects();
429 
434  boolean isModified();
435 
439  void resetModified();
440 
444  void facesReloaded();
445 
451  void nextPoint(Point point, int direction);
452 
453 }
int getTransactionDepth()
Get the transaction depth, which is the number of beginTransaction(String) invocations without matchi...
boolean isMultiArchFittingToMap(@NotNull Archetype< G, A, R > archetype, @NotNull Point pos, boolean allowDouble)
Checks whether an GameObject (multi-arch) would still fit on this map.
void removeMapTransactionListener(@NotNull MapTransactionListener< G, A, R > listener)
Unregisters a map transaction listener.
Exception thrown if the destination path points to the source map.
void addActiveEditType(int editType)
Add edit type to the bitmask of active types.
A MapModel reflects the data of a map.
Definition: MapModel.java:75
void setErrors(@NotNull ErrorCollector< G, A, R > errors)
Sets the errors in this map.
This package contains the framework for validating maps.
void endTransaction()
End a transaction.
void transientGameObjectChange(@NotNull G gameObject)
Method to notify the model that a game object was changed but need not be restored by undo/redo...
void endSquareChange(@NotNull MapSquare< G, A, R > mapSquare)
Method to notify the model that a map square was changed.
void removeGameObject(@NotNull G gameObject, boolean join)
Delete an existing GameObject from the map.
void nextPoint(Point point, int direction)
Moves the given point forward or backward one map square.
boolean isModified()
Return whether the map has been modified from the on-disk state.
Represents a maps directory local map path.
Definition: MapPath.java:31
void clearMap()
Clears this map completely.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
G insertBaseObject(@NotNull BaseObject< G, A, R, ?> baseObject, @NotNull Point pos, boolean allowMany, boolean join, @NotNull InsertionMode< G, A, R > insertionMode)
Inserts a BaseObject to a map.
Base package of all Gridarta classes.
void addGameObjectToMap(@NotNull G gameObject, @NotNull Point pos, @NotNull InsertionMode< G, A, R > insertionMode)
Add a gameObject to the map.
Reflects a game object (object on a map).
Definition: GameObject.java:36
void addMapTransactionListener(@NotNull MapTransactionListener< G, A, R > listener)
Registers a map transaction listener.
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.
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.
void addObjectListToMap(@NotNull Iterable< G > objects)
Adds a list of GameObjects to this map.
void moveInv(@NotNull G gameObject, @NotNull GameObject< G, A, R > prevGameObject)
Moves a GameObject to the inventory of another game object.
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
void beginSquareChange(@NotNull MapSquare< G, A, R > mapSquare)
Method to notify the model that a map square is about to change.
void mapClosed()
This function must be called if this instance is freed.
void moveEnv(@NotNull G gameObject, @NotNull Point pos, @NotNull G nextGameObject)
Moves a GameObject to its environment.
void endAllTransactions()
Ends all transaction.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
Exception thrown if an operation is attempted on an unsaved map.
void resetModified()
Resets the modified flag to false.
MapFile getMapFile()
Returns the map file.
void beginGameObjectChange(@NotNull G gameObject)
Method to notify the model that a game object is about to change.
An interface for classes that collect errors.
void endGameObjectChange(@NotNull G gameObject)
Method to notify the model that a game object was changed.
boolean isAreaEmpty(int left, int top, int width, int height)
Checks whether an area of a map is completely empty.
boolean isAnyTransactionActive()
Returns whether a transaction is currently active.
boolean isEmpty()
Returns whether the map is empty.
void beginTransaction(@NotNull String name)
Starts a new transaction.
void setMapFile(@Nullable MapFile mapFile)
Sets the map file.
ErrorCollector< G, A, R > getErrors()
Gets the errors in this map.
List< G > getAllGameObjects()
Returns all game objects.
void facesReloaded()
Will be called whenever the archetype faces have been reloaded.
The location of a map file with a map directory.
Definition: MapFile.java:31