scratch-sb1-converter 2.0.279 → 2.0.280
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.json +7 -7
- package/playground/main.js +1 -1
- package/playground/view.js +1 -1
- package/src/to-sb2/json-generator.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See
|
|
4
4
|
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.0.280](https://github.com/scratchfoundation/scratch-sb1-converter/compare/v2.0.279...v2.0.280) (2026-08-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* apply a fix for older files, that lack a field necessary for sb2 files ([3e51e25](https://github.com/scratchfoundation/scratch-sb1-converter/commit/3e51e2520404d016379830663a2029378f59810b))
|
|
12
|
+
* fix the test ([ba37b2f](https://github.com/scratchfoundation/scratch-sb1-converter/commit/ba37b2fe45c8648b19eeaaa336003060d1b47040))
|
|
13
|
+
|
|
6
14
|
## [2.0.279](https://github.com/scratchfoundation/scratch-sb1-converter/compare/v2.0.278...v2.0.279) (2025-11-18)
|
|
7
15
|
|
|
8
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scratch-sb1-converter",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.280",
|
|
4
4
|
"description": "Scratch 1 (.sb) to Scratch 2 (.sb2) conversion library for Scratch 3.0",
|
|
5
5
|
"author": "Scratch Foundation",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"text-encoding": "^0.7.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@babel/cli": "7.
|
|
40
|
-
"@babel/core": "7.
|
|
41
|
-
"@babel/eslint-parser": "7.
|
|
42
|
-
"@babel/preset-env": "7.
|
|
43
|
-
"@babel/register": "7.
|
|
39
|
+
"@babel/cli": "7.29.7",
|
|
40
|
+
"@babel/core": "7.29.7",
|
|
41
|
+
"@babel/eslint-parser": "7.29.7",
|
|
42
|
+
"@babel/preset-env": "7.29.7",
|
|
43
|
+
"@babel/register": "7.29.7",
|
|
44
44
|
"@commitlint/cli": "18.6.1",
|
|
45
45
|
"@commitlint/config-conventional": "18.6.3",
|
|
46
46
|
"babel-eslint": "10.1.0",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"html-webpack-plugin": "3.2.0",
|
|
53
53
|
"husky": "8.0.3",
|
|
54
54
|
"jsdoc": "3.6.11",
|
|
55
|
-
"json": "
|
|
55
|
+
"json": "9.0.6",
|
|
56
56
|
"scratch-semantic-release-config": "3.0.0",
|
|
57
57
|
"semantic-release": "19.0.5",
|
|
58
58
|
"tap": "12.7.0",
|
package/playground/main.js
CHANGED
|
@@ -475,7 +475,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) *
|
|
|
475
475
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
476
476
|
|
|
477
477
|
"use strict";
|
|
478
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"toSb2Json\", function() { return toSb2Json; });\n/* harmony import */ var _squeak_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../squeak/types */ \"./src/squeak/types.js\");\n/* harmony import */ var js_md5__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! js-md5 */ \"./node_modules/js-md5/src/md5.js\");\n/* harmony import */ var js_md5__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(js_md5__WEBPACK_IMPORTED_MODULE_1__);\nfunction _typeof(o) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o; }, _typeof(o); }\nfunction _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\nfunction _iterableToArray(r) { if (\"undefined\" != typeof Symbol && null != r[Symbol.iterator] || null != r[\"@@iterator\"]) return Array.from(r); }\nfunction _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }\nfunction _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\nfunction _unsupportedIterableToArray(r, a) { if (r) { if (\"string\" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return \"Object\" === t && r.constructor && (t = r.constructor.name), \"Map\" === t || \"Set\" === t ? Array.from(r) : \"Arguments\" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }\nfunction _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }\nfunction _iterableToArrayLimit(r, l) { var t = null == r ? null : \"undefined\" != typeof Symbol && r[Symbol.iterator] || r[\"@@iterator\"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }\nfunction _arrayWithHoles(r) { if (Array.isArray(r)) return r; }\n/* eslint no-use-before-define:1 */\n\n\n\n\n// https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L292-L308\nvar fixMouseEdgeRef = function fixMouseEdgeRef(block) {\n var oldVal = String(block[block.length - 1]);\n var last = block.length - 1;\n if (oldVal === 'mouse') {\n block[last] = '_mouse_';\n } else if (oldVal === 'edge') {\n block[last] = '_edge_';\n } else if (block[block.length - 1] instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"StageData\"]) {\n block[last] = '_stage_';\n }\n return block;\n};\nvar sb1SpecMap = {\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L197-L199\n 'getParam': function getParam(_ref) {\n var _ref2 = _slicedToArray(_ref, 4),\n a = _ref2[0],\n b = _ref2[1],\n c = _ref2[2],\n d = _ref2[3];\n return [a, b, c, d || 'r'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L200-L212\n 'changeVariable': function changeVariable(block) {\n return [block[2], block[1], block[3]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L213-L219\n 'EventHatMorph': function EventHatMorph(block) {\n if (String(block[1]) === 'Scratch-StartClicked') {\n return ['whenGreenFlag'];\n }\n return ['whenIReceive', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L220-L222\n 'MouseClickEventHatMorph': function MouseClickEventHatMorph() {\n return ['whenClicked'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L223-L226\n 'KeyEventHatMorph': function KeyEventHatMorph(block) {\n return ['whenKeyPressed', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L227-L235\n 'stopScripts': function stopScripts(block) {\n if (String(block[1]) === 'other scripts') {\n return [block[0], 'other scripts in sprite'];\n }\n return block;\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L249-L253\n 'abs': function abs(block) {\n return ['computeFunction:of:', 'abs', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L254-L258\n 'sqrt': function sqrt(block) {\n return ['computeFunction:of:', 'sqrt', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L137\n '\\\\\\\\': function _(block) {\n return ['%'].concat(_toConsumableArray(block.slice(1)));\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L259-L262\n 'doReturn': function doReturn() {\n return ['stopScripts', 'this script'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L263-L266\n 'stopAll': function stopAll() {\n return ['stopScripts', 'all'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L267-L270\n 'showBackground:': function showBackground(block) {\n return ['startScene', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L271-L273\n 'nextBackground': function nextBackground() {\n return ['nextScene'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L274-L282\n 'doForeverIf': function doForeverIf(block) {\n return ['doForever', [['doIf', block[1], block[2]]]];\n },\n 'getAttribute:of:': fixMouseEdgeRef,\n 'gotoSpriteOrMouse:': fixMouseEdgeRef,\n 'distanceTo:': fixMouseEdgeRef,\n 'pointTowards:': fixMouseEdgeRef,\n 'touching:': fixMouseEdgeRef\n};\nvar valueOf = function valueOf(obj) {\n if (_typeof(obj) === 'object' && obj) return obj.valueOf();\n return obj;\n};\nvar toSb2Json = function toSb2Json(root) {\n var info = root.info,\n stageData = root.stageData,\n images = root.images,\n sounds = root.sounds;\n var pairs = function pairs(array) {\n var _pairs = [];\n for (var i = 0; i < array.length; i += 2) {\n _pairs.push([array[i], array[i + 1]]);\n }\n return _pairs;\n };\n var toSb2JsonVariable = function toSb2JsonVariable(_ref3) {\n var _ref4 = _slicedToArray(_ref3, 2),\n name = _ref4[0],\n value = _ref4[1];\n return {\n name: name,\n value: value,\n isPersistent: false\n };\n };\n var toSb2JsonList = function toSb2JsonList(_ref5) {\n var _ref6 = _slicedToArray(_ref5, 2),\n _ref6$ = _ref6[1],\n listName = _ref6$.listName,\n contents = _ref6$.contents,\n x = _ref6$.x,\n y = _ref6$.y,\n width = _ref6$.width,\n height = _ref6$.height,\n hiddenWhenNull = _ref6$.hiddenWhenNull;\n return {\n listName: listName,\n contents: contents,\n isPersistent: false,\n x: x,\n y: y,\n width: width,\n height: height,\n visible: valueOf(hiddenWhenNull) !== null\n };\n };\n\n // TODO: Implement toSb2JsonWatcher\n // const toSb2JsonWatcher = watcher => {\n //\n // };\n\n // TODO: Implement toSb2JsonListWatcher\n // const toSb2JsonListWatcher = listWatcher => {\n //\n // };\n\n var toSb2JsonSound = function toSb2JsonSound(soundMediaData) {\n var soundID = sounds.findIndex(function (sound) {\n return sound.crc === soundMediaData.crc;\n });\n return {\n soundName: soundMediaData.name,\n soundID: soundID,\n md5: \"\".concat(soundMediaData.md5, \".wav\"),\n sampleCount: soundMediaData.sampleCount,\n rate: soundMediaData.rate,\n format: ''\n };\n };\n var toSb2ImageExtension = function toSb2ImageExtension(imageMedia) {\n if (imageMedia.extension === 'uncompressed') {\n return 'png';\n }\n return 'jpg';\n };\n var toSb2JsonCostume = function toSb2JsonCostume(imageMediaData) {\n var baseLayerID = images.findIndex(function (image) {\n return image.crc === imageMediaData.crc;\n });\n return {\n costumeName: imageMediaData.costumeName,\n baseLayerID: baseLayerID,\n baseLayerMD5: \"\".concat(js_md5__WEBPACK_IMPORTED_MODULE_1___default()(imageMediaData.rawBytes), \".\").concat(toSb2ImageExtension(imageMediaData)),\n bitmapResolution: 1,\n rotationCenterX: imageMediaData.rotationCenter.x,\n rotationCenterY: imageMediaData.rotationCenter.y\n };\n };\n var toSb2JsonBlock = function toSb2JsonBlock(blockData) {\n var output = blockData.map(toSb2JsonBlockArg);\n var spec = sb1SpecMap[output[0]];\n if (spec) {\n output = spec(output);\n }\n return output;\n };\n var toSb2JsonStack = function toSb2JsonStack(stackData) {\n return stackData.map(toSb2JsonBlock);\n };\n var toSb2JsonBlockArg = function toSb2JsonBlockArg(argData) {\n if (argData instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SpriteData\"]) {\n return argData.objName;\n } else if (Array.isArray(argData)) {\n if (argData.length === 0 || Array.isArray(argData[0])) {\n return toSb2JsonStack(argData);\n }\n return toSb2JsonBlock(argData);\n }\n return argData;\n };\n var toSb2JsonScript = function toSb2JsonScript(scriptData) {\n return [scriptData[0].x, scriptData[0].y, toSb2JsonStack(scriptData[1])];\n };\n var toSb2JsonSprite = function toSb2JsonSprite(spriteData) {\n var rawCostumes = spriteData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"ImageMediaData\"];\n });\n var rawSounds = spriteData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SoundMediaData\"];\n });\n return {\n objName: spriteData.objName,\n variables: pairs(spriteData.vars).map(toSb2JsonVariable),\n lists: pairs(spriteData.lists).map(toSb2JsonList),\n scripts: spriteData.blocksBin.map(toSb2JsonScript),\n costumes: rawCostumes.map(toSb2JsonCostume),\n currentCostumeIndex: rawCostumes.findIndex(function (image) {\n return image.crc === spriteData.currentCostume.crc;\n }),\n sounds: rawSounds.map(toSb2JsonSound),\n scratchX: spriteData.scratchX,\n scratchY: spriteData.scratchY,\n scale: spriteData.scalePoint.x,\n direction: Math.round(spriteData.rotationDegrees * 1e6) / 1e6 - 270,\n rotationStyle: spriteData.rotationStyle,\n isDraggable: spriteData.draggable,\n indexInLibrary: stageData.spriteOrderInLibrary.indexOf(spriteData),\n visible: spriteData.visible,\n spriteInfo: {}\n };\n };\n var toSb2JsonChild = function toSb2JsonChild(child) {\n if (child instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SpriteData\"]) {\n return toSb2JsonSprite(child);\n }\n return null;\n };\n var toSb2JsonStage = function toSb2JsonStage(_stageData) {\n var rawCostumes = _stageData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"ImageMediaData\"];\n });\n var rawSounds = _stageData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SoundMediaData\"];\n });\n return {\n objName: _stageData.objName,\n variables: pairs(_stageData.vars).map(toSb2JsonVariable),\n lists: pairs(_stageData.lists).map(toSb2JsonList),\n scripts: _stageData.blocksBin.map(toSb2JsonScript),\n costumes: rawCostumes.map(toSb2JsonCostume),\n currentCostumeIndex: rawCostumes.findIndex(function (image) {\n return image.crc === _stageData.currentCostume.crc;\n }),\n sounds: rawSounds.map(toSb2JsonSound),\n // TODO: Where does this come from? Is it always the same for SB1?\n penLayerMD5: '5c81a336fab8be57adc039a8a2b33ca9.png',\n penLayerID: 0,\n tempoBPM: _stageData.tempoBPM,\n videoAlpha: 0.5,\n children: _stageData.stageContents.map(toSb2JsonChild).filter(Boolean).reverse()\n };\n };\n var toSb2JsonInfo = function toSb2JsonInfo(_info) {\n var obj = {};\n for (var i = 0; i < _info.length; i += 2) {\n if (String(_info[i]) === 'thumbnail') continue;\n obj[String(_info[i])] = String(_info[i + 1]);\n }\n return obj;\n };\n return JSON.parse(JSON.stringify(Object.assign(toSb2JsonStage(stageData), {\n info: toSb2JsonInfo(info)\n })));\n};\n\n\n//# sourceURL=webpack:///./src/to-sb2/json-generator.js?");
|
|
478
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"toSb2Json\", function() { return toSb2Json; });\n/* harmony import */ var _squeak_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../squeak/types */ \"./src/squeak/types.js\");\n/* harmony import */ var js_md5__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! js-md5 */ \"./node_modules/js-md5/src/md5.js\");\n/* harmony import */ var js_md5__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(js_md5__WEBPACK_IMPORTED_MODULE_1__);\nfunction _typeof(o) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o; }, _typeof(o); }\nfunction _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\nfunction _iterableToArray(r) { if (\"undefined\" != typeof Symbol && null != r[Symbol.iterator] || null != r[\"@@iterator\"]) return Array.from(r); }\nfunction _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }\nfunction _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\nfunction _unsupportedIterableToArray(r, a) { if (r) { if (\"string\" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return \"Object\" === t && r.constructor && (t = r.constructor.name), \"Map\" === t || \"Set\" === t ? Array.from(r) : \"Arguments\" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }\nfunction _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }\nfunction _iterableToArrayLimit(r, l) { var t = null == r ? null : \"undefined\" != typeof Symbol && r[Symbol.iterator] || r[\"@@iterator\"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }\nfunction _arrayWithHoles(r) { if (Array.isArray(r)) return r; }\n/* eslint no-use-before-define:1 */\n\n\n\n\n// https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L292-L308\nvar fixMouseEdgeRef = function fixMouseEdgeRef(block) {\n var oldVal = String(block[block.length - 1]);\n var last = block.length - 1;\n if (oldVal === 'mouse') {\n block[last] = '_mouse_';\n } else if (oldVal === 'edge') {\n block[last] = '_edge_';\n } else if (block[block.length - 1] instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"StageData\"]) {\n block[last] = '_stage_';\n }\n return block;\n};\nvar sb1SpecMap = {\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L197-L199\n 'getParam': function getParam(_ref) {\n var _ref2 = _slicedToArray(_ref, 4),\n a = _ref2[0],\n b = _ref2[1],\n c = _ref2[2],\n d = _ref2[3];\n return [a, b, c, d || 'r'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L200-L212\n 'changeVariable': function changeVariable(block) {\n return [block[2], block[1], block[3]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L213-L219\n 'EventHatMorph': function EventHatMorph(block) {\n if (String(block[1]) === 'Scratch-StartClicked') {\n return ['whenGreenFlag'];\n }\n return ['whenIReceive', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L220-L222\n 'MouseClickEventHatMorph': function MouseClickEventHatMorph() {\n return ['whenClicked'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L223-L226\n 'KeyEventHatMorph': function KeyEventHatMorph(block) {\n return ['whenKeyPressed', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L227-L235\n 'stopScripts': function stopScripts(block) {\n if (String(block[1]) === 'other scripts') {\n return [block[0], 'other scripts in sprite'];\n }\n return block;\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L249-L253\n 'abs': function abs(block) {\n return ['computeFunction:of:', 'abs', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L254-L258\n 'sqrt': function sqrt(block) {\n return ['computeFunction:of:', 'sqrt', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L137\n '\\\\\\\\': function _(block) {\n return ['%'].concat(_toConsumableArray(block.slice(1)));\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L259-L262\n 'doReturn': function doReturn() {\n return ['stopScripts', 'this script'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L263-L266\n 'stopAll': function stopAll() {\n return ['stopScripts', 'all'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L267-L270\n 'showBackground:': function showBackground(block) {\n return ['startScene', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L271-L273\n 'nextBackground': function nextBackground() {\n return ['nextScene'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L274-L282\n 'doForeverIf': function doForeverIf(block) {\n return ['doForever', [['doIf', block[1], block[2]]]];\n },\n 'getAttribute:of:': fixMouseEdgeRef,\n 'gotoSpriteOrMouse:': fixMouseEdgeRef,\n 'distanceTo:': fixMouseEdgeRef,\n 'pointTowards:': fixMouseEdgeRef,\n 'touching:': fixMouseEdgeRef\n};\nvar valueOf = function valueOf(obj) {\n if (_typeof(obj) === 'object' && obj) return obj.valueOf();\n return obj;\n};\nvar toSb2Json = function toSb2Json(root) {\n var info = root.info,\n stageData = root.stageData,\n images = root.images,\n sounds = root.sounds;\n var pairs = function pairs(array) {\n var _pairs = [];\n for (var i = 0; i < array.length; i += 2) {\n _pairs.push([array[i], array[i + 1]]);\n }\n return _pairs;\n };\n var toSb2JsonVariable = function toSb2JsonVariable(_ref3) {\n var _ref4 = _slicedToArray(_ref3, 2),\n name = _ref4[0],\n value = _ref4[1];\n return {\n name: name,\n value: value,\n isPersistent: false\n };\n };\n var toSb2JsonList = function toSb2JsonList(_ref5) {\n var _ref6 = _slicedToArray(_ref5, 2),\n _ref6$ = _ref6[1],\n listName = _ref6$.listName,\n contents = _ref6$.contents,\n x = _ref6$.x,\n y = _ref6$.y,\n width = _ref6$.width,\n height = _ref6$.height,\n hiddenWhenNull = _ref6$.hiddenWhenNull;\n return {\n listName: listName,\n contents: contents,\n isPersistent: false,\n x: x,\n y: y,\n width: width,\n height: height,\n visible: valueOf(hiddenWhenNull) !== null\n };\n };\n\n // TODO: Implement toSb2JsonWatcher\n // const toSb2JsonWatcher = watcher => {\n //\n // };\n\n // TODO: Implement toSb2JsonListWatcher\n // const toSb2JsonListWatcher = listWatcher => {\n //\n // };\n\n var toSb2JsonSound = function toSb2JsonSound(soundMediaData) {\n var soundID = sounds.findIndex(function (sound) {\n return sound.crc === soundMediaData.crc;\n });\n return {\n soundName: soundMediaData.name,\n soundID: soundID,\n md5: \"\".concat(soundMediaData.md5, \".wav\"),\n sampleCount: soundMediaData.sampleCount,\n rate: soundMediaData.rate,\n format: ''\n };\n };\n var toSb2ImageExtension = function toSb2ImageExtension(imageMedia) {\n if (imageMedia.extension === 'uncompressed') {\n return 'png';\n }\n return 'jpg';\n };\n var toSb2JsonCostume = function toSb2JsonCostume(imageMediaData) {\n var baseLayerID = images.findIndex(function (image) {\n return image.crc === imageMediaData.crc;\n });\n return {\n costumeName: imageMediaData.costumeName,\n baseLayerID: baseLayerID,\n baseLayerMD5: \"\".concat(js_md5__WEBPACK_IMPORTED_MODULE_1___default()(imageMediaData.rawBytes), \".\").concat(toSb2ImageExtension(imageMediaData)),\n bitmapResolution: 1,\n rotationCenterX: imageMediaData.rotationCenter.x,\n rotationCenterY: imageMediaData.rotationCenter.y\n };\n };\n var toSb2JsonBlock = function toSb2JsonBlock(blockData) {\n var output = blockData.map(toSb2JsonBlockArg);\n var spec = sb1SpecMap[output[0]];\n if (spec) {\n output = spec(output);\n }\n return output;\n };\n var toSb2JsonStack = function toSb2JsonStack(stackData) {\n return stackData.map(toSb2JsonBlock);\n };\n var toSb2JsonBlockArg = function toSb2JsonBlockArg(argData) {\n if (argData instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SpriteData\"]) {\n return argData.objName;\n } else if (Array.isArray(argData)) {\n if (argData.length === 0 || Array.isArray(argData[0])) {\n return toSb2JsonStack(argData);\n }\n return toSb2JsonBlock(argData);\n }\n return argData;\n };\n var toSb2JsonScript = function toSb2JsonScript(scriptData) {\n return [scriptData[0].x, scriptData[0].y, toSb2JsonStack(scriptData[1])];\n };\n var toSb2JsonSprite = function toSb2JsonSprite(spriteData) {\n var rawCostumes = spriteData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"ImageMediaData\"];\n });\n var rawSounds = spriteData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SoundMediaData\"];\n });\n return {\n objName: spriteData.objName,\n variables: pairs(spriteData.vars).map(toSb2JsonVariable),\n lists: pairs(spriteData.lists).map(toSb2JsonList),\n scripts: spriteData.blocksBin.map(toSb2JsonScript),\n costumes: rawCostumes.map(toSb2JsonCostume),\n currentCostumeIndex: rawCostumes.findIndex(function (image) {\n return image.crc === spriteData.currentCostume.crc;\n }),\n sounds: rawSounds.map(toSb2JsonSound),\n scratchX: spriteData.scratchX,\n scratchY: spriteData.scratchY,\n scale: spriteData.scalePoint.x,\n direction: Math.round(spriteData.rotationDegrees * 1e6) / 1e6 - 270,\n rotationStyle: spriteData.rotationStyle,\n isDraggable: spriteData.draggable,\n indexInLibrary: stageData.spriteOrderInLibrary ? stageData.spriteOrderInLibrary.indexOf(spriteData) : -1,\n visible: spriteData.visible,\n spriteInfo: {}\n };\n };\n var toSb2JsonChild = function toSb2JsonChild(child) {\n if (child instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SpriteData\"]) {\n return toSb2JsonSprite(child);\n }\n return null;\n };\n var toSb2JsonStage = function toSb2JsonStage(_stageData) {\n var rawCostumes = _stageData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"ImageMediaData\"];\n });\n var rawSounds = _stageData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SoundMediaData\"];\n });\n return {\n objName: _stageData.objName,\n variables: pairs(_stageData.vars).map(toSb2JsonVariable),\n lists: pairs(_stageData.lists).map(toSb2JsonList),\n scripts: _stageData.blocksBin.map(toSb2JsonScript),\n costumes: rawCostumes.map(toSb2JsonCostume),\n currentCostumeIndex: rawCostumes.findIndex(function (image) {\n return image.crc === _stageData.currentCostume.crc;\n }),\n sounds: rawSounds.map(toSb2JsonSound),\n // TODO: Where does this come from? Is it always the same for SB1?\n penLayerMD5: '5c81a336fab8be57adc039a8a2b33ca9.png',\n penLayerID: 0,\n tempoBPM: _stageData.tempoBPM,\n videoAlpha: 0.5,\n children: _stageData.stageContents.map(toSb2JsonChild).filter(Boolean).reverse()\n };\n };\n var toSb2JsonInfo = function toSb2JsonInfo(_info) {\n var obj = {};\n for (var i = 0; i < _info.length; i += 2) {\n if (String(_info[i]) === 'thumbnail') continue;\n obj[String(_info[i])] = String(_info[i + 1]);\n }\n return obj;\n };\n return JSON.parse(JSON.stringify(Object.assign(toSb2JsonStage(stageData), {\n info: toSb2JsonInfo(info)\n })));\n};\n\n\n//# sourceURL=webpack:///./src/to-sb2/json-generator.js?");
|
|
479
479
|
|
|
480
480
|
/***/ }),
|
|
481
481
|
|
package/playground/view.js
CHANGED
|
@@ -703,7 +703,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) *
|
|
|
703
703
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
704
704
|
|
|
705
705
|
"use strict";
|
|
706
|
-
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"toSb2Json\", function() { return toSb2Json; });\n/* harmony import */ var _squeak_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../squeak/types */ \"./src/squeak/types.js\");\n/* harmony import */ var js_md5__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! js-md5 */ \"./node_modules/js-md5/src/md5.js\");\n/* harmony import */ var js_md5__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(js_md5__WEBPACK_IMPORTED_MODULE_1__);\nfunction _typeof(o) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o; }, _typeof(o); }\nfunction _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\nfunction _iterableToArray(r) { if (\"undefined\" != typeof Symbol && null != r[Symbol.iterator] || null != r[\"@@iterator\"]) return Array.from(r); }\nfunction _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }\nfunction _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\nfunction _unsupportedIterableToArray(r, a) { if (r) { if (\"string\" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return \"Object\" === t && r.constructor && (t = r.constructor.name), \"Map\" === t || \"Set\" === t ? Array.from(r) : \"Arguments\" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }\nfunction _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }\nfunction _iterableToArrayLimit(r, l) { var t = null == r ? null : \"undefined\" != typeof Symbol && r[Symbol.iterator] || r[\"@@iterator\"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }\nfunction _arrayWithHoles(r) { if (Array.isArray(r)) return r; }\n/* eslint no-use-before-define:1 */\n\n\n\n\n// https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L292-L308\nvar fixMouseEdgeRef = function fixMouseEdgeRef(block) {\n var oldVal = String(block[block.length - 1]);\n var last = block.length - 1;\n if (oldVal === 'mouse') {\n block[last] = '_mouse_';\n } else if (oldVal === 'edge') {\n block[last] = '_edge_';\n } else if (block[block.length - 1] instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"StageData\"]) {\n block[last] = '_stage_';\n }\n return block;\n};\nvar sb1SpecMap = {\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L197-L199\n 'getParam': function getParam(_ref) {\n var _ref2 = _slicedToArray(_ref, 4),\n a = _ref2[0],\n b = _ref2[1],\n c = _ref2[2],\n d = _ref2[3];\n return [a, b, c, d || 'r'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L200-L212\n 'changeVariable': function changeVariable(block) {\n return [block[2], block[1], block[3]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L213-L219\n 'EventHatMorph': function EventHatMorph(block) {\n if (String(block[1]) === 'Scratch-StartClicked') {\n return ['whenGreenFlag'];\n }\n return ['whenIReceive', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L220-L222\n 'MouseClickEventHatMorph': function MouseClickEventHatMorph() {\n return ['whenClicked'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L223-L226\n 'KeyEventHatMorph': function KeyEventHatMorph(block) {\n return ['whenKeyPressed', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L227-L235\n 'stopScripts': function stopScripts(block) {\n if (String(block[1]) === 'other scripts') {\n return [block[0], 'other scripts in sprite'];\n }\n return block;\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L249-L253\n 'abs': function abs(block) {\n return ['computeFunction:of:', 'abs', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L254-L258\n 'sqrt': function sqrt(block) {\n return ['computeFunction:of:', 'sqrt', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L137\n '\\\\\\\\': function _(block) {\n return ['%'].concat(_toConsumableArray(block.slice(1)));\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L259-L262\n 'doReturn': function doReturn() {\n return ['stopScripts', 'this script'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L263-L266\n 'stopAll': function stopAll() {\n return ['stopScripts', 'all'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L267-L270\n 'showBackground:': function showBackground(block) {\n return ['startScene', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L271-L273\n 'nextBackground': function nextBackground() {\n return ['nextScene'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L274-L282\n 'doForeverIf': function doForeverIf(block) {\n return ['doForever', [['doIf', block[1], block[2]]]];\n },\n 'getAttribute:of:': fixMouseEdgeRef,\n 'gotoSpriteOrMouse:': fixMouseEdgeRef,\n 'distanceTo:': fixMouseEdgeRef,\n 'pointTowards:': fixMouseEdgeRef,\n 'touching:': fixMouseEdgeRef\n};\nvar valueOf = function valueOf(obj) {\n if (_typeof(obj) === 'object' && obj) return obj.valueOf();\n return obj;\n};\nvar toSb2Json = function toSb2Json(root) {\n var info = root.info,\n stageData = root.stageData,\n images = root.images,\n sounds = root.sounds;\n var pairs = function pairs(array) {\n var _pairs = [];\n for (var i = 0; i < array.length; i += 2) {\n _pairs.push([array[i], array[i + 1]]);\n }\n return _pairs;\n };\n var toSb2JsonVariable = function toSb2JsonVariable(_ref3) {\n var _ref4 = _slicedToArray(_ref3, 2),\n name = _ref4[0],\n value = _ref4[1];\n return {\n name: name,\n value: value,\n isPersistent: false\n };\n };\n var toSb2JsonList = function toSb2JsonList(_ref5) {\n var _ref6 = _slicedToArray(_ref5, 2),\n _ref6$ = _ref6[1],\n listName = _ref6$.listName,\n contents = _ref6$.contents,\n x = _ref6$.x,\n y = _ref6$.y,\n width = _ref6$.width,\n height = _ref6$.height,\n hiddenWhenNull = _ref6$.hiddenWhenNull;\n return {\n listName: listName,\n contents: contents,\n isPersistent: false,\n x: x,\n y: y,\n width: width,\n height: height,\n visible: valueOf(hiddenWhenNull) !== null\n };\n };\n\n // TODO: Implement toSb2JsonWatcher\n // const toSb2JsonWatcher = watcher => {\n //\n // };\n\n // TODO: Implement toSb2JsonListWatcher\n // const toSb2JsonListWatcher = listWatcher => {\n //\n // };\n\n var toSb2JsonSound = function toSb2JsonSound(soundMediaData) {\n var soundID = sounds.findIndex(function (sound) {\n return sound.crc === soundMediaData.crc;\n });\n return {\n soundName: soundMediaData.name,\n soundID: soundID,\n md5: \"\".concat(soundMediaData.md5, \".wav\"),\n sampleCount: soundMediaData.sampleCount,\n rate: soundMediaData.rate,\n format: ''\n };\n };\n var toSb2ImageExtension = function toSb2ImageExtension(imageMedia) {\n if (imageMedia.extension === 'uncompressed') {\n return 'png';\n }\n return 'jpg';\n };\n var toSb2JsonCostume = function toSb2JsonCostume(imageMediaData) {\n var baseLayerID = images.findIndex(function (image) {\n return image.crc === imageMediaData.crc;\n });\n return {\n costumeName: imageMediaData.costumeName,\n baseLayerID: baseLayerID,\n baseLayerMD5: \"\".concat(js_md5__WEBPACK_IMPORTED_MODULE_1___default()(imageMediaData.rawBytes), \".\").concat(toSb2ImageExtension(imageMediaData)),\n bitmapResolution: 1,\n rotationCenterX: imageMediaData.rotationCenter.x,\n rotationCenterY: imageMediaData.rotationCenter.y\n };\n };\n var toSb2JsonBlock = function toSb2JsonBlock(blockData) {\n var output = blockData.map(toSb2JsonBlockArg);\n var spec = sb1SpecMap[output[0]];\n if (spec) {\n output = spec(output);\n }\n return output;\n };\n var toSb2JsonStack = function toSb2JsonStack(stackData) {\n return stackData.map(toSb2JsonBlock);\n };\n var toSb2JsonBlockArg = function toSb2JsonBlockArg(argData) {\n if (argData instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SpriteData\"]) {\n return argData.objName;\n } else if (Array.isArray(argData)) {\n if (argData.length === 0 || Array.isArray(argData[0])) {\n return toSb2JsonStack(argData);\n }\n return toSb2JsonBlock(argData);\n }\n return argData;\n };\n var toSb2JsonScript = function toSb2JsonScript(scriptData) {\n return [scriptData[0].x, scriptData[0].y, toSb2JsonStack(scriptData[1])];\n };\n var toSb2JsonSprite = function toSb2JsonSprite(spriteData) {\n var rawCostumes = spriteData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"ImageMediaData\"];\n });\n var rawSounds = spriteData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SoundMediaData\"];\n });\n return {\n objName: spriteData.objName,\n variables: pairs(spriteData.vars).map(toSb2JsonVariable),\n lists: pairs(spriteData.lists).map(toSb2JsonList),\n scripts: spriteData.blocksBin.map(toSb2JsonScript),\n costumes: rawCostumes.map(toSb2JsonCostume),\n currentCostumeIndex: rawCostumes.findIndex(function (image) {\n return image.crc === spriteData.currentCostume.crc;\n }),\n sounds: rawSounds.map(toSb2JsonSound),\n scratchX: spriteData.scratchX,\n scratchY: spriteData.scratchY,\n scale: spriteData.scalePoint.x,\n direction: Math.round(spriteData.rotationDegrees * 1e6) / 1e6 - 270,\n rotationStyle: spriteData.rotationStyle,\n isDraggable: spriteData.draggable,\n indexInLibrary: stageData.spriteOrderInLibrary.indexOf(spriteData),\n visible: spriteData.visible,\n spriteInfo: {}\n };\n };\n var toSb2JsonChild = function toSb2JsonChild(child) {\n if (child instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SpriteData\"]) {\n return toSb2JsonSprite(child);\n }\n return null;\n };\n var toSb2JsonStage = function toSb2JsonStage(_stageData) {\n var rawCostumes = _stageData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"ImageMediaData\"];\n });\n var rawSounds = _stageData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SoundMediaData\"];\n });\n return {\n objName: _stageData.objName,\n variables: pairs(_stageData.vars).map(toSb2JsonVariable),\n lists: pairs(_stageData.lists).map(toSb2JsonList),\n scripts: _stageData.blocksBin.map(toSb2JsonScript),\n costumes: rawCostumes.map(toSb2JsonCostume),\n currentCostumeIndex: rawCostumes.findIndex(function (image) {\n return image.crc === _stageData.currentCostume.crc;\n }),\n sounds: rawSounds.map(toSb2JsonSound),\n // TODO: Where does this come from? Is it always the same for SB1?\n penLayerMD5: '5c81a336fab8be57adc039a8a2b33ca9.png',\n penLayerID: 0,\n tempoBPM: _stageData.tempoBPM,\n videoAlpha: 0.5,\n children: _stageData.stageContents.map(toSb2JsonChild).filter(Boolean).reverse()\n };\n };\n var toSb2JsonInfo = function toSb2JsonInfo(_info) {\n var obj = {};\n for (var i = 0; i < _info.length; i += 2) {\n if (String(_info[i]) === 'thumbnail') continue;\n obj[String(_info[i])] = String(_info[i + 1]);\n }\n return obj;\n };\n return JSON.parse(JSON.stringify(Object.assign(toSb2JsonStage(stageData), {\n info: toSb2JsonInfo(info)\n })));\n};\n\n\n//# sourceURL=webpack:///./src/to-sb2/json-generator.js?");
|
|
706
|
+
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"toSb2Json\", function() { return toSb2Json; });\n/* harmony import */ var _squeak_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../squeak/types */ \"./src/squeak/types.js\");\n/* harmony import */ var js_md5__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! js-md5 */ \"./node_modules/js-md5/src/md5.js\");\n/* harmony import */ var js_md5__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(js_md5__WEBPACK_IMPORTED_MODULE_1__);\nfunction _typeof(o) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o; }, _typeof(o); }\nfunction _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\nfunction _iterableToArray(r) { if (\"undefined\" != typeof Symbol && null != r[Symbol.iterator] || null != r[\"@@iterator\"]) return Array.from(r); }\nfunction _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }\nfunction _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\nfunction _unsupportedIterableToArray(r, a) { if (r) { if (\"string\" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return \"Object\" === t && r.constructor && (t = r.constructor.name), \"Map\" === t || \"Set\" === t ? Array.from(r) : \"Arguments\" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }\nfunction _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }\nfunction _iterableToArrayLimit(r, l) { var t = null == r ? null : \"undefined\" != typeof Symbol && r[Symbol.iterator] || r[\"@@iterator\"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }\nfunction _arrayWithHoles(r) { if (Array.isArray(r)) return r; }\n/* eslint no-use-before-define:1 */\n\n\n\n\n// https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L292-L308\nvar fixMouseEdgeRef = function fixMouseEdgeRef(block) {\n var oldVal = String(block[block.length - 1]);\n var last = block.length - 1;\n if (oldVal === 'mouse') {\n block[last] = '_mouse_';\n } else if (oldVal === 'edge') {\n block[last] = '_edge_';\n } else if (block[block.length - 1] instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"StageData\"]) {\n block[last] = '_stage_';\n }\n return block;\n};\nvar sb1SpecMap = {\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L197-L199\n 'getParam': function getParam(_ref) {\n var _ref2 = _slicedToArray(_ref, 4),\n a = _ref2[0],\n b = _ref2[1],\n c = _ref2[2],\n d = _ref2[3];\n return [a, b, c, d || 'r'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L200-L212\n 'changeVariable': function changeVariable(block) {\n return [block[2], block[1], block[3]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L213-L219\n 'EventHatMorph': function EventHatMorph(block) {\n if (String(block[1]) === 'Scratch-StartClicked') {\n return ['whenGreenFlag'];\n }\n return ['whenIReceive', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L220-L222\n 'MouseClickEventHatMorph': function MouseClickEventHatMorph() {\n return ['whenClicked'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L223-L226\n 'KeyEventHatMorph': function KeyEventHatMorph(block) {\n return ['whenKeyPressed', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L227-L235\n 'stopScripts': function stopScripts(block) {\n if (String(block[1]) === 'other scripts') {\n return [block[0], 'other scripts in sprite'];\n }\n return block;\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L249-L253\n 'abs': function abs(block) {\n return ['computeFunction:of:', 'abs', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L254-L258\n 'sqrt': function sqrt(block) {\n return ['computeFunction:of:', 'sqrt', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L137\n '\\\\\\\\': function _(block) {\n return ['%'].concat(_toConsumableArray(block.slice(1)));\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L259-L262\n 'doReturn': function doReturn() {\n return ['stopScripts', 'this script'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L263-L266\n 'stopAll': function stopAll() {\n return ['stopScripts', 'all'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L267-L270\n 'showBackground:': function showBackground(block) {\n return ['startScene', block[1]];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L271-L273\n 'nextBackground': function nextBackground() {\n return ['nextScene'];\n },\n // https://github.com/LLK/scratch-flash/blob/cb5f42f039ef633710faf9c63b69e8368b280372/src/blocks/BlockIO.as#L274-L282\n 'doForeverIf': function doForeverIf(block) {\n return ['doForever', [['doIf', block[1], block[2]]]];\n },\n 'getAttribute:of:': fixMouseEdgeRef,\n 'gotoSpriteOrMouse:': fixMouseEdgeRef,\n 'distanceTo:': fixMouseEdgeRef,\n 'pointTowards:': fixMouseEdgeRef,\n 'touching:': fixMouseEdgeRef\n};\nvar valueOf = function valueOf(obj) {\n if (_typeof(obj) === 'object' && obj) return obj.valueOf();\n return obj;\n};\nvar toSb2Json = function toSb2Json(root) {\n var info = root.info,\n stageData = root.stageData,\n images = root.images,\n sounds = root.sounds;\n var pairs = function pairs(array) {\n var _pairs = [];\n for (var i = 0; i < array.length; i += 2) {\n _pairs.push([array[i], array[i + 1]]);\n }\n return _pairs;\n };\n var toSb2JsonVariable = function toSb2JsonVariable(_ref3) {\n var _ref4 = _slicedToArray(_ref3, 2),\n name = _ref4[0],\n value = _ref4[1];\n return {\n name: name,\n value: value,\n isPersistent: false\n };\n };\n var toSb2JsonList = function toSb2JsonList(_ref5) {\n var _ref6 = _slicedToArray(_ref5, 2),\n _ref6$ = _ref6[1],\n listName = _ref6$.listName,\n contents = _ref6$.contents,\n x = _ref6$.x,\n y = _ref6$.y,\n width = _ref6$.width,\n height = _ref6$.height,\n hiddenWhenNull = _ref6$.hiddenWhenNull;\n return {\n listName: listName,\n contents: contents,\n isPersistent: false,\n x: x,\n y: y,\n width: width,\n height: height,\n visible: valueOf(hiddenWhenNull) !== null\n };\n };\n\n // TODO: Implement toSb2JsonWatcher\n // const toSb2JsonWatcher = watcher => {\n //\n // };\n\n // TODO: Implement toSb2JsonListWatcher\n // const toSb2JsonListWatcher = listWatcher => {\n //\n // };\n\n var toSb2JsonSound = function toSb2JsonSound(soundMediaData) {\n var soundID = sounds.findIndex(function (sound) {\n return sound.crc === soundMediaData.crc;\n });\n return {\n soundName: soundMediaData.name,\n soundID: soundID,\n md5: \"\".concat(soundMediaData.md5, \".wav\"),\n sampleCount: soundMediaData.sampleCount,\n rate: soundMediaData.rate,\n format: ''\n };\n };\n var toSb2ImageExtension = function toSb2ImageExtension(imageMedia) {\n if (imageMedia.extension === 'uncompressed') {\n return 'png';\n }\n return 'jpg';\n };\n var toSb2JsonCostume = function toSb2JsonCostume(imageMediaData) {\n var baseLayerID = images.findIndex(function (image) {\n return image.crc === imageMediaData.crc;\n });\n return {\n costumeName: imageMediaData.costumeName,\n baseLayerID: baseLayerID,\n baseLayerMD5: \"\".concat(js_md5__WEBPACK_IMPORTED_MODULE_1___default()(imageMediaData.rawBytes), \".\").concat(toSb2ImageExtension(imageMediaData)),\n bitmapResolution: 1,\n rotationCenterX: imageMediaData.rotationCenter.x,\n rotationCenterY: imageMediaData.rotationCenter.y\n };\n };\n var toSb2JsonBlock = function toSb2JsonBlock(blockData) {\n var output = blockData.map(toSb2JsonBlockArg);\n var spec = sb1SpecMap[output[0]];\n if (spec) {\n output = spec(output);\n }\n return output;\n };\n var toSb2JsonStack = function toSb2JsonStack(stackData) {\n return stackData.map(toSb2JsonBlock);\n };\n var toSb2JsonBlockArg = function toSb2JsonBlockArg(argData) {\n if (argData instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SpriteData\"]) {\n return argData.objName;\n } else if (Array.isArray(argData)) {\n if (argData.length === 0 || Array.isArray(argData[0])) {\n return toSb2JsonStack(argData);\n }\n return toSb2JsonBlock(argData);\n }\n return argData;\n };\n var toSb2JsonScript = function toSb2JsonScript(scriptData) {\n return [scriptData[0].x, scriptData[0].y, toSb2JsonStack(scriptData[1])];\n };\n var toSb2JsonSprite = function toSb2JsonSprite(spriteData) {\n var rawCostumes = spriteData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"ImageMediaData\"];\n });\n var rawSounds = spriteData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SoundMediaData\"];\n });\n return {\n objName: spriteData.objName,\n variables: pairs(spriteData.vars).map(toSb2JsonVariable),\n lists: pairs(spriteData.lists).map(toSb2JsonList),\n scripts: spriteData.blocksBin.map(toSb2JsonScript),\n costumes: rawCostumes.map(toSb2JsonCostume),\n currentCostumeIndex: rawCostumes.findIndex(function (image) {\n return image.crc === spriteData.currentCostume.crc;\n }),\n sounds: rawSounds.map(toSb2JsonSound),\n scratchX: spriteData.scratchX,\n scratchY: spriteData.scratchY,\n scale: spriteData.scalePoint.x,\n direction: Math.round(spriteData.rotationDegrees * 1e6) / 1e6 - 270,\n rotationStyle: spriteData.rotationStyle,\n isDraggable: spriteData.draggable,\n indexInLibrary: stageData.spriteOrderInLibrary ? stageData.spriteOrderInLibrary.indexOf(spriteData) : -1,\n visible: spriteData.visible,\n spriteInfo: {}\n };\n };\n var toSb2JsonChild = function toSb2JsonChild(child) {\n if (child instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SpriteData\"]) {\n return toSb2JsonSprite(child);\n }\n return null;\n };\n var toSb2JsonStage = function toSb2JsonStage(_stageData) {\n var rawCostumes = _stageData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"ImageMediaData\"];\n });\n var rawSounds = _stageData.media.filter(function (data) {\n return data instanceof _squeak_types__WEBPACK_IMPORTED_MODULE_0__[\"SoundMediaData\"];\n });\n return {\n objName: _stageData.objName,\n variables: pairs(_stageData.vars).map(toSb2JsonVariable),\n lists: pairs(_stageData.lists).map(toSb2JsonList),\n scripts: _stageData.blocksBin.map(toSb2JsonScript),\n costumes: rawCostumes.map(toSb2JsonCostume),\n currentCostumeIndex: rawCostumes.findIndex(function (image) {\n return image.crc === _stageData.currentCostume.crc;\n }),\n sounds: rawSounds.map(toSb2JsonSound),\n // TODO: Where does this come from? Is it always the same for SB1?\n penLayerMD5: '5c81a336fab8be57adc039a8a2b33ca9.png',\n penLayerID: 0,\n tempoBPM: _stageData.tempoBPM,\n videoAlpha: 0.5,\n children: _stageData.stageContents.map(toSb2JsonChild).filter(Boolean).reverse()\n };\n };\n var toSb2JsonInfo = function toSb2JsonInfo(_info) {\n var obj = {};\n for (var i = 0; i < _info.length; i += 2) {\n if (String(_info[i]) === 'thumbnail') continue;\n obj[String(_info[i])] = String(_info[i + 1]);\n }\n return obj;\n };\n return JSON.parse(JSON.stringify(Object.assign(toSb2JsonStage(stageData), {\n info: toSb2JsonInfo(info)\n })));\n};\n\n\n//# sourceURL=webpack:///./src/to-sb2/json-generator.js?");
|
|
707
707
|
|
|
708
708
|
/***/ }),
|
|
709
709
|
|
|
@@ -190,7 +190,8 @@ const toSb2Json = root => {
|
|
|
190
190
|
direction: (Math.round(spriteData.rotationDegrees * 1e6) / 1e6) - 270,
|
|
191
191
|
rotationStyle: spriteData.rotationStyle,
|
|
192
192
|
isDraggable: spriteData.draggable,
|
|
193
|
-
indexInLibrary: stageData.spriteOrderInLibrary
|
|
193
|
+
indexInLibrary: stageData.spriteOrderInLibrary ?
|
|
194
|
+
stageData.spriteOrderInLibrary.indexOf(spriteData) : -1,
|
|
194
195
|
visible: spriteData.visible,
|
|
195
196
|
spriteInfo: {}
|
|
196
197
|
};
|