MCPcopy Create free account
hub / github.com/Card-Forge/forge / load

Method load

forge-gui-mobile/src/forge/assets/FSkinImageImpl.java:29–123  ·  view source on GitHub ↗
(Pixmap preferredIcons)

Source from the content-addressed store, hash-verified

27
28
29 public void load(Pixmap preferredIcons) {
30 FSkinProp.PropType type = skinProp.getType();
31 String filename = type.getFilename();
32 if (filename == null) {
33 return;
34 }
35 boolean is2D = type == FSkinProp.PropType.ADVENTURE;
36 FileHandle preferredFile = type == FSkinProp.PropType.MANAICONS ? FSkin.getDefaultSkinFile(filename) : FSkin.getSkinFile(filename);
37 Texture texture = Forge.getAssets().getTexture(preferredFile, is2D, false);
38 if (texture == null) {
39 if (preferredFile.exists()) {
40 try {
41 texture = Forge.getAssets().getTexture(preferredFile, is2D, false);
42 }
43 catch (final Exception e) {
44 System.err.println("Failed to load skin file: " + preferredFile);
45 //e.printStackTrace();
46 }
47 }
48 }
49 if (texture != null) {
50 if (!(type == FSkinProp.PropType.ABILITY || type == FSkinProp.PropType.IMAGE || type == FSkinProp.PropType.ICON || type == FSkinProp.PropType.MANAICONS)) { //just return region for preferred file if not icons file
51 textureRegion = new TextureRegion(texture, x, y, w, h);
52 return;
53 }
54
55 int fullWidth = texture.getWidth();
56 int fullHeight = texture.getHeight();
57
58 // Test if requested sub-image in inside bounds of preferred sprite.
59 // (Height and width of preferred sprite were set in loadFontAndImages.)
60 if (x + w <= fullWidth && y + h <= fullHeight) {
61 // Test if various points of requested sub-image are transparent.
62 // If any return true, image exists.
63 int x0 = 0, y0 = 0;
64 Color c;
65
66 // Center
67 x0 = (x + w / 2);
68 y0 = (y + h / 2);
69 c = new Color(preferredIcons.getPixel(x0, y0));
70 if (c.a != 0) {
71 textureRegion = new TextureRegion(texture, x, y, w, h);
72 return;
73 }
74
75 x0 += 2;
76 y0 += 2;
77 c = new Color(preferredIcons.getPixel(x0, y0));
78 if (c.a != 0) {
79 textureRegion = new TextureRegion(texture, x, y, w, h);
80 return;
81 }
82
83 x0 -= 4;
84 c = new Color(preferredIcons.getPixel(x0, y0));
85 if (c.a != 0) {
86 textureRegion = new TextureRegion(texture, x, y, w, h);

Callers 1

loadFullMethod · 0.95

Calls 8

getDefaultSkinFileMethod · 0.95
getSkinFileMethod · 0.95
getAssetsMethod · 0.95
getFilenameMethod · 0.80
getTypeMethod · 0.65
getWidthMethod · 0.65
getHeightMethod · 0.65
getTextureMethod · 0.45

Tested by

no test coverage detected