Class AbstractMapArchObject<A extends MapArchObject<A>>
- java.lang.Object
-
- net.sf.gridarta.model.maparchobject.AbstractMapArchObject<A>
-
- All Implemented Interfaces:
java.io.Serializable,MapArchObject<A>
- Direct Known Subclasses:
MapArchObject,MapArchObject,MapArchObject
public abstract class AbstractMapArchObject<A extends MapArchObject<A>> extends java.lang.Object implements MapArchObject<A>
Base implementation ofMapArchObjectthat covers similarities between Crossfire maps and Daimonin maps.- See Also:
- Serialized Form
- Warning:
- NEVER use this class in a Collection!
hashCode()andequals(Object)work on non-final fields and thus will break any operation inside Collections!
-
-
Field Summary
Fields Modifier and Type Field Description static @NotNull java.lang.StringMAP_NAME_UNNAMEDThe name of an unnamed map.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractMapArchObject()Creates a new instance.protectedAbstractMapArchObject(@NotNull AbstractMapArchObject<A> mapArchObject)Creates a new instance as a copy of another map arch object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMapArchObjectListener(@NotNull MapArchObjectListener listener)Registers an event listener.voidaddText(@NotNull java.lang.String text)Appends 'text' to the map text.voidbeginTransaction()Starts a new transaction.@NotNull java.lang.StringcalculateTilePath(@NotNull Direction direction, @Nullable MapFile mapFile)Calculate a single tile path in a particular direction.voidcalculateTilePaths(@Nullable MapFile mapFile, @NotNull java.io.File mapsDirectory)Calculates tiled paths for the map automatically.voidendTransaction()Ends a transaction.voidendTransaction(boolean fireEvent)Ends a transaction.booleanequals(@Nullable java.lang.Object obj)intgetDarkness()Returns the light / darkness of this map.intgetDifficulty()Returns the map's difficulty.@NotNull java.awt.PointgetEnter()Returns the enter coordinates.intgetEnterX()Returns the enter x coordinate.intgetEnterY()Returns the enter y coordinate.@NotNull java.lang.StringgetMapName()Returns the map name.@NotNull Size2DgetMapSize()Returns the map size.intgetResetTimeout()Returns the reset timeout (in seconds).intgetSwapTime()Returns the swap time (in ticks).@NotNull java.lang.StringgetText()Returns the message text.@NotNull java.lang.StringgetTilePath(@NotNull Direction direction)Returns a tile path.intgetTilePaths()Returns the number of tile paths.inthashCode()booleanisFixedReset()Returns whether this map uses a fixed reset.booleanisOutdoor()Returns whether the map is an "outdoor" map.booleanisPointValid(@Nullable java.awt.Point pos)Checks whether the given coordinate is within map bounds.booleanisTilePathAuto(@NotNull Direction direction, @Nullable MapFile mapFile)Determines whether a tiled map in the specified direction is automatic tiled path or not.voidremoveMapArchObjectListener(@NotNull MapArchObjectListener listener)Unregisters an event listener.voidsetDarkness(int darkness)Sets the light / darkness of this map.voidsetDifficulty(int difficulty)Sets the map's difficulty.voidsetEnterX(int enterX)Sets the enter x coordinate.voidsetEnterY(int enterY)Sets the enter y coordinate.voidsetFixedReset(boolean fixedReset)Sets whether this map uses a fixed reset.voidsetMapName(@NotNull java.lang.String name)Sets the map name.voidsetMapSize(@NotNull Size2D mapSize)Sets the map size.protected voidsetModified()Marks this map arch object as changed.voidsetOutdoor(boolean outdoor)Sets whether the map is an "outdoor" map.voidsetResetTimeout(int resetTimeout)Sets the reset timeout (in seconds).voidsetState(A mapArchObject)Resets the state of this object to the state of the given map arch object.voidsetSwapTime(int swapTime)Sets the swap time (in ticks).voidsetText(java.lang.String text)Sets the map text.voidsetTilePath(@NotNull Direction direction, @NotNull java.lang.String tilePath)Sets a tile path.voidupdateModifiedAttribute(@NotNull java.lang.String userName)Updates the "Modified:" attribute in the message text.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.gridarta.model.maparchobject.MapArchObject
createClone
-
-
-
-
Field Detail
-
MAP_NAME_UNNAMED
@NotNull public static final @NotNull java.lang.String MAP_NAME_UNNAMED
The name of an unnamed map.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractMapArchObject
protected AbstractMapArchObject()
Creates a new instance.
-
AbstractMapArchObject
protected AbstractMapArchObject(@NotNull @NotNull AbstractMapArchObject<A> mapArchObject)Creates a new instance as a copy of another map arch object.- Parameters:
mapArchObject- the other map arch object
-
-
Method Detail
-
getMapSize
@NotNull public @NotNull Size2D getMapSize()
Description copied from interface:MapArchObjectReturns the map size.- Specified by:
getMapSizein interfaceMapArchObject<A extends MapArchObject<A>>- Returns:
- size of the map reflected by this MapArchObject
-
setMapSize
public void setMapSize(@NotNull @NotNull Size2D mapSize)Description copied from interface:MapArchObjectSets the map size.- Specified by:
setMapSizein interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
mapSize- the new map size
-
getMapName
@NotNull public @NotNull java.lang.String getMapName()
Description copied from interface:MapArchObjectReturns the map name.- Specified by:
getMapNamein interfaceMapArchObject<A extends MapArchObject<A>>- Returns:
- the map name
-
setMapName
public void setMapName(@NotNull @NotNull java.lang.String name)Description copied from interface:MapArchObjectSets the map name.- Specified by:
setMapNamein interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
name- the new map name
-
getEnterX
public int getEnterX()
Description copied from interface:MapArchObjectReturns the enter x coordinate.- Specified by:
getEnterXin interfaceMapArchObject<A extends MapArchObject<A>>- Returns:
- the enter x coordinate
-
setEnterX
public void setEnterX(int enterX)
Description copied from interface:MapArchObjectSets the enter x coordinate.- Specified by:
setEnterXin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
enterX- the new enter x coordinate
-
getEnterY
public int getEnterY()
Description copied from interface:MapArchObjectReturns the enter y coordinate.- Specified by:
getEnterYin interfaceMapArchObject<A extends MapArchObject<A>>- Returns:
- the enter y coordinate
-
setEnterY
public void setEnterY(int enterY)
Description copied from interface:MapArchObjectSets the enter y coordinate.- Specified by:
setEnterYin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
enterY- the new enter y coordinate
-
getEnter
@NotNull public @NotNull java.awt.Point getEnter()
Description copied from interface:MapArchObjectReturns the enter coordinates.- Specified by:
getEnterin interfaceMapArchObject<A extends MapArchObject<A>>- Returns:
- the enter coordinates
-
isOutdoor
public boolean isOutdoor()
Description copied from interface:MapArchObjectReturns whether the map is an "outdoor" map.- Specified by:
isOutdoorin interfaceMapArchObject<A extends MapArchObject<A>>- Returns:
- whether the map is an "outdoor" map
-
setOutdoor
public void setOutdoor(boolean outdoor)
Description copied from interface:MapArchObjectSets whether the map is an "outdoor" map.- Specified by:
setOutdoorin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
outdoor- whether the map is an "outdoor" map
-
getResetTimeout
public int getResetTimeout()
Description copied from interface:MapArchObjectReturns the reset timeout (in seconds).- Specified by:
getResetTimeoutin interfaceMapArchObject<A extends MapArchObject<A>>- Returns:
- the reset timeout (in seconds)
-
setResetTimeout
public void setResetTimeout(int resetTimeout)
Description copied from interface:MapArchObjectSets the reset timeout (in seconds).- Specified by:
setResetTimeoutin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
resetTimeout- the new reset timeout (in seconds)
-
getSwapTime
public int getSwapTime()
Description copied from interface:MapArchObjectReturns the swap time (in ticks).- Specified by:
getSwapTimein interfaceMapArchObject<A extends MapArchObject<A>>- Returns:
- the swap time (in ticks)
-
setSwapTime
public void setSwapTime(int swapTime)
Description copied from interface:MapArchObjectSets the swap time (in ticks).- Specified by:
setSwapTimein interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
swapTime- the swap time (in ticks)
-
getDifficulty
public int getDifficulty()
Description copied from interface:MapArchObjectReturns the map's difficulty.- Specified by:
getDifficultyin interfaceMapArchObject<A extends MapArchObject<A>>- Returns:
- the map's difficulty
-
setDifficulty
public void setDifficulty(int difficulty)
Description copied from interface:MapArchObjectSets the map's difficulty.- Specified by:
setDifficultyin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
difficulty- the new difficulty for this map
-
isFixedReset
public boolean isFixedReset()
Description copied from interface:MapArchObjectReturns whether this map uses a fixed reset.- Specified by:
isFixedResetin interfaceMapArchObject<A extends MapArchObject<A>>- Returns:
- whether this map uses a fixed reset
-
setFixedReset
public void setFixedReset(boolean fixedReset)
Description copied from interface:MapArchObjectSets whether this map uses a fixed reset.- Specified by:
setFixedResetin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
fixedReset- whether this map should use a fixed reset
-
getDarkness
public int getDarkness()
Description copied from interface:MapArchObjectReturns the light / darkness of this map. (0 means fully bright)- Specified by:
getDarknessin interfaceMapArchObject<A extends MapArchObject<A>>- Returns:
- the light / darkness of this map
-
setDarkness
public void setDarkness(int darkness)
Description copied from interface:MapArchObjectSets the light / darkness of this map.- Specified by:
setDarknessin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
darkness- the new light / darkness of this map
-
getTilePaths
public int getTilePaths()
Description copied from interface:MapArchObjectReturns the number of tile paths.- Specified by:
getTilePathsin interfaceMapArchObject<A extends MapArchObject<A>>- Returns:
- the number of tile paths
-
getTilePath
@NotNull public @NotNull java.lang.String getTilePath(@NotNull @NotNull Direction direction)Description copied from interface:MapArchObjectReturns a tile path.- Specified by:
getTilePathin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
direction- the tile path direction- Returns:
- the tile path
-
setTilePath
public void setTilePath(@NotNull @NotNull Direction direction, @NotNull @NotNull java.lang.String tilePath)Description copied from interface:MapArchObjectSets a tile path.- Specified by:
setTilePathin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
direction- the tile path directiontilePath- the new tile path
-
calculateTilePath
@NotNull public @NotNull java.lang.String calculateTilePath(@NotNull @NotNull Direction direction, @Nullable @Nullable MapFile mapFile)Description copied from interface:MapArchObjectCalculate a single tile path in a particular direction.- Specified by:
calculateTilePathin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
direction- the directionmapFile- map file- Returns:
- Calculated tile path, empty string on failure.
-
calculateTilePaths
public void calculateTilePaths(@Nullable @Nullable MapFile mapFile, @NotNull @NotNull java.io.File mapsDirectory)Description copied from interface:MapArchObjectCalculates tiled paths for the map automatically.- Specified by:
calculateTilePathsin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
mapFile- map filemapsDirectory- maps directory
-
isTilePathAuto
public boolean isTilePathAuto(@NotNull @NotNull Direction direction, @Nullable @Nullable MapFile mapFile)Description copied from interface:MapArchObjectDetermines whether a tiled map in the specified direction is automatic tiled path or not.- Specified by:
isTilePathAutoin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
direction- direction of the tiled mapmapFile- map file- Returns:
- Whether the tile is automatic.
-
setState
public void setState(@NotNull A mapArchObject)Description copied from interface:MapArchObjectResets the state of this object to the state of the given map arch object.- Specified by:
setStatein interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
mapArchObject- the map arch object to copy the state from
-
equals
public boolean equals(@Nullable @Nullable java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
addMapArchObjectListener
public void addMapArchObjectListener(@NotNull @NotNull MapArchObjectListener listener)Description copied from interface:MapArchObjectRegisters an event listener.- Specified by:
addMapArchObjectListenerin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
listener- the listener to register
-
removeMapArchObjectListener
public void removeMapArchObjectListener(@NotNull @NotNull MapArchObjectListener listener)Description copied from interface:MapArchObjectUnregisters an event listener.- Specified by:
removeMapArchObjectListenerin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
listener- the listener to unregister
-
setModified
protected void setModified()
Marks this map arch object as changed. The map arch object then notifies the registered listeners of the change at the end of the transaction.
-
beginTransaction
public void beginTransaction()
Description copied from interface:MapArchObjectStarts a new transaction. Transactions may be nested. Transactions serve the purpose of firing events to the views when more changes are known to come before the view is really required to update. Each invocation of this function requires its own invocation ofMapArchObject.endTransaction().Beginning a nested transaction is a cheap operation.
- Specified by:
beginTransactionin interfaceMapArchObject<A extends MapArchObject<A>>- See Also:
MapArchObject.endTransaction(),MapArchObject.endTransaction(boolean)
-
endTransaction
public void endTransaction()
Description copied from interface:MapArchObjectEnds a transaction. Invoking this method will reduce the transaction depth by only 1.Ending 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).- Specified by:
endTransactionin interfaceMapArchObject<A extends MapArchObject<A>>- See Also:
MapArchObject.beginTransaction(),MapArchObject.endTransaction(boolean)
-
endTransaction
public void endTransaction(boolean fireEvent)
Description copied from interface:MapArchObjectEnds a transaction. Invoking this method will reduce the transaction depth by only 1.Ending 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
fireEventtotrueis useful even though the outermost transaction is not ended is when during painting the UI should be updated though painting is not finished.- Specified by:
endTransactionin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
fireEvent-trueif an event should be fired even in case this doesn't end the outermost transaction.- See Also:
MapArchObject.beginTransaction(),MapArchObject.endTransaction()
-
addText
public void addText(@NotNull @NotNull java.lang.String text)Description copied from interface:MapArchObjectAppends 'text' to the map text.- Specified by:
addTextin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
text- the string to add
-
setText
public void setText(java.lang.String text)
Description copied from interface:MapArchObjectSets the map text.- Specified by:
setTextin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
text- the new map text
-
getText
@NotNull public @NotNull java.lang.String getText()
Description copied from interface:MapArchObjectReturns the message text.- Specified by:
getTextin interfaceMapArchObject<A extends MapArchObject<A>>- Returns:
- the message text
-
updateModifiedAttribute
public void updateModifiedAttribute(@NotNull @NotNull java.lang.String userName)Description copied from interface:MapArchObjectUpdates the "Modified:" attribute in the message text.- Specified by:
updateModifiedAttributein interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
userName- the user name to include
-
isPointValid
public boolean isPointValid(@Nullable @Nullable java.awt.Point pos)Description copied from interface:MapArchObjectChecks whether the given coordinate is within map bounds.- Specified by:
isPointValidin interfaceMapArchObject<A extends MapArchObject<A>>- Parameters:
pos- the coordinates to check- Returns:
trueif the given coordinates are on the map, otherwisefalse(also returnsfalseifpos == null)
-
-