mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-19 06:03:50 +01:00
debounce updateRAM
This commit is contained in:
parent
efeb37fa52
commit
445e365959
@ -1278,8 +1278,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
const callbackScript = helpers.string(ctx, "callbackScript", _callbackScript);
|
||||
|
||||
const wd = GetServer(SpecialServers.WorldDaemon);
|
||||
if (!(wd instanceof Server))
|
||||
throw new Error("WorldDaemon was not a normal server. This is a bug contact dev.");
|
||||
if (!(wd instanceof Server)) throw new Error("WorldDaemon was not a normal server. This is a bug contact dev.");
|
||||
const hackingRequirements = (): boolean => {
|
||||
if (player.skills.hacking < wd.requiredHackingSkill) return false;
|
||||
if (!wd.hasAdminRights) return false;
|
||||
|
@ -28,14 +28,14 @@ export class SleeveCrimeWork extends Work {
|
||||
getExp(): WorkStats {
|
||||
const crime = this.getCrime();
|
||||
return newWorkStats({
|
||||
money: crime.money*BitNodeMultipliers.CrimeMoney,
|
||||
hackExp: crime.hacking_exp*BitNodeMultipliers.CrimeExpGain,
|
||||
strExp: crime.strength_exp*BitNodeMultipliers.CrimeExpGain,
|
||||
defExp: crime.defense_exp*BitNodeMultipliers.CrimeExpGain,
|
||||
dexExp: crime.dexterity_exp*BitNodeMultipliers.CrimeExpGain,
|
||||
agiExp: crime.agility_exp*BitNodeMultipliers.CrimeExpGain,
|
||||
chaExp: crime.charisma_exp*BitNodeMultipliers.CrimeExpGain,
|
||||
intExp: crime.intelligence_exp*BitNodeMultipliers.CrimeExpGain,
|
||||
money: crime.money * BitNodeMultipliers.CrimeMoney,
|
||||
hackExp: crime.hacking_exp * BitNodeMultipliers.CrimeExpGain,
|
||||
strExp: crime.strength_exp * BitNodeMultipliers.CrimeExpGain,
|
||||
defExp: crime.defense_exp * BitNodeMultipliers.CrimeExpGain,
|
||||
dexExp: crime.dexterity_exp * BitNodeMultipliers.CrimeExpGain,
|
||||
agiExp: crime.agility_exp * BitNodeMultipliers.CrimeExpGain,
|
||||
chaExp: crime.charisma_exp * BitNodeMultipliers.CrimeExpGain,
|
||||
intExp: crime.intelligence_exp * BitNodeMultipliers.CrimeExpGain,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,6 @@ import { Faction } from "./Faction/Faction";
|
||||
import { safetlyCreateUniqueServer } from "./Server/ServerHelpers";
|
||||
import { SpecialServers } from "./Server/data/SpecialServers";
|
||||
import { v2APIBreak } from "./utils/v2APIBreak";
|
||||
import { Script } from "./Script/Script";
|
||||
|
||||
/* SaveObject.js
|
||||
* Defines the object used to save/load games
|
||||
|
@ -1,5 +1,4 @@
|
||||
export enum RamCalculationErrorCode {
|
||||
SyntaxError = -1,
|
||||
ImportError = -2,
|
||||
URLImportError = -3,
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect, useRef, useMemo } from "react";
|
||||
import React, { useState, useEffect, useRef } from "react";
|
||||
import Editor, { Monaco } from "@monaco-editor/react";
|
||||
import * as monaco from "monaco-editor";
|
||||
|
||||
@ -240,22 +240,17 @@ export function Root(props: IProps): React.ReactElement {
|
||||
}
|
||||
}
|
||||
|
||||
const debouncedSetRAM = useMemo(
|
||||
() =>
|
||||
debounce((s, e) => {
|
||||
setRAM(s);
|
||||
setRamEntries(e);
|
||||
setUpdatingRam(false);
|
||||
}, 300),
|
||||
[],
|
||||
);
|
||||
const debouncedUpdateRAM = debounce((newCode: string) => {
|
||||
updateRAM(newCode);
|
||||
setUpdatingRam(false);
|
||||
}, 300);
|
||||
|
||||
async function updateRAM(newCode: string): Promise<void> {
|
||||
function updateRAM(newCode: string): void {
|
||||
if (currentScript != null && currentScript.isTxt) {
|
||||
debouncedSetRAM("N/A", [["N/A", ""]]);
|
||||
setRAM("N/A");
|
||||
setRamEntries([["N/A", ""]]);
|
||||
return;
|
||||
}
|
||||
setUpdatingRam(true);
|
||||
const codeCopy = newCode + "";
|
||||
const ramUsage = calculateRamUsage(props.player, codeCopy, props.player.getCurrentServer().scripts);
|
||||
if (ramUsage.cost > 0) {
|
||||
@ -265,25 +260,28 @@ export function Root(props: IProps): React.ReactElement {
|
||||
entriesDisp.push([`${entry.name} (${entry.type})`, numeralWrapper.formatRAM(entry.cost)]);
|
||||
}
|
||||
|
||||
debouncedSetRAM("RAM: " + numeralWrapper.formatRAM(ramUsage.cost), entriesDisp);
|
||||
setRAM("RAM: " + numeralWrapper.formatRAM(ramUsage.cost));
|
||||
setRamEntries(entriesDisp);
|
||||
return;
|
||||
}
|
||||
let RAM = "";
|
||||
const entriesDisp = [];
|
||||
switch (ramUsage.cost) {
|
||||
case RamCalculationErrorCode.ImportError: {
|
||||
debouncedSetRAM("RAM: Import Error", [["Import Error", ""]]);
|
||||
break;
|
||||
}
|
||||
case RamCalculationErrorCode.URLImportError: {
|
||||
debouncedSetRAM("RAM: HTTP Import Error", [["HTTP Import Error", ""]]);
|
||||
RAM = "RAM: Import Error";
|
||||
entriesDisp.push(["Import Error", ""]);
|
||||
break;
|
||||
}
|
||||
case RamCalculationErrorCode.SyntaxError:
|
||||
default: {
|
||||
debouncedSetRAM("RAM: Syntax Error", [["Syntax Error", ""]]);
|
||||
RAM = "RAM: Syntax Error";
|
||||
entriesDisp.push(["Syntax Error", ""]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new Promise<void>(() => undefined);
|
||||
setRAM(RAM);
|
||||
setRamEntries(entriesDisp);
|
||||
return;
|
||||
}
|
||||
|
||||
// Formats the code
|
||||
@ -446,7 +444,8 @@ export function Root(props: IProps): React.ReactElement {
|
||||
// When the code is updated within the editor
|
||||
function updateCode(newCode?: string): void {
|
||||
if (newCode === undefined) return;
|
||||
updateRAM(newCode);
|
||||
setUpdatingRam(true);
|
||||
debouncedUpdateRAM(newCode);
|
||||
if (editorRef.current === null) return;
|
||||
const newPos = editorRef.current.getPosition();
|
||||
if (newPos === null) return;
|
||||
|
@ -7,8 +7,7 @@ import { IPlayer } from "../PersonObjects/IPlayer";
|
||||
import { dialogBoxCreate } from "../ui/React/DialogBox";
|
||||
import { CrimeType } from "../utils/WorkType";
|
||||
import { Work, WorkType } from "./Work";
|
||||
import { newWorkStats, scaleWorkStats, WorkStats } from "./WorkStats";
|
||||
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
||||
import { scaleWorkStats, WorkStats } from "./WorkStats";
|
||||
import { calculateCrimeWorkStats } from "./formulas/Crime";
|
||||
|
||||
enum newCrimeType {
|
||||
|
Loading…
Reference in New Issue
Block a user