fnbr
Version:
A library to interact with Epic Games' Fortnite HTTP and XMPP services
37 lines • 1.06 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Represents a curve table used for STW power level calculations
* @private
*/
class CurveTable {
/**
* @param data The curve table's data
*/
constructor(data) {
this.keys = [];
for (const value of data) {
this.keys.push([value.KeyTime, value.KeyValue]);
}
}
/**
* Read a value from the curve table
* @param key The key
*/
eval(key) {
if (key < this.keys[0][0]) {
return this.keys[0][1];
}
if (key >= this.keys[this.keys.length - 1][0]) {
return this.keys[this.keys.length - 1][1];
}
const index = this.keys.findIndex((k) => k[0] > key);
const prev = this.keys[index - 1];
const next = this.keys[index];
const fac = (key - prev[0]) / (next[0] - prev[0]);
const final = prev[1] * (1 - fac) + next[1] * fac;
return final;
}
}
exports.default = CurveTable;
//# sourceMappingURL=CurveTable.js.map