Skip to content

Commit

Permalink
fix bug with magic symbols in card descriptions in Japanese and Chinese
Browse files Browse the repository at this point in the history
  • Loading branch information
avolny committed Oct 15, 2020
1 parent 6ab07bd commit 6abf4c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
33 changes: 24 additions & 9 deletions src/main/java/str_exporter/DeckJSONBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.megacrit.cardcrawl.cards.CardGroup;
import com.megacrit.cardcrawl.cards.DescriptionLine;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -165,12 +166,12 @@ private void buildCard(StringBuilder sb, AbstractCard card, boolean repr) {
String desc = sanitizeEmpty(parseDescription(card));
String keywords = sanitizeEmpty(encodeKeywords(card));

AbstractCard copy = card.makeStatEquivalentCopy();
copy.upgrade();
copy.displayUpgrades();
String upgradedDesc = sanitizeEmpty(parseDescription(copy));
String upgradedName = sanitizeEmpty(sanitize(copy.name));
String upgradedKeywords = sanitizeEmpty(encodeKeywords(copy));
AbstractCard cardUpg = card.makeStatEquivalentCopy();
cardUpg.upgrade();
cardUpg.displayUpgrades();
String upgradedDesc = sanitizeEmpty(parseDescription(cardUpg));
String upgradedName = sanitizeEmpty(sanitize(cardUpg.name));
String upgradedKeywords = sanitizeEmpty(encodeKeywords(cardUpg));

int timesUpgraded = card.timesUpgraded;
int cost = card.cost;
Expand All @@ -192,6 +193,10 @@ private void buildCard(StringBuilder sb, AbstractCard card, boolean repr) {
upgradedKeywords = "_";
}

// this odd ordering of properties is supposed to maximize the compression ratio of the custom compression
// algorithm implemented here. It's supposed to cluster features that often change together or don't change
// at all

// for a regular card:
// name ; bottleStatus ; modName ; cardToPreview ; cardToPreview upgraded ; nameUpgraded ; upgrades ; keyword upgraded ; descriptionUpgraded ; keywords ; cost ; cost upgraded ; type ; rarity ; color ; description

Expand All @@ -204,7 +209,7 @@ private void buildCard(StringBuilder sb, AbstractCard card, boolean repr) {
if (!repr) {
sb.append(encodeCardToPreview(card));
sb.append(';');
sb.append(encodeCardToPreview(copy));
sb.append(encodeCardToPreview(cardUpg));
sb.append(';');
}
sb.append(upgradedName);
Expand All @@ -219,7 +224,7 @@ private void buildCard(StringBuilder sb, AbstractCard card, boolean repr) {
sb.append(';');
sb.append(cost);
sb.append(";");
sb.append(copy.cost);
sb.append(cardUpg.cost);
sb.append(";");
sb.append(encodeCardType(card));
sb.append(";");
Expand Down Expand Up @@ -323,7 +328,17 @@ private String parseDescription(AbstractCard card) {
sb.append(" NL ");
}

String[] parts = sb.toString().split(" ");
String description = sb.toString();

if(Settings.lineBreakViaCharacter) { //CN or Japanese localization
description = description.replaceAll("D", "!D!")
.replaceAll("!B!!", "!B!")
.replaceAll("!M!!", "!M!");
}

// logger.info("first description: " + sb.toString());

String[] parts = description.split(" ");
sb.setLength(0);

Pattern patternDynVar = Pattern.compile("!(.+)!(.*)");
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/ModTheSpire.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Slay the Relics Exporter",
"author_list": ["LordAddy"],
"description": "This mod exports data to Slay the Relics Twitch extension. \n\nThis mod in combination with the extension displays deck view and tooltips for viewers on stream for relics, potions, player/monster powers, orbs, even some custom tooltips from some mods. \nThe viewers just need to hover over the respective item just as if they were in the game themselves.\n\nSee the extension config on Twitch for setup instructions (search 'Slay the Relics').",
"version": "1.2.2",
"version": "1.2.4",
"sts_version": "07-30-2020",
"mts_version": "3.15.0",
"dependencies": ["basemod"]
Expand Down

0 comments on commit 6abf4c6

Please sign in to comment.