Gridarta Editor
ArchetypeValidator.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.model.archetypeset;
21 
29 import org.jetbrains.annotations.NotNull;
30 
35 public class ArchetypeValidator {
36 
40  @NotNull
42 
46  @NotNull
47  private final FaceObjects faceObjects;
48 
52  @NotNull
53  private final ErrorView errorView;
54 
62  public ArchetypeValidator(@NotNull final AnimationObjects animationObjects, @NotNull final FaceObjects faceObjects, @NotNull final ErrorView errorView) {
63  this.animationObjects = animationObjects;
64  this.faceObjects = faceObjects;
65  this.errorView = errorView;
66  }
67 
72  public void validate(@NotNull final ArchetypeSet<?, ?, ?> archetypeSet) {
73  for (final Archetype<?, ?, ?> archetype : archetypeSet.getArchetypes()) {
74  validateArchetype(archetype);
75  }
76  }
77 
82  private void validateArchetype(@NotNull final Archetype<?, ?, ?> archetype) {
83  final String animName = archetype.getAnimName();
84  if (animName != null && !animName.equals("NONE")) {
85  final AnimationObject animation = animationObjects.get(animName);
86  if (animation == null) {
87  errorView.addWarning(ErrorViewCategory.ARCHETYPE_INVALID, archetype.getArchetypeName() + " references undefined animation '" + animName + "'");
88  }
89  }
90 
91  final String faceName = archetype.getFaceName();
92  if (faceName != null) {
93  final FaceObject face = faceObjects.get(faceName);
94  if (face == null) {
95  errorView.addWarning(ErrorViewCategory.ARCHETYPE_INVALID, archetype.getArchetypeName() + " references undefined face '" + faceName + "'");
96  }
97  }
98  }
99 
100 }
net.sf.gridarta.model.archetypeset.ArchetypeValidator.animationObjects
final AnimationObjects animationObjects
Definition: ArchetypeValidator.java:41
net.sf.gridarta
net.sf.gridarta.model.anim.AnimationObjects
Definition: AnimationObjects.java:30
net.sf
net.sf.gridarta.model.data.NamedObjects.get
E get(@NotNull String objectName)
net.sf.gridarta.model.errorview.ErrorView.addWarning
void addWarning(@NotNull ErrorViewCategory categoryName, @NotNull String message)
net.sf.gridarta.model.errorview.ErrorView
Definition: ErrorView.java:28
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.archetypeset.ArchetypeValidator.validate
void validate(@NotNull final ArchetypeSet<?, ?, ?> archetypeSet)
Definition: ArchetypeValidator.java:72
net
net.sf.gridarta.model.errorview
Definition: ErrorView.java:20
net.sf.gridarta.model.errorview.ErrorViewCategory
Definition: ErrorViewCategory.java:28
net.sf.gridarta.model.face.FaceObjects
Definition: FaceObjects.java:31
net.sf.gridarta.model.errorview.ErrorViewCategory.ARCHETYPE_INVALID
ARCHETYPE_INVALID
Definition: ErrorViewCategory.java:50
net.sf.gridarta.model.archetypeset.ArchetypeValidator.ArchetypeValidator
ArchetypeValidator(@NotNull final AnimationObjects animationObjects, @NotNull final FaceObjects faceObjects, @NotNull final ErrorView errorView)
Definition: ArchetypeValidator.java:62
net.sf.gridarta.model.archetypeset.ArchetypeSet<?, ?, ?>
net.sf.gridarta.model.archetypeset.ArchetypeValidator.errorView
final ErrorView errorView
Definition: ArchetypeValidator.java:53
net.sf.gridarta.model.face.FaceObject
Definition: FaceObject.java:30
net.sf.gridarta.model.archetypeset.ArchetypeValidator.faceObjects
final FaceObjects faceObjects
Definition: ArchetypeValidator.java:47
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Definition: Archetype.java:41
net.sf.gridarta.model.archetypeset.ArchetypeValidator.validateArchetype
void validateArchetype(@NotNull final Archetype<?, ?, ?> archetype)
Definition: ArchetypeValidator.java:82
net.sf.gridarta.model.face
Definition: AbstractFaceObjects.java:20
net.sf.gridarta.model.anim
Definition: AbstractAnimationObjects.java:20
net.sf.gridarta.model.archetypeset.ArchetypeValidator
Definition: ArchetypeValidator.java:35
net.sf.gridarta.model.anim.AnimationObject
Definition: AnimationObject.java:30