Fixed a performance issue when installing too many Neuroflux at once.

This commit is contained in:
Olivier Gagnon 2021-06-13 11:05:07 -04:00
parent 2b1ec7d573
commit 39b4048603
5 changed files with 36 additions and 8 deletions

@ -2157,15 +2157,31 @@ function installAugmentations() {
dialogBoxCreate("You have not purchased any Augmentations to install!"); dialogBoxCreate("You have not purchased any Augmentations to install!");
return false; return false;
} }
var augmentationList = ""; let augmentationList = "";
for (var i = 0; i < Player.queuedAugmentations.length; ++i) { let nfgIndex = -1;
var aug = Augmentations[Player.queuedAugmentations[i].name]; for(let i = Player.queuedAugmentations.length-1; i >= 0; i--) {
if(Player.queuedAugmentations[i].name === AugmentationNames.NeuroFluxGovernor) {
nfgIndex = i;
break;
}
}
for (let i = 0; i < Player.queuedAugmentations.length; ++i) {
const ownedAug = Player.queuedAugmentations[i];
const aug = Augmentations[ownedAug.name];
if (aug == null) { if (aug == null) {
console.error(`Invalid augmentation: ${Player.queuedAugmentations[i].name}`); console.error(`Invalid augmentation: ${ownedAug.name}`);
continue; continue;
} }
if(ownedAug.name === AugmentationNames.NeuroFluxGovernor
&& i !== nfgIndex) continue;
let level = null;
if (ownedAug.name === AugmentationNames.NeuroFluxGovernor) {
level = ` - ${ownedAug.level}`;
}
applyAugmentation(Player.queuedAugmentations[i]); applyAugmentation(Player.queuedAugmentations[i]);
augmentationList += (aug.name + "<br>"); augmentationList += (aug.name + level + "<br>");
} }
Player.queuedAugmentations = []; Player.queuedAugmentations = [];
dialogBoxCreate("You slowly drift to sleep as scientists put you under in order " + dialogBoxCreate("You slowly drift to sleep as scientists put you under in order " +

@ -7,12 +7,23 @@ import * as React from "react";
import { Augmentations } from "../../Augmentation/Augmentations"; import { Augmentations } from "../../Augmentation/Augmentations";
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
import { Player } from "../../Player"; import { Player } from "../../Player";
import { IPlayerOwnedAugmentation } from "../../Augmentation/PlayerOwnedAugmentation";
import { AugmentationAccordion } from "../../ui/React/AugmentationAccordion"; import { AugmentationAccordion } from "../../ui/React/AugmentationAccordion";
export function PurchasedAugmentations(): React.ReactElement { export function PurchasedAugmentations(): React.ReactElement {
const augs: React.ReactElement[] = []; const augs: React.ReactElement[] = [];
for (const ownedAug of Player.queuedAugmentations) { // Only render the last NeuroFlux (there are no findLastIndex btw)
let nfgIndex = -1;
for(let i = Player.queuedAugmentations.length-1; i >= 0; i--) {
if(Player.queuedAugmentations[i].name === AugmentationNames.NeuroFluxGovernor) {
nfgIndex = i;
break;
}
}
for (let i = 0; i < Player.queuedAugmentations.length; i++) {
const ownedAug = Player.queuedAugmentations[i];
if(ownedAug.name === AugmentationNames.NeuroFluxGovernor && i !== nfgIndex) continue;
const aug = Augmentations[ownedAug.name]; const aug = Augmentations[ownedAug.name];
let level = null; let level = null;
if (ownedAug.name === AugmentationNames.NeuroFluxGovernor) { if (ownedAug.name === AugmentationNames.NeuroFluxGovernor) {

@ -263,6 +263,6 @@ export const CONSTANTS: IMap<any> = {
* Fix weird alignment of donation text box and button. (@Tesseract1234567890) * Fix weird alignment of donation text box and button. (@Tesseract1234567890)
* Fixed an issue where reputation could be transfered to new jobs when unfocused. * Fixed an issue where reputation could be transfered to new jobs when unfocused.
* Empty stack traces should no longer appear. * Empty stack traces should no longer appear.
* Purchasing anything with Infinity money doesn't result in NaN.
`, `,
} }

@ -726,7 +726,7 @@ class DevMenuComponent extends Component {
<button className="std-button" onClick={this.addMoney(1e9)}>Add $1b</button> <button className="std-button" onClick={this.addMoney(1e9)}>Add $1b</button>
<button className="std-button" onClick={this.addMoney(1e12)}>Add $1t</button> <button className="std-button" onClick={this.addMoney(1e12)}>Add $1t</button>
<button className="std-button" onClick={this.addMoney(1e15)}>Add $1000t</button> <button className="std-button" onClick={this.addMoney(1e15)}>Add $1000t</button>
<button className="std-button" onClick={this.addMoney(1e99)}>Add $1e99</button> <button className="std-button" onClick={this.addMoney(Infinity)}>Add $Infinity</button>
<button className="std-button" onClick={this.upgradeRam}>Upgrade Home Computer's RAM</button> <button className="std-button" onClick={this.upgradeRam}>Upgrade Home Computer's RAM</button>
</div> </div>
<div className="row"> <div className="row">

@ -394,6 +394,7 @@ export function loseMoney(money) {
console.error("NaN passed into Player.loseMoney()"); console.error("NaN passed into Player.loseMoney()");
return; return;
} }
if(this.money.eq(Infinity) && money === Infinity) return;
this.money = this.money.minus(money); this.money = this.money.minus(money);
} }