Skip to content

Commit

Permalink
Merge pull request #63 from scratchfoundation/develop
Browse files Browse the repository at this point in the history
Release: 2024-11-07
  • Loading branch information
cwillisf authored Nov 7, 2024
2 parents cb89058 + 3a84ed3 commit 8227b37
Show file tree
Hide file tree
Showing 16 changed files with 29,247 additions and 30 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@scratchfoundation/scratch-engineering
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: build-scratch-analysis
on:
push:
jobs:
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- name: Install Dependencies
run: npm ci
- name: Run Tests
run: npm test
- name: Semantic Release
if: github.ref_name == 'master'
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx --no -- semantic-release



1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
## NPM
/node_modules
npm-*
package-lock.json

## Code Coverage
.nyc_output/
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

24 changes: 24 additions & 0 deletions lib/sb2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
47 changes: 45 additions & 2 deletions lib/sb3.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@ const scripts = function (targets) {
};
};

const costumes = function (targets) {
// Storage objects
let occurrences = 0;
let nameList = [];
let hashList = [];

for (let t in targets) {
for (let a in targets[t].costumes) {
const costume = targets[t].costumes[a];
occurrences++;
nameList.push(costume.name);

let hash = costume.md5ext || `${costume.assetId}.${costume.dataFormat}`;
hashList.push(hash);
}
}

// field are named this way to keep backward compatibility
return {
count: occurrences,
id: nameList,
hash: hashList
};
};

const variables = function (targets, attribute) {
// Storage objects
let occurrences = 0;
Expand Down Expand Up @@ -92,10 +117,22 @@ const blocks = function (targets) {
for (let t in targets) {
for (let a in targets[t].blocks) {
const block = targets[t].blocks[a];
let opcode = block.opcode;

// Check for primitive blocks which don't have the opcode field
if (typeof opcode === 'undefined') {
switch (block[0]) {
case (12):
opcode = 'data_variable';
break;
case (13):
opcode = 'data_listcontents';
break;
}
}

// Get opcode and check variable manipulation for the presence of
// cloud variables
let opcode = block.opcode;
if (opcode === 'data_setvariableto' || opcode === 'data_changevariableby') {
if (isArgCloudVar(block.fields.VARIABLE[1])) {
opcode += '_cloud';
Expand Down Expand Up @@ -133,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),
Expand All @@ -141,7 +182,9 @@ module.exports = function (project, callback) {
lists: variables(project.targets, 'lists'),
comments: extract(project.targets, 'comments'),
sounds: extract(project.targets, 'sounds', 'name', 'md5ext'),
costumes: extract(project.targets, 'costumes', '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),
Expand Down
Loading

0 comments on commit 8227b37

Please sign in to comment.