Gridarta Editor
DefaultFaceObject.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.face;
21 
22 import java.util.regex.Matcher;
23 import java.util.regex.Pattern;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28 
45 public class DefaultFaceObject extends AbstractNamedObject implements FaceObject {
46 
50  private static final long serialVersionUID = 1L;
51 
55  @NotNull
56  private static final Pattern ALTERNATIVE_FACE_NAME_PATTERN = Pattern.compile("\\.a\\.");
57 
62  @NotNull
63  private final String faceName;
64 
69  @NotNull
70  private final String originalFilename;
71 
76  private final int offset;
77 
82  private final int size;
83 
90  private final boolean isDouble;
91 
98  private final boolean isUp;
99 
104  @Nullable
105  private final String alternativeFaceName;
106 
117  public DefaultFaceObject(@NotNull final String faceName, @NotNull final String originalFilename, final int offset, final int size) {
118  super(originalFilename);
119  this.faceName = faceName;
120  this.originalFilename = originalFilename;
121  this.offset = offset;
122  this.size = size;
123  isUp = faceName.contains(".u.");
124  isDouble = faceName.contains(".d.");
125  final Matcher matcher = ALTERNATIVE_FACE_NAME_PATTERN.matcher(faceName);
126  alternativeFaceName = matcher.find() ? matcher.replaceFirst(".b.").intern() : null;
127  }
128 
132  @NotNull
133  @Override
134  public String getName() {
135  return faceName;
136  }
137 
141  @NotNull
142  @Override
143  public String getFaceName() {
144  return faceName;
145  }
146 
147  @NotNull
148  @Override
149  public String getOriginalFilename() {
150  return originalFilename;
151  }
152 
157  public int getOffset() {
158  return offset;
159  }
160 
165  public int getSize() {
166  return size;
167  }
168 
169  @Override
170  public boolean isUp() {
171  return isUp;
172  }
173 
174  @Override
175  public boolean isDouble() {
176  return isDouble;
177  }
178 
179  @Nullable
180  @Override
181  public String getAlternativeFaceName() {
182  return alternativeFaceName;
183  }
184 
185  @NotNull
186  @Override
187  public String getDisplayIconName() {
188  return faceName;
189  }
190 
195  @Override
196  public int compareTo(@NotNull final NamedObject o) {
197  final boolean iAmBug = faceName.equals("bug.111") || faceName.equals("bug.101");
198  final boolean otherIsBug = o.getName().equals("bug.111") || o.getName().equals("bug.101");
199  if (iAmBug && otherIsBug) {
200  return 0;
201  }
202  if (iAmBug) {
203  return -1;
204  }
205  if (otherIsBug) {
206  return 1;
207  }
208  return super.compareTo(o);
209  }
210 
211  @Override
212  public int hashCode() {
213  return faceName.hashCode() ^ super.hashCode();
214  }
215 
216  @Override
217  public boolean equals(@Nullable final Object obj) {
218  if (obj == this) {
219  return true;
220  }
221  if (obj == null || obj.getClass() != getClass()) {
222  return false;
223  }
224  final DefaultFaceObject defaultFaceObject = (DefaultFaceObject) obj;
225  return faceName.equals(defaultFaceObject.faceName) && super.equals(obj);
226  }
227 
228 }
final boolean isDouble
Whether this face is a "double" face.
String getDisplayIconName()
Returns the face name of the display icon for this AbstractNamedObject.
The data package contains classes for handling data that is organized in a tree.
static final long serialVersionUID
The serial version UID.
Common interface for FaceObject.
Definition: FaceObject.java:30
final int size
The size in the file the face was loaded from.
final int offset
The offset in the file the face was loaded from.
static final Pattern ALTERNATIVE_FACE_NAME_PATTERN
A Pattern matching face names having alternative face names.
int compareTo(@NotNull final NamedObject o)
Overridden to sort bug.101 and bug.111 before all other faces.
boolean equals(@Nullable final Object obj)
Base package of all Gridarta classes.
final boolean isUp
Whether this face is an "up" face.
String getAlternativeFaceName()
Returns the alternative face name for image.a.nnn faces.
int getOffset()
Get the offset of this face in the actualFilename.
final String alternativeFaceName
The alternative face name for image.a.nnn faces.
int getSize()
Get the size of this face in the actualFilename.
boolean isUp()
Return whether this face is an up face.
boolean isDouble()
Return whether this face is a double face.
String getOriginalFilename()
Get the original filename of this face.
A FaceObject stores information and meta information about a face and provides methods for accessing ...
final String originalFilename
The filename the face originally came from (origin location).
DefaultFaceObject(@NotNull final String faceName, @NotNull final String originalFilename, final int offset, final int size)
Create a FaceObject.