Split up overlay and underlay drawing and move to functions

This commit is contained in:
Adam
2016-09-16 10:38:11 -04:00
parent 66f5054a62
commit 24dfe07450

View File

@@ -123,6 +123,66 @@ public class MapImageDumper
BufferedImage image = new BufferedImage(dimX, dimY, BufferedImage.TYPE_INT_RGB); BufferedImage image = new BufferedImage(dimX, dimY, BufferedImage.TYPE_INT_RGB);
drawUnderlay(image, z);
drawOverlay(image, z);
// objects
for (Region region : regions)
{
int baseX = region.getBaseX();
int baseY = region.getBaseY();
// to pixel X
int drawBaseX = baseX - lowestX.getBaseX();
// to pixel Y. top most y is 0, but the top most
// region has the greaters y, so invert
int drawBaseY = highestY.getBaseY() - baseY;
Graphics2D graphics = image.createGraphics();
drawObjects(graphics, region, z, drawBaseX, drawBaseY);
graphics.dispose();
}
// map icons
for (Region region : regions)
{
int baseX = region.getBaseX();
int baseY = region.getBaseY();
// to pixel X
int drawBaseX = baseX - lowestX.getBaseX();
// to pixel Y. top most y is 0, but the top most
// region has the greaters y, so invert
int drawBaseY = highestY.getBaseY() - baseY;
Graphics2D graphics = image.createGraphics();
drawMapIcons(graphics, region, z, drawBaseX, drawBaseY);
if (labelRegions)
{
graphics.setColor(Color.WHITE);
graphics.drawString(baseX + "," + baseY, drawBaseX * MAP_SCALE, drawBaseY * MAP_SCALE + graphics.getFontMetrics().getHeight());
}
if (outlineRegions)
{
graphics.setColor(Color.WHITE);
graphics.drawRect(drawBaseX * MAP_SCALE, drawBaseY * MAP_SCALE, Region.X * MAP_SCALE, Region.Y * MAP_SCALE);
}
graphics.dispose();
}
return image;
}
private void drawUnderlay(BufferedImage image, int z)
{
// pass 1 // pass 1
for (Region region : regions) for (Region region : regions)
{ {
@@ -156,7 +216,49 @@ public class MapImageDumper
UnderlayDefinition underlay = findUnderlay(underlayId); UnderlayDefinition underlay = findUnderlay(underlayId);
rgb = underlay.getColor(); rgb = underlay.getColor();
} }
else }
else if (underlayId > -1)
{
UnderlayDefinition underlay = findUnderlay(underlayId);
rgb = underlay.getColor();
}
drawMapSquare(image, drawX, drawY, rgb);
}
}
}
}
private void drawOverlay(BufferedImage image, int z)
{
for (Region region : regions)
{
int baseX = region.getBaseX();
int baseY = region.getBaseY();
// to pixel X
int drawBaseX = baseX - lowestX.getBaseX();
// to pixel Y. top most y is 0, but the top most
// region has the greaters y, so invert
int drawBaseY = highestY.getBaseY() - baseY;
for (int x = 0; x < Region.X; ++x)
{
int drawX = drawBaseX + x;
for (int y = 0; y < Region.Y; ++y)
{
int drawY = drawBaseY + (Region.Y - 1 - y);
int overlayId = region.getOverlayId(z, x, y) - 1;
if (overlayId > -1)
{
OverlayDefinition overlay = findOverlay(overlayId);
int rgb = 0;
if (overlay.isHideUnderlay())
{ {
rgb = overlay.getRgbColor(); rgb = overlay.getRgbColor();
} }
@@ -176,71 +278,12 @@ public class MapImageDumper
rgb = averageColors.get(sprite); rgb = averageColors.get(sprite);
} }
}
else if (underlayId > -1)
{
UnderlayDefinition underlay = findUnderlay(underlayId);
rgb = underlay.getColor();
}
drawMapSquare(image, drawX, drawY, rgb); drawMapSquare(image, drawX, drawY, rgb);
}
} }
} }
} }
// pass 2
for (Region region : regions)
{
int baseX = region.getBaseX();
int baseY = region.getBaseY();
// to pixel X
int drawBaseX = baseX - lowestX.getBaseX();
// to pixel Y. top most y is 0, but the top most
// region has the greaters y, so invert
int drawBaseY = highestY.getBaseY() - baseY;
Graphics2D graphics = image.createGraphics();
drawObjects(graphics, region, z, drawBaseX, drawBaseY);
graphics.dispose();
}
// pass 3
for (Region region : regions)
{
int baseX = region.getBaseX();
int baseY = region.getBaseY();
// to pixel X
int drawBaseX = baseX - lowestX.getBaseX();
// to pixel Y. top most y is 0, but the top most
// region has the greaters y, so invert
int drawBaseY = highestY.getBaseY() - baseY;
Graphics2D graphics = image.createGraphics();
drawMapIcons(graphics, region, z, drawBaseX, drawBaseY);
if (labelRegions)
{
graphics.setColor(Color.WHITE);
graphics.drawString(baseX + "," + baseY, drawBaseX * MAP_SCALE, drawBaseY * MAP_SCALE + graphics.getFontMetrics().getHeight());
}
if (outlineRegions)
{
graphics.setColor(Color.WHITE);
graphics.drawRect(drawBaseX * MAP_SCALE, drawBaseY * MAP_SCALE, Region.X * MAP_SCALE, Region.Y * MAP_SCALE);
}
graphics.dispose();
}
return image;
} }
private void drawMapSquare(BufferedImage image, int x, int y, int rgb) private void drawMapSquare(BufferedImage image, int x, int y, int rgb)