public class DefaultMapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>> extends java.lang.Object implements MapModel<G,A,R>
MapModel that covers the similarities between
crossfire and daimonin. The transaction system is not implemented in a way
that supports overriding its method for change. Therefore all methods
belonging to the transaction system are final.| Constructor and Description |
|---|
DefaultMapModel(@NotNull AutojoinLists<G,A,R> autojoinLists,
A mapArchObject,
@NotNull ArchetypeChooserModel<G,A,R> archetypeChooserModel,
@NotNull GameObjectFactory<G,A,R> gameObjectFactory,
@NotNull GameObjectMatchers gameObjectMatchers,
@NotNull InsertionMode topmostInsertionMode)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addActiveEditType(int editType)
Add edit type to the bitmask of active types.
|
void |
addGameObjectToMap(G gameObject,
@NotNull java.awt.Point pos,
@NotNull InsertionMode insertionMode)
Add a gameObject to the map.
|
void |
addMapModelListener(@NotNull MapModelListener<G,A,R> listener)
Register a map listener.
|
void |
addMapTransactionListener(@NotNull MapTransactionListener<G,A,R> listener)
Registers a map transaction listener.
|
void |
addObjectListToMap(@NotNull java.lang.Iterable<G> objects)
Adds a list of
GameObjects to this map. |
void |
beginGameObjectChange(G gameObject)
Method to notify the model that a game object is about to change.
|
void |
beginSquareChange(@NotNull MapSquare<G,A,R> mapSquare)
Method to notify the model that a map square is about to change.
|
void |
beginTransaction(@NotNull java.lang.String name)
Starts a new transaction.
|
void |
clearMap()
Clears this map completely.
|
void |
endAllTransactions()
Ends all transaction.
|
void |
endGameObjectChange(G gameObject)
Method to notify the model that a game object was changed.
|
void |
endSquareChange(@NotNull MapSquare<G,A,R> mapSquare)
Method to notify the model that a map square was changed.
|
void |
endTransaction()
End a transaction.
|
void |
endTransaction(boolean fireEvent)
End a transaction.
|
void |
facesReloaded()
Will be called whenever the archetype faces have been reloaded.
|
@NotNull java.util.List<G> |
getAllGameObjects()
Returns all game objects.
|
@NotNull ErrorCollector<G,A,R> |
getErrors()
Gets the errors in this map.
|
A |
getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
|
@Nullable MapFile |
getMapFile()
Returns the map file.
|
@NotNull MapFile |
getMapFile(@NotNull MapPath mapPath)
Returns the map file for a map that can be reached by following a
MapPath from this map. |
@NotNull MapSquare<G,A,R> |
getMapSquare(@NotNull java.awt.Point pos)
Get the square at a specified location.
|
int |
getTransactionDepth()
Get the transaction depth, which is the number of
MapModel.beginTransaction(String) invocations without matching MapModel.endTransaction() invocations. |
G |
insertArchToMap(@NotNull BaseObject<G,A,R,?> templateBaseObject,
G nextGameObject,
@NotNull java.awt.Point pos,
boolean join)
Insert a game object to the map at a specified position.
|
G |
insertBaseObject(@NotNull BaseObject<G,A,R,?> baseObject,
@NotNull java.awt.Point pos,
boolean allowMany,
boolean join,
@NotNull InsertionMode insertionMode)
Inserts a
BaseObject to a map. |
boolean |
isAnyTransactionActive()
Returns whether a transaction is currently active.
|
boolean |
isAreaEmpty(int left,
int top,
int width,
int height)
Checks whether an area of a map is completely empty.
|
boolean |
isEmpty()
Returns whether the map is empty.
|
boolean |
isModified()
Return whether the map has been modified from the on-disk state.
|
boolean |
isMultiArchFittingToMap(@NotNull Archetype<G,A,R> archetype,
@NotNull java.awt.Point pos,
boolean allowDouble)
Checks whether a GameObject (multi-arch) would still fit on this map.
|
java.util.Iterator<MapSquare<G,A,R>> |
iterator() |
void |
mapClosed()
This function must be called if this instance is freed.
|
void |
moveEnv(G gameObject,
@NotNull java.awt.Point pos,
G nextGameObject)
Moves a
GameObject to its environment. |
void |
moveInv(G gameObject,
@NotNull GameObject<G,A,R> prevGameObject)
Moves a
GameObject to the inventory of another game object. |
void |
nextPoint(java.awt.Point point,
int direction)
Moves the given point forward or backward one map square.
|
void |
prependMapModelListener(@NotNull MapModelListener<G,A,R> listener)
Register a map listener and call it before all other listeners.
|
void |
removeGameObject(G gameObject,
boolean join)
Delete an existing
GameObject from the map. |
void |
removeMapModelListener(@NotNull MapModelListener<G,A,R> listener)
Unregister a map listener.
|
void |
removeMapTransactionListener(@NotNull MapTransactionListener<G,A,R> listener)
Unregisters a map transaction listener.
|
void |
resetModified()
Resets the modified flag to false.
|
void |
setErrors(@NotNull ErrorCollector<G,A,R> errors)
Sets the errors in this map.
|
void |
setMapFile(@Nullable MapFile mapFile)
Sets the map file.
|
void |
transientGameObjectChange(G gameObject)
Method to notify the model that a game object was changed but need not be
restored by undo/redo.
|
public DefaultMapModel(@NotNull
@NotNull AutojoinLists<G,A,R> autojoinLists,
@NotNull
A mapArchObject,
@NotNull
@NotNull ArchetypeChooserModel<G,A,R> archetypeChooserModel,
@NotNull
@NotNull GameObjectFactory<G,A,R> gameObjectFactory,
@NotNull
@NotNull GameObjectMatchers gameObjectMatchers,
@NotNull
@NotNull InsertionMode topmostInsertionMode)
autojoinLists - the autojoin lists instance to usemapArchObject - the map arch object to associate with this modelarchetypeChooserModel - the archetype chooser controlgameObjectFactory - the game object factory for creating game
objectsgameObjectMatchers - the game object matchers to usetopmostInsertionMode - the "topmost" insertion modepublic void mapClosed()
MapModel@NotNull public A getMapArchObject()
MapModelgetMapArchObject in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>@NotNull public @NotNull MapSquare<G,A,R> getMapSquare(@NotNull @NotNull java.awt.Point pos)
MapModelgetMapSquare in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>pos - location to get square atppublic void addObjectListToMap(@NotNull
@NotNull java.lang.Iterable<G> objects)
MapModelGameObjects to this map.addObjectListToMap in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>objects - the game objects to addpublic void clearMap()
MapModelpublic boolean isEmpty()
MapModelpublic void addMapModelListener(@NotNull
@NotNull MapModelListener<G,A,R> listener)
MapModeladdMapModelListener in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>listener - the listener to registerpublic void prependMapModelListener(@NotNull
@NotNull MapModelListener<G,A,R> listener)
MapModelprependMapModelListener in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>listener - the listener to registerpublic void removeMapModelListener(@NotNull
@NotNull MapModelListener<G,A,R> listener)
MapModelremoveMapModelListener in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>listener - the listener to unregisterpublic void addMapTransactionListener(@NotNull
@NotNull MapTransactionListener<G,A,R> listener)
MapModeladdMapTransactionListener in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>listener - the the listener to registerpublic void removeMapTransactionListener(@NotNull
@NotNull MapTransactionListener<G,A,R> listener)
MapModelremoveMapTransactionListener in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>listener - the listener to unregisterpublic void beginSquareChange(@NotNull
@NotNull MapSquare<G,A,R> mapSquare)
MapModelbeginSquareChange in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>mapSquare - the map square that is about to changepublic void endSquareChange(@NotNull
@NotNull MapSquare<G,A,R> mapSquare)
MapModelMapModel.getTransactionDepth() returns 0, otherwise
it is transactional. The model then notifies the registered listeners of
the changes.endSquareChange in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>mapSquare - the map square that has changedpublic void beginGameObjectChange(@NotNull
G gameObject)
MapModelbeginGameObjectChange in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>gameObject - the game object that is about to changepublic void endGameObjectChange(@NotNull
G gameObject)
MapModelMapModel.getTransactionDepth() returns 0,
otherwise it is transactional. The model then notifies the registered
listeners of the changes.endGameObjectChange in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>gameObject - the game object that has changedpublic void transientGameObjectChange(@NotNull
G gameObject)
MapModelMapModel.getTransactionDepth() returns 0, otherwise it is transactional. The
model then notifies the registered listeners of the changes.transientGameObjectChange in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>gameObject - the game object that has changedpublic void beginTransaction(@NotNull
@NotNull java.lang.String name)
MapModelMapModel.endTransaction().
A transaction has a name. The name of the outermost transaction is used as a String presented to the user for undoing the operation enclosed by that transaction.
Beginning a nested transaction is a cheap operation.
beginTransaction in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>name - the name of the transactionMapModel.endTransaction(),
MapModel.endTransaction(boolean),
MapModel.endAllTransactions(),
MapModel.getTransactionDepth(),
MapModel.isAnyTransactionActive()public void endTransaction()
MapModelEnding a nested operation is a cheap operation. Ending a transaction without changes also is a cheap operation.
If the last transaction is ended, the changes are committed.
Same as endTransaction(false).
endTransaction in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>MapModel.beginTransaction(String),
MapModel.endTransaction(boolean),
MapModel.endAllTransactions(),
MapModel.getTransactionDepth(),
MapModel.isAnyTransactionActive()public void endTransaction(boolean fireEvent)
MapModelEnding a nested operation is a cheap operation. Ending a transaction without changes also is a cheap operation.
If the last transaction is ended, the changes are committed.
An example where setting fireEvent to true is useful even
though the outermost transaction is not ended is when during painting the
UI should be updated though painting is not finished.
endTransaction in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>fireEvent - true if an event should be fired even in case
this doesn't end the outermost transaction.MapModel.beginTransaction(String),
MapModel.endTransaction(),
MapModel.endAllTransactions(),
MapModel.getTransactionDepth(),
MapModel.isAnyTransactionActive()public void endAllTransactions()
MapModelendAllTransactions in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>MapModel.beginTransaction(String),
MapModel.endTransaction(),
MapModel.endTransaction(boolean),
MapModel.getTransactionDepth(),
MapModel.isAnyTransactionActive()public int getTransactionDepth()
MapModelMapModel.beginTransaction(String) invocations without matching MapModel.endTransaction() invocations. A transaction depth of 0 means there is
no ongoing transaction.getTransactionDepth in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>MapModel.beginTransaction(String),
MapModel.endTransaction(),
MapModel.endTransaction(boolean),
MapModel.endAllTransactions(),
MapModel.isAnyTransactionActive()public boolean isAnyTransactionActive()
MapModeltrue if and only if MapModel.getTransactionDepth() returns
a value greater than zero.isAnyTransactionActive in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>true if there's a transaction going on, otherwise false.MapModel.beginTransaction(String),
MapModel.endTransaction(),
MapModel.endTransaction(boolean),
MapModel.endAllTransactions(),
MapModel.getTransactionDepth()public void removeGameObject(@NotNull
G gameObject,
boolean join)
MapModelGameObject from the map.removeGameObject in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>gameObject - the game object to removejoin - if set, auto-joining is supportedpublic boolean isMultiArchFittingToMap(@NotNull
@NotNull Archetype<G,A,R> archetype,
@NotNull
@NotNull java.awt.Point pos,
boolean allowDouble)
MapModelisMultiArchFittingToMap in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>archetype - the archetype to checkpos - position of multi-square headallowDouble - whether overlapping multi-square arches should be
allowed (check is done using the archetype name)public void setErrors(@NotNull
@NotNull ErrorCollector<G,A,R> errors)
MapModel@NotNull public @NotNull ErrorCollector<G,A,R> getErrors()
MapModel@Nullable public G insertArchToMap(@NotNull @NotNull BaseObject<G,A,R,?> templateBaseObject, @Nullable G nextGameObject, @NotNull @NotNull java.awt.Point pos, boolean join)
MapModelinsertArchToMap in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>templateBaseObject - a clone copy of this game object gets inserted
to the map; it can be an archetype of a game objectnextGameObject - the new game object gets inserted before this; if
null, the game object gets inserted at bottompos - the map position to insert the new game objectjoin - if set, auto-joining is supportednull if an error occurred@Nullable public G insertBaseObject(@NotNull @NotNull BaseObject<G,A,R,?> baseObject, @NotNull @NotNull java.awt.Point pos, boolean allowMany, boolean join, @NotNull @NotNull InsertionMode insertionMode)
MapModelBaseObject to a map. Archetypes are instantiated, game
objects are cloned. The direction of the inserted game object is set to
the direction of the archetype chooser. This function allows multi-square
game objects.insertBaseObject in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>baseObject - the base objectpos - the insert-location on this mapallowMany - whether duplicates are allowedjoin - whether to auto-join the inserted game objectinsertionMode - the insertion mode to usenull if nothing was insertedpublic void addGameObjectToMap(@NotNull
G gameObject,
@NotNull
@NotNull java.awt.Point pos,
@NotNull
@NotNull InsertionMode insertionMode)
MapModelgameObject is a new and unlinked object.addGameObjectToMap in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>gameObject - the new GameObject with set destination coordinates to
be linked onto the mappos - the insert locationinsertionMode - the insertion mode to usepublic void moveEnv(@NotNull
G gameObject,
@NotNull
@NotNull java.awt.Point pos,
@NotNull
G nextGameObject)
MapModelGameObject to its environment.public void moveInv(@NotNull
G gameObject,
@NotNull
@NotNull GameObject<G,A,R> prevGameObject)
MapModelGameObject to the inventory of another game object.public boolean isAreaEmpty(int left,
int top,
int width,
int height)
MapModelisAreaEmpty in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>left - the left border of the areatop - the top border of the areawidth - the with of the areaheight - the height of the areapublic void addActiveEditType(int editType)
MapModeladdActiveEditType in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>editType - new edit typepublic void setMapFile(@Nullable
@Nullable MapFile mapFile)
MapModelsetMapFile in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>mapFile - the map file or null if the map has not yet been
saved@Nullable public @Nullable MapFile getMapFile()
MapModelgetMapFile in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>null if the map has not yet been saved@NotNull public @NotNull MapFile getMapFile(@NotNull @NotNull MapPath mapPath) throws SameMapException, UnsavedMapException
MapModelMapPath from this map.getMapFile in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>mapPath - the map path to followSameMapException - of the destination map file is the same as this
map fileUnsavedMapException - if this map is not saved and therefore its
map file is unknown@NotNull public @NotNull java.util.List<G> getAllGameObjects()
MapModelgetAllGameObjects in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>public boolean isModified()
MapModelisModified in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>true if the map has been modified from the on-disk statepublic void resetModified()
MapModelresetModified in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>public void facesReloaded()
MapModelfacesReloaded in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>public void nextPoint(java.awt.Point point,
int direction)
MapModel