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:
parent
9e1f735b3f
commit
7592117306
3 changed files with 16 additions and 26 deletions
|
@ -80,21 +80,15 @@ class Animation extends TileImage
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawWithTimeTo(Graphics2D gr, int time, int destX, int destY, int srcX, int srcY)
|
||||
private TileImage getDefaultImage()
|
||||
{
|
||||
int t = 0;
|
||||
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;
|
||||
}
|
||||
return frames.get(0).frame;
|
||||
}
|
||||
|
||||
// draw nothing
|
||||
return;
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ public class MakeTiles
|
|||
}
|
||||
|
||||
@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
|
||||
|
|
|
@ -7,11 +7,7 @@ public abstract class TileImage
|
|||
{
|
||||
public static final int STD_SIZE = 16;
|
||||
|
||||
public abstract void drawWithTimeTo(Graphics2D gr, int time, 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 abstract void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY);
|
||||
|
||||
public static class TileImageLayer extends TileImage
|
||||
{
|
||||
|
@ -25,12 +21,12 @@ public abstract class TileImage
|
|||
}
|
||||
|
||||
@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) {
|
||||
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
|
||||
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
|
||||
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;
|
||||
srcY = srcY * basisSize / STD_SIZE;
|
||||
|
|
Reference in a new issue