final Array<Page> pages = new Array<Page>();
final Array<Region> regions = new Array<Region>();
public TextureAtlasData (FileHandle packFile, FileHandle imagesDir, boolean flip) {
PriorityQueue<Region> sortedRegions = new PriorityQueue(16, indexComparator);
BufferedReader reader = new BufferedReader(new InputStreamReader(packFile.read()), 64);
try {
Page pageImage = null;
while (true) {
String line = reader.readLine();
if (line == null) break;
if (line.trim().length() == 0)
pageImage = null;
else if (pageImage == null) {
FileHandle file = imagesDir.child(line);
Format format = Format.valueOf(readValue(reader));
readTuple(reader);
TextureFilter min = TextureFilter.valueOf(tuple[0]);
TextureFilter max = TextureFilter.valueOf(tuple[1]);
String direction = readValue(reader);
TextureWrap repeatX = ClampToEdge;
TextureWrap repeatY = ClampToEdge;
if (direction.equals("x"))
repeatX = Repeat;
else if (direction.equals("y"))
repeatY = Repeat;
else if (direction.equals("xy")) {
repeatX = Repeat;
repeatY = Repeat;
}
pageImage = new Page(file, min.isMipMap(), format, min, max, repeatX, repeatY);
pages.add(pageImage);
} else {
boolean rotate = Boolean.valueOf(readValue(reader));
readTuple(reader);
int left = Integer.parseInt(tuple[0]);
int top = Integer.parseInt(tuple[1]);
readTuple(reader);
int width = Integer.parseInt(tuple[0]);
int height = Integer.parseInt(tuple[1]);
Region region = new Region();
region.page = pageImage;
region.left = left;
region.top = top;
region.width = width;
region.height = height;
region.name = line;
region.rotate = rotate;
readTuple(reader);
region.originalWidth = Integer.parseInt(tuple[0]);
region.originalHeight = Integer.parseInt(tuple[1]);
readTuple(reader);
region.offsetX = Integer.parseInt(tuple[0]);
region.offsetY = Integer.parseInt(tuple[1]);
region.index = Integer.parseInt(readValue(reader));
if (flip) region.flip = true;
sortedRegions.add(region);
}
}
} catch (IOException ex) {
throw new GdxRuntimeException("Error reading pack file: " + packFile);
} finally {
try {
reader.close();
} catch (IOException ignored) {
}
}
int n = sortedRegions.size();
for (int i = 0; i < n; i++)
regions.add(sortedRegions.poll());
}