20 package net.sf.gridarta.model.maplocation;
22 import java.awt.Point;
23 import java.util.regex.Pattern;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
68 private MapLocation(@NotNull
final MapPath mapPath,
final int mapXCoordinate,
final int mapYCoordinate) {
70 mapCoordinate =
new Point(mapXCoordinate, mapYCoordinate);
98 if (mapSquare == null) {
103 if (mapFile == null) {
110 final int mapX =
getMapX(gameObject);
111 final int mapY =
getMapY(gameObject);
112 return new MapLocation(canonicalMapPath, mapX, mapY);
130 return new Point(mapCoordinate);
134 public boolean equals(@Nullable
final Object obj) {
138 if (obj == null || obj.getClass() != getClass()) {
147 return mapPath.hashCode() ^ mapCoordinate.hashCode();
178 if (path.isEmpty()) {
182 if (allowRandomMapParameters && (path.equals(
"/!") || path.startsWith(
"/random/"))) {
202 final String msg = gameObject.getMsgText();
207 final String[] lines = PATTERN_END_OF_LINE.split(msg);
208 for (
final String line : lines) {
210 if (tmp.length == 2 && tmp[0].equals(parameterName)) {
221 return mapCoordinate.x +
"/" + mapCoordinate.y +
"@" +
mapPath;
225 @SuppressWarnings(
"CompareToUsesNonFinalVariable")
227 final int cmp = mapPath.toString().compareTo(o.mapPath.toString());
231 if (mapCoordinate.x < o.mapCoordinate.x) {
234 if (mapCoordinate.x > o.mapCoordinate.x) {
237 if (mapCoordinate.y < o.mapCoordinate.y) {
240 if (mapCoordinate.y > o.mapCoordinate.y) {
Utility class for string manipulation.
A set of key/value pairs.
static MapPath newMapPath(@NotNull final String string)
Creates a MapPath instance from string representation.
MapSquare< G, A, R > getMapSquare()
A MapModel reflects the data of a map.
Exception thrown if a game object does not specify a valid exit path.
MapModel< G, A, R > getMapModel()
Returns the MapModel this map square is part of.
A MapPath that is absolute, that is, it starts with a "/".
AbsoluteMapPath getMapPath()
Returns the map path within getMapsDir().
int compareTo(@NotNull final MapLocation o)
Represents a maps directory local map path.
static final Pattern PATTERN_SPACES
The pattern that matches a non-empty sequence of spaces.
String SLAYING
The name of the "slaying" attribute.
final MapPath mapPath
The map path.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
MapPath getMapPath()
Returns the map path.
String HP
The attribute name of the "hp" attribute.
GameObjects are the objects based on Archetypes found on maps.
final Point mapCoordinate
The map coordinate.
Utility class for MapPath related functions.
static int getMapY(@NotNull final Attributes gameObject)
Returns the exit x coordinate of a BaseObject.
static String getRandomMapParameter(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final String parameterName)
Extracts a parameter value for an exit to a random map.
MapLocation(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final boolean allowRandomMapParameters)
Creates a new instance from a BaseObject instance.
static MapLocation newAbsoluteMapLocation(@NotNull final GameObject<?, ?, ?> gameObject, final boolean allowRandomMapParameters)
Creates a new instance from a BaseObject instance.
MapFile getMapFile()
Returns the map file.
String SP
The attribute name of the "sp" attribute.
Represents a location on a map consisting of a map path and a map coordinate.
static AbsoluteMapPath append(@NotNull final AbsoluteMapPath baseMapPath, @NotNull final MapPath mapPath)
Appends a map path to another map path.
static MapPath getMapPath(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final boolean allowRandomMapParameters)
Returns the exit map path of a BaseObject.
Point getMapCoordinate()
Returns the map coordinate.
static final Pattern PATTERN_END_OF_LINE
The Pattern that matches end of lines in random map parameters.
MapLocation(@NotNull final MapPath mapPath, final int mapXCoordinate, final int mapYCoordinate)
Creates a new instance.
boolean equals(@Nullable final Object obj)
The location of a map file with a map directory.
static int getMapX(@NotNull final Attributes gameObject)
Returns the exit y coordinate of a BaseObject.