-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfpsManager.js
68 lines (57 loc) · 1.73 KB
/
fpsManager.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
/* eslint-disable global-require */
"use strict";
/*
* Fps Manager loader. Managing units start and prerequisites
* Author: SaltyMonkey
* Contributors:
*/
/**
* Dependencies
* @typedef {Object} deps
* @property {import('./lib/unitProto')} proto
* @property {import('./lib/unitState')} data
* @property {import('./lib/unitTracker')} tracker
* @property {import('./lib/unitFps')} fps
* @property {import('./lib/management/cmd')} cmd
* @property {*} mod
*/
const msg = {
"proxyWarning": "Proxy runtime detected. Proper work not guaranteed.",
"runtimeWarning": "Outdated runtime detected. Proper work not guaranteed.",
"runtimeOld": "Runtime is so old."
};
const units = [
["log", require("./lib/unitLog")],
["proto", require("./lib/unitProto")],
["data", require("./lib/unitState")],
["tracker", require("./lib/unitTracker")],
["fps", require("./lib/unitFps")],
["cmd", require("./lib/management/cmd")]
];
class FpsManager {
constructor(mod) {
/**
* @type {deps}
*/
let deps = { "mod": mod };
//check compatibility (only warning atm)
if (mod.isProxyCompat)
mod.error(msg.proxyWarning);
// eslint-disable-next-line node/no-missing-require
else if (!require("tera-data-parser").types)
mod.error(msg.runtimeOld);
mod.game.initialize("me");
mod.game.initialize("party");
units.forEach(unit => {
// eslint-disable-next-line no-magic-numbers
deps[unit[0]] = new unit[1](deps);
});
//just in case units will need custom destructors, register them
this.destructor = () => {
Object.keys(deps).forEach(key => {
if (key !== "mod" && typeof deps[key].destructor === "function") { deps[key].destructor(); }
});
};
}
}
module.exports = FpsManager;