Skip to content

Commit 0cb28ea

Browse files
author
Ray Schamp
committed
Cache the default project json and its assets
1 parent adb31ea commit 0cb28ea

11 files changed

+139
-1
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"babel-plugin-transform-object-rest-spread": "^6.22.0",
3939
"babel-preset-es2015": "^6.22.0",
4040
"babel-preset-react": "^6.22.0",
41+
"buffer-loader": "0.0.1",
4142
"chromedriver": "2.33.1",
4243
"classnames": "2.2.5",
4344
"copy-webpack-plugin": "^4.0.1",
@@ -67,6 +68,7 @@
6768
"postcss-simple-vars": "^4.0.0",
6869
"prop-types": "^15.5.10",
6970
"raf": "^3.4.0",
71+
"raw-loader": "0.5.1",
7072
"react": "16.0.0",
7173
"react-contextmenu": "2.8.0",
7274
"react-dom": "16.0.0",
@@ -84,9 +86,9 @@
8486
"redux-throttle": "0.1.1",
8587
"rimraf": "^2.6.1",
8688
"scratch-audio": "latest",
87-
"scratch-paint": "latest",
8889
"scratch-blocks": "latest",
8990
"scratch-l10n": "^2.0.0",
91+
"scratch-paint": "latest",
9092
"scratch-render": "latest",
9193
"scratch-storage": "^0.3.0",
9294
"scratch-vm": "latest",
Lines changed: 42 additions & 0 deletions
Loading
Lines changed: 37 additions & 0 deletions
Loading
Loading
Loading
Binary file not shown.
Binary file not shown.

src/lib/default-project/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import projectJson from './project.json';
2+
import popWav from '!buffer-loader!./83a9787d4cb6f3b7632b4ddfebf74367.wav';
3+
import meowWav from '!buffer-loader!./83c36d806dc92327b9e7049a565c6bff.wav';
4+
import backdrop from '!buffer-loader!./739b5e2a2435f6e1ec2993791b423146.png';
5+
import penLayer from '!buffer-loader!./5c81a336fab8be57adc039a8a2b33ca9.png';
6+
import costume1 from '!raw-loader!./09dc888b0b7df19f70d81588ae73420e.svg';
7+
import costume2 from '!raw-loader!./3696356a03a8d938318876a593572843.svg';
8+
9+
const encoder = new TextEncoder();
10+
export default [{
11+
id: 0,
12+
assetType: 'Project',
13+
dataFormat: 'JSON',
14+
data: projectJson
15+
}, {
16+
id: '83a9787d4cb6f3b7632b4ddfebf74367',
17+
assetType: 'Sound',
18+
dataFormat: 'WAV',
19+
data: popWav
20+
}, {
21+
id: '83c36d806dc92327b9e7049a565c6bff',
22+
assetType: 'Sound',
23+
dataFormat: 'WAV',
24+
data: meowWav
25+
}, {
26+
id: '739b5e2a2435f6e1ec2993791b423146',
27+
assetType: 'ImageBitmap',
28+
dataFormat: 'PNG',
29+
data: backdrop
30+
}, {
31+
id: '5c81a336fab8be57adc039a8a2b33ca9',
32+
assetType: 'ImageBitmap',
33+
dataFormat: 'PNG',
34+
data: penLayer
35+
}, {
36+
id: '09dc888b0b7df19f70d81588ae73420e',
37+
assetType: 'ImageVector',
38+
dataFormat: 'SVG',
39+
data: encoder.encode(costume1)
40+
}, {
41+
id: '3696356a03a8d938318876a593572843',
42+
assetType: 'ImageVector',
43+
dataFormat: 'SVG',
44+
data: encoder.encode(costume2)
45+
}];
File renamed without changes.

src/lib/storage.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import ScratchStorage from 'scratch-storage';
22

3+
import defaultProjectAssets from './default-project';
4+
35
const PROJECT_SERVER = 'https://cdn.projects.scratch.mit.edu';
46
const ASSET_SERVER = 'https://cdn.assets.scratch.mit.edu';
57

@@ -23,6 +25,12 @@ class Storage extends ScratchStorage {
2325
[this.AssetType.ImageVector, this.AssetType.ImageBitmap, this.AssetType.Sound],
2426
asset => `${ASSET_SERVER}/internalapi/asset/${asset.assetId}.${asset.dataFormat}/get/`
2527
);
28+
defaultProjectAssets.forEach(asset => this.cache(
29+
this.AssetType[asset.assetType],
30+
this.DataFormat[asset.dataFormat],
31+
asset.data,
32+
asset.id
33+
));
2634
}
2735
}
2836

webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ module.exports = {
6565
}
6666
}]
6767
},
68+
{
69+
test: /\.(png|wav)$/,
70+
loader: 'raw-loader'
71+
},
6872
{
6973
test: /\.svg$/,
7074
loader: 'file-loader'

0 commit comments

Comments
 (0)