Gridarta Editor
GameObjectMatchersParser.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.match;
21 
25 import nu.xom.Document;
26 import nu.xom.Element;
27 import org.apache.log4j.Category;
28 import org.apache.log4j.Logger;
29 import org.jetbrains.annotations.NotNull;
30 
36 
40  @NotNull
41  private static final Category LOG = Logger.getLogger(GameObjectMatchersParser.class);
42 
47  }
48 
55  public static void readGameObjectMatchers(@NotNull final Document document, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final ErrorViewCollector errorViewCollector) {
56  int count = 0;
57  int editType = 1;
58  final Element rootElement = document.getRootElement();
59  for (final Element node : new ElementsIterable(rootElement.getChildElements("GameObjectMatcher"))) {
60  final NamedGameObjectMatcher archObjectMatcher;
61  try {
62  archObjectMatcher = GameObjectMatcherParser.parseMatcher(node, editType);
63  } catch (final ParsingException ex) {
64  errorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_ENTRY_INVALID, node.getAttribute("id") + ": " + ex.getMessage());
65  continue;
66  }
67  gameObjectMatchers.addGameObjectMatcher(archObjectMatcher);
68  count++;
69  if (editType != 0 && !archObjectMatcher.isSystemMatcher()) {
70  editType <<= 1;
71  if (editType == 0) {
72  errorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_ENTRY_INVALID, "too many GameObjectMatchers, ignoring rest");
73  }
74  }
75  }
76  if (LOG.isInfoEnabled()) {
77  LOG.info("Loaded " + count + " GameObjectMatchers.");
78  }
79  }
80 
81 }
net.sf.gridarta.model.match.GameObjectMatchersParser
Parser for the GameObjectMatchers.xml file.
Definition: GameObjectMatchersParser.java:35
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.match.GameObjectMatcherParser
Class for some default GameObjectMatchers.
Definition: GameObjectMatcherParser.java:37
net.sf.gridarta.model.match.NamedGameObjectMatcher.isSystemMatcher
boolean isSystemMatcher()
Returns whether this matcher is a system matcher.
Definition: NamedGameObjectMatcher.java:160
net.sf
net.sf.gridarta.model.match.NamedGameObjectMatcher
Decorates an arbitrary GameObjectMatcher with a localized name that is suitable for the user interfac...
Definition: NamedGameObjectMatcher.java:33
net.sf.gridarta.model.errorview.ErrorViewCategory.GAMEOBJECTMATCHERS_ENTRY_INVALID
GAMEOBJECTMATCHERS_ENTRY_INVALID
Definition: ErrorViewCategory.java:68
net
net.sf.gridarta.model.match.GameObjectMatchersParser.GameObjectMatchersParser
GameObjectMatchersParser()
Private constructor to prevent instantiation.
Definition: GameObjectMatchersParser.java:46
net.sf.gridarta.model.errorview
Definition: ErrorView.java:20
net.sf.gridarta.model.errorview.ErrorViewCollector
Convenience class for adding messages to a ErrorView instance using a fixed category name.
Definition: ErrorViewCollector.java:31
net.sf.gridarta.model.errorview.ErrorViewCategory
Defines possible error categories for ErrorView instances.
Definition: ErrorViewCategory.java:28
net.sf.gridarta.utils.xml.ElementsIterable
Definition: ElementsIterable.java:30
net.sf.gridarta.model.match.GameObjectMatcherParser.parseMatcher
static NamedGameObjectMatcher parseMatcher(@NotNull final Element el, final int editType)
Creates a NamedGameObjectMatcher from XML.
Definition: GameObjectMatcherParser.java:137
net.sf.gridarta.model.match.GameObjectMatchers
Maintains GameObjectMatcher instances.
Definition: GameObjectMatchers.java:40
net.sf.gridarta.model.match.GameObjectMatchersParser.LOG
static final Category LOG
The Logger for printing log messages.
Definition: GameObjectMatchersParser.java:41
net.sf.gridarta.model.match.ParsingException
Thrown when a parsing error occurs.
Definition: ParsingException.java:29
net.sf.gridarta.model
net.sf.gridarta.utils.xml
Definition: ElementsIterable.java:20
net.sf.gridarta.model.match.GameObjectMatchersParser.readGameObjectMatchers
static void readGameObjectMatchers(@NotNull final Document document, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final ErrorViewCollector errorViewCollector)
Parses a .xml file defining game object matchers.
Definition: GameObjectMatchersParser.java:55
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20