Skip to content

Commit

Permalink
Don't clear when using setAll, to avoid blinking
Browse files Browse the repository at this point in the history
  • Loading branch information
MinusKube committed Jun 10, 2020
1 parent 6304ddf commit 4b1afc5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class BPlayerBoard implements PlayerBoard<String, Integer, String> {

Expand Down Expand Up @@ -121,13 +122,18 @@ public void setAll(String... lines) {
if(this.deleted)
throw new IllegalStateException("The PlayerBoard is deleted!");

clear();

for(int i = 0; i < lines.length; i++) {
String line = lines[i];

set(line, lines.length - i);
}

Set<Integer> scores = new HashSet<>(this.lines.keySet());
for (int score : scores) {
if (score <= 0 || score > lines.length) {
remove(score);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface PlayerBoard<V, N, S> {
* Sets all the lines of the scoreboard.
* This will clear all of the current board lines, then set
* all of the given lines, from top to down, by giving them each a score
* determined by {@code 16 - index}.
* determined by {@code lines.length - index}.
*
* @param lines the new board lines
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class SPlayerBoard implements PlayerBoard<Text, Integer, Text> {

Expand Down Expand Up @@ -125,13 +126,18 @@ public void setAll(Text... lines) {
if(this.deleted)
throw new IllegalStateException("The PlayerBoard is deleted!");

clear();

for(int i = 0; i < lines.length; i++) {
Text line = lines[i];

set(line, lines.length - i);
}

Set<Integer> scores = new HashSet<>(this.lines.keySet());
for (int score : scores) {
if (score <= 0 || score > lines.length) {
remove(score);
}
}
}

@Override
Expand Down

0 comments on commit 4b1afc5

Please sign in to comment.