-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhelpers.js
115 lines (106 loc) · 3.33 KB
/
helpers.js
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
/**
* Created by synopia on 27.06.2014.
*/
selectRecipes = [];
$.each(recipes, function (name, recipe) {
selectRecipes.push({id: name, value: recipe.name})
});
selectRecipes.sort(function (a, b) {
return a["value"].localeCompare(b["value"])
});
var helpers = {
speedFormat : function(value) {
value = value || 0;
if( value.total ) {
value = value.total
}
return helpers.formatNumber(value, 60, 2);
},
countFormat : function(value) {
return helpers.formatNumber(value, 1, 2);
},
formatNumber : function (number, total, digits) {
total = total || 100;
digits = digits || 2;
return +(total * number).toFixed(digits).toString();
},
formatModified : function formatModified(text, mod) {
if( mod ) {
return "<"+mod+">"+text+"</"+mod+">"
} else {
return text;
}
},
renderSpeed : function( line, common ) {
return helpers.speedFormat(line.targetSpeed)
},
renderSpeedRatio : function( line, common ) {
if( line.$level==1 ) {
return helpers.renderSpeed(line, common)
} else {
return helpers.formatNumber(line.relativeSpeed, 100, 0)+"%"
}
},
renderCount : function(line, common) {
if( line.factorySpeed ) {
var count = line.targetSpeed / line.factorySpeed.total;
return helpers.countFormat(count);
} else {
return ""
}
},
renderFactory : function( line, common ) {
if( line.factory ) {
return helpers.formatModified(factories[line.factory].name, line.factoryModified ? "strong" : null)
} else {
return "";
}
},
renderInputInserters: function( line, common ) {
if( line.inputInserters ) {
return helpers.formatModified(inserters[line.inputInserters].name,line.inputInsertersModified ? "strong" : null);
} else {
return "";
}
},
renderOutputInserters: function( line, common ) {
if( line.outputInserters ) {
return helpers.formatModified(inserters[line.outputInserters].name,line.outputInsertersModified ? "strong" : null);
} else {
return "";
}
},
getName: function (item) {
if( recipes[item]!=null ) {
return recipes[item].name;
} else if( resources[item]!=null ) {
return resources[item].name;
} else {
return item
}
},
findFactories : function ( item ) {
var result = [];
var recipe = recipes[item];
var resource = resources[item];
if( recipe ) {
$.each(factories, function (name, factory) {
if (factory.categories.indexOf(recipe.category) != -1) {
if (factory.ingredientCount >= recipe.ingredients.length) {
result.push(factory);
}
}
});
} else if( resource ) {
$.each(factories, function (name, factory) {
if (factory.categories.indexOf(resource.category) != -1) {
result.push(factory);
}
});
}
result.sort(function(a,b){
return a.speed - b.speed;
});
return result;
}
};