Refactored all code that uses the numeral library to use a wrapper class. Implemented configurable locale setting through this wrapper class

This commit is contained in:
danielyxie 2018-09-12 10:53:08 -05:00
parent 5635b51659
commit d50c5abb66
14 changed files with 189 additions and 150 deletions

@ -2,6 +2,7 @@ import {workerScripts,
killWorkerScript} from "./NetscriptWorker"; killWorkerScript} from "./NetscriptWorker";
import {Player} from "./Player"; import {Player} from "./Player";
import {getServer} from "./Server"; import {getServer} from "./Server";
import {numeralWrapper} from "./ui/numeralFormat";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {createAccordionElement} from "../utils/uiHelpers/createAccordionElement"; import {createAccordionElement} from "../utils/uiHelpers/createAccordionElement";
import {arrayToString} from "../utils/helpers/arrayToString"; import {arrayToString} from "../utils/helpers/arrayToString";
@ -10,7 +11,6 @@ import {createProgressBarText} from "../utils/helpers/createProgressBarText"
import {exceptionAlert} from "../utils/helpers/exceptionAlert"; import {exceptionAlert} from "../utils/helpers/exceptionAlert";
import {getElementById} from "../utils/uiHelpers/getElementById"; import {getElementById} from "../utils/uiHelpers/getElementById";
import {logBoxCreate} from "../utils/LogBox"; import {logBoxCreate} from "../utils/LogBox";
import numeral from "numeral/min/numeral.min";
import {formatNumber} from "../utils/StringHelperFunctions"; import {formatNumber} from "../utils/StringHelperFunctions";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement"; import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {removeElement} from "../utils/uiHelpers/removeElement"; import {removeElement} from "../utils/uiHelpers/removeElement";
@ -242,9 +242,9 @@ function updateActiveScriptsItems(maxTasks=150) {
} }
} }
getElementById("active-scripts-total-production-active").innerText = numeral(total).format('$0.000a'); getElementById("active-scripts-total-production-active").innerText = numeralWrapper.format(total, '$0.000a');
getElementById("active-scripts-total-prod-aug-total").innerText = numeral(Player.scriptProdSinceLastAug).format('$0.000a'); getElementById("active-scripts-total-prod-aug-total").innerText = numeralWrapper.format(Player.scriptProdSinceLastAug, '$0.000a');
getElementById("active-scripts-total-prod-aug-avg").innerText = numeral(Player.scriptProdSinceLastAug / (Player.playtimeSinceLastAug/1000)).format('$0.000a'); getElementById("active-scripts-total-prod-aug-avg").innerText = numeralWrapper.format(Player.scriptProdSinceLastAug / (Player.playtimeSinceLastAug/1000), '$0.000a');
return total; return total;
} }

@ -7,6 +7,7 @@ import {Faction, Factions, factionExists,
import {Locations} from "./Locations"; import {Locations} from "./Locations";
import {Player} from "./Player"; import {Player} from "./Player";
import {hackWorldDaemon, redPillFlag} from "./RedPill"; import {hackWorldDaemon, redPillFlag} from "./RedPill";
import {numeralWrapper} from "./ui/numeralFormat";
import {KEY} from "../utils/helpers/keyCodes"; import {KEY} from "../utils/helpers/keyCodes";
import {createProgressBarText} from "../utils/helpers/createProgressBarText"; import {createProgressBarText} from "../utils/helpers/createProgressBarText";
@ -14,7 +15,6 @@ import {dialogBoxCreate} from "../utils/DialogBox";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement"; import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
import numeral from "numeral/min/numeral.min";
import {addOffset} from "../utils/helpers/addOffset"; import {addOffset} from "../utils/helpers/addOffset";
import {appendLineBreaks} from "../utils/uiHelpers/appendLineBreaks"; import {appendLineBreaks} from "../utils/uiHelpers/appendLineBreaks";
import {clearObject} from "../utils/helpers/clearObject"; import {clearObject} from "../utils/helpers/clearObject";
@ -1191,7 +1191,7 @@ Bladeburner.prototype.completeAction = function() {
if (isOperation && this.logging.ops) { if (isOperation && this.logging.ops) {
this.log(action.name + " successfully completed! Gained " + formatNumber(gain, 3) + " rank"); this.log(action.name + " successfully completed! Gained " + formatNumber(gain, 3) + " rank");
} else if (!isOperation && this.logging.contracts) { } else if (!isOperation && this.logging.contracts) {
this.log(action.name + " contract successfully completed! Gained " + formatNumber(gain, 3) + " rank and " + numeral(moneyGain).format("$0.000a")); this.log(action.name + " contract successfully completed! Gained " + formatNumber(gain, 3) + " rank and " + numeralWrapper.format(moneyGain, "$0.000a"));
} }
} }
isOperation ? this.completeOperation(true) : this.completeContract(true); isOperation ? this.completeOperation(true) : this.completeContract(true);
@ -2207,10 +2207,10 @@ Bladeburner.prototype.updateOverviewContent = function() {
"Team Size: " + formatNumber(this.teamSize, 0) + "<br>" + "Team Size: " + formatNumber(this.teamSize, 0) + "<br>" +
"Team Members Lost: " + formatNumber(this.teamLost, 0) + "<br><br>" + "Team Members Lost: " + formatNumber(this.teamLost, 0) + "<br><br>" +
"Num Times Hospitalized: " + this.numHosp + "<br>" + "Num Times Hospitalized: " + this.numHosp + "<br>" +
"Money Lost From Hospitalizations: " + numeral(this.moneyLost).format("$0.000a") + "<br><br>" + "Money Lost From Hospitalizations: " + numeralWrapper.format(this.moneyLost, "$0.000a") + "<br><br>" +
"Current City: " + this.city + "<br>"; "Current City: " + this.city + "<br>";
DomElems.overviewEstPop.childNodes[0].nodeValue = "Est. Synthoid Population: " + numeral(this.getCurrentCity().popEst).format("0.000a"); DomElems.overviewEstPop.childNodes[0].nodeValue = "Est. Synthoid Population: " + numeralWrapper.format(this.getCurrentCity().popEst, "0.000a");
DomElems.overviewEstComms.childNodes[0].nodeValue = "Est. Synthoid Communities: " + formatNumber(this.getCurrentCity().comms, 0); DomElems.overviewEstComms.childNodes[0].nodeValue = "Est. Synthoid Communities: " + formatNumber(this.getCurrentCity().comms, 0);
DomElems.overviewChaos.childNodes[0].nodeValue = "City Chaos: " + formatNumber(this.getCurrentCity().chaos); DomElems.overviewChaos.childNodes[0].nodeValue = "City Chaos: " + formatNumber(this.getCurrentCity().chaos);
DomElems.overviewSkillPoints.innerText = "Skill Points: " + formatNumber(this.skillPoints, 0); DomElems.overviewSkillPoints.innerText = "Skill Points: " + formatNumber(this.skillPoints, 0);

@ -1,5 +1,6 @@
import {Player} from "./Player"; import {Player} from "./Player";
import numeral from "numeral/min/numeral.min";
import {numeralWrapper} from "./ui/numeralFormat";
function CharacterOverview() { function CharacterOverview() {
this.hp = document.getElementById("character-hp-text"); this.hp = document.getElementById("character-hp-text");
@ -33,7 +34,7 @@ CharacterOverview.prototype.update = function() {
let changed = false; let changed = false;
changed = replaceAndChanged(this.hp, Player.hp + " / " + Player.max_hp) || changed; changed = replaceAndChanged(this.hp, Player.hp + " / " + Player.max_hp) || changed;
changed = replaceAndChanged(this.money, numeral(Player.money.toNumber()).format('($0.000a)')) || changed; changed = replaceAndChanged(this.money, numeralWrapper.format(Player.money.toNumber(), '($0.000a)')) || changed;
changed = replaceAndChanged(this.hack, (Player.hacking_skill).toLocaleString()) || changed; changed = replaceAndChanged(this.hack, (Player.hacking_skill).toLocaleString()) || changed;
changed = replaceAndChanged(this.str, (Player.strength).toLocaleString()) || changed; changed = replaceAndChanged(this.str, (Player.strength).toLocaleString()) || changed;
changed = replaceAndChanged(this.def, (Player.defense).toLocaleString()) || changed; changed = replaceAndChanged(this.def, (Player.defense).toLocaleString()) || changed;

@ -5,11 +5,12 @@ import {Locations} from "./Locations";
import {Player} from "./Player"; import {Player} from "./Player";
import Decimal from "decimal.js"; import Decimal from "decimal.js";
import {numeralWrapper} from "./ui/numeralFormat";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {clearSelector} from "../utils/uiHelpers/clearSelector"; import {clearSelector} from "../utils/uiHelpers/clearSelector";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
import numeral from "numeral/min/numeral.min";
import {createElement} from "../utils/uiHelpers/createElement"; import {createElement} from "../utils/uiHelpers/createElement";
import {createPopup} from "../utils/uiHelpers/createPopup"; import {createPopup} from "../utils/uiHelpers/createPopup";
import {Page, routing} from "./ui/navigationTracking"; import {Page, routing} from "./ui/navigationTracking";
@ -453,46 +454,46 @@ var IndustryStartingCosts = {
var IndustryDescriptions = { var IndustryDescriptions = {
Energy: "Engage in the production and distribution of energy.<br><br>" + Energy: "Engage in the production and distribution of energy.<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.Energy).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Energy, "$0.000a") + "<br>" +
"Recommended starting Industry: NO", "Recommended starting Industry: NO",
Utilities: "Distributes water and provides wastewater services.<br><br>" + Utilities: "Distributes water and provides wastewater services.<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.Utilities).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Utilities, "$0.000a") + "<br>" +
"Recommended starting Industry: NO", "Recommended starting Industry: NO",
Agriculture: "Cultive crops and breed livestock to produce food.<br><br>" + Agriculture: "Cultive crops and breed livestock to produce food.<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.Agriculture).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Agriculture, "$0.000a") + "<br>" +
"Recommended starting Industry: YES", "Recommended starting Industry: YES",
Fishing: "Produce food through the breeding and processing of fish and fish products<br><br>" + Fishing: "Produce food through the breeding and processing of fish and fish products<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.Fishing).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Fishing, "$0.000a") + "<br>" +
"Recommended starting Industry: NO", "Recommended starting Industry: NO",
Mining: "Extract and process metals from the earth.<br><br>" + Mining: "Extract and process metals from the earth.<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.Mining).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Mining, "$0.000a") + "<br>" +
"Recommended starting Industry: NO", "Recommended starting Industry: NO",
Food: "Create your own restaurants all around the world.<br><br>" + Food: "Create your own restaurants all around the world.<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.Food).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Food, "$0.000a") + "<br>" +
"Recommended starting Industry: YES", "Recommended starting Industry: YES",
Tobacco: "Create and distribute tobacco and tobacco-related products.<br><br>" + Tobacco: "Create and distribute tobacco and tobacco-related products.<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.Tobacco).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Tobacco, "$0.000a") + "<br>" +
"Recommended starting Industry: YES", "Recommended starting Industry: YES",
Chemical: "Product industrial chemicals<br><br>" + Chemical: "Product industrial chemicals<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.Chemical).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Chemical, "$0.000a") + "<br>" +
"Recommended starting Industry: NO", "Recommended starting Industry: NO",
Pharmaceutical: "Discover, develop, and create new pharmaceutical drugs.<br><br>" + Pharmaceutical: "Discover, develop, and create new pharmaceutical drugs.<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.Pharmaceutical).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Pharmaceutical, "$0.000a") + "<br>" +
"Recommended starting Industry: NO", "Recommended starting Industry: NO",
Computer: "Develop and manufacture new computer hardware and networking infrastructures.<br><br>" + Computer: "Develop and manufacture new computer hardware and networking infrastructures.<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.Computer).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Computer, "$0.000a") + "<br>" +
"Recommended starting Industry: NO", "Recommended starting Industry: NO",
Robotics: "Develop and create robots.<br><br>" + Robotics: "Develop and create robots.<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.Robotics).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Robotics, "$0.000a") + "<br>" +
"Recommended starting Industry: NO", "Recommended starting Industry: NO",
Software: "Develop computer software and create AI Cores.<br><br>" + Software: "Develop computer software and create AI Cores.<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.Software).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Software, "$0.000a") + "<br>" +
"Recommended starting Industry: YES", "Recommended starting Industry: YES",
Healthcare: "Create and manage hospitals.<br><br>" + Healthcare: "Create and manage hospitals.<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.Healthcare).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Healthcare, "$0.000a") + "<br>" +
"Recommended starting Industry: NO", "Recommended starting Industry: NO",
RealEstate: "Develop and manage real estate properties.<br><br>" + RealEstate: "Develop and manage real estate properties.<br><br>" +
"Starting cost: " + numeral(IndustryStartingCosts.RealEstate).format("$0.000a") + "<br>" + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.RealEstate, "$0.000a") + "<br>" +
"Recommended starting Industry: NO", "Recommended starting Industry: NO",
} }
@ -1776,7 +1777,7 @@ Employee.prototype.createUI = function(panel, corporation) {
"Experience: " + formatNumber(this.exp, 3) + "<br>" + "Experience: " + formatNumber(this.exp, 3) + "<br>" +
"Creativity: " + formatNumber(effCre, 3) + "<br>" + "Creativity: " + formatNumber(effCre, 3) + "<br>" +
"Efficiency: " + formatNumber(effEff, 3) + "<br>" + "Efficiency: " + formatNumber(effEff, 3) + "<br>" +
"Salary: " + numeral(this.sal).format("$0.000a") + "/ s<br>", "Salary: " + numeralWrapper.format(this.sal, "$0.000a") + "/ s<br>",
})); }));
//Selector for employee position //Selector for employee position
@ -1826,7 +1827,7 @@ Employee.prototype.updateUI = function(panel, corporation) {
"Experience: " + formatNumber(this.exp, 3) + "<br>" + "Experience: " + formatNumber(this.exp, 3) + "<br>" +
"Creativity: " + formatNumber(effCre, 3) + "<br>" + "Creativity: " + formatNumber(effCre, 3) + "<br>" +
"Efficiency: " + formatNumber(effEff, 3) + "<br>" + "Efficiency: " + formatNumber(effEff, 3) + "<br>" +
"Salary: " + numeral(this.sal).format("$0.000a") + "/ s<br>"; "Salary: " + numeralWrapper.format(this.sal, "$0.000a") + "/ s<br>";
} }
Employee.prototype.toJSON = function() { Employee.prototype.toJSON = function() {
@ -1963,7 +1964,7 @@ OfficeSpace.prototype.findEmployees = function(parentRefs) {
"Experience: " + formatNumber(employee.exp, 1) + "<br>" + "Experience: " + formatNumber(employee.exp, 1) + "<br>" +
"Creativity: " + formatNumber(employee.cre, 1) + "<br>" + "Creativity: " + formatNumber(employee.cre, 1) + "<br>" +
"Efficiency: " + formatNumber(employee.eff, 1) + "<br>" + "Efficiency: " + formatNumber(employee.eff, 1) + "<br>" +
"Salary: " + numeral(employee.sal).format('$0.000a') + " \ s<br>", "Salary: " + numeralWrapper.format(employee.sal, '$0.000a') + " \ s<br>",
clickListener:()=>{ clickListener:()=>{
office.hireEmployee(employee, parentRefs); office.hireEmployee(employee, parentRefs);
removeElementById("cmpy-mgmt-hire-employee-popup"); removeElementById("cmpy-mgmt-hire-employee-popup");
@ -2155,7 +2156,7 @@ Warehouse.prototype.createUI = function(parentRefs) {
//Upgrade warehouse size button //Upgrade warehouse size button
var upgradeCost = WarehouseUpgradeBaseCost * Math.pow(1.07, this.level+1); var upgradeCost = WarehouseUpgradeBaseCost * Math.pow(1.07, this.level+1);
industryWarehouseUpgradeSizeButton = createElement("a", { industryWarehouseUpgradeSizeButton = createElement("a", {
innerText:"Upgrade Warehouse Size - " + numeral(upgradeCost).format('$0.000a'), innerText:"Upgrade Warehouse Size - " + numeralWrapper.format(upgradeCost, '$0.000a'),
display:"inline-block", display:"inline-block",
class: company.funds.lt(upgradeCost) ? "a-link-button-inactive" : "a-link-button", class: company.funds.lt(upgradeCost) ? "a-link-button-inactive" : "a-link-button",
clickListener:()=>{ clickListener:()=>{
@ -2721,9 +2722,9 @@ Warehouse.prototype.createProductUI = function(product, parentRefs) {
"Aesthetics: " + formatNumber(product.aes, 3) + "<br>" + "Aesthetics: " + formatNumber(product.aes, 3) + "<br>" +
"Features: " + formatNumber(product.fea, 3) + "Features: " + formatNumber(product.fea, 3) +
cmpAndDmdText + "</span></p><br>" + cmpAndDmdText + "</span></p><br>" +
"<p class='tooltip'>Est. Production Cost: " + numeral(product.pCost / ProductProductionCostRatio).format("$0.000a") + "<p class='tooltip'>Est. Production Cost: " + numeralWrapper.format(product.pCost / ProductProductionCostRatio, "$0.000a") +
"<span class='tooltiptext'>An estimate of the material cost it takes to create this Product.</span></p><br>" + "<span class='tooltiptext'>An estimate of the material cost it takes to create this Product.</span></p><br>" +
"<p class='tooltip'>Est. Market Price: " + numeral(product.pCost + product.rat / product.mku).format("$0.000a") + "<p class='tooltip'>Est. Market Price: " + numeralWrapper.format(product.pCost + product.rat / product.mku, "$0.000a") +
"<span class='tooltiptext'>An estimate of how much consumers are willing to pay for this product. " + "<span class='tooltiptext'>An estimate of how much consumers are willing to pay for this product. " +
"Setting the sale price above this may result in less sales. Setting the sale price below this may result " + "Setting the sale price above this may result in less sales. Setting the sale price below this may result " +
"in more sales.</span></p>" "in more sales.</span></p>"
@ -2740,7 +2741,7 @@ Warehouse.prototype.createProductUI = function(product, parentRefs) {
if (isString(product.sCost)) { if (isString(product.sCost)) {
sellInnerTextString += (" @ " + product.sCost); sellInnerTextString += (" @ " + product.sCost);
} else { } else {
sellInnerTextString += (" @ " + numeral(product.sCost).format("$0.000a")); sellInnerTextString += (" @ " + numeralWrapper.format(product.sCost, "$0.000a"));
} }
} }
div.appendChild(createElement("a", { div.appendChild(createElement("a", {
@ -3175,9 +3176,9 @@ Corporation.prototype.getInvestment = function() {
noBtn.addEventListener("click", ()=>{ noBtn.addEventListener("click", ()=>{
return yesNoBoxClose(); return yesNoBoxClose();
}); });
yesNoBoxCreate("An investment firm has offered you " + numeral(funding).format('$0.000a') + yesNoBoxCreate("An investment firm has offered you " + numeralWrapper.format(funding, '$0.000a') +
" in funding in exchange for a " + numeral(percShares*100).format("0.000a") + " in funding in exchange for a " + numeralWrapper.format(percShares*100, "0.000a") +
"% stake in the company (" + numeral(investShares).format('0.000a') + " shares).<br><br>" + "% stake in the company (" + numeralWrapper.format(investShares, '0.000a') + " shares).<br><br>" +
"Do you accept or reject this offer?"); "Do you accept or reject this offer?");
} }
@ -3188,11 +3189,11 @@ Corporation.prototype.goPublic = function() {
innerHTML: "Enter the number of shares you would like to issue " + innerHTML: "Enter the number of shares you would like to issue " +
"for your IPO. These shares will be publicly sold " + "for your IPO. These shares will be publicly sold " +
"and you will no longer own them. Your Corporation will receive " + "and you will no longer own them. Your Corporation will receive " +
numeral(initialSharePrice).format('$0.000a') + " per share " + numeralWrapper.format(initialSharePrice, '$0.000a') + " per share " +
"(the IPO money will be deposited directly into your Corporation's funds).<br><br>" + "(the IPO money will be deposited directly into your Corporation's funds).<br><br>" +
"Furthermore, issuing more shares now will help drive up " + "Furthermore, issuing more shares now will help drive up " +
"your company's stock price in the future.<br><br>" + "your company's stock price in the future.<br><br>" +
"You have a total of " + numeral(this.numShares).format("0.000a") + " of shares that you can issue.", "You have a total of " + numeralWrapper.format(this.numShares, "0.000a") + " of shares that you can issue.",
}); });
var yesBtn; var yesBtn;
var input = createElement("input", { var input = createElement("input", {
@ -3635,7 +3636,7 @@ Corporation.prototype.displayCorporationOverviewContent = function() {
innerHTML: "Enter the number of shares you would like to sell. The money from " + innerHTML: "Enter the number of shares you would like to sell. The money from " +
"selling your shares will go directly to you (NOT your Corporation). " + "selling your shares will go directly to you (NOT your Corporation). " +
"The current price of your " + "The current price of your " +
"company's stock is " + numeral(currentStockPrice).format("$0.000a"), "company's stock is " + numeralWrapper.format(currentStockPrice, "$0.000a"),
}); });
var profitIndicator = createElement("p", {}); var profitIndicator = createElement("p", {});
var input = createElement("input", { var input = createElement("input", {
@ -3648,7 +3649,7 @@ Corporation.prototype.displayCorporationOverviewContent = function() {
profitIndicator.innerText = "You don't have this many shares to sell!"; profitIndicator.innerText = "You don't have this many shares to sell!";
} else { } else {
profitIndicator.innerText = "Sell " + numShares + " shares for a total of " + profitIndicator.innerText = "Sell " + numShares + " shares for a total of " +
numeral(numShares * currentStockPrice).format('$0.000a'); numeralWrapper.format(numShares * currentStockPrice, '$0.000a');
} }
} }
}); });
@ -3702,7 +3703,7 @@ Corporation.prototype.displayCorporationOverviewContent = function() {
innerHTML: "Enter the number of shares you would like to buy back at market price. To purchase " + innerHTML: "Enter the number of shares you would like to buy back at market price. To purchase " +
"these shares, you must use your own money (NOT your Corporation's funds). " + "these shares, you must use your own money (NOT your Corporation's funds). " +
"The current price of your " + "The current price of your " +
"company's stock is " + numeral(currentStockPrice).format("$0.000a") + "company's stock is " + numeralWrapper.format(currentStockPrice, "$0.000a") +
". Your company currently has " + formatNumber(this.issuedShares, 3) + " outstanding stock shares", ". Your company currently has " + formatNumber(this.issuedShares, 3) + " outstanding stock shares",
}); });
var costIndicator = createElement("p", {}); var costIndicator = createElement("p", {});
@ -3719,7 +3720,7 @@ Corporation.prototype.displayCorporationOverviewContent = function() {
} else { } else {
console.log("here"); console.log("here");
costIndicator.innerText = "Purchase " + numShares + " shares for a total of " + costIndicator.innerText = "Purchase " + numShares + " shares for a total of " +
numeral(numShares * currentStockPrice).format('$0.000a'); numeralWrapper.format(numShares * currentStockPrice, '$0.000a');
} }
} }
}); });
@ -3734,7 +3735,7 @@ Corporation.prototype.displayCorporationOverviewContent = function() {
dialogBoxCreate("ERROR: There are not this many oustanding shares to buy back"); dialogBoxCreate("ERROR: There are not this many oustanding shares to buy back");
} else if (shares * tempStockPrice > Player.money) { } else if (shares * tempStockPrice > Player.money) {
dialogBoxCreate("ERROR: You do not have enough money to purchase this many shares (you need " + dialogBoxCreate("ERROR: You do not have enough money to purchase this many shares (you need " +
numeral(shares * tempStockPrice).format("$0.000a") + ")"); numeralWrapper.format(shares * tempStockPrice, "$0.000a") + ")");
} else { } else {
this.numShares += shares; this.numShares += shares;
if (isNaN(this.issuedShares)) { if (isNaN(this.issuedShares)) {
@ -3958,7 +3959,7 @@ Corporation.prototype.displayCorporationOverviewContent = function() {
upgradeContainer.appendChild(createElement("div", { upgradeContainer.appendChild(createElement("div", {
class:"cmpy-mgmt-upgrade-div", width:"45%", class:"cmpy-mgmt-upgrade-div", width:"45%",
innerHTML:upgrade[2] + " - " + numeral(upgrade[1]).format("$0.000a"), innerHTML:upgrade[2] + " - " + numeralWrapper.format(upgrade[1], "$0.000a"),
tooltip: upgrade[3], tooltip: upgrade[3],
clickListener:()=>{ clickListener:()=>{
if (corp.funds.lt(upgrade[1])) { if (corp.funds.lt(upgrade[1])) {
@ -3990,7 +3991,7 @@ Corporation.prototype.displayCorporationOverviewContent = function() {
var cost = baseCost * Math.pow(priceMult, corp.upgrades[i]); var cost = baseCost * Math.pow(priceMult, corp.upgrades[i]);
upgradeContainer.appendChild(createElement("div", { upgradeContainer.appendChild(createElement("div", {
class:"cmpy-mgmt-upgrade-div", width:"45%", class:"cmpy-mgmt-upgrade-div", width:"45%",
innerHTML:upgrade[4] + " - " + numeral(cost).format("$0.000a"), innerHTML:upgrade[4] + " - " + numeralWrapper.format(cost, "$0.000a"),
tooltip:upgrade[5], tooltip:upgrade[5],
clickListener:()=>{ clickListener:()=>{
if (corp.funds.lt(cost)) { if (corp.funds.lt(cost)) {
@ -4018,14 +4019,14 @@ Corporation.prototype.updateCorporationOverviewContent = function() {
totalExpenses = new Decimal(0); totalExpenses = new Decimal(0);
var profit = this.revenue.minus(this.expenses).toNumber(), var profit = this.revenue.minus(this.expenses).toNumber(),
profitStr = profit >= 0 ? numeral(profit).format("$0.000a") : "-" + numeral(-1 * profit).format("$0.000a"); profitStr = profit >= 0 ? numeralWrapper.format(profit, "$0.000a") : "-" + numeralWrapper.format(-1 * profit, "$0.000a");
var txt = "Total Funds: " + numeral(totalFunds.toNumber()).format('$0.000a') + "<br>" + var txt = "Total Funds: " + numeralWrapper.format(totalFunds.toNumber(), '$0.000a') + "<br>" +
"Total Revenue: " + numeral(this.revenue.toNumber()).format("$0.000a") + " / s<br>" + "Total Revenue: " + numeralWrapper.format(this.revenue.toNumber(), "$0.000a") + " / s<br>" +
"Total Expenses: " + numeral(this.expenses.toNumber()).format("$0.000a") + "/ s<br>" + "Total Expenses: " + numeralWrapper.format(this.expenses.toNumber(), "$0.000a") + "/ s<br>" +
"Total Profits: " + profitStr + " / s<br>" + "Total Profits: " + profitStr + " / s<br>" +
"Publicly Traded: " + (this.public ? "Yes" : "No") + "<br>" + "Publicly Traded: " + (this.public ? "Yes" : "No") + "<br>" +
"Owned Stock Shares: " + numeral(this.numShares).format('0.000a') + "<br>" + "Owned Stock Shares: " + numeralWrapper.format(this.numShares, '0.000a') + "<br>" +
"Stock Price: " + (this.public ? "$" + formatNumber(this.sharePrice, 2) : "N/A") + "<br><br>"; "Stock Price: " + (this.public ? "$" + formatNumber(this.sharePrice, 2) : "N/A") + "<br><br>";
var prodMult = this.getProductionMultiplier(), var prodMult = this.getProductionMultiplier(),
@ -4071,7 +4072,7 @@ Corporation.prototype.displayDivisionContent = function(division, city) {
var popupId = "cmpy-mgmt-expand-city-popup"; var popupId = "cmpy-mgmt-expand-city-popup";
var text = createElement("p", { var text = createElement("p", {
innerText: "Would you like to expand into a new city by opening an office? " + innerText: "Would you like to expand into a new city by opening an office? " +
"This would cost " + numeral(OfficeInitialCost).format('$0.000a'), "This would cost " + numeralWrapper.format(OfficeInitialCost, '$0.000a'),
}); });
var citySelector = createElement("select", {class: "dropdown", margin:"5px"}); var citySelector = createElement("select", {class: "dropdown", margin:"5px"});
for (var cityName in division.offices) { for (var cityName in division.offices) {
@ -4180,7 +4181,7 @@ Corporation.prototype.displayDivisionContent = function(division, city) {
} }
industryOverviewUpgrades.appendChild(createElement("div", { industryOverviewUpgrades.appendChild(createElement("div", {
class:"cmpy-mgmt-upgrade-div", display:"inline-block", class:"cmpy-mgmt-upgrade-div", display:"inline-block",
innerHTML:upgrade[4] + ' - ' + numeral(cost).format("$0.000a"), innerHTML:upgrade[4] + ' - ' + numeralWrapper.format(cost, "$0.000a"),
tooltip:upgrade[5], tooltip:upgrade[5],
clickListener:()=>{ clickListener:()=>{
if (corp.funds.lt(cost)) { if (corp.funds.lt(cost)) {
@ -4428,7 +4429,7 @@ Corporation.prototype.displayDivisionContent = function(division, city) {
var confirmBtn = createElement("a", { var confirmBtn = createElement("a", {
class: this.funds.lt(upgradeCost) ? "a-link-button-inactive" : "a-link-button", class: this.funds.lt(upgradeCost) ? "a-link-button-inactive" : "a-link-button",
display:"inline-block", margin:"4px", innerText:"by 3", display:"inline-block", margin:"4px", innerText:"by 3",
tooltip:numeral(upgradeCost).format("$0.000a"), tooltip:numeralWrapper.format(upgradeCost, "$0.000a"),
clickListener:()=>{ clickListener:()=>{
if (this.funds.lt(upgradeCost)) { if (this.funds.lt(upgradeCost)) {
dialogBoxCreate("You don't have enough company funds to purchase this upgrade!"); dialogBoxCreate("You don't have enough company funds to purchase this upgrade!");
@ -4445,7 +4446,7 @@ Corporation.prototype.displayDivisionContent = function(division, city) {
var confirmBtn15 = createElement("a", { var confirmBtn15 = createElement("a", {
class: this.funds.lt(upgradeCost15) ? "a-link-button-inactive" : "a-link-button", class: this.funds.lt(upgradeCost15) ? "a-link-button-inactive" : "a-link-button",
display:"inline-block", margin:"4px", innerText:"by 15", display:"inline-block", margin:"4px", innerText:"by 15",
tooltip:numeral(upgradeCost15).format("$0.000a"), tooltip:numeralWrapper.format(upgradeCost15, "$0.000a"),
clickListener:()=>{ clickListener:()=>{
if (this.funds.lt(upgradeCost15)) { if (this.funds.lt(upgradeCost15)) {
dialogBoxCreate("You don't have enough company funds to purchase this upgrade!"); dialogBoxCreate("You don't have enough company funds to purchase this upgrade!");
@ -4462,7 +4463,7 @@ Corporation.prototype.displayDivisionContent = function(division, city) {
var confirmBtnMax = createElement("a", { var confirmBtnMax = createElement("a", {
class:this.funds.lt(upgradeCostMax) ? "a-link-button-inactive" : "a-link-button", class:this.funds.lt(upgradeCostMax) ? "a-link-button-inactive" : "a-link-button",
display:"inline-block", margin:"4px", innerText:"by MAX (" + maxNum*OfficeInitialSize + ")", display:"inline-block", margin:"4px", innerText:"by MAX (" + maxNum*OfficeInitialSize + ")",
tooltip:numeral(upgradeCostMax).format("$0.000a"), tooltip:numeralWrapper.format(upgradeCostMax, "$0.000a"),
clickListener:()=>{ clickListener:()=>{
if (this.funds.lt(upgradeCostMax)) { if (this.funds.lt(upgradeCostMax)) {
dialogBoxCreate("You don't have enough company funds to purchase this upgrade!"); dialogBoxCreate("You don't have enough company funds to purchase this upgrade!");
@ -4511,7 +4512,7 @@ Corporation.prototype.displayDivisionContent = function(division, city) {
totalCostTxt.innerText = "Invalid value entered!" totalCostTxt.innerText = "Invalid value entered!"
} else { } else {
var totalCost = input.value * office.employees.length; var totalCost = input.value * office.employees.length;
totalCostTxt.innerText = "Throwing this party will cost a total of " + numeral(totalCost).format('$0.000a'); totalCostTxt.innerText = "Throwing this party will cost a total of " + numeralWrapper.format(totalCost, '$0.000a');
} }
}, },
onkeyup:(e)=>{ onkeyup:(e)=>{
@ -4726,7 +4727,7 @@ Corporation.prototype.updateDivisionContent = function(division) {
var vechain = (this.unlockUpgrades[4] === 1); var vechain = (this.unlockUpgrades[4] === 1);
//Industry Overview Text //Industry Overview Text
var profit = division.lastCycleRevenue.minus(division.lastCycleExpenses).toNumber(), var profit = division.lastCycleRevenue.minus(division.lastCycleExpenses).toNumber(),
profitStr = profit >= 0 ? numeral(profit).format("$0.000a") : "-" + numeral(-1 * profit).format("$0.000a"); profitStr = profit >= 0 ? numeralWrapper.format(profit, "$0.000a") : "-" + numeralWrapper.format(-1 * profit, "$0.000a");
var advertisingInfo = ""; var advertisingInfo = "";
if (vechain) { if (vechain) {
var advertisingFactors = division.getAdvertisingFactors(); var advertisingFactors = division.getAdvertisingFactors();
@ -4745,12 +4746,12 @@ Corporation.prototype.updateDivisionContent = function(division) {
removeChildrenFromElement(industryOverviewText); removeChildrenFromElement(industryOverviewText);
industryOverviewText.appendChild(createElement("p", { industryOverviewText.appendChild(createElement("p", {
innerHTML:"Industry: " + division.type + " (Corp Funds: " + numeral(this.funds.toNumber()).format("$0.000a") + ")<br><br>" + innerHTML:"Industry: " + division.type + " (Corp Funds: " + numeralWrapper.format(this.funds.toNumber(), "$0.000a") + ")<br><br>" +
"Awareness: " + formatNumber(division.awareness, 3) + "<br>" + "Awareness: " + formatNumber(division.awareness, 3) + "<br>" +
"Popularity: " + formatNumber(division.popularity, 3) + "<br>" + "Popularity: " + formatNumber(division.popularity, 3) + "<br>" +
advertisingInfo + "<br>" + advertisingInfo + "<br>" +
"Revenue: " + numeral(division.lastCycleRevenue.toNumber()).format("$0.000a") + " / s<br>" + "Revenue: " + numeralWrapper.format(division.lastCycleRevenue.toNumber(), "$0.000a") + " / s<br>" +
"Expenses: " + numeral(division.lastCycleExpenses.toNumber()).format("$0.000a") + " /s<br>" + "Expenses: " + numeralWrapper.format(division.lastCycleExpenses.toNumber(), "$0.000a") + " /s<br>" +
"Profit: " + profitStr + " / s<br><br>" "Profit: " + profitStr + " / s<br><br>"
})); }));
industryOverviewText.appendChild(createElement("p", { industryOverviewText.appendChild(createElement("p", {

@ -10,13 +10,13 @@ import {Player} from "./Player";
import {Settings} from "./Settings"; import {Settings} from "./Settings";
import {Page, routing} from "./ui/navigationTracking"; import {Page, routing} from "./ui/navigationTracking";
import {numeralWrapper} from "./ui/numeralFormat";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {factionInvitationBoxCreate} from "../utils/FactionInvitationBox"; import {factionInvitationBoxCreate} from "../utils/FactionInvitationBox";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement"; import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {createElement} from "../utils/uiHelpers/createElement"; import {createElement} from "../utils/uiHelpers/createElement";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
import numeral from "numeral/min/numeral.min";
import {formatNumber} from "../utils/StringHelperFunctions"; import {formatNumber} from "../utils/StringHelperFunctions";
import {yesNoBoxCreate, yesNoBoxGetYesButton, import {yesNoBoxCreate, yesNoBoxGetYesButton,
yesNoBoxGetNoButton, yesNoBoxClose} from "../utils/YesNoBox"; yesNoBoxGetNoButton, yesNoBoxClose} from "../utils/YesNoBox";
@ -337,7 +337,7 @@ function displayFactionContent(factionName) {
Player.loseMoney(amt); Player.loseMoney(amt);
var repGain = amt / CONSTANTS.DonateMoneyToRepDivisor * Player.faction_rep_mult; var repGain = amt / CONSTANTS.DonateMoneyToRepDivisor * Player.faction_rep_mult;
faction.playerReputation += repGain; faction.playerReputation += repGain;
dialogBoxCreate("You just donated " + numeral(amt).format("$0.000a") + " to " + dialogBoxCreate("You just donated " + numeralWrapper.format(amt, "$0.000a") + " to " +
faction.name + " to gain " + formatNumber(repGain, 3) + " reputation"); faction.name + " to gain " + formatNumber(repGain, 3) + " reputation");
displayFactionContent(factionName); displayFactionContent(factionName);
} }
@ -603,10 +603,10 @@ function createFactionAugmentationDisplayElements(augmentationsList, augs, facti
pElem.innerHTML = "ALREADY OWNED"; pElem.innerHTML = "ALREADY OWNED";
} else if (faction.playerReputation >= req) { } else if (faction.playerReputation >= req) {
aElem.setAttribute("class", "a-link-button"); aElem.setAttribute("class", "a-link-button");
pElem.innerHTML = "UNLOCKED - " + numeral(aug.baseCost * factionInfo.augmentationPriceMult).format("$0.000a"); pElem.innerHTML = "UNLOCKED - " + numeralWrapper.format(aug.baseCost * factionInfo.augmentationPriceMult, "$0.000a");
} else { } else {
aElem.setAttribute("class", "a-link-button-inactive"); aElem.setAttribute("class", "a-link-button-inactive");
pElem.innerHTML = "LOCKED (Requires " + formatNumber(req, 1) + " faction reputation) - " + numeral(aug.baseCost * factionInfo.augmentationPriceMult).format("$0.000a"); pElem.innerHTML = "LOCKED (Requires " + formatNumber(req, 1) + " faction reputation) - " + numeralWrapper.format(aug.baseCost * factionInfo.augmentationPriceMult, "$0.000a");
pElem.style.color = "red"; pElem.style.color = "red";
} }
aDiv.appendChild(aElem); aDiv.appendChild(aElem);

@ -3,6 +3,7 @@ import {Engine} from "./engine";
import {Faction, Factions, import {Faction, Factions,
displayFactionContent} from "./Faction"; displayFactionContent} from "./Faction";
import {Player} from "./Player"; import {Player} from "./Player";
import {numeralWrapper} from "./ui/numeralFormat";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
@ -10,7 +11,6 @@ import {createAccordionElement} from "../utils/uiHelpers/createA
import {createElement} from "../utils/uiHelpers/createElement"; import {createElement} from "../utils/uiHelpers/createElement";
import {createPopup} from "../utils/uiHelpers/createPopup"; import {createPopup} from "../utils/uiHelpers/createPopup";
import {Page, routing} from "./ui/navigationTracking"; import {Page, routing} from "./ui/navigationTracking";
import numeral from "numeral/min/numeral.min";
import {formatNumber} from "../utils/StringHelperFunctions"; import {formatNumber} from "../utils/StringHelperFunctions";
import {getRandomInt} from "../utils/helpers/getRandomInt"; import {getRandomInt} from "../utils/helpers/getRandomInt";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement"; import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
@ -892,7 +892,7 @@ function createGangMemberUpgradePanel(memberObj) {
var upg = upgradeArray[j]; var upg = upgradeArray[j];
(function (upg, div, memberObj) { (function (upg, div, memberObj) {
div.appendChild(createElement("a", { div.appendChild(createElement("a", {
innerText:upg.name + " - " + numeral(upg.cost).format("$0.000a"), innerText:upg.name + " - " + numeralWrapper.format(upg.cost, "$0.000a"),
class:"a-link-button", margin:"2px", padding:"2px", display:"block", class:"a-link-button", margin:"2px", padding:"2px", display:"block",
fontSize:"12px", fontSize:"12px",
tooltip:upg.desc, tooltip:upg.desc,
@ -1411,12 +1411,12 @@ function updateGangMemberDisplayElement(memberObj) {
var stats = document.getElementById(name + "gang-member-stats-text"); var stats = document.getElementById(name + "gang-member-stats-text");
if (stats) { if (stats) {
stats.innerHTML = stats.innerHTML =
"Hacking: " + formatNumber(memberObj.hack, 0) + " (" + numeral(memberObj.hack_exp).format('(0.00a)') + " exp)<br>" + "Hacking: " + formatNumber(memberObj.hack, 0) + " (" + numeralWrapper.format(memberObj.hack_exp, '(0.00a)') + " exp)<br>" +
"Strength: " + formatNumber(memberObj.str, 0) + " (" + numeral(memberObj.str_exp).format('(0.00a)') + " exp)<br>" + "Strength: " + formatNumber(memberObj.str, 0) + " (" + numeralWrapper.format(memberObj.str_exp, '(0.00a)') + " exp)<br>" +
"Defense: " + formatNumber(memberObj.def, 0) + " (" + numeral(memberObj.def_exp).format('(0.00a)') + " exp)<br>" + "Defense: " + formatNumber(memberObj.def, 0) + " (" + numeralWrapper.format(memberObj.def_exp, '(0.00a)') + " exp)<br>" +
"Dexterity: " + formatNumber(memberObj.dex, 0) + " (" + numeral(memberObj.dex_exp).format('(0.00a)') + " exp)<br>" + "Dexterity: " + formatNumber(memberObj.dex, 0) + " (" + numeralWrapper.format(memberObj.dex_exp, '(0.00a)') + " exp)<br>" +
"Agility: " + formatNumber(memberObj.agi, 0) + " (" + numeral(memberObj.agi_exp).format('(0.00a)') + " exp)<br>" + "Agility: " + formatNumber(memberObj.agi, 0) + " (" + numeralWrapper.format(memberObj.agi_exp, '(0.00a)') + " exp)<br>" +
"Charisma: " + formatNumber(memberObj.cha, 0) + " (" + numeral(memberObj.cha_exp).format('(0.00a)') + " exp)<br>"; "Charisma: " + formatNumber(memberObj.cha, 0) + " (" + numeralWrapper.format(memberObj.cha_exp, '(0.00a)') + " exp)<br>";
} }
var gainInfo = document.getElementById(name + "gang-member-gain-info"); var gainInfo = document.getElementById(name + "gang-member-gain-info");

@ -15,10 +15,11 @@ import {purchaseServer,
import {Settings} from "./Settings"; import {Settings} from "./Settings";
import {SpecialServerNames, SpecialServerIps} from "./SpecialServerIps"; import {SpecialServerNames, SpecialServerIps} from "./SpecialServerIps";
import {numeralWrapper} from "./ui/numeralFormat";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners"; import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
import {createRandomIp} from "../utils/IPAddress"; import {createRandomIp} from "../utils/IPAddress";
import numeral from "numeral/min/numeral.min";
import {formatNumber} from "../utils/StringHelperFunctions"; import {formatNumber} from "../utils/StringHelperFunctions";
import {yesNoBoxCreate, yesNoTxtInpBoxCreate, import {yesNoBoxCreate, yesNoTxtInpBoxCreate,
yesNoBoxGetYesButton, yesNoBoxGetNoButton, yesNoBoxGetYesButton, yesNoBoxGetNoButton,
@ -1788,7 +1789,7 @@ function initLocationButtons() {
}); });
yesNoBoxCreate("Would you like to purchase additional RAM for your home computer? <br><br>" + yesNoBoxCreate("Would you like to purchase additional RAM for your home computer? <br><br>" +
"This will upgrade your RAM from " + ram + "GB to " + ram*2 + "GB. <br><br>" + "This will upgrade your RAM from " + ram + "GB to " + ram*2 + "GB. <br><br>" +
"This will cost " + numeral(cost).format('$0.000a')); "This will cost " + numeralWrapper.format(cost, '$0.000a'));
}); });
purchaseHomeCores.addEventListener("click", function(e) { purchaseHomeCores.addEventListener("click", function(e) {
@ -1825,7 +1826,7 @@ function initLocationButtons() {
yesNoBoxCreate("Would you like to purchase an additional CPU Core for your home computer? Each CPU Core " + yesNoBoxCreate("Would you like to purchase an additional CPU Core for your home computer? Each CPU Core " +
"lets you start with an additional Core Node in Hacking Missions.<br><br>" + "lets you start with an additional Core Node in Hacking Missions.<br><br>" +
"Purchasing an additional core (for a total of " + (Player.getHomeComputer().cpuCores + 1) + ") will " + "Purchasing an additional core (for a total of " + (Player.getHomeComputer().cpuCores + 1) + ") will " +
"cost " + numeral(cost).format('$0.000a')); "cost " + numeralWrapper.format(cost, '$0.000a'));
}); });
travelToAevum.addEventListener("click", function(e) { travelToAevum.addEventListener("click", function(e) {

@ -21,12 +21,13 @@ import {SpecialServerIps, SpecialServerNames} from "./SpecialServerIps";
import {SourceFiles, applySourceFile} from "./SourceFile"; import {SourceFiles, applySourceFile} from "./SourceFile";
import Decimal from "decimal.js"; import Decimal from "decimal.js";
import {numeralWrapper} from "./ui/numeralFormat";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners"; import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
import {createRandomIp} from "../utils/IPAddress"; import {createRandomIp} from "../utils/IPAddress";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
import numeral from "numeral/min/numeral.min";
import {formatNumber, import {formatNumber,
convertTimeMsToTimeElapsedString} from "../utils/StringHelperFunctions"; convertTimeMsToTimeElapsedString} from "../utils/StringHelperFunctions";
@ -1486,7 +1487,7 @@ PlayerObject.prototype.finishCrime = function(cancelled) {
if (this.committingCrimeThruSingFn) { if (this.committingCrimeThruSingFn) {
if(this.singFnCrimeWorkerScript.disableLogs.ALL == null && this.singFnCrimeWorkerScript.disableLogs.commitCrime == null) { if(this.singFnCrimeWorkerScript.disableLogs.ALL == null && this.singFnCrimeWorkerScript.disableLogs.commitCrime == null) {
this.singFnCrimeWorkerScript.scriptRef.log("Crime successful! Gained " + this.singFnCrimeWorkerScript.scriptRef.log("Crime successful! Gained " +
numeral(this.workMoneyGained).format("$0.000a") + ", " + numeralWrapper.format(this.workMoneyGained, "$0.000a") + ", " +
formatNumber(this.workHackExpGained, 3) + " hack exp, " + formatNumber(this.workHackExpGained, 3) + " hack exp, " +
formatNumber(this.workStrExpGained, 3) + " str exp, " + formatNumber(this.workStrExpGained, 3) + " str exp, " +
formatNumber(this.workDefExpGained, 3) + " def exp, " + formatNumber(this.workDefExpGained, 3) + " def exp, " +
@ -1600,7 +1601,7 @@ PlayerObject.prototype.hospitalize = function() {
dialogBoxCreate( dialogBoxCreate(
"You were in critical condition! You were taken to the hospital where " + "You were in critical condition! You were taken to the hospital where " +
"luckily they were able to save your life. You were charged " + "luckily they were able to save your life. You were charged " +
numeral(this.max_hp * CONSTANTS.HospitalCostPerHp).format('$0.000a') numeralWrapper.format(this.max_hp * CONSTANTS.HospitalCostPerHp, '$0.000a')
); );
} }

@ -33,7 +33,7 @@ import {post} from "./ui/postToTerminal";
import {TextFile} from "./TextFile"; import {TextFile} from "./TextFile";
import {parse, Node} from "../utils/acorn"; import {parse, Node} from "../utils/acorn";
import {Page, routing} from "./ui/navigationTracking"; import {Page, routing} from "./ui/navigationTracking";
import numeral from "numeral/min/numeral.min"; import {numeralWrapper} from "./ui/numeralFormat";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
@ -251,7 +251,7 @@ function updateScriptEditorContent() {
var codeCopy = code.repeat(1); var codeCopy = code.repeat(1);
var ramUsage = calculateRamUsage(codeCopy); var ramUsage = calculateRamUsage(codeCopy);
if (ramUsage !== -1) { if (ramUsage !== -1) {
scriptEditorRamText.innerText = "RAM: " + numeral(ramUsage).format('0.00') + " GB"; scriptEditorRamText.innerText = "RAM: " + numeralWrapper.format(ramUsage, '0.00') + " GB";
} else { } else {
scriptEditorRamText.innerText = "RAM: Syntax Error"; scriptEditorRamText.innerText = "RAM: Syntax Error";
} }
@ -874,7 +874,7 @@ function scriptCalculateOfflineProduction(runningScriptObj) {
console.log(runningScriptObj.filename + " called grow() on " + serv.hostname + " " + timesGrown + " times while offline"); console.log(runningScriptObj.filename + " called grow() on " + serv.hostname + " " + timesGrown + " times while offline");
runningScriptObj.log("Called grow() on " + serv.hostname + " " + timesGrown + " times while offline"); runningScriptObj.log("Called grow() on " + serv.hostname + " " + timesGrown + " times while offline");
var growth = processSingleServerGrowth(serv, timesGrown * 450); var growth = processSingleServerGrowth(serv, timesGrown * 450);
runningScriptObj.log(serv.hostname + " grown by " + numeral(growth * 100 - 100).format('0.000000%') + " from grow() calls made while offline"); runningScriptObj.log(serv.hostname + " grown by " + numeralWrapper.format(growth * 100 - 100, '0.000000%') + " from grow() calls made while offline");
} }
} }

@ -10,7 +10,7 @@ import {clearEventListeners} from "../utils/uiHelpers/clearEv
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
import {Page, routing} from "./ui/navigationTracking"; import {Page, routing} from "./ui/navigationTracking";
import numeral from "numeral/min/numeral.min"; import {numeralWrapper} from "./ui/numeralFormat";
import {exceptionAlert} from "../utils/helpers/exceptionAlert"; import {exceptionAlert} from "../utils/helpers/exceptionAlert";
import {getRandomInt} from "../utils/helpers/getRandomInt"; import {getRandomInt} from "../utils/helpers/getRandomInt";
import {KEY} from "../utils/helpers/keyCodes"; import {KEY} from "../utils/helpers/keyCodes";
@ -87,7 +87,7 @@ function cancelOrder(params, workerScript=null) {
//Order properties are passed in. Need to look for the order //Order properties are passed in. Need to look for the order
var stockOrders = StockMarket["Orders"][params.stock.symbol]; var stockOrders = StockMarket["Orders"][params.stock.symbol];
var orderTxt = params.stock.symbol + " - " + params.shares + " @ " + var orderTxt = params.stock.symbol + " - " + params.shares + " @ " +
numeral(params.price).format('$0.000a'); numeralWrapper.format(params.price, '$0.000a');
for (var i = 0; i < stockOrders.length; ++i) { for (var i = 0; i < stockOrders.length; ++i) {
var order = stockOrders[i]; var order = stockOrders[i];
if (params.shares === order.shares && if (params.shares === order.shares &&
@ -410,7 +410,7 @@ function buyStock(stock, shares) {
var totalPrice = stock.price * shares; var totalPrice = stock.price * shares;
if (Player.money.lt(totalPrice + CONSTANTS.StockMarketCommission)) { if (Player.money.lt(totalPrice + CONSTANTS.StockMarketCommission)) {
dialogBoxCreate("You do not have enough money to purchase this. You need " + dialogBoxCreate("You do not have enough money to purchase this. You need " +
numeral(totalPrice + CONSTANTS.StockMarketCommission).format('($0.000a)') + "."); numeralWrapper.format(totalPrice + CONSTANTS.StockMarketCommission, '($0.000a)') + ".");
return false; return false;
} }
@ -420,9 +420,9 @@ function buyStock(stock, shares) {
stock.playerShares += shares; stock.playerShares += shares;
stock.playerAvgPx = newTotal / stock.playerShares; stock.playerAvgPx = newTotal / stock.playerShares;
updateStockPlayerPosition(stock); updateStockPlayerPosition(stock);
dialogBoxCreate("Bought " + numeral(shares).format('0,0') + " shares of " + stock.symbol + " at " + dialogBoxCreate("Bought " + numeralWrapper.format(shares, '0,0') + " shares of " + stock.symbol + " at " +
numeral(stock.price).format('($0.000a)') + " per share. Paid " + numeralWrapper.format(stock.price, '($0.000a)') + " per share. Paid " +
numeral(CONSTANTS.StockMarketCommission).format('($0.000a)') + " in commission fees."); numeralWrapper.format(CONSTANTS.StockMarketCommission, '($0.000a)') + " in commission fees.");
return true; return true;
} }
@ -443,9 +443,9 @@ function sellStock(stock, shares) {
stock.playerAvgPx = 0; stock.playerAvgPx = 0;
} }
updateStockPlayerPosition(stock); updateStockPlayerPosition(stock);
dialogBoxCreate("Sold " + numeral(shares).format('0,0') + " shares of " + stock.symbol + " at " + dialogBoxCreate("Sold " + numeralWrapper.format(shares, '0,0') + " shares of " + stock.symbol + " at " +
numeral(stock.price).format('($0.000a)') + " per share. After commissions, you gained " + numeralWrapper.format(stock.price, '($0.000a)') + " per share. After commissions, you gained " +
"a total of " + numeral(gains).format('($0.000a)') + "."); "a total of " + numeralWrapper.format(gains, '($0.000a)') + ".");
return true; return true;
} }
@ -469,10 +469,10 @@ function shortStock(stock, shares, workerScript=null) {
if (tixApi) { if (tixApi) {
workerScript.scriptRef.log("ERROR: shortStock() failed because you do not have enough " + workerScript.scriptRef.log("ERROR: shortStock() failed because you do not have enough " +
"money to purchase this short position. You need " + "money to purchase this short position. You need " +
numeral(totalPrice + CONSTANTS.StockMarketCommission).format('($0.000a)') + "."); numeralWrapper.format(totalPrice + CONSTANTS.StockMarketCommission, '($0.000a)') + ".");
} else { } else {
dialogBoxCreate("You do not have enough money to purchase this short position. You need " + dialogBoxCreate("You do not have enough money to purchase this short position. You need " +
numeral(totalPrice + CONSTANTS.StockMarketCommission).format('($0.000a)') + "."); numeralWrapper.format(totalPrice + CONSTANTS.StockMarketCommission, '($0.000a)') + ".");
} }
return false; return false;
@ -486,14 +486,14 @@ function shortStock(stock, shares, workerScript=null) {
updateStockPlayerPosition(stock); updateStockPlayerPosition(stock);
if (tixApi) { if (tixApi) {
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.shortStock == null) { if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.shortStock == null) {
workerScript.scriptRef.log("Bought a short position of " + numeral(shares).format('0,0') + " shares of " + stock.symbol + " at " + workerScript.scriptRef.log("Bought a short position of " + numeralWrapper.format(shares, '0,0') + " shares of " + stock.symbol + " at " +
numeral(stock.price).format('($0.000a)') + " per share. Paid " + numeralWrapper.format(stock.price, '($0.000a)') + " per share. Paid " +
numeral(CONSTANTS.StockMarketCommission).format('($0.000a)') + " in commission fees."); numeralWrapper.format(CONSTANTS.StockMarketCommission, '($0.000a)') + " in commission fees.");
} }
} else { } else {
dialogBoxCreate("Bought a short position of " + numeral(shares).format('0,0') + " shares of " + stock.symbol + " at " + dialogBoxCreate("Bought a short position of " + numeralWrapper.format(shares, '0,0') + " shares of " + stock.symbol + " at " +
numeral(stock.price).format('($0.000a)') + " per share. Paid " + numeralWrapper.format(stock.price, '($0.000a)') + " per share. Paid " +
numeral(CONSTANTS.StockMarketCommission).format('($0.000a)') + " in commission fees."); numeralWrapper.format(CONSTANTS.StockMarketCommission, '($0.000a)') + " in commission fees.");
} }
return true; return true;
} }
@ -530,14 +530,14 @@ function sellShort(stock, shares, workerScript=null) {
updateStockPlayerPosition(stock); updateStockPlayerPosition(stock);
if (tixApi) { if (tixApi) {
if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.sellShort == null) { if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.sellShort == null) {
workerScript.scriptRef.log("Sold your short position of " + numeral(shares).format('0,0') + " shares of " + stock.symbol + " at " + workerScript.scriptRef.log("Sold your short position of " + numeralWrapper.format(shares, '0,0') + " shares of " + stock.symbol + " at " +
numeral(stock.price).format('($0.000a)') + " per share. After commissions, you gained " + numeralWrapper.format(stock.price, '($0.000a)') + " per share. After commissions, you gained " +
"a total of " + numeral(origCost + profit).format('($0.000a)') + "."); "a total of " + numeralWrapper.format(origCost + profit, '($0.000a)') + ".");
} }
} else { } else {
dialogBoxCreate("Sold your short position of " + numeral(shares).format('0,0') + " shares of " + stock.symbol + " at " + dialogBoxCreate("Sold your short position of " + numeralWrapper.format(shares, '0,0') + " shares of " + stock.symbol + " at " +
numeral(stock.price).format('($0.000a)') + " per share. After commissions, you gained " + numeralWrapper.format(stock.price, '($0.000a)') + " per share. After commissions, you gained " +
"a total of " + numeral(origCost + profit).format('($0.000a)') + "."); "a total of " + numeralWrapper.format(origCost + profit, '($0.000a)') + ".");
} }
return true; return true;
@ -696,7 +696,7 @@ function displayStockMarketContent() {
//Purchase WSE Account button //Purchase WSE Account button
var wseAccountButton = clearEventListeners("stock-market-buy-account"); var wseAccountButton = clearEventListeners("stock-market-buy-account");
stylePurchaseButton(wseAccountButton, CONSTANTS.WSEAccountCost, Player.hasWseAccount, stylePurchaseButton(wseAccountButton, CONSTANTS.WSEAccountCost, Player.hasWseAccount,
"Buy WSE Account - " + numeral(CONSTANTS.WSEAccountCost).format('($0.000a)'), "Buy WSE Account - " + numeralWrapper.format(CONSTANTS.WSEAccountCost, '($0.000a)'),
"WSE Account - Purchased"); "WSE Account - Purchased");
wseAccountButton.addEventListener("click", function() { wseAccountButton.addEventListener("click", function() {
Player.hasWseAccount = true; Player.hasWseAccount = true;
@ -710,7 +710,7 @@ function displayStockMarketContent() {
//Purchase TIX API Access account //Purchase TIX API Access account
var tixApiAccessButton = clearEventListeners("stock-market-buy-tix-api"); var tixApiAccessButton = clearEventListeners("stock-market-buy-tix-api");
stylePurchaseButton(tixApiAccessButton, CONSTANTS.TIXAPICost, Player.hasTixApiAccess, stylePurchaseButton(tixApiAccessButton, CONSTANTS.TIXAPICost, Player.hasTixApiAccess,
"Buy Trade Information eXchange (TIX) API Access - " + numeral(CONSTANTS.TIXAPICost).format('($0.000a)'), "Buy Trade Information eXchange (TIX) API Access - " + numeralWrapper.format(CONSTANTS.TIXAPICost, '($0.000a)'),
"TIX API Access - Purchased"); "TIX API Access - Purchased");
tixApiAccessButton.addEventListener("click", function() { tixApiAccessButton.addEventListener("click", function() {
Player.hasTixApiAccess = true; Player.hasTixApiAccess = true;
@ -722,7 +722,7 @@ function displayStockMarketContent() {
//Purchase Four Sigma Market Data Feed //Purchase Four Sigma Market Data Feed
var marketDataButton = clearEventListeners("stock-market-buy-4s-data"); var marketDataButton = clearEventListeners("stock-market-buy-4s-data");
stylePurchaseButton(marketDataButton, CONSTANTS.MarketData4SCost, Player.has4SData, stylePurchaseButton(marketDataButton, CONSTANTS.MarketData4SCost, Player.has4SData,
"Buy 4S Market Data Access - " + numeral(CONSTANTS.MarketData4SCost).format('($0.000a)'), "Buy 4S Market Data Access - " + numeralWrapper.format(CONSTANTS.MarketData4SCost, '($0.000a)'),
"4S Market Data - Purchased"); "4S Market Data - Purchased");
marketDataButton.addEventListener("click", function() { marketDataButton.addEventListener("click", function() {
Player.has4SData = true; Player.has4SData = true;
@ -760,7 +760,7 @@ function displayStockMarketContent() {
//Purchase Four Sigma Market Data TIX API (Requires TIX API Access) //Purchase Four Sigma Market Data TIX API (Requires TIX API Access)
var marketDataTixButton = clearEventListeners("stock-market-buy-4s-tix-api"); var marketDataTixButton = clearEventListeners("stock-market-buy-4s-tix-api");
stylePurchaseButton(marketDataTixButton, CONSTANTS.MarketDataTixApi4SCost, Player.has4SDataTixApi, stylePurchaseButton(marketDataTixButton, CONSTANTS.MarketDataTixApi4SCost, Player.has4SDataTixApi,
"Buy 4S Market Data TIX API Access - " + numeral(CONSTANTS.MarketDataTixApi4SCost).format('($0.000a)'), "Buy 4S Market Data TIX API Access - " + numeralWrapper.format(CONSTANTS.MarketDataTixApi4SCost, '($0.000a)'),
"4S Market Data TIX API - Purchased"); "4S Market Data TIX API - Purchased");
if (Player.hasTixApiAccess) { if (Player.hasTixApiAccess) {
marketDataTixButton.addEventListener("click", function() { marketDataTixButton.addEventListener("click", function() {
@ -823,7 +823,7 @@ function displayStockMarketContent() {
console.log("Creating Stock Market UI"); console.log("Creating Stock Market UI");
commissionText.innerHTML = commissionText.innerHTML =
"Commission Fees: Every transaction you make has a " + "Commission Fees: Every transaction you make has a " +
numeral(CONSTANTS.StockMarketCommission).format('($0.000a)') + " commission fee.<br><br>" + numeralWrapper.format(CONSTANTS.StockMarketCommission, '($0.000a)') + " commission fee.<br><br>" +
"WARNING: When you reset after installing Augmentations, the Stock Market is reset. " + "WARNING: When you reset after installing Augmentations, the Stock Market is reset. " +
"This means all your positions are lost, so make sure to sell your stocks before installing " + "This means all your positions are lost, so make sure to sell your stocks before installing " +
"Augmentations!"; "Augmentations!";
@ -1020,7 +1020,7 @@ function createStockTicker(stock) {
var li = document.createElement("li"), hdr = document.createElement("button"); var li = document.createElement("li"), hdr = document.createElement("button");
hdr.classList.add("accordion-header"); hdr.classList.add("accordion-header");
hdr.setAttribute("id", tickerId + "-hdr"); hdr.setAttribute("id", tickerId + "-hdr");
hdr.innerHTML = stock.name + " - " + stock.symbol + " - " + numeral(stock.price).format('($0.000a)'); hdr.innerHTML = stock.name + " - " + stock.symbol + " - " + numeralWrapper.format(stock.price, '($0.000a)');
//Div for entire panel //Div for entire panel
var stockDiv = document.createElement("div"); var stockDiv = document.createElement("div");
@ -1297,9 +1297,9 @@ function updateStockTicker(stock, increase) {
} }
return; return;
} }
let hdrText = stock.name + " (" + stock.symbol + ") - " + numeral(stock.price).format('($0.000a)'); let hdrText = stock.name + " (" + stock.symbol + ") - " + numeralWrapper.format(stock.price, '($0.000a)');
if (Player.has4SData) { if (Player.has4SData) {
hdrText += " - Volatility: " + numeral(stock.mv).format('0,0.00') + "%" + hdrText += " - Volatility: " + numeralWrapper.format(stock.mv, '0,0.00') + "%" +
" - Price Forecast: "; " - Price Forecast: ";
if (stock.b) { if (stock.b) {
hdrText += "+".repeat(Math.floor(stock.otlkMag/10) + 1); hdrText += "+".repeat(Math.floor(stock.otlkMag/10) + 1);
@ -1363,21 +1363,21 @@ function updateStockPlayerPosition(stock) {
"<h1 class='tooltip stock-market-position-text'>Long Position: " + "<h1 class='tooltip stock-market-position-text'>Long Position: " +
"<span class='tooltiptext'>Shares in the long position will increase " + "<span class='tooltiptext'>Shares in the long position will increase " +
"in value if the price of the corresponding stock increases</span></h1>" + "in value if the price of the corresponding stock increases</span></h1>" +
"<br>Shares: " + numeral(stock.playerShares).format('0,0') + "<br>Shares: " + numeralWrapper.format(stock.playerShares, '0,0') +
"<br>Average Price: " + numeral(stock.playerAvgPx).format('$0.000a') + "<br>Average Price: " + numeralWrapper.format(stock.playerAvgPx, '$0.000a') +
" (Total Cost: " + numeral(totalCost).format('$0.000a') + ")" + " (Total Cost: " + numeralWrapper.format(totalCost, '$0.000a') + ")" +
"<br>Profit: " + numeral(gains).format('$0.000a') + "<br>Profit: " + numeralWrapper.format(gains, '$0.000a') +
" (" + numeral(percentageGains).format('0.00%') + ")<br><br>"; " (" + numeralWrapper.format(percentageGains, '0.00%') + ")<br><br>";
if (Player.bitNodeN === 8 || (hasWallStreetSF && wallStreetSFLvl >= 2)) { if (Player.bitNodeN === 8 || (hasWallStreetSF && wallStreetSFLvl >= 2)) {
stock.posTxtEl.innerHTML += stock.posTxtEl.innerHTML +=
"<h1 class='tooltip stock-market-position-text'>Short Position: " + "<h1 class='tooltip stock-market-position-text'>Short Position: " +
"<span class='tooltiptext'>Shares in short position will increase " + "<span class='tooltiptext'>Shares in short position will increase " +
"in value if the price of the corresponding stock decreases</span></h1>" + "in value if the price of the corresponding stock decreases</span></h1>" +
"<br>Shares: " + numeral(stock.playerShortShares).format('0,0') + "<br>Shares: " + numeralWrapper.format(stock.playerShortShares, '0,0') +
"<br>Average Price: " + numeral(stock.playerAvgShortPx).format('$0.000a') + "<br>Average Price: " + numeralWrapper.format(stock.playerAvgShortPx, '$0.000a') +
" (Total Cost: " + numeral(shortTotalCost).format('$0.000a') + ")" + " (Total Cost: " + numeralWrapper.format(shortTotalCost, '$0.000a') + ")" +
"<br>Profit: " + numeral(shortGains).format('$0.000a') + "<br>Profit: " + numeralWrapper.format(shortGains, '$0.000a') +
" (" + numeral(shortPercentageGains).format('0.00%') + ")" + " (" + numeralWrapper.format(shortPercentageGains, '0.00%') + ")" +
"<br><br><h1 class='stock-market-position-text'>Orders: </h1>"; "<br><br><h1 class='stock-market-position-text'>Orders: </h1>";
} }
@ -1440,7 +1440,7 @@ function updateStockOrderList(stock) {
var posText = (order.pos === PositionTypes.Long ? "Long Position" : "Short Position"); var posText = (order.pos === PositionTypes.Long ? "Long Position" : "Short Position");
li.style.color = "white"; li.style.color = "white";
li.innerText = order.type + " - " + posText + " - " + li.innerText = order.type + " - " + posText + " - " +
order.shares + " @ " + numeral(order.price).format('($0.000a)'); order.shares + " @ " + numeralWrapper.format(order.price, '($0.000a)');
var cancelButton = document.createElement("span"); var cancelButton = document.createElement("span");
cancelButton.classList.add("stock-market-order-cancel-btn"); cancelButton.classList.add("stock-market-order-cancel-btn");

@ -22,7 +22,6 @@ import {iTutorialNextStep, iTutorialSteps,
import {showLiterature} from "./Literature"; import {showLiterature} from "./Literature";
import {showMessage, Message} from "./Message"; import {showMessage, Message} from "./Message";
import {killWorkerScript, addWorkerScript} from "./NetscriptWorker"; import {killWorkerScript, addWorkerScript} from "./NetscriptWorker";
import numeral from "numeral/min/numeral.min";
import {Player} from "./Player"; import {Player} from "./Player";
import {hackWorldDaemon} from "./RedPill"; import {hackWorldDaemon} from "./RedPill";
import {findRunningScript, RunningScript, import {findRunningScript, RunningScript,
@ -37,6 +36,7 @@ import {TextFile, getTextFile} from "./TextFile";
import {containsAllStrings, import {containsAllStrings,
longestCommonStart} from "../utils/StringHelperFunctions"; longestCommonStart} from "../utils/StringHelperFunctions";
import {Page, routing} from "./ui/navigationTracking"; import {Page, routing} from "./ui/navigationTracking";
import {numeralWrapper} from "./ui/numeralFormat";
import {KEY} from "../utils/helpers/keyCodes"; import {KEY} from "../utils/helpers/keyCodes";
import {addOffset} from "../utils/helpers/addOffset"; import {addOffset} from "../utils/helpers/addOffset";
import {isString} from "../utils/helpers/isString"; import {isString} from "../utils/helpers/isString";
@ -700,11 +700,11 @@ let Terminal = {
server.fortify(CONSTANTS.ServerFortifyAmount); server.fortify(CONSTANTS.ServerFortifyAmount);
post("Hack successful! Gained " + numeral(moneyGained).format('($0,0.00)') + " and " + numeral(expGainedOnSuccess).format('0.0000') + " hacking EXP"); post("Hack successful! Gained " + numeralWrapper.format(moneyGained, '($0,0.00)') + " and " + numeralWrapper.format(expGainedOnSuccess, '0.0000') + " hacking EXP");
} else { //Failure } else { //Failure
//Player only gains 25% exp for failure? TODO Can change this later to balance //Player only gains 25% exp for failure? TODO Can change this later to balance
Player.gainHackingExp(expGainedOnFailure) Player.gainHackingExp(expGainedOnFailure)
post("Failed to hack " + server.hostname + ". Gained " + numeral(expGainedOnFailure).format('0.0000') + " hacking EXP"); post("Failed to hack " + server.hostname + ". Gained " + numeralWrapper.format(expGainedOnFailure, '0.0000') + " hacking EXP");
} }
} }
@ -727,10 +727,10 @@ let Terminal = {
else {rootAccess = "NO";} else {rootAccess = "NO";}
post("Root Access: " + rootAccess); post("Root Access: " + rootAccess);
post("Required hacking skill: " + currServ.requiredHackingSkill); post("Required hacking skill: " + currServ.requiredHackingSkill);
post("Server security level: " + numeral(currServ.hackDifficulty).format('0.000a')); post("Server security level: " + numeralWrapper.format(currServ.hackDifficulty, '0.000a'));
post("Chance to hack: " + numeral(calculateHackingChance(currServ) * 100).format('0.00%')); post("Chance to hack: " + numeralWrapper.format(calculateHackingChance(currServ) * 100, '0.00%'));
post("Time to hack: " + numeral(calculateHackingTime(currServ)).format('0.000') + " seconds"); post("Time to hack: " + numeralWrapper.format(calculateHackingTime(currServ), '0.000') + " seconds");
post("Total money available on server: $" + numeral(currServ.moneyAvailable).format('$0,0.00')); post("Total money available on server: $" + numeralWrapper.format(currServ.moneyAvailable, '$0,0.00'));
post("Required number of open ports for NUKE: " + currServ.numOpenPortsRequired); post("Required number of open ports for NUKE: " + currServ.numOpenPortsRequired);
if (currServ.sshPortOpen) { if (currServ.sshPortOpen) {
@ -1245,7 +1245,7 @@ let Terminal = {
var scriptBaseRamUsage = currServ.scripts[i].ramUsage; var scriptBaseRamUsage = currServ.scripts[i].ramUsage;
var ramUsage = scriptBaseRamUsage * numThreads; var ramUsage = scriptBaseRamUsage * numThreads;
post("This script requires " + numeral(ramUsage).format('0.00') + " GB of RAM to run for " + numThreads + " thread(s)"); post("This script requires " + numeralWrapper.format(ramUsage, '0.00') + " GB of RAM to run for " + numThreads + " thread(s)");
return; return;
} }
} }
@ -1597,7 +1597,7 @@ let Terminal = {
var spacesThread = Array(numSpacesThread+1).join(" "); var spacesThread = Array(numSpacesThread+1).join(" ");
//Calculate and transform RAM usage //Calculate and transform RAM usage
ramUsage = numeral(script.scriptRef.ramUsage * script.threads).format('0.00') + " GB"; ramUsage = numeralWrapper.format(script.scriptRef.ramUsage * script.threads, '0.00') + " GB";
var entry = [script.filename, spacesScript, script.threads, spacesThread, ramUsage]; var entry = [script.filename, spacesScript, script.threads, spacesThread, ramUsage];
post(entry.join("")); post(entry.join(""));
@ -1844,9 +1844,9 @@ let Terminal = {
if (commandArray.length != 1) { if (commandArray.length != 1) {
post("Incorrect usage of free command. Usage: free"); return; post("Incorrect usage of free command. Usage: free"); return;
} }
post("Total: " + numeral(Player.getCurrentServer().maxRam).format('0.00') + " GB"); post("Total: " + numeralWrapper.format(Player.getCurrentServer().maxRam, '0.00') + " GB");
post("Used: " + numeral(Player.getCurrentServer().ramUsed,).format('0.00') + " GB"); post("Used: " + numeralWrapper.format(Player.getCurrentServer().ramUsed, '0.00') + " GB");
post("Available: " + numeral(Player.getCurrentServer().maxRam - Player.getCurrentServer().ramUsed).format('0.00') + " GB"); post("Available: " + numeralWrapper.format(Player.getCurrentServer().maxRam - Player.getCurrentServer().ramUsed, '0.00') + " GB");
}, },
//First called when the "run [program]" command is called. Checks to see if you //First called when the "run [program]" command is called. Checks to see if you
@ -1967,9 +1967,9 @@ let Terminal = {
post("Server base security level: " + targetServer.baseDifficulty); post("Server base security level: " + targetServer.baseDifficulty);
post("Server current security level: " + targetServer.hackDifficulty); post("Server current security level: " + targetServer.hackDifficulty);
post("Server growth rate: " + targetServer.serverGrowth); post("Server growth rate: " + targetServer.serverGrowth);
post("Netscript hack() execution time: " + numeral(scriptCalculateHackingTime(targetServer)).format('0.0') + "s"); post("Netscript hack() execution time: " + numeralWrapper.format(scriptCalculateHackingTime(targetServer), '0.0') + "s");
post("Netscript grow() execution time: " + numeral(scriptCalculateGrowTime(targetServer)).format('0.0') + "s"); post("Netscript grow() execution time: " + numeralWrapper.format(scriptCalculateGrowTime(targetServer), '0.0') + "s");
post("Netscript weaken() execution time: " + numeral(scriptCalculateWeakenTime(targetServer)).format('0.0') + "s"); post("Netscript weaken() execution time: " + numeralWrapper.format(scriptCalculateWeakenTime(targetServer), '0.0') + "s");
}; };
programHandlers[Programs.AutoLink.name] = () => { programHandlers[Programs.AutoLink.name] = () => {
post("This executable cannot be run."); post("This executable cannot be run.");
@ -1995,7 +1995,7 @@ let Terminal = {
if(!fulfilled) { if(!fulfilled) {
post("Augmentations: " + Player.augmentations.length + " / 30"); post("Augmentations: " + Player.augmentations.length + " / 30");
post("Money: " + numeral(Player.money.toNumber()).format('($0.000a)') + " / " + numeral(1e11).format('($0.000a)')); post("Money: " + numeralWrapper.format(Player.money.toNumber(), '($0.000a)') + " / " + numeralWrapper.format(1e11, '($0.000a)'));
post("One path below must be fulfilled..."); post("One path below must be fulfilled...");
post("----------HACKING PATH----------"); post("----------HACKING PATH----------");
post("Hacking skill: " + Player.hacking_skill + " / 2500"); post("Hacking skill: " + Player.hacking_skill + " / 2500");

@ -5,13 +5,14 @@ import {clearEventListeners} from "../utils/uiHelpers/clearEv
import {createElement} from "../utils/uiHelpers/createElement"; import {createElement} from "../utils/uiHelpers/createElement";
import {exceptionAlert} from "../utils/helpers/exceptionAlert"; import {exceptionAlert} from "../utils/helpers/exceptionAlert";
import {removeLoadingScreen} from "../utils/uiHelpers/removeLoadingScreen"; import {removeLoadingScreen} from "../utils/uiHelpers/removeLoadingScreen";
import numeral from "numeral/min/numeral.min";
import {numeralWrapper} from "./ui/numeralFormat";
import {formatNumber, import {formatNumber,
convertTimeMsToTimeElapsedString, convertTimeMsToTimeElapsedString,
replaceAt} from "../utils/StringHelperFunctions"; replaceAt} from "../utils/StringHelperFunctions";
import {loxBoxCreate, logBoxUpdateText, import {loxBoxCreate, logBoxUpdateText,
logBoxOpened} from "../utils/LogBox"; logBoxOpened} from "../utils/LogBox";
import {updateActiveScriptsItems} from "./ActiveScriptsUI"; import {updateActiveScriptsItems} from "./ActiveScriptsUI";
import {Augmentations, installAugmentations, import {Augmentations, installAugmentations,
initAugmentations, AugmentationNames, initAugmentations, AugmentationNames,
@ -587,17 +588,17 @@ const Engine = {
'Money: $' + formatNumber(Player.money.toNumber(), 2) + '<br><br><br>' + 'Money: $' + formatNumber(Player.money.toNumber(), 2) + '<br><br><br>' +
'<b>Stats</b><br><br>' + '<b>Stats</b><br><br>' +
'Hacking Level: ' + (Player.hacking_skill).toLocaleString() + 'Hacking Level: ' + (Player.hacking_skill).toLocaleString() +
' (' + numeral(Player.hacking_exp).format('(0.000a)') + ' experience)<br>' + ' (' + numeralWrapper.format(Player.hacking_exp, '(0.000a)') + ' experience)<br>' +
'Strength: ' + (Player.strength).toLocaleString() + 'Strength: ' + (Player.strength).toLocaleString() +
' (' + numeral(Player.strength_exp).format('(0.000a)') + ' experience)<br>' + ' (' + numeralWrapper.format(Player.strength_exp, '(0.000a)') + ' experience)<br>' +
'Defense: ' + (Player.defense).toLocaleString() + 'Defense: ' + (Player.defense).toLocaleString() +
' (' + numeral(Player.defense_exp).format('(0.000a)')+ ' experience)<br>' + ' (' + numeralWrapper.format(Player.defense_exp, '(0.000a)') + ' experience)<br>' +
'Dexterity: ' + (Player.dexterity).toLocaleString() + 'Dexterity: ' + (Player.dexterity).toLocaleString() +
' (' + numeral(Player.dexterity_exp).format('(0.000a)') + ' experience)<br>' + ' (' + numeralWrapper.format(Player.dexterity_exp, '(0.000a)') + ' experience)<br>' +
'Agility: ' + (Player.agility).toLocaleString() + 'Agility: ' + (Player.agility).toLocaleString() +
' (' + numeral(Player.agility_exp).format('(0.000a)') + ' experience)<br>' + ' (' + numeralWrapper.format(Player.agility_exp, '(0.000a)') + ' experience)<br>' +
'Charisma: ' + (Player.charisma).toLocaleString() + 'Charisma: ' + (Player.charisma).toLocaleString() +
' (' + numeral(Player.charisma_exp).format('(0.000a)') + ' experience)<br>' + ' (' + numeralWrapper.format(Player.charisma_exp, '(0.000a)') + ' experience)<br>' +
intText + '<br><br>' + intText + '<br><br>' +
'<b>Multipliers</b><br><br>' + '<b>Multipliers</b><br><br>' +
'Hacking Chance multiplier: ' + formatNumber(Player.hacking_chance_mult * 100, 2) + '%<br>' + 'Hacking Chance multiplier: ' + formatNumber(Player.hacking_chance_mult * 100, 2) + '%<br>' +

34
src/ui/numeralFormat.js Normal file

@ -0,0 +1,34 @@
import numeral from "numeral";
import 'numeral/locales/bg';
import 'numeral/locales/cs';
import 'numeral/locales/da-dk';
import 'numeral/locales/de';
import 'numeral/locales/en-au';
import 'numeral/locales/en-gb';
import 'numeral/locales/es';
import 'numeral/locales/fr';
import 'numeral/locales/hu';
import 'numeral/locales/it';
import 'numeral/locales/lv';
import 'numeral/locales/no';
import 'numeral/locales/pl';
import 'numeral/locales/ru';
class NumeralFormatter {
updateLocale(l) {
if (numeral.locale(l) == null) {
console.warn(`Invalid locale for numeral: ${l}`);
let defaultValue = 'en';
numeral.locale(defaultValue);
return false;
}
return true;
}
format(n, format) {
return numeral(n).format(format);
}
}
export const numeralWrapper = new NumeralFormatter();

@ -1,7 +1,8 @@
import {Engine} from "../engine"; import {Engine} from "../engine";
import {Settings} from "../Settings"; import {Settings} from "../Settings";
import numeral from "numeral/min/numeral.min"; import {numeralWrapper} from "./NumeralFormat";
function setSettingsLabels() { function setSettingsLabels() {
var nsExecTime = document.getElementById("settingsNSExecTimeRangeValLabel"); var nsExecTime = document.getElementById("settingsNSExecTimeRangeValLabel");
@ -28,6 +29,7 @@ function setSettingsLabels() {
autosaveInterval.innerHTML = Settings.AutosaveInterval; autosaveInterval.innerHTML = Settings.AutosaveInterval;
disableHotkeys.checked = Settings.DisableHotkeys; disableHotkeys.checked = Settings.DisableHotkeys;
locale.value = Settings.Locale; locale.value = Settings.Locale;
numeralWrapper.updateLocale(Settings.Locale); //Initialize locale
//Set handlers for when input changes for sliders //Set handlers for when input changes for sliders
var nsExecTimeInput = document.getElementById("settingsNSExecTimeRangeVal"); var nsExecTimeInput = document.getElementById("settingsNSExecTimeRangeVal");
@ -91,16 +93,14 @@ function setSettingsLabels() {
//Locale selector //Locale selector
locale.onchange = function() { locale.onchange = function() {
if (numeral.locale(locale.value) == null) { if (!numeralWrapper.updateLocale(locale.value)) {
console.warn(`Invalid locale for numeral: ${locale.value}`); console.warn(`Invalid locale for numeral: ${locale.value}`);
let defaultValue = 'en'; let defaultValue = 'en';
numeral.locale(defaultValue);
Settings.Locale = defaultValue; Settings.Locale = defaultValue;
locale.value = defaultValue; locale.value = defaultValue;
return; return;
} }
Settings.Locale = locale.value; Settings.Locale = locale.value;
} }