20 package net.sf.gridarta.model.autojoin;
22 import java.io.BufferedReader;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.InputStreamReader;
27 import java.io.Reader;
29 import java.util.ArrayList;
30 import java.util.List;
40 import org.jetbrains.annotations.NotNull;
51 private static final String
FILENAME =
"autojoin.txt";
67 public static <G extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>>
AutojoinLists<G, A, R> loadList(@NotNull
final ErrorView errorView,
final ArchetypeSet<G, A, R> archetypeSet, @NotNull
final File baseDir) {
71 try (InputStream inputStream = url.openStream()) {
73 try (BufferedReader stream =
new BufferedReader(reader)) {
74 return loadList(errorView, archetypeSet, url, stream);
78 }
catch (
final IOException ex) {
81 }
catch (
final IOException ex) {
98 private static <G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends
Archetype<G, A, R>>
AutojoinLists<G, A, R> loadList(@NotNull
final ErrorView errorView,
final ArchetypeSet<G, A, R> archetypeSet, @NotNull
final URL url, @NotNull
final BufferedReader bufferedReader)
throws IOException {
100 boolean sectionFlag =
false;
102 final StringBuilder undefinedArchetypes =
new StringBuilder();
103 boolean skipList =
true;
105 final String line2 = bufferedReader.readLine();
109 if (!line2.startsWith(
"#") && !line2.isEmpty()) {
110 final String line = line2.trim();
114 if (line.equals(
"end")) {
115 if (undefinedArchetypes.length() > 0) {
128 final List<R> tmp =
new ArrayList<>();
131 final R archetype = archetypeSet.
getArchetype(archetypeName);
132 if (archetype.isMulti()) {
139 undefinedArchetypes.append(
' ').append(ex.getMessage());
147 if (line.equals(
"start")) {
151 undefinedArchetypes.setLength(0);
156 return autojoinLists;
Utility class for string manipulation.
AutojoinListsParser()
Creates a new instance.
static final String FILENAME
The file defining autojoin lists.
Loader for AutojoinLists instances from files.
static final String MAP_ENCODING
Encoding to use for maps and other data.
Defines possible error categories for ErrorView instances.
Contains a list of (typically wall-)arches which do autojoining.
Interface for classes displaying error messages.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
R getArchetype(@NotNull String archetypeName)
Returns an Archetype by its name.
Utility-class for Gridarta's I/O.
GameObjects are the objects based on Archetypes found on maps.
Exception thrown if an AutojoinList is invalid.
static URL getResource(@Nullable final File dir, @NotNull final String fileName)
Get the URL of a resource.
void addAutojoinList(@NotNull final AutojoinList< G, A, R > autojoinList)
Adds a new autojoin list.
Exception thrown if an Archetype does not exist.
static final Pattern PATTERN_WHITESPACE
Pattern to match whitespace excluding NL and CR.
static final int SIZE
The number of archetypes in an autojoin list.
Interface that captures similarities between different ArchetypeSet implementations.
Interface for MapArchObjects.