TileImage: refactor: eliminate drawWithTimeTo()

having a context (such as time) may come back in the future,
but for now it seems better to not do this.
This commit is contained in:
Jason Long 2015-01-09 13:32:50 -05:00
parent 9e1f735b3f
commit 7592117306
3 changed files with 16 additions and 26 deletions
src/micropolisj

View file

@ -80,21 +80,15 @@ class Animation extends TileImage
} }
} }
@Override private TileImage getDefaultImage()
public void drawWithTimeTo(Graphics2D gr, int time, int destX, int destY, int srcX, int srcY)
{ {
int t = 0; return frames.get(0).frame;
for (int i = 0; i < frames.size(); i++) { }
Frame f = frames.get(i);
int d = t + f.duration;
if (time < d) {
f.frame.drawTo(gr, destX, destY, srcX, srcY);
return;
}
t = d;
}
// draw nothing @Override
return; public void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY)
{
// Warning: drawing without considering the animation
getDefaultImage().drawTo(gr, destX, destY, srcX, srcY);
} }
} }

View file

@ -112,7 +112,7 @@ public class MakeTiles
} }
@Override @Override
public void drawWithTimeTo(Graphics2D gr, int time, int destX, int destY, int srcX, int srcY) { throw new Error("not implemented"); } public void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY) { throw new UnsupportedOperationException(); }
} }
static class Composer static class Composer

View file

@ -7,11 +7,7 @@ public abstract class TileImage
{ {
public static final int STD_SIZE = 16; public static final int STD_SIZE = 16;
public abstract void drawWithTimeTo(Graphics2D gr, int time, int destX, int destY, int srcX, int srcY); public abstract void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY);
public final void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY)
{
drawWithTimeTo(gr, 0, destX, destY, srcX, srcY);
}
public static class TileImageLayer extends TileImage public static class TileImageLayer extends TileImage
{ {
@ -25,12 +21,12 @@ public abstract class TileImage
} }
@Override @Override
public void drawWithTimeTo(Graphics2D gr, int time, int destX, int destY, int srcX, int srcY) public void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY)
{ {
if (below != null) { if (below != null) {
below.drawWithTimeTo(gr, time, destX, destY, srcX, srcY); below.drawTo(gr, destX, destY, srcX, srcY);
} }
above.drawWithTimeTo(gr, time, destX, destY, srcX, srcY); above.drawTo(gr, destX, destY, srcX, srcY);
} }
} }
@ -46,9 +42,9 @@ public abstract class TileImage
} }
@Override @Override
public void drawWithTimeTo(Graphics2D gr, int time, int destX, int destY, int srcX, int srcY) public void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY)
{ {
source.drawWithTimeTo(gr, time, destX, destY, srcX+offsetX, srcY+offsetY); source.drawTo(gr, destX, destY, srcX+offsetX, srcY+offsetY);
} }
} }
@ -66,7 +62,7 @@ public abstract class TileImage
} }
@Override @Override
public void drawWithTimeTo(Graphics2D gr, int time, int destX, int destY, int srcX, int srcY) public void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY)
{ {
srcX = srcX * basisSize / STD_SIZE; srcX = srcX * basisSize / STD_SIZE;
srcY = srcY * basisSize / STD_SIZE; srcY = srcY * basisSize / STD_SIZE;