Gridarta Editor
MapEnterLocationChecker.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.model.validation.checks;
21 
31 import net.sf.gridarta.utils.Size2D;
32 import org.jetbrains.annotations.NotNull;
33 
38 public class MapEnterLocationChecker<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractValidator<G, A, R> implements MapValidator<G, A, R> {
39 
45  super(validatorPreferences);
46  }
47 
48  @Override
49  public void validateMap(@NotNull final MapModel<G, A, R> mapModel, @NotNull final ErrorCollector<G, A, R> errorCollector) {
50  final MapArchObject<A> mapArchObject = mapModel.getMapArchObject();
51 
52  final int enterX = mapArchObject.getEnterX();
53  final int enterY = mapArchObject.getEnterY();
54  final Size2D mapSize = mapArchObject.getMapSize();
55  if (enterX < 0 || enterY < 0 || enterX >= mapSize.getWidth() || enterY >= mapSize.getHeight()) {
56  errorCollector.collect(new MapEnterLocationInvalidCoordinateError<>(mapModel, "(" + enterX + ", " + enterY + ")", mapSize));
57  }
58  }
59 
60 }
net.sf.gridarta.model.validation.errors.MapEnterLocationInvalidCoordinateError
Validation error that's used when a map's default enter coordinate is invalid.
Definition: MapEnterLocationInvalidCoordinateError.java:34
net.sf.gridarta.utils.Size2D.getWidth
int getWidth()
Returns the width of the area.
Definition: Size2D.java:96
net.sf.gridarta.model.validation.checks.MapEnterLocationChecker
Validator that checks whether the map has a valid difficulty.
Definition: MapEnterLocationChecker.java:38
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta.model.maparchobject.MapArchObject.getEnterX
int getEnterX()
Returns the enter x coordinate.
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.validation.checks.MapEnterLocationChecker.MapEnterLocationChecker
MapEnterLocationChecker(@NotNull final ValidatorPreferences validatorPreferences)
Creates a new instance.
Definition: MapEnterLocationChecker.java:44
net.sf
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.model.validation.checks.MapEnterLocationChecker.validateMap
void validateMap(@NotNull final MapModel< G, A, R > mapModel, @NotNull final ErrorCollector< G, A, R > errorCollector)
Validate a map.
Definition: MapEnterLocationChecker.java:49
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.model.validation.AbstractValidator.validatorPreferences
final ValidatorPreferences validatorPreferences
The ValidatorPreferences to use.
Definition: AbstractValidator.java:55
net.sf.gridarta.model.validation.MapValidator
Interface for Map Validators.
Definition: MapValidator.java:33
net.sf.gridarta.model.validation.ValidatorPreferences
Configuration parameters for Validators.
Definition: ValidatorPreferences.java:28
net.sf.gridarta.model.maparchobject.MapArchObject.getMapSize
Size2D getMapSize()
Returns the map size.
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.utils.Size2D.getHeight
int getHeight()
Returns the height of the area.
Definition: Size2D.java:104
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.model.validation.ErrorCollector
An interface for classes that collect errors.
Definition: ErrorCollector.java:33
net.sf.gridarta.model.validation.AbstractValidator
This is the base class for validators.
Definition: AbstractValidator.java:37
net.sf.gridarta.model.validation
This package contains the framework for validating maps.
Definition: AbstractValidator.java:20
net.sf.gridarta.model.maparchobject.MapArchObject.getEnterY
int getEnterY()
Returns the enter y coordinate.
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.model.validation.errors
Definition: AttributeRangeError.java:20
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.utils.Size2D
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20