mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
prevent crash using invalid theme
This commit is contained in:
@@ -468,18 +468,25 @@ public class FSkin {
|
||||
x0 = tempCoords[0];
|
||||
y0 = tempCoords[1];
|
||||
|
||||
color = bimPreferredSprite.getData().getBounds().contains(x0, y0) ? getColorFromPixel(bimPreferredSprite.getRGB(x0, y0)) : new Color(0, 0, 0, 0);
|
||||
try {
|
||||
color = bimPreferredSprite.getData().getBounds().contains(x0, y0) ? getColorFromPixel(bimPreferredSprite.getRGB(x0, y0)) : new Color(0, 0, 0, 0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawImage(final Graphics g, final SkinImage skinImage, final int x, final int y) {
|
||||
skinImage.draw(g, x, y);
|
||||
if (skinImage != null)
|
||||
skinImage.draw(g, x, y);
|
||||
}
|
||||
public static void drawImage(final Graphics g, final SkinImage skinImage, final int x, final int y, final int w, final int h) {
|
||||
skinImage.draw(g, x, y, w, h);
|
||||
if (skinImage != null)
|
||||
skinImage.draw(g, x, y, w, h);
|
||||
}
|
||||
public static void drawImage(final Graphics g, final SkinImage skinImage, final int dx1, final int dy1, final int dx2, final int dy2, final int sx1, final int sy1, final int sx2, final int sy2) {
|
||||
skinImage.draw(g, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);
|
||||
if (skinImage != null)
|
||||
skinImage.draw(g, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -558,13 +565,18 @@ public class FSkin {
|
||||
newW = (tempCoords.length == 6 ? tempCoords[4] : 0);
|
||||
newH = (tempCoords.length == 6 ? tempCoords[5] : 0);
|
||||
final BufferedImage img = testPreferredSprite(s0);
|
||||
final BufferedImage bi0 = img.getSubimage(x0, y0, w0, h0);
|
||||
if (img == null)
|
||||
return;
|
||||
try {
|
||||
final BufferedImage bi0 = img.getSubimage(x0, y0, w0, h0);
|
||||
|
||||
if (scale && newW != 0) {
|
||||
setImage(s0, bi0.getScaledInstance(newW, newH, Image.SCALE_SMOOTH));
|
||||
}
|
||||
else {
|
||||
setImage(s0, bi0);
|
||||
if (scale && newW != 0) {
|
||||
setImage(s0, bi0.getScaledInstance(newW, newH, Image.SCALE_SMOOTH));
|
||||
} else {
|
||||
setImage(s0, bi0);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -775,8 +787,13 @@ public class FSkin {
|
||||
h0 = tempCoords[3];
|
||||
|
||||
final BufferedImage img = testPreferredSprite(s0);
|
||||
|
||||
setIcon(s0, new ImageIcon(img.getSubimage(x0, y0, w0, h0)));
|
||||
if (img == null)
|
||||
return;
|
||||
try {
|
||||
setIcon(s0, new ImageIcon(img.getSubimage(x0, y0, w0, h0)));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1055,7 +1072,11 @@ public class FSkin {
|
||||
}
|
||||
|
||||
private void updateFont() {
|
||||
this.font = baseFont.deriveFont(this.style, this.size);
|
||||
try {
|
||||
this.font = baseFont.deriveFont(this.style, this.size);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1154,7 +1175,7 @@ public class FSkin {
|
||||
|
||||
// Non-default (preferred) skin name and dir.
|
||||
preferredName = skinName.toLowerCase().replace(' ', '_');
|
||||
preferredDir = preferredName.equals("default") ? ForgeConstants.DEFAULT_SKINS_DIR : ForgeConstants.CACHE_SKINS_DIR + preferredName + "/";
|
||||
preferredDir = preferredName.equalsIgnoreCase("default") || preferredName.isEmpty() ? ForgeConstants.DEFAULT_SKINS_DIR : ForgeConstants.CACHE_SKINS_DIR + preferredName + "/";
|
||||
|
||||
if (onInit) {
|
||||
final File f = new File(preferredDir + ForgeConstants.SPLASH_BG_FILE);
|
||||
@@ -1496,8 +1517,12 @@ public class FSkin {
|
||||
h0 = tempCoords[3];
|
||||
|
||||
if (s0.equals(FSkinProp.IMG_QUEST_DRAFT_DECK)) {
|
||||
final Color c = getColorFromPixel(bimQuestDraftDeck.getRGB((x0 + w0 / 2), (y0 + h0 / 2)));
|
||||
if (c.getAlpha() != 0) { return bimQuestDraftDeck; }
|
||||
if (bimQuestDraftDeck != null) {
|
||||
final Color c = getColorFromPixel(bimQuestDraftDeck.getRGB((x0 + w0 / 2), (y0 + h0 / 2)));
|
||||
if (c.getAlpha() != 0) { return bimQuestDraftDeck; }
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Test if requested sub-image in inside bounds of preferred sprite.
|
||||
@@ -1512,28 +1537,30 @@ public class FSkin {
|
||||
int x, y;
|
||||
Color c;
|
||||
|
||||
// Center
|
||||
x = (x0 + w0 / 2);
|
||||
y = (y0 + h0 / 2);
|
||||
c = getColorFromPixel(bimPreferredSprite.getRGB(x, y));
|
||||
if (c.getAlpha() != 0) { return bimPreferredSprite; }
|
||||
if (bimPreferredSprite != null) {
|
||||
// Center
|
||||
x = (x0 + w0 / 2);
|
||||
y = (y0 + h0 / 2);
|
||||
c = getColorFromPixel(bimPreferredSprite.getRGB(x, y));
|
||||
if (c.getAlpha() != 0) { return bimPreferredSprite; }
|
||||
|
||||
x += 2;
|
||||
y += 2;
|
||||
c = getColorFromPixel(bimPreferredSprite.getRGB(x, y));
|
||||
if (c.getAlpha() != 0) { return bimPreferredSprite; }
|
||||
x += 2;
|
||||
y += 2;
|
||||
c = getColorFromPixel(bimPreferredSprite.getRGB(x, y));
|
||||
if (c.getAlpha() != 0) { return bimPreferredSprite; }
|
||||
|
||||
x -= 4;
|
||||
c = getColorFromPixel(bimPreferredSprite.getRGB(x, y));
|
||||
if (c.getAlpha() != 0) { return bimPreferredSprite; }
|
||||
x -= 4;
|
||||
c = getColorFromPixel(bimPreferredSprite.getRGB(x, y));
|
||||
if (c.getAlpha() != 0) { return bimPreferredSprite; }
|
||||
|
||||
y -= 4;
|
||||
c = getColorFromPixel(bimPreferredSprite.getRGB(x, y));
|
||||
if (c.getAlpha() != 0) { return bimPreferredSprite; }
|
||||
y -= 4;
|
||||
c = getColorFromPixel(bimPreferredSprite.getRGB(x, y));
|
||||
if (c.getAlpha() != 0) { return bimPreferredSprite; }
|
||||
|
||||
x += 4;
|
||||
c = getColorFromPixel(bimPreferredSprite.getRGB(x, y));
|
||||
if (c.getAlpha() != 0) { return bimPreferredSprite; }
|
||||
x += 4;
|
||||
c = getColorFromPixel(bimPreferredSprite.getRGB(x, y));
|
||||
if (c.getAlpha() != 0) { return bimPreferredSprite; }
|
||||
}
|
||||
|
||||
return bimDefaultSprite;
|
||||
}
|
||||
@@ -1569,7 +1596,11 @@ public class FSkin {
|
||||
if (pxTest.getAlpha() == 0) {
|
||||
continue;
|
||||
}
|
||||
avatars.put(counter++, new SkinImage(bimDefaultAvatars.getSubimage(i, j, 100, 100)));
|
||||
try {
|
||||
avatars.put(counter++, new SkinImage(bimDefaultAvatars.getSubimage(i, j, 100, 100)));
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1580,25 +1611,31 @@ public class FSkin {
|
||||
int counter = 0;
|
||||
Color pxTest;
|
||||
|
||||
final int pw = bimDefaultSleeve.getWidth();
|
||||
final int ph = bimDefaultSleeve.getHeight();
|
||||
if (bimDefaultSleeve != null) {
|
||||
final int pw = bimDefaultSleeve.getWidth();
|
||||
final int ph = bimDefaultSleeve.getHeight();
|
||||
|
||||
for (int j = 0; j < ph; j += 500) {
|
||||
for (int i = 0; i < pw; i += 360) {
|
||||
pxTest = getColorFromPixel(bimDefaultSleeve.getRGB(i + 180, j + 250));
|
||||
if (pxTest.getAlpha() == 0) { continue; }
|
||||
sleeves.put(counter++, new SkinImage(bimDefaultSleeve.getSubimage(i, j, 360, 500)));
|
||||
for (int j = 0; j < ph; j += 500) {
|
||||
for (int i = 0; i < pw; i += 360) {
|
||||
pxTest = getColorFromPixel(bimDefaultSleeve.getRGB(i + 180, j + 250));
|
||||
if (pxTest.getAlpha() == 0) {
|
||||
continue;
|
||||
}
|
||||
sleeves.put(counter++, new SkinImage(bimDefaultSleeve.getSubimage(i, j, 360, 500)));
|
||||
}
|
||||
}
|
||||
}
|
||||
//2nd set
|
||||
final int aw = bimDefaultSleeve2.getWidth();
|
||||
final int ah = bimDefaultSleeve2.getHeight();
|
||||
if (bimDefaultSleeve2 != null) {
|
||||
//2nd set
|
||||
final int aw = bimDefaultSleeve2.getWidth();
|
||||
final int ah = bimDefaultSleeve2.getHeight();
|
||||
|
||||
for (int j = 0; j < ah; j += 500) {
|
||||
for (int i = 0; i < aw; i += 360) {
|
||||
pxTest = getColorFromPixel(bimDefaultSleeve2.getRGB(i + 180, j + 250));
|
||||
if (pxTest.getAlpha() == 0) { continue; }
|
||||
sleeves.put(counter++, new SkinImage(bimDefaultSleeve2.getSubimage(i, j, 360, 500)));
|
||||
for (int j = 0; j < ah; j += 500) {
|
||||
for (int i = 0; i < aw; i += 360) {
|
||||
pxTest = getColorFromPixel(bimDefaultSleeve2.getRGB(i + 180, j + 250));
|
||||
if (pxTest.getAlpha() == 0) { continue; }
|
||||
sleeves.put(counter++, new SkinImage(bimDefaultSleeve2.getSubimage(i, j, 360, 500)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user