Skip to content
Merged
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
25 changes: 0 additions & 25 deletions .eslintrc

This file was deleted.

5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
env: {
node: true
}
};
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"start": "webpack-dev-server --port $npm_package_config_port --content-base=./build",
"test": "npm run lint && npm run build"
},
"eslintConfig": {
"extends": ["scratch"]
},
"author": "Massachusetts Institute of Technology",
"license": "BSD-3-Clause",
"homepage": "https://github.com/LLK/scratch-gui#readme",
Expand All @@ -31,14 +34,15 @@
},
"devDependencies": {
"babel-core": "6.14.0",
"babel-eslint": "6.1.2",
"babel-eslint": "7.0.0",
"babel-loader": "6.2.5",
"babel-plugin-transform-object-rest-spread": "6.16.0",
"babel-preset-es2015": "6.14.0",
"babel-preset-react": "6.11.1",
"copy-webpack-plugin": "3.0.1",
"eslint": "3.5.0",
"eslint-plugin-react": "6.2.1",
"eslint-config-scratch": "^1.0.0",
"eslint-plugin-react": "6.4.1",
"gh-pages": "0.11.0",
"html-webpack-plugin": "2.22.0",
"husky": "0.11.9",
Expand All @@ -50,6 +54,7 @@
"react": "15.3.2",
"react-dom": "15.3.2",
"react-modal": "1.5.2",
"react-style-proptype": "1.2.0",
"scratch-blocks": "latest",
"scratch-render": "latest",
"scratch-vm": "latest",
Expand Down
7 changes: 7 additions & 0 deletions src/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
env: {
node: false,
browser: true
},
extends: ['scratch/es6', 'scratch/react']
};
2 changes: 1 addition & 1 deletion src/components/blocks.js → src/components/blocks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class BlocksComponent extends React.Component {
} = this.props;
return (
<div
ref={componentRef}
className="scratch-blocks"
ref={componentRef}
style={{
position: 'absolute',
top: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,54 @@ class CostumeCanvas extends React.Component {
componentDidUpdate (prevProps) {
if (prevProps.url !== this.props.url) {
this.load();
} else {
if (prevProps.width !== this.props.width ||
prevProps.height !== this.props.height ||
prevProps.direction !== this.props.direction) {
this.draw();
}
} else if (
prevProps.width !== this.props.width ||
prevProps.height !== this.props.height ||
prevProps.direction !== this.props.direction
) {
this.draw();
}
}
draw () {
if (!this.refs.costumeCanvas) {
if (!this.canvas) {
return;
}

// Draw the costume to the rendered canvas.
const img = this.img;
const context = this.refs.costumeCanvas.getContext('2d');
const context = this.canvas.getContext('2d');

This comment was marked as abuse.


// Scale to fit.
let scale;

// Choose the larger dimension to scale by.
if (img.width > img.height) {
scale = this.refs.costumeCanvas.width / img.width;
scale = this.canvas.width / img.width;
} else {
scale = this.refs.costumeCanvas.height / img.height;
scale = this.canvas.height / img.height;
}

// Rotate by the Scratch-value direction.
const angle = (-90 + this.props.direction) * Math.PI / 180;

// Rotation origin point will be center of the canvas.
const contextTranslateX = this.refs.costumeCanvas.width / 2;
const contextTranslateY = this.refs.costumeCanvas.height / 2;
const contextTranslateX = this.canvas.width / 2;
const contextTranslateY = this.canvas.height / 2;

// First, clear the canvas.
context.clearRect(0, 0,
this.refs.costumeCanvas.width, this.refs.costumeCanvas.height);
this.canvas.width, this.canvas.height);

// Translate the context to the center of the canvas,
// then rotate canvas drawing by `angle`.
context.translate(contextTranslateX, contextTranslateY);
context.rotate(angle);
context.drawImage(img,
0, 0, img.width, img.height,
-(scale * img.width / 2), -(scale * img.height / 2),
-(scale * img.width / 2), -(scale * img.height / 2),
scale * img.width,
scale * img.height);

// Reset the canvas rotation and translation to 0, (0, 0).
context.rotate(-angle);
context.translate(-contextTranslateX, -contextTranslateY);
Expand All @@ -72,8 +80,8 @@ class CostumeCanvas extends React.Component {
url: url
}, (err, response, body) => {
if (!err) {
svgToImage(body, (err, img) => {
if (!err) {
svgToImage(body, (svgErr, img) => {
if (!svgErr) {

This comment was marked as abuse.

this.img = img;
this.draw();
}
Expand All @@ -84,7 +92,7 @@ class CostumeCanvas extends React.Component {

} else {
// Raster graphics: create Image and draw it.
let img = new Image();
const img = new Image();

This comment was marked as abuse.

img.src = url;
img.onload = () => {
this.img = img;
Expand All @@ -93,11 +101,13 @@ class CostumeCanvas extends React.Component {
}
}
render () {
return <canvas
ref='costumeCanvas'
width={this.props.width}
height={this.props.height}
/>;
return (
<canvas
height={this.props.height}
width={this.props.width}
ref={this._getCanvas} // eslint-disable-line react/jsx-sort-props
/>
);

This comment was marked as abuse.

}
}

Expand All @@ -108,10 +118,10 @@ CostumeCanvas.defaultProps = {
};

CostumeCanvas.propTypes = {
url: React.PropTypes.string,
width: React.PropTypes.number,
direction: React.PropTypes.number,
height: React.PropTypes.number,
direction: React.PropTypes.number
url: React.PropTypes.string,
width: React.PropTypes.number

This comment was marked as abuse.

};

module.exports = CostumeCanvas;
File renamed without changes.
File renamed without changes.
29 changes: 21 additions & 8 deletions src/components/library-item.js → src/components/library-item.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
const bindAll = require('lodash.bindall');
const React = require('react');
const stylePropType = require('react-style-proptype');

const CostumeCanvas = require('./costume-canvas');
const CostumeCanvas = require('./costume-canvas.jsx');

class LibraryItem extends React.Component {
constructor (props) {
super(props);
bindAll(this, ['handleClick']);

This comment was marked as abuse.

}
handleClick (e) {
this.props.onSelect(this.props.id);
e.preventDefault();
}
render () {
let style = (this.props.selected) ?
const style = (this.props.selected) ?
this.props.selectedGridTileStyle : this.props.gridTileStyle;
return (
<div style={style} onClick={() => this.props.onSelect(this.props.id)}>
<div
style={style}
onClick={this.handleClick}

This comment was marked as abuse.

>
<CostumeCanvas url={this.props.iconURL} />
<p>{this.props.name}</p>
</div>
Expand Down Expand Up @@ -37,13 +50,13 @@ LibraryItem.defaultProps = {
};

LibraryItem.propTypes = {
name: React.PropTypes.string,
gridTileStyle: stylePropType,

This comment was marked as abuse.

iconURL: React.PropTypes.string,
gridTileStyle: React.PropTypes.object,
selectedGridTileStyle: React.PropTypes.object,
selected: React.PropTypes.bool,
id: React.PropTypes.number,
name: React.PropTypes.string,
onSelect: React.PropTypes.func,
id: React.PropTypes.number
selected: React.PropTypes.bool,
selectedGridTileStyle: stylePropType
};

module.exports = LibraryItem;
69 changes: 0 additions & 69 deletions src/components/library.js

This file was deleted.

Loading