-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.jsx
121 lines (110 loc) · 3.2 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import React from 'react';
import ReactDOM from 'react-dom';
import Credits from "./components/Credits/Credits";
import Help from "./components/help/help";
import Tip from "./components/Tip/Tip";
import validate from "./helpers/validate";
import Intro from "./components/Intro/Intro";
import SpritePreview from "./components/SpritePreview/SpritePreview";
import Range from "./components/Range/Range";
import AssetInfo from "./components/AssetInfo/AssetInfo";
import DownloadSpriteButton from "./components/DownloadSpriteButton/DownloadSpriteButton";
import Background from "./components/Background/Background";
import BackButton from "./components/BackButton/BackButton";
var App = React.createClass ({
getInitialState: function() {
return {
dragging: false,
files: [],
canvasWidth: 0,
canvasHeight: 0,
assetWidth: 0,
assetHeight: 0,
speed: 0.6
};
},
componentDidMount: function() {
document.body.addEventListener("dragenter", this.dragStart, false);
document.body.addEventListener("dragover", this.dragStart, false);
document.body.addEventListener("dragleave", this.dragEnd, false);
document.body.addEventListener("dragend", this.dragEnd, false);
document.body.addEventListener("drop", this.dropped, false);
},
dragStart: function(e) {
e.stopPropagation();
e.preventDefault();
this.setState({ dragging: true });
},
dragEnd: function(e) {
e.stopPropagation();
e.preventDefault();
this.setState({ dragging: false });
},
dropped: function(e) {
e.stopPropagation();
e.preventDefault();
validate(e.dataTransfer.files,
function(dragging, files, canvasWidth, canvasHeight, assetWidth, assetHeight) {
this.setState({
dragging: dragging,
files: files,
canvasWidth: canvasWidth,
canvasHeight: canvasHeight,
assetWidth: assetWidth,
assetHeight: assetHeight
});
}.bind(this));
},
generateSprite: function(el) {
this.refs["spritePreview"].generateSprite();
},
changeSpeed: function(speed) {
this.setState({ speed: speed });
},
reset: function() {
this.setState(this.getInitialState());
},
render: function() {
if (this.state.files.length === 0) {
const style = "dropbox" + (this.state.dragging ? " dragging" : "");
return (
<div className={style}>
<div className="front">
<Credits />
<Intro />
<Help />
</div>
<Background />
</div>
);
} else {
return (
<div className="dropbox">
<BackButton onClick={() => this.reset()} />
<Tip />
<SpritePreview
ref="spritePreview"
images={this.state.files}
canvasWidth={this.state.canvasWidth}
assetWidth={this.state.assetWidth}
assetHeight={this.state.assetHeight}
speed={this.state.speed} />
<Range
min={0.1}
max={3}
step={0.1}
speed={this.state.speed}
onChange={(speed) => this.changeSpeed(speed)} />
<AssetInfo
assetWidth={this.state.assetWidth}
assetHeight={this.state.assetHeight}
canvasWidth={this.state.canvasWidth}
canvasHeight={this.state.canvasHeight} />
<DownloadSpriteButton
onClick={() => this.generateSprite()} />
</div>
);
}
}
});
ReactDOM.render(<App/>, document.querySelector("#myApp"));