20 package net.sf.gridarta.model.resource;
22 import java.io.BufferedReader;
24 import java.io.FileNotFoundException;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.io.InputStreamReader;
28 import java.io.Reader;
30 import java.util.HashMap;
31 import java.util.List;
46 import net.
sf.japi.swing.action.ActionBuilder;
47 import net.
sf.japi.swing.action.ActionBuilderFactory;
48 import org.apache.log4j.Category;
49 import org.apache.log4j.Logger;
50 import org.jetbrains.annotations.NotNull;
51 import org.jetbrains.annotations.Nullable;
66 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
119 final int animationObjectsSize = animationObjects.
size();
125 try (InputStream inputStream = animationsURL.openStream()) {
127 try (Reader bufferedReader =
new BufferedReader(reader)) {
132 }
catch (
final IOException ex) {
138 if (LOG.isInfoEnabled()) {
139 LOG.info(
"Loaded " + (animationObjects.
size() - animationObjectsSize) +
" animations from '" + animationsURL +
"'.");
141 }
catch (
final FileNotFoundException ex) {
155 protected void addPNGFace(@NotNull
final String filename, @NotNull
final String path, @NotNull
final String name, @NotNull
final ErrorView errorView, @NotNull
final ArchFaceProvider archFaceProvider) {
157 archFaceProvider.addInfo(facename, filename);
159 faceObjects.
addFaceObject(facename, path +
"/" + facename, 0, (
int)
new File(filename).length());
175 if (imageSet != null) {
180 for (
int t = 0; t < name.length() && secondDot == 0; t++) {
181 if (name.charAt(t) ==
'.') {
190 if (firstDot != 0 && secondDot != 0) {
191 return name.substring(0, firstDot) + name.substring(secondDot, name.length() - 4);
193 return name.substring(0, name.length() - 4);
198 return name.substring(0, name.length() - 4);
219 protected static Map<String, String>
loadAnimTree(@NotNull
final URL url)
throws IOException {
220 final Map<String, String> animations;
221 try (InputStream inputStream = url.openStream()) {
223 try (BufferedReader bufferedReader =
new BufferedReader(reader)) {
228 if (LOG.isInfoEnabled()) {
229 LOG.info(
"Loaded " + animations.size() +
" animations from '" + url +
"'.");
241 private static Map<String, String>
loadAnimTree(@NotNull
final BufferedReader reader)
throws IOException {
242 final Map<String, String> animations =
new HashMap<>();
244 final String line = reader.readLine();
248 final int index = line.lastIndexOf(
'/');
249 final String name = line.substring(index + 1);
250 animations.put(name, line);
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.
static final String MAP_ENCODING
Encoding to use for maps and other data.
int size()
Get the number of objects.
FaceObject getExisting()
Returns the other duplicate that caused this exception.
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.
void loadAnimationsFromCollect(@NotNull final ErrorView errorView, @NotNull final Map< String, String > animations)
Loads all animations from the big collected animations file.
final File collectedDirectory
The collected directory.
Defines possible error categories for ErrorView instances.
final AnimationObjects animationObjects
The animation objects instance.
String getOriginalFilename()
Get the original filename of this face.
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.
String generateFaceName(@NotNull final String name)
Generates the facename for a face.
Base package of all Gridarta classes.
void addFaceObject(String faceName, String originalFilename, int offset, int size)
Adds a new face object.
Reflects a game object (object on a map).
FaceObject getFaceObject()
Returns the illegal face object.
Exception that's thrown in case a face name was not unique.
Utility-class for Gridarta's I/O.
final FaceObjects faceObjects
The face objects instance.
Exception thrown to indicate that a face object is not acceptable.
AnimationObjects is a container for AnimationObjects.
GameObjects are the objects based on Archetypes found on maps.
static URL getResource(@Nullable final File dir, @NotNull final String fileName)
Get the URL of a resource.
final String imageSet
The current 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.
FaceObjects is a container for FaceObjects.
static Map< String, String > loadAnimTree(@NotNull final URL url)
Loads animations from a file.
static final Category LOG
The logger for printing log messages.
The face is the appearance of an object.
int getLineNumber()
Get the number of the erroneous line.
AbstractResourcesReader(@NotNull final File collectedDirectory, @Nullable final String imageSet, @NotNull final AnimationObjects animationObjects, @NotNull final FaceObjects faceObjects)
Creates a new instance.
String getFaceName()
Get the faceName, which is the name of the face as usable by the "face" attribute.
FaceObject getDuplicate()
Returns the duplicate that caused this exception.
Implementation of FaceProvider which reads images from the arch directory.
Abstract base class for archetype set loader classes.
abstract FaceProvider read(@NotNull ErrorView errorView, @NotNull List< G > invObjects)
Reads the resources.
static final ActionBuilder ACTION_BUILDER
Action Builder.
static Map< String, String > loadAnimTree(@NotNull final BufferedReader reader)
Reads Animation Tree from Stream.