20 package net.sf.gridarta.model.baseobject;
22 import java.awt.Point;
23 import java.util.Collection;
24 import javax.swing.ImageIcon;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
45 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> {
198 if (this.typeNo == typeNo) {
214 @SuppressWarnings(
"NullableProblems")
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;
381 if (this.editType == editType) {
419 if (this.msgText == null ? trimmedMsgText == null : this.msgText.toString().equals(trimmedMsgText)) {
425 if (trimmedMsgText == null) {
427 }
else if (this.msgText == null) {
428 this.msgText =
new StringBuilder(trimmedMsgText);
430 this.msgText.setLength(0);
431 assert this.msgText != null;
432 this.msgText.append(trimmedMsgText);
486 assert
multi != null;
487 tail.setMulti(
multi);
488 assert
multi != null;
549 @SuppressWarnings(
"unchecked")
564 gameObject.setContainer(
this, 0, 0);
579 final String newObjName = objName2.intern();
582 if (this.objName == newObjName) {
588 this.objName = newObjName;
597 final String baseName;
600 final String archObjName = archetype.
getObjName();
601 if (archObjName.isEmpty()) {
604 baseName = archObjName;
611 return title.isEmpty() ? baseName : baseName +
" " + title;
641 if (!
objName.equals(archetype.getObjName())) {
647 if (
msgText != null && !
msgText.toString().equals(archetype.getMsgText())) {
658 return typeNo == archetype.getTypeNo();
725 part.notifyBeginChange();
738 part.notifyEndChange();
752 part.notifyTransientChange();
767 @SuppressWarnings(
"NullableProblems")
792 return multi != null;
805 @SuppressWarnings(
"NullableProblems")
816 final String newFaceObjName = faceObjName != null ? faceObjName.intern() : null;
819 if (this.faceObjName == newFaceObjName) {
825 this.faceObjName = newFaceObjName;
839 @Nullable String effectiveAnimName;
841 effectiveAnimName = null;
850 effectiveAnimName = null;
853 if (effectiveAnimName != null && effectiveAnimName.equals(
"NONE")) {
854 effectiveAnimName = null;
857 @Nullable String effectiveFaceObjName;
858 if (effectiveAnimName != null) {
860 if (animationObject == null) {
861 effectiveFaceObjName = null;
865 }
catch (
final IndexOutOfBoundsException ignored) {
866 effectiveFaceObjName = null;
877 effectiveFaceObjName = null;
908 if (this.loreText.equals(trimmedLoreText)) {
914 this.loreText = trimmedLoreText.intern();
928 public String
toString(@NotNull
final String format) {
929 final StringBuilder sb =
new StringBuilder();
930 final char[] chars = format.toCharArray();
932 while (pos < chars.length) {
933 if (chars[pos] ==
'$' && pos + 2 < chars.length && chars[pos + 1] ==
'{') {
935 final int startPos = pos;
937 while (pos < chars.length) {
938 if (chars[pos] ==
'}') {
944 }
else if (chars[pos] ==
'$' && pos + 1 < chars.length && chars[pos + 1] ==
'{') {
955 final int endPos = pos - 1;
956 assert startPos <= endPos;
957 final CharSequence spec =
new String(chars, startPos, endPos - startPos);
959 if (tmp.length < 2) {
960 if (tmp[0].equals(
"NAME")) {
972 sb.append(chars[pos]);
977 return sb.toString();
985 protected abstract T
getThis();
String getObjectText()
Returns the object text.
String IS_TURNABLE
The name of the "is_turnable" attribute.
ImageIcon normalFace
The normal face.
String faceName
The name of the face.
void endGameObjectChange()
Records that this game object has changed.
int getSizeX()
Determine the horizontal extent in squares.
String getAttributeValue(@NotNull final String attributeName)
Returns an attribute value by attribute name.
Utility class for string manipulation.
void setObjectText(@NotNull final String objectText)
Collection< String > getAttributeKeys()
Returns all attribute keys of this object.
abstract T getThis()
Returns.
int getMaxX()
Determine the maximum x-coordinate of any part.
boolean removeAttribute(@NotNull final String attributeName, @NotNull final AbstractBaseObject<?, ?, ?, ?> baseObject)
Removes an attribute.
int getAttributeInt(@NotNull final String attributeName, final boolean queryArchetype)
String getObjName()
Returns the name of the object as shown to the player.
static String removeTrailingWhitespace(@NotNull final CharSequence str)
Removes trailing whitespace from a string.
void setTypeNo(final int typeNo)
Sets the type number of this Archetype.
int getSizeY()
Determine the vertical extent in squares.
void setAttributeString(@NotNull final String attributeName, @NotNull final String value)
boolean addObjectText(@NotNull final String line, @NotNull final AbstractBaseObject<?, ?, ?, ?> baseObject)
Appends a line to the object text.
void addTailPart(@NotNull final T tail)
void notifyTransientChange()
Notifies the map model that this container has changed but need not be restored by undo/redo...
Enumeration describing the state of the face.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
String ANIMATION
The attribute name of the object's animation.
boolean hasAttribute(@NotNull final String attributeName)
String FACE
The attribute name of the object's face.
double getAttributeDouble(@NotNull final String attributeName, final boolean queryArchetype)
Utility class for parsing strings into numbers.
boolean setObjectText(@NotNull final String objectText, @NotNull final AbstractBaseObject<?, ?, ?, ?> baseObject)
Sets the object text.
double getAttributeDouble(@NotNull final String attributeName)
int getMinX()
Determine the minimum x-coordinate of any part.
abstract void notifyBeginChange()
AbstractMethodOverridesAbstractMethod // needed because of public modifier
Base class for classes that contain GameObjects as children in the sense of containment.
static CharSequence ensureTrailingNewline(@NotNull final String str)
Returns a given string which ends with a trailing newline character; empty strings remain empty...
String getArchetypeName()
Returns the name of this archetype.
ANIM
This GameObject has an animation defined.
String toString(@NotNull final String format)
String getFirstFrame(int facing)
Get the first frame.
MultiArchData< G, A, R, T > getMulti()
Returns the MultiArchData for this base object.
long getAttributeLong(@NotNull final String attributeName, final boolean queryArchetype)
void addMsgTextLine(@NotNull final String text)
boolean setAttributeValue(@NotNull final String attributeName, final boolean sameAsInArchetype, @NotNull final String value, @NotNull final AbstractBaseObject<?, ?, ?, ?> baseObject)
Updates an attribute's value.
FACE
This GameObject has a normal face defined.
FaceSource faceObjSource
The state where the face comes from.
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 setLoreText(@NotNull final CharSequence loreText)
Base package of all Gridarta classes.
ARCHETYPE_FACE
This GameObject has no face defined and thus inherited the face from its archetype.
Reflects a game object (object on a map).
void beginGameObjectChange()
Records that this game object is about to change.
int mapY
The map y position if on map.
boolean isEqual(@NotNull final BaseObject<?, ?, ?, ?> gameObject)
boolean hasAttribute(@NotNull final String attributeName, final boolean queryArchetype)
static double parseDouble(@NotNull final String s)
Parses a double string.
static int parseInt(@NotNull final String s)
Parses an integer string.
String DIRECTION
The attribute name of the object's direction.
E get(@NotNull String objectName)
Gets a AbstractNamedObject.
StringBuilder msgText
The message text.
final AnimationObjects animationObjects
The AnimationObjects for looking up animations.
int getAttributeInt(@NotNull final String attributeName)
void setFaceObjName(@Nullable final String faceObjName)
Sets the effective face name.
String objName
The name of this object.
void setEditType(final int editType)
AnimationObjects is a container for AnimationObjects.
GameObjectText gameObjectText
The object text of this game object.
GameObjects are the objects based on Archetypes found on maps.
ImageIcon getNormalImage()
void setMapY(final int mapY)
void setMsgText(@Nullable final String msgText)
An AnimationObject reflects the animation ("@code anim\n @endcode " ...
abstract void notifyEndChange()
AbstractMethodOverridesAbstractMethod // needed because of public modifier
boolean isDefaultGameObject()
void setMulti(@NotNull final MultiArchData< G, A, R, T > multi)
void setThisContainer(@NotNull final G gameObject)
void setAttributeInt(@NotNull final String attributeName, final int value)
String animName
The object's animation animation.
int countInvObjects()
Counts the number of all inventory items (recursively).
boolean hasObjectText()
Returns whether an object text is set.
R getArchetype()
Returns the Archetype this GameObject is based on.
void setObjName(@NotNull final String objName)
Sets the name of this object.
T getNext(@NotNull final T ob)
Return the part following a given part.
FaceSource getFaceObjSource()
Provider for faces of GameObjects and Archetypes.
The face is the appearance of an object.
String IS_ANIMATED
The attribute name of the "is_animated" flag.
boolean hasSameContents( @NotNull final GameObjectContainer<?, ?, ?> gameObjectContainer)
Compare this object to another game object container.
void removeAttribute(@NotNull final String attributeName)
T getHead()
Return the head part of this multi-part object.
abstract String getEffectiveFaceName(@NotNull String faceName)
Returns the effective face name for faceName for a given real face name.
void addPart(@NotNull final T tail)
Add a part to this multi-part object.
String NAME
The attribute name of the object's name.
int getMaxY()
Determine the maximum y-coordinate of any part.
Default implementation for GameObject implementing classes.
int typeNo
The object type.
ImageIcon getImageIconForFacename(@NotNull final String faceObjName)
Returns the ImageIcon for a given face object name.
final transient FaceObjectProviders faceObjectProviders
The FaceObjectProviders for looking up faces.
String loreText
The map lore.
String faceObjName
Face name, can be from animation or face.
static long parseLong(@NotNull final String s)
Parses a long string.
String getAttributeString(@NotNull final String attributeName)
FACE_NOT_FOUND
The face of this GameObject was not found.
static final Pattern PATTERN_COLON
The pattern that matches a single colon (":").
String getAttributeValue(@NotNull final String attributeName)
Returns an attribute value by attribute name.
MultiArchData< G, A, R, T > multi
Data for multi-part objects.
String TITLE
The attribute name of the object's title.
void updateCachedAttributes()
Updates attribute values that are cached.
void updateArchetype()
Called whenever getArchetype() has changed.
Collection< String > getAttributeKeys()
Returns all attribute keys of this object.
A set of key/value attributes.
void initMultiData()
Initialize the multi-part data object - must only be called for multi-part arches.
void setFaceName(@NotNull final String faceName)
Sets the face name.
int getMultiRefCount()
Returns the number of parts this multi-part object contains.
void setAnimName(@NotNull final String animName)
Sets object animation.
static final long serialVersionUID
The serial version UID.
void setMapX(final int mapX)
long getAttributeLong(@NotNull final String attributeName)
AbstractBaseObject(@NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects)
Creates a new instance.
ARCHETYPE_ANIM
This GameObject is animated but doesn't define an animation and thus inherited the animation from its...
int getMinY()
Determine the minimum y-coordinate of any part.
Interface for MapArchObjects.
void transientGameObjectChange()
Records that this game object has changed but need not be restored by undo/redo actions.
void setMultiShapeID(final int multiShapeID)
Set the shape ID of this object.
void addObjectText(@NotNull final String line)
int mapX
The map x position if on map.
int direction
The direction determines to which direction the GameObject's face is facing.
Class related to GameObject to store multi-part information.