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(AutojoinLists<G,A,R> autojoinLists,
A mapArchObject,
ArchetypeChooserModel<G,A,R> archetypeChooserModel,
GameObjectFactory<G,A,R> gameObjectFactory,
GameObjectMatchers gameObjectMatchers,
InsertionMode<G,A,R> topmostInsertionMode)
Create 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,
java.awt.Point pos,
InsertionMode<G,A,R> insertionMode)
Add a gameObject to the map.
|
void |
addMapModelListener(MapModelListener<G,A,R> listener)
Register a map listener.
|
void |
addMapTransactionListener(MapTransactionListener<G,A,R> listener)
Registers a map transaction listener.
|
void |
addObjectListToMap(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(MapSquare<G,A,R> mapSquare)
Method to notify the model that a map square is about to change.
|
void |
beginTransaction(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(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.
|
java.util.List<G> |
getAllGameObjects()
Returns all game objects.
|
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.
|
MapFile |
getMapFile()
Returns the map file.
|
MapFile |
getMapFile(MapPath mapPath)
Returns the map file for a map that can be reached by following a
MapPath from this map. |
MapSquare<G,A,R> |
getMapSquare(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(BaseObject<G,A,R,?> templateBaseObject,
G nextGameObject,
java.awt.Point pos,
boolean join)
Insert a game object to the map at a specified position.
|
G |
insertBaseObject(BaseObject<G,A,R,?> baseObject,
java.awt.Point pos,
boolean allowMany,
boolean join,
InsertionMode<G,A,R> 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(Archetype<G,A,R> archetype,
java.awt.Point pos,
boolean allowDouble)
Checks whether an 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,
java.awt.Point pos,
G nextGameObject)
Moves a
GameObject to its environment. |
void |
moveInv(G gameObject,
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 |
removeGameObject(G gameObject,
boolean join)
Delete an existing
GameObject from the map. |
void |
removeMapModelListener(MapModelListener<G,A,R> listener)
Unregister a map listener.
|
void |
removeMapTransactionListener(MapTransactionListener<G,A,R> listener)
Unregisters a map transaction listener.
|
void |
resetModified()
Resets the modified flag to false.
|
void |
setErrors(ErrorCollector<G,A,R> errors)
Sets the errors in this map.
|
void |
setMapFile(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 AutojoinLists<G,A,R> autojoinLists, @NotNull A mapArchObject, @NotNull ArchetypeChooserModel<G,A,R> archetypeChooserModel, @NotNull GameObjectFactory<G,A,R> gameObjectFactory, @NotNull GameObjectMatchers gameObjectMatchers, @NotNull InsertionMode<G,A,R> 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()
@NotNull public A getMapArchObject()
getMapArchObject
in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
@NotNull public MapSquare<G,A,R> getMapSquare(@NotNull java.awt.Point pos)
getMapSquare
in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
pos
- location to get square atp
public void addObjectListToMap(@NotNull java.lang.Iterable<G> objects)
GameObjects
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()
public boolean isEmpty()
public void addMapModelListener(@NotNull MapModelListener<G,A,R> listener)
addMapModelListener
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 MapModelListener<G,A,R> listener)
removeMapModelListener
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 MapTransactionListener<G,A,R> listener)
addMapTransactionListener
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 MapTransactionListener<G,A,R> listener)
removeMapTransactionListener
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 MapSquare<G,A,R> mapSquare)
beginSquareChange
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 MapSquare<G,A,R> mapSquare)
MapModel.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)
beginGameObjectChange
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)
MapModel.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)
MapModel.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 java.lang.String name)
MapModel.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()
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)
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()
endAllTransactions
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()
MapModel.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()
true
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)
GameObject
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 Archetype<G,A,R> archetype, @NotNull java.awt.Point pos, boolean allowDouble)
isMultiArchFittingToMap
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 ErrorCollector<G,A,R> errors)
@NotNull public ErrorCollector<G,A,R> getErrors()
@Nullable public G insertArchToMap(@NotNull BaseObject<G,A,R,?> templateBaseObject, @Nullable G nextGameObject, @NotNull java.awt.Point pos, boolean join)
insertArchToMap
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 BaseObject<G,A,R,?> baseObject, @NotNull java.awt.Point pos, boolean allowMany, boolean join, @NotNull InsertionMode<G,A,R> insertionMode)
BaseObject
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 java.awt.Point pos, @NotNull InsertionMode<G,A,R> insertionMode)
gameObject
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 map.pos
- the insert locationinsertionMode
- the insertion mode to usepublic void moveEnv(@NotNull G gameObject, @NotNull java.awt.Point pos, @NotNull G nextGameObject)
GameObject
to its environment.public void moveInv(@NotNull G gameObject, @NotNull GameObject<G,A,R> prevGameObject)
GameObject
to the inventory of another game object.public boolean isAreaEmpty(int left, int top, int width, int height)
isAreaEmpty
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)
addActiveEditType
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 MapFile mapFile)
setMapFile
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 MapFile getMapFile()
getMapFile
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 MapFile getMapFile(@NotNull MapPath mapPath) throws SameMapException, UnsavedMapException
MapPath
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 java.util.List<G> getAllGameObjects()
getAllGameObjects
in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
public boolean isModified()
isModified
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()
resetModified
in interface MapModel<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
public void facesReloaded()
facesReloaded
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)