Gridarta Editor
AbstractArchetype.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.archetype;
21 
31 import org.jetbrains.annotations.NotNull;
32 import org.jetbrains.annotations.Nullable;
33 
38 public abstract class AbstractArchetype<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractBaseObject<G, A, R, R> implements Archetype<G, A, R> {
39 
43  private static final long serialVersionUID = 1L;
44 
49  @NotNull
50  private String archetypeName;
51 
57  private int multiX;
58 
64  private int multiY;
65 
72  private boolean isLowestPart = true;
73 
78  private int multiShapeID;
79 
84  private int multiPartNr;
85 
90  @Nullable
91  private String editorFolder;
92 
100  private boolean artifact;
101 
109  protected AbstractArchetype(@NotNull final String archetypeName, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects) {
110  super(faceObjectProviders, animationObjects);
111  this.archetypeName = archetypeName.intern();
112  updateArchetype();
113  }
114 
115  @Nullable
116  @Override
118  return null; // archetypes are never part of a container
119  }
120 
121  @Override
122  @NotNull
123  public String getAttributeString(@NotNull final String attributeName, final boolean queryArchetype) {
124  final String result = getAttributeValue(attributeName);
125  return result == null ? "" : result;
126  }
127 
128  @Nullable
129  @Override
130  protected String getEffectiveFaceName(@NotNull final String faceName) {
131  final String normalizedFaceName = faceName.isEmpty() ? null : faceName.intern();
132  //Strings are interned
133  //noinspection StringEquality
134  return normalizedFaceName != null && !normalizedFaceName.isEmpty() ? normalizedFaceName : null;
135  }
136 
140  @Override
141  public void notifyBeginChange() {
142  // ignore
143  }
144 
148  @Override
149  public void notifyEndChange() {
150  // ignore
151  }
152 
156  @Override
157  public void notifyTransientChange() {
158  // ignore
159  }
160 
161  @NotNull
162  @Override
163  public R getArchetype() {
164  return getThis();
165  }
166 
167  @NotNull
168  @Override
169  @SuppressWarnings("unchecked")
170  public R clone() {
171  //noinspection OverriddenMethodCallDuringObjectConstruction
173  return clone.getThis();
174  }
175 
176  @Nullable
177  @Override
178  public G asGameObject() {
179  return null;
180  }
181 
182  @NotNull
183  @Override
184  public G newInstance(@NotNull final GameObjectFactory<G, A, R> gameObjectFactory) {
185  return gameObjectFactory.createGameObject(getThis());
186  }
187 
188  @Override
189  public void visit(@NotNull final BaseObjectVisitor<G, A, R> baseObjectVisitor) {
190  baseObjectVisitor.visit(this);
191  }
192 
193  @NotNull
194  @Override
195  public String getArchetypeName() {
196  return archetypeName;
197  }
198 
199  @Override
200  public void setArchetypeName(@NotNull final String archetypeName) {
201  this.archetypeName = archetypeName;
202  }
203 
204  @Override
205  public void setMultiX(final int multiX) {
206  this.multiX = multiX;
207  }
208 
209  @Override
210  public void setMultiY(final int multiY) {
211  this.multiY = multiY;
212  }
213 
214  @Override
215  public int getMultiX() {
216  return multiX;
217  }
218 
219  @Override
220  public int getMultiY() {
221  return multiY;
222  }
223 
224  @Override
225  public boolean isLowestPart() {
226  return isLowestPart;
227  }
228 
229  @Override
230  public void setLowestPart(final boolean isLowestPart) {
231  this.isLowestPart = isLowestPart;
232  }
233 
234  @Override
235  public int getMultiShapeID() {
236  return multiShapeID;
237  }
238 
239  @Override
240  public void setMultiShapeID(final int multiShapeID) {
241  this.multiShapeID = multiShapeID;
243  if (multi != null) {
244  multi.setMultiShapeID(multiShapeID);
245  }
246  }
247 
248  @Override
249  public int getMultiPartNr() {
250  return multiPartNr;
251  }
252 
253  @Override
254  public void setMultiPartNr(final int multiPartNr) {
255  this.multiPartNr = multiPartNr;
256  }
257 
258  @Nullable
259  @Override
260  public String getEditorFolder() {
261  return editorFolder;
262  }
263 
264  @Override
265  public void setEditorFolder(@Nullable final String editorFolder) {
266  this.editorFolder = editorFolder;
267  }
268 
269  @Override
270  public boolean isArtifact() {
271  return artifact;
272  }
273 
274  @Override
275  public void setArtifact() {
276  artifact = true;
277  }
278 
279 }
void setEditorFolder(@Nullable final String editorFolder)
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
void notifyTransientChange()
NoopMethodInAbstractClass
MultiArchData< G, A, R, T > getMulti()
Returns the MultiArchData for this base object.
int multiX
The x-distance of this part to the head part.
String archetypeName
The name of this archetype.
boolean artifact
If this flag is set, this Archetype is not a "real" Archetype but comes from the artifacts file...
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
Abstract factory for creating GameObject instances.
int multiY
The y-distance of this part to the head part.
final AnimationObjects animationObjects
The AnimationObjects for looking up animations.
AnimationObjects is a container for AnimationObjects.
void notifyBeginChange()
NoopMethodInAbstractClass
GameObjects are the objects based on Archetypes found on maps.
String getEffectiveFaceName(@NotNull final String faceName)
void setArchetypeName(@NotNull final String archetypeName)
G newInstance(@NotNull final GameObjectFactory< G, A, R > gameObjectFactory)
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
static final long serialVersionUID
The serial version UID.
void visit(@NotNull final BaseObjectVisitor< G, A, R > baseObjectVisitor)
Default implementation for GameObject implementing classes.
final transient FaceObjectProviders faceObjectProviders
The FaceObjectProviders for looking up faces.
String getAttributeString(@NotNull final String attributeName, final boolean queryArchetype)
String getAttributeValue(@NotNull final String attributeName)
Returns an attribute value by attribute name.
MultiArchData< G, A, R, T > multi
Data for multi-part objects.
Abstract base class for Archetype implementations.
void updateArchetype()
Called whenever getArchetype() has changed.
String editorFolder
The location in the archetype selector.
AbstractArchetype(@NotNull final String archetypeName, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects)
Creates a new instance.
void setMultiShapeID(final int multiShapeID)
Set the shape ID of this object.
Class related to GameObject to store multi-part information.