20 package net.sf.gridarta.actions;
22 import java.awt.Point;
23 import java.io.IOException;
39 import org.jetbrains.annotations.NotNull;
40 import org.jetbrains.annotations.Nullable;
94 public ExitConnectorActions(@NotNull
final ExitConnectorModel exitConnectorModel, @NotNull
final ExitMatcher<G, A, R> exitMatcher, @NotNull
final ArchetypeSet<G, A, R> archetypeSet, @NotNull
final MapManager<G, A, R> mapManager, @NotNull
final FileControl<G, A, R> fileControl, @NotNull
final InsertionModeSet<G, A, R> insertionModeSet) {
113 if (mapFile == null) {
135 if (sourceExitLocation == null) {
146 if (cursorExit != null) {
147 targetExit = cursorExit;
156 if (targetExit != null) {
160 pasteExit(targetExit, targetMapModel, sourceExitLocation, targetMapFile);
173 if (!
pasteExit(targetLocation, targetMapModel, targetArchetype, sourceExitLocation, targetMapFile)) {
191 if (sourceExitLocation == null) {
197 if (targetMapFile == null) {
210 if (cursorExit != null) {
211 targetExit = cursorExit;
212 targetArchetype = null;
227 }
catch (
final IOException ex) {
232 return doExitConnect(performAction, targetExit, targetArchetype, targetMapModel, targetLocation, targetMapFile, sourceMapControl.
getMapModel(), sourceExitLocation);
238 sourceMapControl.
save();
239 }
catch (
final IOException ex) {
244 mapManager.
release(sourceMapControl);
263 private boolean doExitConnect(
final boolean performAction, @Nullable
final BaseObject<?, ?, ?, ?> targetExit, @Nullable
final BaseObject<G, A, R, ?> targetArchetype, @NotNull
final MapModel<G, A, R> targetMapModel, @NotNull
final Point targetLocation, @NotNull
final MapFile targetMapFile, @NotNull
final MapModel<G, A, R> sourceMapModel, @NotNull
final ExitLocation sourceExitLocation) {
264 final MapFile sourceMapFile = sourceMapModel.getMapFile();
265 if (sourceMapFile == null) {
270 final Point sourceLocation = sourceExitLocation.getMapCoordinate();
277 sourceArchetype = null;
290 final ExitLocation targetExitLocation =
new ExitLocation(targetMapFile, targetLocation, targetMapModel.getMapArchObject().getMapName());
291 if (sourceExit != null) {
292 pasteExit(sourceExit, sourceMapModel, targetExitLocation, sourceMapFile);
294 if (!
pasteExit(sourceLocation, sourceMapModel, sourceArchetype, targetExitLocation, sourceMapFile)) {
299 if (targetExit != null) {
300 pasteExit(targetExit, targetMapModel, sourceExitLocation, targetMapFile);
302 assert targetArchetype != null;
303 if (!
pasteExit(targetLocation, targetMapModel, targetArchetype, sourceExitLocation, targetMapFile)) {
321 mapModel.beginTransaction(
"paste exit");
323 exitLocation.updateExitObject(gameObject, exitConnectorModel.
isPasteExitName(), gameObjectMapFile);
325 mapModel.endTransaction();
340 mapModel.beginTransaction(
"paste exit");
343 if (newExit == null) {
347 exitLocation.updateExitObject(newExit, exitConnectorModel.
isPasteExitName(), mapFile);
349 mapModel.endTransaction();
void save()
Saves the map to a file.
void reportSaveError(@NotNull MapControl< G, A, R > mapControl, @NotNull String message)
Reports an error while saving a map file to the user.
boolean pasteExit(@NotNull final Point location, @NotNull final MapModel< G, A, R > mapModel, @NotNull final BaseObject< G, A, R, ?> archetype, @NotNull final ExitLocation exitLocation, @Nullable final MapFile mapFile)
Creates a new exit game object.
void setExitLocation(@Nullable ExitLocation exitLocation)
Sets the remembered exit location.
A MapModel reflects the data of a map.
A MapManager manages all opened maps.
void release(@NotNull MapControl< G, A, R > mapControl)
Releases a MapControl instance.
G getExit(@NotNull final MapModel< G, A, R > mapModel, @Nullable final Point point)
Returns an exit game object on a given map square.
int getUseCounter()
Returns the use counter.
boolean isModified()
Return whether the map has been modified from the on-disk state.
MapModel< G, A, R > getMapModel()
Returns the map model.
final ExitConnectorModel exitConnectorModel
The ExitConnectorModel to use.
Base package of all Gridarta classes.
boolean isAutoCreateExit()
Returns whether exit game objects should be auto-created when needed.
Reflects a game object (object on a map).
void reportLoadError(@Nullable File file, @NotNull String message)
R getArchetype(@NotNull String archetypeName)
Returns an Archetype by its name.
boolean doExitConnect(final boolean performAction, @NotNull final MapControl< G, A, R > mapControl, @NotNull final Point targetLocation)
Executes the "exit connect" action.
final MapManager< G, A, R > mapManager
The MapManager for loading maps.
Selects valid exit game objects from maps.
InsertionMode< G, A, R > getTopmostInsertionMode()
Returns the "topmost" insertion mode.
GameObjects are the objects based on Archetypes found on maps.
final FileControl< G, A, R > fileControl
The FileControl to use.
void pasteExit(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final MapModel< G, A, R > mapModel, @NotNull final ExitLocation exitLocation, @Nullable final MapFile gameObjectMapFile)
Pastes exit information into an exit game object.
final ExitMatcher< G, A, R > exitMatcher
The ExitMatcher to use.
Exception thrown if an Archetype does not exist.
ExitLocation getExitLocation()
Returns the remembered exit location.
Utility class implementing actions that operate on ExitConnectorModels.
String getExitArchetypeName()
Returns the archetype name when creating exit game objects.
ExitConnectorActions(@NotNull final ExitConnectorModel exitConnectorModel, @NotNull final ExitMatcher< G, A, R > exitMatcher, @NotNull final ArchetypeSet< G, A, R > archetypeSet, @NotNull final MapManager< G, A, R > mapManager, @NotNull final FileControl< G, A, R > fileControl, @NotNull final InsertionModeSet< G, A, R > insertionModeSet)
Creates a new instance.
Stores information needed by the exit connector.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
Stores information about a remembered exit location.
boolean doExitCopy(final boolean performAction, @NotNull final MapControl< G, A, R > mapControl, @NotNull final Point location)
Executes the "exit copy" action.
Currently nothing more than a marker interface for unification.
boolean isPasteExitName()
Returns whether the exit name should be updated.
MapFile getMapFile()
Returns the map file.
File getFile()
Returns a File for this map file.
Interface that captures similarities between different ArchetypeSet implementations.
MapFile getMapFile()
Returns the file of the map that contains the remembered exit.
final ArchetypeSet< G, A, R > archetypeSet
The ArchetypeSet to use.
MapControl< G, A, R > openMapFile(@NotNull MapFile mapFile, boolean interactive)
Loads a map file.
boolean doExitPaste(final boolean performAction, @NotNull final MapControl< G, A, R > mapControl, @NotNull final Point targetLocation)
Executes the "exit paste" action.
boolean doExitConnect(final boolean performAction, @Nullable final BaseObject<?, ?, ?, ?> targetExit, @Nullable final BaseObject< G, A, R, ?> targetArchetype, @NotNull final MapModel< G, A, R > targetMapModel, @NotNull final Point targetLocation, @NotNull final MapFile targetMapFile, @NotNull final MapModel< G, A, R > sourceMapModel, @NotNull final ExitLocation sourceExitLocation)
Executes part of the "exit connect" action.
The location of a map file with a map directory.
Interface for MapArchObjects.
final InsertionModeSet< G, A, R > insertionModeSet
The InsertionModeSet to use.