20 package net.sf.gridarta.model.archetypetype;
22 import java.util.Iterator;
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
35 public class ArchetypeType implements Iterable<ArchetypeAttributeSection> {
57 private final boolean map;
64 private final int[]
inv;
82 private final String
use;
112 public ArchetypeType(@NotNull
final String typeName,
final int typeNo, @NotNull
final String display,
final boolean map, @Nullable
final int[] inv,
final boolean allowsAllInv, @Nullable
final String description, @Nullable
final String use, @NotNull
final ArchetypeAttributesDefinition typeAttributes) {
117 this.inv = inv == null ? null : inv.clone();
130 archetypeAttributeSections.
addSection(newArchetypeAttributeSection);
135 public Iterator<ArchetypeAttributeSection>
iterator() {
136 return archetypeAttributeSections.
iterator();
181 return inv == null ? null : inv.clone();
198 @SuppressWarnings(
"NullableProblems")
201 return result == null ?
"" : result.trim();
209 @SuppressWarnings(
"NullableProblems")
211 final String result =
use;
212 return result == null ?
"" : result.trim();
244 final StringBuilder sb =
new StringBuilder();
246 return sb.toString();
254 public void toString(@NotNull
final StringBuilder sb) {
262 sb.append(typeAttribute);
266 sb.append(
" section:");
267 sb.append(archetypeAttributeSection.getSectionName());
271 sb.append(archetypeAttribute);
284 final StringBuilder sb =
new StringBuilder();
293 while (start <
display.length()) {
294 final int end =
display.indexOf(
"${", start);
299 final int end2 =
display.indexOf(
'}', end + 2);
305 sb.append(
display.substring(start, end));
306 final String spec =
display.substring(end + 2, end2);
307 final int question = spec.indexOf(
'?');
309 if (question == -1) {
310 value = baseObject.getAttributeString(spec);
312 final int colon = spec.indexOf(
':', question + 1);
313 final String attributeValue = baseObject.getAttributeString(spec.substring(0, question));
314 final boolean attributeExists = !attributeValue.isEmpty() && !attributeValue.equals(
"0");
315 if (attributeExists) {
316 value = spec.substring(question + 1, colon == -1 ? spec.length() : colon);
318 value = colon == -1 ?
"" : spec.substring(colon + 1);
324 sb.append(
display.substring(start));
328 return sb.toString();
final String typeName
The type name (artificial).
final String display
Additional description text.
A set of key/value pairs.
int [] getInv()
Returns which archetype types allow this archetype type in their inventories.
boolean hasAttributeKey(@NotNull final Comparable< String > key)
Returns whether an attribute key is defined.
final boolean allowsAllInv
Whether this archetype type allows any inventory game objects, whether these types have "inv" specifi...
boolean hasAttribute()
Returns whether this archetype type defines at least one archetype attribute.
A set of ArchetypeAttributeDefinitions.
boolean hasAttribute()
Returns whether this archetype type defines at least one archetype attribute.
This Class contains the data of one archetype attribute.
void toString(@NotNull final StringBuilder sb)
Appends a string representation of this instance to a StringBuilder.
boolean hasTypeAttributes()
Returns whether any type attributes are defined.
String getDisplayName(@NotNull final Attributes baseObject)
Returns a description of this type.
boolean isMap()
Returns whether this archetype is allowed on maps.
Contains the data of one Gridarta Object-Type.
final boolean map
Whether this archetype type is allowed on maps.
boolean isEmpty()
Returns whether no attribute definitions exist.
ArchetypeType(@NotNull final String typeName, final int typeNo, @NotNull final String display, final boolean map, @Nullable final int[] inv, final boolean allowsAllInv, @Nullable final String description, @Nullable final String use, @NotNull final ArchetypeAttributesDefinition typeAttributes)
Creates a new instance.
final ArchetypeAttributesDefinition typeAttributes
The list of additional attributes that an object must have in order to be of this type...
Base package of all Gridarta classes.
void addArchetypeAttribute(@NotNull final String sectionName, @NotNull final ArchetypeAttribute archetypeAttribute)
Adds an ArchetypeAttribute to this archetype type.
A set of ArchetypeAttributes.
final int [] inv
Which archetype types allow this archetype type in their inventories or.
final String use
The usage notes.
final ArchetypeAttributeSections archetypeAttributeSections
All ArchetypeAttributeSections in display order.
int getTypeNo()
Returns the type number.
final String description
The description.
String getDescription()
Returns the description.
A list of ArchetypeAttributeSection instances.
Holds the key/value pair of an archetype attribute definition.
Iterator< ArchetypeAttributeSection > iterator()
Iterator< ArchetypeAttributeSection > iterator()
Returns a read-only Iterator returning all sections in display order.
boolean hasAttributeKey(@NotNull final Comparable< String > key)
Returns whether an attribute key is defined.
final void addSection(@NotNull final ArchetypeAttributeSection section)
Adds an ArchetypeAttributeSection.
void addAttributeSection(@NotNull final ArchetypeAttributeSection newArchetypeAttributeSection)
Adds an ArchetypeAttributeSection.
final int typeNo
The type number.
boolean matches(@NotNull final BaseObject<?, ?, ?, ?> baseObject)
Checks whether a BaseObject matches all type attributes.
void addArchetypeAttribute(@NotNull final String sectionName, @NotNull final ArchetypeAttribute archetypeAttribute)
Adds an ArchetypeAttribute to this archetype type.
boolean isAllowsAllInv()
Returns whether this archetype type allows any inventory game objects, regardless whether these types...
boolean matches(@NotNull final Attributes baseObject)
Checks whether an Attributes instance matches all type attributes.
String getTypeName()
Returns the type name (artificial).
String getUse()
Returns the usage notes.