20 package net.sf.gridarta.model.mapmodel;
22 import java.io.Serializable;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.List;
30 import org.jetbrains.annotations.NotNull;
62 private List<List<MapSquare<G, A, R>>>
mapGrid;
73 for (
int y = 0; y < mapSize.getHeight(); y++) {
74 for (
int x = 0; x < mapSize.getWidth(); x++) {
75 mapGrid.get(x).set(y,
new MapSquare<>(mapModel, x, y));
87 final ArrayList<List<MapSquare<G, A, R>>> result =
new ArrayList<>(mapSize.getWidth());
88 for (
int x = 0; x < mapSize.getWidth(); x++) {
89 final ArrayList<MapSquare<G, A, R>> column =
new ArrayList<>(mapSize.getHeight());
90 for (
int y = 0; y < mapSize.getHeight(); y++) {
109 return mapGrid.get(x).get(y);
120 for (
int x = 0; x < mapSize.
getWidth(); x++) {
121 for (
int y = 0; y < mapSize.
getHeight(); y++) {
122 final List<MapSquare<G, A, R>> column = mapGrid.get(x);
123 if (column.get(y) == null) {
125 }
else if (!column.get(y).isEmpty()) {
126 column.get(y).beginSquareChange();
130 column.get(y).endSquareChange();
143 for (
int x = 0; x < mapSize.
getWidth(); x++) {
144 for (
int y = 0; y < mapSize.
getHeight(); y++) {
145 if (!mapGrid.get(x).get(y).isEmpty()) {
158 final List<List<MapSquare<G, A, R>>> newGrid =
newMapGrid(newSize);
161 for (
int x = 0; x < newSize.getWidth(); x++) {
162 for (
int y = 0; y < newSize.getHeight(); y++) {
164 newGrid.get(x).set(y, mapGrid.get(x).get(y));
166 newGrid.get(x).set(y,
new MapSquare<>(mapModel, x, y));
185 for (
int x = minX; x < maxX; x++) {
186 for (
int y = minY; y < maxY; y++) {
188 objectsToDelete.add(node.getHead());
static final long serialVersionUID
The serial version UID.
final MapModel< G, A, R > mapModel
The associated MapModel.
List< List< MapSquare< G, A, R > > > mapGrid
The MapSquare of this grid.
void resize(@NotNull final Size2D newSize)
Resizes the map grid to a new size.
boolean isEmpty()
Returns whether the map is empty.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
GameObjects are the objects based on Archetypes found on maps.
int getWidth()
Returns the width of the area.
void clearMap()
This implementation is very safe by recreating every single MapSquare as new empty square with the tr...
MapSquareGrid(@NotNull final MapModel< G, A, R > mapModel, @NotNull final Size2D mapSize)
Creates a new instance.
MapSquare< G, A, R > getMapSquare(final int x, final int y)
Returns the MapSquare at a given location.
A rectangular grid of MapSquare instances.
List< List< MapSquare< G, A, R > > > newMapGrid(@NotNull final Size2D mapSize)
Allocates a new 2-dimensional MapSquare array of the given size.
int getHeight()
Returns the height of the area.
Size2D getMapSize()
Returns the size of this map grid in map squares.
void collectHeads(final int minX, final int minY, final int maxX, final int maxY, @NotNull final Collection< GameObject< G, A, R >> objectsToDelete)
Adds all head parts for game object within an area to a collection.
Size2D mapSize
The size of mapGrid.
Interface for MapArchObjects.
The class Size2D represents a 2d rectangular area.