mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-22 06:02:26 +01:00
Merge pull request #344 from kopelli/lint-cleanup
[style] Cleaning up TSLint violations
This commit is contained in:
commit
300cd01cc8
@ -1,12 +1,47 @@
|
|||||||
// Contains the "information" property for all the Factions, which is just a description of each faction
|
import { IMap } from "./types";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains the "information" property for all the Factions, which is just a description of each faction
|
||||||
|
*/
|
||||||
class FactionInfo {
|
class FactionInfo {
|
||||||
|
/**
|
||||||
|
* The multiplier to apply to augmentation base purchase price.
|
||||||
|
*/
|
||||||
augmentationPriceMult: number;
|
augmentationPriceMult: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The multiplier to apply to augmentation reputation base requirement.
|
||||||
|
*/
|
||||||
augmentationRepRequirementMult: number;
|
augmentationRepRequirementMult: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The names of all other factions considered to be enemies to this faction.
|
||||||
|
*/
|
||||||
enemies: string[];
|
enemies: string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The descriptive text to show on the faction's page.
|
||||||
|
*/
|
||||||
infoText: string;
|
infoText: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A flag indicating if the faction supports field work to earn reputation.
|
||||||
|
*/
|
||||||
offerFieldWork: boolean;
|
offerFieldWork: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A flag indicating if the faction supports hacking missions to earn reputation.
|
||||||
|
*/
|
||||||
offerHackingMission: boolean;
|
offerHackingMission: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A flag indicating if the faction supports hacking work to earn reputation.
|
||||||
|
*/
|
||||||
offerHackingWork: boolean;
|
offerHackingWork: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A flag indicating if the faction supports security work to earn reputation.
|
||||||
|
*/
|
||||||
offerSecurityWork: boolean;
|
offerSecurityWork: boolean;
|
||||||
|
|
||||||
constructor(infoText: string, enemies: string[], offerHackingMission: boolean, offerHackingWork: boolean,
|
constructor(infoText: string, enemies: string[], offerHackingMission: boolean, offerHackingWork: boolean,
|
||||||
@ -24,7 +59,11 @@ class FactionInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const FactionInfos = {
|
/**
|
||||||
|
* A map of all factions and associated info to them.
|
||||||
|
*/
|
||||||
|
// tslint:disable-next-line:variable-name
|
||||||
|
export const FactionInfos: IMap<FactionInfo> = {
|
||||||
// Endgame
|
// Endgame
|
||||||
Illuminati: new FactionInfo("Humanity never changes. No matter how civilized society becomes, it will eventually" +
|
Illuminati: new FactionInfo("Humanity never changes. No matter how civilized society becomes, it will eventually" +
|
||||||
"fall back into chaos. And from this chaos, we are the Invisible hand that guides them to order. ",
|
"fall back into chaos. And from this chaos, we are the Invisible hand that guides them to order. ",
|
||||||
@ -189,5 +228,3 @@ const FactionInfos = {
|
|||||||
"Bladeburner contracts/operations will increase your reputation.",
|
"Bladeburner contracts/operations will increase your reputation.",
|
||||||
[], false, false, false, false),
|
[], false, false, false, false),
|
||||||
};
|
};
|
||||||
|
|
||||||
export {FactionInfos};
|
|
||||||
|
11
src/types.ts
Normal file
11
src/types.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* Performs an equality check between two instances of the same type.
|
||||||
|
*/
|
||||||
|
export type EqualityFunc<T> = (a: T, b: T) => boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A map is an object that holds a mapping between string keys and some consistent type.
|
||||||
|
*/
|
||||||
|
export interface IMap<T> {
|
||||||
|
[key: string]: T;
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
import { EqualityFunc } from "../src/types";
|
||||||
import { dialogBoxCreate } from "./DialogBox";
|
import { dialogBoxCreate } from "./DialogBox";
|
||||||
|
|
||||||
// Netburner String helper functions
|
// Netburner String helper functions
|
||||||
@ -13,11 +14,11 @@ e.g. 10000 -> "0 hours 0 minutes and 10 seconds"
|
|||||||
120000 -> "0 0 hours 2 minutes and 0 seconds"
|
120000 -> "0 0 hours 2 minutes and 0 seconds"
|
||||||
*/
|
*/
|
||||||
function convertTimeMsToTimeElapsedString(time: number): string {
|
function convertTimeMsToTimeElapsedString(time: number): string {
|
||||||
const millisecondsPerSecond = 1000;
|
const millisecondsPerSecond: number = 1000;
|
||||||
const secondPerMinute = 60;
|
const secondPerMinute: number = 60;
|
||||||
const minutesPerHours = 60;
|
const minutesPerHours: number = 60;
|
||||||
const secondPerHours: number = secondPerMinute * minutesPerHours;
|
const secondPerHours: number = secondPerMinute * minutesPerHours;
|
||||||
const hoursPerDays = 24;
|
const hoursPerDays: number = 24;
|
||||||
const secondPerDay: number = secondPerHours * hoursPerDays;
|
const secondPerDay: number = secondPerHours * hoursPerDays;
|
||||||
|
|
||||||
// Convert ms to seconds, since we only have second-level precision
|
// Convert ms to seconds, since we only have second-level precision
|
||||||
@ -34,10 +35,10 @@ function convertTimeMsToTimeElapsedString(time: number): string {
|
|||||||
|
|
||||||
const seconds: number = secTruncMinutes;
|
const seconds: number = secTruncMinutes;
|
||||||
|
|
||||||
let res = "";
|
let res: string = "";
|
||||||
if (days) {res += `${days} days `; }
|
if (days > 0) {res += `${days} days `; }
|
||||||
if (hours) {res += `${hours} hours `; }
|
if (hours > 0) {res += `${hours} hours `; }
|
||||||
if (minutes) {res += `${minutes} minutes `; }
|
if (minutes > 0) {res += `${minutes} minutes `; }
|
||||||
res += `${seconds} seconds `;
|
res += `${seconds} seconds `;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -46,14 +47,18 @@ function convertTimeMsToTimeElapsedString(time: number): string {
|
|||||||
// Finds the longest common starting substring in a set of strings
|
// Finds the longest common starting substring in a set of strings
|
||||||
function longestCommonStart(strings: string[]): string {
|
function longestCommonStart(strings: string[]): string {
|
||||||
if (!containsAllStrings(strings)) {return ""; }
|
if (!containsAllStrings(strings)) {return ""; }
|
||||||
if (strings.length == 0) {return ""; }
|
if (strings.length === 0) {return ""; }
|
||||||
|
|
||||||
const A: string[] = strings.concat().sort();
|
const A: string[] = strings.concat()
|
||||||
|
.sort();
|
||||||
const a1: string = A[0];
|
const a1: string = A[0];
|
||||||
const a2: string = A[A.length - 1];
|
const a2: string = A[A.length - 1];
|
||||||
const L: number = a1.length;
|
const L: number = a1.length;
|
||||||
let i = 0;
|
let i: number = 0;
|
||||||
while (i < L && a1.charAt(i).toLowerCase() === a2.charAt(i).toLowerCase()) { i++; }
|
const areEqualCaseInsensitive: EqualityFunc<string> = (a: string, b: string) => a.toUpperCase() === b.toUpperCase();
|
||||||
|
while (i < L && areEqualCaseInsensitive(a1, a2)) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
return a1.substring(0, i);
|
return a1.substring(0, i);
|
||||||
}
|
}
|
||||||
@ -78,16 +83,16 @@ function formatNumber(num: number, numFractionDigits: number): string {
|
|||||||
|
|
||||||
// Count the number of times a substring occurs in a string
|
// Count the number of times a substring occurs in a string
|
||||||
function numOccurrences(text: string, subString: string): number {
|
function numOccurrences(text: string, subString: string): number {
|
||||||
text += "";
|
const input: string = `${text}`;
|
||||||
subString += "";
|
const search: string = `${subString}`;
|
||||||
if (subString.length <= 0) { return (text.length + 1); }
|
if (search.length <= 0) { return (input.length + 1); }
|
||||||
|
|
||||||
let n = 0;
|
let n: number = 0;
|
||||||
let pos = 0;
|
let pos: number = 0;
|
||||||
const step: number = subString.length;
|
const step: number = search.length;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
pos = text.indexOf(subString, pos);
|
pos = input.indexOf(search, pos);
|
||||||
if (pos >= 0) {
|
if (pos >= 0) {
|
||||||
++n;
|
++n;
|
||||||
pos += step;
|
pos += step;
|
||||||
@ -113,7 +118,8 @@ function numNetscriptOperators(text: string): number {
|
|||||||
numOccurrences(text, "==") +
|
numOccurrences(text, "==") +
|
||||||
numOccurrences(text, "!=");
|
numOccurrences(text, "!=");
|
||||||
if (isNaN(total)) {
|
if (isNaN(total)) {
|
||||||
const message = "ERROR in counting number of operators in script. This is a bug, please report to game developer";
|
// tslint:disable-next-line:max-line-length
|
||||||
|
const message: string = "ERROR in counting number of operators in script. This is a bug, please report to game developer";
|
||||||
dialogBoxCreate(message, false);
|
dialogBoxCreate(message, false);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -124,11 +130,13 @@ function numNetscriptOperators(text: string): number {
|
|||||||
|
|
||||||
// Checks if a string contains HTML elements
|
// Checks if a string contains HTML elements
|
||||||
function isHTML(str: string): boolean {
|
function isHTML(str: string): boolean {
|
||||||
const a = document.createElement("div");
|
const element: HTMLDivElement = document.createElement("div");
|
||||||
a.innerHTML = str;
|
element.innerHTML = str;
|
||||||
const c = a.childNodes;
|
const c: NodeListOf<Node & ChildNode> = element.childNodes;
|
||||||
for (let i = c.length; i--;) {
|
for (let i: number = c.length; i >= 0; i--) {
|
||||||
if (c[i].nodeType == 1) { return true; }
|
if (c[i].nodeType === 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -136,10 +144,10 @@ function isHTML(str: string): boolean {
|
|||||||
|
|
||||||
// Generates a random alphanumeric string with N characters
|
// Generates a random alphanumeric string with N characters
|
||||||
function generateRandomString(n: number): string {
|
function generateRandomString(n: number): string {
|
||||||
let str = "";
|
let str: string = "";
|
||||||
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
const chars: string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
|
||||||
for (let i = 0; i < n; i++) {
|
for (let i: number = 0; i < n; i++) {
|
||||||
str += chars.charAt(Math.floor(Math.random() * chars.length));
|
str += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user