Gridarta Editor
AnimationValidator.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.anim;
21 
27 import org.jetbrains.annotations.NotNull;
28 
33 public class AnimationValidator {
34 
38  @NotNull
39  private final FaceObjects faceObjects;
40 
44  @NotNull
45  private final ErrorView errorView;
46 
52  public AnimationValidator(@NotNull final FaceObjects faceObjects, @NotNull final ErrorView errorView) {
53  this.faceObjects = faceObjects;
54  this.errorView = errorView;
55  }
56 
61  public void validate(@NotNull final Iterable<AnimationObject> animationObjects) {
62  for (final AnimationObject animationObject : animationObjects) {
63  validateAnimation(animationObject);
64  }
65  }
66 
71  private void validateAnimation(@NotNull final AnimationObject animationObject) {
72  for (final String faceName : StringUtils.PATTERN_NEWLINE.split(animationObject.getAnimList())) {
73  if (!faceName.startsWith("facings ")) {
74  final FaceObject face = faceObjects.get(faceName);
75  if (face == null) {
76  errorView.addWarning(ErrorViewCategory.ANIMATION_INVALID, animationObject.getAnimName() + " references undefined face '" + faceName + "'");
77  }
78  }
79  }
80  }
81 
82 }
Utility class for string manipulation.
void validate(@NotNull final Iterable< AnimationObject > animationObjects)
Validates a set of AnimationObjects.
Common interface for FaceObject.
Definition: FaceObject.java:30
static final Pattern PATTERN_NEWLINE
The pattern that matches a single newline ("\n").
final FaceObjects faceObjects
The FaceObjects instance for looking up face names.
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.
An AnimationObject reflects the animation ("@code anim\n @endcode " ...
void validateAnimation(@NotNull final AnimationObject animationObject)
Validates an AnimationObject instance.
FaceObjects is a container for FaceObjects.
AnimationValidator(@NotNull final FaceObjects faceObjects, @NotNull final ErrorView errorView)
Creates a new instance.
The face is the appearance of an object.
Utility class for validating AnimationObject instances.
final ErrorView errorView
The ErrorView for reporting errors.