Files
SpineViewer/tests/atlas-pma-skin.test.js
T
2026-09-10 19:09:43 +08:00

32 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
const assert = require('node:assert/strict');
const utils = require('../js/spine-utils');
const render = require('../js/spine-render');
assert.equal(utils.parseAtlasPma('page.png\nsize:1,1\npma:true\nregion\n'), true);
assert.equal(utils.parseAtlasPma('page.png\r\n pma : false \r\nregion\r\n'), false);
assert.equal(utils.parseAtlasPma('page.png\nsize:1,1\nregion\n'), undefined);
assert.equal(utils.parseAtlasPma('page.png\npma:trueish\n'), undefined);
const first = { name: 'first' }, namedDefault = { name: 'default' }, explicit = { name: 'custom' };
assert.equal(utils.preferredSkin({ defaultSkin: explicit, skins: [first, namedDefault] }), explicit);
assert.equal(utils.preferredSkin({ skins: [first, namedDefault] }), namedDefault);
assert.equal(utils.preferredSkin({ skins: [first] }), first);
assert.equal(utils.preferredSkin({ skins: [] }), null);
for (const version of ['3.4', '3.5', '3.6', '3.7', '3.8', '4.0', '4.1', '4.2', '4.3']) {
const spine = render.loadRuntime(version);
const skin = new spine.Skin('visible');
const data = new spine.SkeletonData();
data.bones.push(new spine.BoneData(0, 'root', null));
data.slots.push(new spine.SlotData(0, 'slot', data.bones[0]));
data.skins.push(skin);
if ('defaultSkin' in data) data.defaultSkin = skin;
const skeleton = new spine.Skeleton(data);
assert.equal(utils.preferredSkin(data), skin, version + ' preferred skin');
assert(utils.applySkin(skeleton, skin), version + ' apply skin');
assert.equal(skeleton.skin, skin, version + ' active skin');
}
console.log('PASS: Atlas PMA detection and default/first skin selection across Spine 3.4–4.3');