Search in sources :

Example 1 with BaseMap

use of objects.BaseMap 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 BaseMap

use of objects.BaseMap 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 3 with BaseMap

use of objects.BaseMap 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)

Example 4 with BaseMap

use of objects.BaseMap 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");
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) 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) Person(objects.Person)

Example 5 with BaseMap

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

the class GameScreen method preMove.

private boolean preMove(Vector3 currentTile, Direction dir) {
    int nx = (int) currentTile.x;
    int ny = (int) currentTile.y;
    if (context.getParty().getMember(0).getPlayer().status == StatusType.SLEEPING) {
        finishTurn(nx, ny);
        return false;
    }
    if (context.getTransportContext() == TransportContext.BALLOON) {
        log("Drift only!");
        return false;
    }
    if (dir == Direction.NORTH) {
        ny = (int) currentTile.y - 1;
    }
    if (dir == Direction.SOUTH) {
        ny = (int) currentTile.y + 1;
    }
    if (dir == Direction.WEST) {
        nx = (int) currentTile.x - 1;
    }
    if (dir == Direction.EAST) {
        nx = (int) currentTile.x + 1;
    }
    BaseMap bm = context.getCurrentMap();
    if (bm.getBorderbehavior() == MapBorderBehavior.exit) {
        if (nx > bm.getWidth() - 1 || nx < 0 || ny > bm.getHeight() - 1 || ny < 0) {
            // remove any city/town actors (chests) from the map we are leaving
            for (Actor a : mapObjectsStage.getActors()) {
                if (a instanceof Drawable) {
                    Drawable d = (Drawable) a;
                    if (d.getMapId() != Maps.WORLD.getId() && d.getMapId() == bm.getId()) {
                        d.remove();
                    }
                }
            }
            Portal p = Maps.WORLD.getMap().getPortal(bm.getId());
            loadNextMap(Maps.WORLD, p.getX(), p.getY());
            return false;
        }
    }
    int mask = bm.getValidMovesMask(context, (int) currentTile.x, (int) currentTile.y);
    if (!Direction.isDirInMask(dir, mask)) {
        Sounds.play(Sound.BLOCKED);
        finishTurn((int) currentTile.x, (int) currentTile.y);
        return false;
    }
    return true;
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor) Drawable(objects.Drawable) Portal(objects.Portal) BaseMap(objects.BaseMap)

Aggregations

BaseMap (objects.BaseMap)17 MapSet (objects.MapSet)10 TileSet (objects.TileSet)10 File (java.io.File)7 JAXBContext (javax.xml.bind.JAXBContext)7 Unmarshaller (javax.xml.bind.Unmarshaller)7 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 Vector3 (com.badlogic.gdx.math.Vector3)3 InputStream (java.io.InputStream)3 Person (objects.Person)3 Portal (objects.Portal)3 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)2 ArrayList (java.util.ArrayList)2 Creature (objects.Creature)2 Drawable (objects.Drawable)2 Moongate (objects.Moongate)2