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")) {
83 if (attributeType.equals(
"bool_special")) {
86 if (attributeType.equals(
"int")) {
92 if (minValue > maxValue) {
97 if (minCheckValue > maxCheckValue) {
102 if (minCheckValue < minValue) {
107 if (maxCheckValue > maxValue) {
114 if (attributeType.equals(
"long")) {
117 if (attributeType.equals(
"float")) {
120 if (attributeType.equals(
"string")) {
123 if (attributeType.equals(
"map_path")) {
126 if (attributeType.equals(
"script_file")) {
129 if (attributeType.equals(
"facename")) {
132 if (attributeType.equals(
"animname")) {
135 if (attributeType.equals(
"text")) {
138 if (attributeType.equals(
"fixed")) {
141 if (attributeType.equals(
"spell")) {
144 if (attributeType.equals(
"nz_spell")) {
147 if (attributeType.equals(
"inv_spell")) {
150 if (attributeType.equals(
"inv_spell_optional")) {
153 if (attributeType.startsWith(
"bitmask")) {
155 final String bitmaskName = attributeType.substring(8).trim();
156 if (archetypeTypeSet.getBitmask(bitmaskName) ==
null) {
162 if (attributeType.startsWith(
"list_")) {
164 final String listName = attributeType.substring(5).trim();
165 if (archetypeTypeSet.getList(listName) ==
null) {
171 if (attributeType.startsWith(
"list2_")) {
173 final String listNames = attributeType.substring(6).trim();
174 final String[] tmp =
UNDERSCORE.split(listNames, 2);
175 if (tmp.length != 2) {
179 final String listName1 = tmp[0];
180 final String listName2 = tmp[1];
181 if (archetypeTypeSet.getList(listName1) ==
null) {
185 if (archetypeTypeSet.getList(listName2) ==
null) {
191 if (attributeType.equals(
"treasurelist")) {
207 private static String
parseText(@NotNull
final Node attributeElement) {
208 final String tmp = attributeElement.getValue().trim();
209 return LINE_BREAK.matcher(tmp).replaceAll(tmp.startsWith(
"<html>") ?
" " :
"\n");
221 final Attribute attr = element.getAttribute(attributeKey);
226 return attr.getValue().trim();
238 final Attribute attr = element.getAttribute(attributeKey);
239 return attr ==
null ? null : attr.getValue().trim();
252 private static int getAttributeIntValue(@NotNull
final Element element, @NotNull
final String attributeKey,
final int defaultValue, @NotNull
final String typeName, @NotNull
final ErrorViewCollector errorViewCollector) {
259 return Integer.parseInt(value);
260 }
catch (
final NumberFormatException ignored) {
261 errorViewCollector.addWarning(
ErrorViewCategory.
TYPES_ENTRY_INVALID,
"type " + typeName +
" has attribute '" + attributeKey +
"' with invalid value '" + value +
"' (must be a number).");