int width = parent.getAttributeValueAsInt("tile-width");
int height = parent.getAttributeValueAsInt("tile-height");
tileSize = new Dimension(width, height);
// import terrain tiles
Node element = parent.getFirstChild("Terrain-Tiles");
String base = element.getAttributeValue("base");
for (Node child : element.getChildren()) {
child.checkNode("Tile");
Integer id = child.getAttributeValueAsInt("id");
Tile tile = new Tile();
Image inner = IOManager.getAsImage(Places.GraphicsScenario, base + "/" + child.getAttributeValue("inner"));
Image outer = inner;
if (child.hasAttribute("outer")) {
outer = IOManager.getAsImage(Places.GraphicsScenario, base + "/" + child.getAttributeValue("outer"));
}
tile.content = new EnhancedTile(inner, outer);
tile.color = GraphicsUtils.convertHexToColor(child.getAttributeValue("color"));
terrainTiles.put(id, tile);
}
for (Tile tile : terrainTiles.values()) {
Dimension size = tile.content.getSize();
if (!tileSize.equals(size)) {
RuntimeException ex = new RuntimeException("Terrain tiles differ in size");
LOG.log(Level.SEVERE, null, ex);
throw ex;
}
}
{
// import river overlay
element = parent.getFirstChild("River-Overlays");
String location = element.getAttributeValue("location");
BufferedImage rivers = IOManager.getAsImage(Places.GraphicsScenario, location);
// test if width and height is a multiple of tileSize
if (rivers.getWidth(null) % tileSize.width != 0 || rivers.getHeight(null) % tileSize.height != 0) {
// LOG
}
int columns = rivers.getWidth(null) / tileSize.width;
int rows = rivers.getHeight(null) / tileSize.height;
// image too small
if (rows * columns < 36) {
}
// lets copy out the parts and store them
riverOverlays = new Image[36];
for (int i = 0; i < 36; i++) {
int x = i % 8 * tileSize.width;
int y = i / 8 * tileSize.height;
riverOverlays[i] = rivers.getSubimage(x, y, tileSize.width, tileSize.height);
}
}
// import resource overlays
element = parent.getFirstChild("Resource-Overlays");
base = element.getAttributeValue("base");
for (Node child : element.getChildren()) {
child.checkNode("Overlay");
Integer id = child.getAttributeValueAsInt("id");
// TODO what if images cannot be loaded because they aren't there, image == null, check
Image inner = IOManager.getAsImage(Places.GraphicsScenario, base + "/" + child.getAttributeValue("inner"));
Image outer = inner;
if (child.hasAttribute("outer")) {
outer = IOManager.getAsImage(Places.GraphicsScenario, base + "/" + child.getAttributeValue("outer"));
}
resourceOverlays.put(id, new EnhancedTile(inner, outer));
}
// import misc overlays
element = parent.getFirstChild("Miscellaneous-Overlays");
for (Node child : element.getChildren()) {
child.checkNode("Overlay");
String id = child.getAttributeValue("id");
String location = child.getAttributeValue("location");
Image image = IOManager.getAsImage(Places.GraphicsScenario, location);
miscOverlays.put(id, image);
}
// import unit overlays
element = parent.getFirstChild("Unit-Overlays");
base = element.getAttributeValue("base");
for (Node child : element.getChildren()) {
child.checkNode("Unit");
String type = child.getAttributeValue("type");
String action = child.getAttributeValue("action");
String location = child.getAttributeValue("location");