 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.actions;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.regex.Matcher;
41 import org.jetbrains.annotations.NotNull;
42 import org.jetbrains.annotations.Nullable;
86 if (mapModel.getMapFile() ==
null) {
91 final List<MapControl<G, A, R>> mapControls =
new ArrayList<>(tilePaths.length);
109 if (mapControl !=
null) {
126 for (@Nullable
final String tilePath : tilePaths) {
128 if (tilePath !=
null && !tilePath.isEmpty()) {
131 }
catch (
final IOException ex) {
137 mapControls.add(mapControl);
149 if (mapControl !=
null) {
151 if (mapControl.getMapModel().isModified()) {
154 }
catch (
final IOException e) {
155 final MapFile mapFile = mapControl.getMapModel().getMapFile();
156 assert mapFile !=
null;
169 boolean repeatFlag =
true;
172 for (
int i = 0; i < mapControls.size(); i++) {
174 if (mapControl !=
null) {
177 for (
final MapLink mapLink : mapLinks) {
178 final Direction direction = mapLink.getMapDirection();
179 if (mapControls.get(direction.ordinal()) ==
null) {
181 if (!tilePath.isEmpty()) {
185 }
catch (
final IOException ex) {
205 final Size2D mapSize = mapModel.getMapArchObject().getMapSize();
207 if (mapControl !=
null) {
211 if (!mapSize.
equals(otherMapSize)) {
214 for (
int ii = 0; ii < 2; ii++) {
230 for (
int i = 0; i < tilePaths.length; i++) {
232 if (mapControl !=
null) {
235 final String canonicalMapPath1 = mapModel.getMapFile().getFile().getPath();
236 final String link1 =
getTilePath(canonicalMapPath1, canonicalMapPath2, mapsDirectory);
238 tilePaths[i] = link1;
240 final String link2 =
getTilePath(canonicalMapPath2, canonicalMapPath1, mapsDirectory);
267 final MapFile mapFile = mapModel.getMapFile();
268 if (mapFile ==
null) {
287 final CharSequence mapDirectory;
289 mapDirectory = mapsDirectory.getCanonicalPath();
290 }
catch (
final IOException e) {
293 final String first = base.substring(mapDirectory.length(), pos).trim();
294 final String second = link.substring(mapDirectory.length(), pos2).trim();
296 final String sep = Matcher.quoteReplacement(File.separator);
299 if (first.isEmpty()) {
300 return link.substring(mapDirectory.length()).trim().replaceAll(sep,
"/");
303 if (first.compareTo(second) == 0) {
304 return link.substring(pos2 + 1).trim().replaceAll(sep,
"/");
307 if (second.startsWith(first)) {
308 return link.substring(pos + 1).trim().replaceAll(sep,
"/");
311 return link.substring(mapDirectory.length()).trim().replaceAll(sep,
"/");
321 return Math.max(base.lastIndexOf(File.separator), base.lastIndexOf(
'/'));
A MapModel reflects the data of a map.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
A MapManager manages all opened maps.
Base package of all Gridarta classes.
void endTransaction()
End a transaction.
void fillAdjacentMaps(@NotNull final List< MapControl< G, A, R >> mapControls)
Fills missing adjacent map slots.
static String getTilePath(@NotNull final String base, @NotNull final String link, @NotNull final File mapsDirectory)
Returns the map path for a tile of a map and a tile path.
void beginTransaction(@NotNull String name)
Starts a new transaction.
void beginTransaction()
Starts a new transaction.
static MapPath newMapPath(@NotNull final String string)
Creates a MapPath instance from string representation.
Reflects a game object (object on a map).
Utility class for MapPath related functions.
void saveAdjacentMaps(@NotNull final Iterable< MapControl< G, A, R >> mapControls)
Saves adjacent maps.
void updateTilePaths(@NotNull final MapModel< G, A, R > mapModel, @NotNull final List< MapControl< G, A, R >> mapControls, @NotNull final String @NotNull[] tilePaths, @NotNull final File mapsDirectory)
Updates map tile paths to match the loaded maps.
Size2D getMapSize()
Returns the map size.
GameObjects are the objects based on Archetypes found on maps.
void validateMapSizes(@NotNull final MapModel< G, A, R > mapModel, @NotNull final Iterable< MapControl< G, A, R >> mapControls)
Validates all links to check that attached maps have matching width/height.
Attaches maps to adjacent tiled maps.
Interface for MapArchObjects.
static int getLastSlashIndex(@NotNull final String base)
Returns the index of the last '/' or File#separator within a string.
File getFile()
Returns a File for this map file.
MapControl< G, A, R > openMapFile(@NotNull MapFile mapFile, boolean interactive)
Loads a map file.
void loadAdjacentMaps(@NotNull final MapModel< G, A, R > mapModel, @NotNull final Collection< MapControl< G, A, R >> mapControls, @NotNull final String @NotNull[] tilePaths)
Loads adjacent map files by "filling" them by checking the "side" path links of the loaded ones.
Exception thrown if an operation is attempted on an unsaved map.
void attachTiledMaps(@NotNull final MapModel< G, A, R > mapModel, @NotNull final String @NotNull[] tilePaths, @NotNull final File mapsDirectory, final boolean performAction)
Updates tile paths of a map.
final TileLink[] tileLinks
The tile links for the attach map algorithm.
The location of a map file with a map directory.
void setTilePath(@NotNull Direction direction, @NotNull String tilePath)
Sets a tile path.
Exception thrown if the size of a map file is unexpected.
MapControl< G, A, R > loadMapControl(@NotNull final MapModel< G, A, R > mapModel, @NotNull final String path)
Loads an adjacent MapControl, ignoring any (I/O-)errors.
void release(@NotNull MapControl< G, A, R > mapControl)
Releases a MapControl instance.
boolean equals(@Nullable final Object obj)
Exception thrown if a map file cannot be saved.
final MapManager< G, A, R > mapManager
The mainControl to use.
Currently nothing more than a marker interface for unification.
MapModel< G, A, R > getMapModel()
Returns the map model.
MapFile getMapFile()
Returns the map file.
The class Size2D represents a 2d rectangular area.
AttachTiledMaps(@NotNull final MapManager< G, A, R > mapManager, @NotNull final TileLink @NotNull[] tileLinks)
Creates a new instance.
void endTransaction()
Ends a transaction.
Exception thrown if a map file cannot be loaded.