@ -1,96 +0,0 @@
|
||||
// Converts the atlas description to a JSON file
|
||||
|
||||
String.prototype.replaceAll = function (search, replacement) {
|
||||
var target = this;
|
||||
return target.split(search).join(replacement);
|
||||
};
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const folder = path.join(__dirname, "res_built", "atlas");
|
||||
const files = fs.readdirSync(folder);
|
||||
|
||||
const metadata = [];
|
||||
|
||||
files.forEach(filename => {
|
||||
if (filename.endsWith(".atlas")) {
|
||||
// Read content
|
||||
|
||||
const content = fs.readFileSync(path.join(folder, filename), "ascii");
|
||||
|
||||
const lines = content.replaceAll("\r", "").replaceAll("\t", "").split("\n");
|
||||
|
||||
const readLine = () => lines.splice(0, 1)[0];
|
||||
const readValue = () => readLine().replaceAll(" ", "").split(":")[1];
|
||||
const readVector = () =>
|
||||
readValue()
|
||||
.split(",")
|
||||
.map(d => parseInt(d, 10));
|
||||
|
||||
let maxAtlas = 100;
|
||||
|
||||
atlasLoop: while (maxAtlas-- > 0 && lines.length >= 7) {
|
||||
const result = {
|
||||
entries: [],
|
||||
};
|
||||
|
||||
// Extract header
|
||||
const header_fileStart = readLine();
|
||||
const header_fileName = readLine();
|
||||
const header_size = readVector();
|
||||
const header_format = readLine();
|
||||
const header_filter = readLine();
|
||||
const header_repeat = readLine();
|
||||
const baseAtlasName = header_fileName.replace(".png", "");
|
||||
|
||||
// Store size
|
||||
result.size = header_size;
|
||||
|
||||
lineLoop: while (lines.length >= 7) {
|
||||
const entryResult = {};
|
||||
|
||||
const nextLine = lines[0];
|
||||
if (nextLine.length === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
const entry_fileName = readLine() + ".png";
|
||||
|
||||
const entry_rotate = readValue();
|
||||
const entry_xy = readVector();
|
||||
const entry_size = readVector();
|
||||
const entry_orig = readVector();
|
||||
const entry_offset = readVector();
|
||||
const entry_index = readValue();
|
||||
|
||||
entryResult.filename = entry_fileName;
|
||||
entryResult.xy = entry_xy;
|
||||
entryResult.size = entry_size;
|
||||
// entryResult.offset = entry_offset;
|
||||
|
||||
entryResult.origSize = entry_orig;
|
||||
|
||||
let offset = [0, 0];
|
||||
|
||||
// GDX Atlas packer uses 1 - y coordinates. This sucks, and we have to convert it
|
||||
offset[0] = entry_offset[0];
|
||||
offset[1] = entry_orig[1] - entry_offset[1] - entry_size[1];
|
||||
|
||||
entryResult.offset = offset;
|
||||
|
||||
result.entries.push(entryResult);
|
||||
}
|
||||
|
||||
console.log("[Atlas]", "'" + baseAtlasName + "'", "has", result.entries.length, "entries");
|
||||
// fs.writeFileSync(path.join(folder, baseAtlasName + ".gen.json"), JSON.stringify(result));
|
||||
|
||||
metadata.push({
|
||||
filename: baseAtlasName + ".png",
|
||||
entries: result,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fs.writeFileSync(path.join(folder, "meta.gen.json"), JSON.stringify(metadata, null, 4));
|
After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 165 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.3 MiB |
Before Width: | Height: | Size: 286 KiB After Width: | Height: | Size: 278 KiB |
Before Width: | Height: | Size: 705 KiB After Width: | Height: | Size: 700 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 705 B After Width: | Height: | Size: 706 B |
Before Width: | Height: | Size: 651 B After Width: | Height: | Size: 651 B |
Before Width: | Height: | Size: 525 B After Width: | Height: | Size: 527 B |
Before Width: | Height: | Size: 516 B After Width: | Height: | Size: 515 B |
Before Width: | Height: | Size: 706 B |
Before Width: | Height: | Size: 651 B |
Before Width: | Height: | Size: 527 B |
Before Width: | Height: | Size: 515 B |