20 package net.sf.gridarta.model.anim;
22 import java.util.ArrayList;
23 import java.util.List;
26 import org.apache.log4j.Category;
27 import org.apache.log4j.Logger;
28 import org.jetbrains.annotations.NotNull;
52 private final List<String>
frames =
new ArrayList<>();
99 if (line.startsWith(
"facings ")) {
100 tmpFacings = Integer.parseInt(line.substring(8));
104 if (tmpFacings < 1) {
105 LOG.warn(
"Ignoring invalid facings value: " + tmpFacings);
108 facings = tmpFacings;
109 boolean first =
true;
111 if (first && line.startsWith(
"facings ")) {
117 if (frames.size() <= 0) {
118 LOG.warn(
"Animation " + animName +
" has no frames");
119 for (
int i = 0; i <
facings; i++) {
120 frames.add(
"bug.111");
122 }
else if (frames.size() % facings != 0) {
123 LOG.warn(
"Animation " + animName +
" has " + frames.size() +
" frames but " + facings +
" facings");
124 while (frames.size() % facings != 0) {
125 frames.add(frames.get(frames.size() - 1));
128 frameCount = frames.size() /
facings;
166 final StringBuilder sb =
new StringBuilder();
172 return sb.toString();
178 for (
int facing = 1; facing <
facings; facing++) {
180 if (!frame.startsWith(
"dummy.")) {
201 public String
getFrame(
final int facing,
final int frame)
throws IndexOutOfBoundsException {
202 if (facing < 0 || facing >= facings) {
203 throw new IndexOutOfBoundsException(
"Invalid facing " + facing +
" (anim only has " + facings +
" facings)");
205 if (frame < 0 || frame >= frameCount) {
206 throw new IndexOutOfBoundsException(
"Invalid frame " + frame +
" (anim only has " + frameCount +
" frames)");
208 return frames.get(facing * frameCount + frame);
String path
The path of this object.
Utility class for string manipulation.
The data package contains classes for handling data that is organized in a tree.
final List< String > frames
The names of the animation frames.
String toString()
The String representation of an AnimationObject is suitable for writing into the animations file...
static final Pattern PATTERN_NEWLINE
The pattern that matches a single newline ("\n").
String getAnimList()
Returns the animation list of this animation.
int getFrameCount()
Get the number of frames per facing.
Base package of all Gridarta classes.
int getFacings()
Get the facings, which is the number of different sub-animations, for instance for different directio...
String getFirstFrame(final int facing)
Get the first frame.
static final long serialVersionUID
The serial version UID.
final String animName
The name of this animation.
String getFrame(final int facing, final int frame)
Get a specific frame.
An AnimationObject reflects the animation ("@code anim\n @endcode " ...
Abstract base implementation of AnimationObject.
final int facings
The number of facings, which is different sub animations, for instance for different directions...
DefaultAnimationObject(@NotNull final String animName, @NotNull final String animList, @NotNull final String path)
Creates a new instance.
final int frameCount
The number of frames per facing in the animation.
static final Category LOG
The Logger for printing log messages.
String getDisplayIconName()
Returns the face name of the display icon for this AbstractNamedObject.
final String animList
The animation list of this animation.