20 package net.sf.gridarta.model.validation.checks;
22 import java.util.HashMap;
33 import org.jetbrains.annotations.NotNull;
39 public class CustomTypeChecker<G
extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>> extends
AbstractValidator<G, A, R> implements
GameObjectValidator<G, A, R> {
47 private final Map<Integer, Map<Integer, Integer>>
ignoreEntries =
new HashMap<>();
54 super(validatorPreferences);
59 final int archetypeTypeNo = gameObject.getArchetype().getTypeNo();
60 final int gameObjectTypeNo = gameObject.getTypeNo();
61 if (gameObjectTypeNo != archetypeTypeNo && !
isAllowedTypeChange(gameObject, archetypeTypeNo, gameObjectTypeNo)) {
62 errorCollector.collect(
new CustomTypeError<>(gameObject, archetypeTypeNo, gameObjectTypeNo));
74 final Map<Integer, Integer> entries = ignoreEntries.get(archetypeTypeNo);
75 if (entries == null) {
79 final Integer allowedEnvType = entries.get(gameObjectTypeNo);
80 if (allowedEnvType == null) {
81 return entries.containsKey(gameObjectTypeNo);
85 if (envGameObject == null) {
89 final int envTypeNo = envGameObject.
getTypeNo();
90 return envTypeNo == allowedEnvType;
98 public void addIgnore(
final int fromType,
final int toType) {
108 public void addIgnore(
final int fromType,
final int toType,
final int envType) {
119 final Map<Integer, Integer> ignoreEntrySet = ignoreEntries.get(type);
120 if (ignoreEntrySet != null) {
121 return ignoreEntrySet;
124 final Map<Integer, Integer> newIgnoreEntrySet =
new HashMap<>();
125 ignoreEntries.put(type, newIgnoreEntrySet);
126 return newIgnoreEntrySet;
void addIgnore(final int fromType, final int toType)
Adds an allowed type change.
This is the base class for validators.
Interface for GameObject Validators.
This package contains the framework for validating maps.
Checks that a game object does not set a custom type.
Base package of all Gridarta classes.
void validateGameObject(@NotNull final G gameObject, @NotNull final ErrorCollector< G, A, R > errorCollector)
Validates a game object.
Reflects a game object (object on a map).
Configuration parameters for Validators.
GameObjects are the objects based on Archetypes found on maps.
CustomTypeChecker(@NotNull final ValidatorPreferences validatorPreferences)
Creates a new instance.
Validation error indicating a game object with a custom type.
Map< Integer, Integer > getIgnoreSet(final int type)
Returns the allowed type changes for a given source type.
boolean isAllowedTypeChange(@NotNull final GameObject< G, A, R > gameObject, final int archetypeTypeNo, final int gameObjectTypeNo)
Returns whether the given game's changed type is allowed.
final ValidatorPreferences validatorPreferences
The ValidatorPreferences to use.
void addIgnore(final int fromType, final int toType, final int envType)
Adds an allowed type change.
final Map< Integer, Map< Integer, Integer > > ignoreEntries
The allowed type changes.
An interface for classes that collect errors.
Interface for MapArchObjects.
int getTypeNo()
Returns the type number of this Archetype.