mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-19 14:13:48 +01:00
yet another any
This commit is contained in:
parent
e9788536ed
commit
88d9a76b04
@ -4,7 +4,7 @@ import { serverMetadata } from "./data/servers";
|
|||||||
|
|
||||||
import { HacknetServer } from "../Hacknet/HacknetServer";
|
import { HacknetServer } from "../Hacknet/HacknetServer";
|
||||||
|
|
||||||
import { IMap } from "../types";
|
import { IMap, IMinMaxRange } from "../types";
|
||||||
import { createRandomIp } from "../utils/IPAddress";
|
import { createRandomIp } from "../utils/IPAddress";
|
||||||
import { getRandomInt } from "../utils/helpers/getRandomInt";
|
import { getRandomInt } from "../utils/helpers/getRandomInt";
|
||||||
import { Reviver } from "../utils/JSONReviver";
|
import { Reviver } from "../utils/JSONReviver";
|
||||||
@ -111,8 +111,6 @@ interface IServerParams {
|
|||||||
organizationName: string;
|
organizationName: string;
|
||||||
requiredHackingSkill?: number;
|
requiredHackingSkill?: number;
|
||||||
serverGrowth?: number;
|
serverGrowth?: number;
|
||||||
|
|
||||||
[key: string]: any;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initForeignServers(homeComputer: Server): void {
|
export function initForeignServers(homeComputer: Server): void {
|
||||||
@ -123,23 +121,9 @@ export function initForeignServers(homeComputer: Server): void {
|
|||||||
networkLayers.push([]);
|
networkLayers.push([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Essentially any property that is of type 'number | IMinMaxRange'
|
const toNumber = (value: number | IMinMaxRange): number => {
|
||||||
const propertiesToPatternMatch: string[] = [
|
if (typeof value === "number") return value;
|
||||||
"hackDifficulty",
|
else return getRandomInt(value.min, value.max);
|
||||||
"moneyAvailable",
|
|
||||||
"requiredHackingSkill",
|
|
||||||
"serverGrowth",
|
|
||||||
];
|
|
||||||
|
|
||||||
const toNumber = (value: any): any => {
|
|
||||||
switch (typeof value) {
|
|
||||||
case "number":
|
|
||||||
return value;
|
|
||||||
case "object":
|
|
||||||
return getRandomInt(value.min, value.max);
|
|
||||||
default:
|
|
||||||
throw Error(`Do not know how to convert the type '${typeof value}' to a number`);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const metadata of serverMetadata) {
|
for (const metadata of serverMetadata) {
|
||||||
@ -154,11 +138,10 @@ export function initForeignServers(homeComputer: Server): void {
|
|||||||
serverParams.maxRam = Math.pow(2, toNumber(metadata.maxRamExponent));
|
serverParams.maxRam = Math.pow(2, toNumber(metadata.maxRamExponent));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const prop of propertiesToPatternMatch) {
|
if (metadata.hackDifficulty) serverParams.hackDifficulty = toNumber(metadata.hackDifficulty);
|
||||||
if (metadata[prop] !== undefined) {
|
if (metadata.moneyAvailable) serverParams.moneyAvailable = toNumber(metadata.moneyAvailable);
|
||||||
serverParams[prop] = toNumber(metadata[prop]);
|
if (metadata.requiredHackingSkill) serverParams.requiredHackingSkill = toNumber(metadata.requiredHackingSkill);
|
||||||
}
|
if (metadata.serverGrowth) serverParams.serverGrowth = toNumber(metadata.serverGrowth);
|
||||||
}
|
|
||||||
|
|
||||||
const server = new Server(serverParams);
|
const server = new Server(serverParams);
|
||||||
for (const filename of metadata.literature || []) {
|
for (const filename of metadata.literature || []) {
|
||||||
|
Loading…
Reference in New Issue
Block a user