1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2024-11-24 09:21:46 +00:00

Added small number formatting

This commit is contained in:
Harley White 2021-05-06 17:51:06 -04:00
parent e6c03dbf4d
commit 83bd52441e
5 changed files with 36 additions and 8 deletions

View file

@ -1,6 +1,6 @@
# The Modding Tree changelog: # The Modding Tree changelog:
# v2.5 (beta) # v2.5: Dreams Really Do Come True -
- Optimizations, hopefully a significant amount. - Optimizations, hopefully a significant amount.
- Added OOM/s point gen display at high values (thanks to Ducdat!) - Added OOM/s point gen display at high values (thanks to Ducdat!)
- Only one tab will display if the window is not wide enough (also thanks to Ducdat!) - Only one tab will display if the window is not wide enough (also thanks to Ducdat!)
@ -12,6 +12,7 @@
- Locked (not yet visible) milestones no longer take up space. Also fixed hidden milestones taking a tiny bit of space. - Locked (not yet visible) milestones no longer take up space. Also fixed hidden milestones taking a tiny bit of space.
- Re-centered respec buttons. - Re-centered respec buttons.
- Force-displayed tooltips are not hidden by resets. - Force-displayed tooltips are not hidden by resets.
- Added formatting support for very small numbers. Disabled in most places by default because rounding errors can cause issues. Access it with formatSmall, or enable it globally by adding "allowSmall: true" to modInfo.
# v2.4.1 - 4/29/21 # v2.4.1 - 4/29/21
- A number of minor fixes, many thanks to thepaperpilot. - A number of minor fixes, many thanks to thepaperpilot.

View file

@ -11,8 +11,8 @@ let modInfo = {
// Set your version in num and name // Set your version in num and name
let VERSION = { let VERSION = {
num: "2.4.2", num: "2.5",
name: "Rationalized Edition", name: "Dreams Really Do Come True",
} }
let changelog = `<h1>Changelog:</h1><br> let changelog = `<h1>Changelog:</h1><br>

View file

@ -5,8 +5,8 @@ var scrolled = false;
// Don't change this // Don't change this
const TMT_VERSION = { const TMT_VERSION = {
tmtNum: "2.4.2", tmtNum: "2.5",
tmtName: "Rationalized Edition" tmtName: "Dreams Really Do Come True"
} }
function getResetGain(layer, useType = null) { function getResetGain(layer, useType = null) {

View file

@ -106,7 +106,7 @@ var systemComponents = {
<h2 class="overlayThing" id="points">{{format(player.points)}}</h2> <h2 class="overlayThing" id="points">{{format(player.points)}}</h2>
<span v-if="player.points.lt('1e1e6')" class="overlayThing"> {{modInfo.pointsName}}</span> <span v-if="player.points.lt('1e1e6')" class="overlayThing"> {{modInfo.pointsName}}</span>
<br> <br>
<span v-if="canGenPoints()" class="overlayThing">({{tmp.other.oompsMag != 0 ? format(tmp.other.oomps) + " OOM" + (tmp.other.oompsMag < 0 ? "^OOM" : tmp.other.oompsMag > 1 ? "^" + tmp.other.oompsMag : "") + "s" : format(getPointGen())}}/sec)</span> <span v-if="canGenPoints()" class="overlayThing">({{tmp.other.oompsMag != 0 ? format(tmp.other.oomps) + " OOM" + (tmp.other.oompsMag < 0 ? "^OOM" : tmp.other.oompsMag > 1 ? "^" + tmp.other.oompsMag : "") + "s" : formatSmall(getPointGen())}}/sec)</span>
<div v-for="thing in tmp.displayThings" class="overlayThing"><span v-if="thing" v-html="thing"></span></div> <div v-for="thing in tmp.displayThings" class="overlayThing"><span v-if="thing" v-html="thing"></span></div>
</div> </div>
` `

View file

@ -22,6 +22,7 @@ function commaFormat(num, precision) {
function regularFormat(num, precision) { function regularFormat(num, precision) {
if (num === null || num === undefined) return "NaN" if (num === null || num === undefined) return "NaN"
if (num.mag < 0.001) return (0).toFixed(precision) if (num.mag < 0.001) return (0).toFixed(precision)
if (num.mag < 0.01) precision = 3
return num.toStringWithDecimalPlaces(precision) return num.toStringWithDecimalPlaces(precision)
} }
@ -35,7 +36,8 @@ function sumValues(x) {
return x.reduce((a, b) => Decimal.add(a, b)) return x.reduce((a, b) => Decimal.add(a, b))
} }
function format(decimal, precision = 2,) { function format(decimal, precision = 2, small) {
small = small || modInfo.allowSmall
decimal = new Decimal(decimal) decimal = new Decimal(decimal)
if (isNaN(decimal.sign) || isNaN(decimal.layer) || isNaN(decimal.mag)) { if (isNaN(decimal.sign) || isNaN(decimal.layer) || isNaN(decimal.mag)) {
player.hasNaN = true; player.hasNaN = true;
@ -52,7 +54,18 @@ function format(decimal, precision = 2,) {
else if (decimal.gte("1e1000")) return exponentialFormat(decimal, 0) else if (decimal.gte("1e1000")) return exponentialFormat(decimal, 0)
else if (decimal.gte(1e9)) return exponentialFormat(decimal, precision) else if (decimal.gte(1e9)) return exponentialFormat(decimal, precision)
else if (decimal.gte(1e3)) return commaFormat(decimal, 0) else if (decimal.gte(1e3)) return commaFormat(decimal, 0)
else return regularFormat(decimal, precision) else if (decimal.gte(0.001) || !small) return regularFormat(decimal, precision)
else if (decimal.eq(0)) return (0).toFixed(precision)
decimal = invertOOM(decimal)
let val = ""
if (decimal.lt(1e1000)){
val = exponentialFormat(decimal, precision)
}
else
val = format(decimal, precision)
return val.replace(/([^(?:e|F)]*)$/, '-$1')
} }
function formatWhole(decimal) { function formatWhole(decimal) {
@ -78,3 +91,17 @@ function toPlaces(x, precision, maxAccepted) {
} }
return result return result
} }
// Will also display very small numbers
function formatSmall(x, precision=2) {
return format(x, precision, true)
}
function invertOOM(x){
let e = x.log10().ceil()
let m = x.div(Decimal.pow(10, e))
e = e.neg()
x = new Decimal(10).pow(e).times(m)
return x
}