daviscook477 / BaseMod

Slay the Spire mod which provides a modding API and a dev console
MIT License
409 stars 113 forks source link

Fix some bad logic for AbstractCard.initializeDescriptionCN() #427

Open Mwallx opened 4 months ago

Mwallx commented 4 months ago

This PR solves 3 issues:

  1. The vanilla code for AbstractCard.initializeDescriptionCN() (used by zhs, kor and jpn etc) uses a flawed logic which would result card strings with double space to be rendered incorrectly. This is because double space when processed by the Java's String.split(" "), will create another empty string "" between each consecutive occurence of spaces.(For example "I[double space]like[double space]it" will be split into "I","","like","","it") The vanilla function then, uses a flawed logic so that whenever it encounters any empty string "", it will set the width of the current line to be processed to 0, no matter it is a new line or not, resulting in some lines having shorter measured width than how long the real text is.
  2. The existing patch CNCardTextColors.java actually doesn't function at all. It's because this insertor patch is located within an if else branch, where a pervious branch's condition completely covers the patch's condition. So whenever the patch's condition could be met, it will met that one earlier so the patch actually doesn't work at all. I have optimized the logic and repositioned where it happens. It's now inserted before that other branch and will function normally.
  3. In the modified patch above, I added another logic to make colored text ignore punctuation's width, just like what vanilla did, if it's located at the ending of a line. Previews of these changes: For 1: before1 after1

For 2: (the forth line is aligned with the third because each colored block of text is incorrectly recognised by vanilla code to be energy orbs) before2 after2

For 3: (notice in the first image the 2 sentences are exactly the same text, but the second one is forced to be split between 2 lines because the period's width isn't ignored like the normal one, resulted in longer width even though there's enough space for it to be shown in one line.) image )9 B)RQ{Q{QAN%EN4~G78$V