Skip to content

Commit

Permalink
fix small bug, minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
avolny committed May 2, 2020
1 parent 93a386a commit 7e40051
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/str_exporter/BackendBroadcaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void readQueue() {
long ts = 0;
queueLock.lock();
try {
if ((sendDuplicates || !message.equals(lastMessage)) && message != null) {
if (message != null && (sendDuplicates || !message.equals(lastMessage))) {
lastMessage = message;
msg = message;
ts = messageTimestamp;
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/str_exporter/DeckJSONBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import basemod.BaseMod;
import basemod.abstracts.DynamicVariable;
import basemod.patches.whatmod.WhatMod;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.CardGroup;
import com.megacrit.cardcrawl.cards.DescriptionLine;
Expand Down Expand Up @@ -71,6 +72,9 @@ private void buildKeywords(StringBuilder sb) {
if(iter.hasNext())
sb.append(";;");
}

if (keywords.size() == 0)
sb.append('-');
}

private String getKeywordRepr(String word) {
Expand Down Expand Up @@ -177,7 +181,7 @@ private void buildCard(StringBuilder sb, AbstractCard card, boolean repr) {
// upgradedKeywords = "_";
} else if (!card.canUpgrade() && card.timesUpgraded == 0) {
// card cannot be upgraded at all, e.g. a Curse
upgradedName = "null";
upgradedName = "-";
upgradedDesc = "-";
upgradedKeywords = "-";
} else if (card.canUpgrade() && card.timesUpgraded == 0 && upgradedName.equals(name + '+')) {
Expand All @@ -188,12 +192,14 @@ private void buildCard(StringBuilder sb, AbstractCard card, boolean repr) {
}

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

sb.append(name);
sb.append(";");
sb.append(encodeBottleStatus(card));
sb.append(';');
sb.append(encodeModName(card));
sb.append(";");
if (!repr) {
sb.append(encodeCardToPreview(card));
sb.append(';');
Expand Down Expand Up @@ -277,6 +283,12 @@ private String encodeBottleStatus(AbstractCard card) {
}
}

private String encodeModName(AbstractCard card) {
String modName = WhatMod.findModName(card.getClass());

return modName != null ? modName : "-";
}

private String sanitize(String s) {
return s.replaceAll(";", ":")
.replaceAll("\"", "\\\"")
Expand Down Expand Up @@ -357,7 +369,7 @@ private String parseDescription(AbstractCard card) {
sb.append(matcherKeyword.group(1));
} else { // Replace color codes for now

part = part.replaceAll("\\[[a-zA-Z_]*\\]", "");
part = part.replaceAll("\\[[a-zA-Z_]{2,}\\]", "");
part = part.replaceAll("\\[#[A-Ea-e0-9]*\\]", "");
part = part.replaceAll("\\[\\]", "");
part = part.replaceAll("\\[\\[", "[");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/str_exporter/TipsJSONBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ public class TipsJSONBuilder extends JSONMessageBuilder{

public TipsJSONBuilder(String login, String secret, String version) {
super(login, secret, version, 1);
powerTips = new ArrayList<>(40);
}

@Override
public void buildMessage(StringBuilder sb) {

powerTips = new ArrayList<>(40);
powerTips.clear();

String character = "";

Expand Down

0 comments on commit 7e40051

Please sign in to comment.