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-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.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  return retErrors.trim().isEmpty() ? null : retErrors;
85  }
86 
87 }
net.sf.gridarta.model.archetypetype
Definition: AbstractArchetypeAttributeInvSpell.java:20
net.sf.gridarta.model.baseobject.BaseObject.NAME
String NAME
Definition: BaseObject.java:60
net.sf.gridarta.model.baseobject.BaseObject.DIRECTION
String DIRECTION
Definition: BaseObject.java:48
net.sf.gridarta.utils.StringUtils
Definition: StringUtils.java:31
net.sf.gridarta
net.sf.gridarta.utils.StringUtils.PATTERN_END_OF_LINE
static final Pattern PATTERN_END_OF_LINE
Definition: StringUtils.java:61
net.sf
net.sf.gridarta.model.baseobject.BaseObject
Definition: BaseObject.java:34
net.sf.gridarta.model.gameobject.GameObjectUtils.GameObjectUtils
GameObjectUtils()
Definition: GameObjectUtils.java:37
net
errors
errors
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:1
net.sf.gridarta.model.baseobject.BaseObject.TYPE
String TYPE
Definition: BaseObject.java:66
net.sf.gridarta.model
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.model.gameobject.GameObjectUtils
Definition: GameObjectUtils.java:32
net.sf.gridarta.model.archetypetype.ArchetypeType
Definition: ArchetypeType.java:35
net.sf.gridarta.model.gameobject.GameObjectUtils.getSyntaxErrors
static String getSyntaxErrors(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final ArchetypeType type)
Definition: GameObjectUtils.java:56
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20