use of objects.TileSet in project ultimate-java by pantinor.
the class VendorTest method printVendors.
// @Test
public void printVendors() throws Exception {
File file2 = new File("target/classes/xml/tileset-base.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(TileSet.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
TileSet ts = (TileSet) jaxbUnmarshaller.unmarshal(file2);
ts.setMaps();
File file3 = new File("target/classes/xml/maps.xml");
jaxbContext = JAXBContext.newInstance(MapSet.class);
jaxbUnmarshaller = jaxbContext.createUnmarshaller();
MapSet ms = (MapSet) jaxbUnmarshaller.unmarshal(file3);
ms.init(ts);
ArrayList<Holder> tm = new ArrayList<>();
for (BaseMap map : ms.getMaps()) {
if (map.getCity() == null) {
continue;
}
for (Person p : map.getCity().getPeople()) {
if (p != null && p.getRole() != null && p.getRole().getInventoryType() != null) {
tm.add(new Holder(p.getRole().getInventoryType(), p, Maps.get(map.getId())));
System.out.println("type=\"" + p.getRole().getInventoryType() + "\" personId=\"" + p.getId() + "\" " + Maps.get(map.getId()));
}
}
}
Collections.sort(tm, new MyComparator());
for (Holder h : tm) {
// System.out.println("type=\"" +h.t+ "\" personId=\"" + h.p.getId() + "\" " + h.map);
}
}
use of objects.TileSet in project ultimate-java by pantinor.
the class WorldMapTmxConvert method create.
@Override
public void create() {
try {
File file2 = new File("assets/xml/tileset-base.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(TileSet.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
TileSet ts = (TileSet) jaxbUnmarshaller.unmarshal(file2);
ts.setMaps();
File file3 = new File("assets/xml/maps.xml");
jaxbContext = JAXBContext.newInstance(MapSet.class);
jaxbUnmarshaller = jaxbContext.createUnmarshaller();
MapSet ms = (MapSet) jaxbUnmarshaller.unmarshal(file3);
ms.init(ts);
BaseMap map = Maps.WORLD.getMap();
Utils.setMapTiles(map, ts);
Tile[] tiles = map.getTiles();
// load the atlas and determine the tile indexes per tilemap position
FileHandle f = new FileHandle("assets/tilemaps/latest-atlas.txt");
TextureAtlasData atlas = new TextureAtlasData(f, f.parent(), false);
int png_grid_width = 24;
Tile[] mapTileIds = new Tile[png_grid_width * Constants.tilePixelWidth + 1];
for (Region r : atlas.getRegions()) {
int x = r.left / r.width;
int y = r.top / r.height;
int i = x + (y * png_grid_width) + 1;
mapTileIds[i] = ts.getTileByName(r.name);
}
// map layer
StringBuilder data = new StringBuilder();
int count = 1;
int total = 1;
for (int i = 0; i < tiles.length; i++) {
Tile t = tiles[i];
data.append(findTileId(mapTileIds, t.getName())).append(",");
count++;
total++;
if (count > 256) {
data.append("\n");
count = 1;
}
}
String dl = data.toString();
dl = dl.substring(0, dl.length() - 2);
// portal layer
List<Portal> portals = map.getPortals();
StringBuilder portalBuffer = new StringBuilder();
// set map tile id per dest map type
for (Portal p : portals) {
BaseMap destMap = Maps.get(p.getDestmapid()).getMap();
p.setName(Constants.Maps.get(p.getDestmapid()).toString());
String ttype = destMap.getCity() == null ? destMap.getType().toString() : destMap.getCity().getType();
p.setMapTileId(findTileId(mapTileIds, ttype));
}
if (portals != null) {
for (int y = 0; y < map.getHeight(); y++) {
for (int x = 0; x < map.getWidth(); x++) {
Portal p = findPortalAtCoords(portals, x, y);
if (p == null) {
portalBuffer.append("0,");
} else {
portalBuffer.append(p.getMapTileId() + ",");
}
}
portalBuffer.append("\n");
}
}
String pl = portalBuffer.toString();
pl = pl.substring(0, pl.length() - 2);
// moongate layer
List<Moongate> moongates = map.getMoongates();
StringBuilder moongateBuffer = new StringBuilder();
// set map tile id per dest map type
for (Moongate m : moongates) {
m.setMapTileId(findTileId(mapTileIds, "moongate"));
}
if (moongates != null) {
for (int y = 0; y < map.getHeight(); y++) {
for (int x = 0; x < map.getWidth(); x++) {
Moongate p = findMoongateAtCoords(moongates, x, y);
if (p == null) {
moongateBuffer.append("0,");
} else {
moongateBuffer.append(p.getMapTileId()).append(",");
}
}
moongateBuffer.append("\n");
}
}
String ml = moongateBuffer.toString();
ml = ml.substring(0, ml.length() - 2);
Formatter c = new Formatter(map.getFname(), "latest.png", map.getWidth(), map.getHeight(), Constants.tilePixelWidth, Constants.tilePixelWidth, dl, pl, ml, portals, moongates, map.getLabels());
FileUtils.writeStringToFile(new File("tmx/map_" + map.getId() + "_World.tmx"), c.toString());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("DONE");
}
Aggregations