Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fancy fraction formatting #386

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Synergism.css
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,22 @@ p#reincarnatehotkeys {
margin: 0 0 0 10px;
}

.num {
font-size: 0.8em;
vertical-align: text-top;
}

.den {
font-size: 0.8em;
}

.den::before {
content: "\2044";
font-size: 1.25em;
margin-left: 0.15em;
margin-right: 0.1em;
}

#goldenQuarkamount {
font-size: 1.2em;
color: gold;
Expand Down
2 changes: 1 addition & 1 deletion src/Octeracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class OcteractUpgrade extends DynamicUpgrade {

public updateUpgradeHTML(): void {
DOMCacheGetOrSet('singularityOcteractsMultiline').innerHTML = this.toString()
DOMCacheGetOrSet('singOcts').textContent = format(player.wowOcteracts, 2, true, true, true)
DOMCacheGetOrSet('singOcts').innerHTML = format(player.wowOcteracts, 2, true, true, true);
}

public computeFreeLevelSoftcap(): number {
Expand Down
4 changes: 3 additions & 1 deletion src/Synergism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,7 @@ const padEvery = (str: string, places = 3) => {
* how many decimal points that are to be displayed (Values <10 if !long, <1000 if long).
* only works up to 305 (308 - 3), however it only worked up to ~14 due to rounding errors regardless
* @param long dictates whether or not a given number displays as scientific at 1,000,000. This auto defaults to short if input >= 1e13
* @param fractional returns html markup when the number requires (will not display nicely with .textContent)
*/
export const format = (
input: Decimal | number | { [Symbol.toPrimitive]: unknown } | null | undefined,
Expand Down Expand Up @@ -1972,7 +1973,8 @@ export const format = (
// If the power is negative, then we will want to address that separately.
if (power < 0 && fractional) {
const powerLodge = Math.floor(-power / 3);
return `${format(mantissa, accuracy, long)} / ${Math.pow(10, -(power % 3))}${FormatList[powerLodge]}`
return `<span class='num'>${format(mantissa, accuracy, long)}</span>` +
`<span class='den'>${Math.pow(10, -(power % 3))}${FormatList[powerLodge]}</span>`
}
if (power < 6 || (long && power < 13)) {
// If the power is less than 6 or format long and less than 13 use standard formatting (123,456,789)
Expand Down
4 changes: 2 additions & 2 deletions src/UpdateVisuals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ export const visualUpdateOcteracts = () => {
if (G['currentTab'] !== 'singularity') {
return
}
DOMCacheGetOrSet('singOcts').textContent = format(player.wowOcteracts, 2, true, true, true)
DOMCacheGetOrSet('singOcts').innerHTML = format(player.wowOcteracts, 2, true, true, true);

const perSecond = octeractGainPerSecond();

Expand All @@ -569,7 +569,7 @@ export const visualUpdateOcteracts = () => {

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