-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflt.js
57 lines (50 loc) · 1.19 KB
/
flt.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
"use strict";
class FTL {
load(buffer) {
this.dv = new DataView(buffer);
}
getInt() {
return this.dv.getInt32((this.offset += 4) - 4, true);
}
skipString() {
this.offset = this.getInt() + this.offset;
}
reset() {
this.offset = 0;
this.version = this.getInt();
if (this.version < 2 || this.version > 11) {
throw "version error: " + this.version;
}
this.skip();
}
skip() {
[
[5 + ~~(this.version > 10) + ~~(this.version > 6), [this.getInt]],
[2, [this.skipString]],
[2, [this.getInt]],
[this.getInt, [this.skipString, this.getInt]],
[3, [this.skipString]],
[this.getInt, [this.skipString, this.skipString]],
[4, this.version > 6 ? [this.getInt] : []]
].map(e => {
for (
let i = 0, len = typeof e[0] === "number" ? e[0] : e[0].bind(this)();
i < len;
i++
) {
e[1].forEach(x => x.bind(this)());
}
});
}
getResources() {
this.reset();
return ["hull", "fuel", "drones", "missiles", "scrap"].map(e => [
e,
this.offset,
this.getInt()
]);
}
setResources(res) {
res.forEach(e => this.dv.setInt32(e[1], e[2], true));
}
}