20 package net.sf.gridarta.model.resource;
22 import java.io.BufferedReader;
24 import java.io.FileInputStream;
25 import java.io.IOException;
26 import java.io.InputStreamReader;
27 import java.io.Reader;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.Collection;
31 import java.util.List;
48 import org.apache.log4j.Category;
49 import org.apache.log4j.Logger;
50 import org.jetbrains.annotations.NotNull;
51 import org.jetbrains.annotations.Nullable;
106 protected AbstractFilesResourcesReader(@NotNull
final File archDirectory, @NotNull
final ArchetypeSet<G, A, R> archetypeSet, @NotNull
final AbstractArchetypeParser<G, A, R, ?> archetypeParser, @NotNull
final ArchFaceProvider archFaceProvider, @NotNull
final File
collectedDirectory, @Nullable
final String
imageSet, @NotNull
final AnimationObjects animationObjects, @NotNull
final FaceObjects faceObjects) {
107 super(collectedDirectory, imageSet, animationObjects, faceObjects);
119 final int animationObjectsSize = animationObjects.
size();
121 final Collection<Pair<String, File>> animFiles =
new ArrayList<>();
123 loadArchetypesFromFiles(archDirectoryErrorViewCollector, archetypeParser,
"", archDirectory, 0,
"default",
"default", invObjects, archFaceProvider, errorView, animFiles);
125 if (LOG.isInfoEnabled()) {
126 LOG.info(
"Loaded " + (animationObjects.
size() - animationObjectsSize) +
" animations from '" + archDirectory +
"'.");
128 if (LOG.isInfoEnabled()) {
129 LOG.info(
"Loaded " + (archetypeSet.
getArchetypeCount() - archetypeCount) +
" archetypes from '" + archDirectory +
"'.");
131 if (LOG.isInfoEnabled()) {
132 LOG.info(
"Loaded " + archFaceProvider.
size() +
" faces from '" + archDirectory +
"'.");
152 private void loadArchetypesFromFiles(@NotNull
final ErrorViewCollector errorViewCollector, @NotNull
final AbstractArchetypeParser<G, A, R, ?> archetypeParser, @NotNull
final String path, @NotNull
final File f,
final int folderLevel, @NotNull
final String panelName, @NotNull
final String folderName, @NotNull
final List<G> invObjects, @NotNull
final ArchFaceProvider archFaceProvider, @NotNull
final ErrorView errorView, @NotNull
final Collection<
Pair<String, File>> animFiles) {
153 final String name = f.getName();
154 if (f.isDirectory()) {
157 final String[] entries = f.list();
158 if (entries != null) {
159 Arrays.sort(entries);
160 final String thisPanelName = folderLevel == 1 ? name : panelName;
161 final String thisFolderName = folderLevel == 1 || folderLevel == 2 ? name : folderName;
162 final String newPath = folderLevel == 0 ?
"" : path +
"/" + name;
163 for (
final String entry : entries) {
164 loadArchetypesFromFiles(errorViewCollector, archetypeParser, newPath,
new File(f, entry), folderLevel + 1, thisPanelName, thisFolderName, invObjects, archFaceProvider, errorView, animFiles);
170 }
else if (f.isFile()) {
173 try (FileInputStream fis =
new FileInputStream(f)) {
174 try (InputStreamReader isr =
new InputStreamReader(fis)) {
175 try (BufferedReader in =
new BufferedReader(isr)) {
176 archetypeParser.parseArchetypeFromStream(in, null, null, null, panelName, folderName, path, invObjects,
new ErrorViewCollector(errorView, f));
180 }
catch (
final IOException ex) {
190 animFiles.add(
new Pair<>(path, f));
201 private void parseDefFace(@NotNull
final ErrorView errorView, @NotNull
final String path, @NotNull
final String filename) {
204 try (FileInputStream fis =
new FileInputStream(path)) {
205 try (InputStreamReader isr =
new InputStreamReader(fis)) {
206 try (Reader in =
new BufferedReader(isr)) {
211 }
catch (
final IOException ex) {
230 final String animPath = pair.getFirst();
231 final File animFile = pair.getSecond();
234 }
catch (
final IOException ex) {
248 protected abstract boolean isValidEntry(
int folderLevel, String name);
int size()
Returns the number of faces.
void loadArchetypesFromFiles(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final AbstractArchetypeParser< G, A, R, ?> archetypeParser, @NotNull final String path, @NotNull final File f, final int folderLevel, @NotNull final String panelName, @NotNull final String folderName, @NotNull final List< G > invObjects, @NotNull final ArchFaceProvider archFaceProvider, @NotNull final ErrorView errorView, @NotNull final Collection< Pair< String, File >> animFiles)
Loads all archetypes and faces by recursing through the.
This exception is thrown when parsing an animation definition file (.
Convenience class for adding messages to a ErrorView instance using a fixed category name...
Reading and writing of maps, handling of paths.
Utility class for reading AnimationObjects from files.
final AbstractArchetypeParser< G, A, R, ?> archetypeParser
The AbstractArchetypeParser to use.
Abstract base class for AbstractResourcesReaders that read from individual files. ...
void addWarning(@NotNull final ErrorViewCategory category)
Adds a warning message.
int size()
Get the number of objects.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
This interface represents a lazy loader that provides images on demand.
FaceProvider read(@NotNull final ErrorView errorView, @NotNull final List< G > invObjects)
final ArchFaceProvider archFaceProvider
The ArchFaceProvider to use.
void loadAnimationsFromFiles(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final Iterable< Pair< String, File >> animFiles)
This method loads animations that are separately defined by looping through all files that were previ...
abstract boolean isValidEntry(int folderLevel, String name)
Returns whether a file name should be processed.
final File collectedDirectory
The collected directory.
Defines possible error categories for ErrorView instances.
final File archDirectory
The "arch" directory to read.
Interface for classes displaying error messages.
static void loadAnimations(@NotNull final AnimationObjects animationObjects, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String path, @NotNull final File animFile, @NotNull final String startKey, final boolean ignoreOtherText)
Loads animations from a file.
Base package of all Gridarta classes.
Utility class defining FileFilters.
void parseDefFace(@NotNull final ErrorView errorView, @NotNull final String path, @NotNull final String filename)
Loads a .face file.
static final FileFilter PNG_FILE_FILTER
Swing FileFilter for png graphics.
Reflects a game object (object on a map).
int getArchetypeCount()
Returns the number of Archetypes available.
final AnimationObjects animationObjects
The AnimationObjects to use.
final FaceObjects faceObjects
The face objects instance.
AnimationObjects is a container for AnimationObjects.
GameObjects are the objects based on Archetypes found on maps.
final String imageSet
The current image set.
static final Category LOG
The logger for printing log messages.
String getImageSet()
Returns the image set.
void addPNGFace( @NotNull final String filename, @NotNull final String path, @NotNull final String name, @NotNull final ErrorView errorView, @NotNull final ArchFaceProvider archFaceProvider)
Loads a png from the file, convert it to IconImage and attach it to the face list.
AbstractFilesResourcesReader(@NotNull final File archDirectory, @NotNull final ArchetypeSet< G, A, R > archetypeSet, @NotNull final AbstractArchetypeParser< G, A, R, ?> archetypeParser, @NotNull final ArchFaceProvider archFaceProvider, @NotNull final File collectedDirectory, @Nullable final String imageSet, @NotNull final AnimationObjects animationObjects, @NotNull final FaceObjects faceObjects)
Creates a new instance.
static final FileFilter ARC_FILE_FILTER
Swing FileFilter for .arc files.
FaceObjects is a container for FaceObjects.
static final FileFilter ANIM_FILE_FILTER
Swing FileFilter for .anim files.
The face is the appearance of an object.
int getLineNumber()
Get the number of the erroneous line.
Interface that captures similarities between different ArchetypeSet implementations.
Implementation of FaceProvider which reads images from the arch directory.
Abstract base class for archetype set loader classes.
Abstract base implementation of ArchetypeParser.
void setLoadedFromArchive(boolean loadedFromArchive)
Sets whether Archetypes were loaded from an archive.
Interface for MapArchObjects.
final ArchetypeSet< G, A, R > archetypeSet
The ArchetypeSet to update.
static final FileFilter FACE_FILE_FILTER
Swing FileFilter for .face files.