 |
Gridarta Editor
|
Go to the documentation of this file.
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;
49 import org.apache.log4j.Category;
50 import org.apache.log4j.Logger;
51 import org.jetbrains.annotations.NotNull;
52 import org.jetbrains.annotations.Nullable;
115 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, @NotNull
final AbstractAnimationObjectsReader animationObjectsReader) {
131 final Collection<Pair<String, File>> animFiles =
new ArrayList<>();
133 loadArchetypesFromFiles(archDirectoryErrorViewCollector,
archetypeParser,
"",
archDirectory, 0,
"default",
"default", invObjects,
archFaceProvider, errorView, animFiles);
135 if (
LOG.isInfoEnabled()) {
138 if (
LOG.isInfoEnabled()) {
141 if (
LOG.isInfoEnabled()) {
162 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) {
163 final String
name = f.getName();
164 if (f.isDirectory()) {
167 final String[] entries = f.list();
168 if (entries ==
null) {
171 Arrays.sort(entries);
172 final String thisPanelName = folderLevel == 1 ?
name : panelName;
173 final String thisFolderName = folderLevel == 1 || folderLevel == 2 ?
name : folderName;
174 final String newPath = folderLevel == 0 ?
"" : path +
"/" +
name;
175 for (
final String entry : entries) {
176 loadArchetypesFromFiles(errorViewCollector,
archetypeParser, newPath,
new File(f, entry), folderLevel + 1, thisPanelName, thisFolderName, invObjects,
archFaceProvider, errorView, animFiles);
180 }
else if (f.isFile()) {
183 try (FileInputStream fis =
new FileInputStream(f)) {
185 try (BufferedReader in =
new BufferedReader(isr)) {
190 }
catch (
final IOException ex) {
200 animFiles.add(
new Pair<>(path, f));
211 private void parseDefFace(@NotNull
final ErrorView errorView, @NotNull
final String path, @NotNull
final String filename) {
214 try (FileInputStream fis =
new FileInputStream(path)) {
216 try (Reader in =
new BufferedReader(isr)) {
221 }
catch (
final IOException ex) {
240 final String animPath = pair.getFirst();
241 final File animFile = pair.getSecond();
244 }
catch (
final IOException ex) {
This interface represents a lazy loader that provides images on demand.
void addWarning(@NotNull final ErrorViewCategory category)
Adds a warning message.
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.
final AnimationObjects animationObjects
The AnimationObjects to use.
Base package of all Gridarta classes.
Abstract base implementation of ArchetypeParser.
AnimationObjects is a container for AnimationObjects.
Implementation of FaceProvider which reads images from the arch directory.
Abstract base class for archetype set loader classes.
void setLoadedFromArchive(boolean loadedFromArchive)
Sets whether Archetypes were loaded from an archive.
Utility class for reading AnimationObjects from files.
int size()
Get the number of objects.
Interface for classes displaying error messages.
final ArchetypeSet< G, A, R > archetypeSet
The ArchetypeSet to update.
Reflects a game object (object on a map).
int getLineNumber()
Returns the number of the erroneous line.
final File collectedDirectory
The collected directory.
GameObjects are the objects based on Archetypes found on maps.
final ArchFaceProvider archFaceProvider
The ArchFaceProvider to use.
FaceProvider read(@NotNull final ErrorView errorView, @NotNull final List< G > invObjects)
int getArchetypeCount()
Returns the number of Archetypes available.
Convenience class for adding messages to a ErrorView instance using a fixed category name.
static final FileFilter ANIM_FILE_FILTER
Swing FileFilter for .anim files.
This exception is thrown when parsing an animation definition file (.
Defines possible error categories for ErrorView instances.
String getImageSet()
Returns the image set.
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, @NotNull final AbstractAnimationObjectsReader animationObjectsReader)
Creates a new instance.
Interface for MapArchObjects.
final String imageSet
The current image set.
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...
static final Category LOG
The logger for printing log messages.
FaceObjects is a container for FaceObjects.
final File archDirectory
The "arch" directory to read.
Interface that captures similarities between different ArchetypeSet implementations.
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.
abstract boolean isValidEntry(int folderLevel, String name)
Returns whether a file name should be processed.
Abstract base class for AbstractResourcesReaders that read from individual files.
Reading and writing of maps, handling of paths.
static final FileFilter ARC_FILE_FILTER
Swing FileFilter for .arc files.
void loadAnimations(@NotNull final AnimationObjects animationObjects, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String path, @NotNull final File animFile, @NotNull final String startKey)
Loads animations from a file.
final FaceObjects faceObjects
The face objects instance.
Utility class defining FileFilters.
Utility-class for Gridarta's I/O.
The face is the appearance of an object.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
void parseDefFace(@NotNull final ErrorView errorView, @NotNull final String path, @NotNull final String filename)
Loads a .face file.
int size()
Returns the number of faces.
static final FileFilter PNG_FILE_FILTER
Swing FileFilter for png graphics.
void parseArchetypeFromStream(@NotNull final BufferedReader in, @Nullable final R prototype, @Nullable final String line, @Nullable final String archName, @NotNull final String panelName, @NotNull final String folderName, @NotNull final String archPath, @NotNull final List< G > invObjects, @NotNull final ErrorViewCollector errorViewCollector)
final AbstractArchetypeParser< G, A, R, ?> archetypeParser
The AbstractArchetypeParser to use.
static final FileFilter FACE_FILE_FILTER
Swing FileFilter for .face files.
static final String MAP_ENCODING
Encoding to use for maps and other data.
final AbstractAnimationObjectsReader animationObjectsReader
The animation objects reader to use.