1 package net.sf.gridarta.action.exportmap;
3 import java.awt.Graphics2D;
5 import java.awt.image.BufferedImage;
6 import java.io.IOException;
7 import java.util.ArrayList;
8 import java.util.Collection;
9 import java.util.Collections;
10 import java.util.HashSet;
11 import java.util.Iterator;
12 import java.util.LinkedHashMap;
13 import java.util.List;
15 import java.util.Map.Entry;
31 import org.jetbrains.annotations.NotNull;
32 import org.jetbrains.annotations.Nullable;
42 private static final int SCALE = 32;
62 private final Map<MapFile, LayoutInfo>
layoutInfo =
new LinkedHashMap<>();
70 private final Map<MapFile, PendingInfo>
pending =
new LinkedHashMap<>();
77 private final Collection<MapFile>
done =
new HashSet<>();
128 progress.setMax(
done.size());
131 final Iterator<Entry<MapFile, PendingInfo>> it =
pending.entrySet().iterator();
135 final Entry<MapFile, PendingInfo> mapFile2 = it.next();
138 add(mapFile2.getKey(), includeTiledMaps, mapFile2.getValue());
139 progress.setMax(
done.size());
140 if (progress.cancel()) {
146 final Graphics2D graphics = image.createGraphics();
148 final List<LayoutInfo> tmp =
new ArrayList<>(
layoutInfo.values());
149 Collections.shuffle(tmp);
155 }
catch (
final IOException ex) {
156 System.err.println(
"cannot load map: " +
layoutInfo.getMapFile() +
": " + ex);
161 final BufferedImage tmp1Image = mapRenderer.
getFullImage();
162 final Image tmp2Image = tmp1Image.getScaledInstance(tmp1Image.getWidth() /
SCALE, tmp1Image.getHeight() /
SCALE, Image.SCALE_AREA_AVERAGING);
169 progress.setValue(
done, image);
170 if (progress.cancel()) {
186 private void add(@NotNull
final MapFile mapFile,
final boolean includeTiledMaps, @NotNull
final PendingInfo pendingInfo) {
190 }
catch (
final IOException ex) {
191 System.err.println(
"cannot load map: " + mapFile +
": " + ex);
197 final int width = imageSize.
getWidth();
198 final int height = imageSize.
getHeight();
200 final int x = pendingInfo.getX(width);
201 final int y = pendingInfo.getY(height);
204 }
else if (x + width >
maxX) {
209 }
else if (y + height >
maxY) {
214 if (includeTiledMaps) {
217 final String tilePath = mapArchObject.getTilePath(direction);
218 if (!tilePath.isEmpty()) {
228 if (
done.add(mapFile2)) {
255 throw new AssertionError(
"unexpected direction: " + direction);