use of objects.TileSet in project ultimate-java by pantinor.
the class UltMapTmxConvert 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);
// 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);
}
for (BaseMap map : ms.getMaps()) {
if (!map.getFname().endsWith("ult")) {
continue;
}
FileInputStream is = new FileInputStream("assets/data/" + map.getFname());
byte[] bytes = IOUtils.toByteArray(is);
Tile[] tiles = new Tile[map.getWidth() * map.getHeight()];
int pos = 0;
for (int y = 0; y < map.getHeight(); y++) {
for (int x = 0; x < map.getWidth(); x++) {
// convert a byte to an unsigned int value
int index = bytes[pos] & 0xff;
pos++;
Tile tile = ts.getTileByIndex(index);
if (tile == null) {
System.out.println("Tile index cannot be found: " + index + " using index 129 for black space.");
tile = ts.getTileByIndex(129);
}
tiles[x + y * map.getWidth()] = tile;
}
}
// 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(findTileMapId(mapTileIds, t.getName())).append(",");
count++;
total++;
if (count > 32) {
data.append("\n");
count = 1;
}
}
String d = data.toString();
d = d.substring(0, d.length() - 2);
List<Person> people = map.getCity().getPeople();
StringBuilder peopleBuffer = new StringBuilder();
if (people != null) {
for (int y = 0; y < map.getHeight(); y++) {
for (int x = 0; x < map.getWidth(); x++) {
Person p = findPersonAtCoords(people, x, y);
if (p == null) {
peopleBuffer.append("0,");
} else {
peopleBuffer.append(findTileMapId(mapTileIds, p.getTile().getName())).append(",");
}
}
peopleBuffer.append("\n");
}
}
String p = peopleBuffer.toString();
if (p == null || p.length() < 1) {
count = 1;
// make empty
for (int i = 0; i < map.getWidth() * map.getHeight(); i++) {
peopleBuffer.append("0,");
count++;
if (count > map.getWidth()) {
peopleBuffer.append("\n");
count = 1;
}
}
p = peopleBuffer.toString();
}
p = p.substring(0, p.length() - 2);
Formatter c = new Formatter(map.getFname(), "latest.png", map.getWidth(), map.getHeight(), Constants.tilePixelWidth, Constants.tilePixelWidth, d, p, people);
String tmxFName = String.format("tmx/map_%s_%s.tmx", map.getId(), map.getCity().getName().replace(" ", ""));
FileUtils.writeStringToFile(new File(tmxFName), c.toString());
System.out.printf("Wrote: %s\n", tmxFName);
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("DONE");
}
use of objects.TileSet in project ultimate-java by pantinor.
the class TestJaxb method testMaps.
// @Test
public void testMaps() throws Exception {
TileSet baseTileSet = (TileSet) Utils.loadXml("tileset-base.xml", TileSet.class);
baseTileSet.setMaps();
MapSet maps = (MapSet) Utils.loadXml("maps.xml", MapSet.class);
maps.init(baseTileSet);
for (BaseMap map : maps.getMaps()) {
if (map.getCity() == null || map.getCity().getTlk_fname() == null) {
continue;
}
String fname = "D:\\xu4\\ULTIMA4\\" + map.getCity().getTlk_fname();
System.out.println("D:\\xu4\\tools\\tlkconv.exe --toxml " + fname + " " + "D:\\work\\ultima-java\\target\\" + map.getCity().getTlk_fname() + ".xml");
}
}
use of objects.TileSet in project ultimate-java by pantinor.
the class TestJaxb method testMapShadows.
// @Test
public void testMapShadows() throws Exception {
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 m = Maps.BRITAIN.getMap();
int startx = 2;
int starty = 4;
long t = System.currentTimeMillis();
SpreadFOV fov = new SpreadFOV(32, 32, true);
float[][] lightMap = fov.calculateFOV(m.getShadownMap(), startx, starty, 20);
for (int y = 0; y < 32; y++) {
for (int x = 0; x < 32; x++) {
if (startx == x && starty == y) {
System.out.print("_");
} else {
// System.out.print(lightMap[x][y] <= 0?"X":" ");
System.out.print(lightMap[x][y]);
}
}
System.out.println("");
}
System.out.println("testLOS2 time: " + (System.currentTimeMillis() - t));
}
use of objects.TileSet in project ultimate-java by pantinor.
the class TestJaxb method findStartsForDungeons.
// @Test
public void findStartsForDungeons() throws Exception {
TileSet baseTileSet = (TileSet) Utils.loadXml("tileset-base.xml", TileSet.class);
baseTileSet.setMaps();
MapSet maps = (MapSet) Utils.loadXml("maps.xml", MapSet.class);
maps.init(baseTileSet);
for (BaseMap map : maps.getMaps()) {
if (map.getType() != MapType.dungeon) {
continue;
}
InputStream is = new FileInputStream("assets/data/" + map.getFname());
byte[] bytes = IOUtils.toByteArray(is);
int pos = 0;
int i = 0;
for (int y = 0; y < DUNGEON_MAP; y++) {
for (int x = 0; x < DUNGEON_MAP; x++) {
int index = bytes[pos] & 0xff;
pos++;
DungeonTile tile = DungeonTile.getTileByValue(index);
if (tile == DungeonTile.LADDER_UP || tile == DungeonTile.LADDER_UP_DOWN) {
System.out.println(map.getFname() + " x=" + x + " y=" + y);
}
}
}
}
}
use of objects.TileSet in project ultimate-java by pantinor.
the class AndiusMapTmxConvert 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);
// 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);
}
BaseMap world = Constants.Maps.WORLD.getMap();
Utils.setMapTiles(world, ts);
Tile[] tiles = world.getTiles();
String tmxFName = "tmx/andius/world.tmx";
WorldFormatter c = new WorldFormatter(world.getWidth(), world.getHeight(), tiles, world.getPortals(), world.getMoongates());
FileUtils.writeStringToFile(new File(tmxFName), c.toString());
System.out.printf("Wrote: %s\n", tmxFName);
for (BaseMap map : ms.getMaps()) {
if (!map.getFname().endsWith("ult")) {
continue;
}
FileInputStream is = new FileInputStream("assets/data/" + map.getFname());
byte[] bytes = IOUtils.toByteArray(is);
tiles = new Tile[map.getWidth() * map.getHeight()];
int pos = 0;
for (int y = 0; y < map.getHeight(); y++) {
for (int x = 0; x < map.getWidth(); x++) {
// convert a byte to an unsigned int value
int index = bytes[pos] & 0xff;
pos++;
Tile tile = ts.getTileByIndex(index);
if (tile == null) {
System.out.println("Tile index cannot be found: " + index + " using index 129 for black space.");
tile = ts.getTileByIndex(129);
}
tiles[x + y * map.getWidth()] = tile;
}
}
tmxFName = String.format("tmx/andius/%s.tmx", map.getCity().getName().replace(" ", "").toLowerCase());
if (map.getFname().equals("lcb_2.ult")) {
tmxFName = "tmx/andius/britannia2.tmx";
}
Formatter fmtter = new Formatter(map.getWidth(), map.getHeight(), tiles);
FileUtils.writeStringToFile(new File(tmxFName), fmtter.toString());
System.out.printf("Wrote: %s\n", tmxFName);
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("DONE");
}
Aggregations