public Tile(Map map, int x, int y, Element tile) { this.map = map; this.x = x; this.y = y; height = (int) Float.parseFloat(tile.getAttribute("height")); if (!tile.getAttribute("caveHeight").equals("")) { caveHeight = (int) Float.parseFloat(tile.getAttribute("caveHeight")); } if (!tile.getAttribute("caveSize").equals("")) { caveSize = (int) Float.parseFloat(tile.getAttribute("caveSize")); } ground = new Ground((Element) tile.getElementsByTagName("ground").item(0)); if (tile.getElementsByTagName("cave").getLength() != 0) { cave = CaveData.get((Element) tile.getElementsByTagName("cave").item(0)); } NodeList labels = tile.getElementsByTagName("label"); if (labels.getLength() != 0) { label = new Label((Element) labels.item(0)); } NodeList caveLabels = tile.getElementsByTagName("caveLabel"); if (caveLabels.getLength() != 0) { caveLabel = new Label((Element) caveLabels.item(0)); } entities = new HashMap<>(); NodeList list = tile.getElementsByTagName("level"); for (int i = 0; i < list.getLength(); i++) { Element level = (Element) list.item(i); int floor = Integer.parseInt(level.getAttribute("value")); NodeList childNodes = level.getElementsByTagName("*"); for (int i2 = 0; i2 < childNodes.getLength(); i2++) { Element entity = (Element) childNodes.item(i2); switch (entity.getNodeName().toLowerCase()) { case "floor": entities.put(new EntityData(floor, EntityType.FLOORROOF), new Floor(entity)); break; case "hwall": Wall hwall = new Wall(entity); if (hwall.data.houseWall) { entities.put(new EntityData(floor, EntityType.HWALL), hwall); } else { entities.put(new EntityData(floor, EntityType.HFENCE), hwall); } break; case "vwall": Wall vwall = new Wall(entity); if (vwall.data.houseWall) { entities.put(new EntityData(floor, EntityType.VWALL), vwall); } else { entities.put(new EntityData(floor, EntityType.VFENCE), vwall); } break; case "hborder": entities.put(new EntityData(0, EntityType.HBORDER), BorderData.get(entity)); break; case "vborder": entities.put(new EntityData(0, EntityType.VBORDER), BorderData.get(entity)); break; case "roof": entities.put(new EntityData(floor, EntityType.FLOORROOF), new Roof(entity)); break; case "object": ObjectLocation loc = ObjectLocation.parse(entity.getAttribute("position")); entities.put(new ObjectEntityData(floor, loc), new GameObject(entity)); break; case "cave": cave = CaveData.get(entity); break; } } } }
public void serialize(Document doc, Element root) { Element tile = doc.createElement("tile"); tile.setAttribute("x", Integer.toString(x)); tile.setAttribute("y", Integer.toString(y)); tile.setAttribute("height", Float.toString(height)); tile.setAttribute("caveHeight", Float.toString(caveHeight)); tile.setAttribute("caveSize", Float.toString(caveSize)); root.appendChild(tile); ground.serialize(doc, tile); cave.serialize(doc, tile); if (label != null) { label.serialize(doc, tile, false); } if (caveLabel != null) { caveLabel.serialize(doc, tile, true); } final HashMap<Integer, Element> levels = new HashMap<>(); for (Entry<EntityData, TileEntity> e : entities.entrySet()) { final EntityData key = e.getKey(); final TileEntity entity = e.getValue(); final int floor = key.getFloor(); Element level = levels.get(floor); if (level == null) { level = doc.createElement("level"); level.setAttribute("value", Integer.toString(key.getFloor())); levels.put(key.getFloor(), level); tile.appendChild(level); } switch (key.getType()) { case FLOORROOF: entity.serialize(doc, level); break; case HWALL: case HFENCE: Element hWall = doc.createElement("hWall"); entity.serialize(doc, hWall); level.appendChild(hWall); break; case VWALL: case VFENCE: Element vWall = doc.createElement("vWall"); entity.serialize(doc, vWall); level.appendChild(vWall); break; case HBORDER: Element hDeco = doc.createElement("hBorder"); entity.serialize(doc, hDeco); level.appendChild(hDeco); break; case VBORDER: Element vDeco = doc.createElement("vBorder"); entity.serialize(doc, vDeco); level.appendChild(vDeco); break; case OBJECT: ObjectEntityData objectData = (ObjectEntityData) key; Element objectElement = doc.createElement("object"); objectElement.setAttribute("position", objectData.getLocation().toString()); entity.serialize(doc, objectElement); level.appendChild(objectElement); break; } } }
private void renderUnderground(GL2 g) { cave.render(g, this); }