Skip to content

Commit 757b784

Browse files
committed
simplified fancy fractions
1 parent 3501c9d commit 757b784

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

src/Octeracts.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { IUpgradeData } from './DynamicUpgrade';
44
import { DynamicUpgrade } from './DynamicUpgrade';
55
import type { Player } from './types/Synergism';
66
import { DOMCacheGetOrSet } from './Cache/DOM';
7-
import { fancyFrac } from './UpdateVisuals';
87

98
export interface IOcteractData extends IUpgradeData {
109
costFormula (level: number, baseCost: number): number
@@ -112,13 +111,13 @@ export class OcteractUpgrade extends DynamicUpgrade {
112111
<span style="color: lightblue">${this.description}</span>
113112
<span style="color: ${color}"> Level ${format(this.level, 0 , true)}${maxLevel}${freeLevelInfo}</span>
114113
<span style="color: gold">${this.getEffect().desc}</span>
115-
Cost for next level: ${fancyFrac('flat', format(costNextLevel,2,true, true, true))} Octeracts.
116-
Spent Octeracts: ${fancyFrac('flat', format(this.octeractsInvested, 2, true, true, true))}`
114+
Cost for next level: ${format(costNextLevel,2,true, true, true)} Octeracts.
115+
Spent Octeracts: ${format(this.octeractsInvested, 2, true, true, true)}`
117116
}
118117

119118
public updateUpgradeHTML(): void {
120119
DOMCacheGetOrSet('singularityOcteractsMultiline').innerHTML = this.toString()
121-
fancyFrac('singOcts', format(player.wowOcteracts, 2, true, true, true));
120+
DOMCacheGetOrSet('singOcts').innerHTML = format(player.wowOcteracts, 2, true, true, true);
122121
}
123122

124123
public computeFreeLevelSoftcap(): number {

src/Synergism.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,7 @@ const padEvery = (str: string, places = 3) => {
18431843
* how many decimal points that are to be displayed (Values <10 if !long, <1000 if long).
18441844
* only works up to 305 (308 - 3), however it only worked up to ~14 due to rounding errors regardless
18451845
* @param long dictates whether or not a given number displays as scientific at 1,000,000. This auto defaults to short if input >= 1e13
1846+
* @param fractional returns html markup when the number requires (will not display nicely with .textContent)
18461847
*/
18471848
export const format = (
18481849
input: Decimal | number | { [Symbol.toPrimitive]: unknown } | null | undefined,
@@ -1910,22 +1911,24 @@ export const format = (
19101911

19111912
// If the power is negative, then we will want to address that separately.
19121913
if (power < 0 && !isDecimal(input) && fractional) {
1914+
const num = '<span class=\'num\'>';
1915+
const den = '</span><span class=\'den\'>';
19131916
if (power <= -15) {
1914-
return `${format(mantissa, accuracy, long)} / ${Math.pow(10, -power - 15)}Qa`
1917+
return `${num + format(mantissa, accuracy, long)}${den + Math.pow(10, -power - 15)}Qa</span>`
19151918
}
19161919
if (power <= -12) {
1917-
return `${format(mantissa, accuracy, long)} / ${Math.pow(10, -power - 12)}T`
1920+
return `${num + format(mantissa, accuracy, long)}${den + Math.pow(10, -power - 12)}T</span>`
19181921
}
19191922
if (power <= -9) {
1920-
return `${format(mantissa, accuracy, long)} / ${Math.pow(10, -power - 9)}B`
1923+
return `${num + format(mantissa, accuracy, long)}${den + Math.pow(10, -power - 9)}B</span>`
19211924
}
19221925
if (power <= -6) {
1923-
return `${format(mantissa, accuracy, long)} / ${Math.pow(10, -power - 6)}M`
1926+
return `${num + format(mantissa, accuracy, long)}${den + Math.pow(10, -power - 6)}M</span>`
19241927
}
19251928
if (power <= -3) {
1926-
return `${format(mantissa, accuracy, long)} / ${Math.pow(10, -power - 3)}K`
1929+
return `${num + format(mantissa, accuracy, long)}${den + Math.pow(10, -power - 3)}K</span>`
19271930
}
1928-
return `${format(mantissa, accuracy, long)} / ${Math.pow(10, -power)}`
1931+
return `${num + format(mantissa, accuracy, long)}${den + Math.pow(10, -power)}</span>`
19291932
} else if (power < 6 || (long && power < 13)) {
19301933
// If the power is less than 6 or format long and less than 13 use standard formatting (123,456,789)
19311934
// Gets the standard representation of the number, safe as power is guaranteed to be > -12 and < 13

src/UpdateVisuals.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -554,22 +554,12 @@ export const visualUpdateSingularity = () => {
554554
}
555555
}
556556

557-
export const fancyFrac = (element: string, formatString: string) => {
558-
const fracArray = formatString.split(' / ');
559-
if (fracArray.length === 1) {
560-
return element === 'flat' ? formatString : DOMCacheGetOrSet(element).textContent = formatString;
561-
} else {
562-
const fancyString = `<span class='num'>${fracArray[0]}</span><span class='den'>${fracArray[1]}</span>`;
563-
return element === 'flat' ? fancyString : DOMCacheGetOrSet(element).innerHTML = fancyString;
564-
}
565-
}
566-
567557
export const visualUpdateOcteracts = () => {
568558
if (G['currentTab'] !== 'singularity') {
569559
return
570560
}
571561

572-
fancyFrac('singOcts',format(player.wowOcteracts, 2, true, true, true))
562+
DOMCacheGetOrSet('singOcts').innerHTML = format(player.wowOcteracts, 2, true, true, true);
573563

574564
const perSecond = octeractGainPerSecond();
575565

@@ -580,7 +570,7 @@ export const visualUpdateOcteracts = () => {
580570

581571
const cTOCB = (calculateTotalOcteractCubeBonus() - 1) * 100;
582572
const cTOQB = (calculateTotalOcteractQuarkBonus() - 1) * 100;
583-
fancyFrac('totalOcts', format(player.totalWowOcteracts, 2, true, true, true));
573+
DOMCacheGetOrSet('totalOcts').innerHTML = format(player.totalWowOcteracts, 2, true, true, true);
584574
DOMCacheGetOrSet('totalOcteractCubeBonus').style.display = cTOCB >= 0.001 ? 'block' : 'none';
585575
DOMCacheGetOrSet('totalOcteractQuarkBonus').style.display = cTOQB >= 0.001 ? 'block' : 'none';
586576
DOMCacheGetOrSet('octCubeBonus').textContent = `+${format(cTOCB, 3, true)}%`

0 commit comments

Comments
 (0)