refactor: improved code to increase readability. (#11418)

Moved the cardViewEquals method from CardPanelRenderModeMTGO to CardView
Decomposed conditional to increase readability.
Changed the variable/constant names to increase the readability.
This commit is contained in:
Tirth Bharatiya 2023-11-17 12:17:53 +05:30 committed by GitHub
parent bea33c7493
commit 44b8a0faf4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 55 deletions

View file

@ -264,21 +264,22 @@ public class ChatPanelBasic extends javax.swing.JPanel {
messageToTest = message.replaceFirst("<font bgcolor=orange.*?</font>", "");
}
if (messageType == MessageType.USER_INFO || messageType == MessageType.GAME || messageType == MessageType.STATUS
|| PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0").equals("0")
|| !PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0").equals("0") && !containsSwearing(messageToTest, PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0"))) {
String cachedProfanityFilterValue = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0");
boolean isContainsSwearing = !containsSwearing(messageToTest, cachedProfanityFilterValue);
boolean isUserInfoOrGameOrStatus = messageType == MessageType.USER_INFO || messageType == MessageType.GAME || messageType == MessageType.STATUS;
if (isUserInfoOrGameOrStatus || cachedProfanityFilterValue.equals("0") || (!cachedProfanityFilterValue.equals("0") && !isContainsSwearing)) {
if (username != null && !username.isEmpty()) {
text.append(getColoredText(userColor, username + userSeparator));
}
text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML(message, ManaSymbols.Type.CHAT)));
this.txtConversation.append(text.toString());
} else if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0").equals("1")) {
} else if (cachedProfanityFilterValue.equals("1")) {
if (username != null && !username.isEmpty()) {
text.append(getColoredText("black", username + userSeparator));
}
text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML("<font color=black size=-2>" + message + "</font> <font size=-2>Profanity detected. Type: <font color=green>/w " + SessionHandler.getUserName() + " profanity 0</font>' to turn the filter off</font></font>", ManaSymbols.Type.CHAT)));
this.txtConversation.append(text.toString());
} else if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_USE_PROFANITY_FILTER, "0").equals("2")) {
} else if (cachedProfanityFilterValue.equals("2")) {
text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML("<font color=black size=-2>" + username + ": Profanity detected. To make it less strict, type: </font> <font color=green size=-2>/w " + SessionHandler.getUserName() + " profanity 1</font>", ManaSymbols.Type.CHAT)));
this.txtConversation.append(text.toString());
}

View file

@ -16,7 +16,6 @@ import org.mage.plugins.card.images.ImageCacheData;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@ -54,43 +53,6 @@ public class CardPanelRenderModeMTGO extends CardPanel {
private int updateArtImageStamp;
private static boolean cardViewEquals(CardView a, CardView b) { // TODO: This belongs in CardView
if (a == b) {
return true;
}
if (a == null || b == null || a.getClass() != b.getClass()) {
return false;
}
if (!(a.getDisplayName().equals(b.getDisplayName()) // TODO: Original code not checking everything. Why is it only checking these values?
&& a.getPower().equals(b.getPower())
&& a.getToughness().equals(b.getToughness())
&& a.getLoyalty().equals(b.getLoyalty())
&& a.getDefense().equals(b.getDefense())
&& 0 == a.getColor().compareTo(b.getColor())
&& a.getCardTypes().equals(b.getCardTypes())
&& a.getSubTypes().equals(b.getSubTypes())
&& a.getSuperTypes().equals(b.getSuperTypes())
&& a.getManaCostStr().equals(b.getManaCostStr())
&& a.getRules().equals(b.getRules())
&& Objects.equals(a.getRarity(), b.getRarity())
&& Objects.equals(a.getCardNumber(), b.getCardNumber())
&& Objects.equals(a.getExpansionSetCode(), b.getExpansionSetCode())
&& a.getFrameStyle() == b.getFrameStyle()
&& Objects.equals(a.getCounters(), b.getCounters())
&& a.isFaceDown() == b.isFaceDown())) {
return false;
}
if (!(a instanceof PermanentView)) {
return true;
}
PermanentView aa = (PermanentView) a;
PermanentView bb = (PermanentView) b;
return aa.hasSummoningSickness() == bb.hasSummoningSickness()
&& aa.getDamage() == bb.getDamage();
}
private static class ImageKey {
final BufferedImage artImage;
final int width;
@ -178,7 +140,7 @@ public class CardPanelRenderModeMTGO extends CardPanel {
&& this.height == that.height
&& this.isChoosable == that.isChoosable
&& this.isSelected == that.isSelected
&& cardViewEquals(this.view, that.view);
&& CardView.cardViewEquals(this.view, that.view);
}
}