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);