 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.model.maparchobject;
22 import java.awt.Point;
24 import java.util.Arrays;
25 import java.util.Collection;
26 import java.util.concurrent.CopyOnWriteArrayList;
27 import java.util.regex.Matcher;
28 import java.util.regex.Pattern;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
77 private static final Pattern
MAP_FILE_NAME_PATTERN = Pattern.compile(
"((?:(?!_(?:[\\d-]+))[\\w_])+)_([\\d-]+)_([\\d-]+)(?:_([\\d-]+))?");
83 private final StringBuilder
msgText =
new StringBuilder();
151 private final Collection<MapArchObjectListener>
listenerList =
new CopyOnWriteArrayList<>();
188 msgText.append(mapArchObject.msgText);
189 mapSize = mapArchObject.mapSize;
190 mapName = mapArchObject.mapName;
191 enterX = mapArchObject.enterX;
192 enterY = mapArchObject.enterY;
193 outdoor = mapArchObject.outdoor;
199 tilePaths = mapArchObject.tilePaths.clone();
210 if (this.mapSize.equals(
mapSize)) {
217 listener.mapSizeChanged(
mapSize);
229 final String trimmedName =
name.trim();
230 if (
mapName.equals(trimmedName)) {
245 if (this.enterX ==
enterX) {
260 if (this.enterY ==
enterY) {
377 if (
tilePaths[direction.ordinal()].equals(tilePath)) {
381 tilePaths[direction.ordinal()] = tilePath;
388 if (mapFile ==
null) {
398 final int x = Integer.parseInt(m.group(2));
399 final int y = Integer.parseInt(m.group(3));
400 final int z = m.group(4) ==
null ? 0 : Integer.parseInt(m.group(4));
402 final StringBuilder sb =
new StringBuilder(m.group(1));
403 sb.append(String.format(
"_%d_%d", x + direction.getDx(), y + direction.getDy()));
404 if (z + direction.getDz() != 0) {
405 sb.append(String.format(
"_%d", z + direction.getDz()));
407 return sb.toString();
412 if (mapFile ==
null) {
417 if (!
tilePaths[direction.ordinal()].isEmpty()) {
422 if (path.isEmpty()) {
427 final String realPath = mapsDirectory +
"/" + mapPath +
"/" + path;
428 final File file =
new File(realPath);
430 if (file.exists() && file.isFile()) {
442 public void setState(@NotNull
final A mapArchObject) {
461 public boolean equals(@Nullable
final Object obj) {
465 if (obj ==
null || obj.getClass() != getClass()) {
504 throw new IllegalStateException(
"A transaction must only be used by one thread.");
518 throw new IllegalStateException(
"Tried to end a transaction but no transaction was open.");
549 listener.mapMetaChanged();
554 public void addText(@NotNull
final String text) {
555 if (text.isEmpty()) {
565 if (
msgText.toString().equals(text)) {
582 final String modifiedAttribute =
MODIFIED_ATTRIBUTE +
" " + String.format(
"%tF", System.currentTimeMillis()) +
" " + userName;
585 if (!matcher.find()) {
588 msgText.append(modifiedAttribute);
590 }
else if (!matcher.group().equals(modifiedAttribute)) {
592 msgText.replace(matcher.start(), matcher.end(), modifiedAttribute);
int getWidth()
Returns the width of the area.
static final Pattern MAP_FILE_NAME_PATTERN
The pattern used to determine the base map name and its x/y/z coordinates from a filename.
int resetTimeout
The number of ticks that need to elapse before this map will be reset.
int enterX
The x coordinate for entering the map.
A MapPath that is absolute, that is, it starts with a "/".
Base package of all Gridarta classes.
boolean equals(@Nullable final Object obj)
boolean isPointValid(@Nullable final Point pos)
static final long serialVersionUID
The serial version UID.
void calculateTilePaths(@Nullable final MapFile mapFile, @NotNull final File mapsDirectory)
Interface for listeners listening on map arch object changes.
String mapName
The name of this map.
void addText(@NotNull final String text)
int enterY
The y coordinate for entering the map.
void setMapName(@NotNull final String name)
void setFixedReset(final boolean fixedReset)
Size2D mapSize
The size of the map reflected by this map arch object.
void setSwapTime(final int swapTime)
void setMapSize(@NotNull final Size2D mapSize)
int difficulty
The map difficulty.
void addMapArchObjectListener(@NotNull final MapArchObjectListener listener)
static final String MODIFIED_ATTRIBUTE
The prefix for the map attribute that is updated with the last modification timestamp.
int getHeight()
Returns the height of the area.
void setResetTimeout(final int resetTimeout)
void setText(final String text)
void setState(@NotNull final A mapArchObject)
void setEnterX(final int enterX)
Interface for MapArchObjects.
void endTransaction(final boolean fireEvent)
static final Size2D ONE
One size object.
void updateModifiedAttribute(@NotNull final String userName)
static final Pattern MODIFIED_ATTRIBUTE_PATTERN
The pattern to find the MODIFIED_ATTRIBUTE in the message text.
Represents a maps directory local map path.
void fireMetaChangedEvent()
Fires a MapMetaChangedEvent.
void setEnterY(final int enterY)
boolean fixedReset
If nonzero, the map reset time will not be updated when someone enters / exits the map.
void removeMapArchObjectListener(@NotNull final MapArchObjectListener listener)
final String[] tilePaths
The map tile paths used for map tiling.
void commitTransaction()
Performs ending a transaction.
The location of a map file with a map directory.
int transactionDepth
The transaction depth.
int swapTime
The number of ticks that must elapse after tha map has not been used before it gets swapped out.
void setDifficulty(final int difficulty)
void setModified()
Marks this map arch object as changed.
AbstractMapArchObject(@NotNull final AbstractMapArchObject< A > mapArchObject)
Creates a new instance as a copy of another map arch object.
Base implementation of MapArchObject that covers similarities between Crossfire maps and Daimonin map...
RelativeMapPath getRelativeMapPathFrom(@NotNull AbsoluteMapPath mapPath)
Returns this map path relative to another map path.
void setDarkness(final int darkness)
AbstractMapArchObject()
Creates a new instance.
int darkness
The light / darkness of map (overall).
boolean isTilePathAuto(@NotNull final Direction direction, @Nullable final MapFile mapFile)
void setTilePath(@NotNull final Direction direction, @NotNull final String tilePath)
void setOutdoor(final boolean outdoor)
String getTilePath(@NotNull final Direction direction)
final Collection< MapArchObjectListener > listenerList
The registered event listeners.
static final String MAP_NAME_UNNAMED
The name of an unnamed map.
boolean attributeHasChanged
Set if any attribute has changed inside the current transaction.
The class Size2D represents a 2d rectangular area.
boolean outdoor
If set, this is an outdoor map.
String calculateTilePath(@NotNull final Direction direction, @Nullable final MapFile mapFile)
final StringBuilder msgText
The map text.
transient Thread transactionThread
The thread that performs the current transaction.