forked from KirkMcDonald/kirkmcdonald.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.js
More file actions
141 lines (136 loc) · 4.38 KB
/
module.js
File metadata and controls
141 lines (136 loc) · 4.38 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*Copyright 2015-2019 Kirk McDonald
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/
"use strict"
function Module(name, col, row, category, order, productivity, speed, power, limit) {
// Other module effects not modeled by this calculator.
this.name = name
this.icon_col = col
this.icon_row = row
this.category = category
this.order = order
this.productivity = productivity
this.speed = speed
this.power = power
this.limit = {}
if (limit) {
for (var i = 0; i < limit.length; i++) {
this.limit[limit[i]] = true
}
}
}
Module.prototype = {
constructor: Module,
shortName: function() {
return this.name[0] + this.name[this.name.length - 1]
},
canUse: function(recipe) {
if (recipe.allModules()) {
return true
}
if (Object.keys(this.limit).length > 0) {
return recipe.name in this.limit
}
return true
},
canBeacon: function() {
return this.productivity.isZero()
},
hasProdEffect: function() {
return !this.productivity.isZero()
},
renderTooltip: function() {
var t = document.createElement("div")
t.classList.add("frame")
var title = document.createElement("h3")
var im = getImage(this, true)
title.appendChild(im)
title.appendChild(new Text(formatName(this.name)))
t.appendChild(title)
var b
var hundred = RationalFromFloat(100)
var first = false
if (!this.power.isZero()) {
var power = this.power.mul(hundred)
if (first) {
t.appendChild(document.createElement("br"))
} else {
first = true
}
b = document.createElement("b")
b.textContent = "Energy consumption: "
t.appendChild(b)
var sign = ""
if (!this.power.less(zero)) {
sign = "+"
}
t.appendChild(new Text(sign + power.toDecimal() + "%"))
}
if (!this.speed.isZero()) {
var speed = this.speed.mul(hundred)
if (first) {
t.appendChild(document.createElement("br"))
} else {
first = true
}
b = document.createElement("b")
b.textContent = "Speed: "
t.appendChild(b)
var sign = ""
if (!this.speed.less(zero)) {
sign = "+"
}
t.appendChild(new Text(sign + speed.toDecimal() + "%"))
}
if (!this.productivity.isZero()) {
var productivity = this.productivity.mul(hundred)
if (first) {
t.appendChild(document.createElement("br"))
} else {
first = true
}
b = document.createElement("b")
b.textContent = "Productivity: "
t.appendChild(b)
var sign = ""
if (!this.productivity.less(zero)) {
sign = "+"
}
t.appendChild(new Text(sign + productivity.toDecimal() + "%"))
}
return t
}
}
function getModules(data) {
var modules = {}
for (var i = 0; i < data.modules.length; i++) {
var name = data.modules[i]
var item = data.items[name]
var effect = item.effect
var category = item.category
var order = item.order
var speed = RationalFromFloat((effect.speed || {}).bonus || 0)
var productivity = RationalFromFloat((effect.productivity || {}).bonus || 0)
var power = RationalFromFloat((effect.consumption || {}).bonus || 0)
var limit = item.limitation
modules[name] = new Module(
name,
item.icon_col,
item.icon_row,
category,
order,
productivity,
speed,
power,
limit
)
}
return modules
}