20 package net.sf.gridarta.model.archetypetype;
22 import java.util.regex.Pattern;
25 import nu.xom.Attribute;
26 import nu.xom.Element;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
41 private static final Pattern
LINE_BREAK = Pattern.compile(
"\\s*\n\\s*");
47 private static final Pattern
UNDERSCORE = Pattern.compile(
"_");
75 @SuppressWarnings(
"FeatureEnvy")
77 final String description =
parseText(attributeElement);
80 if (attributeType.equals(
"bool")) {
82 }
else if (attributeType.equals(
"bool_special")) {
84 }
else if (attributeType.equals(
"int")) {
90 if (minValue > maxValue) {
95 if (minCheckValue > maxCheckValue) {
100 if (minCheckValue < minValue) {
105 if (maxCheckValue > maxValue) {
111 }
else if (attributeType.equals(
"long")) {
113 }
else if (attributeType.equals(
"float")) {
115 }
else if (attributeType.equals(
"string")) {
117 }
else if (attributeType.equals(
"map_path")) {
119 }
else if (attributeType.equals(
"script_file")) {
121 }
else if (attributeType.equals(
"facename")) {
123 }
else if (attributeType.equals(
"animname")) {
125 }
else if (attributeType.equals(
"text")) {
127 }
else if (attributeType.equals(
"fixed")) {
129 }
else if (attributeType.equals(
"spell")) {
131 }
else if (attributeType.equals(
"nz_spell")) {
133 }
else if (attributeType.equals(
"inv_spell")) {
135 }
else if (attributeType.equals(
"inv_spell_optional")) {
137 }
else if (attributeType.startsWith(
"bitmask")) {
139 final String bitmaskName = attributeType.substring(8).trim();
140 if (archetypeTypeSet.getBitmask(bitmaskName) == null) {
145 }
else if (attributeType.startsWith(
"list_")) {
147 final String listName = attributeType.substring(5).trim();
148 if (archetypeTypeSet.getList(listName) == null) {
153 }
else if (attributeType.startsWith(
"list2_")) {
155 final String listNames = attributeType.substring(6).trim();
156 final String[] tmp = UNDERSCORE.split(listNames, 2);
157 if (tmp.length != 2) {
161 final String listName1 = tmp[0];
162 final String listName2 = tmp[1];
163 if (archetypeTypeSet.getList(listName1) == null) {
167 if (archetypeTypeSet.getList(listName2) == null) {
172 }
else if (attributeType.equals(
"treasurelist")) {
189 private static String
parseText(@NotNull
final Node attributeElement) {
190 final String tmp = attributeElement.getValue().trim();
191 return LINE_BREAK.matcher(tmp).replaceAll(tmp.startsWith(
"<html>") ?
" " :
"\n");
203 final Attribute attr = element.getAttribute(attributeKey);
208 return attr.getValue().trim();
220 final Attribute attr = element.getAttribute(attributeKey);
221 return attr == null ? null : attr.getValue().trim();
234 private static int getAttributeIntValue(@NotNull
final Element element, @NotNull
final String attributeKey,
final int defaultValue, @NotNull
final String typeName, @NotNull
final ErrorViewCollector errorViewCollector) {
241 return Integer.parseInt(value);
242 }
catch (
final NumberFormatException ignored) {
243 errorViewCollector.addWarning(
ErrorViewCategory.
TYPES_ENTRY_INVALID,
"type " + typeName +
" has attribute '" + attributeKey +
"' with invalid value '" + value +
"' (must be a number).");
Utility class for parsing ArchetypeAttributes.
Convenience class for adding messages to a ErrorView instance using a fixed category name...
static final String XML_ATTRIBUTE_CHECK_MIN
The name of the "check_min" attribute within XML_ELEMENT_ATTRIBUTE elements.
ArchetypeAttribute load(@NotNull final Element attributeElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final String typeName)
Loading the data from an xml element into this object.
Interface for classes implementing ArchetypeAttribute factories.
Manages ArchetypeType instances, list, and bitmask definitions.
This Class contains the data of one archetype attribute.
ArchetypeAttribute newArchetypeAttributeInvSpellOptional(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "inv spell optional" archetype attribute.
static final Pattern LINE_BREAK
Pattern to match line breaks in attribute text.
static final String XML_ATTRIBUTE_MAX
The name of the "max" attribute within XML_ELEMENT_ATTRIBUTE elements.
ArchetypeAttribute newArchetypeAttributeBitmask(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength, @NotNull String bitmaskName)
Creates a new "bitmask" archetype attribute.
static final String XML_ATTRIBUTE_ARCH_END
The name of the "arch_end" attribute within XML_ELEMENT_ATTRIBUTE elements.
static String getAttributeValueOptional(@NotNull final Element element, @NotNull final String attributeKey)
Returns the value of an attribute.
ArchetypeAttribute newArchetypeAttributeAnimname(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "animname" archetype attribute.
An Exception thrown if an attribute key does not exist.
static final String XML_ATTRIBUTE_LENGTH
The name of the "length" attribute within XML_ELEMENT_ATTRIBUTE elements.
ArchetypeAttribute newArchetypeAttributeList(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength, @NotNull String listName)
Creates a new "list" archetype attribute.
Constants needed to parse "types.xml" files.
static int getAttributeIntValue(@NotNull final Element element, @NotNull final String attributeKey, final int defaultValue, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector)
Returns the value of an attribute as an.
static final String XML_ATTRIBUTE_EDITOR
The name of the "editor" attribute within XML_ELEMENT_ATTRIBUTE elements.
static String parseText(@NotNull final Node attributeElement)
This method reads the text out of the element's "body" and cuts off white spaces at front/end of line...
Defines possible error categories for ErrorView instances.
ArchetypeAttribute newArchetypeAttributeText(@NotNull String archetypeAttributeName, @NotNull String endingOld, @NotNull String attributeName, @NotNull String description, int inputLength, @Nullable String fileExtension)
Creates a new "text" archetype attribute.
Base package of all Gridarta classes.
ArchetypeAttribute newArchetypeAttributeInvSpell(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "inv spell" archetype attribute.
static final String XML_ATTRIBUTE_TRUE
The name of the "true" attribute within XML_ELEMENT_ATTRIBUTE elements.
ArchetypeAttribute newArchetypeAttributeBoolSpec(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength, @NotNull String trueValue, @NotNull String falseValue)
Creates a new "bool spec" archetype attribute.
ArchetypeAttribute newArchetypeAttributeInt(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength, int minValue, int maxValue, int minCheckValue, int maxCheckValue)
Creates a new "int" archetype attribute.
static final String XML_ATTRIBUTE_ARCH
The name of the "arch" attribute within XML_ELEMENT_ATTRIBUTE elements.
static final String XML_ATTRIBUTE_TYPE
The name of the "type" attribute within XML_ELEMENT_ATTRIBUTE elements.
static final String XML_ATTRIBUTE_FALSE
The name of the "false" attribute within XML_ELEMENT_ATTRIBUTE elements.
static final Pattern UNDERSCORE
Pattern to match the list name separator in "list2_xxx_yyy" types.
ArchetypeAttribute newArchetypeAttributeSpell(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "spell" archetype attribute.
ArchetypeAttribute newArchetypeAttributeFacename(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "face name" archetype attribute.
static final String XML_ATTRIBUTE_CHECK_MAX
The name of the "check_max" attribute within XML_ELEMENT_ATTRIBUTE elements.
ArchetypeAttribute newArchetypeAttributeZSpell(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "z-spell" archetype attribute.
ArchetypeAttribute newArchetypeAttributeTreasure(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "treasure" archetype attribute.
ArchetypeAttributeParser(@NotNull final ArchetypeAttributeFactory archetypeAttributeFactory)
Creates a new instance.
static final String XML_ATTRIBUTE_MIN
The name of the "min" attribute within XML_ELEMENT_ATTRIBUTE elements.
ArchetypeAttribute newArchetypeAttributeMapPath(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "map path" archetype attribute.
static final String XML_ATTRIBUTE_VALUE
The name of the "value" attribute within XML_ELEMENT_ATTRIBUTE elements.
static final String XML_ATTRIBUTE_MARKER
The name of the "marker" attribute within XML_ELEMENT_ATTRIBUTE elements.
ArchetypeAttribute newArchetypeAttributeBool(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "bool" archetype attribute.
ArchetypeAttribute newArchetypeAttributeFixed(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "fixed" archetype attribute.
ArchetypeAttribute newArchetypeAttributeString(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "string" archetype attribute.
ArchetypeAttribute newArchetypeAttributeFloat(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "float" archetype attribute.
ArchetypeAttribute newArchetypeAttributeList2(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength, @NotNull String listName1, @NotNull String listName2)
Creates a new "list2" archetype attribute.
static final String XML_ATTRIBUTE_ARCH_BEGIN
The name of the "arch_begin" attribute within XML_ELEMENT_ATTRIBUTE elements.
final ArchetypeAttributeFactory archetypeAttributeFactory
The ArchetypeAttributeFactory for creating ArchetypeAttributes.
ArchetypeAttribute newArchetypeAttributeScriptFile(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "script file" archetype attribute.
static String getAttributeValue(@NotNull final Element element, @NotNull final String attributeKey)
Returns the value of an attribute.
ArchetypeAttribute newArchetypeAttributeLong(@NotNull String archetypeAttributeName, @NotNull String attributeName, @NotNull String description, int inputLength)
Creates a new "long" archetype attribute.