Cleanup format, show correct value for money rewards (#1926)

This commit is contained in:
Matthew 2024-06-07 21:09:12 -04:00 committed by GitHub
parent 7422ebdb28
commit 3022aabc32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 25 additions and 8 deletions

View File

@ -1381,8 +1381,7 @@ export default class BattleScene extends SceneBase {
if (this.money === undefined) {
return;
}
const formattedMoney =
this.moneyFormat === MoneyFormat.ABBREVIATED ? Utils.formatFancyLargeNumber(this.money, 3) : this.money.toLocaleString();
const formattedMoney = Utils.formatMoney(this.moneyFormat, this.money);
this.moneyText.setText(`${formattedMoney}`);
this.fieldUI.moveAbove(this.moneyText, this.luckText);
if (forceVisible) {

View File

@ -25,6 +25,7 @@ import i18next from "#app/plugins/i18n";
import { getModifierTierTextTint } from "#app/ui/text";
import { BattlerTagType } from "#app/data/enums/battler-tag-type.js";
import * as Overrides from "../overrides";
import { MoneyMultiplierModifier } from "./modifier";
const outputModifierData = false;
const useMaxWeightForOutput = false;
@ -631,9 +632,13 @@ export class MoneyRewardModifierType extends ModifierType {
}
getDescription(scene: BattleScene): string {
const moneyAmount = new Utils.IntegerHolder(scene.getWaveMoneyAmount(this.moneyMultiplier));
scene.applyModifiers(MoneyMultiplierModifier, true, moneyAmount);
const formattedMoney = Utils.formatMoney(scene.moneyFormat, moneyAmount.value);
return i18next.t("modifierType:ModifierType.MoneyRewardModifierType.description", {
moneyMultiplier: i18next.t(this.moneyMultiplierDescriptorKey as any),
moneyAmount: scene.getWaveMoneyAmount(this.moneyMultiplier).toLocaleString("en-US"),
moneyAmount: formattedMoney,
});
}
}

View File

@ -89,7 +89,7 @@ const displayStats: DisplayStats = {
},
highestMoney: {
label_key: "highestMoney",
sourceFunc: gameData => Utils.formatFancyLargeNumber(gameData.gameStats.highestMoney, 3),
sourceFunc: gameData => Utils.formatFancyLargeNumber(gameData.gameStats.highestMoney),
},
highestDamage: {
label_key: "highestDamage",

View File

@ -9,6 +9,7 @@ import { handleTutorial, Tutorial } from "../tutorial";
import {Button} from "../enums/buttons";
import MoveInfoOverlay from "./move-info-overlay";
import { allMoves } from "../data/move";
import * as Utils from "./../utils";
export const SHOP_OPTIONS_ROW_LIMIT = 6;
@ -398,7 +399,9 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
updateRerollCostText(): void {
const canReroll = this.scene.money >= this.rerollCost;
this.rerollCostText.setText(`${this.rerollCost.toLocaleString("en-US")}`);
const formattedMoney = Utils.formatMoney(this.scene.moneyFormat, this.rerollCost);
this.rerollCostText.setText(`${formattedMoney}`);
this.rerollCostText.setColor(this.getTextColor(canReroll ? TextStyle.MONEY : TextStyle.PARTY_RED));
this.rerollCostText.setShadowColor(this.getTextColor(canReroll ? TextStyle.MONEY : TextStyle.PARTY_RED, true));
}
@ -656,7 +659,9 @@ class ModifierOption extends Phaser.GameObjects.Container {
const scene = this.scene as BattleScene;
const textStyle = this.modifierTypeOption.cost <= scene.money ? TextStyle.MONEY : TextStyle.PARTY_RED;
this.itemCostText.setText(`${this.modifierTypeOption.cost.toLocaleString("en-US")}`);
const formattedMoney = Utils.formatMoney(scene.moneyFormat, this.modifierTypeOption.cost);
this.itemCostText.setText(`${formattedMoney}`);
this.itemCostText.setColor(getTextColor(textStyle, false, scene.uiTheme));
this.itemCostText.setShadowColor(getTextColor(textStyle, true, scene.uiTheme));
}

View File

@ -1,4 +1,5 @@
import i18next from "i18next";
import { MoneyFormat } from "./enums/money-format";
export const MissingTextureKey = "__MISSING";
@ -237,7 +238,7 @@ export function formatLargeNumber(count: integer, threshold: integer): string {
// Abbreviations from 10^0 to 10^33
const AbbreviationsLargeNumber: string[] = ["", "K", "M", "B", "t", "q", "Q", "s", "S", "o", "n", "d"];
export function formatFancyLargeNumber(number: number, rounded: number = 2): string {
export function formatFancyLargeNumber(number: number, rounded: number = 3): string {
let exponent: number;
if (number < 1000) {
@ -251,7 +252,14 @@ export function formatFancyLargeNumber(number: number, rounded: number = 2): str
number /= Math.pow(1000, exponent);
}
return `${(exponent === 0) ? number : number.toFixed(rounded)}${AbbreviationsLargeNumber[exponent]}`;
return `${(exponent === 0) || number % 1 === 0 ? number : number.toFixed(rounded)}${AbbreviationsLargeNumber[exponent]}`;
}
export function formatMoney(format: MoneyFormat, amount: number) {
if (format === MoneyFormat.ABBREVIATED) {
return formatFancyLargeNumber(amount);
}
return amount.toLocaleString();
}
export function formatStat(stat: integer, forHp: boolean = false): string {