20 package net.sf.gridarta.model.validation.checks;
22 import java.util.Collection;
23 import java.util.HashSet;
24 import java.util.Iterator;
54 import org.apache.log4j.Category;
55 import org.apache.log4j.Logger;
56 import org.jetbrains.annotations.NotNull;
57 import org.jetbrains.annotations.Nullable;
83 public static <G extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>>
void addChecks(@NotNull
final ArchetypeTypeSet archetypeTypeSet, @Nullable
final AttributeRangeChecker<G, A, R> attributeRangeChecker, @NotNull
final EnvironmentChecker<G, A, R> environmentChecker) {
84 if (attributeRangeChecker ==
null) {
88 final Set<Integer> allowsAllInvTypes =
new HashSet<>();
90 if (archetypeType.isAllowsAllInv()) {
91 allowsAllInvTypes.add(archetypeType.getTypeNo());
95 addChecks(archetypeTypeSet, attributeRangeChecker, archetypeType);
96 if (!archetypeType.isMap()) {
97 environmentChecker.addNoMap(archetypeType);
99 final int[] types = archetypeType.getInv();
101 final Collection<Integer> tmp =
new HashSet<>(allowsAllInvTypes);
102 for (
final int type : types) {
105 final int[] tmp2 =
new int[tmp.size()];
106 final Iterator<Integer> it = tmp.iterator();
107 for (
int i = 0; i < tmp2.length; i++) {
110 assert !it.hasNext();
111 environmentChecker.addInv(archetypeType, tmp2);
123 private static <G extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>>
void addChecks(@NotNull
final ArchetypeTypeSet archetypeTypeSet, @NotNull
final AttributeRangeChecker<G, A, R> attributeRangeChecker, @NotNull
final ArchetypeType archetypeType) {
124 if (archetypeType.hasTypeAttributes()) {
128 final ArchetypeAttributeVisitor archetypeAttributeVisitor =
new ArchetypeAttributeVisitor() {
131 public void visit(@NotNull
final ArchetypeAttributeAnimationName archetypeAttribute) {
136 public void visit(@NotNull
final ArchetypeAttributeBitmask archetypeAttribute) {
137 final AttributeBitmask bitmask = archetypeTypeSet.getBitmask(archetypeAttribute.getBitmaskName());
138 if (bitmask !=
null) {
140 attributeRangeChecker.add(archetypeType.getTypeNo(), archetypeAttribute.getArchetypeAttributeName(), archetypeAttribute.getAttributeName(), 0, bitmask.getMaxValue());
141 }
catch (
final InvalidCheckException ex) {
142 LOG.warn(ex.getMessage() +
" in type " + archetypeType.getTypeNo() +
".");
148 public void visit(@NotNull
final ArchetypeAttributeBool archetypeAttribute) {
150 attributeRangeChecker.add(archetypeType.getTypeNo(), archetypeAttribute.getArchetypeAttributeName(), archetypeAttribute.getAttributeName(), 0, 1);
151 }
catch (
final InvalidCheckException ex) {
152 LOG.warn(ex.getMessage() +
" in type " + archetypeType.getTypeNo() +
".");
157 public void visit(@NotNull
final ArchetypeAttributeBoolSpec archetypeAttribute) {
162 public void visit(@NotNull
final ArchetypeAttributeFaceName archetypeAttribute) {
167 public void visit(@NotNull
final ArchetypeAttributeFixed archetypeAttribute) {
172 public void visit(@NotNull
final ArchetypeAttributeFloat archetypeAttribute) {
177 public void visit(@NotNull
final ArchetypeAttributeInt archetypeAttribute) {
179 attributeRangeChecker.add(archetypeType.getTypeNo(), archetypeAttribute.getArchetypeAttributeName(), archetypeAttribute.getAttributeName(), archetypeAttribute.getMinCheckValue(), archetypeAttribute.getMaxCheckValue());
180 }
catch (
final InvalidCheckException ex) {
181 LOG.warn(ex.getMessage() +
" in type " + archetypeType.getTypeNo() +
".");
186 public void visit(@NotNull
final ArchetypeAttributeInvSpell archetypeAttribute) {
191 public void visit(@NotNull
final ArchetypeAttributeList archetypeAttribute) {
196 public void visit(@NotNull
final ArchetypeAttributeList2 archetypeAttribute) {
201 public void visit(@NotNull
final ArchetypeAttributeLong archetypeAttribute) {
206 public void visit(@NotNull
final ArchetypeAttributeMapPath archetypeAttribute) {
211 public void visit(@NotNull
final ArchetypeAttributeScriptFile archetypeAttribute) {
216 public void visit(@NotNull
final ArchetypeAttributeSpell archetypeAttribute) {
221 public void visit(@NotNull
final ArchetypeAttributeString archetypeAttribute) {
226 public void visit(@NotNull
final ArchetypeAttributeText archetypeAttribute) {
231 public void visit(@NotNull
final ArchetypeAttributeTreasure archetypeAttribute) {
236 public void visit(@NotNull
final ArchetypeAttributeZSpell archetypeAttribute) {
242 for (
final ArchetypeAttributeSection archetypeAttributeSection : archetypeType) {
243 for (
final ArchetypeAttribute archetypeAttribute : archetypeAttributeSection) {
244 archetypeAttribute.visit(archetypeAttributeVisitor);