diff --git a/src/ActiveScriptsUI.js b/src/ActiveScriptsUI.js index f222986e8..7317ef903 100644 --- a/src/ActiveScriptsUI.js +++ b/src/ActiveScriptsUI.js @@ -2,6 +2,7 @@ import {workerScripts, killWorkerScript} from "./NetscriptWorker"; import {Player} from "./Player"; import {getServer} from "./Server"; +import {numeralWrapper} from "./ui/numeralFormat"; import {dialogBoxCreate} from "../utils/DialogBox"; import {createAccordionElement} from "../utils/uiHelpers/createAccordionElement"; import {arrayToString} from "../utils/helpers/arrayToString"; @@ -10,7 +11,6 @@ import {createProgressBarText} from "../utils/helpers/createProgressBarText" import {exceptionAlert} from "../utils/helpers/exceptionAlert"; import {getElementById} from "../utils/uiHelpers/getElementById"; import {logBoxCreate} from "../utils/LogBox"; -import numeral from "numeral/min/numeral.min"; import {formatNumber} from "../utils/StringHelperFunctions"; import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement"; 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-prod-aug-total").innerText = numeral(Player.scriptProdSinceLastAug).format('$0.000a'); - getElementById("active-scripts-total-prod-aug-avg").innerText = numeral(Player.scriptProdSinceLastAug / (Player.playtimeSinceLastAug/1000)).format('$0.000a'); + getElementById("active-scripts-total-production-active").innerText = numeralWrapper.format(total, '$0.000a'); + getElementById("active-scripts-total-prod-aug-total").innerText = numeralWrapper.format(Player.scriptProdSinceLastAug, '$0.000a'); + getElementById("active-scripts-total-prod-aug-avg").innerText = numeralWrapper.format(Player.scriptProdSinceLastAug / (Player.playtimeSinceLastAug/1000), '$0.000a'); return total; } diff --git a/src/Bladeburner.js b/src/Bladeburner.js index fcf1494c1..1af878bae 100644 --- a/src/Bladeburner.js +++ b/src/Bladeburner.js @@ -7,6 +7,7 @@ import {Faction, Factions, factionExists, import {Locations} from "./Locations"; import {Player} from "./Player"; import {hackWorldDaemon, redPillFlag} from "./RedPill"; +import {numeralWrapper} from "./ui/numeralFormat"; import {KEY} from "../utils/helpers/keyCodes"; import {createProgressBarText} from "../utils/helpers/createProgressBarText"; @@ -14,7 +15,6 @@ import {dialogBoxCreate} from "../utils/DialogBox"; import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement"; import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver"; -import numeral from "numeral/min/numeral.min"; import {addOffset} from "../utils/helpers/addOffset"; import {appendLineBreaks} from "../utils/uiHelpers/appendLineBreaks"; import {clearObject} from "../utils/helpers/clearObject"; @@ -1191,7 +1191,7 @@ Bladeburner.prototype.completeAction = function() { if (isOperation && this.logging.ops) { this.log(action.name + " successfully completed! Gained " + formatNumber(gain, 3) + " rank"); } 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); @@ -2207,10 +2207,10 @@ Bladeburner.prototype.updateOverviewContent = function() { "Team Size: " + formatNumber(this.teamSize, 0) + "
" + "Team Members Lost: " + formatNumber(this.teamLost, 0) + "

" + "Num Times Hospitalized: " + this.numHosp + "
" + - "Money Lost From Hospitalizations: " + numeral(this.moneyLost).format("$0.000a") + "

" + + "Money Lost From Hospitalizations: " + numeralWrapper.format(this.moneyLost, "$0.000a") + "

" + "Current City: " + this.city + "
"; - 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.overviewChaos.childNodes[0].nodeValue = "City Chaos: " + formatNumber(this.getCurrentCity().chaos); DomElems.overviewSkillPoints.innerText = "Skill Points: " + formatNumber(this.skillPoints, 0); diff --git a/src/CharacterOverview.js b/src/CharacterOverview.js index e2fb03a6a..328f952ab 100644 --- a/src/CharacterOverview.js +++ b/src/CharacterOverview.js @@ -1,5 +1,6 @@ import {Player} from "./Player"; -import numeral from "numeral/min/numeral.min"; + +import {numeralWrapper} from "./ui/numeralFormat"; function CharacterOverview() { this.hp = document.getElementById("character-hp-text"); @@ -33,7 +34,7 @@ CharacterOverview.prototype.update = function() { let changed = false; 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.str, (Player.strength).toLocaleString()) || changed; changed = replaceAndChanged(this.def, (Player.defense).toLocaleString()) || changed; diff --git a/src/CompanyManagement.js b/src/CompanyManagement.js index abb67e1b7..095349577 100644 --- a/src/CompanyManagement.js +++ b/src/CompanyManagement.js @@ -5,11 +5,12 @@ import {Locations} from "./Locations"; import {Player} from "./Player"; import Decimal from "decimal.js"; +import {numeralWrapper} from "./ui/numeralFormat"; + import {dialogBoxCreate} from "../utils/DialogBox"; import {clearSelector} from "../utils/uiHelpers/clearSelector"; import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver"; -import numeral from "numeral/min/numeral.min"; import {createElement} from "../utils/uiHelpers/createElement"; import {createPopup} from "../utils/uiHelpers/createPopup"; import {Page, routing} from "./ui/navigationTracking"; @@ -453,46 +454,46 @@ var IndustryStartingCosts = { var IndustryDescriptions = { Energy: "Engage in the production and distribution of energy.

" + - "Starting cost: " + numeral(IndustryStartingCosts.Energy).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Energy, "$0.000a") + "
" + "Recommended starting Industry: NO", Utilities: "Distributes water and provides wastewater services.

" + - "Starting cost: " + numeral(IndustryStartingCosts.Utilities).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Utilities, "$0.000a") + "
" + "Recommended starting Industry: NO", Agriculture: "Cultive crops and breed livestock to produce food.

" + - "Starting cost: " + numeral(IndustryStartingCosts.Agriculture).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Agriculture, "$0.000a") + "
" + "Recommended starting Industry: YES", Fishing: "Produce food through the breeding and processing of fish and fish products

" + - "Starting cost: " + numeral(IndustryStartingCosts.Fishing).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Fishing, "$0.000a") + "
" + "Recommended starting Industry: NO", Mining: "Extract and process metals from the earth.

" + - "Starting cost: " + numeral(IndustryStartingCosts.Mining).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Mining, "$0.000a") + "
" + "Recommended starting Industry: NO", Food: "Create your own restaurants all around the world.

" + - "Starting cost: " + numeral(IndustryStartingCosts.Food).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Food, "$0.000a") + "
" + "Recommended starting Industry: YES", Tobacco: "Create and distribute tobacco and tobacco-related products.

" + - "Starting cost: " + numeral(IndustryStartingCosts.Tobacco).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Tobacco, "$0.000a") + "
" + "Recommended starting Industry: YES", Chemical: "Product industrial chemicals

" + - "Starting cost: " + numeral(IndustryStartingCosts.Chemical).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Chemical, "$0.000a") + "
" + "Recommended starting Industry: NO", Pharmaceutical: "Discover, develop, and create new pharmaceutical drugs.

" + - "Starting cost: " + numeral(IndustryStartingCosts.Pharmaceutical).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Pharmaceutical, "$0.000a") + "
" + "Recommended starting Industry: NO", Computer: "Develop and manufacture new computer hardware and networking infrastructures.

" + - "Starting cost: " + numeral(IndustryStartingCosts.Computer).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Computer, "$0.000a") + "
" + "Recommended starting Industry: NO", Robotics: "Develop and create robots.

" + - "Starting cost: " + numeral(IndustryStartingCosts.Robotics).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Robotics, "$0.000a") + "
" + "Recommended starting Industry: NO", Software: "Develop computer software and create AI Cores.

" + - "Starting cost: " + numeral(IndustryStartingCosts.Software).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Software, "$0.000a") + "
" + "Recommended starting Industry: YES", Healthcare: "Create and manage hospitals.

" + - "Starting cost: " + numeral(IndustryStartingCosts.Healthcare).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.Healthcare, "$0.000a") + "
" + "Recommended starting Industry: NO", RealEstate: "Develop and manage real estate properties.

" + - "Starting cost: " + numeral(IndustryStartingCosts.RealEstate).format("$0.000a") + "
" + + "Starting cost: " + numeralWrapper.format(IndustryStartingCosts.RealEstate, "$0.000a") + "
" + "Recommended starting Industry: NO", } @@ -1776,7 +1777,7 @@ Employee.prototype.createUI = function(panel, corporation) { "Experience: " + formatNumber(this.exp, 3) + "
" + "Creativity: " + formatNumber(effCre, 3) + "
" + "Efficiency: " + formatNumber(effEff, 3) + "
" + - "Salary: " + numeral(this.sal).format("$0.000a") + "/ s
", + "Salary: " + numeralWrapper.format(this.sal, "$0.000a") + "/ s
", })); //Selector for employee position @@ -1826,7 +1827,7 @@ Employee.prototype.updateUI = function(panel, corporation) { "Experience: " + formatNumber(this.exp, 3) + "
" + "Creativity: " + formatNumber(effCre, 3) + "
" + "Efficiency: " + formatNumber(effEff, 3) + "
" + - "Salary: " + numeral(this.sal).format("$0.000a") + "/ s
"; + "Salary: " + numeralWrapper.format(this.sal, "$0.000a") + "/ s
"; } Employee.prototype.toJSON = function() { @@ -1963,7 +1964,7 @@ OfficeSpace.prototype.findEmployees = function(parentRefs) { "Experience: " + formatNumber(employee.exp, 1) + "
" + "Creativity: " + formatNumber(employee.cre, 1) + "
" + "Efficiency: " + formatNumber(employee.eff, 1) + "
" + - "Salary: " + numeral(employee.sal).format('$0.000a') + " \ s
", + "Salary: " + numeralWrapper.format(employee.sal, '$0.000a') + " \ s
", clickListener:()=>{ office.hireEmployee(employee, parentRefs); removeElementById("cmpy-mgmt-hire-employee-popup"); @@ -2155,7 +2156,7 @@ Warehouse.prototype.createUI = function(parentRefs) { //Upgrade warehouse size button var upgradeCost = WarehouseUpgradeBaseCost * Math.pow(1.07, this.level+1); industryWarehouseUpgradeSizeButton = createElement("a", { - innerText:"Upgrade Warehouse Size - " + numeral(upgradeCost).format('$0.000a'), + innerText:"Upgrade Warehouse Size - " + numeralWrapper.format(upgradeCost, '$0.000a'), display:"inline-block", class: company.funds.lt(upgradeCost) ? "a-link-button-inactive" : "a-link-button", clickListener:()=>{ @@ -2721,9 +2722,9 @@ Warehouse.prototype.createProductUI = function(product, parentRefs) { "Aesthetics: " + formatNumber(product.aes, 3) + "
" + "Features: " + formatNumber(product.fea, 3) + cmpAndDmdText + "


" + - "

Est. Production Cost: " + numeral(product.pCost / ProductProductionCostRatio).format("$0.000a") + + "

Est. Production Cost: " + numeralWrapper.format(product.pCost / ProductProductionCostRatio, "$0.000a") + "An estimate of the material cost it takes to create this Product.


" + - "

Est. Market Price: " + numeral(product.pCost + product.rat / product.mku).format("$0.000a") + + "

Est. Market Price: " + numeralWrapper.format(product.pCost + product.rat / product.mku, "$0.000a") + "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 " + "in more sales.

" @@ -2740,7 +2741,7 @@ Warehouse.prototype.createProductUI = function(product, parentRefs) { if (isString(product.sCost)) { sellInnerTextString += (" @ " + product.sCost); } else { - sellInnerTextString += (" @ " + numeral(product.sCost).format("$0.000a")); + sellInnerTextString += (" @ " + numeralWrapper.format(product.sCost, "$0.000a")); } } div.appendChild(createElement("a", { @@ -3175,9 +3176,9 @@ Corporation.prototype.getInvestment = function() { noBtn.addEventListener("click", ()=>{ return yesNoBoxClose(); }); - yesNoBoxCreate("An investment firm has offered you " + numeral(funding).format('$0.000a') + - " in funding in exchange for a " + numeral(percShares*100).format("0.000a") + - "% stake in the company (" + numeral(investShares).format('0.000a') + " shares).

" + + yesNoBoxCreate("An investment firm has offered you " + numeralWrapper.format(funding, '$0.000a') + + " in funding in exchange for a " + numeralWrapper.format(percShares*100, "0.000a") + + "% stake in the company (" + numeralWrapper.format(investShares, '0.000a') + " shares).

" + "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 " + "for your IPO. These shares will be publicly sold " + "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).

" + "Furthermore, issuing more shares now will help drive up " + "your company's stock price in the future.

" + - "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 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 " + "selling your shares will go directly to you (NOT your Corporation). " + "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 input = createElement("input", { @@ -3648,7 +3649,7 @@ Corporation.prototype.displayCorporationOverviewContent = function() { profitIndicator.innerText = "You don't have this many shares to sell!"; } else { 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 " + "these shares, you must use your own money (NOT your Corporation's funds). " + "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", }); var costIndicator = createElement("p", {}); @@ -3719,7 +3720,7 @@ Corporation.prototype.displayCorporationOverviewContent = function() { } else { console.log("here"); 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"); } else if (shares * tempStockPrice > Player.money) { 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 { this.numShares += shares; if (isNaN(this.issuedShares)) { @@ -3958,7 +3959,7 @@ Corporation.prototype.displayCorporationOverviewContent = function() { upgradeContainer.appendChild(createElement("div", { 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], clickListener:()=>{ if (corp.funds.lt(upgrade[1])) { @@ -3990,7 +3991,7 @@ Corporation.prototype.displayCorporationOverviewContent = function() { var cost = baseCost * Math.pow(priceMult, corp.upgrades[i]); upgradeContainer.appendChild(createElement("div", { 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], clickListener:()=>{ if (corp.funds.lt(cost)) { @@ -4018,14 +4019,14 @@ Corporation.prototype.updateCorporationOverviewContent = function() { totalExpenses = new Decimal(0); 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') + "
" + - "Total Revenue: " + numeral(this.revenue.toNumber()).format("$0.000a") + " / s
" + - "Total Expenses: " + numeral(this.expenses.toNumber()).format("$0.000a") + "/ s
" + + var txt = "Total Funds: " + numeralWrapper.format(totalFunds.toNumber(), '$0.000a') + "
" + + "Total Revenue: " + numeralWrapper.format(this.revenue.toNumber(), "$0.000a") + " / s
" + + "Total Expenses: " + numeralWrapper.format(this.expenses.toNumber(), "$0.000a") + "/ s
" + "Total Profits: " + profitStr + " / s
" + "Publicly Traded: " + (this.public ? "Yes" : "No") + "
" + - "Owned Stock Shares: " + numeral(this.numShares).format('0.000a') + "
" + + "Owned Stock Shares: " + numeralWrapper.format(this.numShares, '0.000a') + "
" + "Stock Price: " + (this.public ? "$" + formatNumber(this.sharePrice, 2) : "N/A") + "

"; var prodMult = this.getProductionMultiplier(), @@ -4071,7 +4072,7 @@ Corporation.prototype.displayDivisionContent = function(division, city) { var popupId = "cmpy-mgmt-expand-city-popup"; var text = createElement("p", { 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"}); for (var cityName in division.offices) { @@ -4180,7 +4181,7 @@ Corporation.prototype.displayDivisionContent = function(division, city) { } industryOverviewUpgrades.appendChild(createElement("div", { 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], clickListener:()=>{ if (corp.funds.lt(cost)) { @@ -4428,7 +4429,7 @@ Corporation.prototype.displayDivisionContent = function(division, city) { var confirmBtn = createElement("a", { class: this.funds.lt(upgradeCost) ? "a-link-button-inactive" : "a-link-button", display:"inline-block", margin:"4px", innerText:"by 3", - tooltip:numeral(upgradeCost).format("$0.000a"), + tooltip:numeralWrapper.format(upgradeCost, "$0.000a"), clickListener:()=>{ if (this.funds.lt(upgradeCost)) { 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", { class: this.funds.lt(upgradeCost15) ? "a-link-button-inactive" : "a-link-button", display:"inline-block", margin:"4px", innerText:"by 15", - tooltip:numeral(upgradeCost15).format("$0.000a"), + tooltip:numeralWrapper.format(upgradeCost15, "$0.000a"), clickListener:()=>{ if (this.funds.lt(upgradeCost15)) { 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", { class:this.funds.lt(upgradeCostMax) ? "a-link-button-inactive" : "a-link-button", display:"inline-block", margin:"4px", innerText:"by MAX (" + maxNum*OfficeInitialSize + ")", - tooltip:numeral(upgradeCostMax).format("$0.000a"), + tooltip:numeralWrapper.format(upgradeCostMax, "$0.000a"), clickListener:()=>{ if (this.funds.lt(upgradeCostMax)) { 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!" } else { 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)=>{ @@ -4726,7 +4727,7 @@ Corporation.prototype.updateDivisionContent = function(division) { var vechain = (this.unlockUpgrades[4] === 1); //Industry Overview Text 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 = ""; if (vechain) { var advertisingFactors = division.getAdvertisingFactors(); @@ -4745,12 +4746,12 @@ Corporation.prototype.updateDivisionContent = function(division) { removeChildrenFromElement(industryOverviewText); industryOverviewText.appendChild(createElement("p", { - innerHTML:"Industry: " + division.type + " (Corp Funds: " + numeral(this.funds.toNumber()).format("$0.000a") + ")

" + + innerHTML:"Industry: " + division.type + " (Corp Funds: " + numeralWrapper.format(this.funds.toNumber(), "$0.000a") + ")

" + "Awareness: " + formatNumber(division.awareness, 3) + "
" + "Popularity: " + formatNumber(division.popularity, 3) + "
" + advertisingInfo + "
" + - "Revenue: " + numeral(division.lastCycleRevenue.toNumber()).format("$0.000a") + " / s
" + - "Expenses: " + numeral(division.lastCycleExpenses.toNumber()).format("$0.000a") + " /s
" + + "Revenue: " + numeralWrapper.format(division.lastCycleRevenue.toNumber(), "$0.000a") + " / s
" + + "Expenses: " + numeralWrapper.format(division.lastCycleExpenses.toNumber(), "$0.000a") + " /s
" + "Profit: " + profitStr + " / s

" })); industryOverviewText.appendChild(createElement("p", { diff --git a/src/Faction.js b/src/Faction.js index fe3d0b094..7d92905ff 100644 --- a/src/Faction.js +++ b/src/Faction.js @@ -10,13 +10,13 @@ import {Player} from "./Player"; import {Settings} from "./Settings"; import {Page, routing} from "./ui/navigationTracking"; +import {numeralWrapper} from "./ui/numeralFormat"; import {dialogBoxCreate} from "../utils/DialogBox"; import {factionInvitationBoxCreate} from "../utils/FactionInvitationBox"; import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement"; import {createElement} from "../utils/uiHelpers/createElement"; import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver"; -import numeral from "numeral/min/numeral.min"; import {formatNumber} from "../utils/StringHelperFunctions"; import {yesNoBoxCreate, yesNoBoxGetYesButton, yesNoBoxGetNoButton, yesNoBoxClose} from "../utils/YesNoBox"; @@ -337,7 +337,7 @@ function displayFactionContent(factionName) { Player.loseMoney(amt); var repGain = amt / CONSTANTS.DonateMoneyToRepDivisor * Player.faction_rep_mult; 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"); displayFactionContent(factionName); } @@ -603,10 +603,10 @@ function createFactionAugmentationDisplayElements(augmentationsList, augs, facti pElem.innerHTML = "ALREADY OWNED"; } else if (faction.playerReputation >= req) { 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 { 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"; } aDiv.appendChild(aElem); diff --git a/src/Gang.js b/src/Gang.js index cf80569c6..576452328 100644 --- a/src/Gang.js +++ b/src/Gang.js @@ -3,6 +3,7 @@ import {Engine} from "./engine"; import {Faction, Factions, displayFactionContent} from "./Faction"; import {Player} from "./Player"; +import {numeralWrapper} from "./ui/numeralFormat"; import {dialogBoxCreate} from "../utils/DialogBox"; import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver"; @@ -10,7 +11,6 @@ import {createAccordionElement} from "../utils/uiHelpers/createA import {createElement} from "../utils/uiHelpers/createElement"; import {createPopup} from "../utils/uiHelpers/createPopup"; import {Page, routing} from "./ui/navigationTracking"; -import numeral from "numeral/min/numeral.min"; import {formatNumber} from "../utils/StringHelperFunctions"; import {getRandomInt} from "../utils/helpers/getRandomInt"; import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement"; @@ -892,7 +892,7 @@ function createGangMemberUpgradePanel(memberObj) { var upg = upgradeArray[j]; (function (upg, div, memberObj) { 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", fontSize:"12px", tooltip:upg.desc, @@ -1411,12 +1411,12 @@ function updateGangMemberDisplayElement(memberObj) { var stats = document.getElementById(name + "gang-member-stats-text"); if (stats) { stats.innerHTML = - "Hacking: " + formatNumber(memberObj.hack, 0) + " (" + numeral(memberObj.hack_exp).format('(0.00a)') + " exp)
" + - "Strength: " + formatNumber(memberObj.str, 0) + " (" + numeral(memberObj.str_exp).format('(0.00a)') + " exp)
" + - "Defense: " + formatNumber(memberObj.def, 0) + " (" + numeral(memberObj.def_exp).format('(0.00a)') + " exp)
" + - "Dexterity: " + formatNumber(memberObj.dex, 0) + " (" + numeral(memberObj.dex_exp).format('(0.00a)') + " exp)
" + - "Agility: " + formatNumber(memberObj.agi, 0) + " (" + numeral(memberObj.agi_exp).format('(0.00a)') + " exp)
" + - "Charisma: " + formatNumber(memberObj.cha, 0) + " (" + numeral(memberObj.cha_exp).format('(0.00a)') + " exp)
"; + "Hacking: " + formatNumber(memberObj.hack, 0) + " (" + numeralWrapper.format(memberObj.hack_exp, '(0.00a)') + " exp)
" + + "Strength: " + formatNumber(memberObj.str, 0) + " (" + numeralWrapper.format(memberObj.str_exp, '(0.00a)') + " exp)
" + + "Defense: " + formatNumber(memberObj.def, 0) + " (" + numeralWrapper.format(memberObj.def_exp, '(0.00a)') + " exp)
" + + "Dexterity: " + formatNumber(memberObj.dex, 0) + " (" + numeralWrapper.format(memberObj.dex_exp, '(0.00a)') + " exp)
" + + "Agility: " + formatNumber(memberObj.agi, 0) + " (" + numeralWrapper.format(memberObj.agi_exp, '(0.00a)') + " exp)
" + + "Charisma: " + formatNumber(memberObj.cha, 0) + " (" + numeralWrapper.format(memberObj.cha_exp, '(0.00a)') + " exp)
"; } var gainInfo = document.getElementById(name + "gang-member-gain-info"); diff --git a/src/Location.js b/src/Location.js index 4abaee68f..e4713e6e9 100644 --- a/src/Location.js +++ b/src/Location.js @@ -15,10 +15,11 @@ import {purchaseServer, import {Settings} from "./Settings"; import {SpecialServerNames, SpecialServerIps} from "./SpecialServerIps"; +import {numeralWrapper} from "./ui/numeralFormat"; + import {dialogBoxCreate} from "../utils/DialogBox"; import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners"; import {createRandomIp} from "../utils/IPAddress"; -import numeral from "numeral/min/numeral.min"; import {formatNumber} from "../utils/StringHelperFunctions"; import {yesNoBoxCreate, yesNoTxtInpBoxCreate, yesNoBoxGetYesButton, yesNoBoxGetNoButton, @@ -1788,7 +1789,7 @@ function initLocationButtons() { }); yesNoBoxCreate("Would you like to purchase additional RAM for your home computer?

" + "This will upgrade your RAM from " + ram + "GB to " + ram*2 + "GB.

" + - "This will cost " + numeral(cost).format('$0.000a')); + "This will cost " + numeralWrapper.format(cost, '$0.000a')); }); 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 " + "lets you start with an additional Core Node in Hacking Missions.

" + "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) { diff --git a/src/Player.js b/src/Player.js index c05c9c8cb..a47debd37 100644 --- a/src/Player.js +++ b/src/Player.js @@ -21,12 +21,13 @@ import {SpecialServerIps, SpecialServerNames} from "./SpecialServerIps"; import {SourceFiles, applySourceFile} from "./SourceFile"; import Decimal from "decimal.js"; +import {numeralWrapper} from "./ui/numeralFormat"; + import {dialogBoxCreate} from "../utils/DialogBox"; import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners"; import {createRandomIp} from "../utils/IPAddress"; import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver"; -import numeral from "numeral/min/numeral.min"; import {formatNumber, convertTimeMsToTimeElapsedString} from "../utils/StringHelperFunctions"; @@ -1486,7 +1487,7 @@ PlayerObject.prototype.finishCrime = function(cancelled) { if (this.committingCrimeThruSingFn) { if(this.singFnCrimeWorkerScript.disableLogs.ALL == null && this.singFnCrimeWorkerScript.disableLogs.commitCrime == null) { 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.workStrExpGained, 3) + " str exp, " + formatNumber(this.workDefExpGained, 3) + " def exp, " + @@ -1600,7 +1601,7 @@ PlayerObject.prototype.hospitalize = function() { dialogBoxCreate( "You were in critical condition! You were taken to the hospital where " + "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') ); } diff --git a/src/Script.js b/src/Script.js index 27c60e193..4247ec7b0 100755 --- a/src/Script.js +++ b/src/Script.js @@ -33,7 +33,7 @@ import {post} from "./ui/postToTerminal"; import {TextFile} from "./TextFile"; import {parse, Node} from "../utils/acorn"; import {Page, routing} from "./ui/navigationTracking"; -import numeral from "numeral/min/numeral.min"; +import {numeralWrapper} from "./ui/numeralFormat"; import {dialogBoxCreate} from "../utils/DialogBox"; import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver"; @@ -251,7 +251,7 @@ function updateScriptEditorContent() { var codeCopy = code.repeat(1); var ramUsage = calculateRamUsage(codeCopy); if (ramUsage !== -1) { - scriptEditorRamText.innerText = "RAM: " + numeral(ramUsage).format('0.00') + " GB"; + scriptEditorRamText.innerText = "RAM: " + numeralWrapper.format(ramUsage, '0.00') + " GB"; } else { 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"); runningScriptObj.log("Called grow() on " + serv.hostname + " " + timesGrown + " times while offline"); 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"); } } diff --git a/src/StockMarket.js b/src/StockMarket.js index e5c829014..913606b3c 100755 --- a/src/StockMarket.js +++ b/src/StockMarket.js @@ -10,7 +10,7 @@ import {clearEventListeners} from "../utils/uiHelpers/clearEv import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver"; 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 {getRandomInt} from "../utils/helpers/getRandomInt"; 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 var stockOrders = StockMarket["Orders"][params.stock.symbol]; 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) { var order = stockOrders[i]; if (params.shares === order.shares && @@ -410,7 +410,7 @@ function buyStock(stock, shares) { var totalPrice = stock.price * shares; if (Player.money.lt(totalPrice + CONSTANTS.StockMarketCommission)) { 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; } @@ -420,9 +420,9 @@ function buyStock(stock, shares) { stock.playerShares += shares; stock.playerAvgPx = newTotal / stock.playerShares; updateStockPlayerPosition(stock); - dialogBoxCreate("Bought " + numeral(shares).format('0,0') + " shares of " + stock.symbol + " at " + - numeral(stock.price).format('($0.000a)') + " per share. Paid " + - numeral(CONSTANTS.StockMarketCommission).format('($0.000a)') + " in commission fees."); + dialogBoxCreate("Bought " + numeralWrapper.format(shares, '0,0') + " shares of " + stock.symbol + " at " + + numeralWrapper.format(stock.price, '($0.000a)') + " per share. Paid " + + numeralWrapper.format(CONSTANTS.StockMarketCommission, '($0.000a)') + " in commission fees."); return true; } @@ -443,9 +443,9 @@ function sellStock(stock, shares) { stock.playerAvgPx = 0; } updateStockPlayerPosition(stock); - dialogBoxCreate("Sold " + numeral(shares).format('0,0') + " shares of " + stock.symbol + " at " + - numeral(stock.price).format('($0.000a)') + " per share. After commissions, you gained " + - "a total of " + numeral(gains).format('($0.000a)') + "."); + dialogBoxCreate("Sold " + numeralWrapper.format(shares, '0,0') + " shares of " + stock.symbol + " at " + + numeralWrapper.format(stock.price, '($0.000a)') + " per share. After commissions, you gained " + + "a total of " + numeralWrapper.format(gains, '($0.000a)') + "."); return true; } @@ -469,10 +469,10 @@ function shortStock(stock, shares, workerScript=null) { if (tixApi) { workerScript.scriptRef.log("ERROR: shortStock() failed because 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)') + "."); } else { 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; @@ -486,14 +486,14 @@ function shortStock(stock, shares, workerScript=null) { updateStockPlayerPosition(stock); if (tixApi) { 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 " + - numeral(stock.price).format('($0.000a)') + " per share. Paid " + - numeral(CONSTANTS.StockMarketCommission).format('($0.000a)') + " in commission fees."); + workerScript.scriptRef.log("Bought a short position of " + numeralWrapper.format(shares, '0,0') + " shares of " + stock.symbol + " at " + + numeralWrapper.format(stock.price, '($0.000a)') + " per share. Paid " + + numeralWrapper.format(CONSTANTS.StockMarketCommission, '($0.000a)') + " in commission fees."); } } else { - dialogBoxCreate("Bought a short position of " + numeral(shares).format('0,0') + " shares of " + stock.symbol + " at " + - numeral(stock.price).format('($0.000a)') + " per share. Paid " + - numeral(CONSTANTS.StockMarketCommission).format('($0.000a)') + " in commission fees."); + dialogBoxCreate("Bought a short position of " + numeralWrapper.format(shares, '0,0') + " shares of " + stock.symbol + " at " + + numeralWrapper.format(stock.price, '($0.000a)') + " per share. Paid " + + numeralWrapper.format(CONSTANTS.StockMarketCommission, '($0.000a)') + " in commission fees."); } return true; } @@ -530,14 +530,14 @@ function sellShort(stock, shares, workerScript=null) { updateStockPlayerPosition(stock); if (tixApi) { 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 " + - numeral(stock.price).format('($0.000a)') + " per share. After commissions, you gained " + - "a total of " + numeral(origCost + profit).format('($0.000a)') + "."); + workerScript.scriptRef.log("Sold your short position of " + numeralWrapper.format(shares, '0,0') + " shares of " + stock.symbol + " at " + + numeralWrapper.format(stock.price, '($0.000a)') + " per share. After commissions, you gained " + + "a total of " + numeralWrapper.format(origCost + profit, '($0.000a)') + "."); } } else { - dialogBoxCreate("Sold your short position of " + numeral(shares).format('0,0') + " shares of " + stock.symbol + " at " + - numeral(stock.price).format('($0.000a)') + " per share. After commissions, you gained " + - "a total of " + numeral(origCost + profit).format('($0.000a)') + "."); + dialogBoxCreate("Sold your short position of " + numeralWrapper.format(shares, '0,0') + " shares of " + stock.symbol + " at " + + numeralWrapper.format(stock.price, '($0.000a)') + " per share. After commissions, you gained " + + "a total of " + numeralWrapper.format(origCost + profit, '($0.000a)') + "."); } return true; @@ -696,7 +696,7 @@ function displayStockMarketContent() { //Purchase WSE Account button var wseAccountButton = clearEventListeners("stock-market-buy-account"); 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"); wseAccountButton.addEventListener("click", function() { Player.hasWseAccount = true; @@ -710,7 +710,7 @@ function displayStockMarketContent() { //Purchase TIX API Access account var tixApiAccessButton = clearEventListeners("stock-market-buy-tix-api"); 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"); tixApiAccessButton.addEventListener("click", function() { Player.hasTixApiAccess = true; @@ -722,7 +722,7 @@ function displayStockMarketContent() { //Purchase Four Sigma Market Data Feed var marketDataButton = clearEventListeners("stock-market-buy-4s-data"); 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"); marketDataButton.addEventListener("click", function() { Player.has4SData = true; @@ -760,7 +760,7 @@ function displayStockMarketContent() { //Purchase Four Sigma Market Data TIX API (Requires TIX API Access) var marketDataTixButton = clearEventListeners("stock-market-buy-4s-tix-api"); 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"); if (Player.hasTixApiAccess) { marketDataTixButton.addEventListener("click", function() { @@ -823,7 +823,7 @@ function displayStockMarketContent() { console.log("Creating Stock Market UI"); commissionText.innerHTML = "Commission Fees: Every transaction you make has a " + - numeral(CONSTANTS.StockMarketCommission).format('($0.000a)') + " commission fee.

" + + numeralWrapper.format(CONSTANTS.StockMarketCommission, '($0.000a)') + " commission fee.

" + "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 " + "Augmentations!"; @@ -1020,7 +1020,7 @@ function createStockTicker(stock) { var li = document.createElement("li"), hdr = document.createElement("button"); hdr.classList.add("accordion-header"); 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 var stockDiv = document.createElement("div"); @@ -1297,9 +1297,9 @@ function updateStockTicker(stock, increase) { } 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) { - hdrText += " - Volatility: " + numeral(stock.mv).format('0,0.00') + "%" + + hdrText += " - Volatility: " + numeralWrapper.format(stock.mv, '0,0.00') + "%" + " - Price Forecast: "; if (stock.b) { hdrText += "+".repeat(Math.floor(stock.otlkMag/10) + 1); @@ -1363,21 +1363,21 @@ function updateStockPlayerPosition(stock) { "

Long Position: " + "Shares in the long position will increase " + "in value if the price of the corresponding stock increases

" + - "
Shares: " + numeral(stock.playerShares).format('0,0') + - "
Average Price: " + numeral(stock.playerAvgPx).format('$0.000a') + - " (Total Cost: " + numeral(totalCost).format('$0.000a') + ")" + - "
Profit: " + numeral(gains).format('$0.000a') + - " (" + numeral(percentageGains).format('0.00%') + ")

"; + "
Shares: " + numeralWrapper.format(stock.playerShares, '0,0') + + "
Average Price: " + numeralWrapper.format(stock.playerAvgPx, '$0.000a') + + " (Total Cost: " + numeralWrapper.format(totalCost, '$0.000a') + ")" + + "
Profit: " + numeralWrapper.format(gains, '$0.000a') + + " (" + numeralWrapper.format(percentageGains, '0.00%') + ")

"; if (Player.bitNodeN === 8 || (hasWallStreetSF && wallStreetSFLvl >= 2)) { stock.posTxtEl.innerHTML += "

Short Position: " + "Shares in short position will increase " + "in value if the price of the corresponding stock decreases

" + - "
Shares: " + numeral(stock.playerShortShares).format('0,0') + - "
Average Price: " + numeral(stock.playerAvgShortPx).format('$0.000a') + - " (Total Cost: " + numeral(shortTotalCost).format('$0.000a') + ")" + - "
Profit: " + numeral(shortGains).format('$0.000a') + - " (" + numeral(shortPercentageGains).format('0.00%') + ")" + + "
Shares: " + numeralWrapper.format(stock.playerShortShares, '0,0') + + "
Average Price: " + numeralWrapper.format(stock.playerAvgShortPx, '$0.000a') + + " (Total Cost: " + numeralWrapper.format(shortTotalCost, '$0.000a') + ")" + + "
Profit: " + numeralWrapper.format(shortGains, '$0.000a') + + " (" + numeralWrapper.format(shortPercentageGains, '0.00%') + ")" + "

Orders:

"; } @@ -1440,7 +1440,7 @@ function updateStockOrderList(stock) { var posText = (order.pos === PositionTypes.Long ? "Long Position" : "Short Position"); li.style.color = "white"; 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"); cancelButton.classList.add("stock-market-order-cancel-btn"); diff --git a/src/Terminal.js b/src/Terminal.js index fa2d87b23..38a1878cc 100644 --- a/src/Terminal.js +++ b/src/Terminal.js @@ -22,7 +22,6 @@ import {iTutorialNextStep, iTutorialSteps, import {showLiterature} from "./Literature"; import {showMessage, Message} from "./Message"; import {killWorkerScript, addWorkerScript} from "./NetscriptWorker"; -import numeral from "numeral/min/numeral.min"; import {Player} from "./Player"; import {hackWorldDaemon} from "./RedPill"; import {findRunningScript, RunningScript, @@ -37,6 +36,7 @@ import {TextFile, getTextFile} from "./TextFile"; import {containsAllStrings, longestCommonStart} from "../utils/StringHelperFunctions"; import {Page, routing} from "./ui/navigationTracking"; +import {numeralWrapper} from "./ui/numeralFormat"; import {KEY} from "../utils/helpers/keyCodes"; import {addOffset} from "../utils/helpers/addOffset"; import {isString} from "../utils/helpers/isString"; @@ -700,11 +700,11 @@ let Terminal = { 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 //Player only gains 25% exp for failure? TODO Can change this later to balance 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";} post("Root Access: " + rootAccess); post("Required hacking skill: " + currServ.requiredHackingSkill); - post("Server security level: " + numeral(currServ.hackDifficulty).format('0.000a')); - post("Chance to hack: " + numeral(calculateHackingChance(currServ) * 100).format('0.00%')); - post("Time to hack: " + numeral(calculateHackingTime(currServ)).format('0.000') + " seconds"); - post("Total money available on server: $" + numeral(currServ.moneyAvailable).format('$0,0.00')); + post("Server security level: " + numeralWrapper.format(currServ.hackDifficulty, '0.000a')); + post("Chance to hack: " + numeralWrapper.format(calculateHackingChance(currServ) * 100, '0.00%')); + post("Time to hack: " + numeralWrapper.format(calculateHackingTime(currServ), '0.000') + " seconds"); + post("Total money available on server: $" + numeralWrapper.format(currServ.moneyAvailable, '$0,0.00')); post("Required number of open ports for NUKE: " + currServ.numOpenPortsRequired); if (currServ.sshPortOpen) { @@ -1245,7 +1245,7 @@ let Terminal = { var scriptBaseRamUsage = currServ.scripts[i].ramUsage; 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; } } @@ -1597,7 +1597,7 @@ let Terminal = { var spacesThread = Array(numSpacesThread+1).join(" "); //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]; post(entry.join("")); @@ -1844,9 +1844,9 @@ let Terminal = { if (commandArray.length != 1) { post("Incorrect usage of free command. Usage: free"); return; } - post("Total: " + numeral(Player.getCurrentServer().maxRam).format('0.00') + " GB"); - post("Used: " + numeral(Player.getCurrentServer().ramUsed,).format('0.00') + " GB"); - post("Available: " + numeral(Player.getCurrentServer().maxRam - Player.getCurrentServer().ramUsed).format('0.00') + " GB"); + post("Total: " + numeralWrapper.format(Player.getCurrentServer().maxRam, '0.00') + " GB"); + post("Used: " + numeralWrapper.format(Player.getCurrentServer().ramUsed, '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 @@ -1967,9 +1967,9 @@ let Terminal = { post("Server base security level: " + targetServer.baseDifficulty); post("Server current security level: " + targetServer.hackDifficulty); post("Server growth rate: " + targetServer.serverGrowth); - post("Netscript hack() execution time: " + numeral(scriptCalculateHackingTime(targetServer)).format('0.0') + "s"); - post("Netscript grow() execution time: " + numeral(scriptCalculateGrowTime(targetServer)).format('0.0') + "s"); - post("Netscript weaken() execution time: " + numeral(scriptCalculateWeakenTime(targetServer)).format('0.0') + "s"); + post("Netscript hack() execution time: " + numeralWrapper.format(scriptCalculateHackingTime(targetServer), '0.0') + "s"); + post("Netscript grow() execution time: " + numeralWrapper.format(scriptCalculateGrowTime(targetServer), '0.0') + "s"); + post("Netscript weaken() execution time: " + numeralWrapper.format(scriptCalculateWeakenTime(targetServer), '0.0') + "s"); }; programHandlers[Programs.AutoLink.name] = () => { post("This executable cannot be run."); @@ -1995,7 +1995,7 @@ let Terminal = { if(!fulfilled) { 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("----------HACKING PATH----------"); post("Hacking skill: " + Player.hacking_skill + " / 2500"); diff --git a/src/engine.js b/src/engine.js index db60b97ee..954c21ab5 100644 --- a/src/engine.js +++ b/src/engine.js @@ -5,13 +5,14 @@ import {clearEventListeners} from "../utils/uiHelpers/clearEv import {createElement} from "../utils/uiHelpers/createElement"; import {exceptionAlert} from "../utils/helpers/exceptionAlert"; import {removeLoadingScreen} from "../utils/uiHelpers/removeLoadingScreen"; -import numeral from "numeral/min/numeral.min"; + +import {numeralWrapper} from "./ui/numeralFormat"; + import {formatNumber, convertTimeMsToTimeElapsedString, replaceAt} from "../utils/StringHelperFunctions"; import {loxBoxCreate, logBoxUpdateText, logBoxOpened} from "../utils/LogBox"; - import {updateActiveScriptsItems} from "./ActiveScriptsUI"; import {Augmentations, installAugmentations, initAugmentations, AugmentationNames, @@ -587,17 +588,17 @@ const Engine = { 'Money: $' + formatNumber(Player.money.toNumber(), 2) + '


' + 'Stats

' + 'Hacking Level: ' + (Player.hacking_skill).toLocaleString() + - ' (' + numeral(Player.hacking_exp).format('(0.000a)') + ' experience)
' + + ' (' + numeralWrapper.format(Player.hacking_exp, '(0.000a)') + ' experience)
' + 'Strength: ' + (Player.strength).toLocaleString() + - ' (' + numeral(Player.strength_exp).format('(0.000a)') + ' experience)
' + + ' (' + numeralWrapper.format(Player.strength_exp, '(0.000a)') + ' experience)
' + 'Defense: ' + (Player.defense).toLocaleString() + - ' (' + numeral(Player.defense_exp).format('(0.000a)')+ ' experience)
' + + ' (' + numeralWrapper.format(Player.defense_exp, '(0.000a)') + ' experience)
' + 'Dexterity: ' + (Player.dexterity).toLocaleString() + - ' (' + numeral(Player.dexterity_exp).format('(0.000a)') + ' experience)
' + + ' (' + numeralWrapper.format(Player.dexterity_exp, '(0.000a)') + ' experience)
' + 'Agility: ' + (Player.agility).toLocaleString() + - ' (' + numeral(Player.agility_exp).format('(0.000a)') + ' experience)
' + + ' (' + numeralWrapper.format(Player.agility_exp, '(0.000a)') + ' experience)
' + 'Charisma: ' + (Player.charisma).toLocaleString() + - ' (' + numeral(Player.charisma_exp).format('(0.000a)') + ' experience)
' + + ' (' + numeralWrapper.format(Player.charisma_exp, '(0.000a)') + ' experience)
' + intText + '

' + 'Multipliers

' + 'Hacking Chance multiplier: ' + formatNumber(Player.hacking_chance_mult * 100, 2) + '%
' + diff --git a/src/ui/numeralFormat.js b/src/ui/numeralFormat.js new file mode 100644 index 000000000..df7f1a2b7 --- /dev/null +++ b/src/ui/numeralFormat.js @@ -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(); diff --git a/src/ui/setSettingsLabels.js b/src/ui/setSettingsLabels.js index 126175619..cfa7dccbf 100644 --- a/src/ui/setSettingsLabels.js +++ b/src/ui/setSettingsLabels.js @@ -1,7 +1,8 @@ import {Engine} from "../engine"; import {Settings} from "../Settings"; -import numeral from "numeral/min/numeral.min"; +import {numeralWrapper} from "./NumeralFormat"; + function setSettingsLabels() { var nsExecTime = document.getElementById("settingsNSExecTimeRangeValLabel"); @@ -28,6 +29,7 @@ function setSettingsLabels() { autosaveInterval.innerHTML = Settings.AutosaveInterval; disableHotkeys.checked = Settings.DisableHotkeys; locale.value = Settings.Locale; + numeralWrapper.updateLocale(Settings.Locale); //Initialize locale //Set handlers for when input changes for sliders var nsExecTimeInput = document.getElementById("settingsNSExecTimeRangeVal"); @@ -91,16 +93,14 @@ function setSettingsLabels() { //Locale selector locale.onchange = function() { - if (numeral.locale(locale.value) == null) { + if (!numeralWrapper.updateLocale(locale.value)) { console.warn(`Invalid locale for numeral: ${locale.value}`); let defaultValue = 'en'; - numeral.locale(defaultValue); Settings.Locale = defaultValue; locale.value = defaultValue; return; } - Settings.Locale = locale.value; }