Package net.sf.gridarta.model.mapmodel
Class MapSquare<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
- java.lang.Object
-
- net.sf.gridarta.model.baseobject.GameObjectContainer<G,A,R>
-
- net.sf.gridarta.model.mapmodel.MapSquare<G,A,R>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<G>
public class MapSquare<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>> extends GameObjectContainer<G,A,R>
A single Map Square. This class is implemented in a way that changes via some modifier methods in a map square will automatically fire events in the associated MapModel. A MapSquare always knows its model. It's not possible to create a MapSquare that is not associated to a model.The objects are stored bottom to top:
GameObjectContainer.getFirst()returns the object at the bottom,GameObjectContainer.getLast()returns the object at the top of the square.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLightSource(@NotNull MapSquare<G,A,R> mapSquare)Adds a light emitting game object that affects this map square.GasGameObject()Returns this instance as aGameObjectornullif this instance is not a game object.voidbeginSquareChange()Method to notify the model that a map square is about to change.protected @NotNull MapSquare<G,A,R>clone()voidendSquareChange()Method to notify the model that a map square was changed.booleanequals(@Nullable java.lang.Object obj)}GgetAfterLast(@NotNull GameObjectMatcher gameObjectMatcher)Returns the game object after the last occurrence of a matching game object.GgetBeforeFirst(@NotNull GameObjectMatcher gameObjectMatcher)Returns the game object before the first occurrence of a matching game object.GgetFirst(@NotNull GameObjectMatcher gameObjectMatcher)Returns the first occurrence of a matching game object.GgetLast(@NotNull GameObjectMatcher gameObjectMatcher)Returns the last occurrence of a matching game object.GgetLastOfLeadingSpan(@NotNull GameObjectMatcher gameObjectMatcher)Returns the last game object of the initial segment of matching game objects.intgetLightRadius()Returns the maximum light radius of all light emitting objects within this map square.@NotNull java.awt.PointgetMapLocation()Returns the coordinate on the map.voidgetMapLocation(@NotNull java.awt.Point pos)Returns the coordinate on the map.voidgetMapLocation(@NotNull java.awt.Point pos, int dx, int dy)Returns the coordinate with an offset on the map.@NotNull MapModel<G,A,R>getMapModel()Returns theMapModelthis map square is part of.@NotNull MapSquare<G,A,R>getMapSquare()Returns theMapSquarethis game object is part of.@NotNull MapSquare<G,A,R>getMapSquareOptional()Returns theMapSquarethis game object is part of.intgetMapX()Returns the x coordinate on the map.intgetMapY()Returns the y coordinate on the map.inthashCode()}booleanisLight()Returns whether this map square is affected by any light emitting game objects.protected voidnotifyBeginChange()Notifies the map model that this container is about to change.protected voidnotifyEndChange()Notifies the map model that this container has changed.voidremoveLightSource(@NotNull MapSquare<G,A,R> mapSquare)Removes a light emitting game object that affects this map square.voidsetLightRadius(int lightRadius)Sets the maximum light radius of all light emitting objects within this map square.protected voidsetThisContainer(G gameObject)Sets aGameObject's container to this container.@NotNull java.lang.StringtoString()}-
Methods inherited from class net.sf.gridarta.model.baseobject.GameObjectContainer
addFirst, addLast, getFirst, getLast, getNext, getPrev, hasSameContents, insertAfter, insertBefore, isBottom, isEmpty, isTop, iterator, moveBottom, moveDown, moveTop, moveUp, recursive, remove, removeAll, replace, reverse
-
-
-
-
Constructor Detail
-
MapSquare
public MapSquare(@NotNull @NotNull MapModel<G,A,R> mapModel, int mapX, int mapY)Creates a new instance.- Parameters:
mapModel- the map model this map square is part ofmapX- the x coordinate of this map square within the model's gridmapY- the y coordinate of this map square within the model's grid
-
-
Method Detail
-
getMapModel
@NotNull public @NotNull MapModel<G,A,R> getMapModel()
Returns theMapModelthis map square is part of.- Returns:
- the map model
-
getMapX
public int getMapX()
Returns the x coordinate on the map.- Returns:
- the x coordinate on map
-
getMapY
public int getMapY()
Returns the y coordinate on the map.- Returns:
- the y coordinate on map
-
getMapLocation
@NotNull public @NotNull java.awt.Point getMapLocation()
Returns the coordinate on the map.- Returns:
- the coordinate on the map
-
getMapLocation
public void getMapLocation(@NotNull @NotNull java.awt.Point pos)Returns the coordinate on the map.- Parameters:
pos- returns the coordinate on the map
-
getMapLocation
public void getMapLocation(@NotNull @NotNull java.awt.Point pos, int dx, int dy)Returns the coordinate with an offset on the map.- Parameters:
pos- returns the coordinate on the mapdx- the x offset to add to the coordinatedy- the y offset to add to the coordinate
-
getMapSquare
@NotNull public @NotNull MapSquare<G,A,R> getMapSquare()
Description copied from class:GameObjectContainerReturns theMapSquarethis game object is part of.- Specified by:
getMapSquarein classGameObjectContainer<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>- Returns:
- the map square
-
getMapSquareOptional
@NotNull public @NotNull MapSquare<G,A,R> getMapSquareOptional()
Description copied from class:GameObjectContainerReturns theMapSquarethis game object is part of.- Specified by:
getMapSquareOptionalin classGameObjectContainer<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>- Returns:
- the map square or
nullif the game object is not part of a map
-
notifyBeginChange
protected void notifyBeginChange()
Description copied from class:GameObjectContainerNotifies the map model that this container is about to change.- Specified by:
notifyBeginChangein classGameObjectContainer<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
-
notifyEndChange
protected void notifyEndChange()
Description copied from class:GameObjectContainerNotifies the map model that this container has changed.- Specified by:
notifyEndChangein classGameObjectContainer<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
-
clone
@NotNull protected @NotNull MapSquare<G,A,R> clone()
- Overrides:
clonein classGameObjectContainer<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
-
setThisContainer
protected void setThisContainer(@NotNull G gameObject)Description copied from class:GameObjectContainerSets aGameObject's container to this container.- Specified by:
setThisContainerin classGameObjectContainer<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>- Parameters:
gameObject- the game object
-
asGameObject
@Nullable public G asGameObject()
Description copied from class:GameObjectContainerReturns this instance as aGameObjectornullif this instance is not a game object.- Specified by:
asGameObjectin classGameObjectContainer<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>- Returns:
- this instance or
null
-
getLast
@Nullable public G getLast(@NotNull @NotNull GameObjectMatcher gameObjectMatcher)
Returns the last occurrence of a matching game object.- Parameters:
gameObjectMatcher- the matcher to use- Returns:
- the last match, or
nullif no such game object exists
-
getAfterLast
@Nullable public G getAfterLast(@NotNull @NotNull GameObjectMatcher gameObjectMatcher)
Returns the game object after the last occurrence of a matching game object.- Parameters:
gameObjectMatcher- the matcher to use- Returns:
- the game object after the last match, or
nullif no such game object exists
-
getFirst
@Nullable public G getFirst(@NotNull @NotNull GameObjectMatcher gameObjectMatcher)
Returns the first occurrence of a matching game object.- Parameters:
gameObjectMatcher- the matcher to use- Returns:
- the first match, or
nullif no such game object exists
-
getBeforeFirst
@Nullable public G getBeforeFirst(@NotNull @NotNull GameObjectMatcher gameObjectMatcher)
Returns the game object before the first occurrence of a matching game object.- Parameters:
gameObjectMatcher- the matcher to use- Returns:
- the game object before the first match, or
nullif no such game object exists
-
getLastOfLeadingSpan
@Nullable public G getLastOfLeadingSpan(@NotNull @NotNull GameObjectMatcher gameObjectMatcher)
Returns the last game object of the initial segment of matching game objects.- Parameters:
gameObjectMatcher- the matcher to use- Returns:
- the result or
nullif the first game object does not matchgameObjectMatcher
-
beginSquareChange
public void beginSquareChange()
Method to notify the model that a map square is about to change.
-
endSquareChange
public void endSquareChange()
Method to notify the model that a map square was changed.
-
equals
public boolean equals(@Nullable @Nullable java.lang.Object obj)}- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
}- Overrides:
hashCodein classjava.lang.Object
-
toString
@NotNull public @NotNull java.lang.String toString()
}- Overrides:
toStringin classGameObjectContainer<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
-
getLightRadius
public int getLightRadius()
Returns the maximum light radius of all light emitting objects within this map square.- Returns:
- the light radius or
0if no light emitting objects are present
-
setLightRadius
public void setLightRadius(int lightRadius)
Sets the maximum light radius of all light emitting objects within this map square.- Parameters:
lightRadius- the light radius or0if no light emitting objects are present
-
addLightSource
public void addLightSource(@NotNull @NotNull MapSquare<G,A,R> mapSquare)Adds a light emitting game object that affects this map square.- Parameters:
mapSquare- the map square that contains the game object
-
removeLightSource
public void removeLightSource(@NotNull @NotNull MapSquare<G,A,R> mapSquare)Removes a light emitting game object that affects this map square.- Parameters:
mapSquare- the map square that contains the game object
-
isLight
public boolean isLight()
Returns whether this map square is affected by any light emitting game objects.- Returns:
- whether this map square is affected by any light emitting game objects
-
-