Skip to content
Draft
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
57 changes: 41 additions & 16 deletions Services/CanvasService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Stunlock.Core;
using StunShared.UI;
using System.Collections;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using TMPro;
Expand Down Expand Up @@ -1065,7 +1066,7 @@ public static string GetBloodStatInfo(int i, string statType)
float classMultiplier = ClassSynergy(bloodStat, _classType, _classStatSynergies);
statValue *= (1 + (_prestigeStatMultiplier * _legacyPrestige)) * classMultiplier * ((float)_legacyLevel / _legacyMaxLevel);

string displayString = $"<color=#00FFFF>{BloodStatTypeAbbreviations[bloodStat]}</color>: <color=#90EE90>{(statValue * 100).ToString("F0") + "%"}</color>";
string displayString = FormatBloodStatBar(bloodStat, statValue);
int statModificationId = ModificationIds.GenerateId(1, (int)bloodStat, statValue);
UnitStatType unitStatType = (UnitStatType)Enum.Parse(typeof(UnitStatType), bloodStat.ToString());

Expand Down Expand Up @@ -2295,21 +2296,48 @@ public static float ClassSynergy<T>(T statType, PlayerClass classType, Dictionar

return 1f;
}
public static string FormatWeaponStatBar(WeaponStatType weaponStat, float statValue)
private const string StatFormatInteger = "integer";
private const string StatFormatDecimal = "decimal";
private const string StatFormatPercentage = "percentage";
private static string FormatStatValue(float statValue, string format)
{
string statValueString = WeaponStatFormats[weaponStat] switch
return format switch
{
"integer" => ((int)statValue).ToString(),
"decimal" => statValue.ToString("0.#"),
"percentage" => (statValue * 100f).ToString("0.#") + "%",
_ => statValue.ToString(),
StatFormatInteger => ((int)statValue).ToString(CultureInfo.InvariantCulture),
StatFormatDecimal => statValue.ToString("0.#", CultureInfo.InvariantCulture),
StatFormatPercentage => (statValue * 100f).ToString("0.#", CultureInfo.InvariantCulture) + "%",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve whole-percent rounding for blood stat UI

This helper now formats every percentage with 0.#, which changes blood-stat presentation from whole percentages to fractional percentages whenever class/prestige scaling produces non-integer results (for example 13.75% now renders as 13.8%). Before this commit, blood stat bars/attributes used F0, so this introduces a user-visible regression in canonical output rather than just refactoring; blood stats should keep their original whole-percent format or use a dedicated blood-specific format token.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex equally address all concerns in full.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

_ => statValue.ToString(CultureInfo.InvariantCulture),
};
}
private static string GetAbbreviation<T>(T statType, IReadOnlyDictionary<T, string> abbreviations) where T : struct, Enum
{
return abbreviations.TryGetValue(statType, out string abbreviation)
? abbreviation
: statType.ToString();
}
public static string FormatWeaponStatBar(WeaponStatType weaponStat, float statValue)
{
string format = WeaponStatFormats.TryGetValue(weaponStat, out string weaponFormat)
? weaponFormat
: StatFormatPercentage;
string statValueString = FormatStatValue(statValue, format);
string abbreviation = GetAbbreviation(weaponStat, WeaponStatTypeAbbreviations);

return $"<color=#00FFFF>{WeaponStatTypeAbbreviations[weaponStat]}</color>: <color=#90EE90>{statValueString}</color>";
return $"<color=#00FFFF>{abbreviation}</color>: <color=#90EE90>{statValueString}</color>";
}
public static string FormatBloodStatBar(BloodStatType bloodStat, float statValue)
{
string format = BloodStatFormats.TryGetValue(bloodStat, out string bloodFormat)
? bloodFormat
: StatFormatPercentage;
string statValueString = FormatStatValue(statValue, format);
string abbreviation = GetAbbreviation(bloodStat, BloodStatTypeAbbreviations);

return $"<color=#00FFFF>{abbreviation}</color>: <color=#90EE90>{statValueString}</color>";
}
public static string FormatAttributeValue(UnitStatType unitStatType, float statValue)
{
string statString = $"<color=#90EE90>+{statValue * 100f:F0}%</color>";
string statString = $"<color=#90EE90>+{FormatStatValue(statValue, StatFormatPercentage)}</color>";

if (Enum.TryParse(unitStatType.ToString(), out WeaponStatType weaponStatType))
statString = FormatWeaponAttribute(weaponStatType, statValue);
Expand All @@ -2318,13 +2346,10 @@ public static string FormatAttributeValue(UnitStatType unitStatType, float statV
}
public static string FormatWeaponAttribute(WeaponStatType weaponStat, float statValue)
{
string statValueString = WeaponStatFormats[weaponStat] switch
{
"integer" => ((int)statValue).ToString(),
"decimal" => statValue.ToString("0.#"),
"percentage" => (statValue * 100f).ToString("0.#") + "%",
_ => statValue.ToString(),
};
string format = WeaponStatFormats.TryGetValue(weaponStat, out string weaponFormat)
? weaponFormat
: StatFormatPercentage;
string statValueString = FormatStatValue(statValue, format);

return $"<color=#90EE90>+{statValueString}</color>";
}
Expand Down
17 changes: 16 additions & 1 deletion Services/DataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,21 @@ public enum BloodStatType
{ "AbilityAttackSpeed", "AAS" },
{ "CorruptionDamageReduction", "CDR" }
};
public static readonly Dictionary<BloodStatType, string> BloodStatFormats = new()
{
{ BloodStatType.HealingReceived, "percentage" },
{ BloodStatType.DamageReduction, "percentage" },
{ BloodStatType.PhysicalResistance, "percentage" },
{ BloodStatType.SpellResistance, "percentage" },
{ BloodStatType.ResourceYield, "percentage" },
{ BloodStatType.ReducedBloodDrain, "percentage" },
{ BloodStatType.SpellCooldownRecoveryRate, "percentage" },
{ BloodStatType.WeaponCooldownRecoveryRate, "percentage" },
{ BloodStatType.UltimateCooldownRecoveryRate, "percentage" },
{ BloodStatType.MinionDamage, "percentage" },
{ BloodStatType.AbilityAttackSpeed, "percentage" },
{ BloodStatType.CorruptionDamageReduction, "percentage" }
};

public static Dictionary<FamiliarStatType, float> _familiarStatValues = [];
public enum FamiliarStatType
Expand Down Expand Up @@ -495,4 +510,4 @@ public static void ParsePlayerData(List<string> playerData)
ShiftSpellData shiftSpellData = new(playerData[index]);
_shiftSpellIndex = shiftSpellData.ShiftSpellIndex;
}
}
}