Gridarta Editor
MapPathParameter.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.plugin.parameter;
21 
22 import java.io.File;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31 
35 public class MapPathParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractStringPluginParameter<G, A, R, String> {
36 
40  @NotNull
41  public static final String PARAMETER_TYPE = "MapPathParameter";
42 
47  @NotNull
48  private final PathManager pathManager;
49 
53  @NotNull
55 
62  public MapPathParameter(@NotNull final PathManager pathManager, @NotNull final ProjectSettings projectSettings) {
63  super("");
64  this.pathManager = pathManager;
65  this.projectSettings = projectSettings;
66  }
67 
68  @NotNull
69  @Override
70  public String getParameterType() {
71  return PARAMETER_TYPE;
72  }
73 
74  @NotNull
75  @Override
76  public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) {
77  return visitor.visit(this);
78  }
79 
80  @NotNull
81  @Override
82  public String getValue() {
83  return getStringValue();
84  }
85 
86  @Nullable
87  @Override
88  public String getValueOrNull() {
89  return getValue();
90  }
91 
97  public void setFile(@NotNull final File file) throws InvalidValueException {
98  final MapFile mapFile = pathManager.getMapFile(file);
99  if (!mapFile.getMapsDir().equals(projectSettings.getMapsDirectory())) {
100  throw new InvalidValueException("the selected file " + mapFile + " must be within the maps directory " + projectSettings.getMapsDirectory());
101  }
102  setStringValue("/" + mapFile.getMapPath().getPath());
103  }
104 
105 }
net.sf.gridarta.plugin.parameter.MapPathParameter.getValue
String getValue()
Definition: MapPathParameter.java:82
net.sf.gridarta.plugin.parameter.MapPathParameter.setFile
void setFile(@NotNull final File file)
Sets the value from a File instance.
Definition: MapPathParameter.java:97
net.sf.gridarta.model.mapmodel.AbsoluteMapPath.getPath
String getPath()
Returns the map path information.
Definition: AbsoluteMapPath.java:80
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.plugin.parameter.MapPathParameter.PARAMETER_TYPE
static final String PARAMETER_TYPE
The string representation of this parameter type.
Definition: MapPathParameter.java:41
net.sf.gridarta.plugin.parameter.MapPathParameter.projectSettings
final ProjectSettings projectSettings
The ProjectSettings instance.
Definition: MapPathParameter.java:54
net.sf
net.sf.gridarta.model.io.PathManager
This class contains methods for converting relative map paths to absolute map paths and vice versa.
Definition: PathManager.java:39
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.plugin.parameter.MapPathParameter.getValueOrNull
String getValueOrNull()
Definition: MapPathParameter.java:88
net.sf.gridarta.plugin.parameter.MapPathParameter.visit
public< T > T visit(@NotNull final PluginParameterVisitor< G, A, R, T > visitor)
Definition: MapPathParameter.java:76
net.sf.gridarta.model.mapmodel.MapFile.getMapPath
AbsoluteMapPath getMapPath()
Returns the map path within getMapsDir().
Definition: MapFile.java:93
net.sf.gridarta.plugin.parameter.MapPathParameter.MapPathParameter
MapPathParameter(@NotNull final PathManager pathManager, @NotNull final ProjectSettings projectSettings)
Creates a new instance.
Definition: MapPathParameter.java:62
net.sf.gridarta.plugin.parameter.AbstractStringPluginParameter< G, A, R, String >::getStringValue
String getStringValue()
Definition: AbstractStringPluginParameter.java:50
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.plugin.parameter.AbstractStringPluginParameter
Abstract base class for PluginParameter implementations for which the value is calculated from the st...
Definition: AbstractStringPluginParameter.java:32
net.sf.gridarta.model.mapmodel.MapFile.getMapsDir
File getMapsDir()
Returns the base directory this map file is part of.
Definition: MapFile.java:84
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.model.io.PathManager.getMapFile
MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath)
Returns a MapFile instance from an AbsoluteMapPath.
Definition: PathManager.java:72
net.sf.gridarta.plugin.parameter.MapPathParameter.getParameterType
String getParameterType()
Definition: MapPathParameter.java:70
net.sf.gridarta.plugin.parameter.InvalidValueException
An exception that is thrown if the string representation of value in a {} cannot be converted to an o...
Definition: InvalidValueException.java:30
net.sf.gridarta.model.mapmodel.MapFile
The location of a map file with a map directory.
Definition: MapFile.java:31
net.sf.gridarta.plugin.parameter.MapPathParameter.pathManager
final PathManager pathManager
The PathManager instance for converting Files into path names.
Definition: MapPathParameter.java:48
net.sf.gridarta.model.io
Reading and writing of maps, handling of paths.
Definition: AbstractAnimationObjectsReader.java:20
net.sf.gridarta.model.settings.ProjectSettings
Settings that apply to a project.
Definition: ProjectSettings.java:29
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.plugin.parameter.AbstractStringPluginParameter< G, A, R, String >::setStringValue
boolean setStringValue( @NotNull final String stringValue)
Updates the parameter value.
Definition: AbstractStringPluginParameter.java:59
net.sf.gridarta.plugin.parameter.MapPathParameter
A PluginParameter that holds a path with in the maps directory.
Definition: MapPathParameter.java:35
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.plugin.parameter.PluginParameterVisitor
Interface for visitors of PluginParameter instances.
Definition: PluginParameterVisitor.java:32
net.sf.gridarta.model.settings.ProjectSettings.getMapsDirectory
File getMapsDirectory()
Returns the default maps directory.
net.sf.gridarta.model.settings
Definition: AbstractDefaultProjectSettings.java:20