Gridarta Editor
PluginParameterFactory.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 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 
30 import nu.xom.Element;
31 import org.jetbrains.annotations.NotNull;
32 
37 public class PluginParameterFactory<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
38 
39  @NotNull
41 
42  @NotNull
44 
45  @NotNull
47 
51  @NotNull
52  private final PathManager pathManager;
53 
58  @NotNull
60 
65  public PluginParameterFactory(@NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final MapManager<G, A, R> mapManager, @NotNull final ProjectSettings projectSettings, @NotNull final PathManager pathManager) {
66  this.archetypeSet = archetypeSet;
67  this.mapManager = mapManager;
68  this.projectSettings = projectSettings;
69  this.pathManager = pathManager;
70  }
71 
72  @NotNull
73  public PluginParameter<G, A, R, ?> createParameter(@NotNull final Element parameterNode) throws NoSuchParameterException {
74  return createParameter(XmlUtils.getChild(parameterNode, "type").getValue(), parameterNode);
75  }
76 
82  @NotNull
83  public PluginParameter<G, A, R, ?> createStringParameter(@NotNull final Element parameterNode) {
84  final PluginParameter<G, A, R, ?> parameter = new StringParameter<>();
85  codec.fromXML(parameter, parameterNode);
86  return parameter;
87  }
88 
89  @NotNull
90  public PluginParameter<G, A, R, ?> createParameter(@NotNull final String type) throws NoSuchParameterException {
91  if (type.equals(StringParameter.PARAMETER_TYPE)) {
92  return new StringParameter<>();
93  }
94  if (type.equals(IntegerParameter.PARAMETER_TYPE)) {
95  return new IntegerParameter<>();
96  }
97  if (type.equals(DoubleParameter.PARAMETER_TYPE)) {
98  return new DoubleParameter<>();
99  }
100  if (type.equals(BooleanParameter.PARAMETER_TYPE)) {
101  return new BooleanParameter<>();
102  }
103  if (type.equals(ArchetypeParameter.PARAMETER_TYPE)) {
105  }
106  if (type.equals(MapParameter.PARAMETER_TYPE)) {
108  }
109  if (type.equals(MapPathParameter.PARAMETER_TYPE)) {
111  }
112  throw new NoSuchParameterException(type);
113  }
114 
115  @NotNull
116  public PluginParameter<G, A, R, ?> createParameter(@NotNull final String type, @NotNull final Element parameterNode) throws NoSuchParameterException {
118  codec.fromXML(p, parameterNode);
119  return p;
120  }
121 
126  @NotNull
127  public static String[] getTypes() {
129  }
130 
131 }
A PluginParameter that holds a MapControl value.
static final String PARAMETER_TYPE
The string representation of this parameter type.
This class contains methods for converting relative map paths to absolute map paths and vice versa...
A MapManager manages all opened maps.
Definition: MapManager.java:37
Reading and writing of maps, handling of paths.
XML related utility functions.
Definition: XmlUtils.java:30
Settings that apply to a project.
static final String PARAMETER_TYPE
The string representation of this parameter type.
A PluginParameter that holds an integer value and a range of valid values.
Base package of all Gridarta classes.
A PluginParameter that holds a boolean value.
Reflects a game object (object on a map).
Definition: GameObject.java:36
final PathManager pathManager
The PathManager instance for converting files into path names.
PluginParameter< G, A, R, ?> createStringParameter(@NotNull final Element parameterNode)
Creates a new StringParameter from XML representation.
PluginParameterFactory(@NotNull final ArchetypeSet< G, A, R > archetypeSet, @NotNull final MapManager< G, A, R > mapManager, @NotNull final ProjectSettings projectSettings, @NotNull final PathManager pathManager)
GameObjects are the objects based on Archetypes found on maps.
static final String PARAMETER_TYPE
The string representation of this parameter type.
A PluginParameter that holds an Archetype value.
final PluginParameterCodec< G, A, R > codec
The PluginParameterCodec for converting PluginParameters to or from XML representation.
A PluginParameter that holds a double value.
PluginParameter< G, A, R, ?> createParameter(@NotNull final String type)
static Element getChild(@NotNull final Element parentElement, @NotNull final String childName)
Returns a child Element of a parent element.
Definition: XmlUtils.java:46
Interface that captures similarities between different ArchetypeSet implementations.
static String [] getTypes()
Returns all available plugin parameter type names.
static final String PARAMETER_TYPE
The string representation of this parameter type.
static final String PARAMETER_TYPE
The string representation of this parameter type.
PluginParameter< G, A, R, ?> createParameter(@NotNull final String type, @NotNull final Element parameterNode)
A PluginParameter that holds a path with in the maps directory.
static final String PARAMETER_TYPE
The string representation of this parameter type.
A PluginParameter that holds a string value.
static final String PARAMETER_TYPE
The string representation of this parameter type.
final PluginParameterVisitor< G, A, R, PluginParameter< G, A, R, ?> > fromXML
A PluginParameterVisitor that restores a PluginParameter from XML representation. ...
PluginParameter< G, A, R, ?> createParameter(@NotNull final Element parameterNode)