-
Notifications
You must be signed in to change notification settings - Fork 46
/
ingredients.jsx
118 lines (106 loc) · 3.25 KB
/
ingredients.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
/* global React,App*/
App.Ingredients = class Ingredients extends React.Component {
state = {
showIngredients: false
}
toggleShowIngredients = (event) => {
event.preventDefault();
this.setState({showIngredients: !this.state.showIngredients});
}
_wholeNumberRoundUpIfAppropriate(number) {
if (this.props.alwaysShowDecimals) {
return this._twoDecimalPlaces(number);
} else {
return Math.ceil(number);
}
}
_twoDecimalPlaces(number) {
return (Math.ceil(number * 100)/100).toFixed(2);
}
remove = (event) => {
event.preventDefault();
this.props.onRemove(this.props.req.name);
}
explain = (event) => {
event.preventDefault();
this.props.onExplain(this.props.req);
}
render() {
var inputs, details;
if (this.props.req.ingredients && this.props.req.ingredients.length && (this.state.showIngredients || this.props.ingredients=="always")) {
var self = this;
inputs = (
<div className="inputs">
{this.props.req.ingredients.map(function(ingredient){
return <Ingredients key={ingredient.recipe.name} req={ingredient.recipe} ingredients="off" alwaysShowDecimals={self.props.alwaysShowDecimals}/>;
})}
</div>
);
}
if (this.props.req.assemblersRequired) {
var madeBy = "assemblers";
if (this.props.req.category == "ore") {
madeBy = "drills";
} else if (this.props.req.category == "smelting") {
madeBy = "furnaces";
} else if (this.props.req.category == "chemistry") {
madeBy = "chemplants";
}
details = [
<div key="assemblers" className="assemblers">
{ this._wholeNumberRoundUpIfAppropriate(this.props.req.assemblersRequired) } <span className="madeBy">{madeBy}</span>
</div>
];
if (this.props.req.type != "fluid")
{
details.push(
<div key="lines_required" className="lines_required">
{ this._wholeNumberRoundUpIfAppropriate(this.props.req.lines) }
</div>
);
}
} else {
details = null;
}
var explainLink;
if (this.props.onExplain) {
explainLink = (
<div className="explain">
<a href onClick={this.explain}>Explain</a>
</div>
);
} else {
explainLink = null;
}
var removeLink;
if (this.props.onRemove) {
removeLink = (
<div className="remove">
<a href onClick={this.remove}>Remove</a>
</div>
);
} else {
removeLink = null;
}
var name;
if (this.props.ingredients == "always" || this.props.ingredients == "never" || !this.props.req.ingredients || !this.props.req.ingredients.length) {
name = (<div className="name">{this.props.req.name}</div>);
} else {
name = (<div className="name"><a href style={{color: "black"}} onClick={this.toggleShowIngredients}>{this.state.showIngredients ? "-" : "+"} {this.props.req.name}</a></div>);
}
return (
<div className="req">
{ name }
<div className="data">
<div className="ips">
{this._twoDecimalPlaces(this.props.req.ips * 60)}
</div>
{details}
{explainLink}
{removeLink}
</div>
{inputs}
</div>
);
}
};