diff --git a/src/micropolisj/build_tool/Animation.java b/src/micropolisj/build_tool/Animation.java
index 86bafef..a53fe28 100644
--- a/src/micropolisj/build_tool/Animation.java
+++ b/src/micropolisj/build_tool/Animation.java
@@ -11,6 +11,7 @@ class Animation extends TileImage
{
static final int DEFAULT_DURATION = 125;
List frames = new ArrayList();
+ int totalDuration;
public static Animation load(File aniFile)
throws IOException
@@ -21,8 +22,10 @@ class Animation extends TileImage
return self;
}
- public void addFrame(Frame f)
+ public void addFrame(TileImage img, int duration)
{
+ totalDuration += duration;
+ Frame f = new Frame(img, totalDuration);
frames.add(f);
}
@@ -48,11 +51,7 @@ class Animation extends TileImage
int duration = tmp != null ? Integer.parseInt(tmp) : DEFAULT_DURATION;
tmp = in.getElementText();
- addFrame(
- new Frame(
- MakeTiles.parseFrameSpec(tmp),
- duration
- ));
+ addFrame( MakeTiles.parseFrameSpec(tmp), duration );
}
else {
// unrecognized element
@@ -98,17 +97,4 @@ class Animation extends TileImage
// draw nothing
return;
}
-
- @Override
- public int getFrameEndTime(int frameTime)
- {
- int t = 0;
- for (int i = 0; i < frames.size(); i++) {
- t += frames.get(i).duration;
- if (frameTime < t) {
- return t;
- }
- }
- return -1;
- }
}
diff --git a/src/micropolisj/build_tool/MakeTiles.java b/src/micropolisj/build_tool/MakeTiles.java
index a6eec56..0a15d77 100644
--- a/src/micropolisj/build_tool/MakeTiles.java
+++ b/src/micropolisj/build_tool/MakeTiles.java
@@ -102,8 +102,6 @@ public class MakeTiles
@Override
public void drawWithTimeTo(Graphics2D gr, int time, int destX, int destY, int srcX, int srcY) { throw new Error("not implemented"); }
- @Override
- public int getFrameEndTime(int frameTime) { throw new Error("not implemented"); }
}
static class Composer
@@ -216,21 +214,15 @@ public class MakeTiles
static TileImage prepareFrames(TileImage ref, Composer c)
{
- if (ref.getFrameEndTime(0) > 0) {
+ if (ref instanceof Animation) {
- Animation ani = new Animation();
- int t = 0;
- int n = ref.getFrameEndTime(t);
- while (n > 0) {
- TileImageSprite s = c.prepareTile(TILE_SIZE);
- Animation.Frame f = new Animation.Frame(s, n-t);
-
- ani.addFrame(f);
-
- t = n;
- n = ref.getFrameEndTime(t);
+ Animation mc = (Animation) ref;
+ Animation dest = new Animation();
+ for (Animation.Frame f : mc.frames) {
+ TileImage s = prepareFrames(f.frame, c);
+ dest.addFrame(s, f.duration);
}
- return ani;
+ return dest;
}
else {
TileImageSprite s = c.prepareTile(TILE_SIZE);
diff --git a/src/micropolisj/graphics/TileImage.java b/src/micropolisj/graphics/TileImage.java
index f011b5f..53850a4 100644
--- a/src/micropolisj/graphics/TileImage.java
+++ b/src/micropolisj/graphics/TileImage.java
@@ -13,13 +13,6 @@ public abstract class TileImage
drawWithTimeTo(gr, 0, destX, destY, srcX, srcY);
}
- /**
- * @return the end-time of the animation frame identified by frameTime;
- * -1 if not an animation, or if frameTime is past the end of the animation
- */
- public abstract int getFrameEndTime(int frameTime);
-
-
public static class TileImageLayer extends TileImage
{
public final TileImageLayer below;
@@ -39,27 +32,6 @@ public abstract class TileImage
}
above.drawWithTimeTo(gr, time, destX, destY, srcX, srcY);
}
-
- @Override
- public int getFrameEndTime(int frameTime)
- {
- if (below == null) {
- return above.getFrameEndTime(frameTime);
- }
-
- int belowEnd = below.getFrameEndTime(frameTime);
- int aboveEnd = above.getFrameEndTime(frameTime);
-
- if (belowEnd < 0) {
- return aboveEnd;
- }
- else if (aboveEnd < 0 || belowEnd < aboveEnd) {
- return belowEnd;
- }
- else {
- return aboveEnd;
- }
- }
}
public static class TileImageSprite extends TileImage
@@ -78,11 +50,6 @@ public abstract class TileImage
{
source.drawWithTimeTo(gr, time, destX, destY, srcX+offsetX, srcY+offsetY);
}
-
- @Override
- public int getFrameEndTime(int frameTime) {
- return source.getFrameEndTime(frameTime);
- }
}
public static class SourceImage extends TileImage
@@ -112,10 +79,5 @@ public abstract class TileImage
srcX+basisSize, srcY+basisSize,
null);
}
-
- @Override
- public int getFrameEndTime(int frameTime) {
- return -1;
- }
}
}