mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Merge remote-tracking branch 'upstream/master' into deck-importer-decks-file-format
This commit is contained in:
@@ -206,6 +206,7 @@ public class ImageCache {
|
||||
boolean noBorder = !useArtCrop && !isPreferenceEnabled(ForgePreferences.FPref.UI_RENDER_BLACK_BORDERS);
|
||||
boolean fetcherEnabled = isPreferenceEnabled(ForgePreferences.FPref.UI_ENABLE_ONLINE_IMAGE_FETCHER);
|
||||
boolean isPlaceholder = (original == null) && fetcherEnabled;
|
||||
String setCode = imageKey.split("/")[0].trim().toUpperCase();
|
||||
|
||||
// If the user has indicated that they prefer Forge NOT render a black border, round the image corners
|
||||
// to account for JPEG images that don't have a transparency.
|
||||
@@ -213,7 +214,6 @@ public class ImageCache {
|
||||
// use a quadratic equation to calculate the needed radius from an image dimension
|
||||
int radius;
|
||||
float width = original.getWidth();
|
||||
String setCode = imageKey.split("/")[0].trim().toUpperCase();
|
||||
if (setCode.equals("A")) { // Alpha
|
||||
// radius = 100; // 745 x 1040
|
||||
// radius = 68; // 488 x 680
|
||||
@@ -239,6 +239,15 @@ public class ImageCache {
|
||||
original = makeRoundedCorner(original, radius);
|
||||
}
|
||||
|
||||
// if image has white corners, get try to crop it out
|
||||
if (original != null && isWhite(FSkin.getColorFromPixel(original.getRGB(0, 0)))) {
|
||||
if (!isWhiteBorderSet(setCode)) {
|
||||
int xSpacing = original.getWidth() / 40;
|
||||
int ySpacing = original.getHeight() / 57;
|
||||
original = original.getSubimage(xSpacing, ySpacing, original.getWidth() - (2* xSpacing), original.getHeight() - (2* ySpacing));
|
||||
}
|
||||
}
|
||||
|
||||
// No image file exists for the given key so optionally associate with
|
||||
// a default "not available" image, however do not add it to the cache,
|
||||
// as otherwise it's problematic to update if the real image gets fetched.
|
||||
@@ -268,6 +277,15 @@ public class ImageCache {
|
||||
return Pair.of(original, isPlaceholder);
|
||||
}
|
||||
|
||||
private static boolean isWhite(Color color) {
|
||||
return color.getRed() > 200 && color.getBlue() > 200 && color.getGreen() > 200;
|
||||
}
|
||||
|
||||
private static boolean isWhiteBorderSet(String setCode) {
|
||||
return setCode.equals("U") || setCode.equals("R") || setCode.equals("4E") || setCode.equals("5E") ||
|
||||
setCode.equals("6E") || setCode.equals("7E") || setCode.equals("8E") || setCode.equals("9E");
|
||||
}
|
||||
|
||||
// cardView is for Emblem, since there is no paper card for them
|
||||
public static BufferedImage scaleImage(String key, final int width, final int height, boolean useDefaultImage, CardView cardView) {
|
||||
if (StringUtils.isEmpty(key) || (3 > width && -1 != width) || (3 > height && -1 != height)) {
|
||||
|
||||
@@ -1498,7 +1498,7 @@ public class FSkin {
|
||||
* @param pixel
|
||||
* @return
|
||||
*/
|
||||
private static Color getColorFromPixel(final int pixel) {
|
||||
public static Color getColorFromPixel(final int pixel) {
|
||||
int r, g, b, a;
|
||||
a = (pixel >> 24) & 0x000000ff;
|
||||
r = (pixel >> 16) & 0x000000ff;
|
||||
|
||||
@@ -172,7 +172,6 @@ public class SimulateMatch {
|
||||
System.out.println("\tq - Quiet flag. Output just the game result, not the entire game log.");
|
||||
}
|
||||
|
||||
|
||||
public static void simulateSingleMatch(final Match mc, int iGame, boolean outputGamelog) {
|
||||
final StopWatch sw = new StopWatch();
|
||||
sw.start();
|
||||
|
||||
@@ -7,14 +7,10 @@ import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
@@ -2246,5 +2242,4 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
|
||||
assertTrue(islandCard.isFoil());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package forge.card;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.ImageKeys;
|
||||
import forge.item.PaperCard;
|
||||
import org.mockito.Mockito;
|
||||
@@ -7,6 +8,8 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
@@ -26,11 +29,11 @@ public class CardDbTestWithNoImage extends CardDbTestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
@BeforeMethod
|
||||
protected void initMocks() throws Exception {
|
||||
protected void initCardImageMocks() {
|
||||
PowerMockito.mockStatic(ImageIO.class);
|
||||
PowerMockito.mockStatic(ImageCache.class);
|
||||
PowerMockito.mockStatic(ImageKeys.class);
|
||||
PowerMockito.when(ImageKeys.hasImage(Mockito.any(PaperCard.class))).thenReturn(false);
|
||||
super.initMocks();
|
||||
PowerMockito.when(ImageKeys.hasImage(Mockito.any(PaperCard.class), Mockito.anyBoolean())).thenReturn(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -114,7 +114,7 @@ public class ForgeCardMockTestCase extends PowerMockTestCase {
|
||||
fLangDir.set(ForgeConstants.class, langDir);
|
||||
}
|
||||
|
||||
private void setMock(Localizer mock) {
|
||||
protected void setMock(Localizer mock) {
|
||||
try {
|
||||
Field instance = Localizer.class.getDeclaredField("instance");
|
||||
instance.setAccessible(true);
|
||||
@@ -128,16 +128,14 @@ public class ForgeCardMockTestCase extends PowerMockTestCase {
|
||||
protected void initMocks() throws Exception {
|
||||
//Loading a card also automatically loads the image, which we do not want (even if it wouldn't cause exceptions).
|
||||
//The static initializer block in ImageCache can't fully be mocked (https://code.google.com/p/powermock/issues/detail?id=256), so we also need to mess with ImageIO...
|
||||
//TODO: make sure that loading images only happens in a GUI environment, so we no longer need to mock this
|
||||
PowerMockito.mockStatic(ImageIO.class);
|
||||
PowerMockito.mockStatic(ImageCache.class);
|
||||
PowerMockito.mockStatic(ImageKeys.class);
|
||||
initCardImageMocks();
|
||||
initForgeConstants();
|
||||
|
||||
// Always Has Image (there is a separated test case to cover the opposite case)
|
||||
PowerMockito.when(ImageKeys.hasImage(Mockito.any(PaperCard.class))).thenReturn(true);
|
||||
|
||||
//Mocking some more static stuff
|
||||
initForgePreferences();
|
||||
initializeStaticData();
|
||||
}
|
||||
|
||||
protected void initForgePreferences() throws IllegalAccessException {
|
||||
PowerMockito.mockStatic(Singletons.class);
|
||||
PowerMockito.mockStatic(FModel.class);
|
||||
ForgePreferences forgePreferences = new ForgePreferences();
|
||||
@@ -161,7 +159,14 @@ public class ForgeCardMockTestCase extends PowerMockTestCase {
|
||||
PowerMockito.field(Localizer.class, "resourceBundle").set(localizerMock, dummyResourceBundle);
|
||||
PowerMockito.when(localizerMock.getMessage(Mockito.anyString())).thenReturn("any string");
|
||||
PowerMockito.when(FModel.getPreferences()).thenReturn(forgePreferences);
|
||||
initializeStaticData();
|
||||
}
|
||||
|
||||
protected void initCardImageMocks() {
|
||||
//make sure that loading images only happens in a GUI environment, so we no longer need to mock this
|
||||
PowerMockito.mockStatic(ImageIO.class);
|
||||
PowerMockito.mockStatic(ImageCache.class);
|
||||
PowerMockito.mockStatic(ImageKeys.class);
|
||||
PowerMockito.when(ImageKeys.hasImage(Mockito.any(PaperCard.class), Mockito.anyBoolean())).thenReturn(true);
|
||||
}
|
||||
|
||||
protected void initializeStaticData() {
|
||||
|
||||
Reference in New Issue
Block a user