 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.model.baseobject;
22 import java.awt.Point;
23 import java.util.Collection;
24 import java.util.Objects;
25 import javax.swing.ImageIcon;
36 import org.jetbrains.annotations.NotNull;
37 import org.jetbrains.annotations.Nullable;
46 public abstract class AbstractBaseObject<G
extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>, T extends
BaseObject<G, A, R, T>> extends
GameObjectContainer<G, A, R> implements
BaseObject<G, A, R, T> {
199 if (this.typeNo ==
typeNo) {
219 if (this.faceName == effectiveFaceName) {
225 this.faceName = effectiveFaceName;
258 public boolean hasAttribute(@NotNull
final String attributeName,
final boolean queryArchetype) {
284 public int getAttributeInt(@NotNull
final String attributeName,
final boolean queryArchetype) {
294 public long getAttributeLong(@NotNull
final String attributeName,
final boolean queryArchetype) {
304 public double getAttributeDouble(@NotNull
final String attributeName,
final boolean queryArchetype) {
315 final boolean sameAsInArchetype =
getArchetype().getAttributeString(attributeName).equals(value);
325 final boolean sameAsInArchetype =
getArchetype().getAttributeInt(attributeName) == value;
364 final int multiShapeID =
getArchetype().getMultiShapeID();
365 assert
multi !=
null;
416 if (!queryArchetype) {
420 return archetype ==
this ? null : archetype.getMsgText(queryArchetype);
426 if (this.msgText ==
null ? trimmedMsgText ==
null : this.msgText.toString().equals(trimmedMsgText)) {
432 if (trimmedMsgText ==
null) {
434 }
else if (this.msgText ==
null) {
435 this.msgText =
new StringBuilder(trimmedMsgText);
437 this.msgText.setLength(0);
438 assert this.msgText !=
null;
439 this.msgText.append(trimmedMsgText);
493 assert
multi !=
null;
494 tail.setMulti(
multi);
495 assert
multi !=
null;
556 @SuppressWarnings(
"unchecked")
565 return clone.getThis();
570 gameObject.setContainer(
this, 0, 0);
585 final String newObjName = objName2.intern();
588 if (this.objName == newObjName) {
594 this.objName = newObjName;
603 final String baseName;
606 final String archObjName = archetype.
getObjName();
607 baseName = archObjName.isEmpty() ? archetype.
getArchetypeName() : archObjName;
613 return title.isEmpty() ? baseName : baseName +
" " + title;
643 if (!
objName.equals(archetype.getObjName())) {
649 if (
msgText !=
null && !
msgText.toString().equals(archetype.getMsgText(
false))) {
658 return typeNo == archetype.getTypeNo();
725 part.notifyBeginChange();
738 part.notifyEndChange();
752 part.notifyTransientChange();
771 if (this.animName == newAnimName) {
777 this.animName = newAnimName;
791 return multi !=
null;
817 if (this.faceObjName == newFaceObjName) {
823 this.faceObjName = newFaceObjName;
837 @Nullable String effectiveAnimName;
839 effectiveAnimName =
null;
848 effectiveAnimName =
null;
851 if (effectiveAnimName !=
null && effectiveAnimName.equals(
"NONE")) {
852 effectiveAnimName =
null;
855 @Nullable String effectiveFaceObjName;
856 if (effectiveAnimName ==
null) {
864 effectiveFaceObjName =
null;
869 if (animationObject ==
null) {
870 effectiveFaceObjName =
null;
874 }
catch (
final IndexOutOfBoundsException ignored) {
875 effectiveFaceObjName =
null;
906 if (this.loreText.equals(trimmedLoreText)) {
912 this.loreText = trimmedLoreText.intern();
926 public String
toString(@NotNull
final String format) {
927 final StringBuilder sb =
new StringBuilder();
928 final char[] chars = format.toCharArray();
930 while (pos < chars.length) {
931 if (chars[pos] ==
'$' && pos + 2 < chars.length && chars[pos + 1] ==
'{') {
933 final int startPos = pos;
935 while (pos < chars.length) {
936 if (chars[pos] ==
'}') {
942 }
else if (chars[pos] ==
'$' && pos + 1 < chars.length && chars[pos + 1] ==
'{') {
953 final int endPos = pos - 1;
954 assert startPos <= endPos;
955 final CharSequence spec =
new String(chars, startPos, endPos - startPos);
957 if (tmp.length < 2) {
958 if (tmp[0].equals(
"NAME")) {
970 sb.append(chars[pos]);
975 return sb.toString();
983 protected abstract T
getThis();
int typeNo
The object type.
boolean isDefaultGameObject()
FACE
This GameObject has a normal face defined.
static int parseInt(@NotNull final String s)
Parses an integer string.
void setLoreText(@NotNull final CharSequence loreText)
String getArchetypeName()
Returns the name of this archetype.
abstract void notifyEndChange()
@noinspection AbstractMethodOverridesAbstractMethod // needed because of public modifier
GameObjectText gameObjectText
The object text of this game object.
int getMaxY()
Returns the maximum y-coordinate of any part.
void setMapX(final int mapX)
void setObjectText(@NotNull final String objectText)
ARCHETYPE_ANIM
This GameObject is animated but doesn't define an animation and thus inherited the animation from its...
Enumeration describing the state of the face.
Base package of all Gridarta classes.
void setAttributeString(@NotNull final String attributeName, @NotNull final String value)
int getAttributeInt(@NotNull final String attributeName, final boolean queryArchetype)
FaceSource getFaceObjSource()
static final Pattern PATTERN_COLON
The pattern that matches a single colon (":").
ANIM
This GameObject has an animation defined.
AnimationObjects is a container for AnimationObjects.
String loreText
The map lore.
Class related to GameObject to store multi-part information.
boolean hasSameContents( @NotNull final GameObjectContainer<?, ?, ?> gameObjectContainer)
Compares this object to another game object container.
A set of key/value attributes.
void beginGameObjectChange()
Records that this game object is about to change.
int getMultiRefCount()
Returns the number of parts this multi-part object contains.
String getAttributeValue(@NotNull final String attributeName)
Returns an attribute value by attribute name.
E get(@NotNull String objectName)
Gets a AbstractNamedObject.
void setFaceName(@NotNull final String faceName)
Sets the face name.
Default implementation for GameObject implementing classes.
double getAttributeDouble(@NotNull final String attributeName, final boolean queryArchetype)
int direction
The direction determines to which direction the GameObject's face is facing.
String TITLE
The attribute name of the object's title.
String faceName
The name of the face.
static final long serialVersionUID
The serial version UID.
void setMultiShapeID(final int multiShapeID)
Sets the shape ID of this object.
void transientGameObjectChange()
Records that this game object has changed but need not be restored by undo/redo actions.
abstract void notifyBeginChange()
@noinspection AbstractMethodOverridesAbstractMethod // needed because of public modifier
void updateArchetype()
Called whenever getArchetype() has changed.
int mapX
The map x position if on map.
long getAttributeLong(@NotNull final String attributeName)
Provider for faces of GameObjects and Archetypes.
Reflects a game object (object on a map).
boolean hasObjectText()
Returns whether an object text is set.
String NAME
The attribute name of the object's name.
long getAttributeLong(@NotNull final String attributeName, final boolean queryArchetype)
static long parseLong(@NotNull final String s)
Parses a long string.
void setMulti(@NotNull final MultiArchData< G, A, R, T > multi)
boolean isEqual(@NotNull final BaseObject<?, ?, ?, ?> gameObject)
String IS_TURNABLE
The name of the "is_turnable" attribute.
String IS_ANIMATED
The attribute name of the "is_animated" flag.
boolean hasAttribute(@NotNull final String attributeName)
StringBuilder msgText
The message text.
R getArchetype()
Returns the Archetype this GameObject is based on.
void setFaceObjName(@Nullable final String faceObjName)
Sets the effective face name.
void setMapY(final int mapY)
void addMsgTextLine(@NotNull final String text)
void setTypeNo(final int typeNo)
Sets the type number of this Archetype.
int getAttributeInt(@NotNull final String attributeName)
MultiArchData< G, A, R, T > getMulti()
Returns the MultiArchData for this base object.
static String removeTrailingWhitespace(@NotNull final CharSequence str)
Removes trailing whitespace from a string.
GameObjects are the objects based on Archetypes found on maps.
boolean setObjectText(@NotNull final String objectText, @NotNull final AbstractBaseObject<?, ?, ?, ?> baseObject)
Sets the object text.
int mapY
The map y position if on map.
int getMaxX()
Returns the maximum x-coordinate of any part.
void setMsgText(@Nullable final String msgText)
double getAttributeDouble(@NotNull final String attributeName)
String FACE
The attribute name of the object's face.
Interface for MapArchObjects.
ImageIcon getNormalImage()
String animName
The object's animation animation.
String getMsgText(final boolean queryArchetype)
T getNext(@NotNull final T ob)
Returns the part following a given part.
boolean removeAttribute(@NotNull final String attributeName, @NotNull final AbstractBaseObject<?, ?, ?, ?> baseObject)
Removes an attribute.
abstract String getEffectiveFaceName(@NotNull String faceName)
Returns the effective face name for faceName for a given real face name.
String getAttributeValue(@NotNull final String attributeName)
Returns an attribute value by attribute name.
Collection< String > getAttributeKeys()
Returns all attribute keys of this object.
T getHead()
Returns the head part of this multi-part object.
void setEditType(final int editType)
public< G extends GameObject< G, A, R >, A extends MapArchObject< A >, R extends Archetype< G, A, R > > ImageIcon getFace(@NotNull final BaseObject< G, A, R, ?> baseObject)
Returns the face of a BaseObject as an ImageIcon.
void setAnimName(@NotNull final String animName)
Sets object animation.
FaceSource faceObjSource
The state where the face comes from.
int getSizeX()
Returns the horizontal extent in squares.
Utility class for string manipulation.
AbstractBaseObject(@NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects)
Creates a new instance.
void setObjName(@NotNull final String objName)
Sets the name of this object.
void setAttributeInt(@NotNull final String attributeName, final int value)
static double parseDouble(@NotNull final String s)
Parses a double string.
ImageIcon normalFace
The normal face.
abstract T getThis()
Returns.
String getAttributeString(@NotNull final String attributeName)
String getObjName()
Returns the name of the object as shown to the player.
void initMultiData()
Initialize the multi-part data object - must only be called for multi-part arches.
static CharSequence ensureTrailingNewline(@NotNull final String str)
Returns a given string which ends with a trailing newline character; empty strings remain empty.
boolean hasAttribute(@NotNull final String attributeName, final boolean queryArchetype)
void setThisContainer(@NotNull final G gameObject)
int getMinY()
Returns the minimum y-coordinate of any part.
String objName
The name of this object.
The face is the appearance of an object.
MultiArchData< G, A, R, T > multi
Data for multi-part objects.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
void addObjectText(@NotNull final String line)
void addPart(@NotNull final T tail)
Adds a part to this multi-part object.
void removeAttribute(@NotNull final String attributeName)
An AnimationObject reflects the animation ("@code anim\n @endcode " ...
ARCHETYPE_FACE
This GameObject has no face defined and thus inherited the face from its archetype.
String faceObjName
Face name, can be from animation or face.
int getSizeY()
Returns the vertical extent in squares.
final AnimationObjects animationObjects
The AnimationObjects for looking up animations.
void endGameObjectChange()
Records that this game object has changed.
String TYPE
The attribute name of the object's type.
static String removeTrailingWhitespaceFromLines(@NotNull final CharSequence str)
Removes trailing whitespace from all lines of a string.
void notifyTransientChange()
Notifies the map model that this container has changed but need not be restored by undo/redo.
int countInvObjects()
Counts the number of all inventory items (recursively).
FACE_NOT_FOUND
The face of this GameObject was not found.
Base class for classes that contain GameObjects as children in the sense of containment.
void addTailPart(@NotNull final T tail)
Collection< String > getAttributeKeys()
Returns all attribute keys of this object.
boolean setAttributeValue(@NotNull final String attributeName, final boolean sameAsInArchetype, @NotNull final String value, @NotNull final AbstractBaseObject<?, ?, ?, ?> baseObject)
Updates an attribute's value.
String toString(@NotNull final String format)
String ANIMATION
The attribute name of the object's animation.
String getFirstFrame(int facing)
Get the first frame.
boolean addObjectText(@NotNull final String line, @NotNull final AbstractBaseObject<?, ?, ?, ?> baseObject)
Appends a line to the object text.
String getObjectText()
Returns the object text.
ImageIcon getImageIconForFacename(@NotNull final String faceObjName)
Returns the ImageIcon for a given face object name.
Utility class for parsing strings into numbers.
String DIRECTION
The attribute name of the object's direction.
int getMinX()
Returns the minimum x-coordinate of any part.
void updateCachedAttributes()
Updates attribute values that are cached.
final transient FaceObjectProviders faceObjectProviders
The FaceObjectProviders for looking up faces.