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 }
final FaceObjects faceObjects
The FaceObjects instance for looking up face names.
Common interface for FaceObject.
Definition: FaceObject.java:30
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
Utility class for validating ArchetypeSet instances.
void validateArchetype(@NotNull final Archetype<?, ?, ?> archetype)
Validates an Archetype instance.
void addWarning(@NotNull ErrorViewCategory categoryName, @NotNull String message)
Adds a warning message.
Defines possible error categories for ErrorView instances.
Interface for classes displaying error messages.
Definition: ErrorView.java:28
Base package of all Gridarta classes.
E get(@NotNull String objectName)
Gets a AbstractNamedObject.
AnimationObjects is a container for AnimationObjects.
An AnimationObject reflects the animation ("@code anim\n @endcode " ...
FaceObjects is a container for FaceObjects.
The face is the appearance of an object.
void validate(@NotNull final ArchetypeSet<?, ?, ?> archetypeSet)
Validates an ArchetypeSet instance.
final AnimationObjects animationObjects
The AnimationObjects instance for looking up animation names.
final ErrorView errorView
The ErrorView for reporting errors.
ArchetypeValidator(@NotNull final AnimationObjects animationObjects, @NotNull final FaceObjects faceObjects, @NotNull final ErrorView errorView)
Creates a new instance.