From 4ba76bbdbd0ee3e6c459919a4e823312949fb720 Mon Sep 17 00:00:00 2001 From: Ray Schamp Date: Thu, 12 Jan 2017 15:34:05 -0500 Subject: [PATCH 01/16] Fix adding SVG costumes Previously it assumed every costume to have a `bitmapResolution` property which doesn't apply to vector costumes. This caused the renderer to not render added SVG costumes when they were added with setCostume. --- src/sprites/rendered-target.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index b5b89365c..69177b9ac 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -329,13 +329,17 @@ RenderedTarget.prototype.setCostume = function (index) { ); if (this.renderer) { var costume = this.sprite.costumes[this.currentCostume]; + var rotationCenter = costume.bitmapResolution ? [ + costume.rotationCenterX / costume.bitmapResolution, + costume.rotationCenterY / costume.bitmapResolution + ] : [ + costume.rotationCenterX, + costume.rotationCenterY + ]; this.renderer.updateDrawableProperties(this.drawableID, { skin: costume.skin, costumeResolution: costume.bitmapResolution, - rotationCenter: [ - costume.rotationCenterX / costume.bitmapResolution, - costume.rotationCenterY / costume.bitmapResolution - ] + rotationCenter: rotationCenter }); if (this.visible) { this.runtime.requestRedraw(); From a56346d0a97383b05b2b3d5042715076aac3ab3b Mon Sep 17 00:00:00 2001 From: Ray Schamp Date: Fri, 13 Jan 2017 12:55:21 -0500 Subject: [PATCH 02/16] Only update costume rotationCenter if it exists This prevents sending `NaN`s to the renderer as the rotation center, which prevents the initial render of the costume/backdrop. Towards LLK/scratch-gui#18 --- src/sprites/rendered-target.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index 69177b9ac..dc7c25d2f 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -329,18 +329,21 @@ RenderedTarget.prototype.setCostume = function (index) { ); if (this.renderer) { var costume = this.sprite.costumes[this.currentCostume]; - var rotationCenter = costume.bitmapResolution ? [ - costume.rotationCenterX / costume.bitmapResolution, - costume.rotationCenterY / costume.bitmapResolution - ] : [ - costume.rotationCenterX, - costume.rotationCenterY - ]; - this.renderer.updateDrawableProperties(this.drawableID, { + var drawableProperties = { skin: costume.skin, - costumeResolution: costume.bitmapResolution, - rotationCenter: rotationCenter - }); + costumeResolution: costume.bitmapResolution + }; + if ( + typeof costume.rotationCenterX !== 'undefined' && + typeof costume.rotationCenterY !== 'undefined' + ) { + var scale = costume.bitmapResolution || 1; + drawableProperties.rotationCenter = [ + costume.rotationCenterX / scale, + costume.rotationCenterY / scale + ]; + } + this.renderer.updateDrawableProperties(this.drawableID, drawableProperties); if (this.visible) { this.runtime.requestRedraw(); } From 9b0439221105aef880435bb6107bd43846fe0028 Mon Sep 17 00:00:00 2001 From: Chris Willis-Ford Date: Fri, 13 Jan 2017 13:34:26 -0800 Subject: [PATCH 03/16] Move build outputs into a `dist/` subdirectory (#375) * Move Node output: /dist.js => /dist/node/scratch-vm.js * Move web output: /vm{.js,.min.js} => /dist/web/scratch-vm{.js,.min.js} * Update build output references in package.json and the playground's index.html * Move the VirtualMachine class out of index.js into its own file, referenced by index.js. The VirtualMachine class is otherwise unchanged. * Add .gitattributes rules for new file types which were added to this repository without specifying their text/binary attributes * Turn on source maps in webpack and add corresponding .gitignore rule --- .eslintignore | 7 +- .gitattributes | 5 + .gitignore | 13 +- package.json | 2 +- playground/index.html | 2 +- src/index.js | 338 +--------------------------------------- src/virtual-machine.js | 339 +++++++++++++++++++++++++++++++++++++++++ webpack.config.js | 23 +-- 8 files changed, 371 insertions(+), 358 deletions(-) create mode 100644 src/virtual-machine.js diff --git a/.eslintignore b/.eslintignore index 564a29d1e..8af9aff65 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,7 +1,4 @@ -build/* -dist.js +coverage/* +dist/* node_modules/* playground/* -vm.js -vm.min.js -coverage/* diff --git a/.gitattributes b/.gitattributes index 103710fec..b7671ba47 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,8 +5,10 @@ # People who (for example) rsync between Windows and Linux need this. # File types which we know are binary +*.sb2 binary # Prefer LF for most file types +*.css text eol=lf *.frag text eol=lf *.htm text eol=lf *.html text eol=lf @@ -17,13 +19,16 @@ *.md text eol=lf *.vert text eol=lf *.xml text eol=lf +*.yml text eol=lf # Prefer LF for these files .editorconfig text eol=lf +.eslintignore text eol=lf .eslintrc text eol=lf .gitattributes text eol=lf .gitignore text eol=lf .gitmodules text eol=lf +.npmignore text eol=lf LICENSE text eol=lf Makefile text eol=lf README text eol=lf diff --git a/.gitignore b/.gitignore index aad54ff5e..fdf767042 100644 --- a/.gitignore +++ b/.gitignore @@ -8,11 +8,16 @@ npm-* # Testing /.nyc_output /coverage -/dist.js -/vm.js -/vm.min.js + +# IDEA +/.idea + +# Build +/dist /playground/assets /playground/media +/playground/scratch-vm.js +/playground/scratch-vm.js.map /playground/vendor.js -/playground/vm.js +/playground/vendor.js.map /playground/zenburn.css diff --git a/package.json b/package.json index 503d6dcf3..663e19e31 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "type": "git", "url": "git+ssh://git@github.com/LLK/scratch-vm.git" }, - "main": "./dist.js", + "main": "./dist/node/scratch-vm.js", "scripts": { "build": "./node_modules/.bin/webpack --progress --colors --bail", "coverage": "./node_modules/.bin/tap ./test/{unit,integration}/*.js --coverage --coverage-report=lcov", diff --git a/playground/index.html b/playground/index.html index 4c0a454bc..370f054dd 100644 --- a/playground/index.html +++ b/playground/index.html @@ -66,7 +66,7 @@ - +