Gridarta Editor
ExitLocation.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.exitconnector;
21 
22 import java.awt.Point;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
29 
34 public class ExitLocation {
35 
39  @NotNull
40  private final MapFile mapFile;
41 
45  private final int x;
46 
50  private final int y;
51 
55  @NotNull
56  private final String mapName;
57 
64  public ExitLocation(@NotNull final MapFile mapFile, @NotNull final Point point, @NotNull final String mapName) {
65  this.mapFile = mapFile;
66  x = point.x;
67  y = point.y;
68  this.mapName = mapName;
69  }
70 
75  @NotNull
76  public Point getMapCoordinate() {
77  return new Point(x, y);
78  }
79 
87  public void updateExitObject(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final boolean updateName, @Nullable final MapFile sourceMapFile) {
88  final MapPath targetMapPath = mapFile.getMapPath();
89  final MapPath mapPath;
90  if (sourceMapFile == null) {
91  // unsaved source map => absolute reference
92  mapPath = targetMapPath;
93  } else {
94  final AbsoluteMapPath sourceMapPath = sourceMapFile.getMapPath();
95  final String sourceMapComponent = sourceMapPath.getMapComponent();
96  final String targetMapComponent = targetMapPath.getMapComponent();
97  if (sourceMapComponent == null ? targetMapComponent == null : sourceMapComponent.equals(targetMapComponent)) {
98  // relative reference
99  mapPath = sourceMapPath.getRelativeMapPathTo(targetMapPath);
100  } else {
101  // absolute reference
102  mapPath = targetMapPath;
103  }
104  }
105  gameObject.setAttributeString(BaseObject.SLAYING, mapPath.toString());
106  gameObject.setAttributeInt(BaseObject.HP, x);
107  gameObject.setAttributeInt(BaseObject.SP, y);
108  if (updateName) {
109  gameObject.setAttributeString(BaseObject.NAME, mapName);
110  }
111  }
112 
117  @NotNull
118  public MapFile getMapFile() {
119  return mapFile;
120  }
121 
122  @Override
123  public boolean equals(@Nullable final Object obj) {
124  if (obj == this) {
125  return true;
126  }
127  if (obj == null || obj.getClass() != getClass()) {
128  return false;
129  }
130  final ExitLocation exitLocation = (ExitLocation) obj;
131  return x == exitLocation.x && y == exitLocation.y && mapFile.equals(exitLocation.mapFile) && mapName.equals(exitLocation.mapName);
132  }
133 
134  @Override
135  public int hashCode() {
136  return x ^ (y << 16) ^ (y >> 16) ^ mapFile.hashCode() ^ mapName.hashCode();
137  }
138 
139  @Override
140  public String toString() {
141  return mapFile + " " + x + "/" + y + " " + mapName;
142  }
143 
144 }
ExitLocation(@NotNull final MapFile mapFile, @NotNull final Point point, @NotNull final String mapName)
Creates a new instance.
A MapPath that is absolute, that is, it starts with a "/".
final int x
The x-coordinate of the remembered exit.
AbsoluteMapPath getMapPath()
Returns the map path within getMapsDir().
Definition: MapFile.java:93
Represents a maps directory local map path.
Definition: MapPath.java:31
String getMapComponent()
Returns the initial path component of a map path.
RelativeMapPath getRelativeMapPathTo(@NotNull final MapPath mapPath)
Returns a map path of an another map path relative to this map path.
String SLAYING
The name of the "slaying" attribute.
Base package of all Gridarta classes.
final int y
The y-coordinate of the remembered exit.
boolean equals(@Nullable final Object obj)
String getMapComponent()
Returns the initial path component of a map path.
boolean equals(@Nullable final Object obj)
Definition: MapFile.java:122
String HP
The attribute name of the "hp" attribute.
Definition: BaseObject.java:90
final String mapName
The map name of the remembered exit.
final MapFile mapFile
The file of the map that contains the remembered exit.
Point getMapCoordinate()
Returns the coordinate of the remembered exit.
Stores information about a remembered exit location.
String SP
The attribute name of the "sp" attribute.
Definition: BaseObject.java:96
String NAME
The attribute name of the object&#39;s name.
Definition: BaseObject.java:60
void updateExitObject(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final boolean updateName, @Nullable final MapFile sourceMapFile)
Updates exit information.
MapFile getMapFile()
Returns the file of the map that contains the remembered exit.
The location of a map file with a map directory.
Definition: MapFile.java:31