From 9e1f735b3fb17e022be09e669bebaab19b2cb608 Mon Sep 17 00:00:00 2001 From: Jason Long Date: Thu, 8 Jan 2015 08:44:08 -0500 Subject: [PATCH] MakeTiles: refactor tile drawing code into drawFrames() method --- src/micropolisj/build_tool/MakeTiles.java | 33 ++++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/micropolisj/build_tool/MakeTiles.java b/src/micropolisj/build_tool/MakeTiles.java index be2bcb4..3b10ec1 100644 --- a/src/micropolisj/build_tool/MakeTiles.java +++ b/src/micropolisj/build_tool/MakeTiles.java @@ -193,22 +193,7 @@ public class MakeTiles for (TileMapping m : mappings) { - assert (m.dest instanceof Animation) || (m.dest instanceof TileImageSprite); - - if (m.dest instanceof Animation) { - Animation ani = (Animation) m.dest; - int t = 0; - for (int i = 0; i < ani.frames.size(); i++) { - Animation.Frame f = ani.frames.get(i); - TileImageSprite s = (TileImageSprite) f.frame; - m.ref.drawWithTimeTo(c.getGr(s), t, s.offsetX, s.offsetY, 0, 0); - t += f.duration; - } - } - else { - TileImageSprite sprite = (TileImageSprite) m.dest; - m.ref.drawTo(c.getGr(sprite), sprite.offsetX, sprite.offsetY, 0, 0); - } + drawFrames(m.dest, c); } // make parent directories if necessary @@ -242,6 +227,22 @@ public class MakeTiles } } + static void drawFrames(TileImage dest, Composer c) + { + if (dest instanceof Animation) { + Animation ani = (Animation) dest; + for (Animation.Frame f : ani.frames) { + drawFrames(f.frame, c); + } + } + else { + assert dest instanceof ComposeFrame; + + ComposeFrame f = (ComposeFrame) dest; + f.refImage.drawTo(c.getGr(f), f.offsetX, f.offsetY, 0, 0); + } + } + static void writeIndexFile(Collection mappings, File indexFile) throws IOException {