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-2023 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 }
net.sf.gridarta.model.anim.AnimationValidator.faceObjects
final FaceObjects faceObjects
The FaceObjects instance for looking up face names.
Definition: AnimationValidator.java:39
net.sf.gridarta
Base package of all Gridarta classes.
net.sf
net.sf.gridarta.model.data.NamedObjects.get
E get(@NotNull String objectName)
Gets a AbstractNamedObject.
net.sf.gridarta.model.errorview.ErrorView.addWarning
void addWarning(@NotNull ErrorViewCategory categoryName, @NotNull String message)
Adds a warning message.
net.sf.gridarta.model.errorview.ErrorView
Interface for classes displaying error messages.
Definition: ErrorView.java:28
net
net.sf.gridarta.model.errorview
Definition: ErrorView.java:20
net.sf.gridarta.model.anim.AnimationValidator.AnimationValidator
AnimationValidator(@NotNull final FaceObjects faceObjects, @NotNull final ErrorView errorView)
Creates a new instance.
Definition: AnimationValidator.java:52
net.sf.gridarta.model.errorview.ErrorViewCategory
Defines possible error categories for ErrorView instances.
Definition: ErrorViewCategory.java:28
net.sf.gridarta.model.anim.AnimationValidator
Utility class for validating AnimationObject instances.
Definition: AnimationValidator.java:33
net.sf.gridarta.model.face.FaceObjects
FaceObjects is a container for FaceObjects.
Definition: FaceObjects.java:31
net.sf.gridarta.utils.StringUtils
Utility class for string manipulation.
Definition: StringUtils.java:31
net.sf.gridarta.model.face.FaceObject
Common interface for FaceObject.
Definition: FaceObject.java:30
net.sf.gridarta.model.anim.AnimationValidator.validateAnimation
void validateAnimation(@NotNull final AnimationObject animationObject)
Validates an AnimationObject instance.
Definition: AnimationValidator.java:71
net.sf.gridarta.model
net.sf.gridarta.model.errorview.ErrorViewCategory.ANIMATION_INVALID
ANIMATION_INVALID
Definition: ErrorViewCategory.java:34
net.sf.gridarta.utils.StringUtils.PATTERN_NEWLINE
static final Pattern PATTERN_NEWLINE
The pattern that matches a single newline ("\n").
Definition: StringUtils.java:109
net.sf.gridarta.model.anim.AnimationValidator.validate
void validate(@NotNull final Iterable< AnimationObject > animationObjects)
Validates a set of AnimationObjects.
Definition: AnimationValidator.java:61
net.sf.gridarta.model.face
The face is the appearance of an object.
Definition: AbstractFaceObjects.java:20
net.sf.gridarta.model.anim.AnimationObject
An AnimationObject reflects the animation ("@code anim\n @endcode " ...
Definition: AnimationObject.java:30
net.sf.gridarta.model.anim.AnimationValidator.errorView
final ErrorView errorView
The ErrorView for reporting errors.
Definition: AnimationValidator.java:45
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20