48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const os = require('node:os');
|
|
const path = require('node:path');
|
|
const utils = require('../js/spine-utils');
|
|
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'spineviewer-mixed-atlas-'));
|
|
try {
|
|
const images = path.join(root, 'images');
|
|
fs.mkdirSync(images);
|
|
fs.writeFileSync(path.join(root, 'metadata.json'), JSON.stringify({ folders: [] }));
|
|
const makeItem = (id, name, body) => {
|
|
const directory = path.join(images, id + '.info');
|
|
fs.mkdirSync(directory);
|
|
fs.writeFileSync(path.join(directory, name), body);
|
|
fs.writeFileSync(path.join(directory, 'metadata.json'), JSON.stringify({ folders: [] }));
|
|
return path.join(directory, name);
|
|
};
|
|
const png = makeItem('png', 'hero.png', 'png');
|
|
const atlas = makeItem('atlas', 'hero.atlas', [
|
|
'hero.png',
|
|
'size: 64,64',
|
|
'format: RGBA8888',
|
|
'filter: Linear,Linear',
|
|
'repeat: none',
|
|
'',
|
|
'hero.jpeg',
|
|
'size: 32,32',
|
|
'format: RGBA8888',
|
|
'filter: Linear,Linear',
|
|
'repeat: none',
|
|
'',
|
|
].join('\n'));
|
|
const jpeg = makeItem('jpg', 'hero.jpg', 'jpg');
|
|
const assets = utils.discoverAssets(atlas, {
|
|
strictStem: true,
|
|
searchRoots: [path.dirname(png), path.dirname(atlas), path.dirname(jpeg)],
|
|
});
|
|
assert.equal(assets.texturePaths['hero.png'], png);
|
|
assert.equal(assets.texturePaths['hero.jpeg'], jpeg, 'JPEG atlas page must prefer .jpg over same-stem .png');
|
|
assert.equal(utils.textureFormatOf('photo.JPEG'), utils.textureFormatOf('photo.jpg'));
|
|
console.log('PASS: SpineViewer resolves mixed PNG/JPEG atlas pages by texture format');
|
|
} finally {
|
|
fs.rmSync(root, { recursive: true, force: true });
|
|
}
|