20 package net.sf.gridarta.model.archetype;
22 import java.util.LinkedHashMap;
24 import java.util.Map.Entry;
32 import org.jetbrains.annotations.NotNull;
33 import org.jetbrains.annotations.Nullable;
66 private final Map<String, String>
attributes =
new LinkedHashMap<>();
94 if (prototype == null) {
97 archetype = prototype.clone();
102 public void reInit(@NotNull
final String archetypeName) {
103 if (archetype == null) {
104 archetype = gameObjectFactory.
newArchetype(archetypeName);
106 archetype.setArchetypeName(archetypeName);
112 if (archetype == null) {
113 throw new IllegalStateException();
115 archetype.setMsgText(msgText);
120 if (archetype == null) {
121 throw new IllegalStateException();
123 return archetype.getArchetypeName();
127 if (archetype == null) {
128 throw new IllegalStateException();
130 if (errorViewCollector == null) {
131 throw new IllegalStateException();
134 if (line.indexOf(
'\n') != -1) {
135 throw new IllegalArgumentException();
139 final String key = tmp[0];
140 if (tmp.length < 2) {
141 assert archetype != null;
142 final String archetypeName = archetype.getArchetypeName();
143 assert errorViewCollector != null;
147 final String value = tmp[1];
148 final String previousValue = attributes.put(key, value);
149 if (previousValue != null) {
150 assert archetype != null;
151 final String archetypeName = archetype.getArchetypeName();
152 assert errorViewCollector != null;
157 public void addLast(@NotNull
final G invObject) {
158 if (archetype == null) {
159 throw new IllegalStateException();
161 archetype.addLast(invObject);
172 assert prototype != null;
176 if (archetype == null) {
177 throw new IllegalStateException();
180 final StringBuilder sb =
new StringBuilder();
184 if (tmp.length == 2 && !attributes.containsKey(tmp[0])) {
185 sb.append(attribute).append(
'\n');
188 for (
final Entry<String, String> attribute : attributes.entrySet()) {
189 sb.append(attribute.getKey()).append(
' ').append(attribute.getValue()).append(
'\n');
191 result.setObjectText(sb.toString());
197 if (archetype == null) {
198 throw new IllegalStateException();
200 archetype.setMultiX(multiX);
204 if (archetype == null) {
205 throw new IllegalStateException();
207 archetype.setMultiY(multiY);
216 if (result == null) {
217 throw new IllegalStateException();
void setMsgText(@NotNull final String msgText)
R finish()
Finishes archetype construction.
Utility class for string manipulation.
Convenience class for adding messages to a ErrorView instance using a fixed category name...
void addLast(@NotNull final G invObject)
void reInit(@NotNull final String archetypeName)
R archetype
The Archetype being built.
void addWarning(@NotNull final ErrorViewCategory category)
Adds a warning message.
static final Pattern PATTERN_SPACES
The pattern that matches a non-empty sequence of spaces.
Defines possible error categories for ErrorView instances.
R prototype
The base Archetype for artifacts.
final Map< String, String > attributes
Collected attributes.
void init(@Nullable final R prototype, @NotNull final ErrorViewCollector errorViewCollector)
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Abstract factory for creating GameObject instances.
final GameObjectFactory< G, A, R > gameObjectFactory
The GameObjectFactory for creating new Archetypes.
GameObjects are the objects based on Archetypes found on maps.
R newArchetype(@NotNull String archetypeName)
Creates a new Archetype instance.
void addObjectText(@NotNull final String line)
void setMultiX(final int multiX)
Creates Archetype instances.
AbstractArchetypeBuilder(@NotNull final GameObjectFactory< G, A, R > gameObjectFactory)
Creates a new instance.
ErrorViewCollector errorViewCollector
The ErrorViewCollector for reporting errors.
void setMultiY(final int multiY)
static final Pattern PATTERN_END_OF_LINE
The pattern to match end of line characters separating lines.
String NAME
The attribute name of the object's name.
R getArchetype()
TypeMayBeWeakened
String getArchetypeName()
Interface for MapArchObjects.