Skip to content

Commit

Permalink
add shop potions/relics and boss relics to custom tips, setup meaning…
Browse files Browse the repository at this point in the history
…ful timing for tips and deck checking and broadcasting, fix deck quote sanitization, sanitize Gdxlib color codes from power tips, fix string compression characters, fix minor bug in custom tips, refactoring in TipsJSONBuilder - extract a hitbox building function, use buildPowerTips for potions and relics, remove redundant code
  • Loading branch information
avolny committed May 3, 2020
1 parent 7e40051 commit bf681b9
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 93 deletions.
6 changes: 3 additions & 3 deletions src/main/java/str_exporter/DeckJSONBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void buildCard(StringBuilder sb, AbstractCard card, boolean repr) {
copy.upgrade();
copy.displayUpgrades();
String upgradedDesc = sanitizeEmpty(parseDescription(copy));
String upgradedName = sanitizeEmpty(copy.name);
String upgradedName = sanitizeEmpty(sanitize(copy.name));
String upgradedKeywords = sanitizeEmpty(encodeKeywords(copy));

int timesUpgraded = card.timesUpgraded;
Expand Down Expand Up @@ -290,8 +290,8 @@ private String encodeModName(AbstractCard card) {
}

private String sanitize(String s) {
return s.replaceAll(";", ":")
.replaceAll("\"", "\\\"")
return s.replace(";", ":")
.replace("\"", "\\\"")
.replaceAll("\\[[A-Z]\\]", "[E]");
}

Expand Down
49 changes: 31 additions & 18 deletions src/main/java/str_exporter/SlayTheRelicsExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public class SlayTheRelicsExporter implements
private static String secret = null;
private static String version = "";

private long lastCheck = System.currentTimeMillis();
private boolean checkNextUpdate = false;
private long lastTipsCheck = System.currentTimeMillis();
private long lastDeckCheck = System.currentTimeMillis();
private boolean checkTipsNextUpdate = false;
private boolean checkDeckNextUpdate = false;

private TipsJSONBuilder tipsJsonBuilder;
private DeckJSONBuilder deckJsonBuilder;
Expand All @@ -55,7 +57,9 @@ public class SlayTheRelicsExporter implements

// private static final long MAX_BROADCAST_PERIOD_MILLIS = 250;
private static final long MAX_CHECK_PERIOD_MILLIS = 1000;
private static final long BROADCAST_CHECK_QUEUE_PERIOD_MILLIS = 500;
private static final long MIN_DECK_CHECK_PERIOD_MILLIS = 1000;
private static final long MAX_DECK_CHECK_PERIOD_MILLIS = 2000;
private static final long BROADCAST_CHECK_QUEUE_PERIOD_MILLIS = 100;
private static final long MAX_OKAY_BROADCAST_PERIOD_MILLIS = 1000;

public static SlayTheRelicsExporter instance = null;
Expand Down Expand Up @@ -126,28 +130,24 @@ public static void initialize()
}

private void queue_check() {
checkNextUpdate = true;
checkTipsNextUpdate = true;
checkDeckNextUpdate = true;
}

private void check() {
if (areCredentialsValid()) {
broadcast();
} else {
// logger.info("Either your secret or your login are null. The config file has probably not loaded properly");
}
}

private void broadcast() {
private void broadcastTips() {
long start = System.nanoTime();
String tips_json = tipsJsonBuilder.buildJson();
long end = System.nanoTime();
logger.info("tips json builder took " + (end - start) / 1e6 + " milliseconds");
// logger.info(tips_json);
tipsBroadcaster.queueMessage(tips_json);
}

start = System.nanoTime();
private void broadcastDeck() {
long start = System.nanoTime();
String deck_json = deckJsonBuilder.buildJson();
end = System.nanoTime();
long end = System.nanoTime();
logger.info("deck json builder took " + (end - start) / 1e6 + " milliseconds");
// logger.info(deck_json);
deckBroadcaster.queueMessage(deck_json);
Expand Down Expand Up @@ -199,12 +199,25 @@ public void receivePostInitialize() {

@Override
public void receivePostRender(SpriteBatch spriteBatch) {
if (checkNextUpdate || System.currentTimeMillis() - lastCheck > MAX_CHECK_PERIOD_MILLIS) {
if (checkTipsNextUpdate || System.currentTimeMillis() - lastTipsCheck > MAX_CHECK_PERIOD_MILLIS) {

lastCheck = System.currentTimeMillis();
check();
lastTipsCheck = System.currentTimeMillis();
if (areCredentialsValid()) {
broadcastTips();
}

checkTipsNextUpdate = false;
}

if ((checkDeckNextUpdate && System.currentTimeMillis() - lastDeckCheck > MIN_DECK_CHECK_PERIOD_MILLIS) ||
System.currentTimeMillis() - lastDeckCheck > MAX_DECK_CHECK_PERIOD_MILLIS) {

lastDeckCheck = System.currentTimeMillis();
if (areCredentialsValid()) {
broadcastDeck();
}

checkNextUpdate = false;
checkDeckNextUpdate = false;
}

if (System.currentTimeMillis() - lastOkayBroadcast > MAX_OKAY_BROADCAST_PERIOD_MILLIS) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/str_exporter/StringCompression.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public int compareTo(Word o) {
}

public static String compress(String s) {
return compress(s, "\\s;:,./");
return compress(s, " \t\n\r\f;:,./");
}

public static String compress(String s, String delims) {
Expand Down
Loading

0 comments on commit bf681b9

Please sign in to comment.