From 0f15431b5fd56dc5b6e70300dc5b21b26e595278 Mon Sep 17 00:00:00 2001
From: Snarling <84951833+Snarling@users.noreply.github.com>
Date: Sat, 20 Aug 2022 19:08:05 -0400
Subject: [PATCH] remove unused eventEmitterForUiReset
---
src/StockMarket/StockMarket.tsx | 44 +++++++-------------------
src/StockMarket/ui/StockMarketRoot.tsx | 4 +--
src/StockMarket/ui/StockTickers.tsx | 2 --
src/ui/GameRoot.tsx | 3 +-
4 files changed, 13 insertions(+), 40 deletions(-)
diff --git a/src/StockMarket/StockMarket.tsx b/src/StockMarket/StockMarket.tsx
index 43413fe46..25b242929 100644
--- a/src/StockMarket/StockMarket.tsx
+++ b/src/StockMarket/StockMarket.tsx
@@ -34,7 +34,7 @@ export function placeOrder(
price: number,
type: OrderTypes,
position: PositionTypes,
- ctx: NetscriptContext | null = null,
+ ctx?: NetscriptContext,
): boolean {
if (!(stock instanceof Stock)) {
if (ctx) {
@@ -87,9 +87,7 @@ export interface ICancelOrderParams {
type?: OrderTypes;
}
export function cancelOrder(params: ICancelOrderParams, ctx?: NetscriptContext): boolean {
- if (StockMarket["Orders"] == null) {
- return false;
- }
+ if (StockMarket["Orders"] == null) return false;
if (params.order && params.order instanceof Order) {
const order = params.order;
// An 'Order' object is passed in
@@ -121,15 +119,11 @@ export function cancelOrder(params: ICancelOrderParams, ctx?: NetscriptContext):
params.pos === order.pos
) {
stockOrders.splice(i, 1);
- if (ctx) {
- helpers.log(ctx, () => "Successfully cancelled order: " + orderTxt);
- }
+ if (ctx) helpers.log(ctx, () => "Successfully cancelled order: " + orderTxt);
return true;
}
}
- if (ctx) {
- helpers.log(ctx, () => "Failed to cancel order: " + orderTxt);
- }
+ if (ctx) helpers.log(ctx, () => "Failed to cancel order: " + orderTxt);
return false;
}
return false;
@@ -143,9 +137,7 @@ export function loadStockMarket(saveString: string): void {
storedCycles: 0,
ticksUntilCycle: 0,
} as IStockMarket;
- } else {
- StockMarket = JSON.parse(saveString, Reviver);
- }
+ } else StockMarket = JSON.parse(saveString, Reviver);
}
export function deleteStockMarket(): void {
@@ -159,9 +151,7 @@ export function deleteStockMarket(): void {
export function initStockMarket(): void {
for (const stk of Object.keys(StockMarket)) {
- if (StockMarket.hasOwnProperty(stk)) {
- delete StockMarket[stk];
- }
+ if (StockMarket.hasOwnProperty(stk)) delete StockMarket[stk];
}
for (const metadata of InitStockMetadata) {
@@ -172,9 +162,7 @@ export function initStockMarket(): void {
const orders: IOrderBook = {};
for (const name of Object.keys(StockMarket)) {
const stock = StockMarket[name];
- if (!(stock instanceof Stock)) {
- continue;
- }
+ if (!(stock instanceof Stock)) continue;
orders[stock.symbol] = [];
}
StockMarket["Orders"] = orders;
@@ -201,9 +189,7 @@ export function initSymbolToStockMap(): void {
function stockMarketCycle(): void {
for (const name of Object.keys(StockMarket)) {
const stock = StockMarket[name];
- if (!(stock instanceof Stock)) {
- continue;
- }
+ if (!(stock instanceof Stock)) continue;
const roll = Math.random();
if (roll < 0.45) {
@@ -231,9 +217,7 @@ export function processStockPrices(numCycles = 1): void {
// We can process the update every 4 seconds as long as there are enough
// stored cycles. This lets us account for offline time
const timeNow = new Date().getTime();
- if (timeNow - StockMarket.lastUpdate < 4e3) {
- return;
- }
+ if (timeNow - StockMarket.lastUpdate < 4e3) return;
StockMarket.lastUpdate = timeNow;
StockMarket.storedCycles -= cyclesPerStockUpdate;
@@ -243,16 +227,12 @@ export function processStockPrices(numCycles = 1): void {
StockMarket.ticksUntilCycle = TicksPerCycle;
}
--StockMarket.ticksUntilCycle;
- if (StockMarket.ticksUntilCycle <= 0) {
- stockMarketCycle();
- }
+ if (StockMarket.ticksUntilCycle <= 0) stockMarketCycle();
const v = Math.random();
for (const name of Object.keys(StockMarket)) {
const stock = StockMarket[name];
- if (!(stock instanceof Stock)) {
- continue;
- }
+ if (!(stock instanceof Stock)) continue;
let av = (v * stock.mv) / 100;
if (isNaN(av)) {
av = 0.02;
@@ -311,5 +291,3 @@ export function initStockMarketFn(): void {
initStockMarket();
initSymbolToStockMap();
}
-
-export const eventEmitterForUiReset = new EventEmitter<[]>();
diff --git a/src/StockMarket/ui/StockMarketRoot.tsx b/src/StockMarket/ui/StockMarketRoot.tsx
index 21eb14b66..0912a3bd7 100644
--- a/src/StockMarket/ui/StockMarketRoot.tsx
+++ b/src/StockMarket/ui/StockMarketRoot.tsx
@@ -9,10 +9,8 @@ import { StockTickers } from "./StockTickers";
import { IStockMarket } from "../IStockMarket";
import { IPlayer } from "../../PersonObjects/IPlayer";
-import { EventEmitter } from "../../utils/EventEmitter";
type IProps = {
- eventEmitterForReset?: EventEmitter<[]>;
initStockMarket: () => void;
p: IPlayer;
stockMarket: IStockMarket;
@@ -32,7 +30,7 @@ export function StockMarketRoot(props: IProps): React.ReactElement {
<>
{props.p.hasWseAccount && (
-
+
)}
>
);
diff --git a/src/StockMarket/ui/StockTickers.tsx b/src/StockMarket/ui/StockTickers.tsx
index ab67d9b3e..12cf52165 100644
--- a/src/StockMarket/ui/StockTickers.tsx
+++ b/src/StockMarket/ui/StockTickers.tsx
@@ -12,10 +12,8 @@ import { IStockMarket } from "../IStockMarket";
import { Stock } from "../Stock";
import { IPlayer } from "../../PersonObjects/IPlayer";
-import { EventEmitter } from "../../utils/EventEmitter";
type IProps = {
- eventEmitterForReset?: EventEmitter<[]>;
p: IPlayer;
stockMarket: IStockMarket;
};
diff --git a/src/ui/GameRoot.tsx b/src/ui/GameRoot.tsx
index 3a7f43cb5..06d98aa5f 100644
--- a/src/ui/GameRoot.tsx
+++ b/src/ui/GameRoot.tsx
@@ -17,7 +17,7 @@ import { prestigeAugmentation } from "../Prestige";
import { dialogBoxCreate } from "./React/DialogBox";
import { GetAllServers } from "../Server/AllServers";
import { Factions } from "../Faction/Factions";
-import { eventEmitterForUiReset, initStockMarketFn, StockMarket } from "../StockMarket/StockMarket";
+import { initStockMarketFn, StockMarket } from "../StockMarket/StockMarket";
import { Theme } from "@mui/material/styles";
import makeStyles from "@mui/styles/makeStyles";
@@ -437,7 +437,6 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
case Page.StockMarket: {
mainPage = (