build bunch of fixes

This commit is contained in:
Olivier Gagnon 2021-09-21 20:30:00 -04:00
parent c94ec2f170
commit 0c932dd4d1
24 changed files with 553 additions and 1075 deletions

28
dist/vendor.bundle.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1357
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -58,7 +58,8 @@
"treant-js": "^1.0.1", "treant-js": "^1.0.1",
"unused-webpack-plugin": "^2.4.0", "unused-webpack-plugin": "^2.4.0",
"uuid": "^3.2.1", "uuid": "^3.2.1",
"w3c-blob": "0.0.1" "w3c-blob": "0.0.1",
"webpack-deadcode-plugin": "^0.1.15"
}, },
"description": "A cyberpunk-themed incremental game", "description": "A cyberpunk-themed incremental game",
"devDependencies": { "devDependencies": {

@ -1 +0,0 @@
export declare let cinematicTextFlag: boolean;

@ -1,119 +0,0 @@
import { Engine } from "./engine";
import { setTimeoutRef } from "./utils/SetTimeoutRef";
import { removeChildrenFromElement } from "../utils/uiHelpers/removeChildrenFromElement";
import { createElement } from "../utils/uiHelpers/createElement";
import { exceptionAlert } from "../utils/helpers/exceptionAlert";
import { isString } from "../utils/helpers/isString";
export let cinematicTextFlag = false;
/**
* Print a message using a hacking-style "typing" effect.
* Note that this clears the UI so that the text from this is the only thing visible.
*
* @param lines {string[]} Array of strings to print, where each element is a separate line
*/
export function writeCinematicText(lines) {
cinematicTextFlag = true;
if (lines.constructor !== Array) {
throw new Error("Invalid non-array argument passed into writeCinematicText()");
}
// Reuse the 'Red Pill' content
Engine.loadCinematicTextContent();
const container = document.getElementById("cinematic-text-container");
container.style.width = "75%";
if (container == null) {
throw new Error("Could not find cinematic-text-container for writeCinematicText()");
}
removeChildrenFromElement(container);
for (let i = 0; i < lines.length; ++i) {
if (!isString(lines[i])) {
throw new Error("Invalid non-string element in 'lines' argument. writeCinematicText() failed");
}
}
return writeCinematicTextRecurse(lines)
.then(function () {
return cinematicTextEnd(); //Puts the continue button
})
.catch(function (e) {
exceptionAlert(e);
});
}
function writeCinematicTextRecurse(lines, lineNumber = 0) {
if (lineNumber >= lines.length) {
return Promise.resolve(true);
}
return writeCinematicTextLine(lines[lineNumber]).then(function () {
return writeCinematicTextRecurse(lines, lineNumber + 1);
});
}
function writeCinematicTextLine(line) {
return new Promise(function (resolve, reject) {
const container = document.getElementById("cinematic-text-container");
const pElem = document.createElement("p");
container.appendChild(pElem);
const promise = writeCinematicTextLetter(pElem, line, 0);
promise.then(
function (res) {
resolve(res);
},
function (e) {
reject(e);
},
);
});
}
function writeCinematicTextLetter(pElem, line, i = 0) {
return new Promise(function (resolve, reject) {
setTimeoutRef(function () {
const textToShow = line.substring(0, i);
if (i >= line.length) {
pElem.innerHTML = textToShow;
return resolve(true);
}
pElem.innerHTML = textToShow + "<span class='typed-cursor'> &#9608; </span>";
const promise = writeCinematicTextLetter(pElem, line, i + 1);
promise.then(
function (res) {
resolve(res);
},
function (e) {
reject(e);
},
);
}, 15);
});
}
function cinematicTextEnd() {
var container = document.getElementById("cinematic-text-container");
var mainMenu = document.getElementById("mainmenu-container");
container.appendChild(createElement("br"));
return new Promise(function (resolve) {
container.appendChild(
createElement("a", {
class: "a-link-button",
innerText: "Continue...",
clickListener: () => {
removeChildrenFromElement(container);
Engine.loadTerminalContent();
mainMenu.style.visibility = "visible";
cinematicTextFlag = false;
resolve();
},
}),
);
});
}

@ -1,7 +1,7 @@
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../utils/JSONReviver"; import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../utils/JSONReviver";
// Array of all valid states // Array of all valid states
export const AllCorporationStates: string[] = ["START", "PURCHASE", "PRODUCTION", "SALE", "EXPORT"]; const AllCorporationStates: string[] = ["START", "PURCHASE", "PRODUCTION", "SALE", "EXPORT"];
export class CorporationState { export class CorporationState {
// Number representing what state the Corporation is in. The number // Number representing what state the Corporation is in. The number

@ -24,35 +24,6 @@ export function checkIfConnectedToDarkweb(): void {
} }
} }
//Handler for dark web commands. The terminal's executeCommand() function will pass
//dark web-specific commands into this. It will pass in the raw split command array
//rather than the command string
export function executeDarkwebTerminalCommand(commandArray: string[]): void {
if (commandArray.length == 0) {
return;
}
switch (commandArray[0]) {
case "buy": {
if (commandArray.length != 2) {
Terminal.error("Incorrect number of arguments. Usage: ");
Terminal.print("buy -l");
Terminal.print("buy [item name]");
return;
}
const arg = commandArray[1];
if (arg == "-l" || arg == "-1" || arg == "--list") {
listAllDarkwebItems();
} else {
buyDarkwebItem(arg);
}
break;
}
default:
Terminal.error("Command not found");
break;
}
}
export function listAllDarkwebItems(): void { export function listAllDarkwebItems(): void {
for (const key in DarkWebItems) { for (const key in DarkWebItems) {
const item = DarkWebItems[key]; const item = DarkWebItems[key];

@ -20,7 +20,7 @@ interface IServerProps {
ip: string; ip: string;
} }
export function ServerAccordion(props: IServerProps): React.ReactElement { function ServerAccordion(props: IServerProps): React.ReactElement {
const server = AllServers[props.ip]; const server = AllServers[props.ip];
let totalSize = 0; let totalSize = 0;
for (const f of server.scripts) { for (const f of server.scripts) {

@ -1,11 +1,11 @@
import { Player } from "../Player"; import { Player } from "../Player";
import { Exploit } from "./Exploit"; import { Exploit } from "./Exploit";
(function () { export function startTampering(): void {
const a = 55; const a = 55;
setInterval(function () { setInterval(function () {
if (a.toExponential() !== "5.5e+1") { if (a.toExponential() !== "5.5e+1") {
Player.giveExploit(Exploit.PrototypeTampering); Player.giveExploit(Exploit.PrototypeTampering);
} }
}, 15 * 60 * 1000); // 15 minutes }, 15 * 60 * 1000); // 15 minutes
})(); }

@ -1,7 +1,7 @@
import { Player } from "../Player"; import { Player } from "../Player";
import { Exploit } from "./Exploit"; import { Exploit } from "./Exploit";
(function () { export function startUnclickable(): void {
function clickTheUnclickable(event: MouseEvent): void { function clickTheUnclickable(event: MouseEvent): void {
if (!event.target || !(event.target instanceof Element)) return; if (!event.target || !(event.target instanceof Element)) return;
const display = window.getComputedStyle(event.target as Element).display; const display = window.getComputedStyle(event.target as Element).display;
@ -19,4 +19,4 @@ import { Exploit } from "./Exploit";
} }
document.addEventListener("DOMContentLoaded", targetElement); document.addEventListener("DOMContentLoaded", targetElement);
})(); }

@ -2,7 +2,7 @@ import { makeRuntimeRejectMsg } from "./NetscriptEvaluator";
import { ScriptUrl } from "./Script/ScriptUrl"; import { ScriptUrl } from "./Script/ScriptUrl";
// Makes a blob that contains the code of a given script. // Makes a blob that contains the code of a given script.
export function makeScriptBlob(code) { function makeScriptBlob(code) {
return new Blob([code], { type: "text/javascript" }); return new Blob([code], { type: "text/javascript" });
} }
@ -93,7 +93,7 @@ function shouldCompile(script, scripts) {
* the script parameter. * the script parameter.
*/ */
// BUG: apparently seen is never consulted. Oops. // BUG: apparently seen is never consulted. Oops.
export function _getScriptUrls(script, scripts, seen) { function _getScriptUrls(script, scripts, seen) {
// Inspired by: https://stackoverflow.com/a/43834063/91401 // Inspired by: https://stackoverflow.com/a/43834063/91401
/** @type {ScriptUrl[]} */ /** @type {ScriptUrl[]} */
const urlStack = []; const urlStack = [];

@ -10,10 +10,6 @@ import { SourceFiles } from "./SourceFile/SourceFiles";
import { dialogBoxCreate } from "../utils/DialogBox"; import { dialogBoxCreate } from "../utils/DialogBox";
let redPillFlag = false; let redPillFlag = false;
function hackWorldDaemon(router, flume = false, quick = false) {
router.toBitVerse(flume, quick);
redPillFlag = true;
}
function giveSourceFile(bitNodeNumber) { function giveSourceFile(bitNodeNumber) {
var sourceFileKey = "SourceFile" + bitNodeNumber.toString(); var sourceFileKey = "SourceFile" + bitNodeNumber.toString();
@ -86,4 +82,4 @@ export function enterBitNode(router, flume, destroyedBitNode, newBitNode) {
prestigeSourceFile(flume); prestigeSourceFile(flume);
} }
export { redPillFlag, hackWorldDaemon }; export { redPillFlag };

@ -3,7 +3,7 @@ export type Position = {
column: number; column: number;
}; };
export class PositionTracker { class PositionTracker {
positions: Map<string, Position>; positions: Map<string, Position>;
constructor() { constructor() {

@ -5,6 +5,14 @@ import { OwnedAugmentationsOrderSetting, PurchaseAugmentationsOrderSetting } fro
* Represents the default settings the player could customize. * Represents the default settings the player could customize.
*/ */
interface IDefaultSettings { interface IDefaultSettings {
/**
* How many servers per page
*/
ActiveScriptsServerPageSize: number;
/**
* How many scripts per page
*/
ActiveScriptsScriptPageSize: number;
/** /**
* How often the game should autosave the player's progress, in seconds. * How often the game should autosave the player's progress, in seconds.
*/ */
@ -101,6 +109,8 @@ interface ISettings extends IDefaultSettings {
} }
const defaultSettings: IDefaultSettings = { const defaultSettings: IDefaultSettings = {
ActiveScriptsServerPageSize: 10,
ActiveScriptsScriptPageSize: 10,
AutosaveInterval: 60, AutosaveInterval: 60,
CodeInstructionRunTime: 50, CodeInstructionRunTime: 50,
DisableASCIIArt: false, DisableASCIIArt: false,
@ -123,6 +133,8 @@ const defaultSettings: IDefaultSettings = {
*/ */
// tslint:disable-next-line:variable-name // tslint:disable-next-line:variable-name
export const Settings: ISettings & ISelfInitializer & ISelfLoading = { export const Settings: ISettings & ISelfInitializer & ISelfLoading = {
ActiveScriptsServerPageSize: defaultSettings.ActiveScriptsServerPageSize,
ActiveScriptsScriptPageSize: defaultSettings.ActiveScriptsScriptPageSize,
AutosaveInterval: defaultSettings.AutosaveInterval, AutosaveInterval: defaultSettings.AutosaveInterval,
CodeInstructionRunTime: 25, CodeInstructionRunTime: 25,
DisableASCIIArt: defaultSettings.DisableASCIIArt, DisableASCIIArt: defaultSettings.DisableASCIIArt,

@ -51,7 +51,6 @@ import { Settings } from "../../Settings/Settings";
import { redPillFlag } from "../../RedPill"; import { redPillFlag } from "../../RedPill";
import { inMission } from "../../Missions"; import { inMission } from "../../Missions";
import { cinematicTextFlag } from "../../CinematicText";
import { KEY } from "../../../utils/helpers/keyCodes"; import { KEY } from "../../../utils/helpers/keyCodes";
import { FconfSettings } from "../../Fconf/FconfSettings"; import { FconfSettings } from "../../Fconf/FconfSettings";
@ -268,7 +267,7 @@ export function SidebarRoot(props: IProps): React.ReactElement {
// Alt-o - Options // Alt-o - Options
function handleShortcuts(this: Document, event: KeyboardEvent): any { function handleShortcuts(this: Document, event: KeyboardEvent): any {
if (Settings.DisableHotkeys) return; if (Settings.DisableHotkeys) return;
if (props.player.isWorking || redPillFlag || inMission || cinematicTextFlag) return; if (props.player.isWorking || redPillFlag || inMission) return;
if (event.keyCode == KEY.T && event.altKey) { if (event.keyCode == KEY.T && event.altKey) {
event.preventDefault(); event.preventDefault();
clickTerminal(); clickTerminal();

@ -44,8 +44,8 @@ import { Reputation } from "./ui/React/Reputation";
import { dialogBoxCreate } from "../utils/DialogBox"; import { dialogBoxCreate } from "../utils/DialogBox";
import { exceptionAlert } from "../utils/helpers/exceptionAlert"; import { exceptionAlert } from "../utils/helpers/exceptionAlert";
import "./Exploits/tampering"; import { startTampering } from "./Exploits/tampering";
import "./Exploits/unclickable"; import { startUnclickable } from "./Exploits/unclickable";
import React from "react"; import React from "react";
@ -246,6 +246,8 @@ const Engine = {
}, },
load: function (saveString) { load: function (saveString) {
startTampering();
startUnclickable();
// Load game from save or create new game // Load game from save or create new game
if (loadGame(saveString)) { if (loadGame(saveString)) {
initBitNodeMultipliers(Player); initBitNodeMultipliers(Player);

@ -1,7 +1,7 @@
import React from "react"; import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import { TTheme as Theme, colors, refreshTheme } from "./ui/React/Theme"; import { TTheme as Theme, colors } from "./ui/React/Theme";
import { LoadingScreen } from "./ui/LoadingScreen"; import { LoadingScreen } from "./ui/LoadingScreen";
import "./engineStyle"; import "./engineStyle";

@ -4,6 +4,7 @@ import { WorkerScriptAccordion } from "./WorkerScriptAccordion";
import List from "@mui/material/List"; import List from "@mui/material/List";
import TablePagination from "@mui/material/TablePagination"; import TablePagination from "@mui/material/TablePagination";
import { TablePaginationActionsAll } from "../React/TablePaginationActionsAll"; import { TablePaginationActionsAll } from "../React/TablePaginationActionsAll";
import { Settings } from "../../Settings/Settings";
interface IProps { interface IProps {
workerScripts: WorkerScript[]; workerScripts: WorkerScript[];
@ -11,12 +12,13 @@ interface IProps {
export function ServerAccordionContent(props: IProps): React.ReactElement { export function ServerAccordionContent(props: IProps): React.ReactElement {
const [page, setPage] = useState(0); const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(10); const [rowsPerPage, setRowsPerPage] = useState(Settings.ActiveScriptsScriptPageSize);
const handleChangePage = (event: unknown, newPage: number): void => { const handleChangePage = (event: unknown, newPage: number): void => {
setPage(newPage); setPage(newPage);
}; };
const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement>): void => { const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement>): void => {
Settings.ActiveScriptsScriptPageSize = parseInt(event.target.value, 10);
setRowsPerPage(parseInt(event.target.value, 10)); setRowsPerPage(parseInt(event.target.value, 10));
setPage(0); setPage(0);
}; };

@ -13,6 +13,7 @@ import { WorkerScript } from "../../Netscript/WorkerScript";
import { WorkerScriptStartStopEventEmitter } from "../../Netscript/WorkerScriptStartStopEventEmitter"; import { WorkerScriptStartStopEventEmitter } from "../../Netscript/WorkerScriptStartStopEventEmitter";
import { getServer } from "../../Server/ServerHelpers"; import { getServer } from "../../Server/ServerHelpers";
import { BaseServer } from "../../Server/BaseServer"; import { BaseServer } from "../../Server/BaseServer";
import { Settings } from "../../Settings/Settings";
import { TablePaginationActionsAll } from "../React/TablePaginationActionsAll"; import { TablePaginationActionsAll } from "../React/TablePaginationActionsAll";
import SearchIcon from "@mui/icons-material/Search"; import SearchIcon from "@mui/icons-material/Search";
@ -33,7 +34,7 @@ type IProps = {
export function ServerAccordions(props: IProps): React.ReactElement { export function ServerAccordions(props: IProps): React.ReactElement {
const [filter, setFilter] = useState(""); const [filter, setFilter] = useState("");
const [page, setPage] = useState(0); const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(10); const [rowsPerPage, setRowsPerPage] = useState(Settings.ActiveScriptsServerPageSize);
const setRerender = useState(false)[1]; const setRerender = useState(false)[1];
const handleChangePage = (event: unknown, newPage: number): void => { const handleChangePage = (event: unknown, newPage: number): void => {
@ -41,6 +42,7 @@ export function ServerAccordions(props: IProps): React.ReactElement {
}; };
const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement>): void => { const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement>): void => {
Settings.ActiveScriptsServerPageSize = parseInt(event.target.value, 10);
setRowsPerPage(parseInt(event.target.value, 10)); setRowsPerPage(parseInt(event.target.value, 10));
setPage(0); setPage(0);
}; };

@ -60,9 +60,9 @@ export let colors = {
rep: "#faffdf", rep: "#faffdf",
}; };
export let theme: Theme; let theme: Theme;
export function refreshTheme() { function refreshTheme() {
theme = createTheme({ theme = createTheme({
colors: { colors: {
hp: "#dd3434", hp: "#dd3434",

@ -11,10 +11,6 @@
* This formula ensures that the effects of the statistic that is being processed * This formula ensures that the effects of the statistic that is being processed
* has diminishing returns, but never loses its effectiveness as you continue * has diminishing returns, but never loses its effectiveness as you continue
* to raise it. * to raise it.
*
* There are two implementations of this component. One is simply a function that
* can be called with the stat and the exponential/linear factors. The other is a
* class where the exponential and linear factors are defined upon construction.
*/ */
export function calculateEffectWithFactors(n: number, expFac: number, linearFac: number): number { export function calculateEffectWithFactors(n: number, expFac: number, linearFac: number): number {
if (expFac <= 0 || expFac >= 1) { if (expFac <= 0 || expFac >= 1) {
@ -26,20 +22,3 @@ export function calculateEffectWithFactors(n: number, expFac: number, linearFac:
return Math.pow(n, expFac) + n / linearFac; return Math.pow(n, expFac) + n / linearFac;
} }
export class EffectWithFactors {
// Exponential factor
private expFac: number;
// Linear Factor
private linearFac: number;
constructor(expFac: number, linearFac: number) {
this.expFac = expFac;
this.linearFac = linearFac;
}
calculate(n: number): number {
return calculateEffectWithFactors(n, this.expFac, this.linearFac);
}
}

@ -6,6 +6,7 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin"); const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const UnusedWebpackPlugin = require("unused-webpack-plugin"); const UnusedWebpackPlugin = require("unused-webpack-plugin");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin"); const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const DeadCodePlugin = require("webpack-deadcode-plugin");
module.exports = (env, argv) => { module.exports = (env, argv) => {
const isDevServer = (env || {}).devServer === true; const isDevServer = (env || {}).devServer === true;
@ -130,6 +131,10 @@ module.exports = (env, argv) => {
module: true, module: true,
}), }),
isDevelopment && new ReactRefreshWebpackPlugin(), isDevelopment && new ReactRefreshWebpackPlugin(),
new DeadCodePlugin({
patterns: ["src/**/*.(js|jsx|css|ts|tsx)"],
exclude: ["**/*.(stories|spec).(js|jsx)"],
}),
].filter(Boolean), ].filter(Boolean),
target: "web", target: "web",
entry: entry, entry: entry,