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-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.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 prependMapModelListener(@NotNull MapModelListener<G, A, R> listener);
113 
118  void removeMapModelListener(@NotNull MapModelListener<G, A, R> listener);
119 
125 
131 
136  void beginSquareChange(@NotNull MapSquare<G, A, R> mapSquare);
137 
145  void endSquareChange(@NotNull MapSquare<G, A, R> mapSquare);
146 
151  void beginGameObjectChange(@NotNull G gameObject);
152 
160  void endGameObjectChange(@NotNull G gameObject);
161 
169  void transientGameObjectChange(@NotNull G gameObject);
170 
189  void beginTransaction(@NotNull String name);
190 
207  void endTransaction();
208 
235  void endTransaction(boolean fireEvent);
236 
248  void endAllTransactions();
249 
262  int getTransactionDepth();
263 
276  boolean isAnyTransactionActive();
277 
285  @NotNull
286  MapSquare<G, A, R> getMapSquare(@NotNull Point pos);
287 
292  void addObjectListToMap(@NotNull Iterable<G> objects);
293 
303  void addGameObjectToMap(@NotNull G gameObject, @NotNull Point pos, @NotNull InsertionMode insertionMode);
304 
311  void moveEnv(@NotNull G gameObject, @NotNull Point pos, @NotNull G nextGameObject);
312 
318  void moveInv(@NotNull G gameObject, @NotNull GameObject<G, A, R> prevGameObject);
319 
332  @Nullable
333  G insertBaseObject(@NotNull BaseObject<G, A, R, ?> baseObject, @NotNull Point pos, boolean allowMany, boolean join, @NotNull InsertionMode insertionMode);
334 
347  @Nullable
348  G insertArchToMap(@NotNull BaseObject<G, A, R, ?> templateBaseObject, @Nullable G nextGameObject, @NotNull Point pos, boolean join);
349 
355  void removeGameObject(@NotNull G gameObject, boolean join);
356 
368  boolean isMultiArchFittingToMap(@NotNull Archetype<G, A, R> archetype, @NotNull Point pos, boolean allowDouble);
369 
375 
380  @NotNull
382 
391  boolean isAreaEmpty(int left, int top, int width, int height);
392 
399  void addActiveEditType(int editType);
400 
406  void setMapFile(@Nullable MapFile mapFile);
407 
412  @Nullable
414 
425  @NotNull
427 
433  @NotNull
434  List<G> getAllGameObjects();
435 
440  boolean isModified();
441 
445  void resetModified();
446 
450  void facesReloaded();
451 
457  void nextPoint(Point point, int direction);
458 
459 }
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.
name
name
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:2
net.sf.gridarta.model.mapmodel.MapModel.setErrors
void setErrors(@NotNull ErrorCollector< G, A, R > errors)
Sets the errors in this map.
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta.model.mapmodel.SameMapException
Exception thrown if the destination path points to the source map.
Definition: SameMapException.java:26
net.sf.gridarta.model.mapmodel.MapModel.getTransactionDepth
int getTransactionDepth()
Get the transaction depth, which is the number of {} invocations without matching { #endTransaction()...
net.sf.gridarta.model.mapmodel.MapModel.nextPoint
void nextPoint(Point point, int direction)
Moves the given point forward or backward one map square.
net.sf.gridarta.model.mapmodel.MapModel.getMapArchObject
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
net.sf.gridarta.model.mapmodel.MapModel.insertBaseObject
G insertBaseObject(@NotNull BaseObject< G, A, R, ?> baseObject, @NotNull Point pos, boolean allowMany, boolean join, @NotNull InsertionMode insertionMode)
Inserts a BaseObject to a map.
net.sf.gridarta.model.mapmodel.MapModel.isAnyTransactionActive
boolean isAnyTransactionActive()
Returns whether a transaction is currently active.
net.sf.gridarta.model.mapmodel.MapModel.resetModified
void resetModified()
Resets the modified flag to false.
net.sf.gridarta.model.mapmodel.MapModel.isEmpty
boolean isEmpty()
Returns whether the map is empty.
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.mapmodel.MapModel.transientGameObjectChange
void transientGameObjectChange(@NotNull G gameObject)
Method to notify the model that a game object was changed but need not be restored by undo/redo.
net.sf.gridarta.model.mapmodel.MapSquare< G, A, R >
net.sf.gridarta.model.mapmodel.MapModel.endTransaction
void endTransaction()
End a transaction.
net.sf.gridarta.model.mapmodel.MapTransactionListener< G, A, R >
net.sf
net.sf.gridarta.model.mapmodel.MapModel.beginTransaction
void beginTransaction(@NotNull String name)
Starts a new transaction.
net.sf.gridarta.model.mapmodel.MapModel.beginSquareChange
void beginSquareChange(@NotNull MapSquare< G, A, R > mapSquare)
Method to notify the model that a map square is about to change.
net.sf.gridarta.model.mapmodel.MapModel.isMultiArchFittingToMap
boolean isMultiArchFittingToMap(@NotNull Archetype< G, A, R > archetype, @NotNull Point pos, boolean allowDouble)
Checks whether a GameObject (multi-arch) would still fit on this map.
net.sf.gridarta.model.mapmodel.MapModel.endAllTransactions
void endAllTransactions()
Ends all transaction.
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.mapmodel.MapModel.moveInv
void moveInv(@NotNull G gameObject, @NotNull GameObject< G, A, R > prevGameObject)
Moves a GameObject to the inventory of another game object.
net.sf.gridarta.model.mapmodel.MapModel.facesReloaded
void facesReloaded()
Will be called whenever the archetype faces have been reloaded.
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.model.mapmodel.MapModel.addGameObjectToMap
void addGameObjectToMap(@NotNull G gameObject, @NotNull Point pos, @NotNull InsertionMode insertionMode)
Add a gameObject to the map.
net.sf.gridarta.model.mapmodel.MapModel.addMapModelListener
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
net.sf.gridarta.model.mapmodel.MapModel.isModified
boolean isModified()
Return whether the map has been modified from the on-disk state.
net.sf.gridarta.model.mapmodel.MapModel.endSquareChange
void endSquareChange(@NotNull MapSquare< G, A, R > mapSquare)
Method to notify the model that a map square was changed.
net.sf.gridarta.model.mapmodel.MapModel.getErrors
ErrorCollector< G, A, R > getErrors()
Gets the errors in this map.
net.sf.gridarta.model.mapmodel.MapModel.beginGameObjectChange
void beginGameObjectChange(@NotNull G gameObject)
Method to notify the model that a game object is about to change.
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
errors
errors
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:1
net.sf.gridarta.model.mapmodel.MapModel.removeMapModelListener
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.model.mapmodel.MapModel.removeGameObject
void removeGameObject(@NotNull G gameObject, boolean join)
Delete an existing GameObject from the map.
net.sf.gridarta.model.mapmodel.MapModel.mapClosed
void mapClosed()
This function must be called if this instance is freed.
net.sf.gridarta.model.mapmodel.MapModel.removeMapTransactionListener
void removeMapTransactionListener(@NotNull MapTransactionListener< G, A, R > listener)
Unregisters a map transaction listener.
net.sf.gridarta.model.validation.ErrorCollector
An interface for classes that collect errors.
Definition: ErrorCollector.java:33
net.sf.gridarta.model.mapmodel.MapPath
Represents a maps directory local map path.
Definition: MapPath.java:31
net.sf.gridarta.model.mapmodel.UnsavedMapException
Exception thrown if an operation is attempted on an unsaved map.
Definition: UnsavedMapException.java:26
net.sf.gridarta.model.mapmodel.MapModel.moveEnv
void moveEnv(@NotNull G gameObject, @NotNull Point pos, @NotNull G nextGameObject)
Moves a GameObject to its environment.
net.sf.gridarta.model.validation
This package contains the framework for validating maps.
Definition: AbstractValidator.java:20
net.sf.gridarta.model.mapmodel.InsertionMode
Insertion modes.
Definition: InsertionMode.java:33
net.sf.gridarta.model.baseobject.BaseObject
Definition: BaseObject.java:34
net.sf.gridarta.model.mapmodel.MapFile
The location of a map file with a map directory.
Definition: MapFile.java:31
net.sf.gridarta.model.mapmodel.MapModel.addMapTransactionListener
void addMapTransactionListener(@NotNull MapTransactionListener< G, A, R > listener)
Registers a map transaction listener.
net.sf.gridarta.model.mapmodel.MapModelListener< G, A, R >
net.sf.gridarta.model.mapmodel.MapModel.getMapSquare
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
net.sf.gridarta.model.mapmodel.MapModel.addActiveEditType
void addActiveEditType(int editType)
Add edit type to the bitmask of active types.
net.sf.gridarta.model.mapmodel.MapModel.endGameObjectChange
void endGameObjectChange(@NotNull G gameObject)
Method to notify the model that a game object was changed.
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.model.mapmodel.MapModel.setMapFile
void setMapFile(@Nullable MapFile mapFile)
Sets the map file.
net.sf.gridarta.model.mapmodel.MapModel.prependMapModelListener
void prependMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener and call it before all other listeners.
net.sf.gridarta.model.mapmodel.MapModel.clearMap
void clearMap()
Clears this map completely.
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.mapmodel.MapModel.getMapFile
MapFile getMapFile()
Returns the map file.
net.sf.gridarta.model.mapmodel.MapModel.addObjectListToMap
void addObjectListToMap(@NotNull Iterable< G > objects)
Adds a list of GameObjects to this map.
net.sf.gridarta.model.mapmodel.MapModel.isAreaEmpty
boolean isAreaEmpty(int left, int top, int width, int height)
Checks whether an area of a map is completely empty.
net.sf.gridarta.model.mapmodel.MapModel.getAllGameObjects
List< G > getAllGameObjects()
Returns all game objects.