use of objects.PersonRole in project ultimate-java by pantinor.
the class Utils method setTMXMap.
public static void setTMXMap(BaseMap map, Maps id, String tmxFile, TileSet ts) {
List<Person> people = new ArrayList<>();
Tile[] tiles = new Tile[map.getWidth() * map.getHeight()];
TmxMapLoader loader = new TmxMapLoader();
TiledMap tm = loader.load("assets/tilemaps/" + tmxFile);
TiledMapTileLayer ml = (TiledMapTileLayer) tm.getLayers().get(map.getId() + "-map");
if (ml != null) {
FileHandle f = new FileHandle("assets/tilemaps/latest-atlas.txt");
TextureAtlas.TextureAtlasData atlas = new TextureAtlas.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 (int y = 0; y < map.getHeight(); y++) {
for (int x = 0; x < map.getWidth(); x++) {
StaticTiledMapTile tr = (StaticTiledMapTile) ml.getCell(x, map.getWidth() - 1 - y).getTile();
Tile tile = mapTileIds[tr.getId()];
if (tile == null) {
tile = ts.getTileByIndex(127);
}
tiles[x + (y * map.getWidth())] = tile;
}
}
}
MapLayer objectsLayer = tm.getLayers().get(map.getId() + "-people");
if (objectsLayer != null) {
Iterator<MapObject> iter = objectsLayer.getObjects().iterator();
while (iter.hasNext()) {
MapObject obj = iter.next();
Person p = new Person();
Conversation conv = new Conversation();
conv.setName(obj.getName());
conv.setMap(id);
p.setConversation(conv);
people.add(p);
Iterator<String> keys = obj.getProperties().getKeys();
while (keys.hasNext()) {
String key = keys.next();
String value = obj.getProperties().get(key).toString();
if (key.equals("tileType")) {
Tile tile = ts.getTileByName(value);
p.setTileIndex(tile.getIndex());
p.setTile(tile);
} else if (key.equals("startX")) {
p.setStart_x(new Float(value).intValue());
} else if (key.equals("startY")) {
p.setStart_y(new Float(value).intValue());
} else if (key.equals("role")) {
PersonRole role = new PersonRole();
role.setInventoryType(InventoryType.valueOf(value));
p.setRole(role);
} else if (key.equals("movement")) {
p.setMovement(ObjectMovementBehavior.valueOf(value));
} else if (key.startsWith("description")) {
conv.setDescription(value);
conv.getTopics().add(conv.new Topic(standardQuery[2], value, null, null, null));
} else if (key.startsWith("topic")) {
String[] splits = value.split(",");
if (splits.length == 5) {
conv.getTopics().add(conv.new Topic(splits[0], splits[1], splits[2], splits[3], splits[4]));
} else {
conv.getTopics().add(conv.new Topic(splits[0], splits[1], null, null, null));
}
}
}
}
}
map.getCity().setPeople(people);
map.setTiles(tiles);
}
Aggregations