Gridarta Editor
GameObjectUtils.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.gameobject;
21 
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
27 
32 public class GameObjectUtils {
33 
37  private GameObjectUtils() {
38  }
39 
55  @Nullable
56  public static String getSyntaxErrors(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final ArchetypeType type) {
57  final StringBuilder errors = new StringBuilder(); // return value: all error lines
58  for (final String line : StringUtils.PATTERN_END_OF_LINE.split(gameObject.getObjectText())) {
59  // get only the key-part of the attribute.
60  final int spaceIndex = line.indexOf(' ');
61  final Comparable<String> attrKey = spaceIndex == -1 ? line : line.substring(0, spaceIndex);
62 
63  // now check if there's a match in the definitions
64  /* we exclude "direction", "type", and "name" on the hard way */
65  if (!attrKey.equals(BaseObject.DIRECTION) && !attrKey.equals(BaseObject.TYPE) && !attrKey.equals(BaseObject.NAME) && !type.hasAttributeKey(attrKey)) {
66  errors.append(line.trim()).append('\n'); // append line to the errors
67  /*
68  // the attribute doesn't match the definitions,
69  // now check if it is a negation of an entry in the archetype
70  if (line.contains(" ")) {
71  String attr_val = line.substring(line.indexOf(" ")).trim();
72  if (!(!archetype.getAttributeString(attrKey, null).isEmpty() && (attr_val.equals("0") || attr_val.equals("null") || attr_val.equals("none")))) {
73  errors.append(line.trim()).append('\n'); // append line to the errors
74  }
75  } else {
76  errors.append(line.trim()).append('\n'); // append line to the errors
77  }
78  */
79  }
80  }
81 
82  // return errors, or null if empty
83  final String retErrors = errors.toString();
84  if (retErrors.trim().isEmpty()) {
85  return null;
86  }
87  return retErrors;
88  }
89 
90 }
GameObjectUtils()
Private constructor to prevent instantiation.
Utility class for string manipulation.
static String getSyntaxErrors(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final ArchetypeType type)
This method checks the objectText for syntax errors.
Contains the data of one Gridarta Object-Type.
String TYPE
The attribute name of the object&#39;s type.
Definition: BaseObject.java:66
Base package of all Gridarta classes.
String DIRECTION
The attribute name of the object&#39;s direction.
Definition: BaseObject.java:48
Utility class for GameObject related functions.
static final Pattern PATTERN_END_OF_LINE
The pattern to match end of line characters separating lines.
String NAME
The attribute name of the object&#39;s name.
Definition: BaseObject.java:60
Defines types of GameObjects with corresponding attributes.