use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData in project bladecoder-adventure-engine by bladecoder.
the class ImageUtils method scaleAtlas.
public static void scaleAtlas(File orgAtlas, File destDir, float scale) throws IOException {
File tmpDir = DesktopUtils.createTempDirectory();
EditorLogger.debug("SCALING: " + orgAtlas.getName());
unpackAtlas(orgAtlas, tmpDir);
String atlasParentPath = orgAtlas.getParentFile().getAbsolutePath();
TextureAtlasData atlasData = new TextureAtlasData(new FileHandle(orgAtlas), new FileHandle(atlasParentPath), false);
String outputFormat = atlasData.getPages().get(0).textureFile.extension();
createAtlas(tmpDir.getAbsolutePath(), destDir.getAbsolutePath(), orgAtlas.getName(), scale, atlasData.getPages().get(0).minFilter, atlasData.getPages().get(0).magFilter, outputFormat);
DesktopUtils.removeDir(tmpDir.getAbsolutePath());
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData in project ultimate-java by pantinor.
the class GeneratedMapTmxConvert method main.
public static void main(String[] args) throws Exception {
int TILE_SIZE = 16;
FileHandle f = new FileHandle("assets/tilemaps/tiles-vga-atlas.txt");
TextureAtlasData atlas = new TextureAtlasData(f, f.parent(), false);
String[] mapTileIds = new String[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] = r.name;
}
List<StaticGeneratedDungeon> dungeons = new ArrayList<StaticGeneratedDungeon>();
dungeons.add(new StaticGeneratedDungeon("The Dark Pit of Emes the Fallen 01 (tsv).txt"));
dungeons.add(new StaticGeneratedDungeon("The Dark Pit of Emes the Fallen 10 (tsv).txt"));
dungeons.add(new StaticGeneratedDungeon("The Dark Pit of Emes the Fallen 20 (tsv).txt"));
List<String> layers = new ArrayList<String>();
for (StaticGeneratedDungeon sd : dungeons) {
StringBuffer data = new StringBuffer();
for (int y = 0; y < StaticGeneratedDungeon.DIM; y++) {
for (int x = 0; x < StaticGeneratedDungeon.DIM; x++) {
Key val = sd.getCell(x, y);
if (val == null) {
val = StaticGeneratedDungeon.Key.NULL;
}
data.append(findTileId(mapTileIds, val.getName()) + ",");
}
data.append("\n");
}
String dl = data.toString();
dl = dl.substring(0, dl.length() - 2);
layers.add(dl);
}
GeneratedMapTmxConvert c = new GeneratedMapTmxConvert("delve", "tiles-vga.png", StaticGeneratedDungeon.DIM, StaticGeneratedDungeon.DIM, TILE_SIZE, TILE_SIZE, layers.get(0), layers.get(1), layers.get(2), "", "", "");
FileUtils.writeStringToFile(new File("assets/tilemaps/generatedDungeon.tmx"), c.toString());
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData 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");
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData 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");
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData in project ultimate-java by pantinor.
the class StaticGeneratedDungeonScreen method init.
public void init() {
assets = new AssetManager();
assets.load("assets/graphics/dirt.png", Texture.class);
assets.load("assets/graphics/map.png", Texture.class);
assets.load("assets/graphics/Stone_Masonry.jpg", Texture.class);
assets.load("assets/graphics/door.png", Texture.class);
assets.load("assets/graphics/mortar.png", Texture.class);
assets.load("assets/graphics/rock.png", Texture.class);
assets.update(2000);
assets.get("assets/graphics/rock.png", Texture.class).setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
assets.get("assets/graphics/door.png", Texture.class).setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
assets.get("assets/graphics/mortar.png", Texture.class).setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
assets.get("assets/graphics/dirt.png", Texture.class).setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
ModelLoader<?> gloader = new G3dModelLoader(new UBJsonReader());
fountainModel = gloader.loadModel(Gdx.files.internal("assets/graphics/fountain2.g3db"));
ladderModel = gloader.loadModel(Gdx.files.internal("assets/graphics/ladder.g3db"));
chestModel = gloader.loadModel(Gdx.files.internal("assets/graphics/chest.g3db"));
orbModel = gloader.loadModel(Gdx.files.internal("assets/graphics/orb.g3db"));
altarModel = gloader.loadModel(Gdx.files.internal("assets/graphics/altar.g3db"));
rocksModel = gloader.loadModel(Gdx.files.internal("assets/graphics/rocks.g3db"));
campfireModel = gloader.loadModel(Gdx.files.internal("assets/graphics/campfire.g3db"));
font = new BitmapFont();
font.setColor(Color.WHITE);
fixedLight = new PointLight().set(1f, 0.8f, 0.6f, 4f, 4f, 4f, 5f);
modelBatch = new ModelBatch();
batch = new SpriteBatch();
camera = new PerspectiveCamera(67, Ultima4.MAP_WIDTH, Ultima4.MAP_HEIGHT);
camera.near = 0.1f;
camera.far = 1000f;
decalBatch = new DecalBatch(new CameraGroupStrategy(camera));
// inputController = new CameraInputController(camera);
// inputController.rotateLeftKey = inputController.rotateRightKey = inputController.forwardKey = inputController.backwardKey = 0;
// inputController.translateUnits = 30f;
ModelBuilder builder = new ModelBuilder();
Model fm = builder.createBox(1, 1, 1, new Material(TextureAttribute.createDiffuse(assets.get("assets/graphics/rock.png", Texture.class))), Usage.Position | Usage.TextureCoordinates | Usage.Normal);
Model cm = builder.createBox(1, 1, 1, new Material(TextureAttribute.createDiffuse(assets.get("assets/graphics/dirt.png", Texture.class))), Usage.Position | Usage.TextureCoordinates | Usage.Normal);
try {
int TILE_SIZE = 16;
FileHandle f = new FileHandle("assets/tilemaps/tiles-vga-atlas.txt");
TextureAtlasData a = new TextureAtlasData(f, f.parent(), false);
mapTileIds = new String[a.getRegions().size + 1];
for (Region r : a.getRegions()) {
int x = r.left / r.width;
int y = r.top / r.height;
int i = y * TILE_SIZE + x + 1;
mapTileIds[i] = r.name;
}
TiledMap map = new TmxMapLoader().load("assets/tilemaps/delveOfSorrows.tmx");
Iterator<MapLayer> iter = map.getLayers().iterator();
int level = 0;
while (iter.hasNext()) {
environment[level] = new Environment();
environment[level].set(new ColorAttribute(ColorAttribute.Ambient, 0.5f, 0.5f, 0.5f, 1f));
environment[level].add(fixedLight);
layers[level] = (TiledMapTileLayer) iter.next();
for (int y = 0; y < DUNGEON_MAP; y++) {
for (int x = 0; x < DUNGEON_MAP; x++) {
String val = mapTileIds[layers[level].getCell(x, DUNGEON_MAP - y - 1).getTile().getId()];
DungeonTile tile = DungeonTile.getTileByName(val);
if (tile == null) {
CreatureType ct = CreatureType.get(val);
if (ct != null) {
Creature creature = Ultima4.creatures.getInstance(ct, Ultima4.standardAtlas);
creature.currentX = x;
creature.currentY = y;
creature.currentLevel = level;
creature.getDecal().setPosition(creature.currentX + .5f, .3f, creature.currentY + .5f);
dngMap.getMap().addCreature(creature);
} else {
System.err.println(val);
}
dungeonTiles[level][x][y] = DungeonTile.NOTHING;
} else if (tile == DungeonTile.WATER) {
Model w = builder.createBox(1, 1, 1, getMaterial(Color.BLUE, .9f), Usage.Position | Usage.Normal);
ModelInstance wi = new ModelInstance(w, x + .5f, -.5f, y + .5f);
DungeonTileModelInstance fin = new DungeonTileModelInstance(wi, DungeonTile.WATER, level);
modelInstances.add(fin);
dungeonTiles[level][x][y] = DungeonTile.NOTHING;
} else {
dungeonTiles[level][x][y] = tile;
addBlock(level, tile, x + .5f, .5f, y + .5f);
}
if (tile == null || tile != DungeonTile.WATER) {
DungeonTileModelInstance fin = new DungeonTileModelInstance(new ModelInstance(fm, new Vector3(x + .5f, -.5f, y + .5f)), DungeonTile.FLOOR, level);
modelInstances.add(fin);
}
DungeonTileModelInstance cin = new DungeonTileModelInstance(new ModelInstance(cm, new Vector3(x + .5f, 1.5f, y + .5f)), DungeonTile.FLOOR, level);
modelInstances.add(cin);
}
}
level++;
}
setStartPosition();
camera.position.set(currentPos);
camera.lookAt(currentPos.x + 1, currentPos.y, currentPos.z);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations