Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,34 @@ jobs:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
run: |
mkdir packages
cd packages
git clone --depth=1 https://github.com/Gandi-IDE/scratch-storage
cd scratch-storage
npx json -f package.json -I -e "this.name='scratch-storage'"
npm install
npm run build > /dev/null
echo "build end"
npm link
cd ..
git clone --depth=1 https://github.com/Gandi-IDE/scratch-parser
cd scratch-parser
npx json -f package.json -I -e "this.dependencies.ajv='^6.3.0'"
rm package-lock.json
npm install
npm link
echo "linked"
cd ../..
npx json -f package.json -I -e "this.dependencies['@babel/runtime']='^7.29.2';this.devDependencies['scratch-render-fonts']='^1.0.0-prerelease.20231017225105';delete this.dependencies['scratch-parser'];delete this.devDependencies['scratch-storage']"
cat package.json
rm yarn.lock
ls
npm install --verbose
echo "third-party module installed"
npm link scratch-storage scratch-parser
ls ./packages
echo "packages/*" >> .eslintignore
- name: Build playground
run: npm run build
- name: Build docs
Expand Down
30 changes: 29 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,35 @@ jobs:
with:
node-version: 20
cache: npm
- run: npm ci
- name: Install dependencies
run: |
mkdir packages
cd packages
git clone --depth=1 https://github.com/Gandi-IDE/scratch-storage
cd scratch-storage
npx json -f package.json -I -e "this.name='scratch-storage'"
npm install
npm run build > /dev/null
echo "build end"
npm link
cd ..
git clone --depth=1 https://github.com/Gandi-IDE/scratch-parser
cd scratch-parser
npx json -f package.json -I -e "this.dependencies.ajv='^6.3.0'"
rm package-lock.json
npm install
npm link
echo "linked"
cd ../..
npx json -f package.json -I -e "this.dependencies['@babel/runtime']='^7.29.2';this.devDependencies['scratch-render-fonts']='^1.0.0-prerelease.20231017225105';delete this['scratch-parser']"
cat package.json
rm yarn.lock
ls
npm install --verbose
echo "third-party module installed"
npm link scratch-storage scratch-parser
ls ./packages
echo "packages/*" >> .eslintignore
- run: npm run lint
- run: npm run build
- run: npm run test
20 changes: 6 additions & 14 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,11 @@ class Runtime extends EventEmitter {
* Total number of finished or errored scratch-storage load() requests since the runtime was created or cleared.
*/
this.finishedAssetRequests = 0;

/**
* @type {ScratchStorage}
*/
this.storage = {};
}

/**
Expand Down Expand Up @@ -1895,19 +1900,6 @@ class Runtime extends EventEmitter {
};
}

/**
* Generate a label between blocks categories or sub-categories.
* @param {ExtensionBlockMetadata} blockInfo - the block to convert
* @returns {ConvertedBlockInfo} - the converted & original block information
* @private
*/
_convertLabelForScratchBlocks (blockInfo) {
return {
info: blockInfo,
xml: `<label text="${xmlEscape(blockInfo.text)}"></label>`
};
}

/**
* Convert a button for scratch-blocks. A button has no opcode but specifies a callback name in the `func` field.
* @param {ExtensionBlockMetadata} buttonInfo - the button to convert
Expand Down Expand Up @@ -2714,7 +2706,7 @@ class Runtime extends EventEmitter {
/**
* CCW
startHatsWithParams is only used in block utility for extension,
WhitExtraMsg means skip field check when start a hat block.
WithExtraMsg means skip field check when start a hat block.
define here is only for debug
* @param {!string} requestedHatOpcode Opcode of hats to start.
* @param {object} data Optionally, contains fields to match on the hat and parameters to ccw_hat_parameter.
Expand Down
66 changes: 39 additions & 27 deletions src/playground/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,21 @@ const PROJECT_SERVER = 'https://cdn.projects.scratch.mit.edu/';

const SLOW = .1;

const projectInput = document.querySelector('#project-id');
if (location.hash) {
projectInput.value = location.hash.substring(1);
}
/**
* @type {HTMLInputElement}
*/
const projectInput = document.querySelector('#project');

const enableCompiler = new URLSearchParams(location.search).get('compiler') === 'true';
const compilerInput = document.querySelector('#enable-compiler');
compilerInput.checked = enableCompiler;

document.querySelector('.run')
.addEventListener('click', () => {
const params = new URLSearchParams(location.search);
params.set('compiler', compilerInput.checked);
location.href = `${location.pathname}?${params}#${projectInput.value}`;
window.profiler.run();
// const params = new URLSearchParams(location.search);
// params.set('compiler', compilerInput.checked);
// location.href = `${location.pathname}?${params}#${projectInput.value}`;
}, false);

const setShareLink = function (json) {
Expand All @@ -81,7 +82,7 @@ const setShareLink = function (json) {
.href = `suite.html`;
};

const getProjectMetadata = async projectId => {
const _getProjectMetadata = async projectId => {
const response = await fetch(`https://trampoline.turbowarp.org/api/projects/${projectId}`);
if (response.status === 404) {
throw new Error('The project is unshared or does not exist');
Expand All @@ -93,24 +94,34 @@ const getProjectMetadata = async projectId => {
return json;
};

const getProjectData = async projectId => {
const metadata = await getProjectMetadata(projectId);
const token = metadata.project_token;
const response = await fetch(`https://projects.scratch.mit.edu/${projectId}?token=${token}`);
const _getProjectData = async () => {
// const metadata = await getProjectMetadata(projectId);
// const token = metadata.project_token;
// const response = await fetch(`https://projects.scratch.mit.edu/${projectId}?token=${token}`);
// if (!response.ok) {
// throw new Error(`HTTP error ${response.status} fetching project data`);
// }
// eslint-disable-next-line no-alert, quotes
const response = await fetch(prompt("输入m.ccw.site sb3") ?? "");
if (!response.ok) {
throw new Error(`HTTP error ${response.status} fetching project data`);
}
const data = await response.arrayBuffer();
return data;
};

const loadProject = function () {
let id = location.hash.substring(1).split(',')[0];
if (id.length < 1 || !isFinite(id)) {
id = projectInput.value;
}
getProjectData(id).then(data => Scratch.vm.loadProject(data));
return id;
const loadProject = function (vm) {
// let id = location.hash.substring(1).split(',')[0];
// if (id.length < 1 || !isFinite(id)) {
// id = projectInput.value;
// }
// getProjectData(id)
new Promise(resolve => {
if (projectInput.files[0]){
projectInput.files[0].arrayBuffer().then(dat => resolve(dat));
}
}).then(data => vm.loadProject(data));
return '';
};

/**
Expand Down Expand Up @@ -539,7 +550,7 @@ class ProfilerRun {
}

run () {
this.projectId = loadProject();
this.projectId = loadProject(this.vm);

window.parent.postMessage({
type: 'BENCH_MESSAGE_LOADING'
Expand Down Expand Up @@ -671,11 +682,12 @@ const runBenchmark = function () {
maxRecordedTime = Number(split[2] || '0') || 6000;
}

new ProfilerRun({
window.profiler = new ProfilerRun({
vm,
warmUpTime,
maxRecordedTime
}).run();
});
window.profiler.run();

// Instantiate the renderer and connect it to the VM.
const canvas = document.getElementById('scratch-stage');
Expand All @@ -695,7 +707,7 @@ const runBenchmark = function () {
canvasWidth: rect.width,
canvasHeight: rect.height
};
Scratch.vm.postIOData('mouse', coordinates);
vm.postIOData('mouse', coordinates);
});
canvas.addEventListener('mousedown', e => {
const rect = canvas.getBoundingClientRect();
Expand All @@ -706,7 +718,7 @@ const runBenchmark = function () {
canvasWidth: rect.width,
canvasHeight: rect.height
};
Scratch.vm.postIOData('mouse', data);
vm.postIOData('mouse', data);
e.preventDefault();
});
canvas.addEventListener('mouseup', e => {
Expand All @@ -718,7 +730,7 @@ const runBenchmark = function () {
canvasWidth: rect.width,
canvasHeight: rect.height
};
Scratch.vm.postIOData('mouse', data);
vm.postIOData('mouse', data);
e.preventDefault();
});

Expand All @@ -728,7 +740,7 @@ const runBenchmark = function () {
if (e.target !== document && e.target !== document.body) {
return;
}
Scratch.vm.postIOData('keyboard', {
vm.postIOData('keyboard', {
keyCode: e.keyCode,
isDown: true
});
Expand All @@ -737,7 +749,7 @@ const runBenchmark = function () {
document.addEventListener('keyup', e => {
// Always capture up events,
// even those that have switched to other targets.
Scratch.vm.postIOData('keyboard', {
vm.postIOData('keyboard', {
keyCode: e.keyCode,
isDown: false
});
Expand Down
2 changes: 1 addition & 1 deletion src/playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h2>Scratch VM Benchmark</h2>
The benchmark is not very useful when the compiler is enabled.
</p>
<div class="run-form">
<input id="project-id" type="text" value="119615668">
<input id="project" type="file" accept=".sb3">
<label>
<input type="checkbox" id="enable-compiler" autocomplete="off">
Enable compiler
Expand Down
Loading