Search in sources :

Example 1 with TileSet

use of objects.TileSet in project ultimate-java by pantinor.

the class TestJaxb method parseTlkFiles.

// @Test
public void parseTlkFiles() throws Exception {
    TileSet baseTileSet = (TileSet) Utils.loadXml("tileset-base.xml", TileSet.class);
    baseTileSet.setMaps();
    MapSet maps = (MapSet) Utils.loadXml("maps.xml", MapSet.class);
    for (BaseMap map : maps.getMaps()) {
        if (map.getCity() == null || map.getCity().getTlk_fname() == null) {
            continue;
        }
        List<Person> people;
        try {
            people = Utils.getPeople(map.getFname(), Maps.get(map.getId()), null);
        } catch (Exception e) {
            continue;
        }
        List<Conversation> cons = Utils.getDialogs(map.getCity().getTlk_fname());
        if (people == null) {
            continue;
        }
        for (Person p : people) {
            if (p != null) {
                for (Conversation c : cons) {
                    if (c.getIndex() == p.getDialogId()) {
                        p.setConversation(c);
                    }
                }
            }
        }
        for (Person p : people) {
        // System.out.println(p);
        }
        for (Conversation c : cons) {
            System.out.println(c.toXMLString(Maps.get(map.getId())));
        }
        for (Conversation c : cons) {
            Person per = null;
            for (Person p : people) {
                if (c.getIndex() == p.getDialogId()) {
                    per = p;
                }
            }
            if (per == null) {
            // System.out.println("Extra Dialog: " + c);
            }
        }
    }
// System.out.printf("Latitude [%s' %s]", (char) ((int) 54 / 16 + 'A'), (char) ((int) 54 % 16 + 'A'));
// System.out.printf(" Longitude [%s' %s]\n", (char) ((int) 182 / 16 + 'A'), (char) ((int) 182 % 16 + 'A'));
}
Also used : MapSet(objects.MapSet) Conversation(objects.Conversation) TileSet(objects.TileSet) Person(objects.Person) BaseMap(objects.BaseMap)

Example 2 with TileSet

use of objects.TileSet in project ultimate-java by pantinor.

the class TestJaxb method testTileSetDungeon.

// @Test
public void testTileSetDungeon() throws Exception {
    File file = new File("target/classes/xml/tileset-dungeon.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(TileSet.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    TileSet ts = (TileSet) jaxbUnmarshaller.unmarshal(file);
    for (Tile t : ts.getTiles()) {
        System.out.println(t);
    }
}
Also used : DungeonTile(ultima.Constants.DungeonTile) Tile(objects.Tile) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) TileSet(objects.TileSet)

Example 3 with TileSet

use of objects.TileSet in project ultimate-java by pantinor.

the class TestJaxb method testTileSetBase.

// @Test
public void testTileSetBase() throws Exception {
    File file = new File("target/classes/xml/tileset-base.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(TileSet.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    TileSet ts = (TileSet) jaxbUnmarshaller.unmarshal(file);
    for (Tile t : ts.getTiles()) {
        System.out.println(t);
    }
}
Also used : DungeonTile(ultima.Constants.DungeonTile) Tile(objects.Tile) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) TileSet(objects.TileSet)

Example 4 with TileSet

use of objects.TileSet in project ultimate-java by pantinor.

the class CombatMapTmxConvert method main.

public static void main(String[] args) 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);
    int TILE_SIZE = 16;
    boolean foundShrine = false;
    for (BaseMap map : ms.getMaps()) {
        String tmxmapname = null;
        boolean isShrine = false;
        if (map.getType() == MapType.combat || (map.getType() == MapType.shrine && !foundShrine)) {
            if (map.getType() == MapType.shrine && !foundShrine) {
                foundShrine = true;
                tmxmapname = "shrine.tmx";
                isShrine = true;
            } else if (map.getType() == MapType.combat) {
                tmxmapname = "combat_" + map.getId() + ".tmx";
            }
        } else {
            continue;
        }
        InputStream is = TestMain.class.getResourceAsStream("/data/" + map.getFname());
        byte[] bytes = IOUtils.toByteArray(is);
        Tile[] tiles = new Tile[map.getWidth() * map.getHeight()];
        int pos = isShrine ? 0 : 64;
        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;
            }
        }
        // load the atlas and determine the tile indexes per tilemap position
        FileHandle f = new FileHandle("target/classes/tilemaps/tile-atlas.txt");
        TextureAtlasData atlas = new TextureAtlasData(f, f.parent(), false);
        Tile[] mapTileIds = new Tile[atlas.getRegions().size + 1];
        for (Region r : atlas.getRegions()) {
            int x = r.left / r.width;
            int y = r.top / r.height;
            int i = y * TILE_SIZE + x + 1;
            mapTileIds[i] = ts.getTileByName(r.name);
        }
        // map layer
        StringBuffer data = new StringBuffer();
        int count = 1;
        int total = 1;
        for (int i = 0; i < tiles.length; i++) {
            Tile t = tiles[i];
            data.append(findTileId(mapTileIds, t.getName()) + ",");
            count++;
            total++;
            if (count > map.getWidth()) {
                data.append("\n");
                count = 1;
            }
            if (total > map.getWidth() * map.getHeight()) {
                break;
            }
        }
        String d = data.toString();
        d = d.substring(0, d.length() - 2);
        Position[] monPos = new Position[16];
        for (int i = 0; i < 16; i++) {
            monPos[i] = new Position(i, (int) bytes[i], 0);
        }
        for (int i = 0; i < 16; i++) {
            monPos[i].startY = (int) bytes[i + 16];
        }
        Position[] playerPos = new Position[8];
        for (int i = 0; i < 8; i++) {
            playerPos[i] = new Position(i, (int) bytes[i + 32], 0);
        }
        for (int i = 0; i < 8; i++) {
            playerPos[i].startY = (int) bytes[i + 40];
        }
        CombatMapTmxConvert c = new CombatMapTmxConvert(map.getFname(), "tiles.png", map.getWidth(), map.getHeight(), TILE_SIZE, TILE_SIZE, TILE_SIZE ^ 2, TILE_SIZE ^ 2, d, monPos, playerPos);
        FileUtils.writeStringToFile(new File("src/main/resources/tilemaps/" + tmxmapname), c.toString());
    }
}
Also used : InputStream(java.io.InputStream) FileHandle(com.badlogic.gdx.files.FileHandle) Tile(objects.Tile) JAXBContext(javax.xml.bind.JAXBContext) TileSet(objects.TileSet) BaseMap(objects.BaseMap) TextureAtlasData(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData) MapSet(objects.MapSet) Region(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Example 5 with TileSet

use of objects.TileSet in project ultimate-java by pantinor.

the class DungeonMapTmxConvert method main.

public static void main(String[] args) 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);
    int TILE_SIZE = 16;
    for (BaseMap map : ms.getMaps()) {
        String tmxmapname = null;
        boolean isAbyss = false;
        if (map.getType() == MapType.dungeon) {
            if (map.getFname().equals("abyss.dng")) {
                tmxmapname = "abyss.tmx";
                isAbyss = true;
            } else {
                tmxmapname = "dungeon_" + map.getId() + ".tmx";
            }
        } else {
            continue;
        }
        InputStream is = new FileInputStream("assets/data/" + map.getFname());
        byte[] bytes = IOUtils.toByteArray(is);
        List<DungeonTile[]> dungeonTiles = new ArrayList<>();
        int pos = 0;
        for (int i = 0; i < 8; i++) {
            DungeonTile[] tiles = new DungeonTile[64];
            for (int y = 0; y < map.getHeight(); ++y) {
                for (int x = 0; x < map.getWidth(); ++x) {
                    int index = bytes[pos] & 0xff;
                    pos++;
                    DungeonTile tile = DungeonTile.getTileByValue(index);
                    tiles[x + y * map.getWidth()] = tile;
                }
            }
            dungeonTiles.add(tiles);
        }
        // load the atlas and determine the tile indexes per tilemap position
        FileHandle f = new FileHandle("assets/tilemaps/tiles-vga-atlas.txt");
        TextureAtlasData atlas = new TextureAtlasData(f, f.parent(), false);
        Tile[] mapTileIds = new Tile[atlas.getRegions().size + 1];
        for (Region r : atlas.getRegions()) {
            int x = r.left / r.width;
            int y = r.top / r.height;
            int i = y * TILE_SIZE + x + 1;
            mapTileIds[i] = ts.getTileByName(r.name);
        }
        // map layers
        List<String> layers = new ArrayList<>();
        for (int j = 0; j < 8; j++) {
            DungeonTile[] tiles = dungeonTiles.get(j);
            StringBuilder data = new StringBuilder();
            int count = 1;
            int total = 1;
            for (int i = 0; i < tiles.length; i++) {
                DungeonTile t = tiles[i];
                data.append(findTileId(mapTileIds, t.getTileName()) + ",");
                count++;
                total++;
                if (count > map.getWidth()) {
                    data.append("\n");
                    count = 1;
                }
                if (total > map.getWidth() * map.getHeight()) {
                    break;
                }
            }
            String d = data.toString();
            d = d.substring(0, d.length() - 2);
            layers.add(d);
        }
        System.out.println("writing");
        DungeonMapTmxConvert c = new DungeonMapTmxConvert(map.getFname(), "tiles-vga.png", map.getWidth(), map.getHeight(), TILE_SIZE, TILE_SIZE, TILE_SIZE ^ 2, TILE_SIZE ^ 2, layers);
        FileUtils.writeStringToFile(new File(tmxmapname), c.toString());
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileHandle(com.badlogic.gdx.files.FileHandle) ArrayList(java.util.ArrayList) Tile(objects.Tile) JAXBContext(javax.xml.bind.JAXBContext) TileSet(objects.TileSet) BaseMap(objects.BaseMap) FileInputStream(java.io.FileInputStream) TextureAtlasData(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData) MapSet(objects.MapSet) Region(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Aggregations

TileSet (objects.TileSet)12 BaseMap (objects.BaseMap)10 MapSet (objects.MapSet)10 File (java.io.File)9 JAXBContext (javax.xml.bind.JAXBContext)9 Unmarshaller (javax.xml.bind.Unmarshaller)9 Tile (objects.Tile)7 FileHandle (com.badlogic.gdx.files.FileHandle)5 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)5 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)3 Person (objects.Person)3 DungeonTile (ultima.Constants.DungeonTile)3 ArrayList (java.util.ArrayList)2 LittleEndianDataInputStream (com.google.common.io.LittleEndianDataInputStream)1 Conversation (objects.Conversation)1 Moongate (objects.Moongate)1 Portal (objects.Portal)1 SpreadFOV (util.SpreadFOV)1