Gridarta Editor
ArchetypeParameter.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 
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
29 
33 public class ArchetypeParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractStringPluginParameter<G, A, R, Archetype<G, A, R>> {
34 
38  @NotNull
39  public static final String PARAMETER_TYPE = Archetype.class.getName();
40 
44  @NotNull
46 
51  public ArchetypeParameter(@NotNull final ArchetypeSet<G, A, R> archetypeSet) {
52  super(""); // XXX
53  this.archetypeSet = archetypeSet;
54  }
55 
56  @NotNull
57  @Override
58  public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) {
59  return visitor.visit(this);
60  }
61 
62  @NotNull
63  @Override
65  final String archetypeName = getStringValue();
66  try {
67  return archetypeSet.getArchetype(archetypeName);
68  } catch (final UndefinedArchetypeException ex) {
69  throw new InvalidValueException("undefined archetype: " + archetypeName, ex);
70  }
71  }
72 
73  @Nullable
74  @Override
76  try {
77  return getValue();
78  } catch (final InvalidValueException ignored) {
79  return null;
80  }
81  }
82 
83  @NotNull
84  @Override
85  public String getParameterType() {
86  return PARAMETER_TYPE;
87  }
88 
89 }
ArchetypeParameter(@NotNull final ArchetypeSet< G, A, R > archetypeSet)
Creates a new instance.
Abstract base class for PluginParameter implementations for which the value is calculated from the st...
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
R getArchetype(@NotNull String archetypeName)
Returns an Archetype by its name.
final ArchetypeSet< G, A, R > archetypeSet
The ArchetypeSet for looking up archetypes.
GameObjects are the objects based on Archetypes found on maps.
A PluginParameter that holds an Archetype value.
Interface for visitors of PluginParameter instances.
An exception that is thrown if the string representation of value in a PluginParameter cannot be conv...
Interface that captures similarities between different ArchetypeSet implementations.
static final String PARAMETER_TYPE
The string representation of this parameter type.