Add aggregate cloud variables data to analysis results

This commit is contained in:
Andrew Sliwinski 2019-03-13 15:01:11 -04:00
parent 9cc13c4519
commit 2967e71261
8 changed files with 118 additions and 1 deletions

View file

@ -154,6 +154,35 @@ const extensions = function (project) {
return result;
};
/**
* Extracts cloud variable information.
* @param {object} project Project object (SB2 format)
* @param {array} names Names of all variables in project
* @return {object} Cloud variable information
*/
const cloud = function (project, names) {
const obj = [];
// Extract "isPersistent" parameter from all variables in project
const cloudyness = extract(project, 'variables', 'isPersistent').id;
// Ensure that variable names and isPersistent parameter list are the same
// length
if (names.length !== cloudyness.length) return -1;
// Iterate over isPersistent values, and extract names of any that are true
for (let i in cloudyness) {
if (cloudyness[i]) {
obj.push(names[i]);
}
}
return {
count: obj.length,
id: obj
};
};
/**
* Analyzes a project and returns summary information about the project.
* @param {object} project Project object (SB2 format)
@ -171,6 +200,8 @@ module.exports = function (project, callback) {
costumes: extract(project, 'costumes', 'costumeName', 'baseLayerMD5')
};
meta.cloud = cloud(project, meta.variables.id);
// Sprites
meta.sprites = sprites(project);

View file

@ -21,9 +21,14 @@ const variables = function (targets, attribute) {
let occurrences = 0;
let idList = [];
// Cloud variables are a type of variable
const isCloud = (attribute === 'cloud');
if (isCloud) attribute = 'variables';
for (let t in targets) {
for (let a in targets[t][attribute]) {
const variable = targets[t][attribute][a];
if (isCloud && (variable.length !== 3 || !variable[2])) continue;
occurrences++;
idList.push(variable[0]);
}
@ -97,6 +102,7 @@ module.exports = function (project, callback) {
const meta = {
scripts: scripts(project.targets),
variables: variables(project.targets, 'variables'),
cloud: variables(project.targets, 'cloud'),
lists: variables(project.targets, 'lists'),
comments: extract(project.targets, 'comments'),
sounds: extract(project.targets, 'sounds', 'name', 'md5ext'),