v3.0.1: improved sync checks in game log

This commit is contained in:
Evan Debenham
2025-03-06 11:40:31 -05:00
parent c04920630a
commit 8f0a13ca22

View File

@@ -54,79 +54,81 @@ public class GameLog extends Component implements Signal.Listener<String> {
@Override @Override
public synchronized void update() { public synchronized void update() {
if (!textsToAdd.isEmpty()){ synchronized (textsToAdd){
int maxLines = SPDSettings.interfaceSize() > 0 ? 5 : 3; if (!textsToAdd.isEmpty()){
for (String text : textsToAdd){ int maxLines = SPDSettings.interfaceSize() > 0 ? 5 : 3;
if (length != entries.size()){ for (String text : textsToAdd){
clear(); if (length != entries.size()){
recreateLines(); clear();
} recreateLines();
}
if (text.equals( GLog.NEW_LINE )){ if (text.equals( GLog.NEW_LINE )){
lastEntry = null;
continue;
}
int color = CharSprite.DEFAULT;
if (text.startsWith( GLog.POSITIVE )) {
text = text.substring( GLog.POSITIVE.length() );
color = CharSprite.POSITIVE;
} else
if (text.startsWith( GLog.NEGATIVE )) {
text = text.substring( GLog.NEGATIVE.length() );
color = CharSprite.NEGATIVE;
} else
if (text.startsWith( GLog.WARNING )) {
text = text.substring( GLog.WARNING.length() );
color = CharSprite.WARNING;
} else
if (text.startsWith( GLog.HIGHLIGHT )) {
text = text.substring( GLog.HIGHLIGHT.length() );
color = CharSprite.NEUTRAL;
}
if (lastEntry != null && color == lastColor && lastEntry.nLines < maxLines) {
String lastMessage = lastEntry.text();
lastEntry.text( lastMessage.length() == 0 ? text : lastMessage + " " + text );
entries.get( entries.size() - 1 ).text = lastEntry.text();
} else {
lastEntry = PixelScene.renderTextBlock( text, 6 );
lastEntry.hardlight( color );
lastColor = color;
add( lastEntry );
entries.add( new Entry( text, color ) );
}
if (length > 0) {
int nLines;
do {
nLines = 0;
for (int i = 0; i < length-1; i++) {
nLines += ((RenderedTextBlock) members.get(i)).nLines;
}
if (nLines > maxLines) {
RenderedTextBlock r = ((RenderedTextBlock) members.get(0));
remove(r);
r.destroy();
entries.remove( 0 );
}
} while (nLines > maxLines);
if (entries.isEmpty()) {
lastEntry = null; lastEntry = null;
continue;
}
int color = CharSprite.DEFAULT;
if (text.startsWith( GLog.POSITIVE )) {
text = text.substring( GLog.POSITIVE.length() );
color = CharSprite.POSITIVE;
} else
if (text.startsWith( GLog.NEGATIVE )) {
text = text.substring( GLog.NEGATIVE.length() );
color = CharSprite.NEGATIVE;
} else
if (text.startsWith( GLog.WARNING )) {
text = text.substring( GLog.WARNING.length() );
color = CharSprite.WARNING;
} else
if (text.startsWith( GLog.HIGHLIGHT )) {
text = text.substring( GLog.HIGHLIGHT.length() );
color = CharSprite.NEUTRAL;
}
if (lastEntry != null && color == lastColor && lastEntry.nLines < maxLines) {
String lastMessage = lastEntry.text();
lastEntry.text( lastMessage.length() == 0 ? text : lastMessage + " " + text );
entries.get( entries.size() - 1 ).text = lastEntry.text();
} else {
lastEntry = PixelScene.renderTextBlock( text, 6 );
lastEntry.hardlight( color );
lastColor = color;
add( lastEntry );
entries.add( new Entry( text, color ) );
}
if (length > 0) {
int nLines;
do {
nLines = 0;
for (int i = 0; i < length-1; i++) {
nLines += ((RenderedTextBlock) members.get(i)).nLines;
}
if (nLines > maxLines) {
RenderedTextBlock r = ((RenderedTextBlock) members.get(0));
remove(r);
r.destroy();
entries.remove( 0 );
}
} while (nLines > maxLines);
if (entries.isEmpty()) {
lastEntry = null;
}
} }
} }
}
layout(); layout();
textsToAdd.clear(); textsToAdd.clear();
}
} }
super.update(); super.update();
} }
@@ -144,8 +146,10 @@ public class GameLog extends Component implements Signal.Listener<String> {
} }
@Override @Override
public synchronized boolean onSignal( String text ) { public boolean onSignal( String text ) {
textsToAdd.add(text); synchronized (textsToAdd) {
textsToAdd.add(text);
}
return false; return false;
} }
@@ -171,7 +175,9 @@ public class GameLog extends Component implements Signal.Listener<String> {
} }
public static void wipe() { public static void wipe() {
entries.clear(); synchronized (textsToAdd) {
textsToAdd.clear(); entries.clear();
textsToAdd.clear();
}
} }
} }