mirror of
https://github.com/scratchfoundation/scratch-analysis.git
synced 2024-11-21 10:48:15 -05:00
Merge pull request #69 from rfronczyk/DPR-430-add-backdrops
Some checks failed
build-scratch-analysis / setup (push) Has been cancelled
Some checks failed
build-scratch-analysis / setup (push) Has been cancelled
DPR-430: Add backdrops to the output
This commit is contained in:
commit
e43d2a4bfb
4 changed files with 93 additions and 0 deletions
24
lib/sb2.js
24
lib/sb2.js
|
@ -67,6 +67,28 @@ const extract = function (project, attribute, id, hash) {
|
|||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Extract summary information about backdrops including
|
||||
* count, list of backdrop names and list of backdrop hashes.
|
||||
* Backdrops are a subset of all costumes.
|
||||
* Backdrops are a costumes from the stage object.
|
||||
* @param {object} project Project object (SB2 format)
|
||||
* @return {object} Summary information
|
||||
*/
|
||||
const backdrops = function (project) {
|
||||
let stageCostumes = project.costumes;
|
||||
|
||||
if (!Array.isArray(stageCostumes)) {
|
||||
return {count: 0, id: [], hash: []};
|
||||
}
|
||||
|
||||
return {
|
||||
count: stageCostumes.length,
|
||||
id: stageCostumes.map((sc) => sc.costumeName),
|
||||
hash: stageCostumes.map((sc) => sc.baseLayerMD5)
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Extract number of sprites from a project object. Will attempt to ignore
|
||||
* "children" which are not sprites.
|
||||
|
@ -227,6 +249,8 @@ module.exports = function (project, callback) {
|
|||
costumes: extract(project, 'costumes', 'costumeName', 'baseLayerMD5')
|
||||
};
|
||||
|
||||
meta.backdrops = backdrops(project);
|
||||
|
||||
meta.cloud = cloud(project, meta.variables.id);
|
||||
|
||||
// Sprites
|
||||
|
|
|
@ -170,6 +170,10 @@ const metadata = function (meta) {
|
|||
return obj;
|
||||
};
|
||||
|
||||
const stageTargets = function (targets) {
|
||||
return targets.filter((target) => target.isStage);
|
||||
};
|
||||
|
||||
module.exports = function (project, callback) {
|
||||
const meta = {
|
||||
scripts: scripts(project.targets),
|
||||
|
@ -179,6 +183,8 @@ module.exports = function (project, callback) {
|
|||
comments: extract(project.targets, 'comments'),
|
||||
sounds: extract(project.targets, 'sounds', 'name', 'md5ext'),
|
||||
costumes: costumes(project.targets),
|
||||
// backdrops are costumes on the stage target
|
||||
backdrops: costumes(stageTargets(project.targets)),
|
||||
sprites: sprites(project.targets),
|
||||
blocks: blocks(project.targets),
|
||||
extensions: extensions(project.extensions),
|
||||
|
|
|
@ -56,6 +56,15 @@ test('default (object)', t => {
|
|||
'3696356a03a8d938318876a593572843.svg'
|
||||
]);
|
||||
|
||||
t.type(result.backdrops, 'object');
|
||||
t.equal(result.backdrops.count, 1);
|
||||
t.same(result.backdrops.id, [
|
||||
'backdrop1'
|
||||
]);
|
||||
t.same(result.backdrops.hash, [
|
||||
'739b5e2a2435f6e1ec2993791b423146.png'
|
||||
]);
|
||||
|
||||
t.type(result.sprites, 'object');
|
||||
t.equal(result.sprites.count, 1);
|
||||
|
||||
|
@ -119,6 +128,15 @@ test('default (binary)', t => {
|
|||
'6e8bd9ae68fdb02b7e1e3df656a75635.svg'
|
||||
]);
|
||||
|
||||
t.type(result.backdrops, 'object');
|
||||
t.equal(result.backdrops.count, 1);
|
||||
t.same(result.backdrops.id, [
|
||||
'backdrop1'
|
||||
]);
|
||||
t.same(result.backdrops.hash, [
|
||||
'739b5e2a2435f6e1ec2993791b423146.png'
|
||||
]);
|
||||
|
||||
t.type(result.sprites, 'object');
|
||||
t.equal(result.sprites.count, 1);
|
||||
|
||||
|
@ -185,6 +203,15 @@ test('complex (binary)', t => {
|
|||
'6e8bd9ae68fdb02b7e1e3df656a75635.svg'
|
||||
]);
|
||||
|
||||
t.type(result.backdrops, 'object');
|
||||
t.equal(result.backdrops.count, 1);
|
||||
t.same(result.backdrops.id, [
|
||||
'backdrop1'
|
||||
]);
|
||||
t.same(result.backdrops.hash, [
|
||||
'5b465b3b07d39019109d8dc6d6ee6593.svg'
|
||||
]);
|
||||
|
||||
t.type(result.sprites, 'object');
|
||||
t.equal(result.sprites.count, 1);
|
||||
|
||||
|
|
|
@ -72,6 +72,15 @@ test('default (object)', t => {
|
|||
'd27716e022fb5f747d7b09fe6eeeca06.svg'
|
||||
]);
|
||||
|
||||
t.type(result.backdrops, 'object');
|
||||
t.equal(result.backdrops.count, 1);
|
||||
t.same(result.backdrops.id, [
|
||||
'backdrop1'
|
||||
]);
|
||||
t.same(result.backdrops.hash, [
|
||||
'cd21514d0531fdffb22204e0ec5ed84a.svg'
|
||||
]);
|
||||
|
||||
t.type(result.sprites, 'object');
|
||||
t.equal(result.sprites.count, 1);
|
||||
|
||||
|
@ -138,6 +147,15 @@ test('default (binary)', t => {
|
|||
'd27716e022fb5f747d7b09fe6eeeca06.svg'
|
||||
]);
|
||||
|
||||
t.type(result.backdrops, 'object');
|
||||
t.equal(result.backdrops.count, 1);
|
||||
t.same(result.backdrops.id, [
|
||||
'backdrop1'
|
||||
]);
|
||||
t.same(result.backdrops.hash, [
|
||||
'cd21514d0531fdffb22204e0ec5ed84a.svg'
|
||||
]);
|
||||
|
||||
t.type(result.sprites, 'object');
|
||||
t.equal(result.sprites.count, 1);
|
||||
|
||||
|
@ -207,6 +225,15 @@ test('complex (binary)', t => {
|
|||
'64208764c777be25d34d813dc0b743c7.svg'
|
||||
]);
|
||||
|
||||
t.type(result.backdrops, 'object');
|
||||
t.equal(result.backdrops.count, 1);
|
||||
t.same(result.backdrops.id, [
|
||||
'backdrop1'
|
||||
]);
|
||||
t.same(result.backdrops.hash, [
|
||||
'7633d36de03d1df75808f581bbccc742.svg'
|
||||
]);
|
||||
|
||||
t.type(result.sprites, 'object');
|
||||
t.equal(result.sprites.count, 1);
|
||||
|
||||
|
@ -341,6 +368,15 @@ test('regression test IBE-198, a bad list does not break library', t => {
|
|||
'e6ddc55a6ddd9cc9d84fe0b4c21e016f.svg'
|
||||
]);
|
||||
|
||||
t.type(result.backdrops, 'object');
|
||||
t.equal(result.backdrops.count, 1);
|
||||
t.same(result.backdrops.id, [
|
||||
'backdrop1'
|
||||
]);
|
||||
t.same(result.backdrops.hash, [
|
||||
'cd21514d0531fdffb22204e0ec5ed84a.svg'
|
||||
]);
|
||||
|
||||
t.type(result.sprites, 'object');
|
||||
t.equal(result.sprites.count, 1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue