= {};
-function createHashUpgrade(p: IConstructorParams) {
+function createHashUpgrade(p: IConstructorParams): void {
HashUpgrades[p.name] = new HashUpgrade(p);
}
diff --git a/src/Hacknet/formulas/HacknetNodes.ts b/src/Hacknet/formulas/HacknetNodes.ts
index 717ab3aeb..176027c98 100644
--- a/src/Hacknet/formulas/HacknetNodes.ts
+++ b/src/Hacknet/formulas/HacknetNodes.ts
@@ -14,7 +14,7 @@ export function calculateMoneyGainRate(level: number, ram: number, cores: number
BitNodeMultipliers.HacknetNodeMoney;
}
-export function calculateLevelUpgradeCost(startingLevel: number, extraLevels: number=1, costMult: number=1): number {
+export function calculateLevelUpgradeCost(startingLevel: number, extraLevels=1, costMult=1): number {
const sanitizedLevels = Math.round(extraLevels);
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
return 0;
@@ -35,7 +35,7 @@ export function calculateLevelUpgradeCost(startingLevel: number, extraLevels: nu
return HacknetNodeConstants.BaseCost / 2 * totalMultiplier * costMult;
}
-export function calculateRamUpgradeCost(startingRam: number, extraLevels: number=1, costMult: number=1): number {
+export function calculateRamUpgradeCost(startingRam: number, extraLevels=1, costMult=1): number {
const sanitizedLevels = Math.round(extraLevels);
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
return 0;
@@ -64,7 +64,7 @@ export function calculateRamUpgradeCost(startingRam: number, extraLevels: number
return totalCost;
}
-export function calculateCoreUpgradeCost(startingCore: number, extraLevels: number=1, costMult: number=1): number {
+export function calculateCoreUpgradeCost(startingCore: number, extraLevels=1, costMult=1): number {
const sanitizedCores = Math.round(extraLevels);
if (isNaN(sanitizedCores) || sanitizedCores < 1) {
return 0;
@@ -88,7 +88,7 @@ export function calculateCoreUpgradeCost(startingCore: number, extraLevels: numb
return totalCost;
}
-export function calculateNodeCost(n: number, mult: number=1): number {
+export function calculateNodeCost(n: number, mult=1): number {
if(n <= 0) {
return 0;
}
diff --git a/src/Hacknet/formulas/HacknetServers.ts b/src/Hacknet/formulas/HacknetServers.ts
index ef73b12b2..8908da045 100644
--- a/src/Hacknet/formulas/HacknetServers.ts
+++ b/src/Hacknet/formulas/HacknetServers.ts
@@ -15,7 +15,7 @@ export function calculateHashGainRate(level: number, ramUsed: number, maxRam: nu
BitNodeMultipliers.HacknetNodeMoney;
}
-export function calculateLevelUpgradeCost(startingLevel: number, extraLevels: number=1, costMult: number=1): number {
+export function calculateLevelUpgradeCost(startingLevel: number, extraLevels=1, costMult=1): number {
const sanitizedLevels = Math.round(extraLevels);
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
return 0;
@@ -36,7 +36,7 @@ export function calculateLevelUpgradeCost(startingLevel: number, extraLevels: nu
return 10 * HacknetServerConstants.BaseCost * totalMultiplier * costMult;
}
-export function calculateRamUpgradeCost(startingRam: number, extraLevels: number=1, costMult: number=1): number {
+export function calculateRamUpgradeCost(startingRam: number, extraLevels=1, costMult=1): number {
const sanitizedLevels = Math.round(extraLevels);
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
return 0;
@@ -50,8 +50,8 @@ export function calculateRamUpgradeCost(startingRam: number, extraLevels: number
let numUpgrades = Math.round(Math.log2(startingRam));
let currentRam = startingRam;
for (let i = 0; i < sanitizedLevels; ++i) {
- let baseCost = currentRam * HacknetServerConstants.RamBaseCost;
- let mult = Math.pow(HacknetServerConstants.UpgradeRamMult, numUpgrades);
+ const baseCost = currentRam * HacknetServerConstants.RamBaseCost;
+ const mult = Math.pow(HacknetServerConstants.UpgradeRamMult, numUpgrades);
totalCost += (baseCost * mult);
@@ -63,7 +63,7 @@ export function calculateRamUpgradeCost(startingRam: number, extraLevels: number
return totalCost;
}
-export function calculateCoreUpgradeCost(startingCores: number, extraLevels: number=1, costMult: number=1): number {
+export function calculateCoreUpgradeCost(startingCores: number, extraLevels=1, costMult=1): number {
const sanitizedLevels = Math.round(extraLevels);
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
return 0;
@@ -86,7 +86,7 @@ export function calculateCoreUpgradeCost(startingCores: number, extraLevels: num
return totalCost;
}
-export function calculateCacheUpgradeCost(startingCache: number, extraLevels: number=1): number {
+export function calculateCacheUpgradeCost(startingCache: number, extraLevels=1): number {
const sanitizedLevels = Math.round(extraLevels);
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
return 0;
@@ -108,7 +108,7 @@ export function calculateCacheUpgradeCost(startingCache: number, extraLevels: nu
return totalCost;
}
-export function calculateServerCost(n: number, mult: number=1): number {
+export function calculateServerCost(n: number, mult=1): number {
if (n-1 >= HacknetServerConstants.MaxServers) { return Infinity; }
return HacknetServerConstants.BaseCost * Math.pow(HacknetServerConstants.PurchaseMult, n-1) * mult;
diff --git a/src/Hacknet/ui/HacknetNode.jsx b/src/Hacknet/ui/HacknetNode.jsx
index 579a5a198..d2321e061 100644
--- a/src/Hacknet/ui/HacknetNode.jsx
+++ b/src/Hacknet/ui/HacknetNode.jsx
@@ -16,7 +16,6 @@ import {
import { Player } from "../../Player";
-import { numeralWrapper } from "../../ui/numeralFormat";
import { Money } from "../../ui/React/Money";
import { MoneyRate } from "../../ui/React/MoneyRate";
diff --git a/src/Hacknet/ui/HacknetServer.jsx b/src/Hacknet/ui/HacknetServer.jsx
index 076b17180..2fd02328a 100644
--- a/src/Hacknet/ui/HacknetServer.jsx
+++ b/src/Hacknet/ui/HacknetServer.jsx
@@ -19,7 +19,6 @@ import {
import { Player } from "../../Player";
-import { numeralWrapper } from "../../ui/numeralFormat";
import { Money } from "../../ui/React/Money";
import { Hashes } from "../../ui/React/Hashes";
import { HashRate } from "../../ui/React/HashRate";
diff --git a/src/Hacknet/ui/HashUpgradePopup.jsx b/src/Hacknet/ui/HashUpgradePopup.jsx
index 7c79b7e3a..3722941bb 100644
--- a/src/Hacknet/ui/HashUpgradePopup.jsx
+++ b/src/Hacknet/ui/HashUpgradePopup.jsx
@@ -8,12 +8,9 @@ import { HashManager } from "../HashManager";
import { HashUpgrades } from "../HashUpgrades";
import { Player } from "../../Player";
-import { AllServers } from "../../Server/AllServers";
-import { Server } from "../../Server/Server";
import { numeralWrapper } from "../../ui/numeralFormat";
-import { removePopup } from "../../ui/React/createPopup";
import { PopupCloseButton } from "../../ui/React/PopupCloseButton";
import { ServerDropdown,
ServerType } from "../../ui/React/ServerDropdown"
@@ -36,7 +33,7 @@ class HashUpgrade extends React.Component {
changeTargetServer(e) {
this.setState({
- selectedServer: e.target.value
+ selectedServer: e.target.value,
});
}
diff --git a/src/Hacknet/ui/PlayerInfo.jsx b/src/Hacknet/ui/PlayerInfo.jsx
index 10ca42e3e..0db2cc528 100644
--- a/src/Hacknet/ui/PlayerInfo.jsx
+++ b/src/Hacknet/ui/PlayerInfo.jsx
@@ -8,7 +8,6 @@ import React from "react";
import { hasHacknetServers } from "../HacknetHelpers";
import { Player } from "../../Player";
-import { numeralWrapper } from "../../ui/numeralFormat";
import { Money } from "../../ui/React/Money";
import { MoneyRate } from "../../ui/React/MoneyRate";
import { HashRate } from "../../ui/React/HashRate";
diff --git a/src/Hacknet/ui/PurchaseButton.jsx b/src/Hacknet/ui/PurchaseButton.jsx
index 96831fcb4..363e4e0ba 100644
--- a/src/Hacknet/ui/PurchaseButton.jsx
+++ b/src/Hacknet/ui/PurchaseButton.jsx
@@ -6,7 +6,6 @@ import React from "react";
import { hasHacknetServers,
hasMaxNumberHacknetServers } from "../HacknetHelpers";
import { Player } from "../../Player";
-import { numeralWrapper } from "../../ui/numeralFormat";
import { Money } from "../../ui/React/Money";
export function PurchaseButton(props) {
diff --git a/src/Hacknet/ui/Root.jsx b/src/Hacknet/ui/Root.jsx
index 886ddae19..4f77bbb07 100644
--- a/src/Hacknet/ui/Root.jsx
+++ b/src/Hacknet/ui/Root.jsx
@@ -20,7 +20,6 @@ import { Player } from "../../Player";
import { AllServers } from "../../Server/AllServers";
import { createPopup } from "../../ui/React/createPopup";
-import { PopupCloseButton } from "../../ui/React/PopupCloseButton";
export const PurchaseMultipliers = Object.freeze({
"x1": 1,
diff --git a/src/Infiltration.js b/src/Infiltration.js
index f6bc21ce7..2ac800e29 100644
--- a/src/Infiltration.js
+++ b/src/Infiltration.js
@@ -490,7 +490,6 @@ function updateInfiltrationLevelText(inst) {
BitNodeMultipliers.InfiltrationMoney;
}
- var expMultiplier = 2 * inst.clearanceLevel / inst.maxClearanceLevel;
// TODO: fix this to not rely on and whitespace for formatting...
/* eslint-disable no-irregular-whitespace */
document.getElementById("infiltration-level-text").innerHTML =
diff --git a/src/InteractiveTutorial.js b/src/InteractiveTutorial.js
index 064bcefd0..a8e93b71f 100644
--- a/src/InteractiveTutorial.js
+++ b/src/InteractiveTutorial.js
@@ -42,7 +42,7 @@ const orderedITutorialSteps = [
"HacknetNodesGoToWorldPage",
"WorldDescription",
"TutorialPageInfo",
- "End"
+ "End",
]
// Create an 'enum' for the Steps
@@ -500,13 +500,13 @@ function iTutorialEnd() {
"Getting Started Guide " +
"Documentation " +
"The Beginner's Guide to Hacking was added to your home computer! It contains some tips/pointers for starting out with the game. " +
- "To read it, go to Terminal and enter cat " + LiteratureNames.HackersStartingHandbook
+ "To read it, go to Terminal and enter cat " + LiteratureNames.HackersStartingHandbook,
});
var gotitBtn = createElement("a", {
class:"a-link-button", float:"right", padding:"6px", innerText:"Got it!",
clickListener:()=>{
removeElementById(popupId);
- }
+ },
});
createPopup(popupId, [txt, gotitBtn]);
diff --git a/src/JSInterpreter.js b/src/JSInterpreter.js
index 145423c44..179ca0b74 100644
--- a/src/JSInterpreter.js
+++ b/src/JSInterpreter.js
@@ -85,7 +85,7 @@ var Interpreter = function(code, opt_initFunc, lineOffset=0) {
*/
Interpreter.PARSE_OPTIONS = {
ecmaVersion: 5,
- locations: true
+ locations: true,
};
/**
@@ -94,7 +94,7 @@ Interpreter.PARSE_OPTIONS = {
Interpreter.READONLY_DESCRIPTOR = {
configurable: true,
enumerable: true,
- writable: false
+ writable: false,
};
/**
@@ -103,7 +103,7 @@ Interpreter.READONLY_DESCRIPTOR = {
Interpreter.NONENUMERABLE_DESCRIPTOR = {
configurable: true,
enumerable: false,
- writable: true
+ writable: true,
};
/**
@@ -112,7 +112,7 @@ Interpreter.NONENUMERABLE_DESCRIPTOR = {
Interpreter.READONLY_NONENUMERABLE_DESCRIPTOR = {
configurable: true,
enumerable: false,
- writable: false
+ writable: false,
};
/**
@@ -121,7 +121,7 @@ Interpreter.READONLY_NONENUMERABLE_DESCRIPTOR = {
Interpreter.VARIABLE_DESCRIPTOR = {
configurable: false,
enumerable: true,
- writable: true
+ writable: true,
};
/**
@@ -312,7 +312,7 @@ Interpreter.prototype.initGlobalScope = function(scope) {
var strFunctions = [
[escape, 'escape'], [unescape, 'unescape'],
[decodeURI, 'decodeURI'], [decodeURIComponent, 'decodeURIComponent'],
- [encodeURI, 'encodeURI'], [encodeURIComponent, 'encodeURIComponent']
+ [encodeURI, 'encodeURI'], [encodeURIComponent, 'encodeURIComponent'],
];
for (var i = 0; i < strFunctions.length; i++) {
var wrapper = (function(nativeFunc) {
@@ -1985,8 +1985,8 @@ Interpreter.prototype.nativeToPseudo = function(nativeObj) {
Array.prototype.slice.call(arguments)
.map(function(i) {
return interpreter.pseudoToNative(i);
- })
- )
+ }),
+ ),
);
};
return this.createNativeFunction(wrapper, undefined);
@@ -2033,7 +2033,7 @@ Interpreter.prototype.pseudoToNative = function(pseudoObj, opt_cycles) {
var cycles = opt_cycles || {
pseudo: [],
- native: []
+ native: [],
};
var i = cycles.pseudo.indexOf(pseudoObj);
if (i !== -1) {
@@ -2610,7 +2610,7 @@ Interpreter.prototype.setValue = function(ref, value) {
BREAK: 1,
CONTINUE: 2,
RETURN: 3,
- THROW: 4
+ THROW: 4,
};
/**
@@ -2691,7 +2691,7 @@ Interpreter.prototype.unwind = function(type, value, label, lineNumberMsg="") {
'ReferenceError': ReferenceError,
'SyntaxError': SyntaxError,
'TypeError': TypeError,
- 'URIError': URIError
+ 'URIError': URIError,
};
var name = this.getProperty(value, 'name').toString();
var message = this.getProperty(value, 'message').valueOf();
@@ -3485,7 +3485,7 @@ Interpreter.prototype['stepObjectExpression'] = function(stack, state, node) {
configurable: true,
enumerable: true,
get: kinds['get'],
- set: kinds['set']
+ set: kinds['set'],
};
this.setProperty(state.object_, key, null, descriptor);
} else {
diff --git a/src/Locations/City.ts b/src/Locations/City.ts
index 374b70f09..ed02e1933 100644
--- a/src/Locations/City.ts
+++ b/src/Locations/City.ts
@@ -20,7 +20,7 @@ export class City {
*/
asciiArt: string;
- constructor(name: CityName, locations: LocationName[]=[], asciiArt: string='') {
+ constructor(name: CityName, locations: LocationName[]=[], asciiArt='') {
this.name = name;
this.locations = locations;
this.asciiArt = asciiArt;
diff --git a/src/Locations/Location.ts b/src/Locations/Location.ts
index 7c67efc85..f3c421870 100644
--- a/src/Locations/Location.ts
+++ b/src/Locations/Location.ts
@@ -33,12 +33,12 @@ export class Location {
/**
* Cost multiplier that influences how expensive a gym/university is
*/
- costMult: number = 0;
+ costMult = 0;
/**
* Exp multiplier that influences how effective a gym/university is
*/
- expMult: number = 0;
+ expMult = 0;
/**
* Companies can be infiltrated. This contains the data required for that
@@ -61,13 +61,13 @@ export class Location {
* Tech vendors allow you to purchase servers.
* This property defines the max RAM server you can purchase from this vendor
*/
- techVendorMaxRam: number = 0;
+ techVendorMaxRam = 0;
/**
* Tech vendors allow you to purchase servers.
* This property defines the max RAM server you can purchase from this vendor
*/
- techVendorMinRam: number = 0;
+ techVendorMinRam = 0;
constructor(p: IConstructorParams) {
if (p.city) { this.city = p.city; }
diff --git a/src/Locations/LocationsHelpers.tsx b/src/Locations/LocationsHelpers.tsx
index 83465a600..217a8d0f0 100644
--- a/src/Locations/LocationsHelpers.tsx
+++ b/src/Locations/LocationsHelpers.tsx
@@ -15,7 +15,7 @@ import { safetlyCreateUniqueServer } from "../Server/ServerHelpers";
import {
getPurchaseServerCost,
purchaseRamForHomeComputer,
- purchaseServer
+ purchaseServer,
} from "../Server/ServerPurchases";
import { SpecialServerIps } from "../Server/SpecialServerIps";
import { Settings } from "../Settings/Settings";
@@ -32,7 +32,7 @@ import {
yesNoTxtInpBoxGetYesButton,
yesNoTxtInpBoxGetNoButton,
yesNoTxtInpBoxClose,
- yesNoTxtInpBoxCreate
+ yesNoTxtInpBoxCreate,
} from "../../utils/YesNoBox";
import { createElement } from "../../utils/uiHelpers/createElement";
@@ -94,8 +94,8 @@ export function createPurchaseServerPopup(ram: number, p: IPlayer): void {
return;
}
- var yesBtn = yesNoTxtInpBoxGetYesButton();
- var noBtn = yesNoTxtInpBoxGetNoButton();
+ const yesBtn = yesNoTxtInpBoxGetYesButton();
+ const noBtn = yesNoTxtInpBoxGetNoButton();
if (yesBtn == null || noBtn == null) { return; }
yesBtn.innerHTML = "Purchase Server";
noBtn.innerHTML = "Cancel";
@@ -116,7 +116,7 @@ export function createPurchaseServerPopup(ram: number, p: IPlayer): void {
* Create a popup that lets the player start a Corporation
* @param {IPlayer} p - Player object
*/
-export function createStartCorporationPopup(p: IPlayer) {
+export function createStartCorporationPopup(p: IPlayer): void {
if (!p.canAccessCorporation() || p.hasCorporation()) { return; }
const popupId = "create-corporation-popup";
@@ -158,7 +158,7 @@ export function createStartCorporationPopup(p: IPlayer) {
"and manage your company in the City");
removeElementById(popupId);
return false;
- }
+ },
});
const seedMoneyButton = createElement("button", {
@@ -179,11 +179,11 @@ export function createStartCorporationPopup(p: IPlayer) {
}
dialogBoxCreate(
"Congratulations! You just started your own corporation with government seed money. " +
- "You can visit and manage your company in the City"
+ "You can visit and manage your company in the City",
);
removeElementById(popupId);
return false;
- }
+ },
})
const cancelBtn = createPopupCloseButton(popupId, { class: "popup-box-button" });
@@ -196,7 +196,7 @@ export function createStartCorporationPopup(p: IPlayer) {
* Create a popup that lets the player upgrade the cores on his/her home computer
* @param {IPlayer} p - Player object
*/
-export function createUpgradeHomeCoresPopup(p: IPlayer) {
+export function createUpgradeHomeCoresPopup(p: IPlayer): void {
const currentCores = p.getHomeComputer().cpuCores;
if (currentCores >= 8) {
dialogBoxCreate(<>
@@ -214,7 +214,7 @@ export function createUpgradeHomeCoresPopup(p: IPlayer) {
100e12,
1e15,
20e15,
- 200e15
+ 200e15,
];
const cost: number = allCosts[currentCores];
@@ -231,7 +231,7 @@ export function createUpgradeHomeCoresPopup(p: IPlayer) {
p.getHomeComputer().cpuCores++;
dialogBoxCreate(
"You purchased an additional CPU Core for your home computer! It now has " +
- p.getHomeComputer().cpuCores + " cores."
+ p.getHomeComputer().cpuCores + " cores.",
);
}
yesNoBoxClose();
@@ -252,7 +252,7 @@ cost {Money(cost)}>);
* Create a popup that lets the player upgrade the RAM on his/her home computer
* @param {IPlayer} p - Player object
*/
-export function createUpgradeHomeRamPopup(p: IPlayer) {
+export function createUpgradeHomeRamPopup(p: IPlayer): void {
const cost: number = p.getUpgradeHomeRamCost();
const ram: number = p.getHomeComputer().maxRam;
@@ -291,7 +291,7 @@ export function createUpgradeHomeRamPopup(p: IPlayer) {
* Attempt to purchase a TOR router
* @param {IPlayer} p - Player object
*/
-export function purchaseTorRouter(p: IPlayer) {
+export function purchaseTorRouter(p: IPlayer): void {
if (p.hasTorRouter()) {
dialogBoxCreate(`You already have a TOR Router`);
return;
@@ -304,7 +304,7 @@ export function purchaseTorRouter(p: IPlayer) {
const darkweb = safetlyCreateUniqueServer({
ip: createUniqueRandomIp(), hostname:"darkweb", organizationName:"",
- isConnectedTo:false, adminRights:false, purchasedByPlayer:false, maxRam:1
+ isConnectedTo:false, adminRights:false, purchasedByPlayer:false, maxRam:1,
});
AddToAllServers(darkweb);
SpecialServerIps.addIp("Darkweb Server", darkweb.ip);
@@ -314,6 +314,6 @@ export function purchaseTorRouter(p: IPlayer) {
dialogBoxCreate(
"You have purchased a Tor router! " +
"You now have access to the dark web from your home computer " +
- "Use the scan/scan-analyze commands to search for the dark web connection."
+ "Use the scan/scan-analyze commands to search for the dark web connection.",
);
}
diff --git a/src/Locations/data/LocationNames.ts b/src/Locations/data/LocationNames.ts
index 0d9f8d532..dfb48c353 100644
--- a/src/Locations/data/LocationNames.ts
+++ b/src/Locations/data/LocationNames.ts
@@ -78,4 +78,4 @@ export enum LocationName {
// Default name for Location objects
Void = "The Void",
-};
+}
diff --git a/src/Locations/ui/ApplyToJobButton.tsx b/src/Locations/ui/ApplyToJobButton.tsx
index 58f464257..1abea2ee3 100644
--- a/src/Locations/ui/ApplyToJobButton.tsx
+++ b/src/Locations/ui/ApplyToJobButton.tsx
@@ -15,7 +15,7 @@ type IProps = {
entryPosType: CompanyPosition;
onClick: (e: React.MouseEvent) => void;
p: IPlayer;
- style?: object;
+ style?: any;
text: string;
}
@@ -28,14 +28,14 @@ export class ApplyToJobButton extends React.Component {
getJobRequirementTooltip(): string {
const pos = this.props.p.getNextCompanyPosition(this.props.company, this.props.entryPosType);
- if (pos == null) { return "" };
+ if (pos == null) { return "" }
if (!this.props.company.hasPosition(pos)) { return ""; }
return getJobRequirementText(this.props.company, pos, true);
}
- render() {
+ render(): React.ReactNode {
return (
{
- asciiCity() {
- const thiscity = this;
- const topprop = this.props;
-
- function LocationLetter(location: LocationName) {
+ asciiCity(): React.ReactNode {
+ const LocationLetter = (location: LocationName): JSX.Element => {
if (location)
- return
+ return
X
return *
@@ -35,10 +36,9 @@ export class LocationCity extends React.Component {
'P': 15,'Q': 16,'R': 17,'S': 18,'T': 19,'U': 20,'V': 21,'W': 22,
'X': 23,'Y': 24,'Z': 25}
- let locI = 0;
- function lineElems(s: string) {
- let elems: any[] = [];
- let matches: any[] = [];
+ const lineElems = (s: string): JSX.Element[] => {
+ const elems: any[] = [];
+ const matches: any[] = [];
let match: any;
while ((match = locationLettersRegex.exec(s)) !== null) {
matches.push(match);
@@ -48,20 +48,18 @@ export class LocationCity extends React.Component {
return elems;
}
- let parts: any[] = [];
for(let i = 0; i < matches.length; i++) {
const startI = i === 0 ? 0 : matches[i-1].index+1;
const endI = matches[i].index;
elems.push(s.slice(startI, endI))
const locationI = letterMap[s[matches[i].index]];
- elems.push(LocationLetter(thiscity.props.city.locations[locationI]))
- locI++;
+ elems.push(LocationLetter(this.props.city.locations[locationI]))
}
elems.push(s.slice(matches[matches.length-1].index+1))
return elems;
}
- let elems: any[] = [];
+ const elems: JSX.Element[] = [];
const lines = this.props.city.asciiArt.split('\n');
for(const i in lines) {
elems.push({lineElems(lines[i])} )
@@ -70,7 +68,7 @@ export class LocationCity extends React.Component {
return elems;
}
- listCity() {
+ listCity(): React.ReactNode {
const locationButtons = this.props.city.locations.map((locName) => {
return (
@@ -86,7 +84,7 @@ export class LocationCity extends React.Component {
)
}
- render() {
+ render(): React.ReactNode {
return (
<>
{Settings.DisableASCIIArt ? this.listCity() : this.asciiCity()}
diff --git a/src/Locations/ui/CompanyLocation.tsx b/src/Locations/ui/CompanyLocation.tsx
index e3bcd1129..dc57c49a5 100644
--- a/src/Locations/ui/CompanyLocation.tsx
+++ b/src/Locations/ui/CompanyLocation.tsx
@@ -21,7 +21,6 @@ import { CompanyPositions } from "../../Company/CompanyPositions";
import * as posNames from "../../Company/data/companypositionnames";
import { IPlayer } from "../../PersonObjects/IPlayer";
-import { numeralWrapper } from "../../ui/numeralFormat";
import { StdButton } from "../../ui/React/StdButton";
import { Reputation } from "../../ui/React/Reputation";
import { Favor } from "../../ui/React/Favor";
@@ -30,7 +29,7 @@ import {
yesNoBoxGetYesButton,
yesNoBoxGetNoButton,
yesNoBoxClose,
- yesNoBoxCreate
+ yesNoBoxCreate,
} from "../../../utils/YesNoBox";
type IProps = {
@@ -63,7 +62,7 @@ export class CompanyLocation extends React.Component {
/**
* Stores button styling that sets them all to block display
*/
- btnStyle: object;
+ btnStyle: any;
/**
* Reference to the Location that this component is being rendered for
@@ -112,73 +111,73 @@ export class CompanyLocation extends React.Component {
this.checkIfEmployedHere(false);
}
- applyForAgentJob(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ applyForAgentJob(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
this.props.p.applyForAgentJob();
this.checkIfEmployedHere(true);
}
- applyForBusinessConsultantJob(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ applyForBusinessConsultantJob(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
this.props.p.applyForBusinessConsultantJob();
this.checkIfEmployedHere(true);
}
- applyForBusinessJob(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ applyForBusinessJob(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
this.props.p.applyForBusinessJob();
this.checkIfEmployedHere(true);
}
- applyForEmployeeJob(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ applyForEmployeeJob(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
this.props.p.applyForEmployeeJob();
this.checkIfEmployedHere(true);
}
- applyForItJob(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ applyForItJob(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
this.props.p.applyForItJob();
this.checkIfEmployedHere(true);
}
- applyForPartTimeEmployeeJob(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ applyForPartTimeEmployeeJob(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
this.props.p.applyForPartTimeEmployeeJob();
this.checkIfEmployedHere(true);
}
- applyForPartTimeWaiterJob(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ applyForPartTimeWaiterJob(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
this.props.p.applyForPartTimeWaiterJob();
this.checkIfEmployedHere(true);
}
- applyForSecurityJob(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ applyForSecurityJob(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
this.props.p.applyForSecurityJob();
this.checkIfEmployedHere(true);
}
- applyForSoftwareConsultantJob(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ applyForSoftwareConsultantJob(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
this.props.p.applyForSoftwareConsultantJob();
this.checkIfEmployedHere(true);
}
- applyForSoftwareJob(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ applyForSoftwareJob(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
this.props.p.applyForSoftwareJob();
this.checkIfEmployedHere(true);
}
- applyForWaiterJob(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ applyForWaiterJob(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
this.props.p.applyForWaiterJob();
this.checkIfEmployedHere(true);
}
- checkIfEmployedHere(updateState=false) {
+ checkIfEmployedHere(updateState=false): void {
this.jobTitle = this.props.p.jobs[this.props.locName];
if (this.jobTitle != null) {
this.companyPosition = CompanyPositions[this.jobTitle];
@@ -186,24 +185,24 @@ export class CompanyLocation extends React.Component {
if (updateState) {
this.setState({
- employedHere: this.jobTitle != null
+ employedHere: this.jobTitle != null,
});
}
}
- startInfiltration(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ startInfiltration(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
const loc = this.location;
this.props.engine.loadInfiltrationContent();
const data = loc.infiltrationData;
- if (data == null) { return false; }
+ if (data == null) { return; }
beginInfiltration(this.props.locName, data.startingSecurityLevel, data.baseRewardValue, data.maxClearanceLevel, data.difficulty);
}
- work(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ work(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
const pos = this.companyPosition;
if (pos instanceof CompanyPosition) {
@@ -215,11 +214,11 @@ export class CompanyLocation extends React.Component {
}
}
- quit(e: React.MouseEvent) {
- if (!e.isTrusted) { return false; }
+ quit(e: React.MouseEvent): void {
+ if (!e.isTrusted) { return; }
- var yesBtn = yesNoBoxGetYesButton();
- var noBtn = yesNoBoxGetNoButton();
+ const yesBtn = yesNoBoxGetYesButton();
+ const noBtn = yesNoBoxGetNoButton();
if (yesBtn == null || noBtn == null) { return; }
yesBtn.innerHTML = "Quit job";
noBtn.innerHTML = "Cancel";
@@ -235,7 +234,7 @@ export class CompanyLocation extends React.Component {
yesNoBoxCreate(<>Would you like to quit your job at {this.company.name}?>);
}
- render() {
+ render(): React.ReactNode {
const isEmployedHere = this.jobTitle != null;
const favorGain = this.company.getFavorGain();
diff --git a/src/Locations/ui/GenericLocation.tsx b/src/Locations/ui/GenericLocation.tsx
index 5de2e7921..ad162ef04 100644
--- a/src/Locations/ui/GenericLocation.tsx
+++ b/src/Locations/ui/GenericLocation.tsx
@@ -42,7 +42,7 @@ export class GenericLocation extends React.Component {
/**
* Stores button styling that sets them all to block display
*/
- btnStyle: object;
+ btnStyle: any;
constructor(props: IProps) {
super(props);
@@ -64,7 +64,7 @@ export class GenericLocation extends React.Component {
key={"companylocation"}
locName={this.props.loc.name}
p={this.props.p}
- />
+ />,
)
}
@@ -74,7 +74,7 @@ export class GenericLocation extends React.Component {
key={"gymlocation"}
loc={this.props.loc}
p={this.props.p}
- />
+ />,
)
}
@@ -83,7 +83,7 @@ export class GenericLocation extends React.Component {
+ />,
)
}
@@ -92,7 +92,7 @@ export class GenericLocation extends React.Component {
+ />,
)
}
@@ -103,7 +103,7 @@ export class GenericLocation extends React.Component {
key={"speciallocation"}
loc={this.props.loc}
p={this.props.p}
- />
+ />,
)
}
@@ -113,7 +113,7 @@ export class GenericLocation extends React.Component {
key={"techvendorlocation"}
loc={this.props.loc}
p={this.props.p}
- />
+ />,
)
}
@@ -123,7 +123,7 @@ export class GenericLocation extends React.Component {
key={"travelagencylocation"}
p={this.props.p}
travel={this.props.travel}
- />
+ />,
)
}
@@ -133,7 +133,7 @@ export class GenericLocation extends React.Component {
key={"universitylocation"}
loc={this.props.loc}
p={this.props.p}
- />
+ />,
)
}
@@ -142,14 +142,14 @@ export class GenericLocation extends React.Component {
+ />,
)
}
return content;
}
- render() {
+ render(): React.ReactNode {
const locContent: React.ReactNode[] = this.getLocationSpecificContent();
const ip = SpecialServerIps.getIp(this.props.loc.name);
const server = getServer(ip);
diff --git a/src/Locations/ui/GymLocation.tsx b/src/Locations/ui/GymLocation.tsx
index 89ad4911c..3b284cfba 100644
--- a/src/Locations/ui/GymLocation.tsx
+++ b/src/Locations/ui/GymLocation.tsx
@@ -13,7 +13,6 @@ import { getServer } from "../../Server/ServerHelpers";
import { Server } from "../../Server/Server";
import { SpecialServerIps } from "../../Server/SpecialServerIps";
-import { numeralWrapper } from "../../ui/numeralFormat";
import { StdButton } from "../../ui/React/StdButton";
import { Money } from "../../ui/React/Money";
@@ -26,7 +25,7 @@ export class GymLocation extends React.Component {
/**
* Stores button styling that sets them all to block display
*/
- btnStyle: object;
+ btnStyle: any;
constructor(props: IProps) {
super(props);
@@ -50,28 +49,28 @@ export class GymLocation extends React.Component {
return this.props.loc.costMult * discount;
}
- train(stat: string) {
+ train(stat: string): void {
const loc = this.props.loc;
this.props.p.startClass(this.calculateCost(), loc.expMult, stat);
}
- trainStrength() {
- return this.train(CONSTANTS.ClassGymStrength);
+ trainStrength(): void {
+ this.train(CONSTANTS.ClassGymStrength);
}
- trainDefense() {
- return this.train(CONSTANTS.ClassGymDefense);
+ trainDefense(): void {
+ this.train(CONSTANTS.ClassGymDefense);
}
- trainDexterity() {
- return this.train(CONSTANTS.ClassGymDexterity);
+ trainDexterity(): void {
+ this.train(CONSTANTS.ClassGymDexterity);
}
- trainAgility() {
- return this.train(CONSTANTS.ClassGymAgility);
+ trainAgility(): void {
+ this.train(CONSTANTS.ClassGymAgility);
}
- render() {
+ render(): React.ReactNode {
const cost = CONSTANTS.ClassGymBaseCost * this.calculateCost();
return (
diff --git a/src/Locations/ui/HospitalLocation.tsx b/src/Locations/ui/HospitalLocation.tsx
index 975f83525..f8892d0f8 100644
--- a/src/Locations/ui/HospitalLocation.tsx
+++ b/src/Locations/ui/HospitalLocation.tsx
@@ -5,11 +5,9 @@
*/
import * as React from "react";
-import { CONSTANTS } from "../../Constants";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { getHospitalizationCost } from "../../Hospital/Hospital";
-import { numeralWrapper } from "../../ui/numeralFormat";
import { AutoupdatingStdButton } from "../../ui/React/AutoupdatingStdButton";
import { Money } from "../../ui/React/Money";
@@ -27,7 +25,7 @@ export class HospitalLocation extends React.Component {
/**
* Stores button styling that sets them all to block display
*/
- btnStyle: object;
+ btnStyle: any;
constructor(props: IProps) {
super(props);
@@ -65,7 +63,7 @@ export class HospitalLocation extends React.Component {
dialogBoxCreate(<>You were healed to full health! The hospital billed you for {Money(cost)}>);
}
- render() {
+ render(): React.ReactNode {
const cost = this.getCost();
return (
diff --git a/src/Locations/ui/Root.tsx b/src/Locations/ui/Root.tsx
index 351741c19..1314425db 100644
--- a/src/Locations/ui/Root.tsx
+++ b/src/Locations/ui/Root.tsx
@@ -136,12 +136,12 @@ export class LocationRoot extends React.Component {
if (this.props.p.travel(to)) {
this.setState({
inCity: true,
- city: to
+ city: to,
});
}
}
- render() {
+ render(): React.ReactNode {
if (this.state.inCity) {
return this.renderCity();
} else {
diff --git a/src/Locations/ui/SlumsLocation.tsx b/src/Locations/ui/SlumsLocation.tsx
index 7afa53bba..08d2afff1 100644
--- a/src/Locations/ui/SlumsLocation.tsx
+++ b/src/Locations/ui/SlumsLocation.tsx
@@ -19,7 +19,7 @@ export class SlumsLocation extends React.Component {
/**
* Stores button styling that sets them all to block display
*/
- btnStyle: object;
+ btnStyle: any;
constructor(props: IProps) {
super(props);
@@ -100,7 +100,7 @@ export class SlumsLocation extends React.Component {
Crimes.Heist.commit(this.props.p);
}
- render() {
+ render(): React.ReactNode {
const shopliftChance = Crimes.Shoplift.successRate(this.props.p);
const robStoreChance = Crimes.RobStore.successRate(this.props.p);
const mugChance = Crimes.Mug.successRate(this.props.p);
diff --git a/src/Locations/ui/SpecialLocation.tsx b/src/Locations/ui/SpecialLocation.tsx
index ba51d8cfa..a24653857 100644
--- a/src/Locations/ui/SpecialLocation.tsx
+++ b/src/Locations/ui/SpecialLocation.tsx
@@ -38,7 +38,7 @@ export class SpecialLocation extends React.Component {
/**
* Stores button styling that sets them all to block display
*/
- btnStyle: object;
+ btnStyle: any;
constructor(props: IProps) {
super(props);
@@ -57,14 +57,14 @@ export class SpecialLocation extends React.Component {
/**
* Click handler for "Create Corporation" button at Sector-12 City Hall
*/
- createCorporationPopup() {
+ createCorporationPopup(): void {
createStartCorporationPopup(this.props.p);
}
/**
* Click handler for Bladeburner button at Sector-12 NSA
*/
- handleBladeburner() {
+ handleBladeburner(): void {
const p = this.props.p;
if (p.inBladeburner()) {
// Enter Bladeburner division
@@ -91,7 +91,7 @@ export class SpecialLocation extends React.Component {
/**
* Click handler for Resleeving button at New Tokyo VitaLife
*/
- handleResleeving() {
+ handleResleeving(): void {
this.props.engine.loadResleevingContent();
}
@@ -130,7 +130,7 @@ export class SpecialLocation extends React.Component {
)
}
- render() {
+ render(): React.ReactNode {
switch (this.props.loc.name) {
case LocationName.NewTokyoVitaLife: {
return this.renderResleeving();
diff --git a/src/Locations/ui/TechVendorLocation.tsx b/src/Locations/ui/TechVendorLocation.tsx
index d0a13b389..11fb1eecf 100644
--- a/src/Locations/ui/TechVendorLocation.tsx
+++ b/src/Locations/ui/TechVendorLocation.tsx
@@ -15,7 +15,6 @@ import { CONSTANTS } from "../../Constants";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { getPurchaseServerCost } from "../../Server/ServerPurchases";
-import { numeralWrapper } from "../../ui/numeralFormat";
import { StdButtonPurchased } from "../../ui/React/StdButtonPurchased";
import { StdButton } from "../../ui/React/StdButton";
import { Money } from "../../ui/React/Money";
@@ -29,7 +28,7 @@ export class TechVendorLocation extends React.Component {
/**
* Stores button styling that sets them all to block display
*/
- btnStyle: object;
+ btnStyle: any;
constructor(props: IProps) {
super(props);
@@ -45,22 +44,22 @@ export class TechVendorLocation extends React.Component {
this.purchaseTorRouter = this.purchaseTorRouter.bind(this);
}
- createUpgradeHomeCoresPopup() {
+ createUpgradeHomeCoresPopup(): void {
createUpgradeHomeCoresPopup(this.props.p);
}
- createUpgradeHomeRamPopup() {
+ createUpgradeHomeRamPopup(): void {
createUpgradeHomeRamPopup(this.props.p);
}
- purchaseTorRouter() {
+ purchaseTorRouter(): void {
purchaseTorRouter(this.props.p);
this.setState({
torPurchased: this.props.p.hasTorRouter(),
});
}
- render() {
+ render(): React.ReactNode {
const loc: Location = this.props.loc;
const purchaseServerButtons: React.ReactNode[] = [];
@@ -72,7 +71,7 @@ export class TechVendorLocation extends React.Component {
onClick={() => createPurchaseServerPopup(i, this.props.p)}
style={this.btnStyle}
text={<>Purchase {i}GB Server - {Money(cost)}>}
- />
+ />,
)
}
diff --git a/src/Locations/ui/TravelAgencyLocation.tsx b/src/Locations/ui/TravelAgencyLocation.tsx
index 7d33b4bac..b0931bd17 100644
--- a/src/Locations/ui/TravelAgencyLocation.tsx
+++ b/src/Locations/ui/TravelAgencyLocation.tsx
@@ -12,7 +12,6 @@ import { CONSTANTS } from "../../Constants";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { Settings } from "../../Settings/Settings";
-import { numeralWrapper } from "../../ui/numeralFormat";
import { StdButton } from "../../ui/React/StdButton";
import { Money } from "../../ui/React/Money";
@@ -25,7 +24,7 @@ export class TravelAgencyLocation extends React.Component {
/**
* Stores button styling that sets them all to block display
*/
- btnStyle: object;
+ btnStyle: any;
constructor(props: IProps) {
super(props);
@@ -33,13 +32,11 @@ export class TravelAgencyLocation extends React.Component {
this.btnStyle = { display: "block" };
}
- asciiWorldMap() {
- const thisTravelAgencyLocation = this;
-
- function LocationLetter(props: any) {
- if(props.city !== thisTravelAgencyLocation.props.p.city) {
- return
- {props.city}
+ asciiWorldMap(): React.ReactNode {
+ const LocationLetter = (props: any): JSX.Element => {
+ if(props.city !== this.props.p.city) {
+ return
+ {props.city}
{props.city[0]}
}
@@ -55,20 +52,20 @@ export class TravelAgencyLocation extends React.Component {
,_ . ._. _. .
, _-\','|~\~ ~/ ;-'_ _-' ,;_;_, ~~-
/~~-\_/-'~'--' \~~| ', ,' / / ~|-_\_/~/~ ~~--~~~~'--_
- / ,/'-/~ '\ ,' _ , ' ,'|~ ._/-, /~
+ / ,/'-/~ '\ ,' _ , ' ,'|~ ._/-, /~
~/-'~\_, '-,| '|. ' ~ ,\ /'~ / /_ /~
-.-~ '| '',\~|\ _\~ ,_ , /,
- '\ /'~ |_/~\\,-,~ \ " ,_,/ |
- | / ._-~'\_ _~| \ )
+.-~ '| '',\~|\ _\~ ,_ , /,
+ '\ /'~ |_/~\\,-,~ \ " ,_,/ |
+ | / ._-~'\_ _~| \ )
\ __-\ '/ ~ |\ \_ / ~
., '\ |, ~-_ - | \\_' ~| /\ \~ ,
~-_' _; '\ '-, \,' /\/ |
'\_,~'\_ \_ _, /' ' |, /|'
/ \_ ~ | / \ ~'; -,_.
| ~\ | | , '-_, ,; ~ ~\
- \, / \ / /| ,-, , -,
+ \, / \ / /| ,-, , -,
| ,/ | |' |/ ,- ~ \ '.
- ,| ,/ \ ,/ \ |
+ ,| ,/ \ ,/ \ |
/ | ~ -~~-, / _
| ,-' ~ /
/ ,' ~
@@ -79,7 +76,7 @@ export class TravelAgencyLocation extends React.Component {
}
- listWorldMap() {
+ listWorldMap(): React.ReactNode {
const travelBtns: React.ReactNode[] = [];
for (const key in CityName) {
const city: CityName = (CityName as any)[key];
@@ -93,7 +90,7 @@ export class TravelAgencyLocation extends React.Component {
onClick={createTravelPopup.bind(null, city, this.props.travel)}
style={this.btnStyle}
text={`Travel to ${city}`}
- />
+ />,
)
}
@@ -108,7 +105,7 @@ export class TravelAgencyLocation extends React.Component {
)
}
- render() {
+ render(): React.ReactNode {
if (Settings.DisableASCIIArt) {
return this.listWorldMap();
} else {
diff --git a/src/Locations/ui/UniversityLocation.tsx b/src/Locations/ui/UniversityLocation.tsx
index 88f5f18cd..3a360e1f5 100644
--- a/src/Locations/ui/UniversityLocation.tsx
+++ b/src/Locations/ui/UniversityLocation.tsx
@@ -13,7 +13,6 @@ import { getServer } from "../../Server/ServerHelpers";
import { Server } from "../../Server/Server";
import { SpecialServerIps } from "../../Server/SpecialServerIps";
-import { numeralWrapper } from "../../ui/numeralFormat";
import { StdButton } from "../../ui/React/StdButton";
import { Money } from "../../ui/React/Money";
@@ -26,7 +25,7 @@ export class UniversityLocation extends React.Component {
/**
* Stores button styling that sets them all to block display
*/
- btnStyle: object;
+ btnStyle: any;
constructor(props: IProps) {
super(props);
@@ -53,36 +52,36 @@ export class UniversityLocation extends React.Component {
return this.props.loc.costMult * discount;
}
- take(stat: string) {
+ take(stat: string): void {
const loc = this.props.loc;
this.props.p.startClass(this.calculateCost(), loc.expMult, stat);
}
- study() {
- return this.take(CONSTANTS.ClassStudyComputerScience);
+ study(): void {
+ this.take(CONSTANTS.ClassStudyComputerScience);
}
- dataStructures() {
- return this.take(CONSTANTS.ClassDataStructures);
+ dataStructures(): void {
+ this.take(CONSTANTS.ClassDataStructures);
}
- networks() {
- return this.take(CONSTANTS.ClassNetworks);
+ networks(): void {
+ this.take(CONSTANTS.ClassNetworks);
}
- algorithms() {
- return this.take(CONSTANTS.ClassAlgorithms);
+ algorithms(): void {
+ this.take(CONSTANTS.ClassAlgorithms);
}
- management() {
- return this.take(CONSTANTS.ClassManagement);
+ management(): void {
+ this.take(CONSTANTS.ClassManagement);
}
- leadership() {
- return this.take(CONSTANTS.ClassLeadership);
+ leadership(): void {
+ this.take(CONSTANTS.ClassLeadership);
}
- render() {
+ render(): React.ReactNode {
const costMult: number = this.calculateCost();
const dataStructuresCost = CONSTANTS.ClassDataStructuresBaseCost * costMult;
diff --git a/src/Message/Message.ts b/src/Message/Message.ts
index 90e24aa2c..737409219 100644
--- a/src/Message/Message.ts
+++ b/src/Message/Message.ts
@@ -3,19 +3,15 @@ import { Reviver,
Generic_fromJSON } from "../../utils/JSONReviver";
export class Message {
- // Initializes a Message Object from a JSON save state
- static fromJSON(value: any): Message {
- return Generic_fromJSON(Message, value.data);
- }
// Name of Message file
- filename: string = "";
+ filename = "";
// The text contains in the Message
- msg: string = "";
+ msg = "";
// Flag indicating whether this Message has been received by the player
- recvd: boolean = false;
+ recvd = false;
constructor(filename="", msg="") {
this.filename = filename;
@@ -27,6 +23,12 @@ export class Message {
toJSON(): any {
return Generic_toJSON("Message", this);
}
+
+ // Initializes a Message Object from a JSON save state
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+ static fromJSON(value: any): Message {
+ return Generic_fromJSON(Message, value.data);
+ }
}
Reviver.constructors.Message = Message;
diff --git a/src/Message/MessageHelpers.js b/src/Message/MessageHelpers.js
index b3af621ac..4932c7be2 100644
--- a/src/Message/MessageHelpers.js
+++ b/src/Message/MessageHelpers.js
@@ -1,5 +1,4 @@
import { Message } from "./Message";
-import { Augmentatation } from "../Augmentation/Augmentation";
import { Augmentations } from "../Augmentation/Augmentations";
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
import { Programs } from "../Programs/Programs";
diff --git a/src/Milestones/MilestoneHelpers.tsx b/src/Milestones/MilestoneHelpers.tsx
index 330aee209..e9ddac327 100644
--- a/src/Milestones/MilestoneHelpers.tsx
+++ b/src/Milestones/MilestoneHelpers.tsx
@@ -7,7 +7,7 @@ import * as ReactDOM from "react-dom";
let milestonesContainer: HTMLElement | null = null;
(function(){
- function setContainer() {
+ function setContainer(): void {
milestonesContainer = document.getElementById("milestones-container");
document.removeEventListener("DOMContentLoaded", setContainer);
}
@@ -15,7 +15,7 @@ let milestonesContainer: HTMLElement | null = null;
document.addEventListener("DOMContentLoaded", setContainer);
})();
-export function displayMilestonesContent() {
+export function displayMilestonesContent(): void {
if (!routing.isOn(Page.Milestones)) {
return;
}
@@ -23,7 +23,7 @@ export function displayMilestonesContent() {
if (milestonesContainer instanceof HTMLElement) {
ReactDOM.render(
,
- milestonesContainer
+ milestonesContainer,
);
}
}
\ No newline at end of file
diff --git a/src/Milestones/Milestones.ts b/src/Milestones/Milestones.ts
index e08b0e297..856c070a9 100644
--- a/src/Milestones/Milestones.ts
+++ b/src/Milestones/Milestones.ts
@@ -1,12 +1,11 @@
import { Milestone } from "./Milestone";
-import { IMap } from "../types";
import { IPlayer } from "../PersonObjects/IPlayer";
import { Factions } from "../Faction/Factions";
import { Faction } from "../Faction/Faction";
import { GetServerByHostname } from "../Server/ServerHelpers";
function allFactionAugs(p: IPlayer, f: Faction): boolean {
- const factionAugs = f.augmentations.slice().filter((aug)=> "NeuroFlux Governor" !== aug);
+ const factionAugs = f.augmentations.slice().filter((aug)=> aug !== "NeuroFlux Governor");
for(const factionAug of factionAugs) {
if(!p.augmentations.some(aug => {return aug.name == factionAug})) return false;
}
@@ -16,7 +15,7 @@ function allFactionAugs(p: IPlayer, f: Faction): boolean {
export const Milestones: Milestone[] = [
{
title: "Gain root access on CSEC",
- fulfilled: (p: IPlayer) => {
+ fulfilled: (): boolean => {
const server = GetServerByHostname("CSEC");
if(!server || !server.hasOwnProperty('hasAdminRights')) return false;
return (server as any).hasAdminRights;
@@ -24,7 +23,7 @@ export const Milestones: Milestone[] = [
},
{
title: "Install the backdoor on CSEC",
- fulfilled: (p: IPlayer) => {
+ fulfilled: (): boolean => {
const server = GetServerByHostname("CSEC");
if(!server || !server.hasOwnProperty('backdoorInstalled')) return false;
return (server as any).backdoorInstalled;
@@ -32,67 +31,67 @@ export const Milestones: Milestone[] = [
},
{
title: "Join the faction hinted at in j1.msg",
- fulfilled: (p: IPlayer) => {
+ fulfilled: (p: IPlayer): boolean => {
return p.factions.includes("CyberSec");
},
},
{
title: "Install all the Augmentations from CSEC",
- fulfilled: (p: IPlayer) => {
+ fulfilled: (p: IPlayer): boolean => {
return allFactionAugs(p, Factions["CyberSec"]);
},
},
{
title: "Join the faction hinted at in j2.msg",
- fulfilled: (p: IPlayer) => {
+ fulfilled: (p: IPlayer): boolean => {
return p.factions.includes("NiteSec");
},
},
{
title: "Install all the Augmentations from NiteSec",
- fulfilled: (p: IPlayer) => {
+ fulfilled: (p: IPlayer): boolean => {
return allFactionAugs(p, Factions["NiteSec"]);
},
},
{
title: "Join the faction hinted at in j3.msg",
- fulfilled: (p: IPlayer) => {
+ fulfilled: (p: IPlayer): boolean => {
return p.factions.includes("The Black Hand");
},
},
{
title: "Install all the Augmentations from The Black Hand",
- fulfilled: (p: IPlayer) => {
+ fulfilled: (p: IPlayer): boolean => {
return allFactionAugs(p, Factions["The Black Hand"]);
},
},
{
title: "Join the faction hinted at in j4.msg",
- fulfilled: (p: IPlayer) => {
+ fulfilled: (p: IPlayer): boolean => {
return p.factions.includes("BitRunners");
},
},
{
title: "Install all the Augmentations from BitRunners",
- fulfilled: (p: IPlayer) => {
+ fulfilled: (p: IPlayer): boolean => {
return allFactionAugs(p, Factions["BitRunners"]);
},
},
{
title: "Join the final faction",
- fulfilled: (p: IPlayer) => {
+ fulfilled: (p: IPlayer): boolean => {
return p.factions.includes("Daedalus");
},
},
{
title: "Install the special Augmentation from Daedalus",
- fulfilled: (p: IPlayer) => {
+ fulfilled: (p: IPlayer): boolean => {
return p.augmentations.some(aug => aug.name == "The Red Pill")
},
},
{
title: "Install the final backdoor and free yourself.",
- fulfilled: () => {
+ fulfilled: (): boolean => {
return false;
},
},
diff --git a/src/Milestones/ui/Root.tsx b/src/Milestones/ui/Root.tsx
index bfaf79b1f..bbf191588 100644
--- a/src/Milestones/ui/Root.tsx
+++ b/src/Milestones/ui/Root.tsx
@@ -16,7 +16,7 @@ function highestMilestone(p: IPlayer, milestones: Milestone[]): number {
return n;
}
-export function Root(props: IProps) {
+export function Root(props: IProps): JSX.Element {
const n = highestMilestone(props.player, Milestones);
const milestones = Milestones.map((milestone: Milestone, i: number) => {
if (i<=n+1) {
diff --git a/src/Missions.jsx b/src/Missions.jsx
index fad515ca2..bbc063dd1 100644
--- a/src/Missions.jsx
+++ b/src/Missions.jsx
@@ -5,7 +5,6 @@ import { Player } from "./Player";
import { dialogBoxCreate } from "../utils/DialogBox";
import { formatNumber } from "../utils/StringHelperFunctions";
-import { numeralWrapper } from "./ui/numeralFormat";
import { Reputation } from "./ui/React/Reputation";
import { addOffset } from "../utils/helpers/addOffset";
@@ -14,8 +13,6 @@ import { isString } from "../utils/helpers/isString";
import { clearEventListeners } from "../utils/uiHelpers/clearEventListeners";
-import jsplumb from "jsplumb";
-
import React from "react";
import ReactDOM from "react-dom";
@@ -65,7 +62,7 @@ let NodeTypes = {
Database: "Database Node", // No actions available
Spam: "Spam Node", // No actions Available
Transfer: "Transfer Node", // Can Weaken, Scan, Fortify and Overflow
- Shield: "Shield Node" // Can Fortify
+ Shield: "Shield Node", // Can Fortify
}
let NodeActions = {
@@ -252,7 +249,7 @@ HackingMission.prototype.init = function() {
var stats = {
atk: randMult * getRandomInt(80, 86),
def: randMult * getRandomInt(5, 10),
- hp: randMult * getRandomInt(210, 230)
+ hp: randMult * getRandomInt(210, 230),
}
this.enemyCores.push(new Node(NodeTypes.Core, stats));
this.enemyCores[i].setControlledByEnemy();
@@ -262,7 +259,7 @@ HackingMission.prototype.init = function() {
var stats = {
atk: 0,
def: randMult * getRandomInt(10, 20),
- hp: randMult * getRandomInt(275, 300)
+ hp: randMult * getRandomInt(275, 300),
}
this.enemyNodes.push(new Node(NodeTypes.Firewall, stats));
this.enemyNodes[i].setControlledByEnemy();
@@ -272,7 +269,7 @@ HackingMission.prototype.init = function() {
var stats = {
atk: 0,
def: randMult * getRandomInt(30, 55),
- hp: randMult * getRandomInt(210, 275)
+ hp: randMult * getRandomInt(210, 275),
}
var node = new Node(NodeTypes.Database, stats);
node.setControlledByEnemy();
@@ -674,7 +671,7 @@ HackingMission.prototype.createMap = function() {
var stats = {
atk: 0,
def: averageAttack * 1.1 + getRandomInt(15, 45),
- hp: randMult * getRandomInt(200, 225)
+ hp: randMult * getRandomInt(200, 225),
}
node = new Node(NodeTypes.Spam, stats);
break;
@@ -682,7 +679,7 @@ HackingMission.prototype.createMap = function() {
var stats = {
atk: 0,
def: averageAttack * 1.1 + getRandomInt(15, 45),
- hp: randMult * getRandomInt(250, 275)
+ hp: randMult * getRandomInt(250, 275),
}
node = new Node(NodeTypes.Transfer, stats);
break;
@@ -691,7 +688,7 @@ HackingMission.prototype.createMap = function() {
var stats = {
atk: 0,
def: averageAttack * 1.1 + getRandomInt(30, 70),
- hp: randMult * getRandomInt(300, 320)
+ hp: randMult * getRandomInt(300, 320),
}
node = new Node(NodeTypes.Shield, stats);
break;
@@ -783,11 +780,11 @@ HackingMission.prototype.updateNodeDomElement = function(nodeObj) {
return;
}
- var id = "hacking-mission-node-" + nodeObj.pos[0] + "-" + nodeObj.pos[1];
- var nodeDiv = document.getElementById(id), txtEl = document.getElementById(id + "-txt");
+ let id = "hacking-mission-node-" + nodeObj.pos[0] + "-" + nodeObj.pos[1];
+ let txtEl = document.getElementById(id + "-txt");
// Set node classes based on type
- var txt;
+ let txt;
switch (nodeObj.type) {
case NodeTypes.Core:
txt = "CPU Core " + "HP: " +
@@ -901,14 +898,13 @@ HackingMission.prototype.configurePlayerNodeElement = function(el) {
if (nodeObj == null) {console.error("Failed getting Node object");}
// Add event listener
- var self = this;
- function selectNodeWrapper() {
- selectNode(self, el);
+ const selectNodeWrapper = () => {
+ selectNode(this, el);
}
el.addEventListener("click", selectNodeWrapper);
- function multiselectNodeWrapper() {
- multiselectNode(self, el);
+ const multiselectNodeWrapper = () => {
+ multiselectNode(this, el);
}
el.addEventListener("dblclick", multiselectNodeWrapper);
@@ -971,10 +967,10 @@ HackingMission.prototype.initJsPlumb = function() {
PaintStyle: {
gradient: { stops: [
[ 0, "#FFFFFF" ],
- [ 1, "#FFFFFF" ]
+ [ 1, "#FFFFFF" ],
] },
stroke: "#FFFFFF",
- strokeWidth: 8
+ strokeWidth: 8,
},
});
@@ -986,7 +982,7 @@ HackingMission.prototype.initJsPlumb = function() {
deleteEndpointsOnEmpty:true,
maxConnections:1,
anchor:"Continuous",
- connector:"Flowchart"
+ connector:"Flowchart",
});
}
@@ -995,33 +991,33 @@ HackingMission.prototype.initJsPlumb = function() {
instance.makeTarget(this.enemyCores[i].el, {
maxConnections:-1,
anchor:"Continuous",
- connector:"Flowchart"
+ connector:"Flowchart",
});
}
for (var i = 0; i < this.enemyDatabases.length; ++i) {
instance.makeTarget(this.enemyDatabases[i].el, {
maxConnections:-1,
anchor:"Continuous",
- connector:["Flowchart"]
+ connector:["Flowchart"],
});
}
for (var i = 0; i < this.enemyNodes.length; ++i) {
instance.makeTarget(this.enemyNodes[i].el, {
maxConnections:-1,
anchor:"Continuous",
- connector:"Flowchart"
+ connector:"Flowchart",
});
}
for (var i = 0; i < this.miscNodes.length; ++i) {
instance.makeTarget(this.miscNodes[i].el, {
maxConnections:-1,
anchor:"Continuous",
- connector:"Flowchart"
+ connector:"Flowchart",
});
}
// Clicking a connection drops it
- instance.bind("click", (conn, originalEvent) => {
+ instance.bind("click", (conn) => {
// Cannot drop enemy's connections
const sourceNode = this.getNodeFromElement(conn.source);
if (sourceNode.enmyCtrl) { return; }
@@ -1051,7 +1047,7 @@ HackingMission.prototype.initJsPlumb = function() {
});
// Detach Connection events
- instance.bind("connectionDetached", (info, originalEvent) => {
+ instance.bind("connectionDetached", (info) => {
var sourceNode = this.getNodeFromElement(info.source);
sourceNode.conn = null;
var targetNode = this.getNodeFromElement(info.target);
@@ -1264,7 +1260,7 @@ HackingMission.prototype.processNode = function(nodeObj, numCycles=1) {
deleteEndpointsOnEmpty:true,
maxConnections:1,
anchor:"Continuous",
- connector:"Flowchart"
+ connector:"Flowchart",
});
} else {
targetNode.setControlledByEnemy();
@@ -1273,7 +1269,7 @@ HackingMission.prototype.processNode = function(nodeObj, numCycles=1) {
this.jsplumbinstance.makeTarget(targetNode.el, {
maxConnections:-1,
anchor:"Continuous",
- connector:["Flowchart"]
+ connector:["Flowchart"],
});
}
@@ -1393,7 +1389,7 @@ HackingMission.prototype.enemyAISelectAction = function(nodeObj) {
// Create connection
nodeObj.conn = this.jsplumbinstance.connect({
source:nodeObj.el,
- target:node.el
+ target:node.el,
});
++node.targetedCount;
} else {
@@ -1409,7 +1405,7 @@ HackingMission.prototype.enemyAISelectAction = function(nodeObj) {
// Create connection
nodeObj.conn = this.jsplumbinstance.connect({
source:nodeObj.el,
- target:node.el
+ target:node.el,
});
++node.targetedCount;
}
diff --git a/src/Netscript/Environment.ts b/src/Netscript/Environment.ts
index 97de95001..0f3a95219 100644
--- a/src/Netscript/Environment.ts
+++ b/src/Netscript/Environment.ts
@@ -13,7 +13,7 @@ export class Environment {
/**
* Whether or not the script that uses this Environment should stop running
*/
- stopFlag: boolean = false;
+ stopFlag = false;
/**
* Environment variables (currently only Netscript functions)
@@ -32,6 +32,7 @@ export class Environment {
* Finds the scope where the variable with the given name is defined
*/
lookup(name: string): Environment | null {
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
let scope: Environment | null = this;
while (scope) {
if (Object.prototype.hasOwnProperty.call(scope.vars, name)) {
@@ -53,8 +54,9 @@ export class Environment {
}
//Sets the value of a variable in any scope
- set(name: string, value: any) {
- var scope = this.lookup(name);
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+ set(name: string, value: any): any {
+ const scope = this.lookup(name);
//If scope has a value, then this variable is already set in a higher scope, so
//set is there. Otherwise, create a new variable in the local scope
@@ -66,7 +68,8 @@ export class Environment {
}
//Creates (or overwrites) a variable in the current scope
- def(name: string, value: any) {
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+ def(name: string, value: any): any {
return this.vars[name] = value;
}
}
diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts
index 01cc550c4..326419d77 100644
--- a/src/Netscript/RamCostGenerator.ts
+++ b/src/Netscript/RamCostGenerator.ts
@@ -23,6 +23,8 @@ export const RamCostConstants: IMap = {
ScriptGetHackingLevelRamCost: 0.05,
ScriptGetMultipliersRamCost: 4.0,
ScriptGetServerRamCost: 0.1,
+ ScriptGetServerMaxRam: 0.05,
+ ScriptGetServerUsedRam: 0.05,
ScriptFileExistsRamCost: 0.1,
ScriptIsRunningRamCost: 0.1,
ScriptHacknetNodesRamCost: 4.0,
@@ -122,6 +124,8 @@ export const RamCosts: IMap = {
getServerGrowth: () => RamCostConstants.ScriptGetServerRamCost,
getServerNumPortsRequired: () => RamCostConstants.ScriptGetServerRamCost,
getServerRam: () => RamCostConstants.ScriptGetServerRamCost,
+ getServerMaxRam: () => RamCostConstants.ScriptGetServerMaxRam,
+ getServerUsedRam: () => RamCostConstants.ScriptGetServerUsedRam,
serverExists: () => RamCostConstants.ScriptGetServerRamCost,
fileExists: () => RamCostConstants.ScriptFileExistsRamCost,
isRunning: () => RamCostConstants.ScriptIsRunningRamCost,
@@ -307,7 +311,7 @@ export const RamCosts: IMap = {
heart: {
// Easter egg function
break : () => 0,
- }
+ },
}
export function getRamCost(...args: string[]): number {
diff --git a/src/Netscript/WorkerScript.ts b/src/Netscript/WorkerScript.ts
index 23c5d48e6..6129f0712 100644
--- a/src/Netscript/WorkerScript.ts
+++ b/src/Netscript/WorkerScript.ts
@@ -24,7 +24,7 @@ export class WorkerScript {
/**
* Copy of the script's code
*/
- code: string = "";
+ code = "";
/**
* Holds the timeoutID (numeric value) for whenever this script is blocked by a
@@ -62,7 +62,7 @@ export class WorkerScript {
/**
* Status message in case of script error. Currently unused I think
*/
- errorMessage: string = "";
+ errorMessage = "";
/**
* Used for static RAM calculation. Stores names of all functions that have
@@ -78,7 +78,7 @@ export class WorkerScript {
/**
* Script's output/return value. Currently not used or implemented
*/
- output: string = "";
+ output = "";
/**
* Process ID. Must be an integer. Used for efficient script
@@ -89,12 +89,12 @@ export class WorkerScript {
/**
* Script's Static RAM usage. Equivalent to underlying script's RAM usage
*/
- ramUsage: number = 0;
+ ramUsage = 0;
/**
* Whether or not this workerScript is currently running
*/
- running: boolean = false;
+ running = false;
/**
* Reference to underlying RunningScript object
@@ -106,7 +106,7 @@ export class WorkerScript {
*/
serverIp: string;
- constructor(runningScriptObj: RunningScript, pid: number, nsFuncsGenerator?: (ws: WorkerScript) => object) {
+ constructor(runningScriptObj: RunningScript, pid: number, nsFuncsGenerator?: (ws: WorkerScript) => any) {
this.name = runningScriptObj.filename;
this.serverIp = runningScriptObj.server;
@@ -146,8 +146,10 @@ export class WorkerScript {
/**
* Returns the Server on which this script is running
*/
- getServer() {
- return AllServers[this.serverIp];
+ getServer(): BaseServer {
+ const server = AllServers[this.serverIp];
+ if(server == null) throw new Error(`Script ${this.name} pid ${this.pid} is running on non-existent server?`);
+ return server;
}
/**
@@ -155,7 +157,7 @@ export class WorkerScript {
* Returns null if it cannot be found (which would be a bug)
*/
getScript(): Script | null {
- let server = this.getServer();
+ const server = this.getServer();
for (let i = 0; i < server.scripts.length; ++i) {
if (server.scripts[i].filename === this.name) {
return server.scripts[i];
diff --git a/src/Netscript/killWorkerScript.ts b/src/Netscript/killWorkerScript.ts
index dc33af1f6..33c91b963 100644
--- a/src/Netscript/killWorkerScript.ts
+++ b/src/Netscript/killWorkerScript.ts
@@ -50,7 +50,7 @@ export function killWorkerScript(script: RunningScript | WorkerScript | number,
}
}
-function killWorkerScriptByPid(pid: number, rerenderUi: boolean=true): boolean {
+function killWorkerScriptByPid(pid: number, rerenderUi=true): boolean {
const ws = workerScripts.get(pid);
if (ws instanceof WorkerScript) {
stopAndCleanUpWorkerScript(ws, rerenderUi);
@@ -61,7 +61,7 @@ function killWorkerScriptByPid(pid: number, rerenderUi: boolean=true): boolean {
return false;
}
-function stopAndCleanUpWorkerScript(workerScript: WorkerScript, rerenderUi: boolean=true): void {
+function stopAndCleanUpWorkerScript(workerScript: WorkerScript, rerenderUi=true): void {
workerScript.env.stopFlag = true;
killNetscriptDelay(workerScript);
removeWorkerScript(workerScript, rerenderUi);
@@ -74,7 +74,7 @@ function stopAndCleanUpWorkerScript(workerScript: WorkerScript, rerenderUi: bool
* @param {WorkerScript | number} - Identifier for WorkerScript. Either the object itself, or
* its index in the global workerScripts array
*/
-function removeWorkerScript(workerScript: WorkerScript, rerenderUi: boolean=true): void {
+function removeWorkerScript(workerScript: WorkerScript, rerenderUi=true): void {
if (workerScript instanceof WorkerScript) {
const ip = workerScript.serverIp;
const name = workerScript.name;
@@ -124,7 +124,7 @@ function removeWorkerScript(workerScript: WorkerScript, rerenderUi: boolean=true
* timed, blocked operation (like hack(), sleep(), etc.). This allows scripts to
* be killed immediately even if they're in the middle of one of those long operations
*/
-function killNetscriptDelay(workerScript: WorkerScript) {
+function killNetscriptDelay(workerScript: WorkerScript): void {
if (workerScript instanceof WorkerScript) {
if (workerScript.delay) {
clearTimeout(workerScript.delay);
diff --git a/src/NetscriptBladeburner.js b/src/NetscriptBladeburner.js
index 1ac7d7eb3..c5509fd96 100644
--- a/src/NetscriptBladeburner.js
+++ b/src/NetscriptBladeburner.js
@@ -1,15 +1,9 @@
-import { Player } from "./Player";
-import { Bladeburner } from "./Bladeburner";
-import { makeRuntimeRejectMsg } from "./NetscriptEvaluator";
-
-function unknownBladeburnerActionErrorMessage(functionName, actionType, actionName) {
+export function unknownBladeburnerActionErrorMessage(functionName, actionType, actionName) {
return `ERROR: bladeburner.${functionName}() failed due to an invalid action specified. ` +
`Type: ${actionType}, Name: ${actionName}. Note that for contracts and operations, the ` +
`name of the operation is case-sensitive.`;
}
-function unknownBladeburnerExceptionMessage(functionName, err) {
+export function unknownBladeburnerExceptionMessage(functionName, err) {
return `bladeburner.${functionName}() failed with exception: ` + err;
-}
-
-export {unknownBladeburnerActionErrorMessage, unknownBladeburnerExceptionMessage, checkBladeburnerAccess};
+}
\ No newline at end of file
diff --git a/src/NetscriptEvaluator.js b/src/NetscriptEvaluator.js
index b61b217c2..8e765591c 100644
--- a/src/NetscriptEvaluator.js
+++ b/src/NetscriptEvaluator.js
@@ -1,11 +1,10 @@
import { setTimeoutRef } from "./utils/SetTimeoutRef";
-import { isValidIPAddress } from "../utils/helpers/isValidIPAddress";
import { isString } from "../utils/helpers/isString";
import { AllServers } from "./Server/AllServers";
export function netscriptDelay(time, workerScript) {
- return new Promise(function(resolve, reject) {
+ return new Promise(function(resolve) {
workerScript.delay = setTimeoutRef(() => {
workerScript.delay = null;
resolve();
@@ -62,6 +61,5 @@ export function isScriptErrorMessage(msg) {
if (splitMsg.length != 4){
return false;
}
- var ip = splitMsg[1];
return true;
}
diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js
index 4a3d81986..74d867f6c 100644
--- a/src/NetscriptFunctions.js
+++ b/src/NetscriptFunctions.js
@@ -5,11 +5,10 @@ import * as libarg from 'arg';
import { getRamCost } from "./Netscript/RamCostGenerator";
import { WorkerScriptStartStopEventEmitter } from "./Netscript/WorkerScriptStartStopEventEmitter";
-import { Augmentation } from "./Augmentation/Augmentation";
import { Augmentations } from "./Augmentation/Augmentations";
import {
augmentationExists,
- installAugmentations
+ installAugmentations,
} from "./Augmentation/AugmentationHelpers";
import { prestigeAugmentation } from "./Prestige";
import { AugmentationNames } from "./Augmentation/data/AugmentationNames";
@@ -17,7 +16,7 @@ import { BitNodeMultipliers } from "./BitNode/BitNodeMultipliers";
import { findCrime } from "./Crime/CrimeHelpers";
import { Bladeburner } from "./Bladeburner";
import { Company } from "./Company/Company";
-import { Companies, companyExists } from "./Company/Companies";
+import { Companies } from "./Company/Companies";
import { CompanyPosition } from "./Company/CompanyPosition";
import { CompanyPositions } from "./Company/CompanyPositions";
import { CONSTANTS } from "./Constants";
@@ -28,22 +27,22 @@ import {
calculatePercentMoneyHacked,
calculateHackingTime,
calculateGrowTime,
- calculateWeakenTime
+ calculateWeakenTime,
} from "./Hacking";
import { calculateServerGrowth } from "./Server/formulas/grow";
import {
AllGangs,
GangMemberUpgrades,
- GangMemberTasks
+ GangMemberTasks,
+ Gang,
} from "./Gang";
-import { Faction } from "./Faction/Faction";
import { Factions, factionExists } from "./Faction/Factions";
import { joinFaction, purchaseAugmentation } from "./Faction/FactionHelpers";
import { FactionWorkType } from "./Faction/FactionWorkTypeEnum";
import {
netscriptCanGrow,
netscriptCanHack,
- netscriptCanWeaken
+ netscriptCanWeaken,
} from "./Hacking/netscriptCanHack";
import {
@@ -74,7 +73,7 @@ import {
calculateServerCost as HScalculateServerCost,
} from "./Hacknet/formulas/HacknetServers";
import { HacknetNodeConstants, HacknetServerConstants } from "./Hacknet/data/Constants";
-import { HacknetServer, MaxNumberHacknetServers } from "./Hacknet/HacknetServer";
+import { HacknetServer } from "./Hacknet/HacknetServer";
import { CityName } from "./Locations/data/CityNames";
import { LocationName } from "./Locations/data/LocationNames";
import { Terminal } from "./Terminal";
@@ -84,7 +83,6 @@ import {
} from "./PersonObjects/formulas/skill";
import { Message } from "./Message/Message";
-import { Messages } from "./Message/MessageHelpers";
import { inMission } from "./Missions";
import { Player } from "./Player";
import { Programs } from "./Programs/Programs";
@@ -94,15 +92,12 @@ import {
findRunningScriptByPid,
} from "./Script/ScriptHelpers";
import { isScriptFilename } from "./Script/ScriptHelpersTS";
-import { _getScriptUrls } from "./NetscriptJSEvaluator";
import {
AllServers,
AddToAllServers,
createUniqueRandomIp,
} from "./Server/AllServers";
import { RunningScript } from "./Script/RunningScript";
-import { startWorkerScript } from "./NetscriptWorker";
-import { Server } from "./Server/Server";
import {
GetServerByHostname,
getServer,
@@ -114,9 +109,8 @@ import {
import {
getPurchaseServerCost,
getPurchaseServerLimit,
- getPurchaseServerMaxRam
+ getPurchaseServerMaxRam,
} from "./Server/ServerPurchases";
-import { Settings } from "./Settings/Settings";
import { SpecialServerIps } from "./Server/SpecialServerIps";
import { SourceFileFlags } from "./SourceFile/SourceFileFlags";
import {
@@ -129,7 +123,6 @@ import {
influenceStockThroughServerHack,
influenceStockThroughServerGrow,
} from "./StockMarket/PlayerInfluencing";
-import { Stock } from "./StockMarket/Stock";
import {
StockMarket,
SymbolToStockMap,
@@ -146,18 +139,15 @@ import { PositionTypes } from "./StockMarket/data/PositionTypes";
import { StockSymbols } from "./StockMarket/data/StockSymbols";
import {
getStockMarket4SDataCost,
- getStockMarket4STixApiCost
+ getStockMarket4STixApiCost,
} from "./StockMarket/StockMarketCosts";
import { isValidFilePath } from "./Terminal/DirectoryHelpers";
import { TextFile, getTextFile, createTextFile } from "./TextFile";
-import {
- unknownBladeburnerActionErrorMessage
-} from"./NetscriptBladeburner";
-import { Gang } from "./Gang";
import {
NetscriptPorts,
runScriptFromScript,
+ startWorkerScript,
} from "./NetscriptWorker";
import { killWorkerScript } from "./Netscript/killWorkerScript";
import { workerScripts } from "./Netscript/WorkerScripts";
@@ -172,18 +162,17 @@ import { SleeveTaskType } from "./PersonObjects/Sleeve/SleeveTaskTypesEnum";
import { findSleevePurchasableAugs } from "./PersonObjects/Sleeve/SleeveHelpers";
import { Exploit } from './Exploits/Exploit.ts';
-import { Page, routing } from "./ui/navigationTracking";
import { numeralWrapper } from "./ui/numeralFormat";
import { post } from "./ui/postToTerminal";
import { setTimeoutRef } from "./utils/SetTimeoutRef";
import { is2DArray } from "./utils/helpers/is2DArray";
-import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions";
+import {
+ formatNumber,
+ convertTimeMsToTimeElapsedString,
+} from "../utils/StringHelperFunctions";
-import { dialogBoxCreate } from "../utils/DialogBox";
-import { formatNumber, isHTML } from "../utils/StringHelperFunctions";
import { logBoxCreate } from "../utils/LogBox";
import { arrayToString } from "../utils/helpers/arrayToString";
-import { isPowerOfTwo } from "../utils/helpers/isPowerOfTwo";
import { isString } from "../utils/helpers/isString";
import { createElement } from "../utils/uiHelpers/createElement";
@@ -261,7 +250,7 @@ const possibleLogs = {
setTerritoryWarfare: true,
}
-const defaultInterpreter = new Interpreter('', function(){});
+const defaultInterpreter = new Interpreter('', () => undefined);
// the acorn interpreter has a bug where it doesn't convert arrays correctly.
// so we have to more or less copy it here.
@@ -351,7 +340,7 @@ function NetscriptFunctions(workerScript) {
throw makeRuntimeRejectMsg(
workerScript,
`Invalid scriptArgs argument passed into getRunningScript() from ${callingFnName}(). ` +
- `This is probably a bug. Please report to game developer`
+ `This is probably a bug. Please report to game developer`,
);
}
@@ -489,7 +478,7 @@ function NetscriptFunctions(workerScript) {
}
return null;
}
- let call = {line: "-1", func: "unknown"};;
+ let call = {line: "-1", func: "unknown"};
let chromeCall = parseChromeStackline(stackline);
if (chromeCall) {
call = chromeCall;
@@ -681,7 +670,7 @@ function NetscriptFunctions(workerScript) {
throw makeRuntimeErrorMsg('hack', canHack.msg);
}
- workerScript.log("hack", `Executing ${ip} in ${hackingTime.toFixed(3)} seconds (t=${threads})`);
+ workerScript.log("hack", `Executing ${ip} in ${convertTimeMsToTimeElapsedString(hackingTime*1000, true)} (t=${numeralWrapper.formatThreads(threads)})`);
return netscriptDelay(hackingTime * 1000, workerScript).then(function() {
if (workerScript.env.stopFlag) {return Promise.reject(workerScript);}
@@ -717,7 +706,7 @@ function NetscriptFunctions(workerScript) {
workerScript.scriptRef.recordHack(server.ip, moneyGained, threads);
Player.gainHackingExp(expGainedOnSuccess);
workerScript.scriptRef.onlineExpGained += expGainedOnSuccess;
- workerScript.log("hack", `Successfully hacked '${server.hostname}' for ${numeralWrapper.formatMoney(moneyGained)} and ${numeralWrapper.formatExp(expGainedOnSuccess)} exp (t=${threads})`);
+ workerScript.log("hack", `Successfully hacked '${server.hostname}' for ${numeralWrapper.formatMoney(moneyGained)} and ${numeralWrapper.formatExp(expGainedOnSuccess)} exp (t=${numeralWrapper.formatThreads(threads)})`);
server.fortify(CONSTANTS.ServerFortifyAmount * Math.min(threads, maxThreadNeeded));
if (stock) {
influenceStockThroughServerHack(server, moneyGained);
@@ -730,7 +719,7 @@ function NetscriptFunctions(workerScript) {
// Player only gains 25% exp for failure?
Player.gainHackingExp(expGainedOnFailure);
workerScript.scriptRef.onlineExpGained += expGainedOnFailure;
- workerScript.log("hack", `Failed to hack '${server.hostname}'. Gained ${numeralWrapper.formatExp(expGainedOnFailure)} exp (t=${threads})`);
+ workerScript.log("hack", `Failed to hack '${server.hostname}'. Gained ${numeralWrapper.formatExp(expGainedOnFailure)} exp (t=${numeralWrapper.formatThreads(threads)})`);
return Promise.resolve(0);
}
});
@@ -948,7 +937,7 @@ function NetscriptFunctions(workerScript) {
}
var growTime = calculateGrowTime(server, Player);
- workerScript.log("grow", `Executing on '${server.hostname}' in ${formatNumber(growTime, 3)} seconds (t=${threads}).`);
+ workerScript.log("grow", `Executing on '${server.hostname}' in ${convertTimeMsToTimeElapsedString(growTime*1000, true)} (t=${numeralWrapper.formatThreads(threads)}).`);
return netscriptDelay(growTime * 1000, workerScript).then(function() {
if (workerScript.env.stopFlag) {return Promise.reject(workerScript);}
const moneyBefore = server.moneyAvailable <= 0 ? 1 : server.moneyAvailable;
@@ -961,7 +950,7 @@ function NetscriptFunctions(workerScript) {
expGain = 0;
}
const logGrowPercent = (moneyAfter/moneyBefore)*100 - 100;
- workerScript.log("grow", `Available money on '${server.hostname}' grown by ${formatNumber(logGrowPercent, 6)}%. Gained ${numeralWrapper.formatExp(expGain)} hacking exp (t=${threads}).`);
+ workerScript.log("grow", `Available money on '${server.hostname}' grown by ${formatNumber(logGrowPercent, 6)}%. Gained ${numeralWrapper.formatExp(expGain)} hacking exp (t=${numeralWrapper.formatThreads(threads)}).`);
workerScript.scriptRef.onlineExpGained += expGain;
Player.gainHackingExp(expGain);
if (stock) {
@@ -999,13 +988,13 @@ function NetscriptFunctions(workerScript) {
}
var weakenTime = calculateWeakenTime(server, Player);
- workerScript.log("weaken", `Executing on '${server.hostname}' in ${formatNumber(weakenTime, 3)} seconds (t=${threads})`);
+ workerScript.log("weaken", `Executing on '${server.hostname}' in ${convertTimeMsToTimeElapsedString(weakenTime*1000, true)} (t=${numeralWrapper.formatThreads(threads)})`);
return netscriptDelay(weakenTime * 1000, workerScript).then(function() {
if (workerScript.env.stopFlag) {return Promise.reject(workerScript);}
server.weaken(CONSTANTS.ServerWeakenAmount * threads);
workerScript.scriptRef.recordWeaken(server.ip, threads);
var expGain = calculateHackingExpGain(server, Player) * threads;
- workerScript.log("weaken", `'${server.hostname}' security level weakened to ${server.hackDifficulty}. Gained ${numeralWrapper.formatExp(expGain)} hacking exp (t=${threads})`);
+ workerScript.log("weaken", `'${server.hostname}' security level weakened to ${server.hackDifficulty}. Gained ${numeralWrapper.formatExp(expGain)} hacking exp (t=${numeralWrapper.formatThreads(threads)})`);
workerScript.scriptRef.onlineExpGained += expGain;
Player.gainHackingExp(expGain);
return Promise.resolve(CONSTANTS.ServerWeakenAmount * threads);
@@ -1343,7 +1332,7 @@ function NetscriptFunctions(workerScript) {
scriptname.forEach(function(script) {
if (NetscriptFunctions(workerScript).scp(script, ip1, ip2)) {
res = true;
- };
+ }
});
return res;
}
@@ -1630,7 +1619,7 @@ function NetscriptFunctions(workerScript) {
},
getBitNodeMultipliers: function() {
updateDynamicRam("getBitNodeMultipliers", getRamCost("getBitNodeMultipliers"));
- if (SourceFileFlags[5] <= 0) {
+ if (SourceFileFlags[5] <= 0 && Player.bitNodeN !== 5) {
throw makeRuntimeErrorMsg("getBitNodeMultipliers", "Requires Source-File 5 to run.");
}
let copy = Object.assign({}, BitNodeMultipliers);
@@ -1720,6 +1709,18 @@ function NetscriptFunctions(workerScript) {
workerScript.log("getServerRam", `returned [${formatNumber(server.maxRam, 2)}GB, ${formatNumber(server.ramUsed, 2)}GB]`);
return [server.maxRam, server.ramUsed];
},
+ getServerMaxRam: function(ip) {
+ updateDynamicRam("getServerMaxRam", getRamCost("getServerMaxRam"));
+ const server = safeGetServer(ip, "getServerMaxRam");
+ workerScript.log("getServerMaxRam", `returned ${formatNumber(server.maxRam, 2)}GB`);
+ return server.maxRam;
+ },
+ getServerUsedRam: function(ip) {
+ updateDynamicRam("getServerUsedRam", getRamCost("getServerUsedRam"));
+ const server = safeGetServer(ip, "getServerUsedRam");
+ workerScript.log("getServerUsedRam", `returned ${formatNumber(server.ramUsed, 2)}GB`);
+ return server.ramUsed;
+ },
serverExists: function(ip) {
updateDynamicRam("serverExists", getRamCost("serverExists"));
return (getServer(ip) !== null);
@@ -1965,7 +1966,7 @@ function NetscriptFunctions(workerScript) {
shares: shares,
price: price,
type: orderType,
- pos: orderPos
+ pos: orderPos,
};
return cancelOrder(params, workerScript);
},
@@ -2468,21 +2469,21 @@ function NetscriptFunctions(workerScript) {
threads: runningScript.threads,
};
},
- getHackTime: function(ip, hack, int) {
+ getHackTime: function(ip) {
updateDynamicRam("getHackTime", getRamCost("getHackTime"));
const server = safeGetServer(ip, "getHackTime");
if (failOnHacknetServer(server, "getHackTime")) { return Infinity; }
return calculateHackingTime(server, Player); // Returns seconds
},
- getGrowTime: function(ip, hack, int) {
+ getGrowTime: function(ip) {
updateDynamicRam("getGrowTime", getRamCost("getGrowTime"));
const server = safeGetServer(ip, "getGrowTime");
if (failOnHacknetServer(server, "getGrowTime")) { return Infinity; }
return calculateGrowTime(server, Player); // Returns seconds
},
- getWeakenTime: function(ip, hack, int) {
+ getWeakenTime: function(ip) {
updateDynamicRam("getWeakenTime", getRamCost("getWeakenTime"));
const server = safeGetServer(ip, "getWeakenTime");
if (failOnHacknetServer(server, "getWeakenTime")) { return Infinity; }
@@ -2570,7 +2571,7 @@ function NetscriptFunctions(workerScript) {
const popupId = `prompt-popup-${txt.slice(0, 20)}`;
const textElement = createElement("p", { innerHTML: txt });
- return new Promise(function(resolve, reject) {
+ return new Promise(function(resolve) {
const yesBtn = createElement("button", {
class: "popup-box-button",
innerText: "Yes",
@@ -2598,7 +2599,7 @@ function NetscriptFunctions(workerScript) {
return Promise.resolve(false);
}
var s = safeGetServer(ip, "wget");
- return new Promise(function(resolve, reject) {
+ return new Promise(function(resolve) {
$.get(url, function(data) {
let res;
if (isScriptFilename(target)) {
@@ -2832,7 +2833,7 @@ function NetscriptFunctions(workerScript) {
var darkweb = safetlyCreateUniqueServer({
ip: createUniqueRandomIp(), hostname:"darkweb", organizationName:"",
- isConnectedTo:false, adminRights:false, purchasedByPlayer:false, maxRam:1
+ isConnectedTo:false, adminRights:false, purchasedByPlayer:false, maxRam:1,
});
AddToAllServers(darkweb);
SpecialServerIps.addIp("Darkweb Server", darkweb.ip);
@@ -2943,7 +2944,7 @@ function NetscriptFunctions(workerScript) {
dexterity: Player.dexterity,
agility: Player.agility,
charisma: Player.charisma,
- intelligence: Player.intelligence
+ intelligence: Player.intelligence,
}
},
getCharacterInformation: function() {
@@ -4087,7 +4088,7 @@ function NetscriptFunctions(workerScript) {
updateDynamicRam("getBonusTime", getRamCost("bladeburner", "getBonusTime"));
checkBladeburnerAccess("getBonusTime");
return Math.round(Player.bladeburner.storedCycles / 5);
- }
+ },
}, // End Bladeburner
// Coding Contract API
@@ -4373,7 +4374,7 @@ function NetscriptFunctions(workerScript) {
}
return Player.sleeves[sleeveNumber].tryBuyAugmentation(Player, aug);
- }
+ },
}, // End sleeve
formulas: {
basic: {
@@ -4438,7 +4439,7 @@ function NetscriptFunctions(workerScript) {
constants: function() {
checkFormulasAccess("hacknetNodes.constants", 5);
return Object.assign({}, HacknetNodeConstants, HacknetServerConstants);
- }
+ },
},
hacknetServers: {
hashGainRate: function(level, ram, cores, mult=1) {
@@ -4476,14 +4477,14 @@ function NetscriptFunctions(workerScript) {
constants: function() {
checkFormulasAccess("hacknetServers.constants", 9);
return Object.assign({}, HacknetServerConstants);
- }
+ },
},
}, // end formulas
heart: {
// Easter egg function
break: function() {
return Player.karma;
- }
+ },
},
exploit: function() {
Player.giveExploit(Exploit.UndocumentedFunctionCall);
@@ -4515,7 +4516,7 @@ function NetscriptFunctions(workerScript) {
ret[key.slice(2)] = value;
}
return ret;
- }
+ },
} // End return
} // End NetscriptFunction()
diff --git a/src/NetscriptJSEvaluator.js b/src/NetscriptJSEvaluator.js
index 257992797..ba8d5f5c3 100644
--- a/src/NetscriptJSEvaluator.js
+++ b/src/NetscriptJSEvaluator.js
@@ -1,5 +1,4 @@
import { makeRuntimeRejectMsg } from "./NetscriptEvaluator";
-import { Script } from "./Script/Script";
import { ScriptUrl } from "./Script/ScriptUrl";
// Makes a blob that contains the code of a given script.
@@ -49,7 +48,7 @@ export async function executeJSScript(scripts = [], workerScript) {
if (urls != null) {
for (const b in urls) URL.revokeObjectURL(b.url);
}
- };
+ }
}
/** Returns whether we should compile the script parameter.
@@ -121,7 +120,7 @@ export function _getScriptUrls(script, scripts, seen) {
// The top url in the stack is the replacement import file for this script.
urlStack.push(...urls);
return [prefix, urls[urls.length - 1].url, suffix].join('');
- }
+ },
);
// We automatically define a print function() in the NetscriptJS module so that
diff --git a/src/NetscriptPort.ts b/src/NetscriptPort.ts
index d9c5ea2a7..9dfcb5e48 100644
--- a/src/NetscriptPort.ts
+++ b/src/NetscriptPort.ts
@@ -3,8 +3,7 @@ import { Settings } from "./Settings/Settings";
export class NetscriptPort {
data: any[] = [];
- constructor() {}
-
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
write(data: any): any {
this.data.push(data);
if (this.data.length > Settings.MaxPortCapacity) {
@@ -13,6 +12,7 @@ export class NetscriptPort {
return null;
}
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
tryWrite(data: any): boolean {
if (this.data.length >= Settings.MaxPortCapacity) {
return false;
@@ -32,7 +32,7 @@ export class NetscriptPort {
if (this.data.length === 0) {
return "NULL PORT DATA";
} else {
- var foo = this.data.slice();
+ const foo = this.data.slice();
return foo[0];
}
}
diff --git a/src/NetscriptWorker.js b/src/NetscriptWorker.js
index 7b9803ab3..9ab2f1d02 100644
--- a/src/NetscriptWorker.js
+++ b/src/NetscriptWorker.js
@@ -21,10 +21,7 @@ import { NetscriptPort } from "./NetscriptPort";
import { Player } from "./Player";
import { RunningScript } from "./Script/RunningScript";
import { getRamUsageFromRunningScript } from "./Script/RunningScriptHelpers";
-import {
- findRunningScript,
- scriptCalculateOfflineProduction,
-} from "./Script/ScriptHelpers";
+import { scriptCalculateOfflineProduction } from "./Script/ScriptHelpers";
import { AllServers } from "./Server/AllServers";
import { Settings } from "./Settings/Settings";
import { setTimeoutRef } from "./utils/SetTimeoutRef";
@@ -32,12 +29,11 @@ import { setTimeoutRef } from "./utils/SetTimeoutRef";
import { generate } from "escodegen";
import { dialogBoxCreate } from "../utils/DialogBox";
-import { compareArrays } from "../utils/helpers/compareArrays";
import { arrayToString } from "../utils/helpers/arrayToString";
import { roundToTwo } from "../utils/helpers/roundToTwo";
import { isString } from "../utils/StringHelperFunctions";
-import { parse, Node } from "acorn";
+import { parse } from "acorn";
const walk = require("acorn-walk");
// Netscript Ports are instantiated here
@@ -111,7 +107,7 @@ function startNetscript2Script(workerScript) {
return result;
}
}
- };
+ }
for (let prop in workerScript.env.vars) {
if (typeof workerScript.env.vars[prop] !== "function") continue;
@@ -180,8 +176,8 @@ function startNetscript1Script(workerScript) {
let fnPromise = entry.apply(null, fnArgs);
fnPromise.then(function(res) {
cb(res);
- }).catch(function(e) {
- // Do nothing?
+ }).catch(function(err) {
+ console.error(err);
});
}
int.setProperty(scope, name, int.createAsyncFunction(tempWrapper));
@@ -330,7 +326,7 @@ function processNetscript1Imports(code, workerScript) {
FunctionDeclaration: (node) => {
fnNames.push(node.id.name);
fnDeclarations.push(node);
- }
+ },
});
//Now we have to generate the code that would create the namespace
@@ -370,7 +366,7 @@ function processNetscript1Imports(code, workerScript) {
if (fnsToImport.includes(node.id.name)) {
fnDeclarations.push(node);
}
- }
+ },
});
//Convert FunctionDeclarations into code
@@ -379,7 +375,7 @@ function processNetscript1Imports(code, workerScript) {
generatedCode += "\n";
});
}
- }
+ },
});
//If there are no imports, just return the original code
@@ -408,7 +404,7 @@ function processNetscript1Imports(code, workerScript) {
var res = {
code: code,
- lineOffset: lineOffset
+ lineOffset: lineOffset,
}
return res;
}
@@ -443,8 +439,6 @@ export function startWorkerScript(runningScript, server) {
* returns {boolean} indicating whether or not the workerScript was successfully added
*/
export function createAndAddWorkerScript(runningScriptObj, server) {
- const filename = runningScriptObj.filename;
-
// Update server's ram usage
let threads = 1;
if (runningScriptObj.threads && !isNaN(runningScriptObj.threads)) {
@@ -459,7 +453,7 @@ export function createAndAddWorkerScript(runningScriptObj, server) {
`Not enough RAM to run script ${runningScriptObj.filename} with args ` +
`${arrayToString(runningScriptObj.args)}. This likely occurred because you re-loaded ` +
`the game and the script's RAM usage increased (either because of an update to the game or ` +
- `your changes to the script.)`
+ `your changes to the script.)`,
);
return false;
}
@@ -470,7 +464,7 @@ export function createAndAddWorkerScript(runningScriptObj, server) {
if (pid === -1) {
throw new Error(
`Failed to start script because could not find available PID. This is most ` +
- `because you have too many scripts running.`
+ `because you have too many scripts running.`,
);
}
diff --git a/src/PersonObjects/IPlayer.ts b/src/PersonObjects/IPlayer.ts
index bb1f26a24..1be384676 100644
--- a/src/PersonObjects/IPlayer.ts
+++ b/src/PersonObjects/IPlayer.ts
@@ -156,7 +156,7 @@ export interface IPlayer {
regenerateHp(amt: number): void;
recordMoneySource(amt: number, source: string): void;
setMoney(amt: number): void;
- startBladeburner(p: object): void;
+ startBladeburner(p: any): void;
startClass(costMult: number, expMult: number, className: string): void;
startCorporation(corpName: string, additionalShares?: number): void;
startCrime(crimeType: string,
diff --git a/src/PersonObjects/Person.ts b/src/PersonObjects/Person.ts
index 8e6619156..dd4eb1176 100644
--- a/src/PersonObjects/Person.ts
+++ b/src/PersonObjects/Person.ts
@@ -1,6 +1,5 @@
// Base class representing a person-like object
import { Augmentation } from "../Augmentation/Augmentation";
-import { Augmentations } from "../Augmentation/Augmentations";
import { IPlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { CityName } from "../Locations/data/CityNames";
@@ -36,67 +35,67 @@ export abstract class Person {
/**
* Stats
*/
- hacking_skill: number = 1;
- strength: number = 1;
- defense: number = 1;
- dexterity: number = 1;
- agility: number = 1;
- charisma: number = 1;
- intelligence: number = 1;
- hp: number = 10;
- max_hp: number = 10;
+ hacking_skill = 1;
+ strength = 1;
+ defense = 1;
+ dexterity = 1;
+ agility = 1;
+ charisma = 1;
+ intelligence = 1;
+ hp = 10;
+ max_hp = 10;
/**
* Experience
*/
- hacking_exp: number = 0;
- strength_exp: number = 0;
- defense_exp: number = 0;
- dexterity_exp: number = 0;
- agility_exp: number = 0;
- charisma_exp: number = 0;
- intelligence_exp: number = 0;
+ hacking_exp = 0;
+ strength_exp = 0;
+ defense_exp = 0;
+ dexterity_exp = 0;
+ agility_exp = 0;
+ charisma_exp = 0;
+ intelligence_exp = 0;
/**
* Multipliers
*/
- hacking_mult: number = 1;
- strength_mult: number = 1;
- defense_mult: number = 1;
- dexterity_mult: number = 1;
- agility_mult: number = 1;
- charisma_mult: number = 1;
+ hacking_mult = 1;
+ strength_mult = 1;
+ defense_mult = 1;
+ dexterity_mult = 1;
+ agility_mult = 1;
+ charisma_mult = 1;
- hacking_exp_mult: number = 1;
- strength_exp_mult: number = 1;
- defense_exp_mult: number = 1;
- dexterity_exp_mult: number = 1;
- agility_exp_mult: number = 1;
- charisma_exp_mult: number = 1;
+ hacking_exp_mult = 1;
+ strength_exp_mult = 1;
+ defense_exp_mult = 1;
+ dexterity_exp_mult = 1;
+ agility_exp_mult = 1;
+ charisma_exp_mult = 1;
- hacking_chance_mult: number = 1;
- hacking_speed_mult: number = 1;
- hacking_money_mult: number = 1;
- hacking_grow_mult: number = 1;
+ hacking_chance_mult = 1;
+ hacking_speed_mult = 1;
+ hacking_money_mult = 1;
+ hacking_grow_mult = 1;
- company_rep_mult: number = 1;
- faction_rep_mult: number = 1;
+ company_rep_mult = 1;
+ faction_rep_mult = 1;
- crime_money_mult: number = 1;
- crime_success_mult: number = 1;
+ crime_money_mult = 1;
+ crime_success_mult = 1;
- work_money_mult: number = 1;
+ work_money_mult = 1;
- hacknet_node_money_mult: number = 1;
- hacknet_node_purchase_cost_mult: number = 1;
- hacknet_node_ram_cost_mult: number = 1;
- hacknet_node_core_cost_mult: number = 1;
- hacknet_node_level_cost_mult: number = 1;
+ hacknet_node_money_mult = 1;
+ hacknet_node_purchase_cost_mult = 1;
+ hacknet_node_ram_cost_mult = 1;
+ hacknet_node_core_cost_mult = 1;
+ hacknet_node_level_cost_mult = 1;
- bladeburner_max_stamina_mult: number = 1;
- bladeburner_stamina_gain_mult: number = 1;
- bladeburner_analysis_mult: number = 1;
- bladeburner_success_chance_mult : number = 1;
+ bladeburner_max_stamina_mult = 1;
+ bladeburner_stamina_gain_mult = 1;
+ bladeburner_analysis_mult = 1;
+ bladeburner_success_chance_mult = 1;
/**
* Augmentations
@@ -109,12 +108,10 @@ export abstract class Person {
*/
city: CityName = CityName.Sector12;
- constructor() {}
-
/**
* Updates this object's multipliers for the given augmentation
*/
- applyAugmentation(aug: Augmentation) {
+ applyAugmentation(aug: Augmentation): void {
for (const mult in aug.mults) {
if ((this)[mult] == null) {
console.warn(`Augmentation has unrecognized multiplier property: ${mult}`);
@@ -128,7 +125,7 @@ export abstract class Person {
* Given an experience amount and stat multiplier, calculates the
* stat level. Stat-agnostic (same formula for every stat)
*/
- calculateStat(exp: number, mult: number=1): number {
+ calculateStat(exp: number, mult=1): number {
return calculateSkill(exp, mult);
}
diff --git a/src/PersonObjects/Player/PlayerObject.js b/src/PersonObjects/Player/PlayerObject.js
index c3b736719..cf30a50d9 100644
--- a/src/PersonObjects/Player/PlayerObject.js
+++ b/src/PersonObjects/Player/PlayerObject.js
@@ -12,7 +12,7 @@ import { MoneySourceTracker } from "../../utils/MoneySourceTracker";
import {
Reviver,
Generic_toJSON,
- Generic_fromJSON
+ Generic_fromJSON,
} from "../../../utils/JSONReviver";
import Decimal from "decimal.js";
@@ -203,7 +203,7 @@ export function PlayerObject() {
this.scriptProdSinceLastAug = 0;
this.exploits = [];
-};
+}
// Apply player methods to the prototype using Object.assign()
Object.assign(
@@ -213,7 +213,7 @@ Object.assign(
bladeburnerMethods,
corporationMethods,
gangMethods,
- augmentationMethods
+ augmentationMethods,
);
PlayerObject.prototype.toJSON = function() {
diff --git a/src/PersonObjects/Player/PlayerObjectCorporationMethods.js b/src/PersonObjects/Player/PlayerObjectCorporationMethods.js
index a1d358232..216109d3d 100644
--- a/src/PersonObjects/Player/PlayerObjectCorporationMethods.js
+++ b/src/PersonObjects/Player/PlayerObjectCorporationMethods.js
@@ -12,7 +12,7 @@ export function hasCorporation() {
export function startCorporation(corpName, additionalShares=0) {
this.corporation = new Corporation({
- name: corpName
+ name: corpName,
});
this.corporation.totalShares += additionalShares;
diff --git a/src/PersonObjects/Player/PlayerObjectGeneralMethods.jsx b/src/PersonObjects/Player/PlayerObjectGeneralMethods.jsx
index 922721b61..76f1de7aa 100644
--- a/src/PersonObjects/Player/PlayerObjectGeneralMethods.jsx
+++ b/src/PersonObjects/Player/PlayerObjectGeneralMethods.jsx
@@ -3,7 +3,6 @@ import { applyAugmentation } from "../../Augmentation/AugmentationHelpers";
import { PlayerOwnedAugmentation } from "../../Augmentation/PlayerOwnedAugmentation";
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
-import { Bladeburner } from "../../Bladeburner";
import { CodingContractRewardType } from "../../CodingContracts";
import { Company } from "../../Company/Company";
import { Companies } from "../../Company/Companies";
@@ -12,7 +11,6 @@ import { getJobRequirementText } from "../../Company/GetJobRequirementText";
import { CompanyPositions } from "../../Company/CompanyPositions";
import * as posNames from "../../Company/data/companypositionnames";
import {CONSTANTS} from "../../Constants";
-import { Corporation } from "../../Corporation/Corporation";
import { Programs } from "../../Programs/Programs";
import { determineCrimeSuccess } from "../../Crime/CrimeHelpers";
import { Crimes } from "../../Crime/Crimes";
@@ -22,7 +20,6 @@ import { Factions } from "../../Faction/Factions";
import { displayFactionContent } from "../../Faction/FactionHelpers";
import { resetGangs } from "../../Gang";
import { hasHacknetServers } from "../../Hacknet/HacknetHelpers";
-import { HashManager } from "../../Hacknet/HashManager";
import { Cities } from "../../Locations/Cities";
import { Locations } from "../../Locations/Locations";
import { CityName } from "../../Locations/data/CityNames";
@@ -56,12 +53,7 @@ import { numeralWrapper } from "../../ui/numeralFormat";
import { MoneySourceTracker } from "../../utils/MoneySourceTracker";
import { dialogBoxCreate } from "../../../utils/DialogBox";
import { clearEventListeners } from "../../../utils/uiHelpers/clearEventListeners";
-import {
- Reviver,
- Generic_toJSON,
- Generic_fromJSON,
-} from "../../../utils/JSONReviver";
-import {convertTimeMsToTimeElapsedString} from "../../../utils/StringHelperFunctions";
+import { convertTimeMsToTimeElapsedString } from "../../../utils/StringHelperFunctions";
import { Reputation } from "../../ui/React/Reputation";
import { Money } from "../../ui/React/Money";
@@ -614,7 +606,6 @@ export function startWork(companyName) {
}
export function cancelationPenalty() {
- const company = Companies[this.companyName];
const specialIp = SpecialServerIps[this.companyName];
if(specialIp) {
const server = AllServers[specialIp];
@@ -1226,7 +1217,7 @@ export function createProgramWork(numCycles) {
>, elem);
}
-export function finishCreateProgramWork(cancelled, sing=false) {
+export function finishCreateProgramWork(cancelled) {
var programName = this.createProgramName;
if (cancelled === false) {
dialogBoxCreate("You've finished creating " + programName + "! " +
@@ -1313,11 +1304,11 @@ export function startClass(costMult, expMult, className) {
this.workMoneyLossRate = cost;
this.workHackExpGainRate = hackExp * this.hacking_exp_mult * BitNodeMultipliers.ClassGymExpGain;
- this.workStrExpGainRate = strExp * this.strength_exp_mult * BitNodeMultipliers.ClassGymExpGain;;
- this.workDefExpGainRate = defExp * this.defense_exp_mult * BitNodeMultipliers.ClassGymExpGain;;
- this.workDexExpGainRate = dexExp * this.dexterity_exp_mult * BitNodeMultipliers.ClassGymExpGain;;
- this.workAgiExpGainRate = agiExp * this.agility_exp_mult * BitNodeMultipliers.ClassGymExpGain;;
- this.workChaExpGainRate = chaExp * this.charisma_exp_mult * BitNodeMultipliers.ClassGymExpGain;;
+ this.workStrExpGainRate = strExp * this.strength_exp_mult * BitNodeMultipliers.ClassGymExpGain;
+ this.workDefExpGainRate = defExp * this.defense_exp_mult * BitNodeMultipliers.ClassGymExpGain;
+ this.workDexExpGainRate = dexExp * this.dexterity_exp_mult * BitNodeMultipliers.ClassGymExpGain;
+ this.workAgiExpGainRate = agiExp * this.agility_exp_mult * BitNodeMultipliers.ClassGymExpGain;
+ this.workChaExpGainRate = chaExp * this.charisma_exp_mult * BitNodeMultipliers.ClassGymExpGain;
var cancelButton = clearEventListeners("work-in-progress-cancel-button");
if (className == CONSTANTS.ClassGymStrength ||
@@ -1460,7 +1451,6 @@ export function commitCrime(numCycles) {
export function finishCrime(cancelled) {
//Determine crime success/failure
if (!cancelled) {
- var statusText = ""; // TODO, unique message for each crime when you succeed
if (determineCrimeSuccess(this, this.crimeType)) {
//Handle Karma and crime statistics
let crime = null;
@@ -1580,7 +1570,7 @@ export function singularityStopWork() {
res = this.finishFactionWork(true, true);
break;
case CONSTANTS.WorkTypeCreateProgram:
- res = this.finishCreateProgramWork(true, true);
+ res = this.finishCreateProgramWork(true);
break;
case CONSTANTS.WorkTypeCrime:
res = this.finishCrime(true);
diff --git a/src/PersonObjects/Player/PlayerObjectServerMethods.ts b/src/PersonObjects/Player/PlayerObjectServerMethods.ts
index 84ec0a79f..e2053c392 100644
--- a/src/PersonObjects/Player/PlayerObjectServerMethods.ts
+++ b/src/PersonObjects/Player/PlayerObjectServerMethods.ts
@@ -6,6 +6,7 @@ import { IPlayer } from "../IPlayer";
import { CONSTANTS } from "../../Constants";
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
+import { Server } from "../../Server/Server";
import { HacknetServer } from "../../Hacknet/HacknetServer";
import {
AddToAllServers,
@@ -14,19 +15,19 @@ import {
} from "../../Server/AllServers";
import { SpecialServerIps } from "../../Server/SpecialServerIps";
-export function hasTorRouter(this: IPlayer) {
+export function hasTorRouter(this: IPlayer): boolean {
return SpecialServerIps.hasOwnProperty("Darkweb Server");
}
-export function getCurrentServer(this: IPlayer) {
+export function getCurrentServer(this: IPlayer): Server | HacknetServer | null {
return AllServers[this.currentServer];
}
-export function getHomeComputer(this: IPlayer) {
+export function getHomeComputer(this: IPlayer): Server | HacknetServer | null {
return AllServers[this.homeComputer];
}
-export function getUpgradeHomeRamCost(this: IPlayer) {
+export function getUpgradeHomeRamCost(this: IPlayer): number {
//Calculate how many times ram has been upgraded (doubled)
const currentRam = this.getHomeComputer().maxRam;
const numUpgrades = Math.log2(currentRam);
@@ -34,7 +35,7 @@ export function getUpgradeHomeRamCost(this: IPlayer) {
//Calculate cost
//Have cost increase by some percentage each time RAM has been upgraded
const mult = Math.pow(1.58, numUpgrades);
- var cost = currentRam * CONSTANTS.BaseCostFor1GBOfRamHome * mult * BitNodeMultipliers.HomeComputerRamCost;
+ const cost = currentRam * CONSTANTS.BaseCostFor1GBOfRamHome * mult * BitNodeMultipliers.HomeComputerRamCost;
return cost;
}
diff --git a/src/PersonObjects/Resleeving/Resleeve.ts b/src/PersonObjects/Resleeving/Resleeve.ts
index 0cd330ad0..c289ac7ab 100644
--- a/src/PersonObjects/Resleeving/Resleeve.ts
+++ b/src/PersonObjects/Resleeving/Resleeve.ts
@@ -10,12 +10,6 @@ import { Augmentations } from "../../Augmentation/Augmentations";
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../../utils/JSONReviver";
export class Resleeve extends Person {
- /**
- * Initiatizes a Resleeve object from a JSON save state.
- */
- static fromJSON(value: any): Resleeve {
- return Generic_fromJSON(Resleeve, value.data);
- }
constructor() {
super();
@@ -23,13 +17,13 @@ export class Resleeve extends Person {
getCost(): number {
// Each experience point adds this to the cost
- const CostPerExp: number = 25e3;
+ const CostPerExp = 25e3;
// Final cost is multiplied by this constant ^ # Augs
- const NumAugsExponent: number = 1.2;
+ const NumAugsExponent = 1.2;
// Get total exp in this re-sleeve
- let totalExp: number = this.hacking_exp +
+ const totalExp: number = this.hacking_exp +
this.strength_exp +
this.defense_exp +
this.dexterity_exp +
@@ -37,14 +31,14 @@ export class Resleeve extends Person {
this.charisma_exp;
// Get total base Augmentation cost for this re-sleeve
- let totalAugmentationCost: number = 0;
+ let totalAugmentationCost = 0;
for (let i = 0; i < this.augmentations.length; ++i) {
const aug: Augmentation | null = Augmentations[this.augmentations[i].name];
if (aug == null) {
console.error(`Could not find Augmentation ${this.augmentations[i].name}`);
continue;
}
- totalAugmentationCost += aug!.startingCost;
+ totalAugmentationCost += aug.startingCost;
}
return (totalExp * CostPerExp) + (totalAugmentationCost * Math.pow(NumAugsExponent, this.augmentations.length));
@@ -56,6 +50,14 @@ export class Resleeve extends Person {
toJSON(): any {
return Generic_toJSON("Resleeve", this);
}
+
+ /**
+ * Initiatizes a Resleeve object from a JSON save state.
+ */
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+ static fromJSON(value: any): Resleeve {
+ return Generic_fromJSON(Resleeve, value.data);
+ }
}
Reviver.constructors.Resleeve = Resleeve;
diff --git a/src/PersonObjects/Resleeving/Resleeving.ts b/src/PersonObjects/Resleeving/Resleeving.ts
index 9b158145c..1c09b9cbf 100644
--- a/src/PersonObjects/Resleeving/Resleeving.ts
+++ b/src/PersonObjects/Resleeving/Resleeving.ts
@@ -76,12 +76,12 @@ export function purchaseResleeve(r: Resleeve, p: IPlayer): boolean {
// Creates all of the Re-sleeves that will be available for purchase at VitaLife
export function generateResleeves(): Resleeve[] {
- const NumResleeves: number = 40; // Total number of Resleeves to generate
+ const NumResleeves = 40; // Total number of Resleeves to generate
- let ret: Resleeve[] = [];
+ const ret: Resleeve[] = [];
for (let i = 0; i < NumResleeves; ++i) {
// i will be a number indicating how "powerful" the Re-sleeve should be
- let r: Resleeve = new Resleeve();
+ const r: Resleeve = new Resleeve();
// Generate experience
const expMult: number = (5 * i) + 1;
@@ -108,7 +108,8 @@ export function generateResleeves(): Resleeve[] {
}
const randAug: Augmentation | null = Augmentations[randKey];
- r.augmentations.push({name: randAug!.name, level: 1});
+ if(randAug === null) throw new Error(`null augmentation: ${randKey}`)
+ r.augmentations.push({name: randAug.name, level: 1});
r.applyAugmentation(Augmentations[randKey]);
r.updateStatLevels();
diff --git a/src/PersonObjects/Resleeving/ResleevingUI.tsx b/src/PersonObjects/Resleeving/ResleevingUI.tsx
index 4957e6dd1..9dab831a9 100644
--- a/src/PersonObjects/Resleeving/ResleevingUI.tsx
+++ b/src/PersonObjects/Resleeving/ResleevingUI.tsx
@@ -61,7 +61,7 @@ const UIElems: IPageUIElems = {
let playerRef: IPlayer | null;
-export function createResleevesPage(p: IPlayer) {
+export function createResleevesPage(p: IPlayer): void {
if (!routing.isOn(Page.Resleeves)) { return; }
try {
@@ -98,7 +98,7 @@ export function createResleevesPage(p: IPlayer) {
// Create a selector for sorting the list of Resleeves
UIElems.sortTag = createElement("p", {
display: "inline-block",
- innerText: "Sort By: "
+ innerText: "Sort By: ",
});
UIElems.sortSelector = createElement("select", { class: "dropdown" }) as HTMLSelectElement;
@@ -115,25 +115,25 @@ export function createResleevesPage(p: IPlayer) {
TotalNumAugmentations = "TotalNumAugmentations",
}
- UIElems.sortSelector!.add(createOptionElement("Cost", SortOption.Cost));
- UIElems.sortSelector!.add(createOptionElement("Hacking Level", SortOption.Hacking));
- UIElems.sortSelector!.add(createOptionElement("Strength Level", SortOption.Strength));
- UIElems.sortSelector!.add(createOptionElement("Defense Level", SortOption.Defense));
- UIElems.sortSelector!.add(createOptionElement("Dexterity Level", SortOption.Dexterity));
- UIElems.sortSelector!.add(createOptionElement("Agility Level", SortOption.Agility));
- UIElems.sortSelector!.add(createOptionElement("Charisma Level", SortOption.Charisma));
- UIElems.sortSelector!.add(createOptionElement("Average Combat Stats", SortOption.AverageCombatStats));
- UIElems.sortSelector!.add(createOptionElement("Average Stats", SortOption.AverageAllStats));
- UIElems.sortSelector!.add(createOptionElement("Number of Augmentations", SortOption.TotalNumAugmentations));
+ UIElems.sortSelector.add(createOptionElement("Cost", SortOption.Cost));
+ UIElems.sortSelector.add(createOptionElement("Hacking Level", SortOption.Hacking));
+ UIElems.sortSelector.add(createOptionElement("Strength Level", SortOption.Strength));
+ UIElems.sortSelector.add(createOptionElement("Defense Level", SortOption.Defense));
+ UIElems.sortSelector.add(createOptionElement("Dexterity Level", SortOption.Dexterity));
+ UIElems.sortSelector.add(createOptionElement("Agility Level", SortOption.Agility));
+ UIElems.sortSelector.add(createOptionElement("Charisma Level", SortOption.Charisma));
+ UIElems.sortSelector.add(createOptionElement("Average Combat Stats", SortOption.AverageCombatStats));
+ UIElems.sortSelector.add(createOptionElement("Average Stats", SortOption.AverageAllStats));
+ UIElems.sortSelector.add(createOptionElement("Number of Augmentations", SortOption.TotalNumAugmentations));
UIElems.resleeveList = createElement("ul");
- UIElems.sortSelector!.onchange = () => {
+ UIElems.sortSelector.onchange = () => {
removeChildrenFromElement(UIElems.resleeveList);
UIElems.resleeves = [];
// Helper function for averaging
- function getAverage(...values: number[]) {
- let sum: number = 0;
+ function getAverage(...values: number[]): number {
+ let sum = 0;
for (let i = 0; i < values.length; ++i) {
sum += values[i];
}
@@ -141,7 +141,7 @@ export function createResleevesPage(p: IPlayer) {
return sum / values.length;
}
- const sortOpt = getSelectValue(UIElems.sortSelector!);
+ const sortOpt = getSelectValue(UIElems.sortSelector);
switch (sortOpt) {
case SortOption.Hacking:
p.resleeves.sort((a, b) => {
@@ -175,16 +175,16 @@ export function createResleevesPage(p: IPlayer) {
break;
case SortOption.AverageCombatStats:
p.resleeves.sort((a, b) => {
- let aAvg = getAverage(a.strength, a.defense, a.dexterity, a.agility);
- let bAvg = getAverage(b.strength, b.defense, b.dexterity, b.agility);
+ const aAvg = getAverage(a.strength, a.defense, a.dexterity, a.agility);
+ const bAvg = getAverage(b.strength, b.defense, b.dexterity, b.agility);
return aAvg - bAvg;
});
break;
case SortOption.AverageAllStats:
p.resleeves.sort((a, b) => {
- let aAvg = getAverage(a.hacking_skill, a.strength, a.defense, a.dexterity, a.agility, a.charisma);
- let bAvg = getAverage(b.hacking_skill, b.strength, b.defense, b.dexterity, b.agility, b.charisma);
+ const aAvg = getAverage(a.hacking_skill, a.strength, a.defense, a.dexterity, a.agility, a.charisma);
+ const bAvg = getAverage(b.hacking_skill, b.strength, b.defense, b.dexterity, b.agility, b.charisma);
return aAvg - bAvg;
});
@@ -202,14 +202,18 @@ export function createResleevesPage(p: IPlayer) {
break;
}
+ if(UIElems.resleeveList == null) throw new Error("UIElems.resleeveList is null in sortSelector.click()");
+ if(UIElems.resleeves == null) throw new Error("UIElems.resleeves is null in sortSelector.click()");
+
// Create UI for all Resleeves
for (const resleeve of p.resleeves) {
const resleeveUi = createResleeveUi(resleeve);
- UIElems.resleeveList!.appendChild(resleeveUi.container!);
- UIElems.resleeves!.push(resleeveUi);
+ if(resleeveUi.container == null) throw new Error("resleeveUi.container is null in sortSelector.click()");
+ UIElems.resleeveList.appendChild(resleeveUi.container);
+ UIElems.resleeves.push(resleeveUi);
}
}
- UIElems.sortSelector!.dispatchEvent(new Event('change')); // Force onchange event
+ UIElems.sortSelector.dispatchEvent(new Event('change')); // Force onchange event
UIElems.container.appendChild(UIElems.info);
UIElems.container.appendChild(createElement("br"));
@@ -217,13 +221,15 @@ export function createResleevesPage(p: IPlayer) {
UIElems.container.appendChild(UIElems.sortSelector);
UIElems.container.appendChild(UIElems.resleeveList);
- document.getElementById("entire-game-container")!.appendChild(UIElems.container);
+ const container = document.getElementById("entire-game-container");
+ if(container == null) throw new Error("Could not find entire-game-container in createResleevesPage()");
+ container.appendChild(UIElems.container);
} catch(e) {
exceptionAlert(e);
}
}
-export function clearResleevesPage() {
+export function clearResleevesPage(): void {
if (UIElems.container instanceof HTMLElement) {
removeElement(UIElems.container);
}
@@ -304,10 +310,10 @@ function createResleeveUi(resleeve: Resleeve): IResleeveUIElems {
`Bladeburner Max Stamina multiplier: ${numeralWrapper.formatPercentage(resleeve.bladeburner_max_stamina_mult)}`,
`Bladeburner Stamina Gain multiplier: ${numeralWrapper.formatPercentage(resleeve.bladeburner_stamina_gain_mult)}`,
`Bladeburner Field Analysis multiplier: ${numeralWrapper.formatPercentage(resleeve.bladeburner_analysis_mult)}`,
- `Bladeburner Success Chance multiplier: ${numeralWrapper.formatPercentage(resleeve.bladeburner_success_chance_mult)}`
- ].join(" "), false
+ `Bladeburner Success Chance multiplier: ${numeralWrapper.formatPercentage(resleeve.bladeburner_success_chance_mult)}`,
+ ].join(" "), false,
)
- }
+ },
});
elems.statsPanel.appendChild(elems.stats);
elems.statsPanel.appendChild(elems.multipliersButton);
@@ -317,7 +323,7 @@ function createResleeveUi(resleeve: Resleeve): IResleeveUIElems {
elems.augDescription = createElement("p");
for (let i = 0; i < resleeve.augmentations.length; ++i) {
elems.augSelector.add(createOptionElement(resleeve.augmentations[i].name));
- };
+ }
elems.augSelector.addEventListener("change", () => {
updateAugDescription(elems);
});
@@ -335,12 +341,13 @@ function createResleeveUi(resleeve: Resleeve): IResleeveUIElems {
class: "std-button",
innerText: "Purchase",
clickListener: () => {
- if (purchaseResleeve(resleeve, playerRef!)) {
+ if(playerRef == null) throw new Error("playerRef is null in buyButton.click()");
+ if (purchaseResleeve(resleeve, playerRef)) {
dialogBoxCreate((<>You re-sleeved for {Money(cost)}!>), false);
} else {
dialogBoxCreate(`You cannot afford to re-sleeve into this body`, false);
}
- }
+ },
});
elems.costPanel.appendChild(elems.costText);
elems.costPanel.appendChild(elems.buyButton);
@@ -352,7 +359,8 @@ function createResleeveUi(resleeve: Resleeve): IResleeveUIElems {
return elems;
}
-function updateAugDescription(elems: IResleeveUIElems) {
+function updateAugDescription(elems: IResleeveUIElems): void {
+ if(elems.augDescription == null) throw new Error("elems.augDescription is null in updateAugDescription()");
const augName: string = getSelectValue(elems.augSelector);
const aug: Augmentation | null = Augmentations[augName];
if (aug == null) {
@@ -360,5 +368,10 @@ function updateAugDescription(elems: IResleeveUIElems) {
return;
}
- elems.augDescription!.innerHTML = aug!.info;
+ let innerHTML = aug.info;
+ if(typeof innerHTML !== 'string') {
+ innerHTML = renderToStaticMarkup(innerHTML);
+ }
+
+ elems.augDescription.innerHTML = innerHTML;
}
diff --git a/src/PersonObjects/Sleeve/Sleeve.ts b/src/PersonObjects/Sleeve/Sleeve.ts
index 34f63312d..12a34cee4 100644
--- a/src/PersonObjects/Sleeve/Sleeve.ts
+++ b/src/PersonObjects/Sleeve/Sleeve.ts
@@ -12,7 +12,7 @@ import { IPlayer } from "../IPlayer";
import {
Person,
ITaskTracker,
- createTaskTracker
+ createTaskTracker,
} from "../Person";
import { Augmentation } from "../../Augmentation/Augmentation";
@@ -39,23 +39,17 @@ import { LocationName } from "../../Locations/data/LocationNames";
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../../utils/JSONReviver";
export class Sleeve extends Person {
- /**
- * Initiatizes a Sleeve object from a JSON save state.
- */
- static fromJSON(value: any): Sleeve {
- return Generic_fromJSON(Sleeve, value.data);
- }
/**
* Stores the name of the class that the player is currently taking
*/
- className: string = "";
+ className = "";
/**
* Stores the type of crime the sleeve is currently attempting
* Must match the name of a Crime object
*/
- crimeType: string = "";
+ crimeType = "";
/**
* Enum value for current task
@@ -70,17 +64,17 @@ export class Sleeve extends Person {
* Crime: Money earned if successful
* Class/Gym: Name of university/gym
*/
- currentTaskLocation: string = "";
+ currentTaskLocation = "";
/**
* Maximum amount of time (in milliseconds) that can be spent on current task.
*/
- currentTaskMaxTime: number = 0;
+ currentTaskMaxTime = 0;
/**
* Milliseconds spent on current task
*/
- currentTaskTime: number = 0;
+ currentTaskTime = 0;
/**
* Keeps track of experience earned for other sleeves
@@ -110,7 +104,7 @@ export class Sleeve extends Person {
/**
* String that stores what stat the sleeve is training at the gym
*/
- gymStatType: string = "";
+ gymStatType = "";
/**
* Keeps track of events/notifications for this sleeve
@@ -120,7 +114,7 @@ export class Sleeve extends Person {
/**
* Clone retains 'memory' synchronization (and maybe exp?) upon prestige/installing Augs
*/
- memory: number = 1;
+ memory = 1;
/**
* Sleeve shock. Number between 0 and 100
@@ -129,19 +123,19 @@ export class Sleeve extends Person {
*
* Reputation earned is also multiplied by shock%
*/
- shock: number = 1;
+ shock = 1;
/**
* Stored number of game "loop" cycles
*/
- storedCycles: number = 0;
+ storedCycles = 0;
/**
* Synchronization. Number between 0 and 100
* When experience is earned by sleeve, both the player and the sleeve get
* sync% of the experience earned. Other sleeves get sync^2% of exp
*/
- sync: number = 1;
+ sync = 1;
constructor(p: IPlayer | null = null) {
super();
@@ -228,7 +222,7 @@ export class Sleeve extends Person {
* Earn experience for any stats (supports multiple)
* This function also handles experience propogating to Player and other sleeves
*/
- gainExperience(p: IPlayer, exp: ITaskTracker, numCycles: number=1, fromOtherSleeve: boolean=false): ITaskTracker {
+ gainExperience(p: IPlayer, exp: ITaskTracker, numCycles=1, fromOtherSleeve=false): ITaskTracker {
// If the experience is coming from another sleeve, it is not multiplied by anything.
// Also the player does not earn anything
if (fromOtherSleeve) {
@@ -335,7 +329,7 @@ export class Sleeve extends Person {
/**
* Earn money for player
*/
- gainMoney(p: IPlayer, task: ITaskTracker, numCycles: number=1): void {
+ gainMoney(p: IPlayer, task: ITaskTracker, numCycles=1): void {
const gain: number = (task.money * numCycles);
this.earningsForTask.money += gain;
this.earningsForPlayer.money += gain;
@@ -373,10 +367,10 @@ export class Sleeve extends Person {
*/
getRepGain(p: IPlayer): number {
if (this.currentTask === SleeveTaskType.Faction) {
- let favorMult: number = 1;
+ let favorMult = 1;
const fac: Faction | null = Factions[this.currentTaskLocation];
if (fac != null) {
- favorMult = 1 + (fac!.favor / 100);
+ favorMult = 1 + (fac.favor / 100);
}
switch (this.factionWorkType) {
@@ -404,10 +398,10 @@ export class Sleeve extends Person {
return 0;
}
- const jobPerformance: number = companyPosition!.calculateJobPerformance(this.hacking_skill, this.strength,
+ const jobPerformance: number = companyPosition.calculateJobPerformance(this.hacking_skill, this.strength,
this.defense, this.dexterity,
this.agility, this.charisma);
- const favorMult = 1 + (company!.favor / 100);
+ const favorMult = 1 + (company.favor / 100);
return jobPerformance * this.company_rep_mult * favorMult;
} else {
@@ -429,7 +423,7 @@ export class Sleeve extends Person {
}
log(entry: string): void {
- const MaxLogSize: number = 50;
+ const MaxLogSize = 50;
this.logs.push(entry);
if (this.logs.length > MaxLogSize) {
this.logs.shift();
@@ -439,7 +433,7 @@ export class Sleeve extends Person {
/**
* Called on every sleeve for a Source File prestige
*/
- prestige(p: IPlayer) {
+ prestige(p: IPlayer): void {
// Reset exp
this.hacking_exp = 0;
this.strength_exp = 0;
@@ -471,7 +465,7 @@ export class Sleeve extends Person {
* Returns an object containing the amount of experience that should be
* transferred to all other sleeves
*/
- process(p: IPlayer, numCycles: number=1): ITaskTracker | null {
+ process(p: IPlayer, numCycles=1): ITaskTracker | null {
// Only process once every second (5 cycles)
const CyclesPerSecond = 1000 / CONSTANTS.MilliPerCycle;
this.storedCycles += numCycles;
@@ -504,7 +498,7 @@ export class Sleeve extends Person {
retValue = this.gainExperience(p, this.gainRatesForTask, cyclesUsed);
this.gainMoney(p, this.gainRatesForTask, cyclesUsed);
break;
- case SleeveTaskType.Faction:
+ case SleeveTaskType.Faction: {
retValue = this.gainExperience(p, this.gainRatesForTask, cyclesUsed);
this.gainMoney(p, this.gainRatesForTask, cyclesUsed);
@@ -517,7 +511,8 @@ export class Sleeve extends Person {
fac.playerReputation += (this.getRepGain(p) * cyclesUsed);
break;
- case SleeveTaskType.Company:
+ }
+ case SleeveTaskType.Company: {
retValue = this.gainExperience(p, this.gainRatesForTask, cyclesUsed);
this.gainMoney(p, this.gainRatesForTask, cyclesUsed);
@@ -527,8 +522,9 @@ export class Sleeve extends Person {
break;
}
- company!.playerReputation += (this.getRepGain(p) * cyclesUsed);
+ company.playerReputation += (this.getRepGain(p) * cyclesUsed);
break;
+ }
case SleeveTaskType.Recovery:
this.shock = Math.min(100, this.shock + (0.0002 * cyclesUsed));
break;
@@ -605,7 +601,7 @@ export class Sleeve extends Person {
// Set exp/money multipliers based on which university.
// Also check that the sleeve is in the right city
- let costMult: number = 1;
+ let costMult = 1;
switch (universityName.toLowerCase()) {
case LocationName.AevumSummitUniversity.toLowerCase():
if (this.city !== CityName.Aevum) { return false; }
@@ -676,7 +672,7 @@ export class Sleeve extends Person {
updateTaskGainRates(p: IPlayer): void {
if (this.currentTask === SleeveTaskType.Class) {
- let expMult: number = 1;
+ let expMult = 1;
switch (this.currentTaskLocation.toLowerCase()) {
case LocationName.AevumSummitUniversity.toLowerCase():
expMult = 3;
@@ -720,7 +716,7 @@ export class Sleeve extends Person {
if (this.currentTask === SleeveTaskType.Gym) {
// Get gym exp multiplier
- let expMult: number = 1;
+ let expMult = 1;
switch (this.currentTaskLocation.toLowerCase()) {
case LocationName.AevumCrushFitnessGym.toLowerCase():
expMult = 2;
@@ -742,7 +738,7 @@ export class Sleeve extends Person {
}
// Set stat gain rate
- const baseGymExp: number = 1;
+ const baseGymExp = 1;
const totalExpMultiplier = p.hashManager.getTrainingMult() * expMult;
const sanitizedStat: string = this.gymStatType.toLowerCase();
if (sanitizedStat.includes("str")) {
@@ -889,7 +885,7 @@ export class Sleeve extends Person {
// Set exp/money multipliers based on which university.
// Also check that the sleeve is in the right city
- let costMult: number = 1;
+ let costMult = 1;
switch (gymName.toLowerCase()) {
case LocationName.AevumCrushFitnessGym.toLowerCase():
if (this.city != CityName.Aevum) { return false; }
@@ -911,7 +907,7 @@ export class Sleeve extends Person {
this.currentTaskLocation = LocationName.Sector12PowerhouseGym;
costMult = 20;
break;
- case LocationName.VolhavenMilleniumFitnessGym:
+ case LocationName.VolhavenMilleniumFitnessGym.toLowerCase():
if (this.city != CityName.Volhaven) { return false; }
this.currentTaskLocation = LocationName.VolhavenMilleniumFitnessGym;
costMult = 7;
@@ -947,6 +943,14 @@ export class Sleeve extends Person {
toJSON(): any {
return Generic_toJSON("Sleeve", this);
}
+
+ /**
+ * Initiatizes a Sleeve object from a JSON save state.
+ */
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+ static fromJSON(value: any): Sleeve {
+ return Generic_fromJSON(Sleeve, value.data);
+ }
}
Reviver.constructors.Sleeve = Sleeve;
diff --git a/src/PersonObjects/Sleeve/SleeveAugmentationsUI.ts b/src/PersonObjects/Sleeve/SleeveAugmentationsUI.ts
index 756987369..9f0dcf243 100644
--- a/src/PersonObjects/Sleeve/SleeveAugmentationsUI.ts
+++ b/src/PersonObjects/Sleeve/SleeveAugmentationsUI.ts
@@ -10,7 +10,6 @@ import { IPlayer } from "../IPlayer";
import { Augmentation } from "../../Augmentation/Augmentation";
import { Augmentations } from "../../Augmentation/Augmentations";
-import { numeralWrapper } from "../../ui/numeralFormat";
import { Money } from "../../ui/React/Money";
import { dialogBoxCreate } from "../../../utils/DialogBox";
@@ -22,7 +21,7 @@ import { removeElementById } from "../../../utils/uiHelpers/removeElementById";
import { renderToStaticMarkup } from "react-dom/server"
-export function createSleevePurchaseAugsPopup(sleeve: Sleeve, p: IPlayer) {
+export function createSleevePurchaseAugsPopup(sleeve: Sleeve, p: IPlayer): void {
// Array of all owned Augmentations. Names only
const ownedAugNames: string[] = sleeve.augmentations.map((e) => {return e.name});
@@ -56,10 +55,15 @@ export function createSleevePurchaseAugsPopup(sleeve: Sleeve, p: IPlayer) {
continue;
}
+ let tooltip = aug.info;
+ if(typeof tooltip !== 'string') {
+ tooltip = renderToStaticMarkup(tooltip);
+ }
+
ownedAugsDiv.appendChild(createElement("div", {
class: "gang-owned-upgrade", // Reusing a class from the Gang UI
innerText: ownedAug,
- tooltip: aug.info,
+ tooltip: tooltip,
}))
}
popupElems.push(ownedAugsDiv);
@@ -73,7 +77,7 @@ export function createSleevePurchaseAugsPopup(sleeve: Sleeve, p: IPlayer) {
`that you have unlocked through Factions. `,
`When purchasing an Augmentation for a Duplicate Sleeve, they are immediately`,
`installed. This means that the Duplicate Sleeve will immediately lose all of`,
- `its stat experience.`
+ `its stat experience.`,
].join(" "),
});
@@ -84,13 +88,18 @@ export function createSleevePurchaseAugsPopup(sleeve: Sleeve, p: IPlayer) {
class: "cmpy-mgmt-upgrade-div", // We'll reuse this CSS class
});
+ let info = aug.info;
+ if(typeof info !== 'string') {
+ info = renderToStaticMarkup(info);
+ }
+
div.appendChild(createElement("p", {
fontSize: "12px",
innerHTML:
[
`${aug.name} `,
`Cost: ${renderToStaticMarkup(Money(aug.startingCost))} `,
- `${aug.info}`
+ `${info}`,
].join(" "),
padding: "2px",
clickListener: () => {
@@ -101,7 +110,7 @@ export function createSleevePurchaseAugsPopup(sleeve: Sleeve, p: IPlayer) {
} else {
dialogBoxCreate(`You cannot afford ${aug.name}`, false);
}
- }
+ },
}));
popupElems.push(div);
diff --git a/src/PersonObjects/Sleeve/SleeveCovenantPurchases.ts b/src/PersonObjects/Sleeve/SleeveCovenantPurchases.ts
index 1ead77eeb..4ccd0a772 100644
--- a/src/PersonObjects/Sleeve/SleeveCovenantPurchases.ts
+++ b/src/PersonObjects/Sleeve/SleeveCovenantPurchases.ts
@@ -8,11 +8,11 @@ import { CovenantPurchasesRoot } from "./ui/CovenantPurchasesRoot";
import { createPopup,
removePopup } from "../../ui/React/createPopup";
-export const MaxSleevesFromCovenant: number = 5;
-export const BaseCostPerSleeve: number = 10e12;
-export const PopupId: string = "covenant-sleeve-purchases-popup";
+export const MaxSleevesFromCovenant = 5;
+export const BaseCostPerSleeve = 10e12;
+export const PopupId = "covenant-sleeve-purchases-popup";
-export function createSleevePurchasesFromCovenantPopup(p: IPlayer) {
+export function createSleevePurchasesFromCovenantPopup(p: IPlayer): void {
const removePopupFn = removePopup.bind(null, PopupId);
createPopup(PopupId, CovenantPurchasesRoot, { p: p, closeFn: removePopupFn });
}
diff --git a/src/PersonObjects/Sleeve/SleeveUI.tsx b/src/PersonObjects/Sleeve/SleeveUI.tsx
index 405a94095..8fd8d7888 100644
--- a/src/PersonObjects/Sleeve/SleeveUI.tsx
+++ b/src/PersonObjects/Sleeve/SleeveUI.tsx
@@ -46,7 +46,6 @@ import { ReputationRate } from "../../ui/React/ReputationRate";
import { StatsElement } from "./ui/StatsElement";
import { MoreStatsContent } from "./ui/MoreStatsContent";
import { MoreEarningsContent } from "./ui/MoreEarningsContent";
-import * as React from "react";
import * as ReactDOM from "react-dom";
import { renderToStaticMarkup } from "react-dom/server"
@@ -91,7 +90,7 @@ const UIElems: IPageUIElems = {
// Creates the UI for the entire Sleeves page
let playerRef: IPlayer | null;
-export function createSleevesPage(p: IPlayer) {
+export function createSleevesPage(p: IPlayer): void {
if (!routing.isOn(Page.Sleeves)) { return; }
try {
@@ -117,7 +116,7 @@ export function createSleevesPage(p: IPlayer) {
innerText: "FAQ",
clickListener: () => {
dialogBoxCreate(SleeveFaq, false);
- }
+ },
});
UIElems.docButton = createElement("a", {
@@ -134,7 +133,8 @@ export function createSleevesPage(p: IPlayer) {
// Create UI modules for all Sleeve
for (const sleeve of p.sleeves) {
const sleeveUi = createSleeveUi(sleeve, p.sleeves);
- UIElems.sleeveList.appendChild(sleeveUi.container!);
+ if(sleeveUi.container == null) throw new Error("sleeveUi.container is null in createSleevesPage()");
+ UIElems.sleeveList.appendChild(sleeveUi.container);
UIElems.sleeves.push(sleeveUi);
}
@@ -143,28 +143,33 @@ export function createSleevesPage(p: IPlayer) {
UIElems.container.appendChild(UIElems.docButton);
UIElems.container.appendChild(UIElems.sleeveList);
- document.getElementById("entire-game-container")!.appendChild(UIElems.container);
+
+ const container = document.getElementById("entire-game-container");
+ if(container === null) throw new Error("entire-game-container not found in createSleevesPage()");
+ container.appendChild(UIElems.container);
} catch(e) {
exceptionAlert(e);
}
}
// Updates the UI for the entire Sleeves page
-export function updateSleevesPage() {
+export function updateSleevesPage(): void {
if (!routing.isOn(Page.Sleeves)) { return; }
+ if (playerRef === null) throw new Error("playerRef is null in updateSleevesPage()");
+ if (UIElems.sleeves === null) throw new Error("UIElems.sleeves is null in updateSleevesPage()");
- try {
- for (let i = 0; i < playerRef!.sleeves.length; ++i) {
- const sleeve: Sleeve = playerRef!.sleeves[i];
- const elems: ISleeveUIElems = UIElems.sleeves![i];
- updateSleeveUi(sleeve!, elems!);
- }
- } catch(e) {
- exceptionAlert(e);
- }
+ try {
+ for (let i = 0; i < playerRef.sleeves.length; ++i) {
+ const sleeve: Sleeve = playerRef.sleeves[i];
+ const elems: ISleeveUIElems = UIElems.sleeves[i];
+ updateSleeveUi(sleeve, elems);
+ }
+ } catch(e) {
+ exceptionAlert(e);
+ }
}
-export function clearSleevesPage() {
+export function clearSleevesPage(): void {
if (UIElems.container instanceof HTMLElement) {
removeElement(UIElems.container);
}
@@ -212,13 +217,13 @@ function createSleeveUi(sleeve: Sleeve, allSleeves: Sleeve[]): ISleeveUIElems {
innerText: "More Stats",
clickListener: () => {
dialogBoxCreate(MoreStatsContent(sleeve));
- }
+ },
});
elems.travelButton = createElement("button", {
class: "std-button",
innerText: "Travel",
clickListener: () => {
- const popupId: string = "sleeve-travel-popup";
+ const popupId = "sleeve-travel-popup";
const popupArguments: HTMLElement[] = [];
popupArguments.push(createPopupCloseButton(popupId, { class: "std-button" }));
popupArguments.push(createElement("p", {
@@ -236,32 +241,34 @@ function createSleeveUi(sleeve: Sleeve, allSleeves: Sleeve[]): ISleeveUIElems {
class: "cmpy-mgmt-find-employee-option",
innerText: cityName,
clickListener: () => {
- if (!playerRef!.canAfford(CONSTANTS.TravelCost)) {
+ if(playerRef == null) throw new Error("playerRef is null in popupArguments.click()");
+ if (!playerRef.canAfford(CONSTANTS.TravelCost)) {
dialogBoxCreate("You cannot afford to have this sleeve travel to another city", false);
return false;
}
sleeve.city = cityName as CityName;
- playerRef!.loseMoney(CONSTANTS.TravelCost);
+ playerRef.loseMoney(CONSTANTS.TravelCost);
sleeve.resetTaskStatus();
removeElementById(popupId);
updateSleeveUi(sleeve, elems);
updateSleeveTaskSelector(sleeve, elems, allSleeves);
return false;
- }
+ },
}));
})(sleeve, cityName);
}
createPopup(popupId, popupArguments);
- }
+ },
});
elems.purchaseAugsButton = createElement("button", {
class: "std-button",
display: "block",
innerText: "Manage Augmentations",
clickListener: () => {
- createSleevePurchaseAugsPopup(sleeve, playerRef!);
- }
+ if(playerRef == null) throw new Error("playerRef is null in purchaseAugsButton.click()");
+ createSleevePurchaseAugsPopup(sleeve, playerRef);
+ },
});
elems.statsPanel.appendChild(elems.stats);
elems.statsPanel.appendChild(elems.moreStatsButton);
@@ -296,7 +303,7 @@ function createSleeveUi(sleeve: Sleeve, allSleeves: Sleeve[]): ISleeveUIElems {
innerText: "Set Task",
clickListener: () => {
setSleeveTask(sleeve, elems);
- }
+ },
});
elems.taskPanel.appendChild(elems.taskSelector);
elems.taskPanel.appendChild(elems.taskDetailsSelector);
@@ -312,7 +319,7 @@ function createSleeveUi(sleeve: Sleeve, allSleeves: Sleeve[]): ISleeveUIElems {
innerText: "More Earnings Info",
clickListener: () => {
dialogBoxCreate(MoreEarningsContent(sleeve));
- }
+ },
});
elems.earningsPanel.appendChild(elems.currentEarningsInfo);
@@ -328,10 +335,14 @@ function createSleeveUi(sleeve: Sleeve, allSleeves: Sleeve[]): ISleeveUIElems {
}
// Updates the UI for a single Sleeve
-function updateSleeveUi(sleeve: Sleeve, elems: ISleeveUIElems) {
+function updateSleeveUi(sleeve: Sleeve, elems: ISleeveUIElems): void {
if (!routing.isOn(Page.Sleeves)) { return; }
+ if(playerRef == null) throw new Error("playerRef is null in updateSleeveUi()");
+ if(elems.taskProgressBar == null) throw new Error("elems.taskProgressBar is null");
+ if(elems.stats == null) throw new Error("elems.stats is null");
+ if(elems.currentEarningsInfo == null) throw new Error("elems.currentEarningsInfo is null");
- ReactDOM.render(StatsElement(sleeve), elems.stats!);
+ ReactDOM.render(StatsElement(sleeve), elems.stats);
if (sleeve.currentTask === SleeveTaskType.Crime) {
const data = [
@@ -341,11 +352,11 @@ function updateSleeveUi(sleeve: Sleeve, elems: ISleeveUIElems) {
[`Defense Exp`, numeralWrapper.formatExp(sleeve.gainRatesForTask.def), `(2x on success)`],
[`Dexterity Exp`, numeralWrapper.formatExp(sleeve.gainRatesForTask.dex), `(2x on success)`],
[`Agility Exp`, numeralWrapper.formatExp(sleeve.gainRatesForTask.agi), `(2x on success)`],
- [`Charisma Exp`, numeralWrapper.formatExp(sleeve.gainRatesForTask.cha), `(2x on success)`]
+ [`Charisma Exp`, numeralWrapper.formatExp(sleeve.gainRatesForTask.cha), `(2x on success)`],
];
- ReactDOM.render(EarningsTableElement('Earnings (Pre-Synchronization)', data), elems.currentEarningsInfo!)
+ ReactDOM.render(EarningsTableElement('Earnings (Pre-Synchronization)', data), elems.currentEarningsInfo)
- elems.taskProgressBar!.innerText = createProgressBarText({
+ elems.taskProgressBar.innerText = createProgressBarText({
progress: sleeve.currentTaskTime / sleeve.currentTaskMaxTime,
totalTicks: 25,
});
@@ -357,16 +368,15 @@ function updateSleeveUi(sleeve: Sleeve, elems: ISleeveUIElems) {
[`Defense Exp:`, `${numeralWrapper.formatExp(5 * sleeve.gainRatesForTask.def)} / s`],
[`Dexterity Exp:`, `${numeralWrapper.formatExp(5 * sleeve.gainRatesForTask.dex)} / s`],
[`Agility Exp:`, `${numeralWrapper.formatExp(5 * sleeve.gainRatesForTask.agi)} / s`],
- [`Charisma Exp:`, `${numeralWrapper.formatExp(5 * sleeve.gainRatesForTask.cha)} / s`]
+ [`Charisma Exp:`, `${numeralWrapper.formatExp(5 * sleeve.gainRatesForTask.cha)} / s`],
];
- let repGainText: string = "";
if (sleeve.currentTask === SleeveTaskType.Company || sleeve.currentTask === SleeveTaskType.Faction) {
- const repGain: number = sleeve.getRepGain(playerRef!);
+ const repGain: number = sleeve.getRepGain(playerRef);
data.push([`Reputation:`, ReputationRate(5 * repGain)]);
}
- ReactDOM.render(EarningsTableElement('Earnings (Pre-Synchronization)', data), elems.currentEarningsInfo!)
+ ReactDOM.render(EarningsTableElement('Earnings (Pre-Synchronization)', data), elems.currentEarningsInfo)
- elems.taskProgressBar!.innerText = "";
+ elems.taskProgressBar.innerText = "";
}
}
@@ -376,18 +386,18 @@ const universitySelectorOptions: string[] = [
"Networks",
"Algorithms",
"Management",
- "Leadership"
+ "Leadership",
];
const gymSelectorOptions: string[] = [
"Train Strength",
"Train Defense",
"Train Dexterity",
- "Train Agility"
+ "Train Agility",
];
// Whenever a new task is selected, the "details" selector must update accordingly
-function updateSleeveTaskSelector(sleeve: Sleeve, elems: ISleeveUIElems, allSleeves: Sleeve[]) {
+function updateSleeveTaskSelector(sleeve: Sleeve, elems: ISleeveUIElems, allSleeves: Sleeve[]): void {
if (playerRef == null) {
throw new Error(`playerRef is null in updateSleeveTaskSelector()`);
}
@@ -410,41 +420,50 @@ function updateSleeveTaskSelector(sleeve: Sleeve, elems: ISleeveUIElems, allSlee
}
}
+ if(elems.taskDetailsSelector === null) {
+ throw new Error("elems.taskDetailsSelector is null");
+ }
+ if(elems.taskDetailsSelector2 === null) {
+ throw new Error("elems.taskDetailsSelector is null");
+ }
+
+
+
// Reset Selectors
removeChildrenFromElement(elems.taskDetailsSelector);
removeChildrenFromElement(elems.taskDetailsSelector2);
- elems.taskDetailsSelector2 = clearEventListeners(elems.taskDetailsSelector2!) as HTMLSelectElement;
+ elems.taskDetailsSelector2 = clearEventListeners(elems.taskDetailsSelector2) as HTMLSelectElement;
const value: string = getSelectValue(elems.taskSelector);
switch(value) {
- case "Work for Company":
- let companyCount: number = 0;
- const allJobs: string[] = Object.keys(playerRef!.jobs!);
+ case "Work for Company": {
+ let companyCount = 0;
+ const allJobs: string[] = Object.keys(playerRef.jobs);
for (let i = 0; i < allJobs.length; ++i) {
if (!forbiddenCompanies.includes(allJobs[i])) {
- elems.taskDetailsSelector!.add(createOptionElement(allJobs[i]));
+ elems.taskDetailsSelector.add(createOptionElement(allJobs[i]));
// Set initial value of the 'Details' selector
if (sleeve.currentTaskLocation === allJobs[i]) {
- elems.taskDetailsSelector!.selectedIndex = companyCount;
+ elems.taskDetailsSelector.selectedIndex = companyCount;
}
++companyCount;
}
- elems.taskDetailsSelector2!.add(createOptionElement("------"));
+ elems.taskDetailsSelector2.add(createOptionElement("------"));
}
break;
- case "Work for Faction":
- let factionCount: number = 0;
- for (let i = 0; i < playerRef!.factions!.length; ++i) {
- const fac: string = playerRef!.factions[i]!;
+ }
+ case "Work for Faction": {
+ let factionCount = 0;
+ for (const fac of playerRef.factions) {
if (!forbiddenFactions.includes(fac)) {
- elems.taskDetailsSelector!.add(createOptionElement(fac));
+ elems.taskDetailsSelector.add(createOptionElement(fac));
// Set initial value of the 'Details' Selector
if (sleeve.currentTaskLocation === fac) {
- elems.taskDetailsSelector!.selectedIndex = factionCount;
+ elems.taskDetailsSelector.selectedIndex = factionCount;
}
++factionCount;
@@ -452,94 +471,98 @@ function updateSleeveTaskSelector(sleeve: Sleeve, elems: ISleeveUIElems, allSlee
}
// The available faction work types depends on the faction
- elems.taskDetailsSelector!.addEventListener("change", () => {
- const facName = getSelectValue(elems.taskDetailsSelector!);
+ elems.taskDetailsSelector.addEventListener("change", () => {
+ if(elems.taskDetailsSelector2 === null)
+ throw new Error("elems.taskDetailsSelector2 is null");
+ const facName = getSelectValue(elems.taskDetailsSelector);
const faction: Faction | null = Factions[facName];
if (faction == null) {
console.warn(`Invalid faction name when trying to update Sleeve Task Selector: ${facName}`);
return;
}
const facInfo = faction.getInfo();
- removeChildrenFromElement(elems.taskDetailsSelector2!);
+ removeChildrenFromElement(elems.taskDetailsSelector2);
let numOptionsAdded = 0;
if (facInfo.offerHackingWork) {
- elems.taskDetailsSelector2!.add(createOptionElement("Hacking Contracts"));
+ elems.taskDetailsSelector2.add(createOptionElement("Hacking Contracts"));
if (sleeve.factionWorkType === FactionWorkType.Hacking) {
- elems.taskDetailsSelector2!.selectedIndex = numOptionsAdded;
+ elems.taskDetailsSelector2.selectedIndex = numOptionsAdded;
}
++numOptionsAdded;
}
if (facInfo.offerFieldWork) {
- elems.taskDetailsSelector2!.add(createOptionElement("Field Work"));
+ elems.taskDetailsSelector2.add(createOptionElement("Field Work"));
if (sleeve.factionWorkType === FactionWorkType.Field) {
- elems.taskDetailsSelector2!.selectedIndex = numOptionsAdded;
+ elems.taskDetailsSelector2.selectedIndex = numOptionsAdded;
}
++numOptionsAdded;
}
if (facInfo.offerSecurityWork) {
- elems.taskDetailsSelector2!.add(createOptionElement("Security Work"));
+ elems.taskDetailsSelector2.add(createOptionElement("Security Work"));
if (sleeve.factionWorkType === FactionWorkType.Security) {
- elems.taskDetailsSelector2!.selectedIndex = numOptionsAdded;
+ elems.taskDetailsSelector2.selectedIndex = numOptionsAdded;
}
++numOptionsAdded;
}
});
- elems.taskDetailsSelector!.dispatchEvent(new Event("change"));
+ elems.taskDetailsSelector.dispatchEvent(new Event("change"));
break;
- case "Commit Crime":
+ }
+ case "Commit Crime": {
let i = 0;
for (const crimeLabel in Crimes) {
const name: string = Crimes[crimeLabel].name;
- elems.taskDetailsSelector!.add(createOptionElement(name, crimeLabel));
+ elems.taskDetailsSelector.add(createOptionElement(name, crimeLabel));
// Set initial value for crime type
if (sleeve.crimeType === "") { continue; }
const crime: Crime | null = Crimes[sleeve.crimeType];
- if (crime == null) { continue; }
- if (name === crime!.name) {
- elems.taskDetailsSelector!.selectedIndex = i;
+ if (crime === null) { continue; }
+ if (name === crime.name) {
+ elems.taskDetailsSelector.selectedIndex = i;
}
++i;
}
- elems.taskDetailsSelector2!.add(createOptionElement("------"));
+ elems.taskDetailsSelector2.add(createOptionElement("------"));
break;
+ }
case "Take University Course":
// First selector has class type
for (let i = 0; i < universitySelectorOptions.length; ++i) {
- elems.taskDetailsSelector!.add(createOptionElement(universitySelectorOptions[i]));
+ elems.taskDetailsSelector.add(createOptionElement(universitySelectorOptions[i]));
// Set initial value
if (sleeve.className === universitySelectorOptions[i]) {
- elems.taskDetailsSelector!.selectedIndex = i;
+ elems.taskDetailsSelector.selectedIndex = i;
}
}
// Second selector has which university
switch (sleeve.city) {
case CityName.Aevum:
- elems.taskDetailsSelector2!.add(createOptionElement(LocationName.AevumSummitUniversity));
+ elems.taskDetailsSelector2.add(createOptionElement(LocationName.AevumSummitUniversity));
break;
case CityName.Sector12:
- elems.taskDetailsSelector2!.add(createOptionElement(LocationName.Sector12RothmanUniversity));
+ elems.taskDetailsSelector2.add(createOptionElement(LocationName.Sector12RothmanUniversity));
break;
case CityName.Volhaven:
- elems.taskDetailsSelector2!.add(createOptionElement(LocationName.VolhavenZBInstituteOfTechnology));
+ elems.taskDetailsSelector2.add(createOptionElement(LocationName.VolhavenZBInstituteOfTechnology));
break;
default:
- elems.taskDetailsSelector2!.add(createOptionElement("No university available in city!"));
+ elems.taskDetailsSelector2.add(createOptionElement("No university available in city!"));
break;
}
break;
case "Workout at Gym":
// First selector has what stat is being trained
for (let i = 0; i < gymSelectorOptions.length; ++i) {
- elems.taskDetailsSelector!.add(createOptionElement(gymSelectorOptions[i]));
+ elems.taskDetailsSelector.add(createOptionElement(gymSelectorOptions[i]));
// Set initial value
if (sleeve.gymStatType === gymSelectorOptions[i]) {
- elems.taskDetailsSelector!.selectedIndex = i;
+ elems.taskDetailsSelector.selectedIndex = i;
}
}
@@ -547,32 +570,32 @@ function updateSleeveTaskSelector(sleeve: Sleeve, elems: ISleeveUIElems, allSlee
// In this switch statement we also set the initial value of the second selector
switch (sleeve.city) {
case CityName.Aevum:
- elems.taskDetailsSelector2!.add(createOptionElement(LocationName.AevumCrushFitnessGym));
- elems.taskDetailsSelector2!.add(createOptionElement(LocationName.AevumSnapFitnessGym));
+ elems.taskDetailsSelector2.add(createOptionElement(LocationName.AevumCrushFitnessGym));
+ elems.taskDetailsSelector2.add(createOptionElement(LocationName.AevumSnapFitnessGym));
// Set initial value
if (sleeve.currentTaskLocation === LocationName.AevumCrushFitnessGym) {
- elems.taskDetailsSelector2!.selectedIndex = 0;
+ elems.taskDetailsSelector2.selectedIndex = 0;
} else if (sleeve.currentTaskLocation === LocationName.AevumSnapFitnessGym) {
- elems.taskDetailsSelector2!.selectedIndex = 1;
+ elems.taskDetailsSelector2.selectedIndex = 1;
}
break;
case CityName.Sector12:
- elems.taskDetailsSelector2!.add(createOptionElement(LocationName.Sector12IronGym));
- elems.taskDetailsSelector2!.add(createOptionElement(LocationName.Sector12PowerhouseGym));
+ elems.taskDetailsSelector2.add(createOptionElement(LocationName.Sector12IronGym));
+ elems.taskDetailsSelector2.add(createOptionElement(LocationName.Sector12PowerhouseGym));
// Set initial value
if (sleeve.currentTaskLocation === LocationName.Sector12IronGym) {
- elems.taskDetailsSelector2!.selectedIndex = 0;
+ elems.taskDetailsSelector2.selectedIndex = 0;
} else if (sleeve.currentTaskLocation === LocationName.Sector12PowerhouseGym) {
- elems.taskDetailsSelector2!.selectedIndex = 1;
+ elems.taskDetailsSelector2.selectedIndex = 1;
}
break;
case CityName.Volhaven:
- elems.taskDetailsSelector2!.add(createOptionElement(LocationName.VolhavenMilleniumFitnessGym));
+ elems.taskDetailsSelector2.add(createOptionElement(LocationName.VolhavenMilleniumFitnessGym));
break;
default:
- elems.taskDetailsSelector2!.add(createOptionElement("No gym available in city!"));
+ elems.taskDetailsSelector2.add(createOptionElement("No gym available in city!"));
break;
}
@@ -581,8 +604,8 @@ function updateSleeveTaskSelector(sleeve: Sleeve, elems: ISleeveUIElems, allSlee
case "Synchronize":
case "------":
// No options in "Details" selector
- elems.taskDetailsSelector!.add(createOptionElement("------"));
- elems.taskDetailsSelector2!.add(createOptionElement("------"));
+ elems.taskDetailsSelector.add(createOptionElement("------"));
+ elems.taskDetailsSelector2.add(createOptionElement("------"));
return;
default:
break;
@@ -594,37 +617,38 @@ function setSleeveTask(sleeve: Sleeve, elems: ISleeveUIElems): boolean {
if (playerRef == null) {
throw new Error("playerRef is null in Sleeve UI's setSleeveTask()");
}
+ if(elems.taskDescription == null) throw new Error("elems.taskDescription is null");
const taskValue: string = getSelectValue(elems.taskSelector);
const detailValue: string = getSelectValue(elems.taskDetailsSelector);
const detailValue2: string = getSelectValue(elems.taskDetailsSelector2);
- let res: boolean = false;
+ let res = false;
switch(taskValue) {
case "------":
- elems.taskDescription!.innerText = "This sleeve is currently idle";
+ elems.taskDescription.innerText = "This sleeve is currently idle";
break;
case "Work for Company":
- res = sleeve.workForCompany(playerRef!, detailValue);
+ res = sleeve.workForCompany(playerRef, detailValue);
break;
case "Work for Faction":
- res = sleeve.workForFaction(playerRef!, detailValue, detailValue2);
+ res = sleeve.workForFaction(playerRef, detailValue, detailValue2);
break;
case "Commit Crime":
- res = sleeve.commitCrime(playerRef!, detailValue);
+ res = sleeve.commitCrime(playerRef, detailValue);
break;
case "Take University Course":
- res = sleeve.takeUniversityCourse(playerRef!, detailValue2, detailValue);
+ res = sleeve.takeUniversityCourse(playerRef, detailValue2, detailValue);
break;
case "Workout at Gym":
- res = sleeve.workoutAtGym(playerRef!, detailValue2, detailValue);
+ res = sleeve.workoutAtGym(playerRef, detailValue2, detailValue);
break;
case "Shock Recovery":
sleeve.currentTask = SleeveTaskType.Recovery;
- res = sleeve.shockRecovery(playerRef!);
+ res = sleeve.shockRecovery(playerRef);
break;
case "Synchronize":
- res = sleeve.synchronize(playerRef!);
+ res = sleeve.synchronize(playerRef);
break;
default:
console.error(`Invalid/Unrecognized taskValue in setSleeveTask(): ${taskValue}`);
@@ -635,10 +659,10 @@ function setSleeveTask(sleeve: Sleeve, elems: ISleeveUIElems): boolean {
} else {
switch (taskValue) {
case "Work for Faction":
- elems.taskDescription!.innerText = "Failed to assign sleeve to task. This is most likely because the selected faction does not offer the selected work type.";
+ elems.taskDescription.innerText = "Failed to assign sleeve to task. This is most likely because the selected faction does not offer the selected work type.";
break;
default:
- elems.taskDescription!.innerText = "Failed to assign sleeve to task. Invalid choice(s).";
+ elems.taskDescription.innerText = "Failed to assign sleeve to task. Invalid choice(s).";
break;
}
@@ -648,8 +672,10 @@ function setSleeveTask(sleeve: Sleeve, elems: ISleeveUIElems): boolean {
updateSleevesPage();
// Update the task selector for all sleeves by triggering a change event
- for (const e of UIElems.sleeves!) {
- e.taskSelector!.dispatchEvent(new Event('change'));
+ if(UIElems.sleeves == null) throw new Error("UIElems.sleeves is null");
+ for (const e of UIElems.sleeves) {
+ if(e.taskSelector == null) throw new Error("e.taskSelector is null");
+ e.taskSelector.dispatchEvent(new Event('change'));
}
}
@@ -670,32 +696,33 @@ function updateSleeveTaskDescription(sleeve: Sleeve, elems: ISleeveUIElems): voi
const taskValue: string = getSelectValue(elems.taskSelector);
const detailValue: string = getSelectValue(elems.taskDetailsSelector);
const detailValue2: string = getSelectValue(elems.taskDetailsSelector2);
+ if(elems.taskDescription == null) throw new Error("elems.taskDescription should not be null")
switch(taskValue) {
case "------":
- elems.taskDescription!.innerText = "This sleeve is currently idle";
+ elems.taskDescription.innerText = "This sleeve is currently idle";
break;
case "Work for Company":
- elems.taskDescription!.innerText = `This sleeve is currently working your job at ${sleeve.currentTaskLocation}.`;
+ elems.taskDescription.innerText = `This sleeve is currently working your job at ${sleeve.currentTaskLocation}.`;
break;
case "Work for Faction":
- elems.taskDescription!.innerText = `This sleeve is currently doing ${detailValue2} for ${sleeve.currentTaskLocation}.`;
+ elems.taskDescription.innerText = `This sleeve is currently doing ${detailValue2} for ${sleeve.currentTaskLocation}.`;
break;
case "Commit Crime":
- elems.taskDescription!.innerText = `This sleeve is currently attempting to ${Crimes[detailValue].type} (Success Rate: ${numeralWrapper.formatPercentage(Crimes[detailValue].successRate(sleeve))}).`;
+ elems.taskDescription.innerText = `This sleeve is currently attempting to ${Crimes[detailValue].type} (Success Rate: ${numeralWrapper.formatPercentage(Crimes[detailValue].successRate(sleeve))}).`;
break;
case "Take University Course":
- elems.taskDescription!.innerText = `This sleeve is currently studying/taking a course at ${sleeve.currentTaskLocation}.`;
+ elems.taskDescription.innerText = `This sleeve is currently studying/taking a course at ${sleeve.currentTaskLocation}.`;
break;
case "Workout at Gym":
- elems.taskDescription!.innerText = `This sleeve is currently working out at ${sleeve.currentTaskLocation}.`;
+ elems.taskDescription.innerText = `This sleeve is currently working out at ${sleeve.currentTaskLocation}.`;
break;
case "Shock Recovery":
- elems.taskDescription!.innerText = "This sleeve is currently set to focus on shock recovery. This causes " +
+ elems.taskDescription.innerText = "This sleeve is currently set to focus on shock recovery. This causes " +
"the Sleeve's shock to decrease at a faster rate.";
break;
case "Synchronize":
- elems.taskDescription!.innerText = "This sleeve is currently set to synchronize with the original consciousness. " +
+ elems.taskDescription.innerText = "This sleeve is currently set to synchronize with the original consciousness. " +
"This causes the Sleeve's synchronization to increase."
break;
default:
diff --git a/src/PersonObjects/Sleeve/ui/CovenantPurchasesRoot.tsx b/src/PersonObjects/Sleeve/ui/CovenantPurchasesRoot.tsx
index 1a5c707ae..cfe8d9801 100644
--- a/src/PersonObjects/Sleeve/ui/CovenantPurchasesRoot.tsx
+++ b/src/PersonObjects/Sleeve/ui/CovenantPurchasesRoot.tsx
@@ -12,8 +12,6 @@ import { BaseCostPerSleeve,
PopupId } from "../SleeveCovenantPurchases";
import { IPlayer } from "../../IPlayer";
-import { numeralWrapper } from "../../../ui/numeralFormat";
-
import { PopupCloseButton } from "../../../ui/React/PopupCloseButton";
import { StdButton } from "../../../ui/React/StdButton";
import { Money } from "../../../ui/React/Money";
@@ -51,13 +49,13 @@ export class CovenantPurchasesRoot extends React.Component {
/**
* Force a rerender by just changing an arbitrary state value
*/
- rerender() {
+ rerender(): void {
this.setState((state: IState) => ({
update: state.update + 1,
}));
}
- render() {
+ render(): React.ReactNode {
// Purchasing a new Duplicate Sleeve
let purchaseDisabled = false;
if (!this.props.p.canAfford(this.purchaseCost())) {
@@ -66,7 +64,7 @@ export class CovenantPurchasesRoot extends React.Component {
if (this.props.p.sleevesFromCovenant >= MaxSleevesFromCovenant) {
purchaseDisabled = true;
}
- const purchaseOnClick = () => {
+ const purchaseOnClick = (): void => {
if (this.props.p.sleevesFromCovenant >= MaxSleevesFromCovenant) { return; }
if (this.props.p.canAfford(this.purchaseCost())) {
@@ -84,7 +82,7 @@ export class CovenantPurchasesRoot extends React.Component {
for (let i = 0; i < this.props.p.sleeves.length; ++i) {
const sleeve = this.props.p.sleeves[i];
upgradePanels.push(
-
+ ,
)
}
diff --git a/src/PersonObjects/Sleeve/ui/CovenantSleeveMemoryUpgrade.tsx b/src/PersonObjects/Sleeve/ui/CovenantSleeveMemoryUpgrade.tsx
index 5424e8bff..37fed827c 100644
--- a/src/PersonObjects/Sleeve/ui/CovenantSleeveMemoryUpgrade.tsx
+++ b/src/PersonObjects/Sleeve/ui/CovenantSleeveMemoryUpgrade.tsx
@@ -60,7 +60,7 @@ export class CovenantSleeveMemoryUpgrade extends React.Component
}
}
- render() {
+ render(): React.ReactNode {
const inputId = `sleeve-${this.props.index}-memory-upgrade-input`;
// Memory cannot go above 100
@@ -83,7 +83,7 @@ export class CovenantSleeveMemoryUpgrade extends React.Component
Upgrade Memory
Purchase a memory upgrade for your sleeve. Note that a sleeve's max memory
- is 100 (current: {numeralWrapper.formatMemory(this.props.sleeve.memory)})
+ is 100 (current: {numeralWrapper.formatSleeveMemory(this.props.sleeve.memory)})
diff --git a/src/PersonObjects/Sleeve/ui/CovenantSleeveUpgrades.tsx b/src/PersonObjects/Sleeve/ui/CovenantSleeveUpgrades.tsx
index 317d9a1a8..fd8e7c776 100644
--- a/src/PersonObjects/Sleeve/ui/CovenantSleeveUpgrades.tsx
+++ b/src/PersonObjects/Sleeve/ui/CovenantSleeveUpgrades.tsx
@@ -17,7 +17,7 @@ interface IProps {
}
export class CovenantSleeveUpgrades extends React.Component {
- render() {
+ render(): React.ReactNode {
return (
Duplicate Sleeve {this.props.index}
diff --git a/src/PersonObjects/Sleeve/ui/MoreEarningsContent.tsx b/src/PersonObjects/Sleeve/ui/MoreEarningsContent.tsx
index a9adffb75..dde778947 100644
--- a/src/PersonObjects/Sleeve/ui/MoreEarningsContent.tsx
+++ b/src/PersonObjects/Sleeve/ui/MoreEarningsContent.tsx
@@ -5,8 +5,6 @@ import * as React from "react";
import { StatsTable } from "../../../ui/React/StatsTable";
export function MoreEarningsContent(sleeve: Sleeve): React.ReactElement {
- let style = {}
- style = {textAlign: 'right'};
return (<>
{StatsTable([
['Money ', Money(sleeve.earningsForTask.money)],
diff --git a/src/PersonObjects/Sleeve/ui/MoreStatsContent.tsx b/src/PersonObjects/Sleeve/ui/MoreStatsContent.tsx
index e996848ab..78471ecca 100644
--- a/src/PersonObjects/Sleeve/ui/MoreStatsContent.tsx
+++ b/src/PersonObjects/Sleeve/ui/MoreStatsContent.tsx
@@ -4,8 +4,6 @@ import { StatsTable } from "../../../ui/React/StatsTable";
import * as React from "react";
export function MoreStatsContent(sleeve: Sleeve): React.ReactElement {
- let style = {}
- style = {textAlign: 'right'};
return (<>
{StatsTable([
['Hacking: ', sleeve.hacking_skill, `(${numeralWrapper.formatExp(sleeve.hacking_exp)} exp)`],
diff --git a/src/PersonObjects/Sleeve/ui/StatsElement.tsx b/src/PersonObjects/Sleeve/ui/StatsElement.tsx
index 17ba6101b..f42c52369 100644
--- a/src/PersonObjects/Sleeve/ui/StatsElement.tsx
+++ b/src/PersonObjects/Sleeve/ui/StatsElement.tsx
@@ -42,15 +42,15 @@ export function StatsElement(sleeve: Sleeve): React.ReactElement {
Shock:
- {numeralWrapper.formatShock(100 - sleeve.shock)}
+ {numeralWrapper.formatSleeveShock(100 - sleeve.shock)}
Sync:
- {numeralWrapper.formatSync(sleeve.sync)}
+ {numeralWrapper.formatSleeveSynchro(sleeve.sync)}
Memory:
- {numeralWrapper.formatMemory(sleeve.memory)}
+ {numeralWrapper.formatSleeveMemory(sleeve.memory)}
diff --git a/src/PersonObjects/formulas/intelligence.ts b/src/PersonObjects/formulas/intelligence.ts
index ac0f66f97..1875e77c4 100644
--- a/src/PersonObjects/formulas/intelligence.ts
+++ b/src/PersonObjects/formulas/intelligence.ts
@@ -1,3 +1,3 @@
-export function calculateIntelligenceBonus(intelligence: number, weight: number = 1): number {
+export function calculateIntelligenceBonus(intelligence: number, weight = 1): number {
return 1+(weight*Math.pow(intelligence, 0.8)/600);
}
\ No newline at end of file
diff --git a/src/PersonObjects/formulas/reputation.ts b/src/PersonObjects/formulas/reputation.ts
index b9006ecaa..6e52ad264 100644
--- a/src/PersonObjects/formulas/reputation.ts
+++ b/src/PersonObjects/formulas/reputation.ts
@@ -4,7 +4,7 @@ import { CONSTANTS } from '../../Constants';
import { BitNodeMultipliers } from '../../BitNode/BitNodeMultipliers';
function mult(f: Faction): number {
- var favorMult = 1 + (f.favor / 100);
+ let favorMult = 1 + (f.favor / 100);
if (isNaN(favorMult)) {favorMult = 1;}
return favorMult * BitNodeMultipliers.FactionWorkRepGain;
}
@@ -16,7 +16,7 @@ export function getHackingWorkRepGain(p: IPlayer, f: Faction): number {
}
export function getFactionSecurityWorkRepGain(p: IPlayer, f: Faction): number {
- var t = 0.9 * (p.hacking_skill / CONSTANTS.MaxSkillLevel +
+ const t = 0.9 * (p.hacking_skill / CONSTANTS.MaxSkillLevel +
p.strength / CONSTANTS.MaxSkillLevel +
p.defense / CONSTANTS.MaxSkillLevel +
p.dexterity / CONSTANTS.MaxSkillLevel +
@@ -25,7 +25,7 @@ export function getFactionSecurityWorkRepGain(p: IPlayer, f: Faction): number {
}
export function getFactionFieldWorkRepGain(p: IPlayer, f: Faction): number {
- var t = 0.9 * (p.hacking_skill / CONSTANTS.MaxSkillLevel +
+ const t = 0.9 * (p.hacking_skill / CONSTANTS.MaxSkillLevel +
p.strength / CONSTANTS.MaxSkillLevel +
p.defense / CONSTANTS.MaxSkillLevel +
p.dexterity / CONSTANTS.MaxSkillLevel +
diff --git a/src/PersonObjects/formulas/skill.ts b/src/PersonObjects/formulas/skill.ts
index 3adba0d39..4cf687aa1 100644
--- a/src/PersonObjects/formulas/skill.ts
+++ b/src/PersonObjects/formulas/skill.ts
@@ -1,7 +1,7 @@
-export function calculateSkill(exp: number, mult: number = 1): number {
+export function calculateSkill(exp: number, mult = 1): number {
return Math.max(Math.floor(mult*(32 * Math.log(exp + 534.5) - 200)), 1);
}
-export function calculateExp(skill: number, mult: number = 1): number {
+export function calculateExp(skill: number, mult = 1): number {
return Math.exp((skill / mult + 200) / 32) - 534.6
}
\ No newline at end of file
diff --git a/src/Prestige.js b/src/Prestige.js
index 19bc56089..6c1ce595b 100755
--- a/src/Prestige.js
+++ b/src/Prestige.js
@@ -1,7 +1,7 @@
import { Augmentations } from "./Augmentation/Augmentations";
import {
augmentationExists,
- initAugmentations
+ initAugmentations,
} from "./Augmentation/AugmentationHelpers";
import { AugmentationNames } from "./Augmentation/data/AugmentationNames";
import { initBitNodeMultipliers } from "./BitNode/BitNode";
@@ -14,10 +14,8 @@ import { Engine } from "./engine";
import { Faction } from "./Faction/Faction";
import { Factions, initFactions } from "./Faction/Factions";
import { joinFaction } from "./Faction/FactionHelpers";
-import { deleteGangDisplayContent } from "./Gang";
import { updateHashManagerCapacity } from "./Hacknet/HacknetHelpers";
-import { Message } from "./Message/Message";
-import { initMessages, Messages } from "./Message/MessageHelpers";
+import { initMessages } from "./Message/MessageHelpers";
import { prestigeWorkerScripts } from "./NetscriptWorker";
import { Player } from "./Player";
import { resetPidCounter } from "./Netscript/Pid";
@@ -27,18 +25,17 @@ import {
AllServers,
AddToAllServers,
initForeignServers,
- prestigeAllServers
+ prestigeAllServers,
} from "./Server/AllServers";
-import { Server } from "./Server/Server";
import { prestigeHomeComputer } from "./Server/ServerHelpers";
import {
SourceFileFlags,
- updateSourceFileFlags
+ updateSourceFileFlags,
} from "./SourceFile/SourceFileFlags";
import {
SpecialServerIps,
prestigeSpecialServerIps,
- SpecialServerNames
+ SpecialServerNames,
} from "./Server/SpecialServerIps";
import {
deleteStockMarket,
@@ -289,7 +286,7 @@ function prestigeSourceFile() {
var popupId = "bladeburner-bitnode-start-nsa-notification";
var txt = createElement("p", {
innerText:"Visit the National Security Agency (NSA) to apply for their Bladeburner " +
- "division! You will need 100 of each combat stat before doing this."
+ "division! You will need 100 of each combat stat before doing this.",
})
var brEl = createElement("br");
var okBtn = createElement("a", {
@@ -297,7 +294,7 @@ function prestigeSourceFile() {
clickListener:()=>{
removeElementById(popupId);
return false;
- }
+ },
});
createPopup(popupId, [txt, brEl, okBtn]);
}).catch(function(e) {
@@ -343,6 +340,11 @@ function prestigeSourceFile() {
updateHashManagerCapacity();
}
+ if(SourceFileFlags[12] > 0) {
+ Player.augmentations.push({name: AugmentationNames.NeuroFluxGovernor, level: SourceFileFlags[12]})
+ Player.reapplyAllAugmentations(true);
+ }
+
// Refresh Main Menu (the 'World' menu, specifically)
document.getElementById("world-menu-header").click();
document.getElementById("world-menu-header").click();
diff --git a/src/Programs/Program.ts b/src/Programs/Program.ts
index 96ad7ce04..959cafb5d 100644
--- a/src/Programs/Program.ts
+++ b/src/Programs/Program.ts
@@ -11,7 +11,7 @@ export interface IProgramCreate {
}
export class Program {
- name: string = "";
+ name = "";
create: IProgramCreate | null;
constructor(name: string, create: IProgramCreate | null) {
diff --git a/src/Programs/ProgramHelpers.js b/src/Programs/ProgramHelpers.js
index 9a0875de3..9281949f6 100644
--- a/src/Programs/ProgramHelpers.js
+++ b/src/Programs/ProgramHelpers.js
@@ -1,6 +1,5 @@
import { Programs } from "./Programs";
-import { CONSTANTS } from "../Constants";
import { Player } from "../Player";
import { createElement } from "../../utils/uiHelpers/createElement";
diff --git a/src/Programs/Programs.ts b/src/Programs/Programs.ts
index aede53dca..7461ae798 100644
--- a/src/Programs/Programs.ts
+++ b/src/Programs/Programs.ts
@@ -1,6 +1,5 @@
import { Program } from "./Program";
-import { IProgramCreationParams,
- programsMetadata } from "./data/programsMetadata";
+import { programsMetadata } from "./data/programsMetadata";
import { IMap } from "../types";
export const Programs: IMap
= {};
diff --git a/src/RedPill.js b/src/RedPill.js
index 05892b359..bb44c5e0d 100644
--- a/src/RedPill.js
+++ b/src/RedPill.js
@@ -16,7 +16,7 @@ import {
yesNoBoxCreate,
yesNoBoxGetYesButton,
yesNoBoxGetNoButton,
- yesNoBoxClose
+ yesNoBoxClose,
} from "../utils/YesNoBox";
import { clearEventListeners } from "../utils/uiHelpers/clearEventListeners";
import { removeChildrenFromElement } from "../utils/uiHelpers/removeChildrenFromElement";
@@ -58,13 +58,17 @@ function writeRedPillLetter(pElem, line, i=0) {
}
let redPillFlag = false;
-function hackWorldDaemon(currentNodeNumber, flume=false) {
+function hackWorldDaemon(currentNodeNumber, flume=false, quick=false) {
// Clear Red Pill screen first
var container = document.getElementById("red-pill-content");
removeChildrenFromElement(container);
redPillFlag = true;
Engine.loadRedPillContent();
+
+ if(quick) {
+ return loadBitVerse(currentNodeNumber, flume, quick);
+ }
return writeRedPillLine("[ERROR] SEMPOOL INVALID").then(function() {
return writeRedPillLine("[ERROR] Segmentation Fault");
}).then(function() {
@@ -143,7 +147,7 @@ function giveSourceFile(bitNodeNumber) {
// is destroyed. Updated every time loadBitVerse() is called
let nextSourceFileFlags = [];
-function loadBitVerse(destroyedBitNodeNum, flume=false) {
+function loadBitVerse(destroyedBitNodeNum, flume=false, quick=false) {
// Clear the screen
const container = document.getElementById("red-pill-content");
removeChildrenFromElement(container);
@@ -151,7 +155,7 @@ function loadBitVerse(destroyedBitNodeNum, flume=false) {
// Update NextSourceFileFlags
nextSourceFileFlags = SourceFileFlags.slice();
if (!flume) {
- if (nextSourceFileFlags[destroyedBitNodeNum] < 3 && destroyedBitNodeNum !== 12)
+ if (nextSourceFileFlags[destroyedBitNodeNum] < 3)
++nextSourceFileFlags[destroyedBitNodeNum];
}
@@ -221,6 +225,10 @@ function loadBitVerse(destroyedBitNodeNum, flume=false) {
}(i)); // Immediate invocation closure
}
+ if(quick) {
+ return Promise.resolve(true);
+ }
+
// Create lore text
return writeRedPillLine("Many decades ago, a humanoid extraterrestial species which we call the Enders descended on the Earth...violently").then(function() {
return writeRedPillLine("Our species fought back, but it was futile. The Enders had technology far beyond our own...");
diff --git a/src/SaveObject.jsx b/src/SaveObject.jsx
index 4a75c75a8..5ffbb156d 100755
--- a/src/SaveObject.jsx
+++ b/src/SaveObject.jsx
@@ -2,10 +2,9 @@ import {
loadAliases,
loadGlobalAliases,
Aliases,
- GlobalAliases
+ GlobalAliases,
} from "./Alias";
import { Companies, loadCompanies } from "./Company/Companies";
-import { CompanyPosition } from "./Company/CompanyPosition";
import { CONSTANTS } from "./Constants";
import { Engine } from "./engine";
import { Factions, loadFactions } from "./Faction/Factions";
@@ -15,7 +14,7 @@ import { FconfSettings } from "./Fconf/FconfSettings";
import { loadAllGangs, AllGangs } from "./Gang";
import {
hasHacknetServers,
- processHacknetEarnings
+ processHacknetEarnings,
} from "./Hacknet/HacknetHelpers";
import { loadMessages, initMessages, Messages } from "./Message/MessageHelpers";
import { loadAllRunningScripts } from "./NetscriptWorker";
@@ -24,13 +23,12 @@ import { AllServers, loadAllServers } from "./Server/AllServers";
import { Settings } from "./Settings/Settings";
import {
loadSpecialServerIps,
- SpecialServerIps
+ SpecialServerIps,
} from "./Server/SpecialServerIps";
import { SourceFileFlags } from "./SourceFile/SourceFileFlags";
import { loadStockMarket, StockMarket } from "./StockMarket/StockMarket";
import { createStatusText } from "./ui/createStatusText";
-import { numeralWrapper } from "./ui/numeralFormat";
import { setTimeoutRef } from "./utils/SetTimeoutRef";
@@ -41,7 +39,7 @@ import { clearEventListeners } from "../utils/uiHelpers/clearEventListeners";
import {
Reviver,
Generic_toJSON,
- Generic_fromJSON
+ Generic_fromJSON,
} from "../utils/JSONReviver";
import { createElement } from "../utils/uiHelpers/createElement";
import { createPopup } from "../utils/uiHelpers/createPopup";
@@ -115,10 +113,6 @@ BitburnerSaveObject.prototype.saveGame = function(db) {
console.error("Error saving game to IndexedDB: " + e);
}
- request.onsuccess = function(e) {
- // TODO anything here?
- }
-
try {
window.localStorage.setItem("bitburnerSave", saveString);
} catch(e) {
@@ -467,13 +461,13 @@ function loadImportedGame(saveObj, saveString) {
var popupId = "import-game-restart-game-notice";
var txt = createElement("p", {
innerText:"Imported game! You need to SAVE the game and then RELOAD the page " +
- "to make sure everything runs smoothly"
+ "to make sure everything runs smoothly",
});
var gotitBtn = createElement("a", {
class:"a-link-button", float:"right", padding:"6px", innerText:"Got it!",
clickListener:() => {
removeElementById(popupId);
- }
+ },
});
createPopup(popupId, [txt, gotitBtn]);
gameOptionsBoxClose();
@@ -507,9 +501,6 @@ function loadImportedGame(saveObj, saveString) {
// Hacknet Nodes offline progress
var offlineProductionFromHacknetNodes = processHacknetEarnings(numCyclesOffline);
- const hacknetProdInfo = hasHacknetServers() ?
- <>Hashes(offlineProductionFromHacknetNodes)} hashes> :
- Money(offlineProductionFromHacknetNodes);
// Passive faction rep gain offline
processPassiveFactionRepGain(numCyclesOffline);
@@ -581,7 +572,7 @@ BitburnerSaveObject.prototype.deleteGame = function(db) {
// Delete from indexedDB
var request = db.transaction(["savestring"], "readwrite").objectStore("savestring").delete("save");
- request.onsuccess = function(e) {
+ request.onsuccess = function() {
console.log("Successfully deleted save from indexedDb");
}
request.onerror = function(e) {
diff --git a/src/Script/RamCalculations.js b/src/Script/RamCalculations.js
index 8bffd43b4..7aa6920fa 100644
--- a/src/Script/RamCalculations.js
+++ b/src/Script/RamCalculations.js
@@ -6,7 +6,7 @@
* the way
*/
import * as walk from "acorn-walk";
-import { parse, Node } from "acorn";
+import { parse } from "acorn";
import { RamCalculationErrorCode } from "./RamCalculationErrorCodes";
@@ -247,7 +247,7 @@ function parseOnlyCalculateDeps(code, currentModule) {
// walkDeeper is for doing recursive walks of expressions in composites that we handle.
function commonVisitors() {
return {
- Identifier: (node, st, walkDeeper) => {
+ Identifier: (node, st) => {
if (objectPrototypeProperties.includes(node.name)) {return;}
addRef(st.key, node.name);
},
@@ -282,7 +282,7 @@ function parseOnlyCalculateDeps(code, currentModule) {
}
walk.recursive(ast, {key: globalKey}, Object.assign({
- ImportDeclaration: (node, st, walkDeeper) => {
+ ImportDeclaration: (node, st) => {
const importModuleName = node.source.value;
additionalModules.push(importModuleName);
@@ -301,8 +301,7 @@ function parseOnlyCalculateDeps(code, currentModule) {
}
}
},
- FunctionDeclaration: (node, st, walkDeeper) => {
- // Don't use walkDeeper, because we are changing the visitor set.
+ FunctionDeclaration: (node) => {
const key = currentModule + "." + node.id.name;
walk.recursive(node, {key: key}, commonVisitors());
},
@@ -324,7 +323,7 @@ export async function calculateRamUsage(codeCopy, otherScripts) {
loadedFns: {},
env: {
vars: RamCosts,
- }
+ },
}
try {
diff --git a/src/Script/RunningScript.ts b/src/Script/RunningScript.ts
index f3f9b617c..a1503fa26 100644
--- a/src/Script/RunningScript.ts
+++ b/src/Script/RunningScript.ts
@@ -11,15 +11,11 @@ import { post } from "../ui/postToTerminal";
import {
Generic_fromJSON,
Generic_toJSON,
- Reviver
+ Reviver,
} from "../../utils/JSONReviver";
import { getTimestamp } from "../../utils/helpers/getTimestamp";
export class RunningScript {
- // Initializes a RunningScript Object from a JSON save state
- static fromJSON(value: any): RunningScript {
- return Generic_fromJSON(RunningScript, value.data);
- }
// Script arguments
args: any[] = [];
@@ -29,44 +25,44 @@ export class RunningScript {
dataMap: IMap = {};
// Script filename
- filename: string = "";
+ filename = "";
// This script's logs. An array of log entries
logs: string[] = [];
// Flag indicating whether the logs have been updated since
// the last time the UI was updated
- logUpd: boolean = false;
+ logUpd = false;
// Total amount of hacking experience earned from this script when offline
- offlineExpGained: number = 0;
+ offlineExpGained = 0;
// Total amount of money made by this script when offline
- offlineMoneyMade: number = 0;
+ offlineMoneyMade = 0;
// Number of seconds that the script has been running offline
- offlineRunningTime: number = 0.01;
+ offlineRunningTime = 0.01;
// Total amount of hacking experience earned from this script when online
- onlineExpGained: number = 0;
+ onlineExpGained = 0;
// Total amount of money made by this script when online
- onlineMoneyMade: number = 0;
+ onlineMoneyMade = 0;
// Number of seconds that this script has been running online
- onlineRunningTime: number = 0.01;
+ onlineRunningTime = 0.01;
// Process ID. Must be an integer and equals the PID of corresponding WorkerScript
- pid: number = -1;
+ pid = -1;
// How much RAM this script uses for ONE thread
- ramUsage: number = 0;
+ ramUsage = 0;
// IP of the server on which this script is running
- server: string = "";
+ server = "";
// Number of threads that this script is running with
- threads: number = 1;
+ threads = 1;
constructor(script: Script | null = null, args: any[] = []) {
if (script == null) { return; }
@@ -91,7 +87,7 @@ export class RunningScript {
}
displayLog(): void {
- for (var i = 0; i < this.logs.length; ++i) {
+ for (let i = 0; i < this.logs.length; ++i) {
post(this.logs[i]);
}
}
@@ -101,7 +97,7 @@ export class RunningScript {
}
// Update the moneyStolen and numTimesHack maps when hacking
- recordHack(serverIp: string, moneyGained: number, n: number=1) {
+ recordHack(serverIp: string, moneyGained: number, n=1): void {
if (this.dataMap[serverIp] == null || this.dataMap[serverIp].constructor !== Array) {
this.dataMap[serverIp] = [0, 0, 0, 0];
}
@@ -110,7 +106,7 @@ export class RunningScript {
}
// Update the grow map when calling grow()
- recordGrow(serverIp: string, n: number=1) {
+ recordGrow(serverIp: string, n=1): void {
if (this.dataMap[serverIp] == null || this.dataMap[serverIp].constructor !== Array) {
this.dataMap[serverIp] = [0, 0, 0, 0];
}
@@ -118,7 +114,7 @@ export class RunningScript {
}
// Update the weaken map when calling weaken() {
- recordWeaken(serverIp: string, n: number=1) {
+ recordWeaken(serverIp: string, n=1): void {
if (this.dataMap[serverIp] == null || this.dataMap[serverIp].constructor !== Array) {
this.dataMap[serverIp] = [0, 0, 0, 0];
}
@@ -129,6 +125,12 @@ export class RunningScript {
toJSON(): any {
return Generic_toJSON("RunningScript", this);
}
+
+ // Initializes a RunningScript Object from a JSON save state
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+ static fromJSON(value: any): RunningScript {
+ return Generic_fromJSON(RunningScript, value.data);
+ }
}
Reviver.constructors.RunningScript = RunningScript;
diff --git a/src/Script/Script.ts b/src/Script/Script.ts
index cb3c8d112..24b8ca87e 100644
--- a/src/Script/Script.ts
+++ b/src/Script/Script.ts
@@ -12,26 +12,22 @@ import { setTimeoutRef } from "../utils/SetTimeoutRef";
import {
Generic_fromJSON,
Generic_toJSON,
- Reviver
+ Reviver,
} from "../../utils/JSONReviver";
import { roundToTwo } from "../../utils/helpers/roundToTwo";
let globalModuleSequenceNumber = 0;
export class Script {
- // Initializes a Script Object from a JSON save state
- static fromJSON(value: any): Script {
- return Generic_fromJSON(Script, value.data);
- }
// Code for this script
- code: string = "";
+ code = "";
// Filename for the script file
- filename: string = "";
+ filename = "";
// url of the script if any, only for NS2.
- url: string = "";
+ url = "";
// The dynamic module generated for this script when it is run.
// This is only applicable for NetscriptJS
@@ -46,12 +42,12 @@ export class Script {
dependencies: ScriptUrl[] = [];
// Amount of RAM this Script requres to run
- ramUsage: number = 0;
+ ramUsage = 0;
// IP of server that this script is on.
- server: string = "";
+ server = "";
- constructor(fn: string="", code: string="", server: string="", otherScripts: Script[]=[]) {
+ constructor(fn="", code="", server="", otherScripts: Script[]=[]) {
this.filename = fn;
this.code = code;
this.ramUsage = 0;
@@ -59,7 +55,7 @@ export class Script {
this.module = "";
this.moduleSequenceNumber = ++globalModuleSequenceNumber;
if (this.code !== "") { this.updateRamUsage(otherScripts); }
- };
+ }
/**
* Download the script as a file
@@ -70,7 +66,7 @@ export class Script {
if (window.navigator.msSaveOrOpenBlob) {// IE10+
window.navigator.msSaveOrOpenBlob(file, filename);
} else { // Others
- var a = document.createElement("a"),
+ const a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
@@ -87,7 +83,7 @@ export class Script {
* Marks this script as having been updated. It will be recompiled next time something tries
* to exec it.
*/
- markUpdated() {
+ markUpdated(): void {
this.module = "";
this.moduleSequenceNumber = ++globalModuleSequenceNumber;
}
@@ -107,7 +103,7 @@ export class Script {
console.error(`Failed to get Script filename DOM element`);
return;
}
- this.filename = filenameElem!.value;
+ this.filename = filenameElem.value;
this.server = serverIp;
this.updateRamUsage(otherScripts);
this.markUpdated();
@@ -118,8 +114,8 @@ export class Script {
* Calculates and updates the script's RAM usage based on its code
* @param {Script[]} otherScripts - Other scripts on the server. Used to process imports
*/
- async updateRamUsage(otherScripts: Script[]) {
- var res = await calculateRamUsage(this.code, otherScripts);
+ async updateRamUsage(otherScripts: Script[]): Promise {
+ const res = await calculateRamUsage(this.code, otherScripts);
if (res > 0) {
this.ramUsage = roundToTwo(res);
}
@@ -129,6 +125,12 @@ export class Script {
toJSON(): any {
return Generic_toJSON("Script", this);
}
+
+ // Initializes a Script Object from a JSON save state
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+ static fromJSON(value: any): Script {
+ return Generic_fromJSON(Script, value.data);
+ }
}
Reviver.constructors.Script = Script;
diff --git a/src/Script/ScriptHelpers.js b/src/Script/ScriptHelpers.js
index 1662c35ad..10cbcf257 100644
--- a/src/Script/ScriptHelpers.js
+++ b/src/Script/ScriptHelpers.js
@@ -7,11 +7,10 @@ import { isScriptFilename } from "./ScriptHelpersTS";
import {CONSTANTS} from "../Constants";
import {Engine} from "../engine";
import { parseFconfSettings } from "../Fconf/Fconf";
-import { FconfSettings } from "../Fconf/FconfSettings";
import {
iTutorialSteps,
iTutorialNextStep,
- ITutorial
+ ITutorial,
} from "../InteractiveTutorial";
import { Player } from "../Player";
import { AceEditor } from "../ScriptEditor/Ace";
@@ -28,11 +27,6 @@ import { Page, routing } from "../ui/navigationTracking";
import { numeralWrapper } from "../ui/numeralFormat";
import { dialogBoxCreate } from "../../utils/DialogBox";
-import {
- Reviver,
- Generic_toJSON,
- Generic_fromJSON
-} from "../../utils/JSONReviver";
import { compareArrays } from "../../utils/helpers/compareArrays";
import { createElement } from "../../utils/uiHelpers/createElement";
@@ -56,12 +50,12 @@ export function scriptEditorInit() {
editor.beautifyScript();
}
return false;
- }
+ },
});
// Text that displays RAM calculation
scriptEditorRamText = createElement("p", {
- display:"inline-block", margin:"10px", id:"script-editor-status-text"
+ display:"inline-block", margin:"10px", id:"script-editor-status-text",
});
// Label for checkbox (defined below)
@@ -70,7 +64,7 @@ export function scriptEditorInit() {
innerText:"Dynamic RAM Usage Checker", color:"white",
tooltip:"Enable/Disable the dynamic RAM Usage display. You may " +
"want to disable it for very long scripts because there may be " +
- "performance issues"
+ "performance issues",
});
// Checkbox for enabling/disabling dynamic RAM calculation
@@ -97,7 +91,7 @@ export function scriptEditorInit() {
clickListener:()=>{
saveAndCloseScriptEditor();
return false;
- }
+ },
});
// Add all buttons to the UI
diff --git a/src/Script/ScriptHelpersTS.ts b/src/Script/ScriptHelpersTS.ts
index f59b69810..d6ff294ba 100644
--- a/src/Script/ScriptHelpersTS.ts
+++ b/src/Script/ScriptHelpersTS.ts
@@ -1,4 +1,4 @@
// Script helper functions
-export function isScriptFilename(f: string) {
+export function isScriptFilename(f: string): boolean {
return f.endsWith(".js") || f.endsWith(".script") || f.endsWith(".ns");
}
diff --git a/src/ScriptEditor/Ace.js b/src/ScriptEditor/Ace.js
index 60f8e93a3..389c3bda9 100644
--- a/src/ScriptEditor/Ace.js
+++ b/src/ScriptEditor/Ace.js
@@ -23,8 +23,6 @@ import { AceKeybindingSetting } from "../Settings/SettingEnums";
import { clearEventListeners } from "../../utils/uiHelpers/clearEventListeners";
import { createElement } from "../../utils/uiHelpers/createElement";
import { createOptionElement } from "../../utils/uiHelpers/createOptionElement";
-import { getSelectText,
- getSelectValue } from "../../utils/uiHelpers/getSelectData";
import { removeChildrenFromElement } from "../../utils/uiHelpers/removeChildrenFromElement";
// Wrapper for Ace editor
@@ -78,16 +76,16 @@ class AceEditorWrapper extends ScriptEditor {
// Configure some of the VIM keybindings
ace.config.loadModule('ace/keyboard/vim', function(module) {
var VimApi = module.CodeMirror.Vim;
- VimApi.defineEx('write', 'w', function(cm, input) {
+ VimApi.defineEx('write', 'w', function(/*cm, input*/) {
params.saveAndCloseFn();
});
- VimApi.defineEx('quit', 'q', function(cm, input) {
+ VimApi.defineEx('quit', 'q', function(/*cm, input*/) {
params.quitFn();
});
- VimApi.defineEx('xwritequit', 'x', function(cm, input) {
+ VimApi.defineEx('xwritequit', 'x', function(/*cm, input*/) {
params.saveAndCloseFn();
});
- VimApi.defineEx('wqwritequit', 'wq', function(cm, input) {
+ VimApi.defineEx('wqwritequit', 'wq', function(/*cm, input*/) {
params.saveAndCloseFn();
});
});
@@ -161,8 +159,6 @@ class AceEditorWrapper extends ScriptEditor {
}
try {
- const optionsPanel = safeGetElementById("script-editor-options-panel", "Script Editor Options Panel");
-
// Set editor to visible
const elem = document.getElementById("ace-editor");
if (elem instanceof HTMLElement) {
@@ -287,7 +283,7 @@ class AceEditorWrapper extends ScriptEditor {
changeListener: () => {
this.editor.getSession().$worker.send("changeOptions", [{maxerr:flex1Input.value}]);
flex1ValueLabel.innerText = flex1Input.value;
- }
+ },
});
flex1Fieldset.appendChild(flex1Input);
flex1Fieldset.appendChild(flex1ValueLabel);
diff --git a/src/ScriptEditor/AceNetscriptMode.js b/src/ScriptEditor/AceNetscriptMode.js
index 15e70087a..d8d6c2233 100644
--- a/src/ScriptEditor/AceNetscriptMode.js
+++ b/src/ScriptEditor/AceNetscriptMode.js
@@ -1,7 +1,7 @@
//This file should be copied into brace/mode/netscript.js
import { NetscriptFunctions } from '../NetscriptFunctions';
-ace.define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(acequire, exports, module) {
+ace.define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(acequire, exports) {
"use strict";
var oop = acequire("../lib/oop");
@@ -11,22 +11,22 @@ var DocCommentHighlightRules = function() {
this.$rules = {
"start" : [ {
token : "comment.doc.tag",
- regex : "@[\\w\\d_]+" // TODO: fix email addresses
+ regex : "@[\\w\\d_]+", // TODO: fix email addresses
},
DocCommentHighlightRules.getTagRule(),
{
defaultToken : "comment.doc",
- caseInsensitive: true
- }]
+ caseInsensitive: true,
+ }],
};
};
oop.inherits(DocCommentHighlightRules, TextHighlightRules);
-DocCommentHighlightRules.getTagRule = function(start) {
+DocCommentHighlightRules.getTagRule = function() {
return {
token : "comment.doc.tag.storage.type",
- regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b"
+ regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b",
};
}
@@ -34,7 +34,7 @@ DocCommentHighlightRules.getStartRule = function(start) {
return {
token : "comment.doc", // doc comment
regex : "\\/\\*(?=\\*)",
- next : start
+ next : start,
};
};
@@ -42,7 +42,7 @@ DocCommentHighlightRules.getEndRule = function (start) {
return {
token : "comment.doc", // closing comment
regex : "\\*\\/",
- next : start
+ next : start,
};
};
@@ -50,7 +50,7 @@ exports.DocCommentHighlightRules = DocCommentHighlightRules;
});
-ace.define("ace/mode/netscript_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(acequire, exports, module) {
+ace.define("ace/mode/netscript_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(acequire, exports) {
"use strict";
var oop = acequire("../lib/oop");
@@ -101,7 +101,7 @@ var NetscriptHighlightRules = function(options) {
"null|Infinity|NaN|undefined",
"support.function":
"alert",
- "constant.language.boolean": "true|false"
+ "constant.language.boolean": "true|false",
}, "identifier");
var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void";
@@ -120,136 +120,136 @@ var NetscriptHighlightRules = function(options) {
{
token : "string",
regex : "'(?=.)",
- next : "qstring"
+ next : "qstring",
}, {
token : "string",
regex : '"(?=.)',
- next : "qqstring"
+ next : "qqstring",
}, {
token : "constant.numeric", // hex
- regex : /0(?:[xX][0-9a-fA-F]+|[bB][01]+)\b/
+ regex : /0(?:[xX][0-9a-fA-F]+|[bB][01]+)\b/,
}, {
token : "constant.numeric", // float
- regex : /[+-]?\d[\d_]*(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
+ regex : /[+-]?\d[\d_]*(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/,
}, {
token : [
"storage.type", "punctuation.operator", "support.function",
- "punctuation.operator", "entity.name.function", "text","keyword.operator"
+ "punctuation.operator", "entity.name.function", "text","keyword.operator",
],
regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)",
- next: "function_arguments"
+ next: "function_arguments",
}, {
token : [
"storage.type", "punctuation.operator", "entity.name.function", "text",
- "keyword.operator", "text", "storage.type", "text", "paren.lparen"
+ "keyword.operator", "text", "storage.type", "text", "paren.lparen",
],
regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
- next: "function_arguments"
+ next: "function_arguments",
}, {
token : [
"entity.name.function", "text", "keyword.operator", "text", "storage.type",
- "text", "paren.lparen"
+ "text", "paren.lparen",
],
regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
- next: "function_arguments"
+ next: "function_arguments",
}, {
token : [
"storage.type", "punctuation.operator", "entity.name.function", "text",
"keyword.operator", "text",
- "storage.type", "text", "entity.name.function", "text", "paren.lparen"
+ "storage.type", "text", "entity.name.function", "text", "paren.lparen",
],
regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s+)(\\w+)(\\s*)(\\()",
- next: "function_arguments"
+ next: "function_arguments",
}, {
token : [
- "storage.type", "text", "entity.name.function", "text", "paren.lparen"
+ "storage.type", "text", "entity.name.function", "text", "paren.lparen",
],
regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()",
- next: "function_arguments"
+ next: "function_arguments",
}, {
token : [
"entity.name.function", "text", "punctuation.operator",
- "text", "storage.type", "text", "paren.lparen"
+ "text", "storage.type", "text", "paren.lparen",
],
regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()",
- next: "function_arguments"
+ next: "function_arguments",
}, {
token : [
- "text", "text", "storage.type", "text", "paren.lparen"
+ "text", "text", "storage.type", "text", "paren.lparen",
],
regex : "(:)(\\s*)(function)(\\s*)(\\()",
- next: "function_arguments"
+ next: "function_arguments",
}, {
token : "keyword",
regex : "(?:" + kwBeforeRe + ")\\b",
- next : "start"
+ next : "start",
}, {
token : ["support.constant"],
- regex : /that\b/
+ regex : /that\b/,
}, {
token : ["storage.type", "punctuation.operator", "support.function.firebug"],
- regex : /(console)(\.)(warn|info|log|error|time|trace|timeEnd|assert)\b/
+ regex : /(console)(\.)(warn|info|log|error|time|trace|timeEnd|assert)\b/,
}, {
token : keywordMapper,
- regex : identifierRe
+ regex : identifierRe,
}, {
token : "punctuation.operator",
regex : /[.](?![.])/,
- next : "property"
+ next : "property",
}, {
token : "keyword.operator",
regex : /--|\+\+|\.{3}|===|==|=|!=|!==|<+=?|>+=?|!|&&|\|\||\?:|[!$%&*+\-~\/^]=?/,
- next : "start"
+ next : "start",
}, {
token : "punctuation.operator",
regex : /[?:,;.]/,
- next : "start"
+ next : "start",
}, {
token : "paren.lparen",
regex : /[\[({]/,
- next : "start"
+ next : "start",
}, {
token : "paren.rparen",
- regex : /[\])}]/
+ regex : /[\])}]/,
}, {
token: "comment",
- regex: /^#!.*$/
- }
+ regex: /^#!.*$/,
+ },
],
property: [{
token : "text",
- regex : "\\s+"
+ regex : "\\s+",
}, {
token : [
"storage.type", "punctuation.operator", "entity.name.function", "text",
"keyword.operator", "text",
- "storage.type", "text", "entity.name.function", "text", "paren.lparen"
+ "storage.type", "text", "entity.name.function", "text", "paren.lparen",
],
regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(?:(\\s+)(\\w+))?(\\s*)(\\()",
- next: "function_arguments"
+ next: "function_arguments",
}, {
token : "punctuation.operator",
- regex : /[.](?![.])/
+ regex : /[.](?![.])/,
}, {
token : "support.function",
- regex : "/|" + functions + "|/"
+ regex : "/|" + functions + "|/",
}, {
token : "support.function",
- regex : /(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/
+ regex : /(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/,
}, {
token : "support.function.dom",
- regex : /(s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName|ClassName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/
+ regex : /(s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName|ClassName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/,
}, {
token : "support.constant",
- regex : /(s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/
+ regex : /(s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/,
}, {
token : "identifier",
- regex : identifierRe
+ regex : identifierRe,
}, {
regex: "",
token: "empty",
- next: "no_regex"
- }
+ next: "no_regex",
+ },
],
"start": [
DocCommentHighlightRules.getStartRule("doc-start"),
@@ -257,113 +257,113 @@ var NetscriptHighlightRules = function(options) {
{
token: "string.regexp",
regex: "\\/",
- next: "regex"
+ next: "regex",
}, {
token : "text",
regex : "\\s+|^$",
- next : "start"
+ next : "start",
}, {
token: "empty",
regex: "",
- next: "no_regex"
- }
+ next: "no_regex",
+ },
],
"regex": [
{
token: "regexp.keyword.operator",
- regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
+ regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)",
}, {
token: "string.regexp",
regex: "/[sxngimy]*",
- next: "no_regex"
+ next: "no_regex",
}, {
token : "invalid",
- regex: /\{\d+\b,?\d*\}[+*]|[+*$^?][+*]|[$^][?]|\?{3,}/
+ regex: /\{\d+\b,?\d*\}[+*]|[+*$^?][+*]|[$^][?]|\?{3,}/,
}, {
token : "constant.language.escape",
- regex: /\(\?[:=!]|\)|\{\d+\b,?\d*\}|[+*]\?|[()$^+*?.]/
+ regex: /\(\?[:=!]|\)|\{\d+\b,?\d*\}|[+*]\?|[()$^+*?.]/,
}, {
token : "constant.language.delimiter",
- regex: /\|/
+ regex: /\|/,
}, {
token: "constant.language.escape",
regex: /\[\^?/,
- next: "regex_character_class"
+ next: "regex_character_class",
}, {
token: "empty",
regex: "$",
- next: "no_regex"
+ next: "no_regex",
}, {
- defaultToken: "string.regexp"
- }
+ defaultToken: "string.regexp",
+ },
],
"regex_character_class": [
{
token: "regexp.charclass.keyword.operator",
- regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
+ regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)",
}, {
token: "constant.language.escape",
regex: "]",
- next: "regex"
+ next: "regex",
}, {
token: "constant.language.escape",
- regex: "-"
+ regex: "-",
}, {
token: "empty",
regex: "$",
- next: "no_regex"
+ next: "no_regex",
}, {
- defaultToken: "string.regexp.charachterclass"
- }
+ defaultToken: "string.regexp.charachterclass",
+ },
],
"function_arguments": [
{
token: "variable.parameter",
- regex: identifierRe
+ regex: identifierRe,
}, {
token: "punctuation.operator",
- regex: "[, ]+"
+ regex: "[, ]+",
}, {
token: "punctuation.operator",
- regex: "$"
+ regex: "$",
}, {
token: "empty",
regex: "",
- next: "no_regex"
- }
+ next: "no_regex",
+ },
],
"qqstring" : [
{
token : "constant.language.escape",
- regex : escapedRe
+ regex : escapedRe,
}, {
token : "string",
regex : "\\\\$",
- next : "qqstring"
+ next : "qqstring",
}, {
token : "string",
regex : '"|$',
- next : "no_regex"
+ next : "no_regex",
}, {
- defaultToken: "string"
- }
+ defaultToken: "string",
+ },
],
"qstring" : [
{
token : "constant.language.escape",
- regex : escapedRe
+ regex : escapedRe,
}, {
token : "string",
regex : "\\\\$",
- next : "qstring"
+ next : "qstring",
}, {
token : "string",
regex : "'|$",
- next : "no_regex"
+ next : "no_regex",
}, {
- defaultToken: "string"
- }
- ]
+ defaultToken: "string",
+ },
+ ],
};
@@ -382,24 +382,24 @@ var NetscriptHighlightRules = function(options) {
}
return val == "{" ? "paren.lparen" : "paren.rparen";
},
- nextState: "start"
+ nextState: "start",
}, {
token : "string.quasi.start",
regex : /`/,
push : [{
token : "constant.language.escape",
- regex : escapedRe
+ regex : escapedRe,
}, {
token : "paren.quasi.start",
regex : /\${/,
- push : "start"
+ push : "start",
}, {
token : "string.quasi.end",
regex : /`/,
- next : "pop"
+ next : "pop",
}, {
- defaultToken: "string.quasi"
- }]
+ defaultToken: "string.quasi",
+ }],
});
if (!options || options.jsx != false)
@@ -436,27 +436,27 @@ function JSX() {
}
return [{
type: "meta.tag.punctuation." + (offset == 1 ? "" : "end-") + "tag-open.xml",
- value: val.slice(0, offset)
+ value: val.slice(0, offset),
}, {
type: "meta.tag.tag-name.xml",
- value: val.substr(offset)
+ value: val.substr(offset),
}];
},
regex : "?" + tagRegex + "",
next: "jsxAttributes",
- nextState: "jsx"
+ nextState: "jsx",
};
this.$rules.start.unshift(jsxTag);
var jsxJsRule = {
regex: "{",
token: "paren.quasi.start",
- push: "start"
+ push: "start",
};
this.$rules.jsx = [
jsxJsRule,
jsxTag,
{include : "reference"},
- {defaultToken: "string"}
+ {defaultToken: "string"},
];
this.$rules.jsxAttributes = [{
token : "meta.tag.punctuation.tag-close.xml",
@@ -474,19 +474,19 @@ function JSX() {
this.next = stack[0] || "start";
return [{type: this.token, value: value}];
},
- nextState: "jsx"
+ nextState: "jsx",
},
jsxJsRule,
comments("jsxAttributes"),
{
token : "entity.other.attribute-name.xml",
- regex : tagRegex
+ regex : tagRegex,
}, {
token : "keyword.operator.attribute-equals.xml",
- regex : "="
+ regex : "=",
}, {
token : "text.tag-whitespace.xml",
- regex : "\\s+"
+ regex : "\\s+",
}, {
token : "string.attribute-value.xml",
regex : "'",
@@ -494,8 +494,8 @@ function JSX() {
push : [
{token : "string.attribute-value.xml", regex: "'", next: "pop"},
{include : "reference"},
- {defaultToken : "string.attribute-value.xml"}
- ]
+ {defaultToken : "string.attribute-value.xml"},
+ ],
}, {
token : "string.attribute-value.xml",
regex : '"',
@@ -503,14 +503,14 @@ function JSX() {
push : [
{token : "string.attribute-value.xml", regex: '"', next: "pop"},
{include : "reference"},
- {defaultToken : "string.attribute-value.xml"}
- ]
+ {defaultToken : "string.attribute-value.xml"},
+ ],
},
- jsxTag
+ jsxTag,
];
this.$rules.reference = [{
token : "constant.language.escape.reference.xml",
- regex : "(?:[0-9]+;)|(?:[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)"
+ regex : "(?:[0-9]+;)|(?:[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)",
}];
}
@@ -522,28 +522,30 @@ function comments(next) {
next: [
DocCommentHighlightRules.getTagRule(),
{token : "comment", regex : "\\*\\/", next : next || "pop"},
- {defaultToken : "comment", caseInsensitive: true}
- ]
+ {defaultToken : "comment", caseInsensitive: true},
+ ],
}, {
token : "comment",
regex : "\\/\\/",
next: [
DocCommentHighlightRules.getTagRule(),
{token : "comment", regex : "$|^", next : next || "pop"},
- {defaultToken : "comment", caseInsensitive: true}
- ]
- }
+ {defaultToken : "comment", caseInsensitive: true},
+ ],
+ },
];
}
exports.NetscriptHighlightRules = NetscriptHighlightRules;
});
-ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(acequire, exports, module) {
+ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(acequire, exports) {
"use strict";
var Range = acequire("../range").Range;
-var MatchingBraceOutdent = function() {};
+var MatchingBraceOutdent = function() {
+ // do nothing.
+};
(function() {
@@ -578,7 +580,7 @@ var MatchingBraceOutdent = function() {};
exports.MatchingBraceOutdent = MatchingBraceOutdent;
});
-ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(acequire, exports, module) {
+ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(acequire, exports) {
"use strict";
var oop = acequire("../../lib/oop");
@@ -588,10 +590,10 @@ var BaseFoldMode = acequire("./fold_mode").FoldMode;
var FoldMode = exports.FoldMode = function(commentRegex) {
if (commentRegex) {
this.foldingStartMarker = new RegExp(
- this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
+ this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start),
);
this.foldingStopMarker = new RegExp(
- this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
+ this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end),
);
}
};
@@ -718,7 +720,7 @@ oop.inherits(FoldMode, BaseFoldMode);
});
-ace.define("ace/mode/netscript",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/netscript_highlight_rules","ace/mode/matching_brace_outdent","ace/worker/worker_client","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"], function(acequire, exports, module) {
+ace.define("ace/mode/netscript",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/netscript_highlight_rules","ace/mode/matching_brace_outdent","ace/worker/worker_client","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"], function(acequire, exports) {
"use strict";
var oop = acequire("../lib/oop");
diff --git a/src/ScriptEditor/CodeMirror.js b/src/ScriptEditor/CodeMirror.js
index d2099c9b6..51d72c4db 100644
--- a/src/ScriptEditor/CodeMirror.js
+++ b/src/ScriptEditor/CodeMirror.js
@@ -98,8 +98,6 @@ import { Settings } from "../Settings/Settings";
import { clearEventListeners } from "../../utils/uiHelpers/clearEventListeners";
import { createElement } from "../../utils/uiHelpers/createElement";
import { createOptionElement } from "../../utils/uiHelpers/createOptionElement";
-import { getSelectText,
- getSelectValue } from "../../utils/uiHelpers/getSelectData";
import { removeChildrenFromElement } from "../../utils/uiHelpers/removeChildrenFromElement";
// Max number of invisibles to be shown in a group if the "Show Invisibles" option
@@ -209,7 +207,7 @@ class CodeMirrorEditorWrapper extends ScriptEditor {
return item.match(regex);
})).sort(),
from: CodeMirror.Pos(cursor.line, start),
- to: CodeMirror.Pos(cursor.line, end)
+ to: CodeMirror.Pos(cursor.line, end),
};
return result;
@@ -217,16 +215,16 @@ class CodeMirrorEditorWrapper extends ScriptEditor {
// Configure VIM keybindings
var VimApi = CodeMirror.Vim;
- VimApi.defineEx('write', 'w', function(cm, input) {
+ VimApi.defineEx('write', 'w', function() {
params.saveAndCloseFn();
});
- VimApi.defineEx('quit', 'q', function(cm, input) {
+ VimApi.defineEx('quit', 'q', function() {
params.quitFn();
});
- VimApi.defineEx('xwritequit', 'x', function(cm, input) {
+ VimApi.defineEx('xwritequit', 'x', function() {
params.saveAndCloseFn();
});
- VimApi.defineEx('wqwritequit', 'wq', function(cm, input) {
+ VimApi.defineEx('wqwritequit', 'wq', function() {
params.saveAndCloseFn();
});
}
@@ -355,7 +353,7 @@ class CodeMirrorEditorWrapper extends ScriptEditor {
keys = keys + key;
this.vimCommandDisplay.innerHTML = keys;
}
- const handleVimCommandDone = (e) => {
+ const handleVimCommandDone = () => {
keys = '';
this.vimCommandDisplay.innerHTML = keys;
}
@@ -387,7 +385,7 @@ class CodeMirrorEditorWrapper extends ScriptEditor {
showInvisiblesChkBox.onchange = () => {
const overlayMode = {
name: 'invisibles',
- token: function nextToken(stream) {
+ token: function(stream) {
var ret,
spaces = 0,
space = stream.peek() === ' ';
@@ -412,7 +410,7 @@ class CodeMirrorEditorWrapper extends ScriptEditor {
}
return ret;
- }
+ },
};
if (showInvisiblesChkBox.checked) {
@@ -452,7 +450,7 @@ class CodeMirrorEditorWrapper extends ScriptEditor {
},
"Shift-Tab": function (cm) {
cm.indentSelection("subtract");
- }
+ },
});
} else {
this.editor.removeKeyMap("soft-tabs-keymap");
diff --git a/src/ScriptEditor/CodeMirrorNetscriptLint.js b/src/ScriptEditor/CodeMirrorNetscriptLint.js
index c83f77ef8..c0a2a776f 100644
--- a/src/ScriptEditor/CodeMirrorNetscriptLint.js
+++ b/src/ScriptEditor/CodeMirrorNetscriptLint.js
@@ -10,6 +10,7 @@
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
+
// declare global: JSHINT
function validator(text, options) {
@@ -72,7 +73,7 @@
message: error.reason,
severity: error.code ? (error.code.startsWith('W') ? "warning" : "error") : "error",
from: CodeMirror.Pos(error.line - 1, start),
- to: CodeMirror.Pos(error.line - 1, end)
+ to: CodeMirror.Pos(error.line - 1, end),
};
output.push(hint);
diff --git a/src/ScriptEditor/CodeMirrorNetscriptMode.js b/src/ScriptEditor/CodeMirrorNetscriptMode.js
index 33c29e1e0..079d77eec 100644
--- a/src/ScriptEditor/CodeMirrorNetscriptMode.js
+++ b/src/ScriptEditor/CodeMirrorNetscriptMode.js
@@ -21,7 +21,7 @@ CodeMirror.defineMode("netscript", function(config, parserConfig) {
// Tokenizer
- var keywords = function(){
+ var keywords = (function(){
function kw(type) {return {type: type, style: "keyword"};}
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c"), D = kw("keyword d");
var operator = kw("operator"), atom = {type: "atom", style: "atom"};
@@ -268,7 +268,7 @@ CodeMirror.defineMode("netscript", function(config, parserConfig) {
"getSleevePurchasableAugs": atom,
"purchaseSleeveAug": atom,
};
- }();
+ }());
var isOperatorChar = /[+\-*&%=<>!?|~^@]/;
var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;
@@ -576,7 +576,7 @@ CodeMirror.defineMode("netscript", function(config, parserConfig) {
if (type == wanted) return cont();
else if (wanted == ";" || type == "}" || type == ")" || type == "]") return pass();
else return cont(exp);
- };
+ }
return exp;
}
@@ -1067,7 +1067,7 @@ CodeMirror.defineMode("netscript", function(config, parserConfig) {
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
localVars: parserConfig.localVars,
context: parserConfig.localVars && new Context(null, null, false),
- indented: basecolumn || 0
+ indented: basecolumn || 0,
};
if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
state.globalVars = parserConfig.globalVars;
@@ -1135,7 +1135,7 @@ CodeMirror.defineMode("netscript", function(config, parserConfig) {
skipExpression: function(state) {
var top = state.cc[state.cc.length - 1]
if (top == expression || top == expressionNoComma) state.cc.pop()
- }
+ },
};
});
diff --git a/src/ScriptEditor/CursorPositions.ts b/src/ScriptEditor/CursorPositions.ts
index a31493f50..710532be6 100644
--- a/src/ScriptEditor/CursorPositions.ts
+++ b/src/ScriptEditor/CursorPositions.ts
@@ -10,7 +10,7 @@ export class PositionTracker {
this.positions = new Map();
}
- saveCursor(filename: string, pos: Position) {
+ saveCursor(filename: string, pos: Position): void {
this.positions.set(filename, pos);
}
@@ -24,6 +24,6 @@ export class PositionTracker {
}
return position;
}
-};
+}
export const CursorPositions: PositionTracker = new PositionTracker();
\ No newline at end of file
diff --git a/src/Server/AllServers.ts b/src/Server/AllServers.ts
index c91dce857..dda3fa5a7 100644
--- a/src/Server/AllServers.ts
+++ b/src/Server/AllServers.ts
@@ -16,7 +16,7 @@ import { Reviver } from "../../utils/JSONReviver";
*/
export let AllServers: IMap = {};
-export function ipExists(ip: string) {
+export function ipExists(ip: string): boolean {
return (AllServers[ip] != null);
}
@@ -33,7 +33,7 @@ export function createUniqueRandomIp(): string {
// Saftely add a Server to the AllServers map
export function AddToAllServers(server: Server | HacknetServer): void {
- var serverIp = server.ip;
+ const serverIp = server.ip;
if (ipExists(serverIp)) {
console.warn(`IP of server that's being added: ${serverIp}`);
console.warn(`Hostname of the server thats being added: ${server.hostname}`);
@@ -58,7 +58,7 @@ interface IServerParams {
[key: string]: any;
}
-export function initForeignServers(homeComputer: Server) {
+export function initForeignServers(homeComputer: Server): void {
/* Create a randomized network for all the foreign servers */
//Groupings for creating a randomized network
const networkLayers: Server[][] = [];
@@ -71,10 +71,10 @@ export function initForeignServers(homeComputer: Server) {
"hackDifficulty",
"moneyAvailable",
"requiredHackingSkill",
- "serverGrowth"
+ "serverGrowth",
];
- const toNumber = (value: any) => {
+ const toNumber = (value: any): any => {
switch (typeof value) {
case 'number':
return value;
@@ -90,7 +90,7 @@ export function initForeignServers(homeComputer: Server) {
hostname: metadata.hostname,
ip: createUniqueRandomIp(),
numOpenPortsRequired: metadata.numOpenPortsRequired,
- organizationName: metadata.organizationName
+ organizationName: metadata.organizationName,
};
if (metadata.maxRamExponent !== undefined) {
@@ -119,14 +119,14 @@ export function initForeignServers(homeComputer: Server) {
}
/* Create a randomized network for all the foreign servers */
- const linkComputers = (server1: Server, server2: Server) => {
+ const linkComputers = (server1: Server, server2: Server): void => {
server1.serversOnNetwork.push(server2.ip);
server2.serversOnNetwork.push(server1.ip);
};
- const getRandomArrayItem = (arr: any[]) => arr[Math.floor(Math.random() * arr.length)];
+ const getRandomArrayItem = (arr: any[]): any => arr[Math.floor(Math.random() * arr.length)];
- const linkNetworkLayers = (network1: Server[], selectServer: () => Server) => {
+ const linkNetworkLayers = (network1: Server[], selectServer: () => Server): void => {
for (const server of network1) {
linkComputers(server, selectServer());
}
@@ -139,13 +139,13 @@ export function initForeignServers(homeComputer: Server) {
}
}
-export function prestigeAllServers() {
- for (var member in AllServers) {
+export function prestigeAllServers(): void {
+ for (const member in AllServers) {
delete AllServers[member];
}
AllServers = {};
}
-export function loadAllServers(saveString: string) {
+export function loadAllServers(saveString: string): void {
AllServers = JSON.parse(saveString, Reviver);
}
diff --git a/src/Server/BaseServer.ts b/src/Server/BaseServer.ts
index f5351787f..b86e1849e 100644
--- a/src/Server/BaseServer.ts
+++ b/src/Server/BaseServer.ts
@@ -23,34 +23,39 @@ interface IConstructorParams {
organizationName?: string;
}
+interface writeResult {
+ success: boolean;
+ overwritten: boolean;
+}
+
export class BaseServer {
// Coding Contract files on this server
contracts: CodingContract[] = [];
// How many CPU cores this server has. Maximum of 8.
// Currently, this only affects hacking missions
- cpuCores: number = 1;
+ cpuCores = 1;
// Flag indicating whether the FTP port is open
- ftpPortOpen: boolean = false;
+ ftpPortOpen = false;
// Flag indicating whether player has admin/root access to this server
- hasAdminRights: boolean = false;
+ hasAdminRights = false;
// Hostname. Must be unique
- hostname: string = "";
+ hostname = "";
// Flag indicating whether HTTP Port is open
- httpPortOpen: boolean = false;
+ httpPortOpen = false;
// IP Address. Must be unique
- ip: string = "";
+ ip = "";
// Flag indicating whether player is curently connected to this server
- isConnectedTo: boolean = false;
+ isConnectedTo = false;
// RAM (GB) available on this server
- maxRam: number = 0;
+ maxRam = 0;
// Message files AND Literature files on this Server
// For Literature files, this array contains only the filename (string)
@@ -60,13 +65,13 @@ export class BaseServer {
// Name of company/faction/etc. that this server belongs to.
// Optional, not applicable to all Servers
- organizationName: string = "";
+ organizationName = "";
// Programs on this servers. Contains only the names of the programs
programs: string[] = [];
// RAM (GB) used. i.e. unavailable RAM
- ramUsed: number = 0;
+ ramUsed = 0;
// RunningScript files on this server
runningScripts: RunningScript[] = [];
@@ -79,13 +84,13 @@ export class BaseServer {
serversOnNetwork: string[] = [];
// Flag indicating whether SMTP Port is open
- smtpPortOpen: boolean = false;
+ smtpPortOpen = false;
// Flag indicating whether SQL Port is open
- sqlPortOpen: boolean = false;
+ sqlPortOpen = false;
// Flag indicating whether the SSH Port is open
- sshPortOpen: boolean = false;
+ sshPortOpen = false;
// Text files on this server
textFiles: TextFile[] = [];
@@ -101,7 +106,7 @@ export class BaseServer {
this.hasAdminRights = params.adminRights != null ? params.adminRights : false;
}
- addContract(contract: CodingContract) {
+ addContract(contract: CodingContract): void {
this.contracts.push(contract);
}
@@ -122,7 +127,7 @@ export class BaseServer {
* Returns null if no such script can be found
*/
getRunningScript(scriptName: string, scriptArgs: any[]): RunningScript | null {
- for (let rs of this.runningScripts) {
+ for (const rs of this.runningScripts) {
if (rs.filename === scriptName && compareArrays(rs.args, scriptArgs)) {
return rs;
}
@@ -158,7 +163,7 @@ export class BaseServer {
return false;
}
- removeContract(contract: CodingContract) {
+ removeContract(contract: CodingContract): void {
if (contract instanceof CodingContract) {
this.contracts = this.contracts.filter((c) => {
return c.fn !== contract.fn;
@@ -199,7 +204,7 @@ export class BaseServer {
}
} else if (fn.endsWith(".lit")) {
for (let i = 0; i < this.messages.length; ++i) {
- let f = this.messages[i];
+ const f = this.messages[i];
if (typeof f === "string" && f === fn) {
this.messages.splice(i, 1);
return { res: true };
@@ -242,14 +247,14 @@ export class BaseServer {
* Write to a script file
* Overwrites existing files. Creates new files if the script does not eixst
*/
- writeToScriptFile(fn: string, code: string) {
- var ret = { success: false, overwritten: false };
+ writeToScriptFile(fn: string, code: string): writeResult {
+ const ret = { success: false, overwritten: false };
if (!isValidFilePath(fn) || !isScriptFilename(fn)) { return ret; }
// Check if the script already exists, and overwrite it if it does
for (let i = 0; i < this.scripts.length; ++i) {
if (fn === this.scripts[i].filename) {
- let script = this.scripts[i];
+ const script = this.scripts[i];
script.code = code;
script.updateRamUsage(this.scripts);
script.markUpdated();
@@ -268,8 +273,8 @@ export class BaseServer {
// Write to a text file
// Overwrites existing files. Creates new files if the text file does not exist
- writeToTextFile(fn: string, txt: string) {
- var ret = { success: false, overwritten: false };
+ writeToTextFile(fn: string, txt: string): writeResult {
+ const ret = { success: false, overwritten: false };
if (!isValidFilePath(fn) || !fn.endsWith("txt")) { return ret; }
// Check if the text file already exists, and overwrite if it does
@@ -283,7 +288,7 @@ export class BaseServer {
}
// Otherwise create a new text file
- var newFile = new TextFile(fn, txt);
+ const newFile = new TextFile(fn, txt);
this.textFiles.push(newFile);
ret.success = true;
return ret;
diff --git a/src/Server/Server.ts b/src/Server/Server.ts
index 4dc8bb201..f33f5b0fc 100644
--- a/src/Server/Server.ts
+++ b/src/Server/Server.ts
@@ -25,45 +25,41 @@ export interface IConstructorParams {
}
export class Server extends BaseServer {
- // Initializes a Server Object from a JSON save state
- static fromJSON(value: any): Server {
- return Generic_fromJSON(Server, value.data);
- }
// Flag indicating whether this server has a backdoor installed by a player
- backdoorInstalled: boolean = false;
+ backdoorInstalled = false;
// Initial server security level
// (i.e. security level when the server was created)
- baseDifficulty: number = 1;
+ baseDifficulty = 1;
// Server Security Level
- hackDifficulty: number = 1;
+ hackDifficulty = 1;
// Minimum server security level that this server can be weakened to
- minDifficulty: number = 1;
+ minDifficulty = 1;
// How much money currently resides on the server and can be hacked
- moneyAvailable: number = 0;
+ moneyAvailable = 0;
// Maximum amount of money that this server can hold
- moneyMax: number = 0;
+ moneyMax = 0;
// Number of open ports required in order to gain admin/root access
- numOpenPortsRequired: number = 5;
+ numOpenPortsRequired = 5;
// How many ports are currently opened on the server
- openPortCount: number = 0;
+ openPortCount = 0;
// Flag indicating wehther this is a purchased server
- purchasedByPlayer: boolean = false;
+ purchasedByPlayer = false;
// Hacking level required to hack this server
- requiredHackingSkill: number = 1;
+ requiredHackingSkill = 1;
// Parameter that affects how effectively this server's money can
// be increased using the grow() Netscript function
- serverGrowth: number = 1;
+ serverGrowth = 1;
constructor(params: IConstructorParams={hostname: "", ip: createRandomIp() }) {
super(params);
@@ -91,7 +87,7 @@ export class Server extends BaseServer {
//Port information, required for porthacking servers to get admin rights
this.numOpenPortsRequired = params.numOpenPortsRequired != null ? params.numOpenPortsRequired : 5;
- };
+ }
/**
* Ensures that the server's difficulty (server security) doesn't get too high
@@ -110,7 +106,7 @@ export class Server extends BaseServer {
* @param n - Value by which to increase/decrease the server's minimum security
* @param perc - Whether it should be changed by a percentage, or a flat value
*/
- changeMinimumSecurity(n: number, perc: boolean=false): void {
+ changeMinimumSecurity(n: number, perc=false): void {
if (perc) {
this.minDifficulty *= n;
} else {
@@ -126,7 +122,7 @@ export class Server extends BaseServer {
* @param n - Value by which to change the server's maximum money
* @param perc - Whether it should be changed by a percentage, or a flat value
*/
- changeMaximumMoney(n: number, perc: boolean=false): void {
+ changeMaximumMoney(n: number, perc=false): void {
if (perc) {
this.moneyMax *= n;
} else {
@@ -156,6 +152,12 @@ export class Server extends BaseServer {
toJSON(): any {
return Generic_toJSON("Server", this);
}
+
+ // Initializes a Server Object from a JSON save state
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+ static fromJSON(value: any): Server {
+ return Generic_fromJSON(Server, value.data);
+ }
}
Reviver.constructors.Server = Server;
diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts
index 1f7c026d7..a7171e6c3 100644
--- a/src/Server/ServerHelpers.ts
+++ b/src/Server/ServerHelpers.ts
@@ -46,7 +46,7 @@ export function safetlyCreateUniqueServer(params: IConstructorParams): Server {
* @param p - Reference to Player object
* @returns Number of "growth cycles" needed
*/
-export function numCycleForGrowth(server: Server, growth: number, p: IPlayer) {
+export function numCycleForGrowth(server: Server, growth: number, p: IPlayer): number {
let ajdGrowthRate = 1 + (CONSTANTS.ServerBaseGrowthRate - 1) / server.hackDifficulty;
if (ajdGrowthRate > CONSTANTS.ServerMaxGrowthRate) {
ajdGrowthRate = CONSTANTS.ServerMaxGrowthRate;
@@ -60,7 +60,7 @@ export function numCycleForGrowth(server: Server, growth: number, p: IPlayer) {
}
//Applied server growth for a single server. Returns the percentage growth
-export function processSingleServerGrowth(server: Server, threads: number, p: IPlayer) {
+export function processSingleServerGrowth(server: Server, threads: number, p: IPlayer): number {
let serverGrowth = calculateServerGrowth(server, threads, p);
if (serverGrowth < 1) {
console.warn("serverGrowth calculated to be less than 1");
@@ -90,7 +90,7 @@ export function processSingleServerGrowth(server: Server, threads: number, p: IP
return server.moneyAvailable / oldMoneyAvailable;
}
-export function prestigeHomeComputer(homeComp: Server) {
+export function prestigeHomeComputer(homeComp: Server): void {
const hasBitflume = homeComp.programs.includes(Programs.BitFlume.name);
homeComp.programs.length = 0; //Remove programs
@@ -113,7 +113,7 @@ export function prestigeHomeComputer(homeComp: Server) {
//Returns server object with corresponding hostname
// Relatively slow, would rather not use this a lot
export function GetServerByHostname(hostname: string): Server | HacknetServer | null {
- for (var ip in AllServers) {
+ for (const ip in AllServers) {
if (AllServers.hasOwnProperty(ip)) {
if (AllServers[ip].hostname == hostname) {
return AllServers[ip];
@@ -139,10 +139,10 @@ export function getServer(s: string): Server | HacknetServer | null {
// Returns the i-th server on the specified server's network
// A Server's serverOnNetwork property holds only the IPs. This function returns
// the actual Server object
-export function getServerOnNetwork(server: Server, i: number) {
+export function getServerOnNetwork(server: Server, i: number): Server | HacknetServer | null {
if (i > server.serversOnNetwork.length) {
console.error("Tried to get server on network that was out of range");
- return;
+ return null;
}
return AllServers[server.serversOnNetwork[i]];
diff --git a/src/Server/ServerPurchases.ts b/src/Server/ServerPurchases.ts
index 4cf47549a..6863a4493 100644
--- a/src/Server/ServerPurchases.ts
+++ b/src/Server/ServerPurchases.ts
@@ -22,7 +22,7 @@ import { isPowerOfTwo } from "../../utils/helpers/isPowerOfTwo";
* @param ram Amount of RAM on purchased server (GB)
* @returns Cost of purchasing the given server. Returns infinity for invalid arguments
*/
-export function getPurchaseServerCost(ram: number) {
+export function getPurchaseServerCost(ram: number): number {
const sanitizedRam = Math.round(ram);
if (isNaN(sanitizedRam) || !isPowerOfTwo(sanitizedRam)) {
return Infinity;
@@ -35,11 +35,11 @@ export function getPurchaseServerCost(ram: number) {
return sanitizedRam * CONSTANTS.BaseCostFor1GBOfRamServer * BitNodeMultipliers.PurchasedServerCost;
}
-export function getPurchaseServerLimit() {
+export function getPurchaseServerLimit(): number {
return Math.round(CONSTANTS.PurchasedServerLimit * BitNodeMultipliers.PurchasedServerLimit);
}
-export function getPurchaseServerMaxRam() {
+export function getPurchaseServerMaxRam(): number {
const ram = Math.round(CONSTANTS.PurchasedServerMaxRam * BitNodeMultipliers.PurchasedServerMaxRam);
// Round this to the nearest power of 2
@@ -47,7 +47,7 @@ export function getPurchaseServerMaxRam() {
}
// Manually purchase a server (NOT through Netscript)
-export function purchaseServer(ram: number, p: IPlayer) {
+export function purchaseServer(ram: number, p: IPlayer): void {
const cost = getPurchaseServerCost(ram);
//Check if player has enough money
@@ -64,7 +64,7 @@ export function purchaseServer(ram: number, p: IPlayer) {
return;
}
- var hostname = yesNoTxtInpBoxGetInput();
+ const hostname = yesNoTxtInpBoxGetInput();
if (hostname == "") {
dialogBoxCreate("You must enter a hostname for your new server!");
return;
@@ -86,7 +86,7 @@ export function purchaseServer(ram: number, p: IPlayer) {
p.purchasedServers.push(newServ.ip);
// Connect new server to home computer
- var homeComputer = p.getHomeComputer();
+ const homeComputer = p.getHomeComputer();
homeComputer.serversOnNetwork.push(newServ.ip);
newServ.serversOnNetwork.push(homeComputer.ip);
@@ -96,7 +96,7 @@ export function purchaseServer(ram: number, p: IPlayer) {
}
// Manually upgrade RAM on home computer (NOT through Netscript)
-export function purchaseRamForHomeComputer(cost: number, p: IPlayer) {
+export function purchaseRamForHomeComputer(cost: number, p: IPlayer): void {
if (!p.canAfford(cost)) {
dialogBoxCreate("You do not have enough money to purchase additional RAM for your home computer");
return;
diff --git a/src/Server/SpecialServerIps.ts b/src/Server/SpecialServerIps.ts
index a5a73e90f..466acfda6 100644
--- a/src/Server/SpecialServerIps.ts
+++ b/src/Server/SpecialServerIps.ts
@@ -4,7 +4,7 @@ import { Reviver,
Generic_fromJSON } from "../../utils/JSONReviver";
/* Holds IP of Special Servers */
-export let SpecialServerNames: IMap = {
+export const SpecialServerNames: IMap = {
FulcrumSecretTechnologies: "Fulcrum Secret Technologies Server",
CyberSecServer: "CyberSec Server",
NiteSecServer: "NiteSec Server",
@@ -16,16 +16,10 @@ export let SpecialServerNames: IMap = {
}
export class SpecialServerIpsMap {
- // Initializes a SpecialServerIpsMap Object from a JSON save state
- static fromJSON(value: any): SpecialServerIpsMap {
- return Generic_fromJSON(SpecialServerIpsMap, value.data);
- }
-
+ // eslint-disable-next-line @typescript-eslint/ban-types
[key: string]: Function | string;
- constructor() {}
-
- addIp(name:string, ip: string) {
+ addIp(name:string, ip: string): void {
this[name] = ip;
}
@@ -37,24 +31,30 @@ export class SpecialServerIpsMap {
toJSON(): any {
return Generic_toJSON("SpecialServerIpsMap", this);
}
+
+ // Initializes a SpecialServerIpsMap Object from a JSON save state
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+ static fromJSON(value: any): SpecialServerIpsMap {
+ return Generic_fromJSON(SpecialServerIpsMap, value.data);
+ }
}
Reviver.constructors.SpecialServerIpsMap = SpecialServerIpsMap;
export let SpecialServerIps: SpecialServerIpsMap = new SpecialServerIpsMap();
-export function prestigeSpecialServerIps() {
- for (var member in SpecialServerIps) {
+export function prestigeSpecialServerIps(): void {
+ for (const member in SpecialServerIps) {
delete SpecialServerIps[member];
}
SpecialServerIps = new SpecialServerIpsMap();
}
-export function loadSpecialServerIps(saveString: string) {
+export function loadSpecialServerIps(saveString: string): void {
SpecialServerIps = JSON.parse(saveString, Reviver);
}
-export function initSpecialServerIps() {
+export function initSpecialServerIps(): void {
SpecialServerIps = new SpecialServerIpsMap();
}
diff --git a/src/Server/data/servers.ts b/src/Server/data/servers.ts
index bd05f97e3..6cef057ce 100644
--- a/src/Server/data/servers.ts
+++ b/src/Server/data/servers.ts
@@ -1203,10 +1203,10 @@ export const serverMetadata: IServerMetadata[] = [
},
{
hackDifficulty: 1,
- hostname: "foodnstuff",
+ hostname: "n00dles",
literature: [LiteratureNames.Sector12Crime],
- maxRamExponent: 4,
- moneyAvailable: 40000,
+ maxRamExponent: 2,
+ moneyAvailable: 70000,
networkLayer: 1,
numOpenPortsRequired: 0,
organizationName: LocationName.Sector12FoodNStuff,
@@ -1215,26 +1215,39 @@ export const serverMetadata: IServerMetadata[] = [
specialName: LocationName.Sector12FoodNStuff,
},
{
- hackDifficulty: 3,
+ hackDifficulty: 10,
+ hostname: "foodnstuff",
+ literature: [LiteratureNames.Sector12Crime],
+ maxRamExponent: 4,
+ moneyAvailable: 2000000,
+ networkLayer: 1,
+ numOpenPortsRequired: 0,
+ organizationName: LocationName.Sector12FoodNStuff,
+ requiredHackingSkill: 1,
+ serverGrowth: 5,
+ specialName: LocationName.Sector12FoodNStuff,
+ },
+ {
+ hackDifficulty: 10,
hostname: "sigma-cosmetics",
maxRamExponent: 4,
- moneyAvailable: 70000,
+ moneyAvailable: 2300000,
networkLayer: 1,
numOpenPortsRequired: 0,
organizationName: "Sigma Cosmetics",
requiredHackingSkill: 5,
- serverGrowth: 3000,
+ serverGrowth: 10,
},
{
- hackDifficulty: 9,
+ hackDifficulty: 15,
hostname: "joesguns",
maxRamExponent: 4,
- moneyAvailable: 600000,
+ moneyAvailable: 2500000,
networkLayer: 1,
numOpenPortsRequired: 0,
organizationName: LocationName.Sector12JoesGuns,
requiredHackingSkill: 10,
- serverGrowth: 500,
+ serverGrowth: 20,
specialName: LocationName.Sector12JoesGuns,
},
{
@@ -1569,4 +1582,4 @@ export const serverMetadata: IServerMetadata[] = [
serverGrowth: 0,
specialName: "w0r1d_d43m0n",
},
-];
+];
\ No newline at end of file
diff --git a/src/Server/formulas/grow.ts b/src/Server/formulas/grow.ts
index 76f6d7c90..f9f08336b 100644
--- a/src/Server/formulas/grow.ts
+++ b/src/Server/formulas/grow.ts
@@ -3,7 +3,7 @@ import { Server } from "../Server";
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
import { IPlayer } from "../../PersonObjects/IPlayer";
-export function calculateServerGrowth(server: Server, threads: number, p: IPlayer) {
+export function calculateServerGrowth(server: Server, threads: number, p: IPlayer): number {
const numServerGrowthCycles = Math.max(Math.floor(threads), 0);
//Get adjusted growth rate, which accounts for server security
diff --git a/src/SourceFile/PlayerOwnedSourceFile.ts b/src/SourceFile/PlayerOwnedSourceFile.ts
index 2f641136d..6eb40f3f9 100644
--- a/src/SourceFile/PlayerOwnedSourceFile.ts
+++ b/src/SourceFile/PlayerOwnedSourceFile.ts
@@ -1,9 +1,9 @@
export class PlayerOwnedSourceFile {
// Source-File level
- lvl: number = 1;
+ lvl = 1;
// Source-File number
- n: number = 1;
+ n = 1;
constructor(n: number, level: number) {
this.n = n;
diff --git a/src/SourceFile/SourceFile.ts b/src/SourceFile/SourceFile.ts
index 96290507a..67c217e0f 100644
--- a/src/SourceFile/SourceFile.ts
+++ b/src/SourceFile/SourceFile.ts
@@ -2,12 +2,12 @@ import { BitNodes } from "../BitNode/BitNode";
export class SourceFile {
info: string;
- lvl: number = 1;
+ lvl = 1;
n: number;
name: string;
- owned: boolean = false;
+ owned = false;
- constructor(number: number, info: string="") {
+ constructor(number: number, info="") {
const bitnodeKey = "BitNode" + number;
const bitnode = BitNodes[bitnodeKey];
if (bitnode == null) {
diff --git a/src/SourceFile/SourceFileFlags.ts b/src/SourceFile/SourceFileFlags.ts
index db6fa701e..dc4565864 100644
--- a/src/SourceFile/SourceFileFlags.ts
+++ b/src/SourceFile/SourceFileFlags.ts
@@ -6,7 +6,7 @@ import { IPlayer } from "../PersonObjects/IPlayer";
export const SourceFileFlags: number[] = Array(CONSTANTS.TotalNumBitNodes + 1); // Skip index 0
-export function updateSourceFileFlags(p: IPlayer) {
+export function updateSourceFileFlags(p: IPlayer): void {
for (let i = 0; i < SourceFileFlags.length; ++i) {
SourceFileFlags[i] = 0;
}
diff --git a/src/SourceFile/SourceFiles.ts b/src/SourceFile/SourceFiles.ts
index bc35dcba8..5a351eb1c 100644
--- a/src/SourceFile/SourceFiles.ts
+++ b/src/SourceFile/SourceFiles.ts
@@ -60,5 +60,4 @@ SourceFiles["SourceFile11"] = new SourceFile(11, "This Source-File makes it so t
"Level 1: 32% " +
"Level 2: 48% " +
"Level 3: 56% ");
-SourceFiles["SourceFile12"] = new SourceFile(12, "This Source-File increases all your multipliers by 1% per level. This effect is multiplicative with itself. " +
- "In other words, level N of this Source-File will result in a multiplier of 1.01^N (or 0.99^N for multipliers that decrease)");
+SourceFiles["SourceFile12"] = new SourceFile(12, "This Source-File lets the player start with Neuroflux Governor equal to the level of this Source-File.");
diff --git a/src/SourceFile/applySourceFile.ts b/src/SourceFile/applySourceFile.ts
index 45f4c839f..03fdadd23 100644
--- a/src/SourceFile/applySourceFile.ts
+++ b/src/SourceFile/applySourceFile.ts
@@ -3,7 +3,7 @@ import { SourceFiles } from "./SourceFiles";
import { Player } from "../Player";
-export function applySourceFile(srcFile: PlayerOwnedSourceFile) {
+export function applySourceFile(srcFile: PlayerOwnedSourceFile): void {
const srcFileKey = "SourceFile" + srcFile.n;
const sourceFileObject = SourceFiles[srcFileKey];
if (sourceFileObject == null) {
@@ -12,13 +12,13 @@ export function applySourceFile(srcFile: PlayerOwnedSourceFile) {
}
switch (srcFile.n) {
- case 1: // The Source Genesis
- var mult = 0;
- for (var i = 0; i < srcFile.lvl; ++i) {
+ case 1: { // The Source Genesis
+ let mult = 0;
+ for (let i = 0; i < srcFile.lvl; ++i) {
mult += (16 / (Math.pow(2, i)));
}
- var incMult = 1 + (mult / 100);
- var decMult = 1 - (mult / 100);
+ const incMult = 1 + (mult / 100);
+ const decMult = 1 - (mult / 100);
Player.hacking_chance_mult *= incMult;
Player.hacking_speed_mult *= incMult;
Player.hacking_money_mult *= incMult;
@@ -46,34 +46,38 @@ export function applySourceFile(srcFile: PlayerOwnedSourceFile) {
Player.hacknet_node_level_cost_mult *= decMult;
Player.work_money_mult *= incMult;
break;
- case 2: // Rise of the Underworld
- var mult = 0;
- for (var i = 0; i < srcFile.lvl; ++i) {
+ }
+ case 2: { // Rise of the Underworld
+ let mult = 0;
+ for (let i = 0; i < srcFile.lvl; ++i) {
mult += (24 / (Math.pow(2, i)));
}
- var incMult = 1 + (mult / 100);
+ const incMult = 1 + (mult / 100);
Player.crime_money_mult *= incMult;
Player.crime_success_mult *= incMult;
Player.charisma_mult *= incMult;
break;
- case 3: // Corporatocracy
- var mult = 0;
- for (var i = 0; i < srcFile.lvl; ++i) {
+ }
+ case 3: { // Corporatocracy
+ let mult = 0;
+ for (let i = 0; i < srcFile.lvl; ++i) {
mult += (8 / (Math.pow(2, i)));
}
- var incMult = 1 + (mult / 100);
+ const incMult = 1 + (mult / 100);
Player.charisma_mult *= incMult;
Player.work_money_mult *= incMult;
break;
- case 4: // The Singularity
+ }
+ case 4: { // The Singularity
// No effects, just gives access to Singularity functions
break;
- case 5: // Artificial Intelligence
- var mult = 0;
- for (var i = 0; i < srcFile.lvl; ++i) {
+ }
+ case 5: { // Artificial Intelligence
+ let mult = 0;
+ for (let i = 0; i < srcFile.lvl; ++i) {
mult += (8 / (Math.pow(2, i)));
}
- var incMult = 1 + (mult / 100);
+ const incMult = 1 + (mult / 100);
Player.hacking_chance_mult *= incMult;
Player.hacking_speed_mult *= incMult;
Player.hacking_money_mult *= incMult;
@@ -81,12 +85,13 @@ export function applySourceFile(srcFile: PlayerOwnedSourceFile) {
Player.hacking_mult *= incMult;
Player.hacking_exp_mult *= incMult;
break;
- case 6: // Bladeburner
- var mult = 0;
- for (var i = 0; i < srcFile.lvl; ++i) {
+ }
+ case 6: { // Bladeburner
+ let mult = 0;
+ for (let i = 0; i < srcFile.lvl; ++i) {
mult += (8 / (Math.pow(2, i)));
}
- var incMult = 1 + (mult / 100);
+ const incMult = 1 + (mult / 100);
Player.strength_exp_mult *= incMult;
Player.defense_exp_mult *= incMult;
Player.dexterity_exp_mult *= incMult;
@@ -96,76 +101,48 @@ export function applySourceFile(srcFile: PlayerOwnedSourceFile) {
Player.dexterity_mult *= incMult;
Player.agility_mult *= incMult;
break;
- case 7: // Bladeburner 2079
- var mult = 0;
- for (var i = 0; i < srcFile.lvl; ++i) {
+ }
+ case 7: { // Bladeburner 2079
+ let mult = 0;
+ for (let i = 0; i < srcFile.lvl; ++i) {
mult += (8 / (Math.pow(2, i)));
}
- var incMult = 1 + (mult / 100);
+ const incMult = 1 + (mult / 100);
Player.bladeburner_max_stamina_mult *= incMult;
Player.bladeburner_stamina_gain_mult *= incMult;
Player.bladeburner_analysis_mult *= incMult;
Player.bladeburner_success_chance_mult *= incMult;
break;
- case 8: // Ghost of Wall Street
- var mult = 0;
- for (var i = 0; i < srcFile.lvl; ++i) {
+ }
+ case 8: { // Ghost of Wall Street
+ let mult = 0;
+ for (let i = 0; i < srcFile.lvl; ++i) {
mult += (12 / (Math.pow(2, i)));
}
- var incMult = 1 + (mult / 100);
+ const incMult = 1 + (mult / 100);
Player.hacking_grow_mult *= incMult;
break;
- case 9: // Hacktocracy
+ }
+ case 9: { // Hacktocracy
// This has non-multiplier effects
break;
- case 10: // Digital Carbon
+ }
+ case 10: { // Digital Carbon
// No effects, just grants sleeves
break;
- case 11: // The Big Crash
- var mult = 0;
- for (var i = 0; i < srcFile.lvl; ++i) {
+ }
+ case 11: { // The Big Crash
+ let mult = 0;
+ for (let i = 0; i < srcFile.lvl; ++i) {
mult += (32 / (Math.pow(2, i)));
}
- var incMult = 1 + (mult / 100);
+ const incMult = 1 + (mult / 100);
Player.work_money_mult *= incMult;
Player.company_rep_mult *= incMult;
break;
+ }
case 12: // The Recursion
- var inc = Math.pow(1.01, srcFile.lvl);
- var dec = Math.pow(0.99, srcFile.lvl);
-
- Player.hacking_chance_mult *= inc;
- Player.hacking_speed_mult *= inc;
- Player.hacking_money_mult *= inc;
- Player.hacking_grow_mult *= inc;
- Player.hacking_mult *= inc;
-
- Player.strength_mult *= inc;
- Player.defense_mult *= inc;
- Player.dexterity_mult *= inc;
- Player.agility_mult *= inc;
- Player.charisma_mult *= inc;
-
- Player.hacking_exp_mult *= inc;
- Player.strength_exp_mult *= inc;
- Player.defense_exp_mult *= inc;
- Player.dexterity_exp_mult *= inc;
- Player.agility_exp_mult *= inc;
- Player.charisma_exp_mult *= inc;
-
- Player.company_rep_mult *= inc;
- Player.faction_rep_mult *= inc;
-
- Player.crime_money_mult *= inc;
- Player.crime_success_mult *= inc;
-
- Player.hacknet_node_money_mult *= inc;
- Player.hacknet_node_purchase_cost_mult *= dec;
- Player.hacknet_node_ram_cost_mult *= dec;
- Player.hacknet_node_core_cost_mult *= dec;
- Player.hacknet_node_level_cost_mult *= dec;
-
- Player.work_money_mult *= inc;
+ // No effects, grants neuroflux.
break;
default:
console.error(`Invalid source file number: ${srcFile.n}`);
diff --git a/src/StockMarket/BuyingAndSelling.tsx b/src/StockMarket/BuyingAndSelling.tsx
index e7d4ddec6..cbabd494e 100644
--- a/src/StockMarket/BuyingAndSelling.tsx
+++ b/src/StockMarket/BuyingAndSelling.tsx
@@ -21,8 +21,6 @@ import { Money } from "../ui/React/Money";
import { dialogBoxCreate } from "../../utils/DialogBox";
import * as React from "react";
-import * as ReactDOM from "react-dom";
-import { renderToStaticMarkup } from "react-dom/server"
/**
* Each function takes an optional config object as its last argument
@@ -41,14 +39,13 @@ interface IOptions {
* @returns {boolean} - true if successful, false otherwise
*/
export function buyStock(stock: Stock, shares: number, workerScript: WorkerScript | null=null, opts: IOptions={}): boolean {
- const tixApi = (workerScript instanceof WorkerScript);
// Validate arguments
shares = Math.round(shares);
if (shares <= 0) { return false; }
if (stock == null || isNaN(shares)) {
- if (tixApi) {
- workerScript!.log("buyStock", `Invalid arguments: stock='${stock}' shares='${shares}'`);
+ if (workerScript) {
+ workerScript.log("buyStock", `Invalid arguments: stock='${stock}' shares='${shares}'`);
} else if (opts.suppressDialog !== true) {
dialogBoxCreate("Failed to buy stock. This may be a bug, contact developer");
}
@@ -60,8 +57,8 @@ export function buyStock(stock: Stock, shares: number, workerScript: WorkerScrip
const totalPrice = getBuyTransactionCost(stock, shares, PositionTypes.Long);
if (totalPrice == null) { return false; }
if (Player.money.lt(totalPrice)) {
- if (tixApi) {
- workerScript!.log("buyStock", `You do not have enough money to purchase this position. You need ${numeralWrapper.formatMoney(totalPrice)}.`);
+ if (workerScript) {
+ workerScript.log("buyStock", `You do not have enough money to purchase this position. You need ${numeralWrapper.formatMoney(totalPrice)}.`);
} else if (opts.suppressDialog !== true) {
dialogBoxCreate(<>You do not have enough money to purchase this. You need {Money(totalPrice)}>);
}
@@ -71,8 +68,8 @@ export function buyStock(stock: Stock, shares: number, workerScript: WorkerScrip
// Would this purchase exceed the maximum number of shares?
if (shares + stock.playerShares + stock.playerShortShares > stock.maxShares) {
- if (tixApi) {
- workerScript!.log("buyStock", `Purchasing '${shares + stock.playerShares + stock.playerShortShares}' shares would exceed ${stock.symbol}'s maximum (${stock.maxShares}) number of shares`);
+ if (workerScript) {
+ workerScript.log("buyStock", `Purchasing '${shares + stock.playerShares + stock.playerShortShares}' shares would exceed ${stock.symbol}'s maximum (${stock.maxShares}) number of shares`);
} else if (opts.suppressDialog !== true) {
dialogBoxCreate(`You cannot purchase this many shares. ${stock.symbol} has a maximum of ${numeralWrapper.formatShares(stock.maxShares)} shares.`);
}
@@ -90,10 +87,10 @@ export function buyStock(stock: Stock, shares: number, workerScript: WorkerScrip
opts.rerenderFn();
}
- if (tixApi) {
+ if (workerScript) {
const resultTxt = `Bought ${numeralWrapper.formatShares(shares)} shares of ${stock.symbol} for ${numeralWrapper.formatMoney(totalPrice)}. ` +
`Paid ${numeralWrapper.formatMoney(CONSTANTS.StockMarketCommission)} in commission fees.`
- workerScript!.log("buyStock", resultTxt)
+ workerScript.log("buyStock", resultTxt)
} else if (opts.suppressDialog !== true) {
dialogBoxCreate(<>Bought {numeralWrapper.formatShares(shares)} shares of {stock.symbol} for {Money(totalPrice)}. Paid {Money(CONSTANTS.StockMarketCommission)} in commission fees.>);
}
@@ -110,12 +107,11 @@ export function buyStock(stock: Stock, shares: number, workerScript: WorkerScrip
* returns {boolean} - true if successfully sells given number of shares OR MAX owned, false otherwise
*/
export function sellStock(stock: Stock, shares: number, workerScript: WorkerScript | null=null, opts: IOptions={}): boolean {
- const tixApi = (workerScript instanceof WorkerScript);
// Sanitize/Validate arguments
if (stock == null || shares < 0 || isNaN(shares)) {
- if (tixApi) {
- workerScript!.log("sellStock", `Invalid arguments: stock='${stock}' shares='${shares}'`);
+ if (workerScript) {
+ workerScript.log("sellStock", `Invalid arguments: stock='${stock}' shares='${shares}'`);
} else if (opts.suppressDialog !== true) {
dialogBoxCreate("Failed to sell stock. This is probably due to an invalid quantity. Otherwise, this may be a bug, contact developer");
}
@@ -132,8 +128,8 @@ export function sellStock(stock: Stock, shares: number, workerScript: WorkerScri
if (isNaN(netProfit)) { netProfit = 0; }
Player.gainMoney(gains);
Player.recordMoneySource(netProfit, "stock");
- if (tixApi) {
- workerScript!.scriptRef.onlineMoneyMade += netProfit;
+ if (workerScript) {
+ workerScript.scriptRef.onlineMoneyMade += netProfit;
Player.scriptProdSinceLastAug += netProfit;
}
@@ -149,10 +145,10 @@ export function sellStock(stock: Stock, shares: number, workerScript: WorkerScri
}
- if (tixApi) {
+ if (workerScript) {
const resultTxt = `Sold ${numeralWrapper.formatShares(shares)} shares of ${stock.symbol}. ` +
`After commissions, you gained a total of ${numeralWrapper.formatMoney(gains)}.`;
- workerScript!.log("sellStock", resultTxt)
+ workerScript.log("sellStock", resultTxt)
} else if (opts.suppressDialog !== true) {
dialogBoxCreate(<>Sold {numeralWrapper.formatShares(shares)} shares of {stock.symbol}. After commissions, you gained a total of {Money(gains)}.>);
}
@@ -169,14 +165,13 @@ export function sellStock(stock: Stock, shares: number, workerScript: WorkerScri
* @returns {boolean} - true if successful, false otherwise
*/
export function shortStock(stock: Stock, shares: number, workerScript: WorkerScript | null=null, opts: IOptions={}): boolean {
- const tixApi = (workerScript instanceof WorkerScript);
// Validate arguments
shares = Math.round(shares);
if (shares <= 0) { return false; }
if (stock == null || isNaN(shares)) {
- if (tixApi) {
- workerScript!.log("shortStock", `Invalid arguments: stock='${stock}' shares='${shares}'`);
+ if (workerScript) {
+ workerScript.log("shortStock", `Invalid arguments: stock='${stock}' shares='${shares}'`);
} else if (opts.suppressDialog !== true) {
dialogBoxCreate("Failed to initiate a short position in a stock. This is probably " +
"due to an invalid quantity. Otherwise, this may be a bug, so contact developer");
@@ -188,8 +183,8 @@ export function shortStock(stock: Stock, shares: number, workerScript: WorkerScr
const totalPrice = getBuyTransactionCost(stock, shares, PositionTypes.Short);
if (totalPrice == null) { return false; }
if (Player.money.lt(totalPrice)) {
- if (tixApi) {
- workerScript!.log("shortStock", "You do not have enough " +
+ if (workerScript) {
+ workerScript.log("shortStock", "You do not have enough " +
"money to purchase this short position. You need " +
numeralWrapper.formatMoney(totalPrice));
} else if (opts.suppressDialog !== true) {
@@ -201,8 +196,8 @@ export function shortStock(stock: Stock, shares: number, workerScript: WorkerScr
// Would this purchase exceed the maximum number of shares?
if (shares + stock.playerShares + stock.playerShortShares > stock.maxShares) {
- if (tixApi) {
- workerScript!.log("shortStock", `This '${shares + stock.playerShares + stock.playerShortShares}' short shares would exceed ${stock.symbol}'s maximum (${stock.maxShares}) number of shares.`);
+ if (workerScript) {
+ workerScript.log("shortStock", `This '${shares + stock.playerShares + stock.playerShortShares}' short shares would exceed ${stock.symbol}'s maximum (${stock.maxShares}) number of shares.`);
} else if (opts.suppressDialog !== true) {
dialogBoxCreate(`You cannot purchase this many shares. ${stock.symbol} has a maximum of ${stock.maxShares} shares.`);
}
@@ -221,11 +216,11 @@ export function shortStock(stock: Stock, shares: number, workerScript: WorkerScr
opts.rerenderFn();
}
- if (tixApi) {
+ if (workerScript) {
const resultTxt = `Bought a short position of ${numeralWrapper.formatShares(shares)} shares of ${stock.symbol} ` +
`for ${numeralWrapper.formatMoney(totalPrice)}. Paid ${numeralWrapper.formatMoney(CONSTANTS.StockMarketCommission)} ` +
`in commission fees.`;
- workerScript!.log("shortStock", resultTxt);
+ workerScript.log("shortStock", resultTxt);
} else if (!opts.suppressDialog) {
dialogBoxCreate(<>Bought a short position of {numeralWrapper.formatShares(shares)} shares of {stock.symbol} for {Money(totalPrice)}. Paid {Money(CONSTANTS.StockMarketCommission)} in commission fees.>);
}
@@ -242,11 +237,10 @@ export function shortStock(stock: Stock, shares: number, workerScript: WorkerScr
* @returns {boolean} true if successfully sells given amount OR max owned, false otherwise
*/
export function sellShort(stock: Stock, shares: number, workerScript: WorkerScript | null=null, opts: IOptions={}): boolean {
- const tixApi = (workerScript instanceof WorkerScript);
if (stock == null || isNaN(shares) || shares < 0) {
- if (tixApi) {
- workerScript!.log("sellShort", `Invalid arguments: stock='${stock}' shares='${shares}'`);
+ if (workerScript) {
+ workerScript.log("sellShort", `Invalid arguments: stock='${stock}' shares='${shares}'`);
} else if (!opts.suppressDialog) {
dialogBoxCreate("Failed to sell a short position in a stock. This is probably " +
"due to an invalid quantity. Otherwise, this may be a bug, so contact developer");
@@ -261,8 +255,8 @@ export function sellShort(stock: Stock, shares: number, workerScript: WorkerScri
const origCost = shares * stock.playerAvgShortPx;
const totalGain = getSellTransactionGain(stock, shares, PositionTypes.Short);
if (totalGain == null || isNaN(totalGain) || origCost == null) {
- if (tixApi) {
- workerScript!.log("sellShort", `Failed to sell short position in a stock. This is probably either due to invalid arguments, or a bug`);
+ if (workerScript) {
+ workerScript.log("sellShort", `Failed to sell short position in a stock. This is probably either due to invalid arguments, or a bug`);
} else if (!opts.suppressDialog) {
dialogBoxCreate(`Failed to sell short position in a stock. This is probably either due to invalid arguments, or a bug`);
}
@@ -273,8 +267,8 @@ export function sellShort(stock: Stock, shares: number, workerScript: WorkerScri
if (isNaN(profit)) { profit = 0; }
Player.gainMoney(totalGain);
Player.recordMoneySource(profit, "stock");
- if (tixApi) {
- workerScript!.scriptRef.onlineMoneyMade += profit;
+ if (workerScript) {
+ workerScript.scriptRef.onlineMoneyMade += profit;
Player.scriptProdSinceLastAug += profit;
}
@@ -288,10 +282,10 @@ export function sellShort(stock: Stock, shares: number, workerScript: WorkerScri
opts.rerenderFn();
}
- if (tixApi) {
+ if (workerScript) {
const resultTxt = `Sold your short position of ${numeralWrapper.formatShares(shares)} shares of ${stock.symbol}. ` +
`After commissions, you gained a total of ${numeralWrapper.formatMoney(totalGain)}`;
- workerScript!.log("sellShort", resultTxt);
+ workerScript.log("sellShort", resultTxt);
} else if (!opts.suppressDialog) {
dialogBoxCreate(<>Sold your short position of {numeralWrapper.formatShares(shares)} shares of {stock.symbol}. After commissions, you gained a total of {Money(totalGain)}>);
}
diff --git a/src/StockMarket/Order.ts b/src/StockMarket/Order.ts
index 7fe880713..41653f036 100644
--- a/src/StockMarket/Order.ts
+++ b/src/StockMarket/Order.ts
@@ -12,12 +12,6 @@ import {
} from "../../utils/JSONReviver";
export class Order {
- /**
- * Initializes a Order from a JSON save state
- */
- static fromJSON(value: any): Order {
- return Generic_fromJSON(Order, value.data);
- }
readonly pos: PositionTypes;
readonly price: number;
@@ -25,9 +19,9 @@ export class Order {
readonly stockSymbol: string;
readonly type: OrderTypes;
- constructor(stockSymbol: string="", shares: number=0, price: number=0, typ: OrderTypes=OrderTypes.LimitBuy, pos: PositionTypes=PositionTypes.Long) {
+ constructor(stockSymbol="", shares=0, price=0, typ: OrderTypes=OrderTypes.LimitBuy, pos: PositionTypes=PositionTypes.Long) {
// Validate arguments
- let invalidArgs: boolean = false;
+ let invalidArgs = false;
if (typeof shares !== "number" || typeof price !== "number") {
invalidArgs = true;
}
@@ -54,6 +48,14 @@ export class Order {
toJSON(): any {
return Generic_toJSON("Order", this);
}
+
+ /**
+ * Initializes a Order from a JSON save state
+ */
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+ static fromJSON(value: any): Order {
+ return Generic_fromJSON(Order, value.data);
+ }
}
Reviver.constructors.Order = Order;
diff --git a/src/StockMarket/OrderProcessing.tsx b/src/StockMarket/OrderProcessing.tsx
index 7d35c2f21..f6a5e5d37 100644
--- a/src/StockMarket/OrderProcessing.tsx
+++ b/src/StockMarket/OrderProcessing.tsx
@@ -39,7 +39,7 @@ export interface IProcessOrderRefs {
* @param {IProcessOrderRefs} refs - References to objects/functions that are required for this function
*/
export function processOrders(stock: Stock, orderType: OrderTypes, posType: PositionTypes, refs: IProcessOrderRefs): void {
- let orderBook = refs.stockMarket["Orders"];
+ const orderBook = refs.stockMarket["Orders"];
if (orderBook == null) {
const orders: IOrderBook = {};
for (const name in refs.stockMarket) {
@@ -101,7 +101,7 @@ export function processOrders(stock: Stock, orderType: OrderTypes, posType: Posi
* @param {Order} order - Order being executed
* @param {IProcessOrderRefs} refs - References to objects/functions that are required for this function
*/
-function executeOrder(order: Order, refs: IProcessOrderRefs) {
+function executeOrder(order: Order, refs: IProcessOrderRefs): void {
const stock = refs.symbolToStockMap[order.stockSymbol];
if (!(stock instanceof Stock)) {
console.error(`Could not find stock for this order: ${order.stockSymbol}`);
@@ -115,7 +115,7 @@ function executeOrder(order: Order, refs: IProcessOrderRefs) {
// emit popup dialog boxes. This options object configures the functions for that
const opts = {
rerenderFn: refs.rerenderFn,
- suppressDialog: true
+ suppressDialog: true,
}
let res = true;
diff --git a/src/StockMarket/Stock.ts b/src/StockMarket/Stock.ts
index a95455eba..b5f0b7dd6 100644
--- a/src/StockMarket/Stock.ts
+++ b/src/StockMarket/Stock.ts
@@ -2,7 +2,7 @@ import { IMinMaxRange } from "../types";
import {
Generic_fromJSON,
Generic_toJSON,
- Reviver
+ Reviver,
} from "../../utils/JSONReviver";
import { getRandomInt } from "../../utils/helpers/getRandomInt";
@@ -59,13 +59,6 @@ function toNumber(n: number | IMinMaxRange): number {
* Represents the valuation of a company in the World Stock Exchange.
*/
export class Stock {
- /**
- * Initializes a Stock from a JSON save state
- */
- static fromJSON(value: any): Stock {
- return Generic_fromJSON(Stock, value.data);
- }
-
/**
* Bear or bull (more likely to go up or down, based on otlkMag)
*/
@@ -181,11 +174,11 @@ export class Stock {
this.shareTxUntilMovement = this.shareTxForMovement;
// Total shares is determined by market cap, and is rounded to nearest 100k
- let totalSharesUnrounded: number = (p.marketCap / this.price);
+ const totalSharesUnrounded: number = (p.marketCap / this.price);
this.totalShares = Math.round(totalSharesUnrounded / 1e5) * 1e5;
// Max Shares (Outstanding shares) is a percentage of total shares
- const outstandingSharePercentage: number = 0.2;
+ const outstandingSharePercentage = 0.2;
this.maxShares = Math.round((this.totalShares * outstandingSharePercentage) / 1e5) * 1e5;
}
@@ -214,7 +207,7 @@ export class Stock {
* The way a stock's forecast changes depends on various internal properties,
* but is ultimately determined by RNG
*/
- cycleForecast(changeAmt: number=0.1): void {
+ cycleForecast(changeAmt=0.1): void {
const increaseChance = this.getForecastIncreaseChance();
if (Math.random() < increaseChance) {
@@ -244,7 +237,7 @@ export class Stock {
* Change's the stock's second-order forecast during a stock market 'tick'.
* The change for the second-order forecast to increase is 50/50
*/
- cycleForecastForecast(changeAmt: number=0.1): void {
+ cycleForecastForecast(changeAmt=0.1): void {
if (Math.random() < 0.5) {
this.changeForecastForecast(this.otlkMagForecast + changeAmt);
} else {
@@ -324,6 +317,14 @@ export class Stock {
toJSON(): any {
return Generic_toJSON("Stock", this);
}
+
+ /**
+ * Initializes a Stock from a JSON save state
+ */
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+ static fromJSON(value: any): Stock {
+ return Generic_fromJSON(Stock, value.data);
+ }
}
Reviver.constructors.Stock = Stock;
diff --git a/src/StockMarket/StockMarket.tsx b/src/StockMarket/StockMarket.tsx
index 307dd5d80..3782e4eed 100644
--- a/src/StockMarket/StockMarket.tsx
+++ b/src/StockMarket/StockMarket.tsx
@@ -32,21 +32,20 @@ import * as React from "react";
import * as ReactDOM from "react-dom";
export let StockMarket: IStockMarket | IMap = {}; // Maps full stock name -> Stock object
-export let SymbolToStockMap: IMap = {}; // Maps symbol -> Stock object
+export const SymbolToStockMap: IMap = {}; // Maps symbol -> Stock object
export function placeOrder(stock: Stock, shares: number, price: number, type: OrderTypes, position: PositionTypes, workerScript: WorkerScript | null=null): boolean {
- const tixApi = (workerScript instanceof WorkerScript);
if (!(stock instanceof Stock)) {
- if (tixApi) {
- workerScript!.log("placeOrder", `Invalid stock: '${stock}'`);
+ if (workerScript) {
+ workerScript.log("placeOrder", `Invalid stock: '${stock}'`);
} else {
dialogBoxCreate(`ERROR: Invalid stock passed to placeOrder() function`);
}
return false;
}
if (typeof shares !== "number" || typeof price !== "number") {
- if (tixApi) {
- workerScript!.log("placeOrder", `Invalid arguments: shares='${shares}' price='${price}'`);
+ if (workerScript) {
+ workerScript.log("placeOrder", `Invalid arguments: shares='${shares}' price='${price}'`);
} else {
dialogBoxCreate("ERROR: Invalid numeric value provided for either 'shares' or 'price' argument");
}
@@ -87,13 +86,12 @@ interface ICancelOrderParams {
type?: OrderTypes;
}
export function cancelOrder(params: ICancelOrderParams, workerScript: WorkerScript | null=null): boolean {
- var tixApi = (workerScript instanceof WorkerScript);
if (StockMarket["Orders"] == null) {return false;}
if (params.order && params.order instanceof Order) {
const order = params.order;
// An 'Order' object is passed in
- var stockOrders = StockMarket["Orders"][order.stockSymbol];
- for (var i = 0; i < stockOrders.length; ++i) {
+ const stockOrders = StockMarket["Orders"][order.stockSymbol];
+ for (let i = 0; i < stockOrders.length; ++i) {
if (order == stockOrders[i]) {
stockOrders.splice(i, 1);
displayStockMarketContent();
@@ -104,32 +102,32 @@ export function cancelOrder(params: ICancelOrderParams, workerScript: WorkerScri
} else if (params.stock && params.shares && params.price && params.type &&
params.pos && params.stock instanceof Stock) {
// Order properties are passed in. Need to look for the order
- var stockOrders = StockMarket["Orders"][params.stock.symbol];
- var orderTxt = params.stock.symbol + " - " + params.shares + " @ " +
+ const stockOrders = StockMarket["Orders"][params.stock.symbol];
+ const orderTxt = params.stock.symbol + " - " + params.shares + " @ " +
numeralWrapper.formatMoney(params.price);
- for (var i = 0; i < stockOrders.length; ++i) {
- var order = stockOrders[i];
+ for (let i = 0; i < stockOrders.length; ++i) {
+ const order = stockOrders[i];
if (params.shares === order.shares &&
params.price === order.price &&
params.type === order.type &&
params.pos === order.pos) {
stockOrders.splice(i, 1);
displayStockMarketContent();
- if (tixApi) {
- workerScript!.scriptRef.log("Successfully cancelled order: " + orderTxt);
+ if (workerScript) {
+ workerScript.scriptRef.log("Successfully cancelled order: " + orderTxt);
}
return true;
}
}
- if (tixApi) {
- workerScript!.scriptRef.log("Failed to cancel order: " + orderTxt);
+ if (workerScript) {
+ workerScript.scriptRef.log("Failed to cancel order: " + orderTxt);
}
return false;
}
return false;
}
-export function loadStockMarket(saveString: string) {
+export function loadStockMarket(saveString: string): void {
if (saveString === "") {
StockMarket = {};
} else {
@@ -137,11 +135,11 @@ export function loadStockMarket(saveString: string) {
}
}
-export function deleteStockMarket() {
+export function deleteStockMarket(): void {
StockMarket = {};
}
-export function initStockMarket() {
+export function initStockMarket(): void {
for (const stk in StockMarket) {
if (StockMarket.hasOwnProperty(stk)) {
delete StockMarket[stk];
@@ -166,7 +164,7 @@ export function initStockMarket() {
StockMarket.ticksUntilCycle = TicksPerCycle;
}
-export function initSymbolToStockMap() {
+export function initSymbolToStockMap(): void {
for (const name in StockSymbols) {
if (StockSymbols.hasOwnProperty(name)) {
const stock = StockMarket[name];
@@ -180,7 +178,7 @@ export function initSymbolToStockMap() {
}
}
-export function stockMarketCycle() {
+export function stockMarketCycle(): void {
for (const name in StockMarket) {
const stock = StockMarket[name];
if (!(stock instanceof Stock)) { continue; }
@@ -198,7 +196,7 @@ export function stockMarketCycle() {
// Stock prices updated every 6 seconds
const msPerStockUpdate = 6e3;
const cyclesPerStockUpdate = msPerStockUpdate / CONSTANTS.MilliPerCycle;
-export function processStockPrices(numCycles=1) {
+export function processStockPrices(numCycles=1): void {
if (StockMarket.storedCycles == null || isNaN(StockMarket.storedCycles)) { StockMarket.storedCycles = 0; }
StockMarket.storedCycles += numCycles;
@@ -221,7 +219,7 @@ export function processStockPrices(numCycles=1) {
stockMarketCycle();
}
- var v = Math.random();
+ const v = Math.random();
for (const name in StockMarket) {
const stock = StockMarket[name];
if (!(stock instanceof Stock)) { continue; }
@@ -279,21 +277,21 @@ export function processStockPrices(numCycles=1) {
}
let stockMarketContainer: HTMLElement | null = null;
-function setStockMarketContainer() {
+function setStockMarketContainer(): void {
stockMarketContainer = document.getElementById("stock-market-container");
document.removeEventListener("DOMContentLoaded", setStockMarketContainer);
}
document.addEventListener("DOMContentLoaded", setStockMarketContainer);
-function initStockMarketFnForReact() {
+function initStockMarketFnForReact(): void {
initStockMarket();
initSymbolToStockMap();
}
const eventEmitterForUiReset = new EventEmitter();
-export function displayStockMarketContent() {
+export function displayStockMarketContent(): void {
if (!routing.isOn(Page.StockMarket)) {
return;
}
@@ -315,7 +313,7 @@ export function displayStockMarketContent() {
sellStockShort={sellShort}
stockMarket={castedStockMarket}
/>,
- stockMarketContainer
+ stockMarketContainer,
)
}
}
diff --git a/src/StockMarket/StockMarketHelpers.ts b/src/StockMarket/StockMarketHelpers.ts
index 476305668..20675398f 100644
--- a/src/StockMarket/StockMarketHelpers.ts
+++ b/src/StockMarket/StockMarketHelpers.ts
@@ -87,7 +87,7 @@ export function processTransactionForecastMovement(stock: Stock, shares: number)
}
// Calculate how many iterations of price changes we need to account for
- let remainingShares = shares - firstShares;
+ const remainingShares = shares - firstShares;
let numIterations = 1 + Math.ceil(remainingShares / stock.shareTxForMovement);
// If on the offchance we end up perfectly at the next price movement
@@ -118,8 +118,8 @@ export function calculateBuyMaxAmount(stock: Stock, posType: PositionTypes, mone
const isLong = (posType === PositionTypes.Long);
- let remainingMoney = money - CONSTANTS.StockMarketCommission;
- let currPrice = isLong ? stock.getAskPrice() : stock.getBidPrice();
+ const remainingMoney = money - CONSTANTS.StockMarketCommission;
+ const currPrice = isLong ? stock.getAskPrice() : stock.getBidPrice();
return Math.floor(remainingMoney / currPrice);
}
diff --git a/src/StockMarket/ui/InfoAndPurchases.tsx b/src/StockMarket/ui/InfoAndPurchases.tsx
index f927b71df..a4bd49230 100644
--- a/src/StockMarket/ui/InfoAndPurchases.tsx
+++ b/src/StockMarket/ui/InfoAndPurchases.tsx
@@ -7,12 +7,11 @@ import * as React from "react";
import {
getStockMarket4SDataCost,
- getStockMarket4STixApiCost
+ getStockMarket4STixApiCost,
} from "../StockMarketCosts";
import { CONSTANTS } from "../../Constants";
import { IPlayer } from "../../PersonObjects/IPlayer";
-import { numeralWrapper } from "../../ui/numeralFormat";
import { StdButton } from "../../ui/React/StdButton";
import { StdButtonPurchased } from "../../ui/React/StdButtonPurchased";
import { Money } from "../../ui/React/Money";
@@ -40,7 +39,7 @@ export class InfoAndPurchases extends React.Component {
this.purchase4SMarketDataTixApiAccess = this.purchase4SMarketDataTixApiAccess.bind(this);
}
- handleClick4SMarketDataHelpTip() {
+ handleClick4SMarketDataHelpTip(): void {
dialogBoxCreate(
"Access to the 4S Market Data feed will display two additional pieces " +
"of information about each stock: Price Forecast & Volatility " +
@@ -55,11 +54,11 @@ export class InfoAndPurchases extends React.Component {
"can change every tick (a tick occurs every few seconds while the game " +
"is running). " +
"A stock's price forecast can change over time. This is also affected by volatility. " +
- "The more volatile a stock is, the more its price forecast will change."
+ "The more volatile a stock is, the more its price forecast will change.",
);
}
- purchaseWseAccount() {
+ purchaseWseAccount(): void {
if (this.props.p.hasWseAccount) { return; }
if (!this.props.p.canAfford(CONSTANTS.WSEAccountCost)) { return; }
this.props.p.hasWseAccount = true;
@@ -73,7 +72,7 @@ export class InfoAndPurchases extends React.Component {
}
}
- purchaseTixApiAccess() {
+ purchaseTixApiAccess(): void {
if (this.props.p.hasTixApiAccess) { return; }
if (!this.props.p.canAfford(CONSTANTS.TIXAPICost)) { return; }
this.props.p.hasTixApiAccess = true;
@@ -81,7 +80,7 @@ export class InfoAndPurchases extends React.Component {
this.props.rerender();
}
- purchase4SMarketData() {
+ purchase4SMarketData(): void {
if (this.props.p.has4SData) { return; }
if (!this.props.p.canAfford(getStockMarket4SDataCost())) { return; }
this.props.p.has4SData = true;
@@ -89,7 +88,7 @@ export class InfoAndPurchases extends React.Component {
this.props.rerender();
}
- purchase4SMarketDataTixApiAccess() {
+ purchase4SMarketDataTixApiAccess(): void {
if (this.props.p.has4SDataTixApi) { return; }
if (!this.props.p.canAfford(getStockMarket4STixApiCost())) { return; }
this.props.p.has4SDataTixApi = true;
@@ -182,7 +181,7 @@ export class InfoAndPurchases extends React.Component {
}
}
- render() {
+ render(): React.ReactNode {
const documentationLink = "https://bitburner.readthedocs.io/en/latest/basicgameplay/stockmarket.html";
return (
diff --git a/src/StockMarket/ui/Root.tsx b/src/StockMarket/ui/Root.tsx
index 771a61e28..815f9e61b 100644
--- a/src/StockMarket/ui/Root.tsx
+++ b/src/StockMarket/ui/Root.tsx
@@ -20,7 +20,7 @@ export type placeOrderFn = (stock: Stock, shares: number, price: number, ordType
type IProps = {
buyStockLong: txFn;
buyStockShort: txFn;
- cancelOrder: (params: object) => void;
+ cancelOrder: (params: any) => void;
eventEmitterForReset?: EventEmitter;
initStockMarket: () => void;
p: IPlayer;
@@ -53,7 +53,7 @@ export class StockMarketRoot extends React.Component
{
});
}
- render() {
+ render(): React.ReactNode {
return (
void;
+ cancelOrder: (params: any) => void;
orders: Order[];
p: IPlayer;
placeOrder: placeOrderFn;
@@ -83,12 +83,12 @@ export class StockTicker extends React.Component {
this.handleSellAllButtonClick = this.handleSellAllButtonClick.bind(this);
}
- createPlaceOrderPopupBox(yesTxt: string, popupTxt: string, yesBtnCb: (price: number) => void) {
+ createPlaceOrderPopupBox(yesTxt: string, popupTxt: string, yesBtnCb: (price: number) => void): void {
const yesBtn = yesNoTxtInpBoxGetYesButton();
const noBtn = yesNoTxtInpBoxGetNoButton();
- yesBtn!.innerText = yesTxt;
- yesBtn!.addEventListener("click", () => {
+ yesBtn.innerText = yesTxt;
+ yesBtn.addEventListener("click", () => {
const price = parseFloat(yesNoTxtInpBoxGetInput());
if (isNaN(price)) {
dialogBoxCreate(`Invalid input for price: ${yesNoTxtInpBoxGetInput()}`);
@@ -99,8 +99,8 @@ export class StockTicker extends React.Component {
yesNoTxtInpBoxClose();
});
- noBtn!.innerText = "Cancel Order";
- noBtn!.addEventListener("click", () => {
+ noBtn.innerText = "Cancel Order";
+ noBtn.addEventListener("click", () => {
yesNoTxtInpBoxClose();
});
@@ -143,7 +143,7 @@ export class StockTicker extends React.Component {
return <>Selling {numeralWrapper.formatShares(qty)} shares ({this.state.position === PositionTypes.Long ? "Long" : "Short"}) will result in a gain of {Money(cost)}.>;
}
- handleBuyButtonClick() {
+ handleBuyButtonClick(): void {
const shares = this.getQuantity();
if (isNaN(shares)) {
dialogBoxCreate(`Invalid input for quantity (number of shares): ${this.state.qty}`);
@@ -166,7 +166,7 @@ export class StockTicker extends React.Component {
"Enter the price for your Limit Order",
(price: number) => {
this.props.placeOrder(this.props.stock, shares, price, OrderTypes.LimitBuy, this.state.position);
- }
+ },
);
break;
}
@@ -176,7 +176,7 @@ export class StockTicker extends React.Component {
"Enter the price for your Stop Order",
(price: number) => {
this.props.placeOrder(this.props.stock, shares, price, OrderTypes.StopBuy, this.state.position);
- }
+ },
);
break;
}
@@ -185,7 +185,7 @@ export class StockTicker extends React.Component {
}
}
- handleBuyMaxButtonClick() {
+ handleBuyMaxButtonClick(): void {
const playerMoney: number = this.props.p.money.toNumber();
const stock = this.props.stock;
@@ -209,19 +209,19 @@ export class StockTicker extends React.Component {
}
}
- handleHeaderClick(e: React.MouseEvent) {
+ handleHeaderClick(e: React.MouseEvent): void {
const elem = e.currentTarget;
elem.classList.toggle("active");
const panel: HTMLElement = elem.nextElementSibling as HTMLElement;
- if (panel!.style.display === "block") {
- panel!.style.display = "none";
+ if (panel.style.display === "block") {
+ panel.style.display = "none";
} else {
panel.style.display = "block";
}
}
- handleOrderTypeChange(e: React.ChangeEvent) {
+ handleOrderTypeChange(e: React.ChangeEvent): void {
const val = e.target.value;
// The select value returns a string. Afaik TypeScript doesnt make it easy
@@ -245,7 +245,7 @@ export class StockTicker extends React.Component {
}
}
- handlePositionTypeChange(e: React.ChangeEvent) {
+ handlePositionTypeChange(e: React.ChangeEvent): void {
const val = e.target.value;
if (val === PositionTypes.Short) {
@@ -260,13 +260,13 @@ export class StockTicker extends React.Component {
}
- handleQuantityChange(e: React.ChangeEvent) {
+ handleQuantityChange(e: React.ChangeEvent): void {
this.setState({
qty: e.target.value,
});
}
- handleSellButtonClick() {
+ handleSellButtonClick(): void {
const shares = this.getQuantity();
if (isNaN(shares)) {
dialogBoxCreate(`Invalid input for quantity (number of shares): ${this.state.qty}`);
@@ -289,7 +289,7 @@ export class StockTicker extends React.Component {
"Enter the price for your Limit Order",
(price: number) => {
this.props.placeOrder(this.props.stock, shares, price, OrderTypes.LimitSell, this.state.position);
- }
+ },
);
break;
}
@@ -299,7 +299,7 @@ export class StockTicker extends React.Component {
"Enter the price for your Stop Order",
(price: number) => {
this.props.placeOrder(this.props.stock, shares, price, OrderTypes.StopSell, this.state.position);
- }
+ },
)
break;
}
@@ -308,7 +308,7 @@ export class StockTicker extends React.Component {
}
}
- handleSellAllButtonClick() {
+ handleSellAllButtonClick(): void {
const stock = this.props.stock;
switch (this.state.orderType) {
@@ -338,10 +338,7 @@ export class StockTicker extends React.Component {
return (this.props.p.bitNodeN === 8 || (SourceFileFlags[8] >= 2));
}
- render() {
- // Determine if the player's intended transaction will cause a price movement
- const qty = this.getQuantity();
-
+ render(): React.ReactNode {
return (
void;
+ cancelOrder: (params: any) => void;
order: Order;
}
@@ -21,11 +21,11 @@ export class StockTickerOrder extends React.Component {
this.handleCancelOrderClick = this.handleCancelOrderClick.bind(this);
}
- handleCancelOrderClick() {
+ handleCancelOrderClick(): void {
this.props.cancelOrder({ order: this.props.order });
}
- render() {
+ render(): React.ReactNode {
const order = this.props.order;
const posTxt = order.pos === PositionTypes.Long ? "Long Position" : "Short Position";
diff --git a/src/StockMarket/ui/StockTickerOrderList.tsx b/src/StockMarket/ui/StockTickerOrderList.tsx
index beb21f940..77f239fb4 100644
--- a/src/StockMarket/ui/StockTickerOrderList.tsx
+++ b/src/StockMarket/ui/StockTickerOrderList.tsx
@@ -12,14 +12,14 @@ import { Stock } from "../Stock";
import { IPlayer } from "../../PersonObjects/IPlayer";
type IProps = {
- cancelOrder: (params: object) => void;
+ cancelOrder: (params: any) => void;
orders: Order[];
p: IPlayer;
stock: Stock;
}
export class StockTickerOrderList extends React.Component {
- render() {
+ render(): React.ReactNode {
const orders: React.ReactElement[] = [];
for (let i = 0; i < this.props.orders.length; ++i) {
const o = this.props.orders[i];
diff --git a/src/StockMarket/ui/StockTickerPositionText.tsx b/src/StockMarket/ui/StockTickerPositionText.tsx
index 282965ce2..dbb1977aa 100644
--- a/src/StockMarket/ui/StockTickerPositionText.tsx
+++ b/src/StockMarket/ui/StockTickerPositionText.tsx
@@ -87,7 +87,7 @@ export class StockTickerPositionText extends React.Component {
}
}
- render() {
+ render(): React.ReactNode {
const stock = this.props.stock;
return (
diff --git a/src/StockMarket/ui/StockTickerTxButton.tsx b/src/StockMarket/ui/StockTickerTxButton.tsx
index 927320a4e..00fadb6b6 100644
--- a/src/StockMarket/ui/StockTickerTxButton.tsx
+++ b/src/StockMarket/ui/StockTickerTxButton.tsx
@@ -10,10 +10,6 @@ type IProps = {
tooltip?: JSX.Element | null;
}
-type IInnerHTMLMarkup = {
- __html: string;
-}
-
export function StockTickerTxButton(props: IProps): React.ReactElement {
let className = "stock-market-input std-button";
@@ -26,8 +22,8 @@ export function StockTickerTxButton(props: IProps): React.ReactElement {
{props.text}
{
- hasTooltip &&
- {props.tooltip!}
+ props.tooltip != null &&
+ {props.tooltip}
}
)
diff --git a/src/StockMarket/ui/StockTickers.tsx b/src/StockMarket/ui/StockTickers.tsx
index 1771b7679..130c09b67 100644
--- a/src/StockMarket/ui/StockTickers.tsx
+++ b/src/StockMarket/ui/StockTickers.tsx
@@ -24,7 +24,7 @@ export type placeOrderFn = (stock: Stock, shares: number, price: number, ordType
type IProps = {
buyStockLong: txFn;
buyStockShort: txFn;
- cancelOrder: (params: object) => void;
+ cancelOrder: (params: any) => void;
eventEmitterForReset?: EventEmitter;
p: IPlayer;
placeOrder: placeOrderFn;
@@ -62,7 +62,7 @@ export class StockTickers extends React.Component {
this.listRef = React.createRef();
}
- changeDisplayMode() {
+ changeDisplayMode(): void {
if (this.state.tickerDisplayMode === TickerDisplayMode.AllStocks) {
this.setState({
tickerDisplayMode: TickerDisplayMode.Portfolio,
@@ -74,7 +74,7 @@ export class StockTickers extends React.Component {
}
}
- changeWatchlistFilter(e: React.ChangeEvent) {
+ changeWatchlistFilter(e: React.ChangeEvent): void {
const watchlist = e.target.value;
const sanitizedWatchlist = watchlist.replace(/\s/g, '');
@@ -93,7 +93,7 @@ export class StockTickers extends React.Component {
}
}
- collapseAllTickers() {
+ collapseAllTickers(): void {
const ul = this.listRef.current;
if (ul == null) { return; }
const tickers = ul.getElementsByClassName("accordion-header");
@@ -109,7 +109,7 @@ export class StockTickers extends React.Component {
}
}
- expandAllTickers() {
+ expandAllTickers(): void {
const ul = this.listRef.current;
if (ul == null) { return; }
const tickers = ul.getElementsByClassName("accordion-header");
@@ -125,7 +125,7 @@ export class StockTickers extends React.Component {
}
}
- rerender() {
+ rerender(): void {
this.setState((prevState) => {
return {
rerenderFlag: !prevState.rerenderFlag,
@@ -133,7 +133,7 @@ export class StockTickers extends React.Component {
});
}
- render() {
+ render(): React.ReactNode {
const tickers: React.ReactElement[] = [];
for (const stockMarketProp in this.props.stockMarket) {
const val = this.props.stockMarket[stockMarketProp];
@@ -168,7 +168,7 @@ export class StockTickers extends React.Component {
sellStockLong={this.props.sellStockLong}
sellStockShort={this.props.sellStockShort}
stock={val}
- />
+ />,
)
}
}
diff --git a/src/StockMarket/ui/StockTickersConfig.tsx b/src/StockMarket/ui/StockTickersConfig.tsx
index 115da22b8..d4c3144b4 100644
--- a/src/StockMarket/ui/StockTickersConfig.tsx
+++ b/src/StockMarket/ui/StockTickersConfig.tsx
@@ -25,9 +25,9 @@ export class StockTickersConfig extends React.Component {
super(props);
}
- renderDisplayModeButton() {
- let txt: string = "";
- let tooltip: string = "";
+ renderDisplayModeButton(): React.ReactNode {
+ let txt = "";
+ let tooltip = "";
if (this.props.tickerDisplayMode === TickerDisplayMode.Portfolio) {
txt = "Switch to 'All Stocks' Mode";
tooltip = "Displays all stocks on the WSE";
@@ -45,7 +45,7 @@ export class StockTickersConfig extends React.Component {
)
}
- render() {
+ render(): React.ReactNode {
return (
{this.renderDisplayModeButton()}
diff --git a/src/Terminal.jsx b/src/Terminal.jsx
index cfe596851..501a216bd 100644
--- a/src/Terminal.jsx
+++ b/src/Terminal.jsx
@@ -4,37 +4,30 @@ import {
getFirstParentDirectory,
isInRootDirectory,
isValidDirectoryPath,
- isValidFilename,
removeLeadingSlash,
- removeTrailingSlash
+ removeTrailingSlash,
} from "./Terminal/DirectoryHelpers";
import { determineAllPossibilitiesForTabCompletion } from "./Terminal/determineAllPossibilitiesForTabCompletion";
import { TerminalHelpText, HelpTexts } from "./Terminal/HelpText";
import { tabCompletion } from "./Terminal/tabCompletion";
import {
- Aliases,
- GlobalAliases,
parseAliasDeclaration,
printAliases,
removeAlias,
- substituteAliases
+ substituteAliases,
} from "./Alias";
import { BitNodeMultipliers } from "./BitNode/BitNodeMultipliers";
import {
- CodingContract,
CodingContractResult,
- CodingContractRewardType
} from "./CodingContracts";
import { CONSTANTS } from "./Constants";
import { Programs } from "./Programs/Programs";
import {
executeDarkwebTerminalCommand,
- checkIfConnectedToDarkweb
+ checkIfConnectedToDarkweb,
} from "./DarkWeb/DarkWeb";
-import { DarkWebItems } from "./DarkWeb/DarkWebItems";
import { Engine } from "./engine";
-import { parseFconfSettings, createFconf } from "./Fconf/Fconf";
import { FconfSettings } from "./Fconf/FconfSettings";
import {
calculateHackingChance,
@@ -42,13 +35,13 @@ import {
calculatePercentMoneyHacked,
calculateHackingTime,
calculateGrowTime,
- calculateWeakenTime
+ calculateWeakenTime,
} from "./Hacking";
import { HacknetServer } from "./Hacknet/HacknetServer";
import {
iTutorialNextStep,
iTutorialSteps,
- ITutorial
+ ITutorial,
} from "./InteractiveTutorial";
import { showLiterature } from "./Literature/LiteratureHelpers";
import { Message } from "./Message/Message";
@@ -60,27 +53,26 @@ import { Player } from "./Player";
import { hackWorldDaemon } from "./RedPill";
import { RunningScript } from "./Script/RunningScript";
import { getRamUsageFromRunningScript } from "./Script/RunningScriptHelpers";
-import { getCurrentEditor, findRunningScript } from "./Script/ScriptHelpers";
+import {
+ getCurrentEditor,
+ findRunningScript,
+ findRunningScriptByPid,
+} from "./Script/ScriptHelpers";
import { isScriptFilename } from "./Script/ScriptHelpersTS";
import { AllServers } from "./Server/AllServers";
-import { Server } from "./Server/Server";
import {
GetServerByHostname,
getServer,
- getServerOnNetwork
+ getServerOnNetwork,
} from "./Server/ServerHelpers";
-import { Settings } from "./Settings/Settings";
import {
SpecialServerIps,
- SpecialServerNames
+ SpecialServerNames,
} from "./Server/SpecialServerIps";
-import { getTextFile } from "./TextFile";
import { setTimeoutRef } from "./utils/SetTimeoutRef";
import { Page, routing } from "./ui/navigationTracking";
import { numeralWrapper } from "./ui/numeralFormat";
import { KEY } from "../utils/helpers/keyCodes";
-import { addOffset } from "../utils/helpers/addOffset";
-import { isString } from "../utils/helpers/isString";
import { arrayToString } from "../utils/helpers/arrayToString";
import { getTimestamp } from "../utils/helpers/getTimestamp";
import { logBoxCreate } from "../utils/LogBox";
@@ -88,7 +80,7 @@ import {
yesNoBoxCreate,
yesNoBoxGetYesButton,
yesNoBoxGetNoButton,
- yesNoBoxClose
+ yesNoBoxClose,
} from "../utils/YesNoBox";
import {
post,
@@ -96,7 +88,7 @@ import {
postContent,
postError,
hackProgressBarPost,
- hackProgressPost
+ hackProgressPost,
} from "./ui/postToTerminal";
import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions";
import { Money } from "./ui/React/Money";
@@ -136,7 +128,7 @@ $(document).keydown(function(event) {
"
[" +
(FconfSettings.ENABLE_TIMESTAMPS ? getTimestamp() + " " : "") +
Player.getCurrentServer().hostname +
- ` ~${dir}]> ${command}`
+ ` ~${dir}]> ${command}`,
);
if (command.length > 0) {
@@ -393,7 +385,6 @@ let Terminal = {
var inputLength = terminalInput.value.length;
var start = terminalInput.selectionStart;
- var end = terminalInput.selectionEnd;
var inputText = terminalInput.value;
switch(mod.toLowerCase()) {
@@ -436,7 +427,6 @@ let Terminal = {
var inputLength = terminalInput.value.length;
var start = terminalInput.selectionStart;
- var end = terminalInput.selectionEnd;
switch(loc.toLowerCase()) {
case "home":
@@ -585,47 +575,26 @@ let Terminal = {
let currServ = Player.getCurrentServer();
const isHacknet = currServ instanceof HacknetServer;
post(currServ.hostname + ": ");
- post("Organization name: " + currServ.organizationName);
- var rootAccess = "";
- if (currServ.hasAdminRights) {rootAccess = "YES";}
- else {rootAccess = "NO";}
- post("Root Access: " + rootAccess);
- if (!isHacknet) { post("Required hacking skill: " + currServ.requiredHackingSkill); }
- post("Server security level: " + numeralWrapper.formatServerSecurity(currServ.hackDifficulty));
- post("Chance to hack: " + numeralWrapper.formatPercentage(calculateHackingChance(currServ, Player)));
- post("Time to hack: " + convertTimeMsToTimeElapsedString(calculateHackingTime(currServ, Player)*1000));
- postElement(<>Total money available on server: {Money(currServ.moneyAvailable)}>);
- if (!isHacknet) { post("Required number of open ports for NUKE: " + currServ.numOpenPortsRequired); }
-
- if (currServ.sshPortOpen) {
- post("SSH port: Open")
- } else {
- post("SSH port: Closed")
- }
-
- if (currServ.ftpPortOpen) {
- post("FTP port: Open")
- } else {
- post("FTP port: Closed")
- }
-
- if (currServ.smtpPortOpen) {
- post("SMTP port: Open")
- } else {
- post("SMTP port: Closed")
- }
-
- if (currServ.httpPortOpen) {
- post("HTTP port: Open")
- } else {
- post("HTTP port: Closed")
- }
-
- if (currServ.sqlPortOpen) {
- post("SQL port: Open")
- } else {
- post("SQL port: Closed")
- }
+ const org = currServ.organizationName
+ post("Organization name: " + (!isHacknet ? org : "Player"));
+ const admin = currServ.hasAdminRights;
+ post("Root Access: " + (!isHacknet ? "YES" : "NO"));
+ const hackingSkill = currServ.requiredHackingSkill
+ post("Required hacking skill: " + (!isHacknet ? hackingSkill : "N/A"));
+ const security = currServ.hackDifficulty;
+ post("Server security level: " + (!isHacknet ? numeralWrapper.formatServerSecurity(security) : "N/A"));
+ const hackingChance = calculateHackingChance(currServ, Player)
+ post("Chance to hack: " + (!isHacknet ? numeralWrapper.formatPercentage(hackingChance) : "N/A"));
+ const hackingTime = calculateHackingTime(currServ, Player)*1000;
+ post("Time to hack: " + (!isHacknet ? convertTimeMsToTimeElapsedString(hackingTime, true) : "N/A"));
+ postElement(<>Total money available on server: {!isHacknet ? Money(currServ.moneyAvailable) : "N/A"}>);
+ const numPort = currServ.numOpenPortsRequired;
+ post("Required number of open ports for NUKE: " + (!isHacknet ? numPort : "N/A"));
+ post("SSH port: "+ (currServ.sshPortOpen ? "Open" : "Closed"))
+ post("FTP port: "+ (currServ.ftpPortOpen ? "Open" : "Closed"))
+ post("SMTP port: "+ (currServ.smtpPortOpen ? "Open" : "Closed"))
+ post("HTTP port: "+ (currServ.httpPortOpen ? "Open" : "Closed"))
+ post("SQL port: "+ (currServ.sqlPortOpen ? "Open" : "Closed"))
}
Terminal.analyzeFlag = false;
},
@@ -1419,10 +1388,10 @@ let Terminal = {
try {
if (commandArray.length < 2) {
postError("Incorrect number of arguments. Usage: tail [script] [arg1] [arg2]...");
- } else {
+ } else if(typeof commandArray[1] === 'string') {
const scriptName = Terminal.getFilepath(commandArray[1]);
if (!isScriptFilename(scriptName)) {
- postError("tail can only be called on .script files (filename must end with .script)");
+ postError("tail can only be called on .script, .ns, .js files, or by pid");
return;
}
@@ -1439,6 +1408,13 @@ let Terminal = {
return;
}
logBoxCreate(runningScript);
+ } else {
+ const runningScript = findRunningScriptByPid(commandArray[1], Player.getCurrentServer());
+ if (runningScript == null) {
+ postError("No such script exists");
+ return;
+ }
+ logBoxCreate(runningScript);
}
} catch(e) {
Terminal.postThrownError(e);
@@ -1543,7 +1519,7 @@ let Terminal = {
spacesPid,
script.threads,
spacesThread,
- ramUsage
+ ramUsage,
].join("");
post(entry);
}
@@ -1778,7 +1754,6 @@ let Terminal = {
return;
}
- const s = Player.getCurrentServer();
const scriptName = commandArray[1];
let numThreads = 1;
if (commandArray.length === 4 && commandArray[2] === "-t") {
@@ -1960,7 +1935,6 @@ let Terminal = {
postError(`Invalid destination. ${commandArray[2]} not found`);
return;
}
- const ip = destServer.ip;
const currServ = Player.getCurrentServer();
// Scp for lit files
@@ -2152,13 +2126,19 @@ let Terminal = {
post("Invalid server IP/hostname");
return;
}
+
+ if(targetServer instanceof HacknetServer) {
+ post(`${Programs.ServerProfiler.name} cannot be run on a Hacknet Server.`);
+ return
+ }
+
post(targetServer.hostname + ":");
post("Server base security level: " + targetServer.baseDifficulty);
post("Server current security level: " + targetServer.hackDifficulty);
post("Server growth rate: " + targetServer.serverGrowth);
- post(`Netscript hack() execution time: ${convertTimeMsToTimeElapsedString(calculateHackingTime(targetServer, Player)*1000)}`);
- post(`Netscript grow() execution time: ${convertTimeMsToTimeElapsedString(calculateGrowTime(targetServer, Player)*1000)}`);
- post(`Netscript weaken() execution time: ${convertTimeMsToTimeElapsedString(calculateWeakenTime(targetServer, Player)*1000)}`);
+ post(`Netscript hack() execution time: ${convertTimeMsToTimeElapsedString(calculateHackingTime(targetServer, Player)*1000, true)}`);
+ post(`Netscript grow() execution time: ${convertTimeMsToTimeElapsedString(calculateGrowTime(targetServer, Player)*1000, true)}`);
+ post(`Netscript weaken() execution time: ${convertTimeMsToTimeElapsedString(calculateWeakenTime(targetServer, Player)*1000, true)}`);
};
programHandlers[Programs.AutoLink.name] = () => {
post("This executable cannot be run.");
diff --git a/src/Terminal/DirectoryHelpers.ts b/src/Terminal/DirectoryHelpers.ts
index 0a3692e54..700e72b3f 100644
--- a/src/Terminal/DirectoryHelpers.ts
+++ b/src/Terminal/DirectoryHelpers.ts
@@ -99,7 +99,7 @@ export function isValidDirectoryPath(path: string): boolean {
*/
export function isValidFilePath(path: string): boolean {
if (path == null || typeof path !== "string") { return false; }
- let t_path = path;
+ const t_path = path;
// Impossible for filename to have less than length of 3
if (t_path.length < 3) { return false; }
@@ -132,7 +132,7 @@ export function getFirstParentDirectory(path: string): string {
if (t_path.lastIndexOf("/") === -1) { return "/"; }
- let dirs = t_path.split("/");
+ const dirs = t_path.split("/");
if (dirs.length === 0) { return "/"; }
return dirs[0] + "/";
@@ -146,7 +146,7 @@ export function getFirstParentDirectory(path: string): string {
* If there are no parent directories, it returns the empty string
*/
export function getAllParentDirectories(path: string): string {
- let t_path = path;
+ const t_path = path;
const lastSlash = t_path.lastIndexOf("/");
if (lastSlash === -1) { return ""; }
diff --git a/src/Terminal/DirectoryServerHelpers.ts b/src/Terminal/DirectoryServerHelpers.ts
index 69a77f89f..8757e7066 100644
--- a/src/Terminal/DirectoryServerHelpers.ts
+++ b/src/Terminal/DirectoryServerHelpers.ts
@@ -26,7 +26,7 @@ export function getSubdirectories(serv: BaseServer, dir: string): string[] {
let t_dir = dir;
if (!t_dir.endsWith("/")) { t_dir += "/"; }
- function processFile(fn: string) {
+ function processFile(fn: string): void {
if (t_dir === "/" && isInRootDirectory(fn)) {
const subdir = getFirstParentDirectory(fn);
if (subdir !== "/" && !res.includes(subdir)) {
diff --git a/src/Terminal/determineAllPossibilitiesForTabCompletion.ts b/src/Terminal/determineAllPossibilitiesForTabCompletion.ts
index 2753c5267..ffe356cf4 100644
--- a/src/Terminal/determineAllPossibilitiesForTabCompletion.ts
+++ b/src/Terminal/determineAllPossibilitiesForTabCompletion.ts
@@ -6,7 +6,7 @@ import { getSubdirectories } from "./DirectoryServerHelpers";
import {
Aliases,
- GlobalAliases
+ GlobalAliases,
} from "../Alias";
import { DarkWebItems } from "../DarkWeb/DarkWebItems";
import { Message } from "../Message/Message";
@@ -48,26 +48,26 @@ const commands = [
"sudov",
"tail",
"theme",
- "top"
+ "top",
];
-export function determineAllPossibilitiesForTabCompletion(p: IPlayer, input: string, index: number, currPath: string=""): string[] {
+export function determineAllPossibilitiesForTabCompletion(p: IPlayer, input: string, index: number, currPath=""): string[] {
let allPos: string[] = [];
allPos = allPos.concat(Object.keys(GlobalAliases));
const currServ = p.getCurrentServer();
const homeComputer = p.getHomeComputer();
- let parentDirPath: string = "";
+ let parentDirPath = "";
let evaledParentDirPath: string | null = null;
// Helper functions
- function addAllCodingContracts() {
+ function addAllCodingContracts(): void {
for (const cct of currServ.contracts) {
allPos.push(cct.fn);
}
}
- function addAllLitFiles() {
+ function addAllLitFiles(): void {
for (const file of currServ.messages) {
if (!(file instanceof Message)) {
allPos.push(file);
@@ -75,7 +75,7 @@ export function determineAllPossibilitiesForTabCompletion(p: IPlayer, input: str
}
}
- function addAllMessages() {
+ function addAllMessages(): void {
for (const file of currServ.messages) {
if (file instanceof Message) {
allPos.push(file.filename);
@@ -83,13 +83,13 @@ export function determineAllPossibilitiesForTabCompletion(p: IPlayer, input: str
}
}
- function addAllPrograms() {
+ function addAllPrograms(): void {
for (const program of homeComputer.programs) {
allPos.push(program);
}
}
- function addAllScripts() {
+ function addAllScripts(): void {
for (const script of currServ.scripts) {
const res = processFilepath(script.filename);
if (res) {
@@ -98,7 +98,7 @@ export function determineAllPossibilitiesForTabCompletion(p: IPlayer, input: str
}
}
- function addAllTextFiles() {
+ function addAllTextFiles(): void {
for (const txt of currServ.textFiles) {
const res = processFilepath(txt.fn);
if (res) {
@@ -107,7 +107,7 @@ export function determineAllPossibilitiesForTabCompletion(p: IPlayer, input: str
}
}
- function addAllDirectories() {
+ function addAllDirectories(): void {
// Directories are based on the currently evaluated path
const subdirs = getSubdirectories(currServ, evaledParentDirPath == null ? "/" : evaledParentDirPath);
@@ -157,7 +157,7 @@ export function determineAllPossibilitiesForTabCompletion(p: IPlayer, input: str
return null;
}
- function isCommand(cmd: string) {
+ function isCommand(cmd: string): boolean {
let t_cmd = cmd;
if (!t_cmd.endsWith(" ")) {
t_cmd += " ";
@@ -173,12 +173,12 @@ export function determineAllPossibilitiesForTabCompletion(p: IPlayer, input: str
*/
if (isCommand("./") && index == -1) {
//All programs and scripts
- for (var i = 0; i < currServ.scripts.length; ++i) {
+ for (let i = 0; i < currServ.scripts.length; ++i) {
allPos.push("./" + currServ.scripts[i].filename);
}
//Programs are on home computer
- for(var i = 0; i < homeComputer.programs.length; ++i) {
+ for(let i = 0; i < homeComputer.programs.length; ++i) {
allPos.push("./" + homeComputer.programs[i]);
}
return allPos;
@@ -208,7 +208,7 @@ export function determineAllPossibilitiesForTabCompletion(p: IPlayer, input: str
}
if (isCommand("buy")) {
- let options = [];
+ const options = [];
for (const i in DarkWebItems) {
const item = DarkWebItems[i]
options.push(item.program);
@@ -237,8 +237,8 @@ export function determineAllPossibilitiesForTabCompletion(p: IPlayer, input: str
if (isCommand("connect")) {
// All network connections
- for (var i = 0; i < currServ.serversOnNetwork.length; ++i) {
- var serv = AllServers[currServ.serversOnNetwork[i]];
+ for (let i = 0; i < currServ.serversOnNetwork.length; ++i) {
+ const serv = AllServers[currServ.serversOnNetwork[i]];
if (serv == null) { continue; }
allPos.push(serv.ip);
allPos.push(serv.hostname);
diff --git a/src/Terminal/tabCompletion.ts b/src/Terminal/tabCompletion.ts
index 033323d2d..19b6bd479 100644
--- a/src/Terminal/tabCompletion.ts
+++ b/src/Terminal/tabCompletion.ts
@@ -1,10 +1,10 @@
import {
- post
+ post,
} from "../ui/postToTerminal";
import {
containsAllStrings,
- longestCommonStart
+ longestCommonStart,
} from "../../utils/StringHelperFunctions";
/**
diff --git a/src/TextFile.ts b/src/TextFile.ts
index 0e5a6bd3e..67442d3f7 100644
--- a/src/TextFile.ts
+++ b/src/TextFile.ts
@@ -3,7 +3,7 @@ import { dialogBoxCreate } from "../utils/DialogBox";
import {
Generic_fromJSON,
Generic_toJSON,
- Reviver
+ Reviver,
} from "../utils/JSONReviver";
@@ -11,13 +11,6 @@ import {
* Represents a plain text file that is typically stored on a server.
*/
export class TextFile {
- /**
- * Initiatizes a TextFile from a JSON save state.
- */
- static fromJSON(value: any): TextFile {
- return Generic_fromJSON(TextFile, value.data);
- }
-
/**
* The full file name.
*/
@@ -28,7 +21,7 @@ export class TextFile {
*/
text: string;
- constructor(fn: string = "", txt: string = "") {
+ constructor(fn = "", txt = "") {
this.fn = (fn.endsWith(".txt") ? fn : `${fn}.txt`).replace(/\s+/g, "");
this.text = txt;
}
@@ -92,6 +85,14 @@ export class TextFile {
write(txt: string): void {
this.text = txt;
}
+
+ /**
+ * Initiatizes a TextFile from a JSON save state.
+ */
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+ static fromJSON(value: any): TextFile {
+ return Generic_fromJSON(TextFile, value.data);
+ }
}
Reviver.constructors.TextFile = TextFile;
@@ -102,6 +103,7 @@ Reviver.constructors.TextFile = TextFile;
* @param server The server object to look in
* @returns The file object, or null if it couldn't find it.
*/
+// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function getTextFile(fn: string, server: any): TextFile | null {
const filename: string = !fn.endsWith(".txt") ? `${fn}.txt` : fn;
@@ -121,6 +123,7 @@ export function getTextFile(fn: string, server: any): TextFile | null {
* @param server The server that the file should be created on.
* @returns The instance of the file.
*/
+// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function createTextFile(fn: string, txt: string, server: any): TextFile | undefined {
if (getTextFile(fn, server) !== null) {
// This should probably be a `throw`...
@@ -134,18 +137,3 @@ export function createTextFile(fn: string, txt: string, server: any): TextFile |
return file;
}
-
-/* tslint:disable-next-line:no-unused-variable */
-function deleteTextFile(fn: string, server: any): boolean {
- const filename: string = !fn.endsWith(".txt") ? `${fn}.txt` : fn;
- /* tslint:disable-next-line:typedef */
- for (let i = 0; i < server.textFiles.length; ++i) {
- if (server.textFiles[i].fn === filename) {
- server.textFiles.splice(i, 1);
-
- return true;
- }
- }
-
- return false;
-}
diff --git a/src/ThirdParty/Treant.js b/src/ThirdParty/Treant.js
index d6c70e515..2ac51885a 100644
--- a/src/ThirdParty/Treant.js
+++ b/src/ThirdParty/Treant.js
@@ -17,7 +17,7 @@
* Dave Goodchild, https://github.com/dlgoodchild
*/
-;( function() {
+( function() {
// Polyfill for IE to use startsWith
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position){
@@ -161,7 +161,7 @@
+ UTIL.getStyle( element, 'border-bottom-width', true )
+ UTIL.getStyle( element, 'padding-top', true )
+ UTIL.getStyle( element, 'padding-bottom', true )
- + nRoundingCompensation
+ + nRoundingCompensation,
);
}
},
@@ -181,7 +181,7 @@
+ UTIL.getStyle( element, 'border-right-width', true )
+ UTIL.getStyle( element, 'padding-left', true )
+ UTIL.getStyle( element, 'padding-right', true )
- + nRoundingCompensation
+ + nRoundingCompensation,
);
}
},
@@ -195,7 +195,7 @@
strCssRule = strCssRule.replace(/\-(\w)/g,
function (strMatch, p1){
return p1.toUpperCase();
- }
+ },
);
strValue = element.currentStyle[strCssRule];
}
@@ -332,7 +332,7 @@
*/
isNotLoading: function() {
return ( this.loading.length === 0 );
- }
+ },
};
/**
@@ -392,7 +392,7 @@
this.store[treeId] = null;
}
return this;
- }
+ },
};
/**
@@ -513,7 +513,7 @@
function() {
root.toggleCollapse();
},
- this.CONFIG.animateOnInitDelay
+ this.CONFIG.animateOnInitDelay,
);
}
@@ -531,7 +531,7 @@
setTimeout(
function() {
self.positionTree( callback );
- }, 10
+ }, 10,
);
}
return this;
@@ -751,7 +751,7 @@
var self = this,
treeSize = {
x: self.nodeDB.getMinMaxCoord('X', null, null),
- y: self.nodeDB.getMinMaxCoord('Y', null, null)
+ y: self.nodeDB.getMinMaxCoord('Y', null, null),
},
treeWidth = treeSize.x.max - treeSize.x.min,
@@ -759,7 +759,7 @@
treeCenter = {
x: treeSize.x.max - treeWidth/2,
- y: treeSize.y.max - treeHeight/2
+ y: treeSize.y.max - treeHeight/2,
};
this.handleOverflow(treeWidth, treeHeight);
@@ -767,7 +767,7 @@
var
containerCenter = {
x: self.drawArea.clientWidth/2,
- y: self.drawArea.clientHeight/2
+ y: self.drawArea.clientHeight/2,
},
deltaX = containerCenter.x - treeCenter.x,
@@ -857,7 +857,7 @@
if (jq_drawArea.hasClass('ps-container')) { // znaci da je 'fancy' vec inicijaliziran, treba updateat
jq_drawArea.find('.Treant').css({
width: viewWidth,
- height: viewHeight
+ height: viewHeight,
});
jq_drawArea.perfectScrollbar('update');
@@ -868,7 +868,7 @@
child.css({
width: viewWidth,
- height: viewHeight
+ height: viewHeight,
});
mainContainer.perfectScrollbar();
@@ -948,7 +948,7 @@
{
path: pathString.charAt(0) === "_"?
pathString.substring(1):
- pathString // remove the "_" prefix if it exists
+ pathString, // remove the "_" prefix if it exists
},
this.CONFIG.animation.connectorsSpeed,
this.CONFIG.animation.connectorsAnimation,
@@ -957,7 +957,7 @@
path.hide();
path.hidden = true;
}
- }
+ },
);
return this;
},
@@ -1064,7 +1064,7 @@
calcLevelDim: function( node, level ) { // root node is on level 0
this.levelMaxDim[level] = {
width: Math.max( this.levelMaxDim[level]? this.levelMaxDim[level].width: 0, node.width ),
- height: Math.max( this.levelMaxDim[level]? this.levelMaxDim[level].height: 0, node.height )
+ height: Math.max( this.levelMaxDim[level]? this.levelMaxDim[level].height: 0, node.height ),
};
return this;
},
@@ -1083,7 +1083,7 @@
*/
root: function() {
return this.nodeDB.get( 0 );
- }
+ },
};
/**
@@ -1232,7 +1232,7 @@
else {
parent.children.splice(
Math.max( position, parent.children.length - 1 ),
- 0, node.id
+ 0, node.id,
);
}
}
@@ -1256,7 +1256,7 @@
MinMax = MinMax || { // start with root node dimensions
min: parent[dim],
- max: parent[dim] + ( ( dim === 'X' )? parent.width: parent.height )
+ max: parent[dim] + ( ( dim === 'X' )? parent.width: parent.height ),
};
var i = parent.childrenCount();
@@ -1290,7 +1290,7 @@
}
}
return false;
- }
+ },
};
/**
@@ -1622,7 +1622,7 @@
self.toggleCollapse();
self.getTreeConfig().callback.onAfterClickCollapseSwitch.apply( self, [ nodeSwitch, e ] );
- }
+ },
);
},
@@ -1669,7 +1669,7 @@
},
( oTree.CONFIG.animation.nodeSpeed > oTree.CONFIG.animation.connectorsSpeed )?
oTree.CONFIG.animation.nodeSpeed:
- oTree.CONFIG.animation.connectorsSpeed
+ oTree.CONFIG.animation.connectorsSpeed,
);
}
return this;
@@ -1686,7 +1686,7 @@
var tree = this.getTree(),
config = this.getTreeConfig(),
oNewState = {
- opacity: 0
+ opacity: 0,
};
if ( collapse_to_point ) {
@@ -1713,7 +1713,7 @@
oNewState, config.animation.nodeSpeed, config.animation.nodeAnimation,
function () {
this.style.visibility = 'hidden';
- }
+ },
);
}
else {
@@ -1752,7 +1752,7 @@
oPath.animate(
{ 'opacity': 0 },
oTree.CONFIG.animation.connectorsSpeed,
- oTree.CONFIG.animation.connectorsAnimation
+ oTree.CONFIG.animation.connectorsAnimation,
);
}
return this;
@@ -1769,7 +1769,7 @@
var oNewState = {
left: this.X,
top: this.Y,
- opacity: 1
+ opacity: 1,
},
config = this.getTreeConfig();
@@ -1781,7 +1781,7 @@
function () {
// $.animate applies "overflow:hidden" to the node, remove it to avoid visual problems
this.style.overflow = "";
- }
+ },
);
}
else {
@@ -1810,11 +1810,11 @@
oPath.animate(
{ 'opacity': 1 },
oTree.CONFIG.animation.connectorsSpeed,
- oTree.CONFIG.animation.connectorsAnimation
+ oTree.CONFIG.animation.connectorsAnimation,
);
}
return this;
- }
+ },
};
@@ -1868,8 +1868,8 @@
textElement.className = "node-"+key;
textElement.appendChild(document.createTextNode(
this.text[key].val ? this.text[key].val :
- this.text[key] instanceof Object ? "'val' param missing!" : this.text[key]
- )
+ this.text[key] instanceof Object ? "'val' param missing!" : this.text[key],
+ ),
);
node.appendChild(textElement);
@@ -1941,7 +1941,7 @@
}
else {
node.data = {
- 'treenode': this
+ 'treenode': this,
};
}
@@ -2017,9 +2017,9 @@
connectors: {
type: 'curve', // 'curve' || 'step' || 'straight' || 'bCurve'
style: {
- stroke: 'black'
+ stroke: 'black',
},
- stackIndent: 15
+ stackIndent: 15,
},
node: { // each node inherits this, it can all be overridden in node config
@@ -2028,15 +2028,15 @@
// drawLineThrough: false,
// collapsable: false,
link: {
- target: '_self'
- }
+ target: '_self',
+ },
},
animation: { // each node inherits this, it can all be overridden in node config
nodeSpeed: 450,
nodeAnimation: 'linear',
connectorsSpeed: 450,
- connectorsAnimation: 'linear'
+ connectorsAnimation: 'linear',
},
callback: {
@@ -2049,12 +2049,12 @@
onToggleCollapseFinished: function ( treeNode, bIsCollapsed ) {}, // this = Tree
onAfterClickCollapseSwitch: function( nodeSwitch, event ) {}, // this = TreeNode
onBeforeClickCollapseSwitch: function( nodeSwitch, event ) {}, // this = TreeNode
- onTreeLoaded: function( rootTreeNode ) {} // this = Tree
- }
+ onTreeLoaded: function( rootTreeNode ) {}, // this = Tree
+ },
};
TreeNode.CONFIG = {
- nodeHTMLclass: 'node'
+ nodeHTMLclass: 'node',
};
// #############################################
@@ -2068,7 +2068,7 @@
this.jsonStructure = {
chart: null,
- nodeStructure: null
+ nodeStructure: null,
};
//fist loop: find config, find root;
while(i--) {
@@ -2141,7 +2141,7 @@
return i++;
};
}
- )()
+ )(),
};
/**
diff --git a/src/ThirdParty/raphael.min.js b/src/ThirdParty/raphael.min.js
index 75a545b54..16fd7b4b0 100644
--- a/src/ThirdParty/raphael.min.js
+++ b/src/ThirdParty/raphael.min.js
@@ -1 +1 @@
-!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Raphael=e():t.Raphael=e()}(window,function(){return function(t){var e={};function r(i){if(e[i])return e[i].exports;var n=e[i]={i:i,l:!1,exports:{}};return t[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=t,r.c=e,r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},r.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=4)}([function(t,e,r){var i,n;i=[r(3)],void 0===(n=function(t){function e(i){if(e.is(i,"function"))return r?i():t.on("raphael.DOMload",i);if(e.is(i,T))return e._engine.create[c](e,i.splice(0,3+e.is(i[0],A))).add(i);var n=Array.prototype.slice.call(arguments,0);if(e.is(n[n.length-1],"function")){var a=n.pop();return r?a.call(e._engine.create[c](e,n)):t.on("raphael.DOMload",function(){a.call(e._engine.create[c](e,n))})}return e._engine.create[c](e,arguments)}e.version="2.2.0",e.eve=t;var r,i,n=/[, ]+/,a={circle:1,rect:1,path:1,ellipse:1,text:1,image:1},s=/\{(\d+)\}/g,o="hasOwnProperty",l={doc:document,win:window},h={was:Object.prototype[o].call(l.win,"Raphael"),is:l.win.Raphael},u=function(){this.ca=this.customAttributes={}},c="apply",f="concat",p="ontouchstart"in l.win||l.win.DocumentTouch&&l.doc instanceof DocumentTouch,d="",g=" ",x=String,v="split",y="click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[v](g),m={mousedown:"touchstart",mousemove:"touchmove",mouseup:"touchend"},b=x.prototype.toLowerCase,_=Math,w=_.max,k=_.min,B=_.abs,C=_.pow,S=_.PI,A="number",T="array",M=Object.prototype.toString,E=(e._ISURL=/^url\(['"]?(.+?)['"]?\)$/i,/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\))\s*$/i),N={NaN:1,Infinity:1,"-Infinity":1},L=/^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,P=_.round,z=parseFloat,F=parseInt,R=x.prototype.toUpperCase,j=e._availableAttrs={"arrow-end":"none","arrow-start":"none",blur:0,"clip-rect":"0 0 1e9 1e9",cursor:"default",cx:0,cy:0,fill:"#fff","fill-opacity":1,font:'10px "Arial"',"font-family":'"Arial"',"font-size":"10","font-style":"normal","font-weight":400,gradient:0,height:0,href:"http://raphaeljs.com/","letter-spacing":0,opacity:1,path:"M0,0",r:0,rx:0,ry:0,src:"",stroke:"#000","stroke-dasharray":"","stroke-linecap":"butt","stroke-linejoin":"butt","stroke-miterlimit":0,"stroke-opacity":1,"stroke-width":1,target:"_blank","text-anchor":"middle",title:"Raphael",transform:"",width:0,x:0,y:0,class:""},I=e._availableAnimAttrs={blur:A,"clip-rect":"csv",cx:A,cy:A,fill:"colour","fill-opacity":A,"font-size":A,height:A,opacity:A,path:"path",r:A,rx:A,ry:A,stroke:"colour","stroke-opacity":A,"stroke-width":A,transform:"transform",width:A,x:A,y:A},D=/[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/,q={hs:1,rg:1},O=/,?([achlmqrstvxz]),?/gi,V=/([achlmrqstvz])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/gi,Y=/([rstm])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/gi,W=/(-?\d*\.?\d*(?:e[\-+]?\d+)?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/gi,G=(e._radial_gradient=/^r(?:\(([^,]+?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*([^\)]+?)\))?/,{}),H=function(t,e){return z(t)-z(e)},X=function(t){return t},U=e._rectPath=function(t,e,r,i,n){return n?[["M",t+n,e],["l",r-2*n,0],["a",n,n,0,0,1,n,n],["l",0,i-2*n],["a",n,n,0,0,1,-n,n],["l",2*n-r,0],["a",n,n,0,0,1,-n,-n],["l",0,2*n-i],["a",n,n,0,0,1,n,-n],["z"]]:[["M",t,e],["l",r,0],["l",0,i],["l",-r,0],["z"]]},$=function(t,e,r,i){return null==i&&(i=r),[["M",t,e],["m",0,-i],["a",r,i,0,1,1,0,2*i],["a",r,i,0,1,1,0,-2*i],["z"]]},Z=e._getPath={path:function(t){return t.attr("path")},circle:function(t){var e=t.attrs;return $(e.cx,e.cy,e.r)},ellipse:function(t){var e=t.attrs;return $(e.cx,e.cy,e.rx,e.ry)},rect:function(t){var e=t.attrs;return U(e.x,e.y,e.width,e.height,e.r)},image:function(t){var e=t.attrs;return U(e.x,e.y,e.width,e.height)},text:function(t){var e=t._getBBox();return U(e.x,e.y,e.width,e.height)},set:function(t){var e=t._getBBox();return U(e.x,e.y,e.width,e.height)}},Q=e.mapPath=function(t,e){if(!e)return t;var r,i,n,a,s,o,l;for(n=0,s=(t=At(t)).length;n
',(J=K.firstChild).style.behavior="url(#default#VML)",!J||"object"!=typeof J.adj)return e.type=d;K=null}function tt(t){if("function"==typeof t||Object(t)!==t)return t;var e=new t.constructor;for(var r in t)t[o](r)&&(e[r]=tt(t[r]));return e}e.svg=!(e.vml="VML"==e.type),e._Paper=u,e.fn=i=u.prototype=e.prototype,e._id=0,e.is=function(t,e){return"finite"==(e=b.call(e))?!N[o](+t):"array"==e?t instanceof Array:"null"==e&&null===t||e==typeof t&&null!==t||"object"==e&&t===Object(t)||"array"==e&&Array.isArray&&Array.isArray(t)||M.call(t).slice(8,-1).toLowerCase()==e},e.angle=function(t,r,i,n,a,s){if(null==a){var o=t-i,l=r-n;return o||l?(180+180*_.atan2(-l,-o)/S+360)%360:0}return e.angle(t,r,a,s)-e.angle(i,n,a,s)},e.rad=function(t){return t%360*S/180},e.deg=function(t){return Math.round(180*t/S%360*1e3)/1e3},e.snapTo=function(t,r,i){if(i=e.is(i,"finite")?i:10,e.is(t,T)){for(var n=t.length;n--;)if(B(t[n]-r)<=i)return t[n]}else{var a=r%(t=+t);if(a
t-i)return r-a+t}return r};var et,rt;e.createUUID=(et=/[xy]/g,rt=function(t){var e=16*_.random()|0;return("x"==t?e:3&e|8).toString(16)},function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(et,rt).toUpperCase()});e.setWindow=function(r){t("raphael.setWindow",e,l.win,r),l.win=r,l.doc=l.win.document,e._engine.initWin&&e._engine.initWin(l.win)};var it=function(t){if(e.vml){var r,i=/^\s+|\s+$/g;try{var n=new ActiveXObject("htmlfile");n.write(""),n.close(),r=n.body}catch(t){r=createPopup().document.body}var a=r.createTextRange();it=ht(function(t){try{r.style.color=x(t).replace(i,d);var e=a.queryCommandValue("ForeColor");return"#"+("000000"+(e=(255&e)<<16|65280&e|(16711680&e)>>>16).toString(16)).slice(-6)}catch(t){return"none"}})}else{var s=l.doc.createElement("i");s.title="Raphaël Colour Picker",s.style.display="none",l.doc.body.appendChild(s),it=ht(function(t){return s.style.color=t,l.doc.defaultView.getComputedStyle(s,d).getPropertyValue("color")})}return it(t)},nt=function(){return"hsb("+[this.h,this.s,this.b]+")"},at=function(){return"hsl("+[this.h,this.s,this.l]+")"},st=function(){return this.hex},ot=function(t,r,i){if(null==r&&e.is(t,"object")&&"r"in t&&"g"in t&&"b"in t&&(i=t.b,r=t.g,t=t.r),null==r&&e.is(t,"string")){var n=e.getRGB(t);t=n.r,r=n.g,i=n.b}return(t>1||r>1||i>1)&&(t/=255,r/=255,i/=255),[t,r,i]},lt=function(t,r,i,n){var a={r:t*=255,g:r*=255,b:i*=255,hex:e.rgb(t,r,i),toString:st};return e.is(n,"finite")&&(a.opacity=n),a};function ht(t,e,r){return function i(){var n=Array.prototype.slice.call(arguments,0),a=n.join("␀"),s=i.cache=i.cache||{},l=i.count=i.count||[];return s[o](a)?(function(t,e){for(var r=0,i=t.length;r=1e3&&delete s[l.shift()],l.push(a),s[a]=t[c](e,n),r?r(s[a]):s[a])}}e.color=function(t){var r;return e.is(t,"object")&&"h"in t&&"s"in t&&"b"in t?(r=e.hsb2rgb(t),t.r=r.r,t.g=r.g,t.b=r.b,t.hex=r.hex):e.is(t,"object")&&"h"in t&&"s"in t&&"l"in t?(r=e.hsl2rgb(t),t.r=r.r,t.g=r.g,t.b=r.b,t.hex=r.hex):(e.is(t,"string")&&(t=e.getRGB(t)),e.is(t,"object")&&"r"in t&&"g"in t&&"b"in t?(r=e.rgb2hsl(t),t.h=r.h,t.s=r.s,t.l=r.l,r=e.rgb2hsb(t),t.v=r.b):(t={hex:"none"}).r=t.g=t.b=t.h=t.s=t.v=t.l=-1),t.toString=st,t},e.hsb2rgb=function(t,e,r,i){var n,a,s,o,l;return this.is(t,"object")&&"h"in t&&"s"in t&&"b"in t&&(r=t.b,e=t.s,i=t.o,t=t.h),o=(l=r*e)*(1-B((t=(t*=360)%360/60)%2-1)),n=a=s=r-l,lt(n+=[l,o,0,0,o,l][t=~~t],a+=[o,l,l,o,0,0][t],s+=[0,0,o,l,l,o][t],i)},e.hsl2rgb=function(t,e,r,i){var n,a,s,o,l;return this.is(t,"object")&&"h"in t&&"s"in t&&"l"in t&&(r=t.l,e=t.s,t=t.h),(t>1||e>1||r>1)&&(t/=360,e/=100,r/=100),t=(t*=360)%360/60,o=(l=2*e*(r<.5?r:1-r))*(1-B(t%2-1)),n=a=s=r-l/2,lt(n+=[l,o,0,0,o,l][t=~~t],a+=[o,l,l,o,0,0][t],s+=[0,0,o,l,l,o][t],i)},e.rgb2hsb=function(t,e,r){var i,n;return t=(r=ot(t,e,r))[0],e=r[1],r=r[2],{h:((0==(n=(i=w(t,e,r))-k(t,e,r))?null:i==t?(e-r)/n:i==e?(r-t)/n+2:(t-e)/n+4)+360)%6*60/360,s:0==n?0:n/i,b:i,toString:nt}},e.rgb2hsl=function(t,e,r){var i,n,a,s;return t=(r=ot(t,e,r))[0],e=r[1],r=r[2],i=((n=w(t,e,r))+(a=k(t,e,r)))/2,{h:((0==(s=n-a)?null:n==t?(e-r)/s:n==e?(r-t)/s+2:(t-e)/s+4)+360)%6*60/360,s:0==s?0:i<.5?s/(2*i):s/(2-2*i),l:i,toString:at}},e._path2string=function(){return this.join(",").replace(O,"$1")};e._preload=function(t,e){var r=l.doc.createElement("img");r.style.cssText="position:absolute;left:-9999em;top:-9999em",r.onload=function(){e.call(this),this.onload=null,l.doc.body.removeChild(this)},r.onerror=function(){l.doc.body.removeChild(this)},l.doc.body.appendChild(r),r.src=t};function ut(){return this.hex}function ct(t,e){for(var r=[],i=0,n=t.length;n-2*!e>i;i+=2){var a=[{x:+t[i-2],y:+t[i-1]},{x:+t[i],y:+t[i+1]},{x:+t[i+2],y:+t[i+3]},{x:+t[i+4],y:+t[i+5]}];e?i?n-4==i?a[3]={x:+t[0],y:+t[1]}:n-2==i&&(a[2]={x:+t[0],y:+t[1]},a[3]={x:+t[2],y:+t[3]}):a[0]={x:+t[n-2],y:+t[n-1]}:n-4==i?a[3]=a[2]:i||(a[0]={x:+t[i],y:+t[i+1]}),r.push(["C",(-a[0].x+6*a[1].x+a[2].x)/6,(-a[0].y+6*a[1].y+a[2].y)/6,(a[1].x+6*a[2].x-a[3].x)/6,(a[1].y+6*a[2].y-a[3].y)/6,a[2].x,a[2].y])}return r}e.getRGB=ht(function(t){if(!t||(t=x(t)).indexOf("-")+1)return{r:-1,g:-1,b:-1,hex:"none",error:1,toString:ut};if("none"==t)return{r:-1,g:-1,b:-1,hex:"none",toString:ut};!q[o](t.toLowerCase().substring(0,2))&&"#"!=t.charAt()&&(t=it(t));var r,i,n,a,s,l,h=t.match(E);return h?(h[2]&&(n=F(h[2].substring(5),16),i=F(h[2].substring(3,5),16),r=F(h[2].substring(1,3),16)),h[3]&&(n=F((s=h[3].charAt(3))+s,16),i=F((s=h[3].charAt(2))+s,16),r=F((s=h[3].charAt(1))+s,16)),h[4]&&(l=h[4][v](D),r=z(l[0]),"%"==l[0].slice(-1)&&(r*=2.55),i=z(l[1]),"%"==l[1].slice(-1)&&(i*=2.55),n=z(l[2]),"%"==l[2].slice(-1)&&(n*=2.55),"rgba"==h[1].toLowerCase().slice(0,4)&&(a=z(l[3])),l[3]&&"%"==l[3].slice(-1)&&(a/=100)),h[5]?(l=h[5][v](D),r=z(l[0]),"%"==l[0].slice(-1)&&(r*=2.55),i=z(l[1]),"%"==l[1].slice(-1)&&(i*=2.55),n=z(l[2]),"%"==l[2].slice(-1)&&(n*=2.55),("deg"==l[0].slice(-3)||"°"==l[0].slice(-1))&&(r/=360),"hsba"==h[1].toLowerCase().slice(0,4)&&(a=z(l[3])),l[3]&&"%"==l[3].slice(-1)&&(a/=100),e.hsb2rgb(r,i,n,a)):h[6]?(l=h[6][v](D),r=z(l[0]),"%"==l[0].slice(-1)&&(r*=2.55),i=z(l[1]),"%"==l[1].slice(-1)&&(i*=2.55),n=z(l[2]),"%"==l[2].slice(-1)&&(n*=2.55),("deg"==l[0].slice(-3)||"°"==l[0].slice(-1))&&(r/=360),"hsla"==h[1].toLowerCase().slice(0,4)&&(a=z(l[3])),l[3]&&"%"==l[3].slice(-1)&&(a/=100),e.hsl2rgb(r,i,n,a)):((h={r:r,g:i,b:n,toString:ut}).hex="#"+(16777216|n|i<<8|r<<16).toString(16).slice(1),e.is(a,"finite")&&(h.opacity=a),h)):{r:-1,g:-1,b:-1,hex:"none",error:1,toString:ut}},e),e.hsb=ht(function(t,r,i){return e.hsb2rgb(t,r,i).hex}),e.hsl=ht(function(t,r,i){return e.hsl2rgb(t,r,i).hex}),e.rgb=ht(function(t,e,r){function i(t){return t+.5|0}return"#"+(16777216|i(r)|i(e)<<8|i(t)<<16).toString(16).slice(1)}),e.getColor=function(t){var e=this.getColor.start=this.getColor.start||{h:0,s:1,b:t||.75},r=this.hsb2rgb(e.h,e.s,e.b);return e.h+=.075,e.h>1&&(e.h=0,e.s-=.2,e.s<=0&&(this.getColor.start={h:0,s:1,b:e.b})),r.hex},e.getColor.reset=function(){delete this.start},e.parsePathString=function(t){if(!t)return null;var r=ft(t);if(r.arr)return mt(r.arr);var i={a:7,c:6,h:1,l:2,m:2,r:4,q:4,s:4,t:2,v:1,z:0},n=[];return e.is(t,T)&&e.is(t[0],T)&&(n=mt(t)),n.length||x(t).replace(V,function(t,e,r){var a=[],s=e.toLowerCase();if(r.replace(W,function(t,e){e&&a.push(+e)}),"m"==s&&a.length>2&&(n.push([e][f](a.splice(0,2))),s="l",e="m"==e?"l":"L"),"r"==s)n.push([e][f](a));else for(;a.length>=i[s]&&(n.push([e][f](a.splice(0,i[s]))),i[s]););}),n.toString=e._path2string,r.arr=mt(n),n},e.parseTransformString=ht(function(t){if(!t)return null;var r=[];return e.is(t,T)&&e.is(t[0],T)&&(r=mt(t)),r.length||x(t).replace(Y,function(t,e,i){var n=[];b.call(e);i.replace(W,function(t,e){e&&n.push(+e)}),r.push([e][f](n))}),r.toString=e._path2string,r});var ft=function(t){var e=ft.ps=ft.ps||{};return e[t]?e[t].sleep=100:e[t]={sleep:100},setTimeout(function(){for(var r in e)e[o](r)&&r!=t&&(e[r].sleep--,!e[r].sleep&&delete e[r])}),e[t]};function pt(t,e,r,i,n){return t*(t*(-3*e+9*r-9*i+3*n)+6*e-12*r+6*i)-3*e+3*r}function dt(t,e,r,i,n,a,s,o,l){null==l&&(l=1);for(var h=(l=l>1?1:l<0?0:l)/2,u=[-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816],c=[.2491,.2491,.2335,.2335,.2032,.2032,.1601,.1601,.1069,.1069,.0472,.0472],f=0,p=0;p<12;p++){var d=h*u[p]+h,g=pt(d,t,r,n,s),x=pt(d,e,i,a,o),v=g*g+x*x;f+=c[p]*_.sqrt(v)}return h*f}function gt(t,e,r,i,n,a,s,o){if(!(w(t,r)w(n,s)||w(e,i)w(a,o))){var l=(t-r)*(a-o)-(e-i)*(n-s);if(l){var h=((t*i-e*r)*(n-s)-(t-r)*(n*o-a*s))/l,u=((t*i-e*r)*(a-o)-(e-i)*(n*o-a*s))/l,c=+h.toFixed(2),f=+u.toFixed(2);if(!(c<+k(t,r).toFixed(2)||c>+w(t,r).toFixed(2)||c<+k(n,s).toFixed(2)||c>+w(n,s).toFixed(2)||f<+k(e,i).toFixed(2)||f>+w(e,i).toFixed(2)||f<+k(a,o).toFixed(2)||f>+w(a,o).toFixed(2)))return{x:h,y:u}}}}function xt(t,r,i){var n=e.bezierBBox(t),a=e.bezierBBox(r);if(!e.isBBoxIntersect(n,a))return i?0:[];for(var s=dt.apply(0,t),o=dt.apply(0,r),l=w(~~(s/5),1),h=w(~~(o/5),1),u=[],c=[],f={},p=i?0:[],d=0;d=0&&A<=1.001&&T>=0&&T<=1.001&&(i?p++:p.push({x:S.x,y:S.y,t1:k(A,1),t2:k(T,1)}))}}return p}function vt(t,r,i){t=e._path2curve(t),r=e._path2curve(r);for(var n,a,s,o,l,h,u,c,f,p,d=i?0:[],g=0,x=t.length;gy||v=t.x&&e<=t.x2&&r>=t.y&&r<=t.y2},e.isBBoxIntersect=function(t,r){var i=e.isPointInsideBBox;return i(r,t.x,t.y)||i(r,t.x2,t.y)||i(r,t.x,t.y2)||i(r,t.x2,t.y2)||i(t,r.x,r.y)||i(t,r.x2,r.y)||i(t,r.x,r.y2)||i(t,r.x2,r.y2)||(t.xr.x||r.xt.x)&&(t.yr.y||r.yt.y)},e.pathIntersection=function(t,e){return vt(t,e)},e.pathIntersectionNumber=function(t,e){return vt(t,e,1)},e.isPointInsidePath=function(t,r,i){var n=e.pathBBox(t);return e.isPointInsideBBox(n,r,i)&&vt(t,[["M",r,i],["H",n.x2+10]],1)%2==1},e._removedFactory=function(e){return function(){t("raphael.log",null,"Raphaël: you are calling to method “"+e+"” of removed object",e)}};var yt=e.pathBBox=function(t){var e=ft(t);if(e.bbox)return tt(e.bbox);if(!t)return{x:0,y:0,width:0,height:0,x2:0,y2:0};for(var r,i=0,n=0,a=[],s=[],o=0,l=(t=At(t)).length;o1&&(r*=m=_.sqrt(m),i*=m);var b=r*r,w=i*i,k=(a==s?-1:1)*_.sqrt(B((b*w-b*y*y-w*x*x)/(b*y*y+w*x*x))),C=k*r*y/i+(t+o)/2,A=k*-i*x/r+(e+l)/2,T=_.asin(((e-A)/i).toFixed(9)),M=_.asin(((l-A)/i).toFixed(9));T=tM&&(T-=2*S),!s&&M>T&&(M-=2*S)}var E=M-T;if(B(E)>c){var N=M,L=o,P=l;M=T+c*(s&&M>T?1:-1),o=C+r*_.cos(M),l=A+i*_.sin(M),d=Bt(o,l,r,i,n,0,s,L,P,[M,N,C,A])}E=M-T;var z=_.cos(T),F=_.sin(T),R=_.cos(M),j=_.sin(M),I=_.tan(E/4),D=4/3*r*I,q=4/3*i*I,O=[t,e],V=[t+D*F,e-q*z],Y=[o+D*j,l-q*R],W=[o,l];if(V[0]=2*O[0]-V[0],V[1]=2*O[1]-V[1],h)return[V,Y,W][f](d);for(var G=[],H=0,X=(d=[V,Y,W][f](d).join()[v](",")).length;H"1e12"&&(p=.5),B(d)>"1e12"&&(d=.5),p>0&&p<1&&(l=Ct(t,e,r,i,n,a,s,o,p),x.push(l.x),g.push(l.y)),d>0&&d<1&&(l=Ct(t,e,r,i,n,a,s,o,d),x.push(l.x),g.push(l.y)),h=a-2*i+e-(o-2*a+i),f=e-i,p=(-(u=2*(i-e)-2*(a-i))+_.sqrt(u*u-4*h*f))/2/h,d=(-u-_.sqrt(u*u-4*h*f))/2/h,B(p)>"1e12"&&(p=.5),B(d)>"1e12"&&(d=.5),p>0&&p<1&&(l=Ct(t,e,r,i,n,a,s,o,p),x.push(l.x),g.push(l.y)),d>0&&d<1&&(l=Ct(t,e,r,i,n,a,s,o,d),x.push(l.x),g.push(l.y)),{min:{x:k[c](0,x),y:k[c](0,g)},max:{x:w[c](0,x),y:w[c](0,g)}}}),At=e._path2curve=ht(function(t,e){var r=!e&&ft(t);if(!e&&r.curve)return mt(r.curve);for(var i=_t(t),n=e&&_t(e),a={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},s={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},o=function(t,e,r){var i,n;if(!t)return["C",e.x,e.y,e.x,e.y,e.x,e.y];switch(!(t[0]in{T:1,Q:1})&&(e.qx=e.qy=null),t[0]){case"M":e.X=t[1],e.Y=t[2];break;case"A":t=["C"][f](Bt[c](0,[e.x,e.y][f](t.slice(1))));break;case"S":"C"==r||"S"==r?(i=2*e.x-e.bx,n=2*e.y-e.by):(i=e.x,n=e.y),t=["C",i,n][f](t.slice(1));break;case"T":"Q"==r||"T"==r?(e.qx=2*e.x-e.qx,e.qy=2*e.y-e.qy):(e.qx=e.x,e.qy=e.y),t=["C"][f](kt(e.x,e.y,e.qx,e.qy,t[1],t[2]));break;case"Q":e.qx=t[1],e.qy=t[2],t=["C"][f](kt(e.x,e.y,t[1],t[2],t[3],t[4]));break;case"L":t=["C"][f](wt(e.x,e.y,t[1],t[2]));break;case"H":t=["C"][f](wt(e.x,e.y,t[1],e.y));break;case"V":t=["C"][f](wt(e.x,e.y,e.x,t[1]));break;case"Z":t=["C"][f](wt(e.x,e.y,e.X,e.Y))}return t},l=function(t,e){if(t[e].length>7){t[e].shift();for(var r=t[e];r.length;)u[e]="A",n&&(p[e]="A"),t.splice(e++,0,["C"][f](r.splice(0,6)));t.splice(e,1),v=w(i.length,n&&n.length||0)}},h=function(t,e,r,a,s){t&&e&&"M"==t[s][0]&&"M"!=e[s][0]&&(e.splice(s,0,["M",a.x,a.y]),r.bx=0,r.by=0,r.x=t[s][1],r.y=t[s][2],v=w(i.length,n&&n.length||0))},u=[],p=[],d="",g="",x=0,v=w(i.length,n&&n.length||0);x.01;)u/=2,h=dt(t,e,r,i,n,a,s,o,c+=(hn){if(r&&!f.start){if(c+=["C"+(u=Xt(s,o,l[1],l[2],l[3],l[4],l[5],l[6],n-p)).start.x,u.start.y,u.m.x,u.m.y,u.x,u.y],a)return c;f.start=c,c=["M"+u.x,u.y+"C"+u.n.x,u.n.y,u.end.x,u.end.y,l[5],l[6]].join(),p+=h,s=+l[5],o=+l[6];continue}if(!t&&!r)return{x:(u=Xt(s,o,l[1],l[2],l[3],l[4],l[5],l[6],n-p)).x,y:u.y,alpha:u.alpha}}p+=h,s=+l[5],o=+l[6]}c+=l.shift()+l}return f.end=c,(u=t?p:r?f:e.findDotsAtSegment(s,o,l[0],l[1],l[2],l[3],l[4],l[5],1)).alpha&&(u={x:u.x,y:u.y,alpha:u.alpha}),u}},$t=Ut(1),Zt=Ut(),Qt=Ut(0,1);e.getTotalLength=$t,e.getPointAtLength=Zt,e.getSubpath=function(t,e,r){if(this.getTotalLength(t)-r<1e-6)return Qt(t,e).end;var i=Qt(t,r,1);return e?Qt(i,e).end:i},Yt.getTotalLength=function(){var t=this.getPath();if(t)return this.node.getTotalLength?this.node.getTotalLength():$t(t)},Yt.getPointAtLength=function(t){var e=this.getPath();if(e)return Zt(e,t)},Yt.getPath=function(){var t,r=e._getPath[this.type];if("text"!=this.type&&"set"!=this.type)return r&&(t=r(this)),t},Yt.getSubpath=function(t,r){var i=this.getPath();if(i)return e.getSubpath(i,t,r)};var Jt=e.easing_formulas={linear:function(t){return t},"<":function(t){return C(t,1.7)},">":function(t){return C(t,.48)},"<>":function(t){var e=.48-t/1.04,r=_.sqrt(.1734+e*e),i=r-e,n=-r-e,a=C(B(i),1/3)*(i<0?-1:1)+C(B(n),1/3)*(n<0?-1:1)+.5;return 3*(1-a)*a*a+a*a*a},backIn:function(t){var e=1.70158;return t*t*((e+1)*t-e)},backOut:function(t){var e=1.70158;return(t-=1)*t*((e+1)*t+e)+1},elastic:function(t){return t==!!t?t:C(2,-10*t)*_.sin(2*S*(t-.075)/.3)+1},bounce:function(t){var e=7.5625,r=2.75;return t<1/r?e*t*t:t<2/r?e*(t-=1.5/r)*t+.75:t<2.5/r?e*(t-=2.25/r)*t+.9375:e*(t-=2.625/r)*t+.984375}};Jt.easeIn=Jt["ease-in"]=Jt["<"],Jt.easeOut=Jt["ease-out"]=Jt[">"],Jt.easeInOut=Jt["ease-in-out"]=Jt["<>"],Jt["back-in"]=Jt.backIn,Jt["back-out"]=Jt.backOut;var Kt=[],te=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){setTimeout(t,16)},ee=function(){for(var r=+new Date,i=0;i1&&!n.next){for(s in d)d[o](s)&&(y[s]=n.totalOrigin[s]);n.el.attr(y),ae(n.anim,n.el,n.anim.percents[0],null,n.totalOrigin,n.repeat-1)}n.next&&!n.stop&&ae(n.anim,n.el,n.next,null,n.totalOrigin,n.repeat)}}}Kt.length&&te(ee)},re=function(t){return t>255?255:t<0?0:t};function ie(t,e,r,i,n,a){var s=3*e,o=3*(i-e)-s,l=1-s-o,h=3*r,u=3*(n-r)-h,c=1-h-u;function f(t){return((l*t+o)*t+s)*t}return function(t,e){var r=function(t,e){var r,i,n,a,h,u;for(n=t,u=0;u<8;u++){if(a=f(n)-t,B(a)i)return i;for(;ra?r=n:i=n,n=(i-r)/2+r}return n}(t,e);return((c*r+u)*r+h)*r}(t,1/(200*a))}function ne(t,e){var r=[],i={};if(this.ms=e,this.times=1,t){for(var n in t)t[o](n)&&(i[z(n)]=t[n],r.push(z(n)));r.sort(H)}this.anim=i,this.top=r[r.length-1],this.percents=r}function ae(r,i,a,s,l,h){a=z(a);var u,c,p,d,g,y,m=r.ms,b={},_={},w={};if(s)for(B=0,C=Kt.length;Bs*r.top){a=r.percents[B],g=r.percents[B-1]||0,m=m/r.top*(a-g),d=r.percents[B+1],u=r.anim[a];break}s&&i.attr(r.anim[r.percents[B]])}if(u){if(c)c.initstatus=s,c.start=new Date-c.ms*s;else{for(var S in u)if(u[o](S)&&(I[o](S)||i.paper.customAttributes[o](S)))switch(b[S]=i.attr(S),null==b[S]&&(b[S]=j[S]),_[S]=u[S],I[S]){case A:w[S]=(_[S]-b[S])/m;break;case"colour":b[S]=e.getRGB(b[S]);var T=e.getRGB(_[S]);w[S]={r:(T.r-b[S].r)/m,g:(T.g-b[S].g)/m,b:(T.b-b[S].b)/m};break;case"path":var M=At(b[S],_[S]),E=M[1];for(b[S]=M[0],w[S]=[],B=0,C=b[S].length;Bh&&(h=c)}!t[h+="%"].callback&&(t[h].callback=n)}return new ne(t,r)},Yt.animate=function(t,r,i,n){if(this.removed)return n&&n.call(this),this;var a=t instanceof ne?t:e.animation(t,r,i,n);return ae(a,this,a.percents[0],null,this.attr()),this},Yt.setTime=function(t,e){return t&&null!=e&&this.status(t,k(e,t.ms)/t.ms),this},Yt.status=function(t,e){var r,i,n=[],a=0;if(null!=e)return ae(t,this,-1,k(e,1)),this;for(r=Kt.length;a"));var U=H.getBoundingClientRect();A.W=g.w=(U.right-U.left)/100,A.H=g.h=(U.bottom-U.top)/100,A.X=g.x,A.Y=g.y+A.H/2,("x"in l||"y"in l)&&(A.path.v=t.format("m{0},{1}l{2},{1}",a(g.x*y),a(g.y*y),a(g.x*y)+1));for(var $=["x","y","text","font","font-family","font-weight","font-style","font-size"],Z=0,Q=$.length;Z.25&&(r=n.sqrt(.25-o(e-.5,2))*(2*(r>.5)-1)+.5),h=e+c+r),f})).split(/\s*\-\s*/),"linear"==l){var u=a.shift();if(u=-i(u),isNaN(u))return null}var p=t._parseDots(a);if(!p)return null;if(e=e.shape||e.node,p.length){e.removeChild(s),s.on=!0,s.method="none",s.color=p[0].color,s.color2=p[p.length-1].color;for(var d=[],g=0,x=p.length;g')}}catch(t){k=function(t){return e.createElement("<"+t+' xmlns="urn:schemas-microsoft.com:vml" class="rvml">')}}},t._engine.initWin(t._g.win),t._engine.create=function(){var e=t._getContainer.apply(0,arguments),r=e.container,i=e.height,n=e.width,a=e.x,s=e.y;if(!r)throw new Error("VML container not found.");var o=new t._Paper,l=o.canvas=t._g.doc.createElement("div"),h=l.style;return a=a||0,s=s||0,n=n||512,i=i||342,o.width=n,o.height=i,n==+n&&(n+="px"),i==+i&&(i+="px"),o.coordsize=216e5+c+216e5,o.coordorigin="0 0",o.span=t._g.doc.createElement("span"),o.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;",l.appendChild(o.span),h.cssText=t.format("top:0;left:0;width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden",n,i),1==r?(t._g.doc.body.appendChild(l),h.left=a+"px",h.top=s+"px",h.position="absolute"):r.firstChild?r.insertBefore(l,r.firstChild):r.appendChild(l),o.renderfix=function(){},o},t.prototype.clear=function(){t.eve("raphael.clear",this),this.canvas.innerHTML=f,this.span=t._g.doc.createElement("span"),this.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;",this.canvas.appendChild(this.span),this.bottom=this.top=null},t.prototype.remove=function(){for(var e in t.eve("raphael.remove",this),this.canvas.parentNode.removeChild(this.canvas),this)this[e]="function"==typeof this[e]?t._removedFactory(e):null;return!0};var M=t.st;for(var E in T)T[e](E)&&!M[e](E)&&(M[E]=function(t){return function(){var e=arguments;return this.forEach(function(r){r[t].apply(r,e)})}}(E))}}.apply(e,i))||(t.exports=n)},function(t,e,r){var i,n;i=[r(0)],void 0===(n=function(t){if(!t||t.svg){var e="hasOwnProperty",r=String,i=parseFloat,n=parseInt,a=Math,s=a.max,o=a.abs,l=a.pow,h=/[, ]+/,u=t.eve,c="",f=" ",p="http://www.w3.org/1999/xlink",d={block:"M5,0 0,2.5 5,5z",classic:"M5,0 0,2.5 5,5 3.5,3 3.5,2z",diamond:"M2.5,0 5,2.5 2.5,5 0,2.5z",open:"M6,1 1,3.5 6,6",oval:"M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"},g={};t.toString=function(){return"Your browser supports SVG.\nYou are running Raphaël "+this.version};var x=function(i,n){if(n)for(var a in"string"==typeof i&&(i=x(i)),n)n[e](a)&&("xlink:"==a.substring(0,6)?i.setAttributeNS(p,a.substring(6),r(n[a])):i.setAttribute(a,r(n[a])));else(i=t._g.doc.createElementNS("http://www.w3.org/2000/svg",i)).style&&(i.style.webkitTapHighlightColor="rgba(0,0,0,0)");return i},v=function(e,n){var h="linear",u=e.id+n,f=.5,p=.5,d=e.node,g=e.paper,v=d.style,m=t._g.doc.getElementById(u);if(!m){if(n=(n=r(n).replace(t._radial_gradient,function(t,e,r){if(h="radial",e&&r){f=i(e);var n=2*((p=i(r))>.5)-1;l(f-.5,2)+l(p-.5,2)>.25&&(p=a.sqrt(.25-l(f-.5,2))*n+.5)&&.5!=p&&(p=p.toFixed(5)-1e-5*n)}return c})).split(/\s*\-\s*/),"linear"==h){var b=n.shift();if(b=-i(b),isNaN(b))return null;var _=[0,0,a.cos(t.rad(b)),a.sin(t.rad(b))],w=1/(s(o(_[2]),o(_[3]))||1);_[2]*=w,_[3]*=w,_[2]<0&&(_[0]=-_[2],_[2]=0),_[3]<0&&(_[1]=-_[3],_[3]=0)}var k=t._parseDots(n);if(!k)return null;if(u=u.replace(/[\(\)\s,\xb0#]/g,"_"),e.gradient&&u!=e.gradient.id&&(g.defs.removeChild(e.gradient),delete e.gradient),!e.gradient){m=x(h+"Gradient",{id:u}),e.gradient=m,x(m,"radial"==h?{fx:f,fy:p}:{x1:_[0],y1:_[1],x2:_[2],y2:_[3],gradientTransform:e.matrix.invert()}),g.defs.appendChild(m);for(var B=0,C=k.length;B1?P.opacity/100:P.opacity});case"stroke":P=t.getRGB(g),l.setAttribute(d,P.hex),"stroke"==d&&P[e]("opacity")&&x(l,{"stroke-opacity":P.opacity>1?P.opacity/100:P.opacity}),"stroke"==d&&i._.arrows&&("startString"in i._.arrows&&b(i,i._.arrows.startString),"endString"in i._.arrows&&b(i,i._.arrows.endString,1));break;case"gradient":("circle"==i.type||"ellipse"==i.type||"r"!=r(g).charAt())&&v(i,g);break;case"opacity":u.gradient&&!u[e]("stroke-opacity")&&x(l,{"stroke-opacity":g>1?g/100:g});case"fill-opacity":if(u.gradient){(z=t._g.doc.getElementById(l.getAttribute("fill").replace(/^url\(#|\)$/g,c)))&&(F=z.getElementsByTagName("stop"),x(F[F.length-1],{"stop-opacity":g}));break}default:"font-size"==d&&(g=n(g,10)+"px");var R=d.replace(/(\-.)/g,function(t){return t.substring(1).toUpperCase()});l.style[R]=g,i._.dirty=1,l.setAttribute(d,g)}}B(i,a),l.style.visibility=f},B=function(i,a){if("text"==i.type&&(a[e]("text")||a[e]("font")||a[e]("font-size")||a[e]("x")||a[e]("y"))){var s=i.attrs,o=i.node,l=o.firstChild?n(t._g.doc.defaultView.getComputedStyle(o.firstChild,c).getPropertyValue("font-size"),10):10;if(a[e]("text")){for(s.text=a.text;o.firstChild;)o.removeChild(o.firstChild);for(var h,u=r(a.text).split("\n"),f=[],p=0,d=u.length;p1)for(var i=0,n=r.length;i ',(J=K.firstChild).style.behavior="url(#default#VML)",!J||typeof J.adj!="object")return e.type=d;K=null}function tt(t){if(typeof t=="function"||Object(t)!==t)return t;var e=new t.constructor;for(var r in t)t[o](r)&&(e[r]=tt(t[r]));return e}e.svg=!(e.vml=e.type=="VML"),e._Paper=u,e.fn=i=u.prototype=e.prototype,e._id=0,e.is=function(t,e){return(e=b.call(e))=="finite"?!N[o](+t):e=="array"?t instanceof Array:e=="null"&&t===null||e==typeof t&&t!==null||e=="object"&&t===Object(t)||e=="array"&&Array.isArray&&Array.isArray(t)||M.call(t).slice(8,-1).toLowerCase()==e},e.angle=function(t,r,i,n,a,s){if(a==null){var o=t-i,l=r-n;return o||l?(180+180*_.atan2(-l,-o)/S+360)%360:0}return e.angle(t,r,a,s)-e.angle(i,n,a,s)},e.rad=function(t){return t%360*S/180},e.deg=function(t){return Math.round(180*t/S%360*1e3)/1e3},e.snapTo=function(t,r,i){if(i=e.is(i,"finite")?i:10,e.is(t,T)){for(var n=t.length;n--;)if(B(t[n]-r)<=i)return t[n]}else{var a=r%(t=+t);if(at-i)return r-a+t}return r};var et,rt;e.createUUID=(et=/[xy]/g,rt=function(t){var e=16*_.random()|0;return(t=="x"?e:3&e|8).toString(16)},function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(et,rt).toUpperCase()});e.setWindow=function(r){t("raphael.setWindow",e,l.win,r),l.win=r,l.doc=l.win.document,e._engine.initWin&&e._engine.initWin(l.win)};var it=function(t){if(e.vml){var r,i=/^\s+|\s+$/g;try{var n=new ActiveXObject("htmlfile");n.write(""),n.close(),r=n.body}catch(t){r=createPopup().document.body}var a=r.createTextRange();it=ht(function(t){try{r.style.color=x(t).replace(i,d);var e=a.queryCommandValue("ForeColor");return"#"+("000000"+(e=(255&e)<<16|65280&e|(16711680&e)>>>16).toString(16)).slice(-6)}catch(t){return"none"}})}else{var s=l.doc.createElement("i");s.title="Raphaël Colour Picker",s.style.display="none",l.doc.body.appendChild(s),it=ht(function(t){return s.style.color=t,l.doc.defaultView.getComputedStyle(s,d).getPropertyValue("color")})}return it(t)},nt=function(){return"hsb("+[this.h,this.s,this.b]+")"},at=function(){return"hsl("+[this.h,this.s,this.l]+")"},st=function(){return this.hex},ot=function(t,r,i){if(r==null&&e.is(t,"object")&&"r"in t&&"g"in t&&"b"in t&&(i=t.b,r=t.g,t=t.r),r==null&&e.is(t,"string")){var n=e.getRGB(t);t=n.r,r=n.g,i=n.b}return(t>1||r>1||i>1)&&(t/=255,r/=255,i/=255),[t,r,i]},lt=function(t,r,i,n){var a={r:t*=255,g:r*=255,b:i*=255,hex:e.rgb(t,r,i),toString:st};return e.is(n,"finite")&&(a.opacity=n),a};function ht(t,e,r){return function i(){var n=Array.prototype.slice.call(arguments,0),a=n.join("␀"),s=i.cache=i.cache||{},l=i.count=i.count||[];return s[o](a)?((function(t,e){for(var r=0,i=t.length;r=1e3&&delete s[l.shift()],l.push(a),s[a]=t[c](e,n),r?r(s[a]):s[a])}}e.color=function(t){var r;return e.is(t,"object")&&"h"in t&&"s"in t&&"b"in t?(r=e.hsb2rgb(t),t.r=r.r,t.g=r.g,t.b=r.b,t.hex=r.hex):e.is(t,"object")&&"h"in t&&"s"in t&&"l"in t?(r=e.hsl2rgb(t),t.r=r.r,t.g=r.g,t.b=r.b,t.hex=r.hex):(e.is(t,"string")&&(t=e.getRGB(t)),e.is(t,"object")&&"r"in t&&"g"in t&&"b"in t?(r=e.rgb2hsl(t),t.h=r.h,t.s=r.s,t.l=r.l,r=e.rgb2hsb(t),t.v=r.b):(t={hex:"none"}).r=t.g=t.b=t.h=t.s=t.v=t.l=-1),t.toString=st,t},e.hsb2rgb=function(t,e,r,i){var n,a,s,o,l;return this.is(t,"object")&&"h"in t&&"s"in t&&"b"in t&&(r=t.b,e=t.s,i=t.o,t=t.h),o=(l=r*e)*(1-B((t=(t*=360)%360/60)%2-1)),n=a=s=r-l,lt(n+=[l,o,0,0,o,l][t=~~t],a+=[o,l,l,o,0,0][t],s+=[0,0,o,l,l,o][t],i)},e.hsl2rgb=function(t,e,r,i){var n,a,s,o,l;return this.is(t,"object")&&"h"in t&&"s"in t&&"l"in t&&(r=t.l,e=t.s,t=t.h),(t>1||e>1||r>1)&&(t/=360,e/=100,r/=100),t=(t*=360)%360/60,o=(l=2*e*(r<.5?r:1-r))*(1-B(t%2-1)),n=a=s=r-l/2,lt(n+=[l,o,0,0,o,l][t=~~t],a+=[o,l,l,o,0,0][t],s+=[0,0,o,l,l,o][t],i)},e.rgb2hsb=function(t,e,r){var i,n;return t=(r=ot(t,e,r))[0],e=r[1],r=r[2],{h:(((n=(i=w(t,e,r))-k(t,e,r))==0?null:i==t?(e-r)/n:i==e?(r-t)/n+2:(t-e)/n+4)+360)%6*60/360,s:n==0?0:n/i,b:i,toString:nt}},e.rgb2hsl=function(t,e,r){var i,n,a,s;return t=(r=ot(t,e,r))[0],e=r[1],r=r[2],i=((n=w(t,e,r))+(a=k(t,e,r)))/2,{h:(((s=n-a)==0?null:n==t?(e-r)/s:n==e?(r-t)/s+2:(t-e)/s+4)+360)%6*60/360,s:s==0?0:i<.5?s/(2*i):s/(2-2*i),l:i,toString:at}},e._path2string=function(){return this.join(",").replace(O,"$1")};e._preload=function(t,e){var r=l.doc.createElement("img");r.style.cssText="position:absolute;left:-9999em;top:-9999em",r.onload=function(){e.call(this),this.onload=null,l.doc.body.removeChild(this)},r.onerror=function(){l.doc.body.removeChild(this)},l.doc.body.appendChild(r),r.src=t};function ut(){return this.hex}function ct(t,e){for(var r=[],i=0,n=t.length;n-2*!e>i;i+=2){var a=[{x:+t[i-2],y:+t[i-1]},{x:+t[i],y:+t[i+1]},{x:+t[i+2],y:+t[i+3]},{x:+t[i+4],y:+t[i+5]}];e?i?n-4==i?a[3]={x:+t[0],y:+t[1]}:n-2==i&&(a[2]={x:+t[0],y:+t[1]},a[3]={x:+t[2],y:+t[3]}):a[0]={x:+t[n-2],y:+t[n-1]}:n-4==i?a[3]=a[2]:i||(a[0]={x:+t[i],y:+t[i+1]}),r.push(["C",(-a[0].x+6*a[1].x+a[2].x)/6,(-a[0].y+6*a[1].y+a[2].y)/6,(a[1].x+6*a[2].x-a[3].x)/6,(a[1].y+6*a[2].y-a[3].y)/6,a[2].x,a[2].y])}return r}e.getRGB=ht(function(t){if(!t||(t=x(t)).indexOf("-")+1)return{r:-1,g:-1,b:-1,hex:"none",error:1,toString:ut};if(t=="none")return{r:-1,g:-1,b:-1,hex:"none",toString:ut};!q[o](t.toLowerCase().substring(0,2))&&t.charAt()!="#"&&(t=it(t));var r,i,n,a,s,l,h=t.match(E);return h?(h[2]&&(n=F(h[2].substring(5),16),i=F(h[2].substring(3,5),16),r=F(h[2].substring(1,3),16)),h[3]&&(n=F((s=h[3].charAt(3))+s,16),i=F((s=h[3].charAt(2))+s,16),r=F((s=h[3].charAt(1))+s,16)),h[4]&&(l=h[4][v](D),r=z(l[0]),l[0].slice(-1)=="%"&&(r*=2.55),i=z(l[1]),l[1].slice(-1)=="%"&&(i*=2.55),n=z(l[2]),l[2].slice(-1)=="%"&&(n*=2.55),h[1].toLowerCase().slice(0,4)=="rgba"&&(a=z(l[3])),l[3]&&l[3].slice(-1)=="%"&&(a/=100)),h[5]?(l=h[5][v](D),r=z(l[0]),l[0].slice(-1)=="%"&&(r*=2.55),i=z(l[1]),l[1].slice(-1)=="%"&&(i*=2.55),n=z(l[2]),l[2].slice(-1)=="%"&&(n*=2.55),(l[0].slice(-3)=="deg"||l[0].slice(-1)=="°")&&(r/=360),h[1].toLowerCase().slice(0,4)=="hsba"&&(a=z(l[3])),l[3]&&l[3].slice(-1)=="%"&&(a/=100),e.hsb2rgb(r,i,n,a)):h[6]?(l=h[6][v](D),r=z(l[0]),l[0].slice(-1)=="%"&&(r*=2.55),i=z(l[1]),l[1].slice(-1)=="%"&&(i*=2.55),n=z(l[2]),l[2].slice(-1)=="%"&&(n*=2.55),(l[0].slice(-3)=="deg"||l[0].slice(-1)=="°")&&(r/=360),h[1].toLowerCase().slice(0,4)=="hsla"&&(a=z(l[3])),l[3]&&l[3].slice(-1)=="%"&&(a/=100),e.hsl2rgb(r,i,n,a)):((h={r:r,g:i,b:n,toString:ut}).hex="#"+(16777216|n|i<<8|r<<16).toString(16).slice(1),e.is(a,"finite")&&(h.opacity=a),h)):{r:-1,g:-1,b:-1,hex:"none",error:1,toString:ut}},e),e.hsb=ht(function(t,r,i){return e.hsb2rgb(t,r,i).hex}),e.hsl=ht(function(t,r,i){return e.hsl2rgb(t,r,i).hex}),e.rgb=ht(function(t,e,r){function i(t){return t+.5|0}return"#"+(16777216|i(r)|i(e)<<8|i(t)<<16).toString(16).slice(1)}),e.getColor=function(t){var e=this.getColor.start=this.getColor.start||{h:0,s:1,b:t||.75},r=this.hsb2rgb(e.h,e.s,e.b);return e.h+=.075,e.h>1&&(e.h=0,e.s-=.2,e.s<=0&&(this.getColor.start={h:0,s:1,b:e.b})),r.hex},e.getColor.reset=function(){delete this.start},e.parsePathString=function(t){if(!t)return null;var r=ft(t);if(r.arr)return mt(r.arr);var i={a:7,c:6,h:1,l:2,m:2,r:4,q:4,s:4,t:2,v:1,z:0},n=[];return e.is(t,T)&&e.is(t[0],T)&&(n=mt(t)),n.length||x(t).replace(V,function(t,e,r){var a=[],s=e.toLowerCase();if(r.replace(W,function(t,e){e&&a.push(+e)}),s=="m"&&a.length>2&&(n.push([e][f](a.splice(0,2))),s="l",e=e=="m"?"l":"L"),s=="r")n.push([e][f](a));else for(;a.length>=i[s]&&(n.push([e][f](a.splice(0,i[s]))),i[s]););}),n.toString=e._path2string,r.arr=mt(n),n},e.parseTransformString=ht(function(t){if(!t)return null;var r=[];return e.is(t,T)&&e.is(t[0],T)&&(r=mt(t)),r.length||x(t).replace(Y,function(t,e,i){var n=[];b.call(e);i.replace(W,function(t,e){e&&n.push(+e)}),r.push([e][f](n))}),r.toString=e._path2string,r});var ft=function(t){var e=ft.ps=ft.ps||{};return e[t]?e[t].sleep=100:e[t]={sleep:100},setTimeout(function(){for(var r in e)e[o](r)&&r!=t&&(e[r].sleep--,!e[r].sleep&&delete e[r])}),e[t]};function pt(t,e,r,i,n){return t*(t*(-3*e+9*r-9*i+3*n)+6*e-12*r+6*i)-3*e+3*r}function dt(t,e,r,i,n,a,s,o,l){l==null&&(l=1);for(var h=(l=l>1?1:l<0?0:l)/2,u=[-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816],c=[.2491,.2491,.2335,.2335,.2032,.2032,.1601,.1601,.1069,.1069,.0472,.0472],f=0,p=0;p<12;p++){var d=h*u[p]+h,g=pt(d,t,r,n,s),x=pt(d,e,i,a,o),v=g*g+x*x;f+=c[p]*_.sqrt(v)}return h*f}function gt(t,e,r,i,n,a,s,o){if(!(w(t,r)w(n,s)||w(e,i)w(a,o))){var l=(t-r)*(a-o)-(e-i)*(n-s);if(l){var h=((t*i-e*r)*(n-s)-(t-r)*(n*o-a*s))/l,u=((t*i-e*r)*(a-o)-(e-i)*(n*o-a*s))/l,c=+h.toFixed(2),f=+u.toFixed(2);if(!(c<+k(t,r).toFixed(2)||c>+w(t,r).toFixed(2)||c<+k(n,s).toFixed(2)||c>+w(n,s).toFixed(2)||f<+k(e,i).toFixed(2)||f>+w(e,i).toFixed(2)||f<+k(a,o).toFixed(2)||f>+w(a,o).toFixed(2)))return{x:h,y:u}}}}function xt(t,r,i){var n=e.bezierBBox(t),a=e.bezierBBox(r);if(!e.isBBoxIntersect(n,a))return i?0:[];for(var s=dt.apply(0,t),o=dt.apply(0,r),l=w(~~(s/5),1),h=w(~~(o/5),1),u=[],c=[],f={},p=i?0:[],d=0;d=0&&A<=1.001&&T>=0&&T<=1.001&&(i?p++:p.push({x:S.x,y:S.y,t1:k(A,1),t2:k(T,1)}))}}return p}function vt(t,r,i){t=e._path2curve(t),r=e._path2curve(r);for(var n,a,s,o,l,h,u,c,f,p,d=i?0:[],g=0,x=t.length;gy||v=t.x&&e<=t.x2&&r>=t.y&&r<=t.y2},e.isBBoxIntersect=function(t,r){var i=e.isPointInsideBBox;return i(r,t.x,t.y)||i(r,t.x2,t.y)||i(r,t.x,t.y2)||i(r,t.x2,t.y2)||i(t,r.x,r.y)||i(t,r.x2,r.y)||i(t,r.x,r.y2)||i(t,r.x2,r.y2)||(t.xr.x||r.xt.x)&&(t.yr.y||r.yt.y)},e.pathIntersection=function(t,e){return vt(t,e)},e.pathIntersectionNumber=function(t,e){return vt(t,e,1)},e.isPointInsidePath=function(t,r,i){var n=e.pathBBox(t);return e.isPointInsideBBox(n,r,i)&&vt(t,[["M",r,i],["H",n.x2+10]],1)%2==1},e._removedFactory=function(e){return function(){t("raphael.log",null,"Raphaël: you are calling to method “"+e+"” of removed object",e)}};var yt=e.pathBBox=function(t){var e=ft(t);if(e.bbox)return tt(e.bbox);if(!t)return{x:0,y:0,width:0,height:0,x2:0,y2:0};for(var r,i=0,n=0,a=[],s=[],o=0,l=(t=At(t)).length;o1&&(r*=m=_.sqrt(m),i*=m);var b=r*r,w=i*i,k=(a==s?-1:1)*_.sqrt(B((b*w-b*y*y-w*x*x)/(b*y*y+w*x*x))),C=k*r*y/i+(t+o)/2,A=k*-i*x/r+(e+l)/2,T=_.asin(((e-A)/i).toFixed(9)),M=_.asin(((l-A)/i).toFixed(9));T=tM&&(T-=2*S),!s&&M>T&&(M-=2*S)}var E=M-T;if(B(E)>c){var N=M,L=o,P=l;M=T+c*(s&&M>T?1:-1),o=C+r*_.cos(M),l=A+i*_.sin(M),d=Bt(o,l,r,i,n,0,s,L,P,[M,N,C,A])}E=M-T;var z=_.cos(T),F=_.sin(T),R=_.cos(M),j=_.sin(M),I=_.tan(E/4),D=4/3*r*I,q=4/3*i*I,O=[t,e],V=[t+D*F,e-q*z],Y=[o+D*j,l-q*R],W=[o,l];if(V[0]=2*O[0]-V[0],V[1]=2*O[1]-V[1],h)return[V,Y,W][f](d);for(var G=[],H=0,X=(d=[V,Y,W][f](d).join()[v](",")).length;H"1e12"&&(p=.5),B(d)>"1e12"&&(d=.5),p>0&&p<1&&(l=Ct(t,e,r,i,n,a,s,o,p),x.push(l.x),g.push(l.y)),d>0&&d<1&&(l=Ct(t,e,r,i,n,a,s,o,d),x.push(l.x),g.push(l.y)),h=a-2*i+e-(o-2*a+i),f=e-i,p=(-(u=2*(i-e)-2*(a-i))+_.sqrt(u*u-4*h*f))/2/h,d=(-u-_.sqrt(u*u-4*h*f))/2/h,B(p)>"1e12"&&(p=.5),B(d)>"1e12"&&(d=.5),p>0&&p<1&&(l=Ct(t,e,r,i,n,a,s,o,p),x.push(l.x),g.push(l.y)),d>0&&d<1&&(l=Ct(t,e,r,i,n,a,s,o,d),x.push(l.x),g.push(l.y)),{min:{x:k[c](0,x),y:k[c](0,g)},max:{x:w[c](0,x),y:w[c](0,g)}}}),At=e._path2curve=ht(function(t,e){var r=!e&&ft(t);if(!e&&r.curve)return mt(r.curve);for(var i=_t(t),n=e&&_t(e),a={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},s={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},o=function(t,e,r){var i,n;if(!t)return["C",e.x,e.y,e.x,e.y,e.x,e.y];switch(!(t[0]in{T:1,Q:1})&&(e.qx=e.qy=null),t[0]){case"M": e.X=t[1],e.Y=t[2];break;case"A": t=["C"][f](Bt[c](0,[e.x,e.y][f](t.slice(1))));break;case"S": r=="C"||r=="S"?(i=2*e.x-e.bx,n=2*e.y-e.by):(i=e.x,n=e.y),t=["C",i,n][f](t.slice(1));break;case"T": r=="Q"||r=="T"?(e.qx=2*e.x-e.qx,e.qy=2*e.y-e.qy):(e.qx=e.x,e.qy=e.y),t=["C"][f](kt(e.x,e.y,e.qx,e.qy,t[1],t[2]));break;case"Q": e.qx=t[1],e.qy=t[2],t=["C"][f](kt(e.x,e.y,t[1],t[2],t[3],t[4]));break;case"L": t=["C"][f](wt(e.x,e.y,t[1],t[2]));break;case"H": t=["C"][f](wt(e.x,e.y,t[1],e.y));break;case"V": t=["C"][f](wt(e.x,e.y,e.x,t[1]));break;case"Z": t=["C"][f](wt(e.x,e.y,e.X,e.Y))}return t},l=function(t,e){if(t[e].length>7){t[e].shift();for(var r=t[e];r.length;)u[e]="A",n&&(p[e]="A"),t.splice(e++,0,["C"][f](r.splice(0,6)));t.splice(e,1),v=w(i.length,n&&n.length||0)}},h=function(t,e,r,a,s){t&&e&&t[s][0]=="M"&&e[s][0]!="M"&&(e.splice(s,0,["M",a.x,a.y]),r.bx=0,r.by=0,r.x=t[s][1],r.y=t[s][2],v=w(i.length,n&&n.length||0))},u=[],p=[],d="",g="",x=0,v=w(i.length,n&&n.length||0);x.01;)u/=2,h=dt(t,e,r,i,n,a,s,o,c+=(hn){if(r&&!f.start){if(c+=["C"+(u=Xt(s,o,l[1],l[2],l[3],l[4],l[5],l[6],n-p)).start.x,u.start.y,u.m.x,u.m.y,u.x,u.y],a)return c;f.start=c,c=["M"+u.x,u.y+"C"+u.n.x,u.n.y,u.end.x,u.end.y,l[5],l[6]].join(),p+=h,s=+l[5],o=+l[6];continue}if(!t&&!r)return{x:(u=Xt(s,o,l[1],l[2],l[3],l[4],l[5],l[6],n-p)).x,y:u.y,alpha:u.alpha}}p+=h,s=+l[5],o=+l[6]}c+=l.shift()+l}return f.end=c,(u=t?p:r?f:e.findDotsAtSegment(s,o,l[0],l[1],l[2],l[3],l[4],l[5],1)).alpha&&(u={x:u.x,y:u.y,alpha:u.alpha}),u}},$t=Ut(1),Zt=Ut(),Qt=Ut(0,1);e.getTotalLength=$t,e.getPointAtLength=Zt,e.getSubpath=function(t,e,r){if(this.getTotalLength(t)-r<1e-6)return Qt(t,e).end;var i=Qt(t,r,1);return e?Qt(i,e).end:i},Yt.getTotalLength=function(){var t=this.getPath();if(t)return this.node.getTotalLength?this.node.getTotalLength():$t(t)},Yt.getPointAtLength=function(t){var e=this.getPath();if(e)return Zt(e,t)},Yt.getPath=function(){var t,r=e._getPath[this.type];if(this.type!="text"&&this.type!="set")return r&&(t=r(this)),t},Yt.getSubpath=function(t,r){var i=this.getPath();if(i)return e.getSubpath(i,t,r)};var Jt=e.easing_formulas={linear:function(t){return t},"<":function(t){return C(t,1.7)},">":function(t){return C(t,.48)},"<>":function(t){var e=.48-t/1.04,r=_.sqrt(.1734+e*e),i=r-e,n=-r-e,a=C(B(i),1/3)*(i<0?-1:1)+C(B(n),1/3)*(n<0?-1:1)+.5;return 3*(1-a)*a*a+a*a*a},backIn:function(t){var e=1.70158;return t*t*((e+1)*t-e)},backOut:function(t){var e=1.70158;return(t-=1)*t*((e+1)*t+e)+1},elastic:function(t){return t==!!t?t:C(2,-10*t)*_.sin(2*S*(t-.075)/.3)+1},bounce:function(t){var e=7.5625,r=2.75;return t<1/r?e*t*t:t<2/r?e*(t-=1.5/r)*t+.75:t<2.5/r?e*(t-=2.25/r)*t+.9375:e*(t-=2.625/r)*t+.984375}};Jt.easeIn=Jt["ease-in"]=Jt["<"],Jt.easeOut=Jt["ease-out"]=Jt[">"],Jt.easeInOut=Jt["ease-in-out"]=Jt["<>"],Jt["back-in"]=Jt.backIn,Jt["back-out"]=Jt.backOut;var Kt=[],te=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){setTimeout(t,16)},ee=function(){for(var r=+new Date,i=0;i1&&!n.next){for(s in d)d[o](s)&&(y[s]=n.totalOrigin[s]);n.el.attr(y),ae(n.anim,n.el,n.anim.percents[0],null,n.totalOrigin,n.repeat-1)}n.next&&!n.stop&&ae(n.anim,n.el,n.next,null,n.totalOrigin,n.repeat)}}}Kt.length&&te(ee)},re=function(t){return t>255?255:t<0?0:t};function ie(t,e,r,i,n,a){var s=3*e,o=3*(i-e)-s,l=1-s-o,h=3*r,u=3*(n-r)-h,c=1-h-u;function f(t){return((l*t+o)*t+s)*t}return (function(t,e){var r=(function(t,e){var r,i,n,a,h,u;for(n=t,u=0;u<8;u++){if(a=f(n)-t,B(a)i)return i;for(;ra?r=n:i=n,n=(i-r)/2+r}return n}(t,e));return((c*r+u)*r+h)*r}(t,1/(200*a)))}function ne(t,e){var r=[],i={};if(this.ms=e,this.times=1,t){for(var n in t)t[o](n)&&(i[z(n)]=t[n],r.push(z(n)));r.sort(H)}this.anim=i,this.top=r[r.length-1],this.percents=r}function ae(r,i,a,s,l,h){a=z(a);var u,c,p,d,g,y,m=r.ms,b={},_={},w={};if(s)for(B=0,C=Kt.length;Bs*r.top){a=r.percents[B],g=r.percents[B-1]||0,m=m/r.top*(a-g),d=r.percents[B+1],u=r.anim[a];break}s&&i.attr(r.anim[r.percents[B]])}if(u){if(c)c.initstatus=s,c.start=new Date-c.ms*s;else{for(var S in u)if(u[o](S)&&(I[o](S)||i.paper.customAttributes[o](S)))switch(b[S]=i.attr(S),b[S]==null&&(b[S]=j[S]),_[S]=u[S],I[S]){case A: w[S]=(_[S]-b[S])/m;break;case"colour": b[S]=e.getRGB(b[S]);var T=e.getRGB(_[S]);w[S]={r:(T.r-b[S].r)/m,g:(T.g-b[S].g)/m,b:(T.b-b[S].b)/m};break;case"path": var M=At(b[S],_[S]),E=M[1];for(b[S]=M[0],w[S]=[],B=0,C=b[S].length;Bh&&(h=c)}!t[h+="%"].callback&&(t[h].callback=n)}return new ne(t,r)},Yt.animate=function(t,r,i,n){if(this.removed)return n&&n.call(this),this;var a=t instanceof ne?t:e.animation(t,r,i,n);return ae(a,this,a.percents[0],null,this.attr()),this},Yt.setTime=function(t,e){return t&&e!=null&&this.status(t,k(e,t.ms)/t.ms),this},Yt.status=function(t,e){var r,i,n=[],a=0;if(e!=null)return ae(t,this,-1,k(e,1)),this;for(r=Kt.length;a"));var U=H.getBoundingClientRect();A.W=g.w=(U.right-U.left)/100,A.H=g.h=(U.bottom-U.top)/100,A.X=g.x,A.Y=g.y+A.H/2,("x"in l||"y"in l)&&(A.path.v=t.format("m{0},{1}l{2},{1}",a(g.x*y),a(g.y*y),a(g.x*y)+1));for(var $=["x","y","text","font","font-family","font-weight","font-style","font-size"],Z=0,Q=$.length;Z.25&&(r=n.sqrt(.25-o(e-.5,2))*(2*(r>.5)-1)+.5),h=e+c+r),f})).split(/\s*\-\s*/),l=="linear"){var u=a.shift();if(u=-i(u),isNaN(u))return null}var p=t._parseDots(a);if(!p)return null;if(e=e.shape||e.node,p.length){e.removeChild(s),s.on=!0,s.method="none",s.color=p[0].color,s.color2=p[p.length-1].color;for(var d=[],g=0,x=p.length;g')}}catch(t){k=function(t){return e.createElement("<"+t+' xmlns="urn:schemas-microsoft.com:vml" class="rvml">')}}},t._engine.initWin(t._g.win),t._engine.create=function(){var e=t._getContainer.apply(0,arguments),r=e.container,i=e.height,n=e.width,a=e.x,s=e.y;if(!r)throw new Error("VML container not found.");var o=new t._Paper,l=o.canvas=t._g.doc.createElement("div"),h=l.style;return a=a||0,s=s||0,n=n||512,i=i||342,o.width=n,o.height=i,n==+n&&(n+="px"),i==+i&&(i+="px"),o.coordsize=216e5+c+216e5,o.coordorigin="0 0",o.span=t._g.doc.createElement("span"),o.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;",l.appendChild(o.span),h.cssText=t.format("top:0;left:0;width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden",n,i),r==1?(t._g.doc.body.appendChild(l),h.left=a+"px",h.top=s+"px",h.position="absolute"):r.firstChild?r.insertBefore(l,r.firstChild):r.appendChild(l),o.renderfix=function(){},o},t.prototype.clear=function(){t.eve("raphael.clear",this),this.canvas.innerHTML=f,this.span=t._g.doc.createElement("span"),this.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;",this.canvas.appendChild(this.span),this.bottom=this.top=null},t.prototype.remove=function(){for(var e in t.eve("raphael.remove",this),this.canvas.parentNode.removeChild(this.canvas),this)this[e]=typeof this[e]=="function"?t._removedFactory(e):null;return!0};var M=t.st;for(var E in T)T[e](E)&&!M[e](E)&&(M[E]=(function(t){return function(){var e=arguments;return this.forEach(function(r){r[t].apply(r,e)})}}(E)))}}.apply(e,i))||(t.exports=n)},function(t,e,r){var i,n;i=[r(0)],void 0===(n=function(t){if(!t||t.svg){var e="hasOwnProperty",r=String,i=parseFloat,n=parseInt,a=Math,s=a.max,o=a.abs,l=a.pow,h=/[, ]+/,u=t.eve,c="",f=" ",p="http://www.w3.org/1999/xlink",d={block:"M5,0 0,2.5 5,5z",classic:"M5,0 0,2.5 5,5 3.5,3 3.5,2z",diamond:"M2.5,0 5,2.5 2.5,5 0,2.5z",open:"M6,1 1,3.5 6,6",oval:"M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"},g={};t.toString=function(){return"Your browser supports SVG.\nYou are running Raphaël "+this.version};var x=function(i,n){if(n)for(var a in typeof i=="string"&&(i=x(i)),n)n[e](a)&&(a.substring(0,6)=="xlink:"?i.setAttributeNS(p,a.substring(6),r(n[a])):i.setAttribute(a,r(n[a])));else(i=t._g.doc.createElementNS("http://www.w3.org/2000/svg",i)).style&&(i.style.webkitTapHighlightColor="rgba(0,0,0,0)");return i},v=function(e,n){var h="linear",u=e.id+n,f=.5,p=.5,d=e.node,g=e.paper,v=d.style,m=t._g.doc.getElementById(u);if(!m){if(n=(n=r(n).replace(t._radial_gradient,function(t,e,r){if(h="radial",e&&r){f=i(e);var n=2*((p=i(r))>.5)-1;l(f-.5,2)+l(p-.5,2)>.25&&(p=a.sqrt(.25-l(f-.5,2))*n+.5)&&p!=.5&&(p=p.toFixed(5)-1e-5*n)}return c})).split(/\s*\-\s*/),h=="linear"){var b=n.shift();if(b=-i(b),isNaN(b))return null;var _=[0,0,a.cos(t.rad(b)),a.sin(t.rad(b))],w=1/(s(o(_[2]),o(_[3]))||1);_[2]*=w,_[3]*=w,_[2]<0&&(_[0]=-_[2],_[2]=0),_[3]<0&&(_[1]=-_[3],_[3]=0)}var k=t._parseDots(n);if(!k)return null;if(u=u.replace(/[\(\)\s,\xb0#]/g,"_"),e.gradient&&u!=e.gradient.id&&(g.defs.removeChild(e.gradient),delete e.gradient),!e.gradient){m=x(h+"Gradient",{id:u}),e.gradient=m,x(m,h=="radial"?{fx:f,fy:p}:{x1:_[0],y1:_[1],x2:_[2],y2:_[3],gradientTransform:e.matrix.invert()}),g.defs.appendChild(m);for(var B=0,C=k.length;B1?P.opacity/100:P.opacity});case"stroke": P=t.getRGB(g),l.setAttribute(d,P.hex),d=="stroke"&&P[e]("opacity")&&x(l,{"stroke-opacity":P.opacity>1?P.opacity/100:P.opacity}),d=="stroke"&&i._.arrows&&("startString"in i._.arrows&&b(i,i._.arrows.startString),"endString"in i._.arrows&&b(i,i._.arrows.endString,1));break;case"gradient": (i.type=="circle"||i.type=="ellipse"||r(g).charAt()!="r")&&v(i,g);break;case"opacity": u.gradient&&!u[e]("stroke-opacity")&&x(l,{"stroke-opacity":g>1?g/100:g});case"fill-opacity": if(u.gradient){(z=t._g.doc.getElementById(l.getAttribute("fill").replace(/^url\(#|\)$/g,c)))&&(F=z.getElementsByTagName("stop"),x(F[F.length-1],{"stop-opacity":g}));break}default: d=="font-size"&&(g=n(g,10)+"px");var R=d.replace(/(\-.)/g,function(t){return t.substring(1).toUpperCase()});l.style[R]=g,i._.dirty=1,l.setAttribute(d,g)}}B(i,a),l.style.visibility=f},B=function(i,a){if(i.type=="text"&&(a[e]("text")||a[e]("font")||a[e]("font-size")||a[e]("x")||a[e]("y"))){var s=i.attrs,o=i.node,l=o.firstChild?n(t._g.doc.defaultView.getComputedStyle(o.firstChild,c).getPropertyValue("font-size"),10):10;if(a[e]("text")){for(s.text=a.text;o.firstChild;)o.removeChild(o.firstChild);for(var h,u=r(a.text).split("\n"),f=[],p=0,d=u.length;p1)for(var i=0,n=r.length;i {
let s: string = e.toString();
@@ -52,18 +52,18 @@ function convert2DArrayToString(arr: any[][]) {
export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
{
- desc: (n: number) => {
+ desc: (n: number): string => {
return ["A prime factor is a factor that is a prime number.",
`What is the largest prime factor of ${n}?`].join(" ");
},
difficulty: 1,
- gen: () => {
+ gen: (): number => {
return getRandomInt(500, 1e9);
},
name: "Find Largest Prime Factor",
numTries: 10,
- solver: (data: number, ans: string) => {
- let fac: number = 2;
+ solver: (data: number, ans: string): boolean => {
+ let fac = 2;
let n: number = data;
while (n > ((fac-1) * (fac-1))) {
while (n % fac === 0) {
@@ -76,18 +76,18 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (n: number[]) => {
+ desc: (n: number[]): string => {
return ["Given the following integer array, find the contiguous subarray",
"(containing at least one number) which has the largest sum and return that sum.",
"'Sum' refers to the sum of all the numbers in the subarray.\n",
`${n.toString()}`].join(" ");
},
difficulty: 1,
- gen: () => {
+ gen: (): number[] => {
const len: number = getRandomInt(5, 40);
const arr: number[] = [];
arr.length = len;
- for (let i: number = 0; i < len; ++i) {
+ for (let i = 0; i < len; ++i) {
arr[i] = getRandomInt(-10, 10);
}
@@ -95,9 +95,9 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Subarray with Maximum Sum",
numTries: 10,
- solver: (data: number[], ans: string) => {
+ solver: (data: number[], ans: string): boolean => {
const nums: number[] = data.slice();
- for (let i: number = 1; i < nums.length; i++) {
+ for (let i = 1; i < nums.length; i++) {
nums[i] = Math.max(nums[i], nums[i] + nums[i - 1]);
}
@@ -105,7 +105,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (n: number) => {
+ desc: (n: number): string => {
return ["It is possible write four as a sum in exactly four different ways:\n\n",
" 3 + 1\n",
" 2 + 2\n",
@@ -115,16 +115,16 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
"two positive integers?"].join(" ");
},
difficulty: 1.5,
- gen: () => {
+ gen: (): number => {
return getRandomInt(8, 100);
},
name: "Total Ways to Sum",
numTries: 10,
- solver: (data: number, ans: string) => {
+ solver: (data: number, ans: string): boolean => {
const ways: number[] = [1];
ways.length = data + 1;
ways.fill(0, 1);
- for (let i: number = 1; i < data; ++i) {
+ for (let i = 1; i < data; ++i) {
for (let j: number = i; j <= data; ++j) {
ways[j] += ways[j - i];
}
@@ -134,7 +134,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (n: number[][]) => {
+ desc: (n: number[][]): string => {
let d: string = ["Given the following array of array of numbers representing a 2D matrix,",
"return the elements of the matrix as an array in spiral order:\n\n"].join(" ");
for (const line of n) {
@@ -157,18 +157,18 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
return d;
},
difficulty: 2,
- gen: () => {
+ gen: (): number[][] => {
const m: number = getRandomInt(1, 15);
const n: number = getRandomInt(1, 15);
const matrix: number[][] = [];
matrix.length = m;
- for (let i: number = 0; i < m; ++i) {
+ for (let i = 0; i < m; ++i) {
matrix[i] = [];
matrix[i].length = n;
}
- for (let i: number = 0; i < m; ++i) {
- for (let j: number = 0; j < n; ++j) {
+ for (let i = 0; i < m; ++i) {
+ for (let j = 0; j < n; ++j) {
matrix[i][j] = getRandomInt(1, 50);
}
}
@@ -177,15 +177,15 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Spiralize Matrix",
numTries: 10,
- solver: (data: number[][], ans: string) => {
+ solver: (data: number[][], ans: string): boolean => {
const spiral: number[] = [];
const m: number = data.length;
const n: number = data[0].length;
- let u: number = 0;
+ let u = 0;
let d: number = m - 1;
- let l: number = 0;
+ let l = 0;
let r: number = n - 1;
- let k: number = 0;
+ let k = 0;
while (true) {
// Up
for (let col: number = l; col <= r; col++) {
@@ -219,11 +219,11 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
const sanitizedPlayerAns: string = removeBracketsFromArrayString(ans)
.replace(/\s/g, "");
const playerAns: any[] = sanitizedPlayerAns.split(",");
- for (let i: number = 0; i < playerAns.length; ++i) {
+ for (let i = 0; i < playerAns.length; ++i) {
playerAns[i] = parseInt(playerAns[i], 10);
}
if (spiral.length !== playerAns.length) { return false; }
- for (let i: number = 0; i < spiral.length; ++i) {
+ for (let i = 0; i < spiral.length; ++i) {
if (spiral[i] !== playerAns[i]) {
return false;
}
@@ -233,7 +233,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (arr: number[]) => {
+ desc: (arr: number[]): string => {
return ["You are given the following array of integers:\n\n",
`${arr}\n\n`,
"Each element in the array represents your MAXIMUM jump length",
@@ -246,11 +246,11 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
"Your answer should be submitted as 1 or 0, representing true and false respectively"].join(" ");
},
difficulty: 2.5,
- gen: () => {
+ gen: (): number[] => {
const len: number = getRandomInt(3, 25);
const arr: number[] = [];
arr.length = len;
- for (let i: number = 0; i < arr.length; ++i) {
+ for (let i = 0; i < arr.length; ++i) {
if (Math.random() < 0.2) {
arr[i] = 0; // 20% chance of being 0
} else {
@@ -262,10 +262,10 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Array Jumping Game",
numTries: 1,
- solver: (data: number[], ans: string) => {
+ solver: (data: number[], ans: string): boolean => {
const n: number = data.length;
- let i: number = 0;
- for (let reach: number = 0; i < n && i <= reach; ++i) {
+ let i = 0;
+ for (let reach = 0; i < n && i <= reach; ++i) {
reach = Math.max(i + data[i], reach);
}
const solution: boolean = (i === n);
@@ -277,7 +277,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (arr: number[][]) => {
+ desc: (arr: number[][]): string => {
return ["Given the following array of array of numbers representing a list of",
"intervals, merge all overlapping intervals.\n\n",
`[${convert2DArrayToString(arr)}]\n\n`,
@@ -289,10 +289,10 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
"smaller than the second."].join(" ");
},
difficulty: 3,
- gen: () => {
+ gen: (): number[][] => {
const intervals: number[][] = [];
const numIntervals: number = getRandomInt(3, 20);
- for (let i: number = 0; i < numIntervals; ++i) {
+ for (let i = 0; i < numIntervals; ++i) {
const start: number = getRandomInt(1, 25);
const end: number = start + getRandomInt(1, 10);
intervals.push([start, end]);
@@ -302,7 +302,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Merge Overlapping Intervals",
numTries: 15,
- solver: (data: number[][], ans: string) => {
+ solver: (data: number[][], ans: string): boolean => {
const intervals: number[][] = data.slice();
intervals.sort((a: number[], b: number[]) => {
return a[0] - b[0];
@@ -330,7 +330,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (data: string) => {
+ desc: (data: string): string => {
return ["Given the following string containing only digits, return",
"an array with all possible valid IP address combinations",
"that can be created from the string:\n\n",
@@ -342,9 +342,9 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
"1938718066 -> [193.87.180.66]"].join(" ");
},
difficulty: 3,
- gen: () => {
- let str: string = "";
- for (let i: number = 0; i < 4; ++i) {
+ gen: (): string => {
+ let str = "";
+ for (let i = 0; i < 4; ++i) {
const num: number = getRandomInt(0, 255);
const convNum: string = num.toString();
str += convNum;
@@ -354,12 +354,12 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Generate IP Addresses",
numTries: 10,
- solver: (data: string, ans: string) => {
+ solver: (data: string, ans: string): boolean => {
const ret: string[] = [];
- for (let a: number = 1; a <= 3; ++a) {
- for (let b: number = 1; b <= 3; ++b) {
- for (let c: number = 1; c <= 3; ++c) {
- for (let d: number = 1; d <= 3; ++d) {
+ for (let a = 1; a <= 3; ++a) {
+ for (let b = 1; b <= 3; ++b) {
+ for (let c = 1; c <= 3; ++c) {
+ for (let d = 1; d <= 3; ++d) {
if (a + b + c + d === data.length) {
const A: number = parseInt(data.substring(0, a), 10);
const B: number = parseInt(data.substring(a, a + b), 10);
@@ -392,7 +392,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (data: number[]) => {
+ desc: (data: number[]): string => {
return ["You are given the following array of stock prices (which are numbers)",
"where the i-th element represents the stock price on day i:\n\n",
`${data}\n\n`,
@@ -402,11 +402,11 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
"that you have to buy the stock before you can sell it"].join(" ");
},
difficulty: 1,
- gen: () => {
+ gen: (): number[] => {
const len: number = getRandomInt(3, 50);
const arr: number[] = [];
arr.length = len;
- for (let i: number = 0; i < len; ++i) {
+ for (let i = 0; i < len; ++i) {
arr[i] = getRandomInt(1, 200);
}
@@ -414,10 +414,10 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Algorithmic Stock Trader I",
numTries: 5,
- solver: (data: number[], ans: string) => {
- let maxCur: number = 0;
- let maxSoFar: number = 0;
- for (let i: number = 1; i < data.length; ++i) {
+ solver: (data: number[], ans: string): boolean => {
+ let maxCur = 0;
+ let maxSoFar = 0;
+ for (let i = 1; i < data.length; ++i) {
maxCur = Math.max(0, maxCur += data[i] - data[i - 1]);
maxSoFar = Math.max(maxCur, maxSoFar);
}
@@ -426,7 +426,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (data: number[]) => {
+ desc: (data: number[]): string => {
return ["You are given the following array of stock prices (which are numbers)",
"where the i-th element represents the stock price on day i:\n\n",
`${data}\n\n`,
@@ -438,11 +438,11 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
"If no profit can be made, then the answer should be 0"].join(" ");
},
difficulty: 2,
- gen: () => {
+ gen: (): number[] => {
const len: number = getRandomInt(3, 50);
const arr: number[] = [];
arr.length = len;
- for (let i: number = 0; i < len; ++i) {
+ for (let i = 0; i < len; ++i) {
arr[i] = getRandomInt(1, 200);
}
@@ -450,9 +450,9 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Algorithmic Stock Trader II",
numTries: 10,
- solver: (data: number[], ans: string) => {
- let profit: number = 0;
- for (let p: number = 1; p < data.length; ++p) {
+ solver: (data: number[], ans: string): boolean => {
+ let profit = 0;
+ for (let p = 1; p < data.length; ++p) {
profit += Math.max(data[p] - data[p - 1], 0);
}
@@ -460,7 +460,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (data: number[]) => {
+ desc: (data: number[]): string => {
return ["You are given the following array of stock prices (which are numbers)",
"where the i-th element represents the stock price on day i:\n\n",
`${data}\n\n`,
@@ -472,11 +472,11 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
"If no profit can be made, then the answer should be 0"].join(" ");
},
difficulty: 5,
- gen: () => {
+ gen: (): number[] => {
const len: number = getRandomInt(3, 50);
const arr: number[] = [];
arr.length = len;
- for (let i: number = 0; i < len; ++i) {
+ for (let i = 0; i < len; ++i) {
arr[i] = getRandomInt(1, 200);
}
@@ -484,11 +484,11 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Algorithmic Stock Trader III",
numTries: 10,
- solver: (data: number[], ans: string) => {
+ solver: (data: number[], ans: string): boolean => {
let hold1: number = Number.MIN_SAFE_INTEGER;
let hold2: number = Number.MIN_SAFE_INTEGER;
- let release1: number = 0;
- let release2: number = 0;
+ let release1 = 0;
+ let release2 = 0;
for (const price of data) {
release2 = Math.max(release2, hold2 + price);
hold2 = Math.max(hold2, release1 - price);
@@ -500,7 +500,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (data: any[]) => {
+ desc: (data: any[]): string => {
const k: number = (data[0]);
const prices: number[] = (data[1]);
return ["You are given the following array with two elements:\n\n",
@@ -516,7 +516,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
"If no profit can be made, then the answer should be 0."].join(" ");
},
difficulty: 8,
- gen: () => {
+ gen: (): any[] => {
const k: number = getRandomInt(2, 10);
const len: number = getRandomInt(3, 50);
const prices: number[] = [];
@@ -529,14 +529,14 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Algorithmic Stock Trader IV",
numTries: 10,
- solver: (data: any[], ans: string) => {
+ solver: (data: any[], ans: string): boolean => {
const k: number = (data[0]);
const prices: number[] = (data[1]);
const len = prices.length;
if (len < 2) { return (parseInt(ans) === 0); }
if (k > len / 2) {
- let res: number = 0;
+ let res = 0;
for (let i = 1; i < len; ++i) {
res += Math.max(prices[i] - prices[i-1], 0);
}
@@ -566,8 +566,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (data: number[][]) => {
- function createTriangleRecurse(data: number[][], level: number = 0): string {
+ desc: (data: number[][]): string => {
+ function createTriangleRecurse(data: number[][], level = 0): string {
const numLevels: number = data.length;
if (level >= numLevels) { return ""; }
const numSpaces = numLevels - level + 1;
@@ -580,7 +580,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
return str + "\n" + createTriangleRecurse(data, level+1);
}
- function createTriangle(data: number[][]) {
+ function createTriangle(data: number[][]): string {
return ["[\n", createTriangleRecurse(data), "]"].join("");
}
@@ -600,7 +600,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
"The minimum path sum is 11 (2 -> 3 -> 5 -> 1)."].join(" ");
},
difficulty: 5,
- gen: () => {
+ gen: (): number[][] => {
const triangle: number[][] = [];
const levels: number = getRandomInt(3, 12);
triangle.length = levels;
@@ -617,9 +617,9 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Minimum Path Sum in a Triangle",
numTries: 10,
- solver: (data: number[][], ans: string) => {
- let n: number = data.length;
- let dp: number[] = data[n-1].slice();
+ solver: (data: number[][], ans: string): boolean => {
+ const n: number = data.length;
+ const dp: number[] = data[n-1].slice();
for (let i = n-2; i > -1; --i) {
for (let j = 0; j < data[i].length; ++j) {
dp[j] = Math.min(dp[j], dp[j + 1]) + data[i][j];
@@ -630,7 +630,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (data: number[]) => {
+ desc: (data: number[]): string => {
const numRows = data[0];
const numColumns = data[1];
return ["You are in a grid with",
@@ -644,7 +644,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
`[${numRows}, ${numColumns}]`].join(" ");
},
difficulty: 3,
- gen: () => {
+ gen: (): number[] => {
const numRows: number = getRandomInt(2, 14);
const numColumns: number = getRandomInt(2, 14);
@@ -652,10 +652,10 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Unique Paths in a Grid I",
numTries: 10,
- solver: (data: number[], ans: string) => {
- let n: number = data[0]; // Number of rows
- let m: number = data[1]; // Number of columns
- let currentRow: number[] = [];
+ solver: (data: number[], ans: string): boolean => {
+ const n: number = data[0]; // Number of rows
+ const m: number = data[1]; // Number of columns
+ const currentRow: number[] = [];
currentRow.length = n;
for (let i = 0; i < n; i++) {
@@ -671,8 +671,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (data: number[][]) => {
- let gridString: string = "";
+ desc: (data: number[][]): string => {
+ let gridString = "";
for (const line of data) {
gridString += `${line.toString()},\n`;
}
@@ -686,7 +686,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
"NOTE: The data returned for this contract is an 2D array of numbers representing the grid."].join(" ");
},
difficulty: 5,
- gen: () => {
+ gen: (): number[][] => {
const numRows: number = getRandomInt(2, 12);
const numColumns: number = getRandomInt(2, 12);
@@ -714,8 +714,8 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Unique Paths in a Grid II",
numTries: 10,
- solver: (data: number[][], ans: string) => {
- let obstacleGrid: number[][] = [];
+ solver: (data: number[][], ans: string): boolean => {
+ const obstacleGrid: number[][] = [];
obstacleGrid.length = data.length;
for (let i = 0; i < obstacleGrid.length; ++i) {
obstacleGrid[i] = data[i].slice();
@@ -738,7 +738,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (data: string) => {
+ desc: (data: string): string => {
return ["Given the following string:\n\n",
`${data}\n\n`,
"remove the minimum number of invalid parentheses in order to validate",
@@ -753,9 +753,9 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
`")( -> [""]`].join(" ");
},
difficulty: 10,
- gen: () => {
+ gen: (): string => {
const len: number = getRandomInt(6, 20);
- let chars: string[] = [];
+ const chars: string[] = [];
chars.length = len;
// 80% chance of the first parenthesis being (
@@ -776,10 +776,10 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Sanitize Parentheses in Expression",
numTries: 10,
- solver: (data: string, ans: string) => {
+ solver: (data: string, ans: string): boolean => {
let left = 0;
let right = 0;
- let res: string[] = [];
+ const res: string[] = [];
for (let i = 0; i < data.length; ++i) {
if (data[i] === '(') {
@@ -789,10 +789,10 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
}
}
- function dfs(pair: number, index: number, left: number, right: number, s: string, solution: string, res: string[]) {
+ function dfs(pair: number, index: number, left: number, right: number, s: string, solution: string, res: string[]): void {
if (s.length === index) {
if (left === 0 && right === 0 && pair === 0) {
- for(var i = 0; i < res.length; i++) {
+ for(let i = 0; i < res.length; i++) {
if(res[i] === solution) { return; }
}
res.push(solution);
@@ -828,7 +828,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
},
{
- desc: (data: any[]) => {
+ desc: (data: any[]): string => {
const digits: string = data[0];
const target: number = data[1];
@@ -850,7 +850,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
`Output: [1*0+5, 10-5]`].join(" ");
},
difficulty: 10,
- gen: () => {
+ gen: (): any[] => {
const numDigits = getRandomInt(4, 12);
const digitsArray: string[] = [];
digitsArray.length = numDigits;
@@ -869,11 +869,11 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
},
name: "Find All Valid Math Expressions",
numTries: 10,
- solver: (data: any[], ans: string) => {
+ solver: (data: any[], ans: string): boolean => {
const num: string = data[0];
const target: number = data[1];
- function helper(res: string[], path: string, num: string, target: number, pos: number, evaluated: number, multed: number) {
+ function helper(res: string[], path: string, num: string, target: number, pos: number, evaluated: number, multed: number): void {
if (pos === num.length) {
if (target === evaluated) {
res.push(path);
@@ -883,7 +883,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
for (let i = pos; i < num.length; ++i) {
if (i != pos && num[pos] == '0') { break; }
- let cur = parseInt(num.substring(pos, i+1));
+ const cur = parseInt(num.substring(pos, i+1));
if (pos === 0) {
helper(res, path + cur, num, target, i + 1, cur, cur);
@@ -899,7 +899,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
const sanitizedPlayerAnsArr: string[] = sanitizedPlayerAns.split(",");
for (let i = 0; i < sanitizedPlayerAnsArr.length; ++i) {
sanitizedPlayerAnsArr[i] = removeQuotesFromString(sanitizedPlayerAnsArr[i])
- .replace(/\s/g, "");;
+ .replace(/\s/g, "");
}
if (num == null || num.length === 0) {
@@ -908,7 +908,7 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
return false;
}
- let result: string[] = [];
+ const result: string[] = [];
helper(result, "", num, target, 0, 0, 0);
for (const expr of result) {
diff --git a/src/data/gangmembertasks.ts b/src/data/gangmembertasks.ts
index 16732c5ab..9aefa0059 100644
--- a/src/data/gangmembertasks.ts
+++ b/src/data/gangmembertasks.ts
@@ -146,9 +146,9 @@ export const gangMemberTasksMetadata: IGangMemberTaskMetadata[] = [
territory: {
money: 1.6,
respect: 1.1,
- wanted: 1.5
- }
- }
+ wanted: 1.5,
+ },
+ },
},
{
desc: "Assign this gang member to run cons Earns money - Increases respect - Increases wanted level",
@@ -212,8 +212,8 @@ export const gangMemberTasksMetadata: IGangMemberTaskMetadata[] = [
money: 1.5,
respect: 1.5,
wanted: 1.6,
- }
- }
+ },
+ },
},
{
desc: "Assign this gang member to commit acts of terrorism Greatly increases respect - Greatly increases wanted level - Scales heavily with territory",
@@ -254,7 +254,7 @@ export const gangMemberTasksMetadata: IGangMemberTaskMetadata[] = [
name: "Train Combat",
params: {
strWeight: 25, defWeight: 25, dexWeight: 25, agiWeight: 25,
- difficulty: 5
+ difficulty: 5,
},
},
{
@@ -278,7 +278,7 @@ export const gangMemberTasksMetadata: IGangMemberTaskMetadata[] = [
name: "Territory Warfare",
params: {
hackWeight: 15, strWeight: 20, defWeight: 20, dexWeight: 20, agiWeight: 20, chaWeight: 5,
- difficulty: 5
+ difficulty: 5,
},
},
];
diff --git a/src/engine.jsx b/src/engine.jsx
index 06dc0b1e9..5e7dae147 100644
--- a/src/engine.jsx
+++ b/src/engine.jsx
@@ -5,7 +5,7 @@
*/
import {
convertTimeMsToTimeElapsedString,
- replaceAt
+ replaceAt,
} from "../utils/StringHelperFunctions";
import { logBoxUpdateText, logBoxOpened } from "../utils/LogBox";
import { Augmentations } from "./Augmentation/Augmentations";
@@ -15,7 +15,7 @@ import {
} from "./Augmentation/AugmentationHelpers";
import { AugmentationNames } from "./Augmentation/data/AugmentationNames";
import {
- initBitNodeMultipliers
+ initBitNodeMultipliers,
} from "./BitNode/BitNode";
import { Bladeburner } from "./Bladeburner";
import { CharacterOverviewComponent } from "./ui/React/CharacterOverview";
@@ -30,14 +30,14 @@ import {
displayFactionContent,
joinFaction,
processPassiveFactionRepGain,
- inviteToFaction
+ inviteToFaction,
} from "./Faction/FactionHelpers";
import { FconfSettings } from "./Fconf/FconfSettings";
import {
hasHacknetServers,
renderHacknetNodesUI,
clearHacknetNodesUI,
- processHacknetEarnings
+ processHacknetEarnings,
} from "./Hacknet/HacknetHelpers";
import { iTutorialStart } from "./InteractiveTutorial";
import { LocationName } from "./Locations/data/LocationNames";
@@ -54,14 +54,14 @@ import { prestigeAugmentation } from "./Prestige";
import {
displayCreateProgramContent,
getNumAvailableCreateProgram,
- initCreateProgramButtons
+ initCreateProgramButtons,
} from "./Programs/ProgramHelpers";
import { redPillFlag } from "./RedPill";
import { saveObject, loadGame } from "./SaveObject";
import {
getCurrentEditor,
scriptEditorInit,
- updateScriptEditorContent
+ updateScriptEditorContent,
} from "./Script/ScriptHelpers";
import { initForeignServers } from "./Server/AllServers";
import { Settings } from "./Settings/Settings";
@@ -70,7 +70,7 @@ import { initSpecialServerIps } from "./Server/SpecialServerIps";
import {
initSymbolToStockMap,
processStockPrices,
- displayStockMarketContent
+ displayStockMarketContent,
} from "./StockMarket/StockMarket";
import { displayMilestonesContent } from "./Milestones/MilestoneHelpers";
import { Terminal, postNetburnerText } from "./Terminal";
@@ -78,17 +78,16 @@ import { Sleeve } from "./PersonObjects/Sleeve/Sleeve";
import {
clearSleevesPage,
createSleevesPage,
- updateSleevesPage
+ updateSleevesPage,
} from "./PersonObjects/Sleeve/SleeveUI";
import {
clearResleevesPage,
- createResleevesPage
+ createResleevesPage,
} from "./PersonObjects/Resleeving/ResleevingUI";
import { createStatusText } from "./ui/createStatusText";
import { CharacterInfo } from "./ui/CharacterInfo";
import { Page, routing } from "./ui/navigationTracking";
-import { numeralWrapper } from "./ui/numeralFormat";
import { setSettingsLabels } from "./ui/setSettingsLabels";
import { Money } from "./ui/React/Money";
import { Hashes } from "./ui/React/Hashes";
@@ -134,7 +133,7 @@ $(document).keydown(function(e) {
if (getCurrentEditor().isFocused()) {
return;
}
- } catch(e) {}
+ } catch(error) {}
if (!Player.isWorking && !redPillFlag && !inMission && !cinematicTextFlag) {
if (e.keyCode == KEY.T && e.altKey) {
@@ -270,7 +269,7 @@ const Engine = {
routing.navigateTo(Page.ActiveScripts);
ReactDOM.render(
,
- Engine.Display.activeScriptsContent
+ Engine.Display.activeScriptsContent,
)
MainMenuLinks.ActiveScripts.classList.add("active");
},
@@ -590,10 +589,10 @@ const Engine = {
// Factions
Engine.Display.factionsContent.appendChild(createElement("h1", {
- innerText:"Factions"
+ innerText:"Factions",
}));
Engine.Display.factionsContent.appendChild(createElement("p", {
- innerText:"Lists all factions you have joined"
+ innerText:"Lists all factions you have joined",
}));
var factionsList = createElement("ul");
Engine.Display.factionsContent.appendChild(createElement("br"));
@@ -610,7 +609,7 @@ const Engine = {
Engine.loadFactionContent();
displayFactionContent(factionName);
return false;
- }
+ },
}));
factionsList.appendChild(createElement("br"));
}()); // Immediate invocation
@@ -620,12 +619,12 @@ const Engine = {
// Invited Factions
Engine.Display.factionsContent.appendChild(createElement("h1", {
- innerText:"Outstanding Faction Invitations"
+ innerText:"Outstanding Faction Invitations",
}));
Engine.Display.factionsContent.appendChild(createElement("p", {
width:"70%",
innerText:"Lists factions you have been invited to. You can accept " +
- "these faction invitations at any time."
+ "these faction invitations at any time.",
}));
var invitationsList = createElement("ul");
@@ -636,7 +635,7 @@ const Engine = {
var item = createElement("li", {padding:"6px", margin:"6px"});
item.appendChild(createElement("p", {
- innerText:factionName, display:"inline", margin:"4px", padding:"4px"
+ innerText:factionName, display:"inline", margin:"4px", padding:"4px",
}));
item.appendChild(createElement("a", {
innerText:"Accept Faction Invitation",
@@ -652,7 +651,7 @@ const Engine = {
}
Engine.displayFactionsInfo();
return false;
- }
+ },
}));
invitationsList.appendChild(item);
@@ -829,7 +828,7 @@ const Engine = {
if (routing.isOn(Page.ActiveScripts)) {
ReactDOM.render(
,
- Engine.Display.activeScriptsContent
+ Engine.Display.activeScriptsContent,
)
}
@@ -1229,7 +1228,7 @@ const Engine = {
Engine.openMainMenuHeader(
[terminal, createScript, activeScripts, stats,
hacknetnodes, city, milestones,
- tutorial, options]
+ tutorial, options],
);
// Start interactive tutorial
@@ -1474,7 +1473,6 @@ const Engine = {
var cancelButton = document.getElementById("work-in-progress-cancel-button");
cancelButton.addEventListener("click", function() {
if (Player.workType == CONSTANTS.WorkTypeFaction) {
- var fac = Factions[Player.currentWorkFactionName];
Player.finishFactionWork(true);
} else if (Player.workType == CONSTANTS.WorkTypeCreateProgram) {
Player.finishCreateProgramWork(true);
@@ -1534,7 +1532,8 @@ const Engine = {
// Use the Async Clipboard API
navigator.clipboard.writeText(saveString).then(function() {
createStatusText("Copied save to clipboard");
- }, function(e) {
+ }, function(err) {
+ console.error(err);
console.error("Unable to copy save data to clipboard using Async API");
createStatusText("Failed to copy save");
})
@@ -1561,7 +1560,7 @@ const Engine = {
start: function() {
// Run main loop
Engine.idleTimer();
- }
+ },
};
var indexedDb, indexedDbRequest;
@@ -1593,14 +1592,14 @@ window.onload = function() {
return Engine.load(null); // Try to load from localstorage
}
- request.onsuccess = function(e) {
+ request.onsuccess = function() {
Engine.load(request.result);
}
};
indexedDbRequest.onupgradeneeded = function(e) {
- var db = e.target.result;
- var objectStore = db.createObjectStore("savestring");
+ const db = e.target.result;
+ db.createObjectStore("savestring");
}
};
diff --git a/src/index.html b/src/index.html
index d5b147ec9..87f0044e1 100644
--- a/src/index.html
+++ b/src/index.html
@@ -340,8 +340,8 @@ if (htmlWebpackPlugin.options.googleAnalytics.trackingId) { %>
Would you like to join?
Warning: Joining this faction may prevent you from joining other factions during this run!
-
-
+
+
diff --git a/src/ui/ActiveScripts/Root.tsx b/src/ui/ActiveScripts/Root.tsx
index 00ac8bbbb..d18dec637 100644
--- a/src/ui/ActiveScripts/Root.tsx
+++ b/src/ui/ActiveScripts/Root.tsx
@@ -20,7 +20,7 @@ export class ActiveScriptsRoot extends React.Component {
super(props);
}
- render() {
+ render(): React.ReactNode {
return (
<>
diff --git a/src/ui/ActiveScripts/ScriptProduction.tsx b/src/ui/ActiveScripts/ScriptProduction.tsx
index 3f9d51f60..d82d430dc 100644
--- a/src/ui/ActiveScripts/ScriptProduction.tsx
+++ b/src/ui/ActiveScripts/ScriptProduction.tsx
@@ -4,8 +4,6 @@
*/
import * as React from "react";
-import { numeralWrapper } from "../numeralFormat";
-
import { WorkerScript } from "../../Netscript/WorkerScript";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { Money } from "../React/Money";
diff --git a/src/ui/ActiveScripts/ServerAccordion.tsx b/src/ui/ActiveScripts/ServerAccordion.tsx
index 9a0d1c57f..35a78e6a2 100644
--- a/src/ui/ActiveScripts/ServerAccordion.tsx
+++ b/src/ui/ActiveScripts/ServerAccordion.tsx
@@ -26,7 +26,7 @@ export function ServerAccordion(props: IProps): React.ReactElement {
const paddedName = `${server.hostname}${" ".repeat(longestHostnameLength)}`.slice(0, Math.max(server.hostname.length, longestHostnameLength));
const barOptions = {
progress: server.ramUsed / server.maxRam,
- totalTicks: 30
+ totalTicks: 30,
};
const headerTxt = `${paddedName} ${createProgressBarText(barOptions)}`;
diff --git a/src/ui/ActiveScripts/ServerAccordions.tsx b/src/ui/ActiveScripts/ServerAccordions.tsx
index acd279870..6368eef89 100644
--- a/src/ui/ActiveScripts/ServerAccordions.tsx
+++ b/src/ui/ActiveScripts/ServerAccordions.tsx
@@ -47,14 +47,14 @@ export class ServerAccordions extends React.Component {
this.rerender = this.rerender.bind(this);
}
- componentDidMount() {
+ componentDidMount(): void {
WorkerScriptStartStopEventEmitter.addSubscriber({
cb: this.rerender,
id: subscriberId,
})
}
- componentWillUnmount() {
+ componentWillUnmount(): void {
WorkerScriptStartStopEventEmitter.removeSubscriber(subscriberId);
}
@@ -81,14 +81,14 @@ export class ServerAccordions extends React.Component {
this.serverToScriptMap = map;
}
- rerender() {
+ rerender(): void {
this.updateServerToScriptsMap();
this.setState((prevState) => {
return { rerenderFlag: !prevState.rerenderFlag }
});
}
- render() {
+ render(): React.ReactNode {
const elems = Object.keys(this.serverToScriptMap).map((serverName) => {
const data = this.serverToScriptMap[serverName];
return (
diff --git a/src/ui/ActiveScripts/WorkerScriptAccordion.tsx b/src/ui/ActiveScripts/WorkerScriptAccordion.tsx
index c62546bb8..f055fd07a 100644
--- a/src/ui/ActiveScripts/WorkerScriptAccordion.tsx
+++ b/src/ui/ActiveScripts/WorkerScriptAccordion.tsx
@@ -29,7 +29,7 @@ export function WorkerScriptAccordion(props: IProps): React.ReactElement {
const logClickHandler = logBoxCreate.bind(null, scriptRef);
const killScript = killWorkerScript.bind(null, scriptRef as any, scriptRef.server);
- function killScriptClickHandler() {
+ function killScriptClickHandler(): void {
killScript();
dialogBoxCreate("Killing script");
}
@@ -49,7 +49,7 @@ export function WorkerScriptAccordion(props: IProps): React.ReactElement {
panelClass="active-scripts-script-panel"
panelContent={
<>
- Threads: {props.workerScript.scriptRef.threads}
+ Threads: {numeralWrapper.formatThreads(props.workerScript.scriptRef.threads)}
Args: {arrayToString(props.workerScript.args)}
Online Time: {convertTimeMsToTimeElapsedString(scriptRef.onlineRunningTime * 1e3)}
Offline Time: {convertTimeMsToTimeElapsedString(scriptRef.offlineRunningTime * 1e3)}
diff --git a/src/ui/CharacterInfo.tsx b/src/ui/CharacterInfo.tsx
index 03b84f3fc..fbd98f6cf 100644
--- a/src/ui/CharacterInfo.tsx
+++ b/src/ui/CharacterInfo.tsx
@@ -47,25 +47,25 @@ export function CharacterInfo(p: IPlayer): React.ReactElement {
}
function convertMoneySourceTrackerToString(src: MoneySourceTracker): React.ReactElement {
- let parts: any[][] = [[`Total:`, Money(src.total)]];
- if (src.bladeburner) { parts.push([`Bladeburner:`, Money(src.bladeburner)]) };
- if (src.codingcontract) { parts.push([`Coding Contracts:`, Money(src.codingcontract)]) };
- if (src.work) { parts.push([`Company Work:`, Money(src.work)]) };
- if (src.class) { parts.push([`Class:`, Money(src.class)]) };
- if (src.corporation) { parts.push([`Corporation:`, Money(src.corporation)]) };
- if (src.crime) { parts.push([`Crimes:`, Money(src.crime)]) };
- if (src.gang) { parts.push([`Gang:`, Money(src.gang)]) };
- if (src.hacking) { parts.push([`Hacking:`, Money(src.hacking)]) };
- if (src.hacknetnode) { parts.push([`Hacknet Nodes:`, Money(src.hacknetnode)]) };
- if (src.hospitalization) { parts.push([`Hospitalization:`, Money(src.hospitalization)]) };
- if (src.infiltration) { parts.push([`Infiltration:`, Money(src.infiltration)]) };
- if (src.stock) { parts.push([`Stock Market:`, Money(src.stock)]) };
- if (src.casino) { parts.push([`Casino:`, Money(src.casino)]) };
+ const parts: any[][] = [[`Total:`, Money(src.total)]];
+ if (src.bladeburner) { parts.push([`Bladeburner:`, Money(src.bladeburner)]) }
+ if (src.codingcontract) { parts.push([`Coding Contracts:`, Money(src.codingcontract)]) }
+ if (src.work) { parts.push([`Company Work:`, Money(src.work)]) }
+ if (src.class) { parts.push([`Class:`, Money(src.class)]) }
+ if (src.corporation) { parts.push([`Corporation:`, Money(src.corporation)]) }
+ if (src.crime) { parts.push([`Crimes:`, Money(src.crime)]) }
+ if (src.gang) { parts.push([`Gang:`, Money(src.gang)]) }
+ if (src.hacking) { parts.push([`Hacking:`, Money(src.hacking)]) }
+ if (src.hacknetnode) { parts.push([`Hacknet Nodes:`, Money(src.hacknetnode)]) }
+ if (src.hospitalization) { parts.push([`Hospitalization:`, Money(src.hospitalization)]) }
+ if (src.infiltration) { parts.push([`Infiltration:`, Money(src.infiltration)]) }
+ if (src.stock) { parts.push([`Stock Market:`, Money(src.stock)]) }
+ if (src.casino) { parts.push([`Casino:`, Money(src.casino)]) }
return StatsTable(parts, "");
}
- function openMoneyModal() {
+ function openMoneyModal(): void {
let content = (<>
Money earned since you last installed Augmentations:
{convertMoneySourceTrackerToString(p.moneySourceA)}
@@ -80,7 +80,7 @@ export function CharacterInfo(p: IPlayer): React.ReactElement {
function Intelligence(): React.ReactElement {
if (p.intelligence > 0) {
- return
+ return
Intelligence:
{numeralWrapper.formatSkill(p.intelligence)}
;
@@ -89,9 +89,9 @@ export function CharacterInfo(p: IPlayer): React.ReactElement {
}
function MultiplierTable(props: any): React.ReactElement {
- function bn5Stat(r: any) {
+ function bn5Stat(r: any): JSX.Element {
if(SourceFileFlags[5] > 0 && r.length > 2 && r[1] != r[2]) {
- return ({numeralWrapper.formatPercentage(r[2])})
+ return ({numeralWrapper.formatPercentage(r[2])})
}
return <>>;
}
@@ -99,8 +99,8 @@ export function CharacterInfo(p: IPlayer): React.ReactElement {
{props.rows.map((r: any) =>
- {`${r[0]} multiplier:`}
- {numeralWrapper.formatPercentage(r[1])}
+ {`${r[0]} multiplier:`}
+ {numeralWrapper.formatPercentage(r[1])}
{bn5Stat(r)}
)}
@@ -146,35 +146,35 @@ export function CharacterInfo(p: IPlayer): React.ReactElement {
Stats
-
- Hacking:
- {numeralWrapper.formatSkill(p.hacking_skill)}
- ({numeralWrapper.formatExp(p.hacking_exp)} exp)
+
+ Hacking:
+ {numeralWrapper.formatSkill(p.hacking_skill)}
+ ({numeralWrapper.formatExp(p.hacking_exp)} exp)
-
- Strength:
- {numeralWrapper.formatSkill(p.strength)}
- ({numeralWrapper.formatExp(p.strength_exp)} exp)
+
+ Strength:
+ {numeralWrapper.formatSkill(p.strength)}
+ ({numeralWrapper.formatExp(p.strength_exp)} exp)
-
- Defense:
- {numeralWrapper.formatSkill(p.defense)}
- ({numeralWrapper.formatExp(p.defense_exp)} exp)
+
+ Defense:
+ {numeralWrapper.formatSkill(p.defense)}
+ ({numeralWrapper.formatExp(p.defense_exp)} exp)
-
- Dexterity:
- {numeralWrapper.formatSkill(p.dexterity)}
- ({numeralWrapper.formatExp(p.dexterity_exp)} exp)
+
+ Dexterity:
+ {numeralWrapper.formatSkill(p.dexterity)}
+ ({numeralWrapper.formatExp(p.dexterity_exp)} exp)
-
- Agility:
- {numeralWrapper.formatSkill(p.agility)}
- ({numeralWrapper.formatExp(p.agility_exp)} exp)
+
+ Agility:
+ {numeralWrapper.formatSkill(p.agility)}
+ ({numeralWrapper.formatExp(p.agility_exp)} exp)
-
- Charisma:
- {numeralWrapper.formatSkill(p.charisma)}
- ({numeralWrapper.formatExp(p.charisma_exp)} exp)
+
+ Charisma:
+ {numeralWrapper.formatSkill(p.charisma)}
+ ({numeralWrapper.formatExp(p.charisma_exp)} exp)
@@ -184,7 +184,7 @@ export function CharacterInfo(p: IPlayer): React.ReactElement {
['Hacking Chance', p.hacking_chance_mult],
['Hacking Speed', p.hacking_speed_mult],
['Hacking Money', p.hacking_money_mult, p.hacking_money_mult*BitNodeMultipliers.ScriptHackMoney],
- ['Hacking Growth', p.hacking_grow_mult, p.hacking_grow_mult*BitNodeMultipliers.ServerGrowthRate]
+ ['Hacking Growth', p.hacking_grow_mult, p.hacking_grow_mult*BitNodeMultipliers.ServerGrowthRate],
]} />
Misc.
diff --git a/src/ui/MainMenu/Headers.ts b/src/ui/MainMenu/Headers.ts
index 09931f15b..6e076285f 100644
--- a/src/ui/MainMenu/Headers.ts
+++ b/src/ui/MainMenu/Headers.ts
@@ -17,8 +17,8 @@ export const MainMenuHeaders: IMainMenuHeaders = {
}
// Implements collapsible toggle feature when a header is clicked
-function toggleHeader(open: boolean, elems: HTMLElement[], links: HTMLElement[]) {
- for (var i = 0; i < elems.length; ++i) {
+function toggleHeader(open: boolean, elems: HTMLElement[], links: HTMLElement[]): void {
+ for (let i = 0; i < elems.length; ++i) {
if (open) {
elems[i].style.opacity = "1";
elems[i].style.maxHeight = elems[i].scrollHeight + "px";
@@ -28,7 +28,7 @@ function toggleHeader(open: boolean, elems: HTMLElement[], links: HTMLElement[])
}
}
- for (var i = 0; i < links.length; ++i) {
+ for (let i = 0; i < links.length; ++i) {
if (open) {
links[i].style.opacity = "1";
links[i].style.maxHeight = links[i].scrollHeight + "px";
@@ -48,7 +48,7 @@ export function initializeMainMenuHeaders(p: IPlayer, dev = false): boolean {
throw new Error(`Failed to find element with id ${id} in initializeMainMenuHeaders()`);
}
- return elem!;
+ return elem;
}
try {
@@ -71,7 +71,7 @@ export function initializeMainMenuHeaders(p: IPlayer, dev = false): boolean {
(this as any).classList.toggle("opened");
const elems: HTMLElement[] = [terminal, createScript, activeScripts, createProgram];
- const links: HTMLElement[] = [MainMenuLinks.Terminal!, MainMenuLinks.ScriptEditor!, MainMenuLinks.ActiveScripts!, MainMenuLinks.CreateProgram!];
+ const links: HTMLElement[] = [MainMenuLinks.Terminal, MainMenuLinks.ScriptEditor, MainMenuLinks.ActiveScripts, MainMenuLinks.CreateProgram];
if (terminal.style.maxHeight) {
toggleHeader(false, elems, links);
createProgramNot.style.display = "none";
@@ -93,7 +93,7 @@ export function initializeMainMenuHeaders(p: IPlayer, dev = false): boolean {
(this as any).classList.toggle("opened");
const elems: HTMLElement[] = [stats, factions, augmentations, hacknetnodes, sleeves];
- const links: HTMLElement[] = [MainMenuLinks.Stats!, MainMenuLinks.Factions!, MainMenuLinks.Augmentations!, MainMenuLinks.HacknetNodes!, MainMenuLinks.Sleeves!];
+ const links: HTMLElement[] = [MainMenuLinks.Stats, MainMenuLinks.Factions, MainMenuLinks.Augmentations, MainMenuLinks.HacknetNodes, MainMenuLinks.Sleeves];
if (stats.style.maxHeight) {
toggleHeader(false, elems, links);
} else {
@@ -120,7 +120,7 @@ export function initializeMainMenuHeaders(p: IPlayer, dev = false): boolean {
(this as any).classList.toggle("opened");
const elems: HTMLElement[] = [city, travel, job, stockmarket, bladeburner, corporation, gang];
- const links: HTMLElement[] = [MainMenuLinks.City!, MainMenuLinks.Travel!, MainMenuLinks.Job!, MainMenuLinks.StockMarket!, MainMenuLinks.Bladeburner!, MainMenuLinks.Corporation!, MainMenuLinks.Gang!];
+ const links: HTMLElement[] = [MainMenuLinks.City, MainMenuLinks.Travel, MainMenuLinks.Job, MainMenuLinks.StockMarket, MainMenuLinks.Bladeburner, MainMenuLinks.Corporation, MainMenuLinks.Gang];
if (city.style.maxHeight) {
toggleHeader(false, elems, links);
} else {
@@ -136,7 +136,7 @@ export function initializeMainMenuHeaders(p: IPlayer, dev = false): boolean {
(this as any).classList.toggle("opened");
const elems: HTMLElement[] = [milestones, tutorial, options];
- const links: HTMLElement[] = [MainMenuLinks.Milestones!, MainMenuLinks.Tutorial!, MainMenuLinks.Options!];
+ const links: HTMLElement[] = [MainMenuLinks.Milestones, MainMenuLinks.Tutorial, MainMenuLinks.Options];
if (dev) {
elems.push(safeGetElement("dev-tab"));
diff --git a/src/ui/MainMenu/Links.ts b/src/ui/MainMenu/Links.ts
index b86bd8cba..890efa405 100644
--- a/src/ui/MainMenu/Links.ts
+++ b/src/ui/MainMenu/Links.ts
@@ -3,49 +3,55 @@
import { clearEventListeners } from "../../../utils/uiHelpers/clearEventListeners";
interface IMainMenuLinks {
- Terminal: HTMLElement | null;
- ScriptEditor: HTMLElement | null;
- ActiveScripts: HTMLElement | null;
- CreateProgram: HTMLElement | null;
- Stats: HTMLElement | null;
- Factions: HTMLElement | null;
- Augmentations: HTMLElement | null;
- HacknetNodes: HTMLElement | null;
- Sleeves: HTMLElement | null;
- City: HTMLElement | null;
- Travel: HTMLElement | null;
- Job: HTMLElement | null;
- StockMarket: HTMLElement | null;
- Bladeburner: HTMLElement | null;
- Corporation: HTMLElement | null;
- Gang: HTMLElement | null;
- Milestones: HTMLElement | null;
- Tutorial: HTMLElement | null;
- Options: HTMLElement | null;
- DevMenu: HTMLElement | null;
+ Terminal: HTMLElement;
+ ScriptEditor: HTMLElement;
+ ActiveScripts: HTMLElement;
+ CreateProgram: HTMLElement;
+ Stats: HTMLElement;
+ Factions: HTMLElement;
+ Augmentations: HTMLElement;
+ HacknetNodes: HTMLElement;
+ Sleeves: HTMLElement;
+ City: HTMLElement;
+ Travel: HTMLElement;
+ Job: HTMLElement;
+ StockMarket: HTMLElement;
+ Bladeburner: HTMLElement;
+ Corporation: HTMLElement;
+ Gang: HTMLElement;
+ Milestones: HTMLElement;
+ Tutorial: HTMLElement;
+ Options: HTMLElement;
+ DevMenu: HTMLElement;
}
+const emptyElement: HTMLElement = ((): HTMLElement => {
+ const elem = document.createElement('div');
+ if(elem === null) throw new Error("unable to create empty div element");
+ return elem;
+})();
+
export const MainMenuLinks: IMainMenuLinks = {
- Terminal: null,
- ScriptEditor: null,
- ActiveScripts: null,
- CreateProgram: null,
- Stats: null,
- Factions: null,
- Augmentations: null,
- HacknetNodes: null,
- Sleeves: null,
- City: null,
- Travel: null,
- Job: null,
- StockMarket: null,
- Bladeburner: null,
- Corporation: null,
- Gang: null,
- Milestones: null,
- Tutorial: null,
- Options: null,
- DevMenu: null,
+ Terminal: emptyElement,
+ ScriptEditor: emptyElement,
+ ActiveScripts: emptyElement,
+ CreateProgram: emptyElement,
+ Stats: emptyElement,
+ Factions: emptyElement,
+ Augmentations: emptyElement,
+ HacknetNodes: emptyElement,
+ Sleeves: emptyElement,
+ City: emptyElement,
+ Travel: emptyElement,
+ Job: emptyElement,
+ StockMarket: emptyElement,
+ Bladeburner: emptyElement,
+ Corporation: emptyElement,
+ Gang: emptyElement,
+ Milestones: emptyElement,
+ Tutorial: emptyElement,
+ Options: emptyElement,
+ DevMenu: emptyElement,
}
export function initializeMainMenuLinks(): boolean {
@@ -77,7 +83,9 @@ export function initializeMainMenuLinks(): boolean {
MainMenuLinks.Gang = safeGetLink("gang-menu-link");
MainMenuLinks.Milestones = safeGetLink("milestones-menu-link");
MainMenuLinks.Tutorial = safeGetLink("tutorial-menu-link");
- MainMenuLinks.Options = document.getElementById("options-menu-link"); // This click listener is already set, so don't clear it
+ const op: HTMLElement | null = document.getElementById("options-menu-link");
+ if(op === null) throw new Error(`Could not find element with id: "options-menu-link"`);
+ MainMenuLinks.Options = op; // This click listener is already set, so don't clear it
MainMenuLinks.DevMenu = safeGetLink("dev-menu-link");
return true;
diff --git a/src/ui/React/Accordion.tsx b/src/ui/React/Accordion.tsx
index a90be06f0..d45055cfb 100644
--- a/src/ui/React/Accordion.tsx
+++ b/src/ui/React/Accordion.tsx
@@ -27,26 +27,26 @@ export class Accordion extends React.Component {
}
}
- handleHeaderClick(e: React.MouseEvent) {
+ handleHeaderClick(e: React.MouseEvent): void {
const elem = e.currentTarget;
elem.classList.toggle("active");
const panel: HTMLElement = elem.nextElementSibling as HTMLElement;
const active = elem.classList.contains("active");
if (active) {
- panel!.style.display = "block";
+ panel.style.display = "block";
this.setState({
panelOpened: true,
});
} else {
- panel!.style.display = "none";
+ panel.style.display = "none";
this.setState({
panelOpened: false,
});
}
}
- render() {
+ render(): React.ReactNode {
let className = "accordion-header";
if (typeof this.props.headerClass === "string") {
className = this.props.headerClass;
@@ -74,11 +74,11 @@ type IPanelProps = {
}
class AccordionPanel extends React.Component {
- shouldComponentUpdate(nextProps: IPanelProps) {
+ shouldComponentUpdate(nextProps: IPanelProps): boolean {
return this.props.opened || nextProps.opened;
}
- render() {
+ render(): React.ReactNode {
let className = "accordion-panel"
if (typeof this.props.panelClass === "string") {
className = this.props.panelClass;
diff --git a/src/ui/React/AccordionButton.tsx b/src/ui/React/AccordionButton.tsx
index f60c6b821..722a1c188 100644
--- a/src/ui/React/AccordionButton.tsx
+++ b/src/ui/React/AccordionButton.tsx
@@ -10,7 +10,7 @@ interface IProps {
disabled?: boolean;
id?: string;
onClick?: (e: React.MouseEvent) => any;
- style?: object;
+ style?: any;
text: string;
tooltip?: string;
}
@@ -33,11 +33,8 @@ export function AccordionButton(props: IProps): React.ReactElement {
}
// Tooltip will be set using inner HTML
- let tooltipMarkup: IInnerHTMLMarkup | null;
- if (hasTooltip) {
- tooltipMarkup = {
- __html: props.tooltip!
- }
+ const tooltipMarkup: IInnerHTMLMarkup = {
+ __html: props.tooltip ? props.tooltip : "",
}
return (
@@ -45,7 +42,7 @@ export function AccordionButton(props: IProps): React.ReactElement {
{props.text}
{
hasTooltip &&
-
+
}
)
diff --git a/src/ui/React/Augmentation.tsx b/src/ui/React/Augmentation.tsx
index 0bfeb93b3..fddbf7e41 100644
--- a/src/ui/React/Augmentation.tsx
+++ b/src/ui/React/Augmentation.tsx
@@ -1,5 +1,4 @@
import * as React from "react";
-import { numeralWrapper } from "../../ui/numeralFormat";
export function Augmentation(name: string): JSX.Element {
return {name}
diff --git a/src/ui/React/AugmentationAccordion.tsx b/src/ui/React/AugmentationAccordion.tsx
index 98b95f8f1..19eb601f2 100644
--- a/src/ui/React/AugmentationAccordion.tsx
+++ b/src/ui/React/AugmentationAccordion.tsx
@@ -12,8 +12,8 @@ import { Augmentation } from "../../Augmentation/Augmentation";
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
type IProps = {
- aug: Augmentation,
- level?: number | string | null,
+ aug: Augmentation;
+ level?: number | string | null;
}
export function AugmentationAccordion(props: IProps): React.ReactElement {
@@ -24,10 +24,19 @@ export function AugmentationAccordion(props: IProps): React.ReactElement {
}
}
+ if(typeof props.aug.info === 'string') {
+ return (
+ {displayName}>}
+ panelContent={
}
+ />
+ )
+ }
+
return (
{displayName}>}
- panelContent={
}
+ panelContent={{props.aug.info}
}
/>
)
}
diff --git a/src/ui/React/AutoupdatingParagraph.tsx b/src/ui/React/AutoupdatingParagraph.tsx
index 28e9d47c9..10572b346 100644
--- a/src/ui/React/AutoupdatingParagraph.tsx
+++ b/src/ui/React/AutoupdatingParagraph.tsx
@@ -7,7 +7,7 @@ import * as React from "react";
interface IProps {
intervalTime?: number;
- style?: object;
+ style?: any;
getContent: () => JSX.Element;
getTooltip?: () => JSX.Element;
}
@@ -16,15 +16,11 @@ interface IState {
i: number;
}
-type IInnerHTMLMarkup = {
- __html: string;
-}
-
export class AutoupdatingParagraph extends React.Component {
/**
* Timer ID for auto-updating implementation (returned value from setInterval())
*/
- interval: number = 0;
+ interval = 0;
constructor(props: IProps) {
super(props);
@@ -33,37 +29,40 @@ export class AutoupdatingParagraph extends React.Component {
}
}
- componentDidMount() {
+ componentDidMount(): void {
const time = this.props.intervalTime ? this.props.intervalTime : 1000;
this.interval = setInterval(() => this.tick(), time);
}
- componentWillUnmount() {
+ componentWillUnmount(): void {
clearInterval(this.interval);
}
- tick() {
+ tick(): void {
this.setState(prevState => ({
- i: prevState.i + 1
+ i: prevState.i + 1,
}));
}
- render() {
- let hasTooltip = this.props.getTooltip != null;
- let tooltip: JSX.Element | null;
- if (hasTooltip) {
- tooltip = this.props.getTooltip!();
- if (!tooltip) {
- hasTooltip = false;
- }
+ hasTooltip(): boolean {
+ if (this.props.getTooltip != null) {
+ return !!this.props.getTooltip()
}
+ return true;
+ }
+ tooltip(): JSX.Element {
+ if(!this.props.getTooltip) return <>>;
+ return this.props.getTooltip();
+ }
+
+ render(): React.ReactNode {
return (
{this.props.getContent()}
{
- hasTooltip &&
- {tooltip!}
+ this.hasTooltip() &&
+ {this.tooltip()}
}
)
diff --git a/src/ui/React/AutoupdatingStdButton.tsx b/src/ui/React/AutoupdatingStdButton.tsx
index ff3c5a608..bcf5b6f2f 100644
--- a/src/ui/React/AutoupdatingStdButton.tsx
+++ b/src/ui/React/AutoupdatingStdButton.tsx
@@ -10,7 +10,7 @@ interface IProps {
disabled?: boolean;
intervalTime?: number;
onClick?: (e: React.MouseEvent) => any;
- style?: object;
+ style?: any;
text: string | JSX.Element;
tooltip?: string;
}
@@ -27,7 +27,7 @@ export class AutoupdatingStdButton extends React.Component {
/**
* Timer ID for auto-updating implementation (returned value from setInterval())
*/
- interval: number = 0;
+ interval = 0;
constructor(props: IProps) {
super(props);
@@ -36,22 +36,22 @@ export class AutoupdatingStdButton extends React.Component {
}
}
- componentDidMount() {
+ componentDidMount(): void {
const time = this.props.intervalTime ? this.props.intervalTime : 1000;
this.interval = setInterval(() => this.tick(), time);
}
- componentWillUnmount() {
+ componentWillUnmount(): void {
clearInterval(this.interval);
}
- tick() {
+ tick(): void {
this.setState(prevState => ({
- i: prevState.i + 1
+ i: prevState.i + 1,
}));
}
- render() {
+ render(): React.ReactNode {
const hasTooltip = this.props.tooltip != null && this.props.tooltip !== "";
let className = this.props.disabled ? "std-button-disabled" : "std-button";
@@ -60,11 +60,8 @@ export class AutoupdatingStdButton extends React.Component {
}
// Tooltip will eb set using inner HTML
- let tooltipMarkup: IInnerHTMLMarkup | null;
- if (hasTooltip) {
- tooltipMarkup = {
- __html: this.props.tooltip!
- }
+ const tooltipMarkup: IInnerHTMLMarkup = {
+ __html: this.props.tooltip ? this.props.tooltip : "",
}
return (
@@ -72,7 +69,7 @@ export class AutoupdatingStdButton extends React.Component {
{this.props.text}
{
hasTooltip &&
-
+
}
)
diff --git a/src/ui/React/CharacterOverview.jsx b/src/ui/React/CharacterOverview.jsx
index 631145721..638da227f 100644
--- a/src/ui/React/CharacterOverview.jsx
+++ b/src/ui/React/CharacterOverview.jsx
@@ -15,8 +15,7 @@ export class CharacterOverviewComponent extends Component {
);
return (
-
-
+
Hp: {numeralWrapper.formatHp(Player.hp) + " / " + numeralWrapper.formatHp(Player.max_hp)}
@@ -47,8 +46,7 @@ export class CharacterOverviewComponent extends Component {
intelligence
}
-
-
+
)
}
}
\ No newline at end of file
diff --git a/src/ui/React/CopyableText.tsx b/src/ui/React/CopyableText.tsx
index da103505b..26ea3dc1a 100644
--- a/src/ui/React/CopyableText.tsx
+++ b/src/ui/React/CopyableText.tsx
@@ -21,7 +21,7 @@ export class CopyableText extends React.Component
{
}
}
- copy(e: React.MouseEvent) {
+ copy(): void {
const copyText = document.createElement("textarea");
copyText.value = this.props.value;
document.body.appendChild(copyText);
@@ -52,7 +52,7 @@ export class CopyableText extends React.Component {
}
- render() {
+ render(): React.ReactNode {
return (
{this.props.value}
Copied!
diff --git a/src/ui/React/CorruptableText.tsx b/src/ui/React/CorruptableText.tsx
index 4a54e0175..926e1ece6 100644
--- a/src/ui/React/CorruptableText.tsx
+++ b/src/ui/React/CorruptableText.tsx
@@ -26,7 +26,7 @@ function randomize(char: string): string {
return randFrom(other);
}
-export function CorruptableText(props: IProps) {
+export function CorruptableText(props: IProps): JSX.Element {
const [content, setContent] = useState(props.content);
useEffect(() => {
diff --git a/src/ui/React/ErrorBoundary.tsx b/src/ui/React/ErrorBoundary.tsx
index 203f0c5fe..ee65679b8 100644
--- a/src/ui/React/ErrorBoundary.tsx
+++ b/src/ui/React/ErrorBoundary.tsx
@@ -37,45 +37,40 @@ export class ErrorBoundary extends React.Component {
}
}
- static getDerivedStateFromError(error: Error) {
- return {
- errorInfo: error.message,
- hasError: true,
- };
- }
-
- componentDidCatch(error: Error, info: IErrorInfo) {
+ componentDidCatch(error: Error, info: IErrorInfo): void {
console.error(`Caught error in React ErrorBoundary. Component stack:`);
console.error(info.componentStack);
}
- componentDidMount() {
- const cb = () => {
+ componentDidMount(): void {
+ const cb = (): void => {
this.setState({
hasError: false,
});
}
if (this.hasEventEmitter()) {
- this.props.eventEmitterForReset!.addSubscriber({
+ (this.props.eventEmitterForReset as EventEmitter).addSubscriber({
cb: cb,
- id: this.props.id!,
+ id: (this.props.id as string),
});
}
}
- componentWillUnmount() {
+ componentWillUnmount(): void {
if (this.hasEventEmitter()) {
- this.props.eventEmitterForReset!.removeSubscriber(this.props.id!);
+ (this.props.eventEmitterForReset as EventEmitter).removeSubscriber((this.props.id as string));
}
}
hasEventEmitter(): boolean {
- return this.props.eventEmitterForReset instanceof EventEmitter
- && typeof this.props.id === "string";
+ return this.props.eventEmitterForReset != null &&
+ this.props.eventEmitterForReset instanceof EventEmitter &&
+ this.props.id != null &&
+ typeof this.props.id === "string";
}
- render() {
+ render(): React.ReactNode {
if (this.state.hasError) {
return (
@@ -100,4 +95,11 @@ export class ErrorBoundary extends React.Component
{
return this.props.children;
}
+
+ static getDerivedStateFromError(error: Error): IState {
+ return {
+ errorInfo: error.message,
+ hasError: true,
+ };
+ }
}
diff --git a/src/ui/React/HashRate.tsx b/src/ui/React/HashRate.tsx
index c19759c0d..88785f3dc 100644
--- a/src/ui/React/HashRate.tsx
+++ b/src/ui/React/HashRate.tsx
@@ -1,4 +1,3 @@
-import * as React from "react";
import { numeralWrapper } from "../../ui/numeralFormat";
import { Hashes } from "../../ui/React/Hashes";
diff --git a/src/ui/React/MoneyRate.tsx b/src/ui/React/MoneyRate.tsx
index e0b832675..6e03a06f5 100644
--- a/src/ui/React/MoneyRate.tsx
+++ b/src/ui/React/MoneyRate.tsx
@@ -1,4 +1,3 @@
-import * as React from "react";
import { numeralWrapper } from "../../ui/numeralFormat";
import { Money } from "../../ui/React/Money";
diff --git a/src/ui/React/ParagraphWithTooltip.tsx b/src/ui/React/ParagraphWithTooltip.tsx
index fb2af3933..288b53fee 100644
--- a/src/ui/React/ParagraphWithTooltip.tsx
+++ b/src/ui/React/ParagraphWithTooltip.tsx
@@ -4,13 +4,13 @@
import * as React from "react";
export interface IParagraphWithTooltipProps {
- style?: object;
+ style?: any;
content: JSX.Element;
tooltip: string;
}
export class ParagraphWithTooltip extends React.Component {
- render() {
+ render(): React.ReactNode {
return (
{this.props.content}
diff --git a/src/ui/React/Popup.tsx b/src/ui/React/Popup.tsx
index c296809bb..89f2a3c12 100644
--- a/src/ui/React/Popup.tsx
+++ b/src/ui/React/Popup.tsx
@@ -10,7 +10,7 @@ type ReactComponent = new(...args: any[]) => React.Component
interface IProps {
content: ReactComponent;
id: string;
- props: object;
+ props: any;
}
export function Popup(props: IProps): React.ReactElement {
diff --git a/src/ui/React/PopupCloseButton.tsx b/src/ui/React/PopupCloseButton.tsx
index dfd581926..8375fabec 100644
--- a/src/ui/React/PopupCloseButton.tsx
+++ b/src/ui/React/PopupCloseButton.tsx
@@ -14,7 +14,7 @@ import { removeElement } from "../../../utils/uiHelpers/removeElement";
export interface IPopupCloseButtonProps {
class?: string;
popup: HTMLElement | string;
- style?: object;
+ style?: any;
text: string;
}
@@ -26,15 +26,15 @@ export class PopupCloseButton extends React.Component) => any;
- style?: object;
+ style?: any;
text: string | JSX.Element;
tooltip?: string | JSX.Element;
}
@@ -33,13 +33,12 @@ export function StdButton(props: IStdButtonProps): React.ReactElement {
let tooltip;
if (hasTooltip) {
if(typeof props.tooltip === 'string') {
- let tooltipMarkup: IInnerHTMLMarkup | null;
- tooltipMarkup = {
- __html: props.tooltip!
+ const tooltipMarkup: IInnerHTMLMarkup = {
+ __html: props.tooltip,
}
- tooltip =
+ tooltip =
} else {
- tooltip = {props.tooltip!}
+ tooltip = {props.tooltip}
}
}
diff --git a/src/ui/React/StdButtonPurchased.tsx b/src/ui/React/StdButtonPurchased.tsx
index db041af0a..afdab4cba 100644
--- a/src/ui/React/StdButtonPurchased.tsx
+++ b/src/ui/React/StdButtonPurchased.tsx
@@ -5,7 +5,7 @@ import * as React from "react";
interface IStdButtonPurchasedProps {
onClick?: (e: React.MouseEvent) => any;
- style?: object;
+ style?: any;
text: string;
tooltip?: string;
}
@@ -15,18 +15,35 @@ type IInnerHTMLMarkup = {
}
export class StdButtonPurchased extends React.Component {
- render() {
- const hasTooltip = this.props.tooltip != null && this.props.tooltip !== "";
+
+ constructor(props: IStdButtonPurchasedProps) {
+ super(props);
+ this.hasTooltip = this.hasTooltip.bind(this);
+ this.tooltip = this.tooltip.bind(this);
+ }
+
+ hasTooltip(): boolean {
+ return this.props.tooltip != null && this.props.tooltip !== "";
+ }
+
+ tooltip(): string {
+ if(!this.props.tooltip) return "";
+ return this.props.tooltip;
+ }
+
+ render(): React.ReactNode {
let className = "std-button-bought";
- if (hasTooltip) {
+ if (this.hasTooltip()) {
className += " tooltip";
}
// Tooltip will be set using inner HTML
- let tooltipMarkup: IInnerHTMLMarkup | null;
- if (hasTooltip) {
+ let tooltipMarkup: IInnerHTMLMarkup = {
+ __html: "",
+ }
+ if (this.hasTooltip()) {
tooltipMarkup = {
- __html: this.props.tooltip!
+ __html: this.tooltip(),
}
}
@@ -34,8 +51,8 @@ export class StdButtonPurchased extends React.Component
{this.props.text}
{
- hasTooltip &&
-
+ this.hasTooltip() &&
+
}
)
diff --git a/src/ui/React/createPopup.tsx b/src/ui/React/createPopup.tsx
index 3f9bb5e25..0f1a7d4a3 100644
--- a/src/ui/React/createPopup.tsx
+++ b/src/ui/React/createPopup.tsx
@@ -18,8 +18,8 @@ type ReactComponent = new(...args: any[]) => React.Component;
let gameContainer: HTMLElement;
-function getGameContainer() {
- let container = document.getElementById("entire-game-container");
+function getGameContainer(): void {
+ const container = document.getElementById("entire-game-container");
if (container == null) {
throw new Error(`Failed to find game container DOM element`)
}
@@ -30,7 +30,8 @@ function getGameContainer() {
document.addEventListener("DOMContentLoaded", getGameContainer);
-export function createPopup(id: string, rootComponent: ReactComponent, props: object): HTMLElement | null {
+// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+export function createPopup(id: string, rootComponent: ReactComponent, props: any): HTMLElement | null {
let container = document.getElementById(id);
if (container == null) {
container = createElement("div", {
@@ -51,7 +52,7 @@ export function createPopup(id: string, rootComponent: ReactComponent, props: ob
* Closes a popup created with the createPopup() function above
*/
export function removePopup(id: string): void {
- let content = document.getElementById(`${id}`);
+ const content = document.getElementById(`${id}`);
if (content == null) { return; }
ReactDOM.unmountComponentAtNode(content);
diff --git a/src/ui/createStatusText.ts b/src/ui/createStatusText.ts
index 161eb047e..58ee30947 100644
--- a/src/ui/createStatusText.ts
+++ b/src/ui/createStatusText.ts
@@ -2,14 +2,14 @@ import { setTimeoutRef } from "../utils/SetTimeoutRef";
import { getElementById } from "../../utils/uiHelpers/getElementById";
import { Action } from "../types";
-const threeSeconds: number = 3000;
+const threeSeconds = 3000;
let x: number | undefined;
/**
* Displays a status message to the player for approximately 3 seconds.
* @param text The status text to display
*/
-export function createStatusText(text: string) {
+export function createStatusText(text: string): void {
if (x !== undefined) {
clearTimeout(x);
// Likely not needed due to clearTimeout, but just in case...
diff --git a/src/ui/navigationTracking.ts b/src/ui/navigationTracking.ts
index 7f448aed4..6005c7b56 100644
--- a/src/ui/navigationTracking.ts
+++ b/src/ui/navigationTracking.ts
@@ -137,7 +137,7 @@ class Routing {
* Determines if the player is currently on the specified page.
* @param page The page to compare against the current state.
*/
- isOn(page: Page) {
+ isOn(page: Page): boolean {
return this.currentPage === page;
}
@@ -145,7 +145,7 @@ class Routing {
* Routes the player to the appropriate page.
* @param page The page to navigate to.
*/
- navigateTo(page: Page) {
+ navigateTo(page: Page): void {
this.currentPage = page;
}
}
diff --git a/src/ui/numeralFormat.ts b/src/ui/numeralFormat.ts
index 3c4e7c5f9..30d55cf3c 100644
--- a/src/ui/numeralFormat.ts
+++ b/src/ui/numeralFormat.ts
@@ -53,6 +53,9 @@ class NumeralFormatter {
}
formatMoney(n: number): string {
+ if(n < 1000) {
+ return this.format(n, "$0.00");
+ }
return this.format(n, "$0.000a");
}
@@ -85,7 +88,7 @@ class NumeralFormatter {
return this.format(n, formatter);
}
- formatServerSecurity(n: number, decimalPlaces = 2): string {
+ formatServerSecurity(n: number): string {
return this.format(n, "0,0.000");
}
@@ -101,15 +104,15 @@ class NumeralFormatter {
return this.format(n, "0,0.00");
}
- formatShock(n: number): string {
+ formatSleeveShock(n: number): string {
return this.format(n, "0,0.000");
}
- formatSync(n: number): string {
+ formatSleeveSynchro(n: number): string {
return this.format(n, "0,0.000");
}
- formatMemory(n: number): string {
+ formatSleeveMemory(n: number): string {
return this.format(n, "0");
}
@@ -131,6 +134,10 @@ class NumeralFormatter {
formatInfiltrationSecurity(n: number): string {
return this.format(n, "0.000a");
}
+
+ formatThreads(n: number): string {
+ return this.format(n, "0,0");
+ }
}
export const numeralWrapper = new NumeralFormatter();
diff --git a/src/ui/postToTerminal.tsx b/src/ui/postToTerminal.tsx
index 5716e8569..7f06e03ff 100644
--- a/src/ui/postToTerminal.tsx
+++ b/src/ui/postToTerminal.tsx
@@ -1,4 +1,3 @@
-import * as React from "react";
import { renderToStaticMarkup } from "react-dom/server"
import { getElementById } from "../../utils/uiHelpers/getElementById";
@@ -6,11 +5,11 @@ import { getElementById } from "../../utils/uiHelpers/getElementById";
* Adds some output to the terminal.
* @param input Text or HTML to output to the terminal
*/
-export function post(input: string) {
+export function post(input: string): void {
postContent(input);
}
-export function postError(input: string) {
+export function postError(input: string): void {
postContent(`ERROR: ${input}`, { color: "#ff2929" });
}
@@ -18,7 +17,7 @@ export function postError(input: string) {
* Adds some output to the terminal with an identifier of "hack-progress-bar"
* @param input Text or HTML to output to the terminal
*/
-export function hackProgressBarPost(input: string) {
+export function hackProgressBarPost(input: string): void {
postContent(input, { id: "hack-progress-bar" });
}
@@ -26,7 +25,7 @@ export function hackProgressBarPost(input: string) {
* Adds some output to the terminal with an identifier of "hack-progress"
* @param input Text or HTML to output to the terminal
*/
-export function hackProgressPost(input: string) {
+export function hackProgressPost(input: string): void {
postContent(input, { id: "hack-progress" });
}
@@ -35,21 +34,21 @@ interface IPostContentConfig {
color?: string; // Additional class for terminal-line. Does NOT replace
}
-export function postElement(element: JSX.Element) {
+export function postElement(element: JSX.Element): void {
postContent(renderToStaticMarkup(element));
}
-export function postContent(input: string, config: IPostContentConfig = {}) {
+export function postContent(input: string, config: IPostContentConfig = {}): void {
// tslint:disable-next-line:max-line-length
- const style: string = `color: ${config.color != null ? config.color : "var(--my-font-color)"}; background-color:var(--my-background-color);${config.id === undefined ? " white-space:pre-wrap;" : ""}`;
+ const style = `color: ${config.color != null ? config.color : "var(--my-font-color)"}; background-color:var(--my-background-color);${config.id === undefined ? " white-space:pre-wrap;" : ""}`;
// tslint:disable-next-line:max-line-length
- const content: string = `${input} `;
+ const content = `${input} `;
const inputElement: HTMLElement = getElementById("terminal-input");
inputElement.insertAdjacentHTML("beforebegin", content);
scrollTerminalToBottom();
}
-function scrollTerminalToBottom() {
+function scrollTerminalToBottom(): void {
const container: HTMLElement = getElementById("terminal-container");
container.scrollTop = container.scrollHeight;
}
diff --git a/src/utils/EventEmitter.ts b/src/utils/EventEmitter.ts
index b513d76d5..5064ac05f 100644
--- a/src/utils/EventEmitter.ts
+++ b/src/utils/EventEmitter.ts
@@ -31,19 +31,19 @@ export class EventEmitter {
}
}
- addSubscriber(s: ISubscriber) {
+ addSubscriber(s: ISubscriber): void {
this.subscribers[s.id] = s.cb;
}
emitEvent(...args: any[]): void {
for (const s in this.subscribers) {
- const cb = this.subscribers[s];
+ const sub = this.subscribers[s];
- cb(args);
+ sub(args);
}
}
- removeSubscriber(id: string) {
+ removeSubscriber(id: string): void {
delete this.subscribers[id];
}
diff --git a/src/utils/MoneySourceTracker.ts b/src/utils/MoneySourceTracker.ts
index 66fdb18a4..891e3389f 100644
--- a/src/utils/MoneySourceTracker.ts
+++ b/src/utils/MoneySourceTracker.ts
@@ -5,6 +5,7 @@
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../utils/JSONReviver";
export class MoneySourceTracker {
+ // eslint-disable-next-line @typescript-eslint/ban-types
[key: string]: number | Function;
bladeburner = 0;
@@ -49,6 +50,7 @@ export class MoneySourceTracker {
}
// Initiatizes a MoneySourceTracker object from a JSON save state.
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
static fromJSON(value: any): MoneySourceTracker {
return Generic_fromJSON(MoneySourceTracker, value.data);
}
diff --git a/src/utils/helpers/createRandomString.ts b/src/utils/helpers/createRandomString.ts
index d963e8a41..97261a919 100644
--- a/src/utils/helpers/createRandomString.ts
+++ b/src/utils/helpers/createRandomString.ts
@@ -2,7 +2,7 @@
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
export function createRandomString(n: number): string {
- let str: string = "";
+ let str = "";
for (let i = 0; i < n; ++i) {
str += chars.charAt(Math.floor(Math.random() * chars.length));
diff --git a/stylelint.config.js b/stylelint.config.js
index 34255608b..6a3a7e05e 100644
--- a/stylelint.config.js
+++ b/stylelint.config.js
@@ -2,7 +2,7 @@
module.exports = {
plugins: [
"stylelint-declaration-use-variable",
- "stylelint-order" /*,
+ "stylelint-order", /*,
"stylelint-scss" */
],
rules: {
@@ -139,20 +139,20 @@ module.exports = {
"custom-properties",
{
type: "at-rule",
- name: "extend"
+ name: "extend",
},
{
type: "at-rule",
- name: "include"
+ name: "include",
},
"declarations",
"rules",
"at-rules",
- "less-mixins"
+ "less-mixins",
],
{
- unspecified: "bottom"
- }
+ unspecified: "bottom",
+ },
],
// "order/properties-order": [
// []
@@ -162,7 +162,7 @@ module.exports = {
"grid-area",
"grid-template",
"grid-column",
- "grid-row"
+ "grid-row",
],
"property-case": "lower",
"property-no-unknown": true,
@@ -236,7 +236,7 @@ module.exports = {
"selector-attribute-operator-space-after": "never",
"selector-attribute-operator-space-before": "never",
"selector-attribute-operator-whitelist": [
- "="
+ "=",
],
"selector-attribute-quotes": "always",
"selector-class-pattern": ".+",
@@ -264,9 +264,9 @@ module.exports = {
true,
{
ignore: [
- "attribute", "class"
- ]
- }
+ "attribute", "class",
+ ],
+ },
],
"selector-no-vendor-prefix": true,
"selector-pseudo-class-blacklist": [],
@@ -284,7 +284,7 @@ module.exports = {
"not",
"last-child",
"root",
- "visited"
+ "visited",
],
//"selector-pseudo-element-blacklist": [],
"selector-pseudo-element-case": "lower",
@@ -315,7 +315,7 @@ module.exports = {
"ms",
"s",
"vw",
- "%"
+ "%",
],
// "value-keyword-case": "lower",
"value-list-comma-newline-after": "always-multi-line",
@@ -323,6 +323,6 @@ module.exports = {
"value-list-comma-space-after": "always-single-line",
"value-list-comma-space-before": "never",
"value-list-max-empty-lines": 0,
- "value-no-vendor-prefix": true
- }
+ "value-no-vendor-prefix": true,
+ },
};
diff --git a/test/Netscript/DynamicRamCalculationTests.js b/test/Netscript/DynamicRamCalculationTests.js
index e23bc41a3..5552508f0 100644
--- a/test/Netscript/DynamicRamCalculationTests.js
+++ b/test/Netscript/DynamicRamCalculationTests.js
@@ -34,7 +34,7 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function() {
function runPotentiallyAsyncFunction(fn) {
let res = fn();
if (res instanceof Promise) {
- res.catch(() => {});
+ res.catch(() => undefined);
}
}
@@ -394,6 +394,16 @@ describe("Netscript Dynamic RAM Calculation/Generation Tests", function() {
await testNonzeroDynamicRamCost(f);
});
+ it("getServerMaxRam()", async function() {
+ const f = ["getServerMaxRam"];
+ await testNonzeroDynamicRamCost(f);
+ });
+
+ it("getServerUsedRam()", async function() {
+ const f = ["getServerUsedRam"];
+ await testNonzeroDynamicRamCost(f);
+ });
+
it("serverExists()", async function() {
const f = ["serverExists"];
await testNonzeroDynamicRamCost(f);
diff --git a/test/Netscript/StaticRamCalculationTests.js b/test/Netscript/StaticRamCalculationTests.js
index 6c59d8b7e..bd40a32c3 100644
--- a/test/Netscript/StaticRamCalculationTests.js
+++ b/test/Netscript/StaticRamCalculationTests.js
@@ -54,7 +54,6 @@ describe("Netscript Static RAM Calculation/Generation Tests", function() {
const calculated = await calculateRamUsage(code, []);
testEquality(calculated, ScriptBaseCost);
- const multipleCallsCode = code.repeat(3);
const multipleCallsCalculated = await calculateRamUsage(code, []);
expect(multipleCallsCalculated).to.equal(ScriptBaseCost);
}
@@ -285,6 +284,16 @@ describe("Netscript Static RAM Calculation/Generation Tests", function() {
await expectNonZeroRamCost(f);
});
+ it("getServerMaxRam()", async function() {
+ const f = ["getServerMaxRam"];
+ await expectNonZeroRamCost(f);
+ });
+
+ it("getServerUsedRam()", async function() {
+ const f = ["getServerUsedRam"];
+ await expectNonZeroRamCost(f);
+ });
+
it("serverExists()", async function() {
const f = ["serverExists"];
await expectNonZeroRamCost(f);
diff --git a/test/StockMarketTests.ts b/test/StockMarketTests.ts
index bd933478d..10a89f63a 100644
--- a/test/StockMarketTests.ts
+++ b/test/StockMarketTests.ts
@@ -63,7 +63,7 @@ describe("Stock Market Tests", function() {
};
beforeEach(function() {
- function construct() {
+ function construct(): void {
stock = new Stock(ctorParams);
}
@@ -73,13 +73,14 @@ describe("Stock Market Tests", function() {
describe("Stock Class", function() {
describe("constructor", function() {
it("should have default parameters", function() {
- let defaultStock: Stock;
- function construct() {
- defaultStock = new Stock();
+ function construct(): void {
+ new Stock(); // eslint-disable-line no-new
}
-
expect(construct).to.not.throw();
- expect(defaultStock!.name).to.equal("");
+
+ const defaultStock = new Stock();
+ expect(defaultStock).to.not.equal(null);
+ expect(defaultStock.name).to.equal("");
});
it("should properly initialize props from parameters", function() {
@@ -99,7 +100,6 @@ describe("Stock Market Tests", function() {
});
it ("should properly initialize props from range-values", function() {
- let stock: Stock;
const params = {
b: true,
initPrice: {
@@ -126,15 +126,18 @@ describe("Stock Market Tests", function() {
symbol: "mock",
};
- function construct() {
- stock = new Stock(params);
+ function construct(): void {
+ new Stock(params); // eslint-disable-line no-new
}
expect(construct).to.not.throw();
- expect(stock!.price).to.be.within(params.initPrice.min, params.initPrice.max);
- expect(stock!.mv).to.be.within(params.mv.min / params.mv.divisor, params.mv.max / params.mv.divisor);
- expect(stock!.spreadPerc).to.be.within(params.spreadPerc.min / params.spreadPerc.divisor, params.spreadPerc.max / params.spreadPerc.divisor);
- expect(stock!.shareTxForMovement).to.be.within(params.shareTxForMovement.min, params.shareTxForMovement.max);
+
+ const stock = new Stock(params);
+ expect(stock).not.equal(null);
+ expect(stock.price).to.be.within(params.initPrice.min, params.initPrice.max);
+ expect(stock.mv).to.be.within(params.mv.min / params.mv.divisor, params.mv.max / params.mv.divisor);
+ expect(stock.spreadPerc).to.be.within(params.spreadPerc.min / params.spreadPerc.divisor, params.spreadPerc.max / params.spreadPerc.divisor);
+ expect(stock.shareTxForMovement).to.be.within(params.shareTxForMovement.min, params.shareTxForMovement.max);
});
it("should round the 'totalShare' prop to the nearest 100k", function() {
@@ -569,17 +572,19 @@ describe("Stock Market Tests", function() {
describe("Forecast Movement Processor Function", function() {
// N = 1 is the original forecast
- function getNthForecast(origForecast: number, n: number) {
+ function getNthForecast(origForecast: number, n: number): number {
return origForecast - forecastChangePerPriceMovement * (n - 1);
}
- function getNthForecastForecast(origForecastForecast: number, n: number) {
+ function getNthForecastForecast(origForecastForecast: number, n: number): number {
if (stock.otlkMagForecast > 50) {
const expected = origForecastForecast - (forecastChangePerPriceMovement * (n - 1) * (stock.mv / 100));
return expected < 50 ? 50 : expected;
} else if (stock.otlkMagForecast < 50) {
const expected = origForecastForecast + (forecastChangePerPriceMovement * (n - 1) * (stock.mv / 100));
return expected > 50 ? 50 : expected;
+ } else {
+ return 50;
}
}
@@ -838,9 +843,10 @@ describe("Stock Market Tests", function() {
const cost = getBuyTransactionCost(stock, shares, PositionTypes.Long);
if (cost == null) {
expect.fail();
+ return;
}
- Player.setMoney(cost!);
+ Player.setMoney(cost);
expect(buyStock(stock, shares, null, suppressDialogOpt)).to.equal(true);
expect(stock.playerShares).to.equal(shares);
@@ -932,9 +938,10 @@ describe("Stock Market Tests", function() {
const cost = getBuyTransactionCost(stock, shares, PositionTypes.Short);
if (cost == null) {
expect.fail();
+ return
}
- Player.setMoney(cost!);
+ Player.setMoney(cost);
expect(shortStock(stock, shares, null, suppressDialogOpt)).to.equal(true);
expect(stock.playerShortShares).to.equal(shares);
@@ -1006,19 +1013,19 @@ describe("Stock Market Tests", function() {
describe("Order Class", function() {
it("should throw on invalid arguments", function() {
- function invalid1() {
+ function invalid1(): Order {
return new Order({} as string, 1, 1, OrderTypes.LimitBuy, PositionTypes.Long);
}
- function invalid2() {
+ function invalid2(): Order {
return new Order("FOO", "z" as any as number, 0, OrderTypes.LimitBuy, PositionTypes.Short);
}
- function invalid3() {
+ function invalid3(): Order {
return new Order("FOO", 1, {} as number, OrderTypes.LimitBuy, PositionTypes.Short);
}
- function invalid4() {
+ function invalid4(): Order {
return new Order("FOO", 1, NaN, OrderTypes.LimitBuy, PositionTypes.Short);
}
- function invalid5() {
+ function invalid5(): Order {
return new Order("FOO", NaN, 0, OrderTypes.LimitBuy, PositionTypes.Short);
}
@@ -1089,7 +1096,7 @@ describe("Stock Market Tests", function() {
shares: 1e3,
price: 9e3,
type: OrderTypes.LimitBuy,
- pos: PositionTypes.Long
+ pos: PositionTypes.Long,
});
expect(res).to.equal(true);
expect(StockMarket["Orders"][stock.symbol]).to.have.lengthOf(0);
@@ -1107,7 +1114,7 @@ describe("Stock Market Tests", function() {
shares: 999,
price: 9e3,
type: OrderTypes.LimitBuy,
- pos: PositionTypes.Long
+ pos: PositionTypes.Long,
});
expect(res2).to.equal(false);
expect(StockMarket["Orders"][stock.symbol]).to.have.lengthOf(1);
@@ -1130,20 +1137,20 @@ describe("Stock Market Tests", function() {
Player.setMoney(100e9);
processOrdersRefs = {
- rerenderFn: () => {},
+ rerenderFn: () => undefined,
stockMarket: StockMarket as IStockMarket,
symbolToStockMap: SymbolToStockMap,
};
});
- function checkThatOrderExists(placeOrderRes?: boolean) {
+ function checkThatOrderExists(placeOrderRes?: boolean): void {
if (typeof placeOrderRes === "boolean") {
expect(placeOrderRes).to.equal(true);
}
expect(StockMarket["Orders"][stock.symbol]).to.have.lengthOf(1);
}
- function checkThatOrderExecuted() {
+ function checkThatOrderExecuted(): void {
expect(StockMarket["Orders"][stock.symbol]).to.have.lengthOf(0);
}
diff --git a/test/StringHelperFunctionsTests.ts b/test/StringHelperFunctionsTests.ts
new file mode 100644
index 000000000..2e45f7845
--- /dev/null
+++ b/test/StringHelperFunctionsTests.ts
@@ -0,0 +1,11 @@
+import { expect } from "chai";
+import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions";
+
+describe("StringHelperFunctions Tests", function() {
+ expect(convertTimeMsToTimeElapsedString(1000)).to.equal("1 seconds");
+ expect(convertTimeMsToTimeElapsedString(5*60*1000+34*1000)).to.equal("5 minutes 34 seconds");
+ expect(convertTimeMsToTimeElapsedString(2*60*60*24*1000+5*60*1000+34*1000)).to.equal("2 days 5 minutes 34 seconds");
+ expect(convertTimeMsToTimeElapsedString(2*60*60*24*1000+5*60*1000+34*1000, true)).to.equal("2 days 5 minutes 34.000 seconds");
+ expect(convertTimeMsToTimeElapsedString(2*60*60*24*1000+5*60*1000+34*1000+123, true)).to.equal("2 days 5 minutes 34.123 seconds");
+ expect(convertTimeMsToTimeElapsedString(2*60*60*24*1000+5*60*1000+34*1000+123.888, true)).to.equal("2 days 5 minutes 34.123 seconds");
+})
\ No newline at end of file
diff --git a/test/Terminal/DirectoryTests.js b/test/Terminal/DirectoryTests.js
index e8516ca18..e63136626 100644
--- a/test/Terminal/DirectoryTests.js
+++ b/test/Terminal/DirectoryTests.js
@@ -286,13 +286,13 @@ describe("Terminal Directory Tests", function() {
});
describe("evaluateDirectoryPath()", function() {
- const evaluateDirectoryPath = dirHelpers.evaluateDirectoryPath;
+ //const evaluateDirectoryPath = dirHelpers.evaluateDirectoryPath;
// TODO
});
describe("evaluateFilePath()", function() {
- const evaluateFilePath = dirHelpers.evaluateFilePath;
+ //const evaluateFilePath = dirHelpers.evaluateFilePath;
// TODO
})
diff --git a/test/index.js b/test/index.js
index 68045825f..3b95de359 100644
--- a/test/index.js
+++ b/test/index.js
@@ -1,4 +1,5 @@
export * from "./Netscript/DynamicRamCalculationTests";
export * from "./Netscript/StaticRamCalculationTests";
export * from "./StockMarketTests";
+export * from "./StringHelperFunctionsTests";
export * from "./Terminal/DirectoryTests";
diff --git a/utils/DialogBox.d.ts b/utils/DialogBox.d.ts
index 7273671cb..87e1ea85a 100644
--- a/utils/DialogBox.d.ts
+++ b/utils/DialogBox.d.ts
@@ -1,2 +1,2 @@
export function dialogBoxCreate(txt: string | JSX.Element, preformatted?: boolean): void;
-export var dialogBoxOpened: boolean;
+export let dialogBoxOpened: boolean;
diff --git a/utils/DialogBox.jsx b/utils/DialogBox.jsx
index 5a93cb23f..56d5daa9c 100644
--- a/utils/DialogBox.jsx
+++ b/utils/DialogBox.jsx
@@ -31,7 +31,7 @@ function closeTopmostDialogBox() {
}
// Dialog box close buttons
-$(document).on('click', '.dialog-box-close-button', function( event ) {
+$(document).on('click', '.dialog-box-close-button', function() {
closeTopmostDialogBox();
});
diff --git a/utils/FactionInvitationBox.js b/utils/FactionInvitationBox.js
index f6ed35ab6..8150def89 100644
--- a/utils/FactionInvitationBox.js
+++ b/utils/FactionInvitationBox.js
@@ -20,11 +20,6 @@ function factionInvitationSetText(txt) {
textBox.innerHTML = txt;
}
-function factionInvitationSetMessage(msg) {
- var msgBox = document.getElementById("faction-invitation-box-message");
- msgBox.innerHTML = msg;
-}
-
//ram argument is in GB
function factionInvitationBoxCreate(faction) {
factionInvitationSetText("You have received a faction invitation from " + faction.name);
diff --git a/utils/GameOptions.js b/utils/GameOptions.js
index ad929a6cc..654a17bdf 100644
--- a/utils/GameOptions.js
+++ b/utils/GameOptions.js
@@ -23,7 +23,7 @@ function gameOptionsBoxInit() {
gameOptionsBoxClose();
return false;
});
-};
+}
document.addEventListener("DOMContentLoaded", gameOptionsBoxInit, false);
diff --git a/utils/InfiltrationBox.js b/utils/InfiltrationBox.js
index 59db25098..ab05179cc 100644
--- a/utils/InfiltrationBox.js
+++ b/utils/InfiltrationBox.js
@@ -4,7 +4,6 @@ import { formatNumber } from "./StringHelperFunctions";
import { BitNodeMultipliers } from "../src/BitNode/BitNodeMultipliers";
import { CONSTANTS } from "../src/Constants";
-import { Faction } from "../src/Faction/Faction";
import { Factions } from "../src/Faction/Factions";
import { Player } from "../src/Player";
diff --git a/utils/JSONReviver.d.ts b/utils/JSONReviver.d.ts
index f4405df83..237eb0364 100644
--- a/utils/JSONReviver.d.ts
+++ b/utils/JSONReviver.d.ts
@@ -1,10 +1,10 @@
interface IReviverValue {
ctor: string;
- data: object
+ data: any;
}
export function Generic_fromJSON(ctor: new () => T, data: any): T;
-export function Generic_toJSON(ctorName: string, obj: object, keys?: string[]): string;
+export function Generic_toJSON(ctorName: string, obj: any, keys?: string[]): string;
export function Reviver(key, value: IReviverValue);
export namespace Reviver {
- export var constructors: any;
+ export let constructors: any;
}
diff --git a/utils/JSONReviver.js b/utils/JSONReviver.js
index 8d10ceee5..b23656b86 100644
--- a/utils/JSONReviver.js
+++ b/utils/JSONReviver.js
@@ -46,7 +46,7 @@ Reviver.constructors = {}; // A list of constructors the smart reviver should kn
// Returns: The structure (which will then be turned into a string
// as part of the JSON.stringify algorithm)
function Generic_toJSON(ctorName, obj, keys) {
- var data, index, key;
+ var data, key;
if (!keys) {
keys = Object.keys(obj); // Only "own" properties are included
diff --git a/utils/LogBox.ts b/utils/LogBox.ts
index 10633e035..23fce3c59 100644
--- a/utils/LogBox.ts
+++ b/utils/LogBox.ts
@@ -42,18 +42,18 @@ function logBoxInit(): void {
logBoxClose();
document.removeEventListener("DOMContentLoaded", logBoxInit);
-};
+}
document.addEventListener("DOMContentLoaded", logBoxInit);
-function logBoxClose() {
+function logBoxClose(): void {
logBoxOpened = false;
if (logBoxContainer instanceof HTMLElement) {
logBoxContainer.style.display = "none";
}
}
-function logBoxOpen() {
+function logBoxOpen(): void {
logBoxOpened = true;
if (logBoxContainer instanceof HTMLElement) {
@@ -64,7 +64,7 @@ function logBoxOpen() {
export let logBoxOpened = false;
let logBoxCurrentScript: RunningScript | null = null;
-export function logBoxCreate(script: RunningScript) {
+export function logBoxCreate(script: RunningScript): void {
logBoxCurrentScript = script;
const killScriptBtn = clearEventListeners("log-box-kill-script");
@@ -92,7 +92,7 @@ export function logBoxCreate(script: RunningScript) {
logBoxUpdateText();
}
-export function logBoxUpdateText() {
+export function logBoxUpdateText(): void {
if (!(logText instanceof HTMLElement)) { return; }
if (logBoxCurrentScript && logBoxOpened && logBoxCurrentScript.logUpd) {
diff --git a/utils/StringHelperFunctions.ts b/utils/StringHelperFunctions.ts
index 01a69ce69..90f80fab5 100644
--- a/utils/StringHelperFunctions.ts
+++ b/utils/StringHelperFunctions.ts
@@ -13,12 +13,13 @@ Converts a date representing time in milliseconds to a string with the format H
e.g. 10000 -> "10 seconds"
120000 -> "2 minutes and 0 seconds"
*/
-function convertTimeMsToTimeElapsedString(time: number): string {
- const millisecondsPerSecond: number = 1000;
- const secondPerMinute: number = 60;
- const minutesPerHours: number = 60;
+function convertTimeMsToTimeElapsedString(time: number, showMilli=false): string {
+ time = Math.floor(time);
+ const millisecondsPerSecond = 1000;
+ const secondPerMinute = 60;
+ const minutesPerHours = 60;
const secondPerHours: number = secondPerMinute * minutesPerHours;
- const hoursPerDays: number = 24;
+ const hoursPerDays = 24;
const secondPerDay: number = secondPerHours * hoursPerDays;
// Convert ms to seconds, since we only have second-level precision
@@ -33,9 +34,15 @@ function convertTimeMsToTimeElapsedString(time: number): string {
const minutes: number = Math.floor(secTruncHours / secondPerMinute);
const secTruncMinutes: number = secTruncHours % secondPerMinute;
- const seconds: number = secTruncMinutes;
+ const milliTruncSec: string = (() => {
+ let str: string = `${time % millisecondsPerSecond}`;
+ while(str.length < 3) str = "0"+str;
+ return str;
+ })()
- let res: string = "";
+ const seconds: string = showMilli ? `${secTruncMinutes}.${milliTruncSec}` : `${secTruncMinutes}`;
+
+ let res = "";
if (days > 0) {res += `${days} days `; }
if (hours > 0) {res += `${hours} hours `; }
if (minutes > 0) {res += `${minutes} minutes `; }
@@ -54,7 +61,7 @@ function longestCommonStart(strings: string[]): string {
const a1: string = A[0];
const a2: string = A[A.length - 1];
const L: number = a1.length;
- let i: number = 0;
+ let i = 0;
const areEqualCaseInsensitive: EqualityFunc = (a: string, b: string) => a.toUpperCase() === b.toUpperCase();
while (i < L && areEqualCaseInsensitive(a1.charAt(i), a2.charAt(i))) {
i++;
@@ -92,10 +99,10 @@ function isHTML(str: string): boolean {
// Generates a random alphanumeric string with N characters
function generateRandomString(n: number): string {
- let str: string = "";
- const chars: string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ let str = "";
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- for (let i: number = 0; i < n; i++) {
+ for (let i = 0; i < n; i++) {
str += chars.charAt(Math.floor(Math.random() * chars.length));
}
diff --git a/utils/YesNoBox.ts b/utils/YesNoBox.ts
index ca1da968f..bbac42b1e 100644
--- a/utils/YesNoBox.ts
+++ b/utils/YesNoBox.ts
@@ -8,15 +8,14 @@
*/
import { clearEventListeners } from "./uiHelpers/clearEventListeners";
import { KEY } from "./helpers/keyCodes";
-import * as React from "react";
import * as ReactDOM from "react-dom";
-export let yesNoBoxOpen: boolean = false;
+export let yesNoBoxOpen = false;
const yesNoBoxContainer: HTMLElement | null = document.getElementById("yes-no-box-container");
const yesNoBoxTextElement: HTMLElement | null = document.getElementById("yes-no-box-text");
-function yesNoBoxHotkeyHandler(e: KeyboardEvent) {
+function yesNoBoxHotkeyHandler(e: KeyboardEvent): void {
if (e.keyCode === KEY.ESC) {
yesNoBoxClose();
} else if (e.keyCode === KEY.ENTER) {
@@ -43,15 +42,15 @@ export function yesNoBoxClose(): boolean {
return false; //So that 'return yesNoBoxClose()' is return false in event listeners
}
-export function yesNoBoxGetYesButton() {
+export function yesNoBoxGetYesButton(): HTMLElement | null {
return clearEventListeners("yes-no-box-yes");
}
-export function yesNoBoxGetNoButton() {
+export function yesNoBoxGetNoButton(): HTMLElement | null {
return clearEventListeners("yes-no-box-no");
}
-export function yesNoBoxCreate(txt: string | JSX.Element) {
+export function yesNoBoxCreate(txt: string | JSX.Element): boolean {
if (yesNoBoxOpen) { return false; } //Already open
yesNoBoxOpen = true;
@@ -86,7 +85,7 @@ const yesNoTextInputBoxContainer: HTMLElement | null = document.getElementById("
const yesNoTextInputBoxInput: HTMLInputElement | null = document.getElementById("yes-no-text-input-box-input") as HTMLInputElement;
const yesNoTextInputBoxTextElement: HTMLElement | null = document.getElementById("yes-no-text-input-box-text");
-export function yesNoTxtInpBoxHotkeyHandler(e: KeyboardEvent) {
+export function yesNoTxtInpBoxHotkeyHandler(e: KeyboardEvent): void {
if (e.keyCode === KEY.ESC) {
yesNoTxtInpBoxClose();
} else if (e.keyCode === KEY.ENTER) {
@@ -106,8 +105,9 @@ export function yesNoTxtInpBoxClose(): boolean {
console.error("Container not found for YesNoTextInputBox");
return false;
}
+ if(!yesNoTextInputBoxInput) throw new Error("yesNoTextInputBoxInput was not set");
yesNoBoxOpen = false;
- yesNoTextInputBoxInput!.value = "";
+ yesNoTextInputBoxInput.value = "";
// Remove hotkey handler
document.removeEventListener("keydown", yesNoTxtInpBoxHotkeyHandler);
@@ -115,25 +115,29 @@ export function yesNoTxtInpBoxClose(): boolean {
return false;
}
-export function yesNoTxtInpBoxGetYesButton(): HTMLElement | null {
- return clearEventListeners("yes-no-text-input-box-yes");
+export function yesNoTxtInpBoxGetYesButton(): HTMLElement {
+ const elem = clearEventListeners("yes-no-text-input-box-yes");
+ if(elem === null) throw new Error("Could not find element with id: 'yes-no-text-input-box-yes'");
+ return elem;
}
-export function yesNoTxtInpBoxGetNoButton(): HTMLElement | null {
- return clearEventListeners("yes-no-text-input-box-no");
+export function yesNoTxtInpBoxGetNoButton(): HTMLElement {
+ const elem = clearEventListeners("yes-no-text-input-box-no");
+ if(elem === null) throw new Error("Could not find element with id: 'yes-no-text-input-box-no'");
+ return elem;
}
export function yesNoTxtInpBoxGetInput(): string {
- if (yesNoTextInputBoxInput == null) {
+ if (!yesNoTextInputBoxInput) {
console.error("Could not find YesNoTextInputBox input element");
return "";
}
- let val: string = yesNoTextInputBoxInput!.value;
+ let val: string = yesNoTextInputBoxInput.value;
val = val.replace(/\s+/g, '');
return val;
}
-export function yesNoTxtInpBoxCreate(txt: string | JSX.Element) {
+export function yesNoTxtInpBoxCreate(txt: string | JSX.Element): void {
yesNoBoxOpen = true;
@@ -156,5 +160,6 @@ export function yesNoTxtInpBoxCreate(txt: string | JSX.Element) {
// Add event listener for Esc and Enter hotkeys
document.addEventListener("keydown", yesNoTxtInpBoxHotkeyHandler);
- yesNoTextInputBoxInput!.focus();
+ if(!yesNoTextInputBoxInput) throw new Error("yesNoTextInputBoxInput was not set");
+ yesNoTextInputBoxInput.focus();
}
diff --git a/utils/helpers/addOffset.ts b/utils/helpers/addOffset.ts
index a45ababd4..2463a8aff 100644
--- a/utils/helpers/addOffset.ts
+++ b/utils/helpers/addOffset.ts
@@ -9,8 +9,8 @@
* @param midpoint The number to be the midpoint of the offset range
* @param percentage The percentage (in a range of 0-100) to offset
*/
-export function addOffset(midpoint: number, percentage: number) {
- const maxPercent: number = 100;
+export function addOffset(midpoint: number, percentage: number): number {
+ const maxPercent = 100;
if (percentage < 0 || percentage > maxPercent) {
return midpoint;
}
diff --git a/utils/helpers/arrayToString.ts b/utils/helpers/arrayToString.ts
index 815dd4495..f301c6563 100644
--- a/utils/helpers/arrayToString.ts
+++ b/utils/helpers/arrayToString.ts
@@ -5,7 +5,7 @@
* - Adds brackets around the array
* - Adds quotation marks around strings
*/
-export function arrayToString(a: T[]) {
+export function arrayToString(a: T[]): string {
const vals: any[] = [];
for (let i = 0; i < a.length; ++i) {
let elem: any = a[i];
diff --git a/utils/helpers/clearObject.ts b/utils/helpers/clearObject.ts
index fec858b20..57a92b6f4 100644
--- a/utils/helpers/clearObject.ts
+++ b/utils/helpers/clearObject.ts
@@ -4,7 +4,8 @@
* @deprecated Look into using `Map` or `Set` rather than manipulating properties on an Object.
* @param obj the object to clear all properties
*/
-export function clearObject(obj: any) {
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+export function clearObject(obj: any): void {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
// tslint:disable-next-line:no-dynamic-delete
diff --git a/utils/helpers/compareArrays.ts b/utils/helpers/compareArrays.ts
index 257b2912a..8b88caf13 100644
--- a/utils/helpers/compareArrays.ts
+++ b/utils/helpers/compareArrays.ts
@@ -4,7 +4,7 @@
* @param a1 The first array
* @param a2 The second array
*/
-export function compareArrays(a1: T[], a2: T[]) {
+export function compareArrays(a1: T[], a2: T[]): boolean {
if (a1.length !== a2.length) {
return false;
}
diff --git a/utils/helpers/createProgressBarText.ts b/utils/helpers/createProgressBarText.ts
index 37f433a00..2107de5eb 100644
--- a/utils/helpers/createProgressBarText.ts
+++ b/utils/helpers/createProgressBarText.ts
@@ -26,7 +26,7 @@ interface IProgressBarConfigurationMaterialized extends IProgressBarConfiguratio
* e.g.: [||||---------------]
* @param params The configuration parameters for the progress bar
*/
-export function createProgressBarText(params: IProgressBarConfiguration) {
+export function createProgressBarText(params: IProgressBarConfiguration): string {
// Default values
const defaultParams: IProgressBarConfigurationMaterialized = {
progress: 0,
diff --git a/utils/helpers/exceptionAlert.ts b/utils/helpers/exceptionAlert.ts
index 2a6998c89..5130b2fb5 100644
--- a/utils/helpers/exceptionAlert.ts
+++ b/utils/helpers/exceptionAlert.ts
@@ -1,8 +1,8 @@
import { dialogBoxCreate } from "../DialogBox";
interface IError {
- fileName?: string,
- lineNumber?: number,
+ fileName?: string;
+ lineNumber?: number;
}
export function exceptionAlert(e: IError): void {
diff --git a/utils/helpers/getRandomByte.ts b/utils/helpers/getRandomByte.ts
index 5b6ddf57d..954d45d83 100644
--- a/utils/helpers/getRandomByte.ts
+++ b/utils/helpers/getRandomByte.ts
@@ -4,9 +4,9 @@ import { getRandomInt } from "./getRandomInt";
* Gets a random value in the range of a byte (0 - 255), or up to the maximum.
* @param max The maximum value (up to 255).
*/
-export function getRandomByte(max: number) {
+export function getRandomByte(max: number): number {
// Technically 2^8 is 256, but the values are 0-255, not 1-256.
- const byteMaximum: number = 255;
+ const byteMaximum = 255;
const upper: number = Math.max(Math.min(max, byteMaximum), 0);
return getRandomInt(0, upper);
diff --git a/utils/helpers/getRandomInt.ts b/utils/helpers/getRandomInt.ts
index 4f5dc15b5..1dc4956f1 100644
--- a/utils/helpers/getRandomInt.ts
+++ b/utils/helpers/getRandomInt.ts
@@ -3,7 +3,7 @@
* @param min The minimum value in the range.
* @param max The maximum value in the range.
*/
-export function getRandomInt(min: number, max: number) {
+export function getRandomInt(min: number, max: number): number {
const lower: number = Math.min(min, max);
const upper: number = Math.max(min, max);
diff --git a/utils/helpers/getTimestamp.ts b/utils/helpers/getTimestamp.ts
index 6e7ee119f..bd523f727 100644
--- a/utils/helpers/getTimestamp.ts
+++ b/utils/helpers/getTimestamp.ts
@@ -1,10 +1,10 @@
/**
* Returns a MM/DD HH:MM timestamp for the current time
*/
-export function getTimestamp() {
+export function getTimestamp(): string {
const d: Date = new Date();
// A negative slice value takes from the end of the string rather than the beginning.
- const stringWidth: number = -2;
+ const stringWidth = -2;
const formattedHours: string = `0${d.getHours()}`.slice(stringWidth);
const formattedMinutes: string = `0${d.getMinutes()}`.slice(stringWidth);
diff --git a/utils/helpers/isPowerOfTwo.ts b/utils/helpers/isPowerOfTwo.ts
index 6f98ccf83..c0822c704 100644
--- a/utils/helpers/isPowerOfTwo.ts
+++ b/utils/helpers/isPowerOfTwo.ts
@@ -2,7 +2,7 @@
* Determines if the number is a power of 2
* @param n The number to check.
*/
-export function isPowerOfTwo(n: number) {
+export function isPowerOfTwo(n: number): boolean {
if (isNaN(n)) {
return false;
}
diff --git a/utils/helpers/isString.ts b/utils/helpers/isString.ts
index 5d24bc197..204d42427 100644
--- a/utils/helpers/isString.ts
+++ b/utils/helpers/isString.ts
@@ -2,6 +2,7 @@
* Checks whether the value passed in can be considered a string.
* @param value The value to check if it is a string.
*/
+// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function isString(value: any): boolean {
return (typeof value === "string" || value instanceof String);
}
diff --git a/utils/helpers/isValidIPAddress.ts b/utils/helpers/isValidIPAddress.ts
index 67b40257f..47afdbb43 100644
--- a/utils/helpers/isValidIPAddress.ts
+++ b/utils/helpers/isValidIPAddress.ts
@@ -3,10 +3,10 @@
* Checks whether a IP Address string is valid.
* @param ipaddress A string representing a potential IP Address
*/
-export function isValidIPAddress(ipaddress: string) {
- const byteRange: string = "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
- const regexStr: string = `^${byteRange}\.${byteRange}\.${byteRange}\.${byteRange}$`;
- const ipAddressRegex: RegExp = new RegExp(regexStr);
+export function isValidIPAddress(ipaddress: string): boolean {
+ const byteRange = "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
+ const regexStr = `^${byteRange}\.${byteRange}\.${byteRange}\.${byteRange}$`;
+ const ipAddressRegex = new RegExp(regexStr);
return ipAddressRegex.test(ipaddress);
}
diff --git a/utils/helpers/roundToTwo.ts b/utils/helpers/roundToTwo.ts
index 33053ec61..a7fa1c2fb 100644
--- a/utils/helpers/roundToTwo.ts
+++ b/utils/helpers/roundToTwo.ts
@@ -2,7 +2,7 @@
* Rounds a number to two decimal places.
* @param decimal A decimal value to trim to two places.
*/
-export function roundToTwo(decimal: number) {
+export function roundToTwo(decimal: number): number {
const leftShift: number = Math.round(parseFloat(`${decimal}e+2`));
return +(`${leftShift}e-2`);
diff --git a/utils/uiHelpers/appendLineBreaks.ts b/utils/uiHelpers/appendLineBreaks.ts
index f2895c536..02ac2ca1e 100644
--- a/utils/uiHelpers/appendLineBreaks.ts
+++ b/utils/uiHelpers/appendLineBreaks.ts
@@ -5,8 +5,8 @@ import { createElement } from "./createElement";
* @param el The element to add child break elements to.
* @param n The number of breaks to add.
*/
-export function appendLineBreaks(el: HTMLElement, n: number) {
- for (let i: number = 0; i < n; ++i) {
+export function appendLineBreaks(el: HTMLElement, n: number): void {
+ for (let i = 0; i < n; ++i) {
el.appendChild(createElement("br"));
}
}
diff --git a/utils/uiHelpers/clearSelector.ts b/utils/uiHelpers/clearSelector.ts
index 39e087bc0..887f72a53 100644
--- a/utils/uiHelpers/clearSelector.ts
+++ b/utils/uiHelpers/clearSelector.ts
@@ -2,7 +2,7 @@
* Clears all elements from a .
* @param selector The element
*/
-export function clearSelector(selector: HTMLSelectElement) {
+export function clearSelector(selector: HTMLSelectElement): void {
for (let i: number = selector.options.length - 1; i >= 0; i--) {
selector.remove(i);
}
diff --git a/utils/uiHelpers/createAccordionElement.ts b/utils/uiHelpers/createAccordionElement.ts
index d3baf6f8b..c66b5d792 100644
--- a/utils/uiHelpers/createAccordionElement.ts
+++ b/utils/uiHelpers/createAccordionElement.ts
@@ -24,7 +24,7 @@ interface IAccordionConfigurationParameters {
* Creates both the header and panel element of an accordion and sets the click handler
* @param params The creation parameters.
*/
-export function createAccordionElement(params: IAccordionConfigurationParameters) {
+export function createAccordionElement(params: IAccordionConfigurationParameters): any[] {
const liElem: HTMLLIElement = createElement("li") as HTMLLIElement;
const header: HTMLButtonElement = createElement("button", {
class: "accordion-header",
diff --git a/utils/uiHelpers/createElement.ts b/utils/uiHelpers/createElement.ts
index 776ee2586..7e6225fbc 100644
--- a/utils/uiHelpers/createElement.ts
+++ b/utils/uiHelpers/createElement.ts
@@ -99,7 +99,7 @@ interface ICreateElementOptions extends
tabIndex?: number;
}
-function setElementAnchor(el: HTMLAnchorElement, params: ICreateElementAnchorOptions) {
+function setElementAnchor(el: HTMLAnchorElement, params: ICreateElementAnchorOptions): void {
if (params.text !== undefined) {
el.text = params.text;
}
@@ -111,7 +111,7 @@ function setElementAnchor(el: HTMLAnchorElement, params: ICreateElementAnchorOpt
}
}
-function setElementInput(el: HTMLInputElement, params: ICreateElementInputOptions) {
+function setElementInput(el: HTMLInputElement, params: ICreateElementInputOptions): void {
if (params.name !== undefined) {
el.name = params.name;
}
@@ -144,13 +144,13 @@ function setElementInput(el: HTMLInputElement, params: ICreateElementInputOption
}
}
-function setElementLabel(el: HTMLLabelElement, params: ICreateElementLabelOptions) {
+function setElementLabel(el: HTMLLabelElement, params: ICreateElementLabelOptions): void {
if (params.for !== undefined) {
el.htmlFor = params.for;
}
}
-function setElementListeners(el: HTMLElement, params: ICreateElementListenerOptions) {
+function setElementListeners(el: HTMLElement, params: ICreateElementListenerOptions): void {
// tslint:disable:no-unbound-method
if (params.clickListener !== undefined) {
el.addEventListener("click", params.clickListener);
@@ -173,7 +173,7 @@ function setElementListeners(el: HTMLElement, params: ICreateElementListenerOpti
// tslint:enable:no-unbound-method
}
-function setElementStyle(el: HTMLElement, params: ICreateElementStyleOptions) {
+function setElementStyle(el: HTMLElement, params: ICreateElementStyleOptions): void {
if (params.display !== undefined) {
el.style.display = params.display;
}
@@ -221,7 +221,7 @@ function setElementStyle(el: HTMLElement, params: ICreateElementStyleOptions) {
}
}
-function setElementTooltip(el: HTMLElement, params: ICreateElementTooltipOptions) {
+function setElementTooltip(el: HTMLElement, params: ICreateElementTooltipOptions): void {
if (params.tooltip !== undefined && params.tooltip !== "") {
el.className += " tooltip";
el.appendChild(createElement("span", {
@@ -254,7 +254,7 @@ function setElementTooltip(el: HTMLElement, params: ICreateElementTooltipOptions
* @param tagName The HTML tag/element name
* @param params Additional parameters to set on the element
*/
-export function createElement(tagName: string, params: ICreateElementOptions = {}) {
+export function createElement(tagName: string, params: ICreateElementOptions = {}): HTMLElement {
const el: HTMLElement = document.createElement(tagName);
if (params.id !== undefined) {
diff --git a/utils/uiHelpers/createOptionElement.ts b/utils/uiHelpers/createOptionElement.ts
index cbd09f8ba..85ef37743 100644
--- a/utils/uiHelpers/createOptionElement.ts
+++ b/utils/uiHelpers/createOptionElement.ts
@@ -1,6 +1,6 @@
import { createElement } from "./createElement";
-export function createOptionElement(text: string, value: string=""): HTMLOptionElement {
+export function createOptionElement(text: string, value=""): HTMLOptionElement {
let sanitizedValue: string = value;
if (sanitizedValue === "") { sanitizedValue = text; }
diff --git a/utils/uiHelpers/createPopup.ts b/utils/uiHelpers/createPopup.ts
index dd791a168..ac9b91545 100644
--- a/utils/uiHelpers/createPopup.ts
+++ b/utils/uiHelpers/createPopup.ts
@@ -11,7 +11,7 @@ interface ICreatePopupOptions {
* @param id The (hopefully) unique identifier for the popup container.
* @param elems The collection of HTML Elements to show within the popup.
*/
-export function createPopup(id: string, elems: HTMLElement[], options: ICreatePopupOptions={}) {
+export function createPopup(id: string, elems: HTMLElement[], options: ICreatePopupOptions={}): HTMLDivElement {
const container: HTMLDivElement = createElement("div", {
class: "popup-box-container",
display: "flex",
diff --git a/utils/uiHelpers/createPopupCloseButton.ts b/utils/uiHelpers/createPopupCloseButton.ts
index 22c34bcd7..6fc16e960 100644
--- a/utils/uiHelpers/createPopupCloseButton.ts
+++ b/utils/uiHelpers/createPopupCloseButton.ts
@@ -12,8 +12,12 @@ interface ICreatePopupCloseButtonOptions {
type?: string;
}
-export function createPopupCloseButton(popup: Element | string, options: ICreatePopupCloseButtonOptions) {
- let button: HTMLButtonElement;
+export function createPopupCloseButton(popup: Element | string, options: ICreatePopupCloseButtonOptions): HTMLButtonElement {
+ const button = createElement("button", {
+ class: options.class ? options.class : "popup-box-button",
+ display: options.display ? options.display : "inline-block",
+ innerText: options.innerText == null ? "Cancel" : options.innerText,
+ }) as HTMLButtonElement;
function closePopupWithEscFn(e: any): void {
if (e.keyCode === 27) {
@@ -21,28 +25,23 @@ export function createPopupCloseButton(popup: Element | string, options: ICreate
}
}
- button = createElement("button", {
- class: options.class ? options.class : "popup-box-button",
- display: options.display ? options.display : "inline-block",
- innerText: options.innerText == null ? "Cancel" : options.innerText,
- clickListener: () => {
- if (popup instanceof Element) {
- removeElement(popup);
- } else {
- try {
- const popupEl = document.getElementById(popup);
- if (popupEl instanceof Element) {
- removeElement(popupEl);
- }
- } catch(e) {
- console.error(`createPopupCloseButton() threw: ${e}`);
+ button.addEventListener("click", () => {
+ if (popup instanceof Element) {
+ removeElement(popup);
+ } else {
+ try {
+ const popupEl = document.getElementById(popup);
+ if (popupEl instanceof Element) {
+ removeElement(popupEl);
}
+ } catch(e) {
+ console.error(`createPopupCloseButton() threw: ${e}`);
}
+ }
- document.removeEventListener("keydown", closePopupWithEscFn);
- return false;
- },
- }) as HTMLButtonElement;
+ document.removeEventListener("keydown", closePopupWithEscFn);
+ return false;
+ });
document.addEventListener("keydown", closePopupWithEscFn);
diff --git a/utils/uiHelpers/getElementById.ts b/utils/uiHelpers/getElementById.ts
index 6ecfc5afb..3bc9d6c34 100644
--- a/utils/uiHelpers/getElementById.ts
+++ b/utils/uiHelpers/getElementById.ts
@@ -4,7 +4,7 @@
* @param elementId The HTML ID to retrieve the element by.
* @throws {Error} When the 'elementId' cannot be found.
*/
-export function getElementById(elementId: string) {
+export function getElementById(elementId: string): HTMLElement {
const el: HTMLElement | null = document.getElementById(elementId);
if (el === null) {
throw new Error(`Unable to find element with id '${elementId}'`);
diff --git a/utils/uiHelpers/removeChildrenFromElement.ts b/utils/uiHelpers/removeChildrenFromElement.ts
index 410d7a927..4040ade69 100644
--- a/utils/uiHelpers/removeChildrenFromElement.ts
+++ b/utils/uiHelpers/removeChildrenFromElement.ts
@@ -6,7 +6,7 @@ import { getElementById } from "./getElementById";
* If a string is passed in, it will treat it as an ID and search for the element to delete all children from.
* @param el The element or ID of an element to remove all children from.
*/
-export function removeChildrenFromElement(el: string | null | Element) {
+export function removeChildrenFromElement(el: string | null | Element): void {
if (el === null) {
return;
}
diff --git a/utils/uiHelpers/removeElement.ts b/utils/uiHelpers/removeElement.ts
index 6f75ff025..e25781ed6 100644
--- a/utils/uiHelpers/removeElement.ts
+++ b/utils/uiHelpers/removeElement.ts
@@ -2,7 +2,7 @@
* For a given element, this function removes it AND its children
* @param elem The element to remove.
*/
-export function removeElement(elem: Element | null) {
+export function removeElement(elem: Element | null): void {
if (elem === null) {
// tslint:disable-next-line:no-console
console.debug("The element passed into 'removeElement' was null.");
diff --git a/utils/uiHelpers/removeElementById.ts b/utils/uiHelpers/removeElementById.ts
index f0fe4125b..893e3b21f 100644
--- a/utils/uiHelpers/removeElementById.ts
+++ b/utils/uiHelpers/removeElementById.ts
@@ -5,7 +5,7 @@ import { removeElement } from "./removeElement";
* Given its id, this function removes an element AND its children
* @param id The HTML identifier to search for and remove.
*/
-export function removeElementById(id: string) {
+export function removeElementById(id: string): void {
try {
const elem: HTMLElement = getElementById(id);
removeElement(elem);
diff --git a/utils/uiHelpers/removeLoadingScreen.ts b/utils/uiHelpers/removeLoadingScreen.ts
index 00675af34..0d800a672 100644
--- a/utils/uiHelpers/removeLoadingScreen.ts
+++ b/utils/uiHelpers/removeLoadingScreen.ts
@@ -4,7 +4,7 @@ import { removeElementById } from "./removeElementById";
/**
* Routes the player from the Loading screen to the main game content.
*/
-export function removeLoadingScreen() {
+export function removeLoadingScreen(): void {
// TODO: Have this manipulate CSS classes instead of direct styles
removeElementById("loader");
getElementById("entire-game-container").style.visibility = "visible";
diff --git a/webpack.config-test.js b/webpack.config-test.js
index 106bc7afa..72cf7b365 100644
--- a/webpack.config-test.js
+++ b/webpack.config-test.js
@@ -3,10 +3,8 @@
*/
var path = require('path');
var webpack = require('webpack');
-var MiniCssExtractPlugin = require('mini-css-extract-plugin');
-var HtmlWebpackPlugin = require('html-webpack-plugin');
-module.exports = (env, argv) => {
+module.exports = () => {
const statsConfig = {
builtAt: true,
children: false,
@@ -21,7 +19,7 @@ module.exports = (env, argv) => {
return {
plugins: [
new webpack.DefinePlugin({
- 'process.env.NODE_ENV': "\"development\""
+ 'process.env.NODE_ENV': "\"development\"",
}),
new webpack.ProvidePlugin({
// Automtically detect jQuery and $ as free var in modules
@@ -30,7 +28,7 @@ module.exports = (env, argv) => {
// http://stackoverflow.com/questions/29080148/expose-jquery-to-real-window-object-with-webpack
jquery: "jquery",
jQuery: "jquery",
- $: "jquery"
+ $: "jquery",
}),
],
entry: "./test/index.js",
@@ -45,20 +43,20 @@ module.exports = (env, argv) => {
{
test: /\.tsx?$/,
loader: 'ts-loader',
- exclude: /node_modules/
+ exclude: /node_modules/,
},
{
test: /\.(jsx)$/,
exclude: /node_modules/,
use: {
- loader: "babel-loader"
- }
+ loader: "babel-loader",
+ },
},
{
test: /\.s?css$/,
loader: 'null-loader',
},
- ]
+ ],
},
optimization: {
removeAvailableModules: true,
@@ -79,10 +77,10 @@ module.exports = (env, argv) => {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: `tests/vendor`,
- chunks: 'all'
- }
- }
- }
+ chunks: 'all',
+ },
+ },
+ },
},
resolve: {
extensions: [
@@ -90,7 +88,7 @@ module.exports = (env, argv) => {
".ts",
".js",
".jsx",
- ]
+ ],
},
stats: statsConfig,
};
diff --git a/webpack.config.js b/webpack.config.js
index 4b95407c6..da342707b 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -25,7 +25,7 @@ module.exports = (env, argv) => {
return {
plugins: [
new webpack.DefinePlugin({
- 'process.env.NODE_ENV': isDevelopment ? "\"development\"" : "\"production\""
+ 'process.env.NODE_ENV': isDevelopment ? "\"development\"" : "\"production\"",
}),
// http://stackoverflow.com/questions/29080148/expose-jquery-to-real-window-object-with-webpack
new webpack.ProvidePlugin({
@@ -34,14 +34,14 @@ module.exports = (env, argv) => {
// This is required by many jquery plugins
jquery: "jquery",
jQuery: "jquery",
- $: "jquery"
+ $: "jquery",
}),
new HtmlWebpackPlugin({
title: "Bitburner" + (isDevelopment ? ' - development' : ""),
template: "src/index.html",
favicon: "favicon.ico",
googleAnalytics: {
- trackingId: 'UA-100157497-1'
+ trackingId: 'UA-100157497-1',
},
meta: {},
minify: isDevelopment ? false : {
@@ -69,43 +69,43 @@ module.exports = (env, argv) => {
removeTagWhitespace: false,
sortAttributes: false,
sortClassName: false,
- useShortDoctype: false
+ useShortDoctype: false,
},
}),
new MiniCssExtractPlugin({
- filename: "[name].css"
- })
+ filename: "[name].css",
+ }),
],
target: "web",
entry: entries,
devtool: "source-map",
output: {
path: path.resolve(__dirname, "./"),
- filename: "[name].bundle.js"
+ filename: "[name].bundle.js",
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
- exclude: /node_modules/
+ exclude: /node_modules/,
},
{
test: /\.(jsx)$/,
exclude: /node_modules/,
use: {
- loader: "babel-loader"
- }
+ loader: "babel-loader",
+ },
},
{
test: /\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
- "sass-loader"
- ]
+ "sass-loader",
+ ],
},
- ]
+ ],
},
optimization: {
removeAvailableModules: true,
@@ -126,10 +126,10 @@ module.exports = (env, argv) => {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: `${outputDirectory}/vendor`,
- chunks: 'all'
- }
- }
- }
+ chunks: 'all',
+ },
+ },
+ },
},
devServer: {
port: 8000,
@@ -142,7 +142,7 @@ module.exports = (env, argv) => {
".ts",
".js",
".jsx",
- ]
+ ],
},
stats: statsConfig,
};