forked from KirkMcDonald/kirkmcdonald.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fragment.js
163 lines (160 loc) · 5.15 KB
/
fragment.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
"use strict"
function formatSettings() {
var settings = ""
if (currentTab != DEFAULT_TAB) {
settings += "tab=" + currentTab.slice(0, currentTab.indexOf("_")) + "&"
}
if (showDebug != DEFAULT_DEBUG) {
settings += "debug=on&"
}
var mod = currentMod()
if (mod != DEFAULT_MODIFICATION) {
settings += "data=" + mod + "&"
}
if (colorScheme.name != DEFAULT_COLOR_SCHEME) {
settings += "c=" + colorScheme.name + "&"
}
if (rateName != DEFAULT_RATE) {
settings += "rate=" + rateName + "&"
}
if (ratePrecision != DEFAULT_RATE_PRECISION) {
settings += "rp=" + ratePrecision + "&"
}
if (countPrecision != DEFAULT_COUNT_PRECISION) {
settings += "cp=" + countPrecision + "&"
}
if (minimumAssembler != DEFAULT_MINIMUM) {
settings += "min=" + minimumAssembler + "&"
}
if (spec.furnace.name != DEFAULT_FURNACE) {
settings += "furnace=" + spec.furnace.name + "&"
}
if (preferredFuel.name != DEFAULT_FUEL) {
settings += "fuel=" + preferredFuel.name + "&"
}
if (oilGroup != DEFAULT_OIL) {
settings += "p=" + oilGroup + "&"
}
if (kovarexEnabled != DEFAULT_KOVAREX) {
settings += "k=off&"
}
if (preferredBelt != DEFAULT_BELT) {
settings += "belt=" + preferredBelt + "&"
}
if (!minPipeLength.equal(DEFAULT_PIPE)) {
settings += "pipe=" + minPipeLength.toDecimal(0) + "&"
}
if (!spec.miningProd.isZero()) {
var hundred = RationalFromFloat(100)
var mprod = spec.miningProd.mul(hundred).toString()
settings += "mprod=" + mprod + "&"
}
if (spec.defaultModule) {
settings += "dm=" + spec.defaultModule.shortName() + "&"
}
if (spec.defaultBeacon) {
settings += "db=" + spec.defaultBeacon.shortName() + "&"
}
if (!spec.defaultBeaconCount.isZero()) {
settings += "dbc=" + spec.defaultBeaconCount.toDecimal(0) + "&"
}
if (displayFormat != DEFAULT_FORMAT) {
settings += "vf=" + displayFormat[0] + "&"
}
if (tooltipsEnabled != DEFAULT_TOOLTIP) {
settings += "t=off&"
}
settings += "items="
var targetStrings = []
for (var i = 0; i < build_targets.length; i++) {
var target = build_targets[i]
var targetString = ""
if (target.changedFactory) {
targetString = sprintf("%s:f:%s", target.itemName, target.factories.value)
if (target.recipeIndex != 0) {
targetString += ";" + target.recipeIndex
}
} else {
targetString = sprintf("%s:r:%s", target.itemName, target.rateValue.mul(displayRateFactor).toString())
}
targetStrings.push(targetString)
}
settings += targetStrings.join(",")
var ignore = []
for (var recipeName in spec.ignore) {
if (recipeName in globalTotals.totals) {
ignore.push(recipeName)
}
}
if (ignore.length > 0) {
settings += "&ignore=" + ignore.join(",")
}
var specs = []
for (var recipeName in spec.spec) {
if (!(recipeName in globalTotals.totals)) {
continue
}
var factory = spec.spec[recipeName]
var modules = []
var beacon = ""
var any = false
for (var i=0; i < factory.modules.length; i++) {
var module = factory.modules[i]
if (module !== spec.defaultModule) {
var moduleName
if (module) {
moduleName = module.shortName()
} else {
moduleName = "null"
}
modules.push(moduleName)
any = true
}
}
if (factory.beaconModule !== spec.defaultBeacon || !factory.beaconCount.equal(spec.defaultBeaconCount)) {
var beaconModule = factory.beaconModule
var moduleName
if (beaconModule) {
moduleName = beaconModule.shortName()
} else {
moduleName = "null"
}
beacon = sprintf("%s:%d", moduleName, factory.beaconCount.toFloat())
any = true
}
if (any) {
var recipeSpec = sprintf("%s:%s", recipeName, modules.join(":"))
if (beacon != "") {
recipeSpec += ";" + beacon
}
specs.push(recipeSpec)
}
}
if (specs.length > 0) {
settings += "&modules=" + specs.join(",")
}
var zip = "zip=" + window.btoa(pako.deflateRaw(settings, {to: "string"}))
if (zip.length < settings.length) {
return zip
}
return settings
}
function loadSettings(fragment) {
var settings = {}
fragment = fragment.substr(1)
var pairs = fragment.split("&")
for (var i=0; i < pairs.length; i++) {
var j = pairs[i].indexOf("=")
if (j == -1) {
continue
}
var name = pairs[i].substr(0, j)
var value = pairs[i].substr(j + 1)
settings[name] = value
}
if ("zip" in settings) {
var unzip = pako.inflateRaw(window.atob(settings.zip), {to: "string"})
return loadSettings("#" + unzip)
}
return settings
}