Gridarta Editor
NonAbsoluteExitPathChecker.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.var.crossfire.model.validation.checks;
21 
37 import org.jetbrains.annotations.NotNull;
38 
45 public class NonAbsoluteExitPathChecker extends AbstractValidator<GameObject, MapArchObject, Archetype> implements GameObjectValidator<GameObject, MapArchObject, Archetype> {
46 
50  @NotNull
52 
59  public NonAbsoluteExitPathChecker(@NotNull final ValidatorPreferences validatorPreferences, @NotNull final GameObjectMatcher exitGameObjectMatcher) {
60  super(validatorPreferences);
61  this.exitGameObjectMatcher = exitGameObjectMatcher;
62  }
63 
64  @Override
65  public void validateGameObject(@NotNull final GameObject gameObject, @NotNull final ErrorCollector<GameObject, MapArchObject, Archetype> errorCollector) {
66  if (!exitGameObjectMatcher.isMatching(gameObject)) {
67  return; // not an exit => skip
68  }
69 
71  if (mapSquare == null) {
72  return; // not on a map => skip
73  }
74 
76  final MapArchObject mapArchObject = mapModel.getMapArchObject();
77  if (!mapArchObject.isUnique()) {
78  return; // not on an unique map => skip
79  }
80 
81  final MapPath exitPath;
82  try {
83  exitPath = MapLocation.getMapPath(gameObject, true);
84  } catch (final NoExitPathException ignored) {
85  return; // unset exit path => skip
86  }
87  if (exitPath instanceof AbsoluteMapPath) {
88  return; // absolute exit path => ok
89  }
90 
91  errorCollector.collect(new NonAbsoluteExitPathError<>(gameObject, exitPath));
92  }
93 
94 }
final GameObjectMatcher exitGameObjectMatcher
The GameObjectMatcher for matching exit objects.
A MapModel reflects the data of a map.
Definition: MapModel.java:75
NonAbsoluteExitPathChecker(@NotNull final ValidatorPreferences validatorPreferences, @NotNull final GameObjectMatcher exitGameObjectMatcher)
Creates a new instance.
This is the base class for validators.
Interface for classes that match GameObjects.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
Exception thrown if a game object does not specify a valid exit path.
MapModel< G, A, R > getMapModel()
Returns the MapModel this map square is part of.
Definition: MapSquare.java:99
This package contains the framework for validating maps.
A MapPath that is absolute, that is, it starts with a "/".
void validateGameObject(@NotNull final GameObject gameObject, @NotNull final ErrorCollector< GameObject, MapArchObject, Archetype > errorCollector)
MapArchObject contains the specific meta data about a map that is stored in the map-arch, at the very beginning of the map file.
Handles the Crossfire variants of GameObjects and Archetypes.
Represents a maps directory local map path.
Definition: MapPath.java:31
Base package of all Gridarta classes.
MapPath getMapPath()
Returns the map path.
Main package of Gridarta4Crossfire, contains all classes specific to the Crossfire version of the Gri...
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
final ValidatorPreferences validatorPreferences
The ValidatorPreferences to use.
A GameObjectValidationError that describes an exit GameObject having an invalid exit path...
Represents a location on a map consisting of a map path and a map coordinate.
An interface for classes that collect errors.
This package contains the checks for validating maps.
A net.sf.gridarta.model.validation.MapValidator that checks for relative exit paths within unique map...
boolean isMatching(@NotNull GameObject<?, ?, ?> gameObject)
Matches an GameObject.