Gridarta Editor
DoubleLayerChecker.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 
22 import java.util.HashMap;
23 import java.util.Map;
34 import org.jetbrains.annotations.NotNull;
35 
41 public class DoubleLayerChecker<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractValidator<G, A, R> implements SquareValidator<G, A, R> {
42 
48  super(validatorPreferences);
49  }
50 
51  @Override
52  public void validateSquare(@NotNull final MapSquare<G, A, R> mapSquare, @NotNull final ErrorCollector<G, A, R> errorCollector) {
53  final Map<Integer, G> gameObjects = new HashMap<>();
54  final Map<Integer, DoubleLayerError<G, A, R>> errors = new HashMap<>();
55  for (final G gameObject : mapSquare) {
56  final int layer = gameObject.getHead().getAttributeInt(DefaultIsoGameObject.LAYER, true);
57  if (layer == 0) {
58  // ignore layer 0
59  } else {
60  final DoubleLayerError<G, A, R> existingError = errors.get(layer);
61  if (existingError == null) {
62  final G existingGameObject = gameObjects.get(layer);
63  if (existingGameObject == null) {
64  gameObjects.put(layer, gameObject);
65  } else {
66  final DoubleLayerError<G, A, R> error = new DoubleLayerError<>(mapSquare, existingGameObject);
67  errors.put(layer, error);
68  errorCollector.collect(error);
69  }
70  } else {
71  existingError.addGameObject(gameObject);
72  }
73  }
74  }
75  }
76 
77 }
net.sf.gridarta.model.gameobject.DefaultIsoGameObject
Default implementation for GameObject implementing classes.
Definition: DefaultIsoGameObject.java:38
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.validation.SquareValidator
Interface for Square Validators.
Definition: SquareValidator.java:33
net.sf.gridarta.model.mapmodel.MapSquare
A single Map Square.
Definition: MapSquare.java:45
net.sf.gridarta.model.validation.checks.DoubleLayerChecker.DoubleLayerChecker
DoubleLayerChecker(@NotNull final ValidatorPreferences validatorPreferences)
Creates a new instance.
Definition: DoubleLayerChecker.java:47
net.sf
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.model.validation.AbstractValidator.validatorPreferences
final ValidatorPreferences validatorPreferences
The ValidatorPreferences to use.
Definition: AbstractValidator.java:55
net.sf.gridarta.model.validation.ValidatorPreferences
Configuration parameters for Validators.
Definition: ValidatorPreferences.java:28
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.validation.checks.DoubleLayerChecker
A SquareValidator to assert that there are no two objects within the same layer.
Definition: DoubleLayerChecker.java:41
errors
errors
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:1
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.validation.checks.DoubleLayerChecker.validateSquare
void validateSquare(@NotNull final MapSquare< G, A, R > mapSquare, @NotNull final ErrorCollector< G, A, R > errorCollector)
Validate a map square.
Definition: DoubleLayerChecker.java:52
net.sf.gridarta.model.gameobject.DefaultIsoGameObject.LAYER
static final String LAYER
The name of the "layer" attribute.
Definition: DefaultIsoGameObject.java:61
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.model.validation.errors.DoubleLayerError.addGameObject
void addGameObject(@NotNull final G gameObject)
Definition: DoubleLayerError.java:57
net.sf.gridarta.model.validation.errors.DoubleLayerError
Validation error that's used when the DoubleLayerChecker detected a possible error on the map.
Definition: DoubleLayerError.java:34