mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-25 10:42:51 +02:00
4d230c3121
* REFACTOR: Rewrite infiltration to pull state out of React Upcoming projects (auto-infil, the possibility of making infil a work task, etc.) require infiltration state to transition with predictable timing and be under our control, instead of inside React. This refactor accomplishes this by pulling the state out into accompanying model classes. After this, infiltration can theoretically run headless (without UI), although it doesn't actually, and you would quickly be hospitalized due to failing all the minigames. There should be no user-visible changes, aside from the progress-bars scrolling much more smoothly. * Fix console warning in InfiltrationRoot It turns out true isn't actually a safe value to use in JSX, only false works. * Fix up some comments
29 lines
935 B
TypeScript
29 lines
935 B
TypeScript
interface DifficultySettings<T> {
|
|
Trivial: T;
|
|
Normal: T;
|
|
Hard: T;
|
|
Brutal: T;
|
|
}
|
|
|
|
// interpolates between 2 numbers.
|
|
function lerp(x: number, y: number, t: number): number {
|
|
return (1 - t) * x + t * y;
|
|
}
|
|
|
|
// interpolates between 2 difficulties.
|
|
function lerpD<T extends Record<string, number>>(a: T, b: T, t: number): T {
|
|
const out: Record<string, number> = {};
|
|
for (const key of Object.keys(a)) {
|
|
out[key] = lerp(a[key], b[key], t);
|
|
}
|
|
return out as T;
|
|
}
|
|
|
|
export function interpolate<T extends Record<string, number>>(settings: DifficultySettings<T>, n: number): T {
|
|
if (n < 0) return lerpD(settings.Trivial, settings.Trivial, 0);
|
|
if (n >= 0 && n < 1) return lerpD(settings.Trivial, settings.Normal, n);
|
|
if (n >= 1 && n < 2) return lerpD(settings.Normal, settings.Hard, n - 1);
|
|
if (n >= 2 && n < 3) return lerpD(settings.Hard, settings.Brutal, n - 2);
|
|
return lerpD(settings.Brutal, settings.Brutal, 0);
|
|
}
|